function read_lmg_met1m(yd)
% read_lmg_met1m(yd) converts and separates 
% 1-min raw LMG JGOFS met data for yearday yd
% into MatLab variables. it also looks for 
% missing data gaps in time and fills with
% NaNs, since some gaps appear in LMG02-1A.
% jg0x.dat must first have /,: removed using
% textpad.  cleans spikes in sst
% 2/7/02

% get JGOFS data
if yd<100
   filnam=['jg0',int2str(yd),'.txt'];
   eval(['load ',filnam]);
   filnam=['jg0',int2str(yd)];
   eval(['zz=',filnam,';'])
end
if yd>=100
   filnam=['jg',int2str(yd),'.txt'];
   eval(['load ',filnam]);
   filnam=['jg',int2str(yd)];
   eval(['zz=',filnam,';'])
end

% compute raw time base
[N,M]=size(zz);
da=zz(:,1);mo=zz(:,2);yr=zz(:,3)+2000;
hr=zz(:,4);min=zz(:,5);sec=0*zz(:,6);
traw=julian([yr mo da hr min sec])-julian(2002,1,1,0)+1;
zz=[traw zz(:,7:M)];
[N,M]=size(zz);
disp(['size of gaps = ',int2str(1440-N)])

% check raw time base
dt=1/1440;
t=[yd:dt:yd+1-dt]';
if N==1440
   t=traw;
   zzn=zz;
end
if N<1440
   zzn=NaN*ones(1440,M);
   zzn(:,1)=t;
   for k=1:N
      err=1/(1440*10);
      tk=traw(k);
      m=find(t>tk-err & t<tk+err);
      zzn(m,2:M)=zz(k,2:M);
   end
end

% fill gaps if small or few enough
gf=input('enter 1 to fill NaN gaps, 0 to not fill');
if gf==1
   zzn=gapfil(zzn);
end

% separate variables
x=zzn(:,3);
y=zzn(:,2);
z=zzn(:,12);
sog=zzn(:,4);
gyro=zzn(:,6);
ws=zzn(:,13); % wind speed
wd=zzn(:,14); % wind direction met convention
at=zzn(:,15);
rh=zzn(:,16);
bp=zzn(:,17);
sopar=zzn(:,8);
sst=zzn(:,9); sst=clean_gould_sst(sst);
sss=zzn(:,11);
sw=zzn(:,20);
lw=zzn(:,21);
fluor=zzn(:,18);


% correct for system off on yd=49
if yd==49
   m=820:860;
   ws(m)=nan*ws(m);
   wd(m)=nan*wd(m);
   at(m)=nan*at(m);
   bp(m)=nan*bp(m);
   rh(m)=nan*rh(m);
   sw(m)=nan*sw(m);
   lw(m)=nan*lw(m);
   sopar(m)=nan*sopar(m);
end

% save 
eval(['save ',filnam,'a  fluor t x y z sog gyro ws wd at rh bp sopar sst sss sw lw'])
