% go_etl for stratus
% look at L for new files (get) - etl_files copies to local
%    etl raw files on  L: which is \\ps3das04\Data -group psd3
% maybe want to skip last file (hour) and may need to check
% at nidnight for end of yesterday's files
% if new files copied over, process me1,me2 with get_etl
set_up
if exist('etl.mat','file')
    load etl.mat
else
    etl=[];
end

nfn=get_etl_files(etldir);
fprintf('got %d new files \n',nfn);
if nfn > 0
    newfiles=dir('data/etl/new/me1*.txt');
    for iiif = 1:length(newfiles),
        fname=newfiles(iiif).name;
        % fname like me101109112_raw.txt
        % file_date  123456789 12345 fname(3:11)
        file_date=fname(4:11);
        indir='data/etl/new/' ;
        fprintf('%d %s  ',iiif, file_date);
        
        %% now get the data from this file
        newetl=get_etl(indir,file_date);
        if exist('etl','var') && isstruct(etl)
            if isstruct(newetl)
                if isfield(newetl,'swr')
                  etl=structsadd(etl,newetl);
                end
            end
        else
            if isstruct(newetl)
                etl=newetl;
            end
        end
        save etl.mat etl
        load etl.mat
    end
    if ~issorted(etl.mday)
        [mday,edx]=sort(etl.mday);
        structsort(etl, edx);
    end
    save etl.mat etl
    etl=get_str_avg(etl);
    save etl1h.mat etl
end
try
   movefile( 'data/etl/new/*','data/etl/read');
catch
    disp('not moving any files');
end
% % now sort (unique) all the fields
%
% [jjyday,kx,j]=unique(etl.mday); clear j jjyday
%
%
% % keyboard
%
% % [etl_s] = structsort(etl, kx);
% % save etl_sorted.mat etl
% %
% % disp('saved etl_sorted.mat')
%

