%  if exist('/Volumes/WORKGROUP;MUDI/
% copyfile ('/Volumes/WORKGROUP;DOGO/gps/gps.txt', 'gps.txt');
% stat=system('awk ''(NF ==11){print}'' gps.txt  | tail +9160 > gps.asc')
% if stat == 0, 
%     load gps.asc
dv=datevvec(now); year=dv(1); yearstr=num2str(year);

startday=datenum(year,10,1);
infile=['gps_' yearstr '.txt'] ;
%infile='data/etl/met00827919_raw.txt';
fid=fopen(infile,'rt');

%reads whole file into single cell
incellraw=textscan(fid, '%s', 'delimiter', '\n', ...
    'whitespace', '');
incell=incellraw{1};
npts = length(incell);
fnames={'year','month','day','hour','minu','sec','lat','lon','spd','cog','magvar'};
nvars=length(fnames);
%fprintf('processing %d points %d variables\n',npts,nvars);

% 2008 10 09 12 36 54 22.2736 -84.9324 6.8935 224.1000 -2.100
% 2008 10 09 12 37 54 22.2709 -84.9351 6.8935 222.7000 -2.100
% 2008 10 09 12 38 54 22.2682 -84.9379 6.8935 222.4000 -2.100
gpsarr=ones(npts,nvars)*NaN;
ox=0;
for inx=1:npts,
    mystr=incell{inx};
    nflds=length(findstr(mystr,' '))+1;
    if nflds == nvars,
        blah=sscanf(mystr,'%d %d %d %d %d %f %f %f %f %f');
         if blah(1)==2008,
             ox=ox+1;
             gpsarr(ox,:)=blah(:);
         %else            
         end
    end
end
gpsarr=gpsarr(1:ox,:);
gps=structfromarr(gpsarr,fnames);
fclose(infile)
gps.mday=datenum(gps.year, gps.month,gps.day,gps.hour, gps.minu,gps.sec);
iddx=find(gps.mday > startday);
save gps.mat gps


    
%         
%         
%     
%    
%     gv=find(yday > 100);
%     gps=gps(gv,:);
%     mday=datenum(gps(:,1:6));  lat=gps(:,7); lon=gps(:,8); 
%     speed=gps(:,9); cog=gps(:,9);
%     save gps.mat mday lat lon speed cog
% else
%     fprintf('error copying gps from dogo\n')
% end
% 
