% assumes header line is removed from .txt file and renamed "z440XX.dat"
yr=input('Enter year (2-digits):');
by=input('Enter buoy (2-digits):','s');
eval(['load /data5/jmanning/wind/rtda/z440',by,'h19',num2str(yr),'.dat']);
eval(['w=z440',by,'h19',num2str(yr),';']);
k=0;
skip=1;
disp('WARNING: wind.txt files sometimes come with minutes col');
disp('WARNING: anemometer hgt is hardcoded to 5m');
for i=1:skip:length(w);
%  if w(i,6)~=999;
  if w(i,5)~=999;
    k=k+1;
%    yd(k)=julian(w(i,2),w(i,3),w(i,1),w(i,4)*100+w(i,5));
    yd(k)=julian(w(i,2),w(i,3),w(i,1),w(i,4)*100);
%    [u(k),v(k)]=sd2uv(w(i,7),w(i,6));
    [u(k),v(k)]=sd2uv(w(i,6),w(i,5));
    u(k)=u(k)*(-1);
    v(k)=v(k)*(-1);
    [taux(k),tauy(k)]=wstr(u(k),v(k),5);
  end;
end;

y=[yd;taux;tauy; u; v]';
[ydn,id]=sort(y(:,1));
y=y(id,:);
save wind.dat y -ascii

t=yd;
y=[u; v]';
[ydn,id]=sort(t);
t=t(id);
y=y(id,:);
eval(['save /data5/jmanning/wind/rtda/b',by,num2str(yr),' t y']);
t=t';taux=taux(id)';tauy=tauy(id)';
eval(['save /data5/jmanning/wind/rtda/b',by,num2str(yr),'ws t taux tauy;']);
