function compute_lmg_wshf5m
% compute_lmg_wshf5m computes 5-min wind
% stress and heat flux time series using 
% the 5-min basic data in lmg_met5m for
% LMG03-02.  
% 2/28/03

load lmg_met5m

% lmg sensor heights
zr=29;zt=zr;zq=zr; 
d2r=pi./180;

% compute air-sea fluxes
A=hfbulktc(ws,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=2003*ones(size(t));
lat=y;long=-x; %west is positive,east is negative
[qsw,alb]=swhf(t-1,yr,long,lat,sw);
[sunalt,sorad]=soradna1(t-1,2003,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;

MHA=1;
if MHA==1;
   % create 1-hr averaged data
   B=[t qnet qsw qlw qsen qlat tx ty];
   Ba=boxave(B,1,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 lmg_wshf1h  ta qneta qswa qlwa qsena qlata txa tya stressa wda
end

% save back in lmg_met5m
save bob1 qnet qsw qlw qlat qsen stress tx ty sunalt sorad

clear
load lmg_met5m
load bob1
save lmg_met5m
delete bob1.mat
