%must set up things as in run_aedit
%
%----------------------------------------------------------------------%

if (~isfield(config, 'prefix'))
   config.prefix = 'a_';
end


start_dd = config.start_dd;
ddrange = config.ddrange;
config.ddrange = config.ddrange + 2*dt;   %pad on each side by dt;

for dd = floor(start_dd): ddrange : floor(config.end_dd)+1
   config.start_dd = dd - dt;
   
   %now call 
   [data, config] = agetmat(config);
   
   if (~isempty(data))
      [flagged, pfc] = aflagit(data, config, pfc); %let aflagit update pfc

      pflags.yearbase = config.yearbase;
      pflags.dday = data.dday;
      pflags.flagged = flagged;
      pflags.flag = pfc.flag;
      
      fprintf('saving flags to %s%03d.mat\n', fileprefix, dd)
      eval(sprintf('save %s%03d.mat pflags',  fileprefix, dd))
   end
end

flagfiles = dir([fileprefix,'*.mat']);
alistit(flagfiles);


%prompt to apply editing
fprintf('NOW do the following\n')

dbname = sprintf('%s%s', config.dbpath, config.dbname);

fprintf('apply editing to database:\n\n')
fprintf('dbupdate %s abottom.asc >& edit.log\n', dbname)
fprintf('dbupdate %s abadprf.asc >>& edit.log\n', dbname)
fprintf('badbin   %s abadbin.asc >>& edit.log\n', dbname)
fprintf('set_lgb %s >>& edit.log\n', dbname)
fprintf('setflags setflags.cnt >>& edit.log\n')

%prompt to apply nav steps
fprintf('apply nav steps\n')
fprintf('cd ../nav\n')
fprintf('(should have already run ubprint)\n')
fprintf('ubprint        ubprint.cnt     >& nav.log\n')
fprintf('adcpsect       as_nav.cnt     >>& nav.log\n')
fprintf('refabs         refabs.cnt     >>& nav.log\n')
fprintf('smoothr        smoothr.cnt    >>& nav.log\n')
fprintf('putnav         putnav.cnt     >>& nav.log\n')
fprintf('cd ../edit\n')
fprintf(' ')
fprintf('... or if you ran quick_adcp.prl or newday.prl:\n');
fprintf('adcpsect as_nav.tmp; refabs  refabs.tmp; smoothr smoothr.tmp;  putnav         putnav.tmp\n');

