function merge_lmg_met1mA
% merge_lmg_met1mA adds new daily JGOFS 
% data in jg0yda.mat up through last_yd to the 
% existing combined lmg_met1m.mat file. used
% on LMG03-2A
% modified by Irene Beardsley
% always start with yd 45
% modified to add last 4 days to existing lmg_met1m

load lmg_met1m

% make arrays
soparm=sopar;
tm=t;wsm=ws;wdm=wd;rhm=rh;atm=at;sstm=sst;
xm=x;ym=y;swm=sw;lwm=lw;sogm=sog;gyrom=gyro;
bpm=bp;zm=z;sssm=sss;fluorm=fluor;

first_yd=58;
last_yd=61;

for ydn=first_yd:last_yd;
   if ydn<10
      filnam=['jg00',int2str(ydn),'a'];
      eval(['load ',filnam]);
   end
   if (ydn<100) & (ydn>=10)
      filnam=['jg0',int2str(ydn),'a'];
      eval(['load ',filnam]);
   end
   if ydn>=100
      filnam=['jg',int2str(ydn),'a'];
      eval(['load ',filnam]);
   end
   tm=[tm;t];
   xm=[xm;x];
   ym=[ym;y];
   sogm=[sogm;sog];
   gyrom=[gyrom;gyro];
   zm=[zm;z];
   wsm=[wsm;ws];
   wdm=[wdm;wd];
   rhm=[rhm;rh];
   atm=[atm;at];
   sstm=[sstm;sst];
   bpm=[bpm;bp];
   swm=[swm;sw];
   lwm=[lwm;lw];
   soparm=[soparm;sopar];
   sssm=[sssm;sss];
   fluorm=[fluorm;fluor];
   disp(ydn)   
end

% rename
sopar=soparm;
t=tm;ws=wsm;wd=wdm;rh=rhm;at=atm;sst=sstm;
x=xm;y=ym;sw=swm;lw=lwm;sog=sogm;gyro=gyrom;
bp=bpm;z=zm;sss=sssm;fluor=fluorm;

% convert met to ocean wind convention and save
d2r=pi./180;
wdo=wd+180;
u=ws.*sin(d2r*wdo);
v=ws.*cos(d2r*wdo);
wdr=atan2(v,u)./d2r;

% sst=clean_gould_sst(sst);

save lmg_met1m sopar t u v  fluor wdr ws wd rh at sst x y sw lw sog gyro bp z sss 

