disp('fix_conv')
%load C:\temp\finsnake.prn


%x=[4.5 0 29.2 27.6 24.8 18.1 203 413 0 600 1010 15 15 15];
n=icount-1;
y=zeros(n,21);
clear u_f;clear u10n_f;clear taub_f;clear taui_f;clear tauc_f;clear gust_f;
tims=dt(:,1);%time in big file
jday=tims;
us=eyes(:,6);%ship speed
ts=dt(:,4);%sea surf temp
t=dt(:,5);%air temp
qs=dt(:,6);%sea surf spec hum
q=dt(:,7);%air spec hum
rs=dt(:,8);%downward solar flux
rl=dt(:,9);%downward longwave flux
rain=dt(:,10);%rain rate (partial record)
%zi=finsnake(:,11);%height of inversion (assumed)
%p=finsnake(:,12);%atmos pressure
zu=dt(:,38);%height of anemmometer
zt=zu;%finsnake(:,14);%height of slow temp sensor
zq=zu;%finsnake(:,15);%height of mean humidity sensor
tsb=dt(:,4);%sea surf temp
tauc=dt(:,37);%covariance stress
tauc=sign(tauc).*min(abs(tauc),9.99);
tauc=max(-.05,tauc);
hsc=dt(:,35);%covariance sensible heat
hlc=dt(:,36);%covariance latent heat 
hlc=sign(hlc).*min(abs(hlc),999);
hlc=max(-20,hlc);
taui=Hi(:,3);
hsi=Hi(:,1);
hli=Hi(:,2);
taui=sign(taui).*min(abs(taui),9.99);
hli=sign(hli).*min(abs(hli),999);
hsi=sign(hsi).*min(abs(hsi),999);
rhoar=P*100./(Rgas*(t+tdk).*(1+0.61*q/1000));

reldir=eyes(:,5);
u=dt(:,2);
hs=dt(:,11);
hl=dt(:,12);
tau=dt(:,13);
wtv=hs./rhoar/cpa+.61*hl/Le./rhoar.*(t+tdk);
spd=sqrt(u.^2+1.56*(grav./(t+tdk).*abs(wtv)*600).^.667);
u10n=u+dt(:,18)/.4.*(log(10./zu)+psiug(zu./dt(:,17)));
un=u+dt(:,18)/.4.*(psiug(zu./dt(:,17)));
spd10n=spd+dt(:,18)/.4.*(log(10./zu)+psiug(zu./dt(:,17)));
visa=1.325e-5*(1+6.542e-3*t+8.301e-6*t.*t-4.8e-9*t.*t.*t);
gust=spd./u;

%recompute flux time series, create edited dataset
j=1;
k=1;
kk=1;
relmax=300;
for i=1:n
%   x=[ut(i) 0 ts(i) t(i) qs(i) q(i) rs(i) rl(i) rain(i) zi(i) p(i) zu(i) zt(i) zq(i)];
 %  yy=coul_lkb(x);
   %     y=[hsb hlb tau zo zot zoq L usr tsr qsr dter dqer tkt RF hl_webb Cd Ch Ce Cdn_10 Chn_10 Cen_10];   
   %         1    2   3  4  5   6  7  8   9   10  11   12   13 14   15    16 17 18  19       20    21 
   
   
   %build filtered data set
   if zu(i)==11
      relmax=200;
   end;
   
      
   if us(i)<2%shipspeed less than 2 m/s
      if reldir(i)<60 | reldir(i) >relmax %rel wind direct +- 60 of bow
         if eyes(i,1)<1 %ship motion corrections 
            if rain(i)<1   %rainrate 
               if abs(tauc(i)-taui(i))<.07
               	if eyes(i,4)<3    %motion
            tim_f(k)=jday(i);
            u_f(k)=u(i);
            u10n_f(k)=u10n(i);
            spd10n_f(k)=spd10n(i);
            gust_f(k)=gust(i);
            tauc_f(k)=tauc(i);
         	taub_f(k)=tau(i);
         	hsc_f(k)=hsc(i);
         	hsb_f(k)=hs(i);
         	hlc_f(k)=hlc(i);
            hlb_f(k)=hl(i);
            taui_f(k)=taui(i);
            tauij_f(k)=Hi_j(i,1);
            hsi_f(k)=hsi(i);
            hli_f(k)=hli(i);
            rhoar_f(k)=rhoar(i);
            if eyes(i,2)<20 
               tim_ff(kk)=tims(i);
               hlc_ff(kk)=hlc(i);
               hlb_ff(kk)=hl(i);
               hli_ff(kk)=hli(i);
               u_ff(kk)=u(i);
               u10n_ff(kk)=u10n(i);
               qs_ff(kk)=qs(i);
               q_ff(kk)=q(i);
               ts_ff(kk)=ts(i);
               t_ff(kk)=t(i);
               rhoar_ff(kk)=rhoar(i);
               kk=kk+1;
            end;
            k=k+1;
            end;%end q
            end;%end tauc
            end;%end rain
      	end;   
      end;%end if reldir
   end;%end if us
   
end;%end for i
m=k-1;
figure;plot(taub_f(1:m),taub_f(1:m),taub_f(1:m),tauc_f(1:m),'.');axis([0 .4 -.1 .4]);xlabel('Bulk Stress (N/m^2)');ylabel('Cov Stess (N/m^2)')
figure;plot(taub_f(1:m),taub_f(1:m),taub_f(1:m),tauij_f(1:m),'.');axis([0 .4 -.1 .4]);xlabel('Bulk Stress (N/m^2)');ylabel('ID Stess (N/m^2)')

   