asetup
set(0, 'defaulttextinterpreter', 'none')
mvec_scale = 35;
topo_clev = [-9000:500:0];  % Topography contour levels.

% set for this application
config.ddrange        =    5;         %number of ddays to get data
config.os_cutoff = 1;
%check values in aflagit_setup for your cruise.
aflagit_setup

load auto_refsm
load adcpllt

stable_cutoff = .2;      % for on-station: low jitter
cleaner_threshold = 1;
cleaner_runs = 10;
%closeraw_cutoff = 5; %cm/s        for u and v
%closediff_cutoff = 10 ;   %cm/s  - for ddu and ddv
closetime_cutoff = 2.5*5; % 3.5 * ensemble time
%boxfilt_length = 5;
%uvdiff_scale = 20;  


%%%%%

start_dd = config.start_dd;
for dd = start_dd: config.ddrange : config.end_dd

   config.start_dd = dd;
   
   [data, config] = agetmat(config);
   flagged = aflagit(data, config, pfc);

   dtfm = ones(size(flagged));    %ones where good
   dtfm(find(flagged ~= 0)) = NaN;  %nans where bad

   %dot-multiply flag mask
   dtfm = ones(size(flagged));    %ones where good
   dtfm(find(flagged ~= 0)) = NaN;  %nans where bad
   
   rlbins = config.rl_range(1) : config.rl_range(2);
   okrefli = find(~isnan(sum(dtfm(rlbins,:))));
   okosi = find(data.clmps(okrefli) < config.os_cutoff);
   okosi = okrefli(okosi);

   figure(3);whitebg(gcf,'w');clf
   ajitter_bias
   
   figure(4);whitebg(gcf,'w');clf
   ajitter_topo
   
   
   paused
end

