% get the argos data that has been dwnloaded vial lftp
% this one just does stratus 10 - stratus 9 is now dead!

addpath([matlabroot '/work/ships'])
set_up
dv=datevec(now); this_year=dv(1);
day1=datenum(this_year,1,0);
if ~exist('minx','var'), minx=0.0; end
if ~exist('maxx','var'), maxx=1000.0; end
fprintf('get_Argos: minx %.1f maxx %.1f\', minx, maxx);

% if the processed file is file is fresh, you're done
rfdir=dir('incoming/sys.mat');
rawfdate= rfdir.datenum;
pfdir=dir('Argos.mat');
procfdate=pfdir.datenum;
if rawfdate > procfdate
    % give it a minute in case its being written?
    pause(60)
    fprintf('\nfound new argos data\n');

    %% load  10 ; correct yearday for year offset
    % stratus 10
    load incoming/sys.mat
    doffset=day1 - datenum(start_year,1,0);
    if doffset > 0,
        fprintf('unwrapping argos day s10sys.mat by %.2f days\n', doffset);
    end
    imet_1=sys1;  clear sys3;
    imet_1(:,1)=imet_1(:,1)-doffset;
    imet_2=sys2;  clear sys2;
    imet_2(:,1)=imet_2(:,1)-doffset;

    % get structures

    sys1=argos_to_vars(imet_1,minx,maxx);
    if isstruct(sys1)
        %         savecmd=[savecmd 'sys1 '];
    else
        fprintf('not saving sys1\n');
    end
    sys2=argos_to_vars(imet_2,minx,maxx);
    if isstruct(sys2)
        %         savecmd=[savecmd 'sys2 '];
    else
        fprintf('not saving sys2\n');
    end

    save Argos.mat sys1 sys2
end
