% go_etl_flux
% Run manually, nce per day, when a new file appears
% e.g. K:\RHB\flux\Processed\STRATUS_2011_PSD_flux_5min_2011_04_04_094.txt
% this code will copy it to data/etl/proc/new, process, move to proc/read
%
set_up
etlfluxdir='K:\RHB\flux\Processed\';
localdir='data/etl_proc/';
if exist('etl_flux.mat','file')
    load etl_flux.mat
else
    flux=[];
end
nnewf=get_etl_flux_files(etlfluxdir,localdir);
fprintf('%d new files\n',nnewf);
if nnewf > 0
    infiles=dir('data/etl_proc/new/*flux_5min*.txt');
    if ~isempty(infiles)
        for iiff=1:length(infiles)
            infile=['data/etl_proc/new/' infiles(iiff).name ];
            [newflux] = get_etl_flux(infile,year);
            if isstruct(newflux)
                if isstruct(flux)
                    flux=structsadd(flux,newflux);
                else
                    flux=newflux;
                end
            else
                disp(['error in ' infile]);
            end
            [j,idx,j]=unique(flux.mday);
            flux = structsort(flux, idx);
            save etl_flux.mat flux
            try
                movefile( infile, [localdir 'read']);
            catch
                disp(['can  not move ' infile]);
            end
        end
    end
    if isstruct(flux)
        [j,idx,j]=unique(flux.mday);
        flux = structsort(flux, idx);
        save etl_flux.mat flux
        flux=rmfield(flux,'cog');
        flux=get_avg_wdirs(flux,'wspd_true', 'wdir_true');
        save etl_flux1h.mat flux
    end
end
