function compute_lmg_wshf1m
% compute_lmg_wshf5m computes 1-min wind
% stress and heat flux time series using 
% the 1-min basic data in cruise_met for
% lmg02-1A.  also makes 1-hr averaged 
% series.
% 2/28/02; 3/1/02

clear
clf
load cruise_met

% fill small nan gap
lw=gapfil(lw);
bp=gapfil(bp);
sst=gapfil(sst);
rh=gapfil(rh);
at=gapfil(at);


% fill wind speed and direction gap
d2r=pi./180;
u=ws.*cos(d2r.*wd); % wd is wdr in lmg_met1m
v=ws.*sin(d2r.*wd); % wd is ocean convention
u=gapfil(u);
v=gapfil(v);
wspeed=sqrt(u.^2+v.^2);
ws=wspeed;
wd=atan2(v,u)./d2r;

% lmg sensor heights
zr=29;zt=zr;zq=zr; 

% compute air-sea fluxes
A=hfbulktc(wspeed,zr,at,zt,rh,zq,bp,sst);
qsen=A(:,1);
qlat=A(:,2);
stress=A(:,4);
tx=stress.*cos(d2r.*wd);
ty=stress.*sin(d2r.*wd);
disp(['air-sea fluxes done'])

% compute sw flux
yr=2002*ones(size(t));
lat=y;long=-x; %west is positive,east is negative
% remove negative values
mm=find(swnf<0);swnf(mm)=0*swnf(mm);clear mm;
[qsw,alb]=swhf(t-1,yr,long,lat,swnf);
[sunalt,sorad]=soradna1(t-1,2002,long,lat);
disp(['shortwave flux is done'])

% compute lw
qlw=lwhf(sst,lw);
disp(['longwave flux is done'])
% net heat flux
qnet=qsw+qlw+qsen+qlat;

% create 1-hr averaged data
B=[t qnet qsw qlw qsen qlat tx ty];
Ba=boxave(B,19,60);
ta=Ba(:,1);qneta=Ba(:,2);qswa=Ba(:,3);qlwa=Ba(:,4);
qsena=Ba(:,5);qlata=Ba(:,6);txa=Ba(:,7);tya=Ba(:,8);
stressa=sqrt(txa.^2+tya.^2);
wda=atan2(tya,txa)./d2r;


% save back in cruise_met
save bob1 qnet qsw qlw qlat qsen stress tx ty sunalt sorad
save bob2 ta qneta qswa qlwa qsena qlata txa tya stressa wda
save bob3 lw bp sst rh at

clear
load cruise_met
load bob1
load bob2
load bob3
save cruise_met
delete bob1.mat bob2.mat bob3.mat
