FUNCTION fit_simul_wind_function,p

common func_simul_wind_xy, x, y1, y2, y3, y4

;The function we are trying to fit is
;y=((d+(k0/kl)^(1/(b-4))*D)/po))^(b-2)
;
;p(0)=ko
;p(1)=wind
;p(2)=kl
;p(3)=kt
;p(4)=b
;p(5)=po


a=1./(p(4)-4)
b=p(4)-2
koxl=float(p(0)/p(2))
koyl=float(p(0)/p(2))
koxt=float(p(0)/p(3))
koyt=float(p(0)/p(3))


;xtrans
;For this use
;kt to fit xt
;k0 to fit xo
xtrans_tot=abs(total((y1-p(3)*(((x+(koxt^a)*.17)/p(5))^b*$
	          (5e-7/(x+(koxt^a)*.17))^2))^2))
;xlong
;For this use
;w*kl to fit xl
;w*k0 to fit x0
xlong_tot=abs(total((y2-p(1)*p(2)*(((x+(koxl^a)*.17)/p(5))^b*$
                  (5e-7/(x+(koxl^a)*.17))^2))^2))
;ytrans
;For this use
;w*kt to fit yt
;w*k0 to fit y0
ytrans_tot=abs(total((y3-p(1)*p(3)*(((x+(koyt^a)*.17)/p(5))^b*$
                  (5e-7/(x+(koyt^a)*.17))^2))^2))

;ylong
;For this use
;kl to fit yl
;k0 to fit y0
ylong_tot=abs(total((y4-p(2)*(((x+(koyl^a)*.17)/p(5))^b*$
                  (5e-7/(x+(koyl^a)*.17))^2))^2))

print,((ylong_tot+ytrans_tot+xlong_tot+xtrans_tot))
return,((ylong_tot+ytrans_tot+xlong_tot+xtrans_tot))

end

