
%run_alookit_raw
% 

% Jules 2000/11/27

% This program shows the effect of the editing paramters applied by  "aflagit.m"
% using the values in aflagit_setup.m - if you want to see your data without the
% editing applied, go down below and set config.flagged = 0*flagged

%run asetup.m; use those parameters; set more:


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

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


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


%%%% for ajitter_rsdiff
cleaner_threshold = 1;
cleaner_runs = 10;
closeraw_cutoff = 2; %cm/s
closediff_cutoff = .011 * 5; % like .015m/s   |urefl-usm|
closetime_cutoff = 2.5*5; % 3.5 * ensemble time
boxfilt_length = 5;
  
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);
   config.flagged = flagged;
   
   %find slow enough - for osi
   %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);

   %for jitter_rsdiff
   %for doublediff
   %m/s: d2uabs/dt2
   absddu = abs(diff(diff(data.uship_g + mstdgap(data.umeas(rlbins,:)))));
   absddu = [0 absddu 0]; %to give it the same timestamp
   absddv = abs(diff(diff(data.vship_g + mstdgap(data.vmeas(rlbins,:)))));
   absddv = [0 absddv 0]; %to give it the same timestampe
   
   uvdiff =  abs(absddu + i*absddv);
   
   closei_diff = find( boxfilt(uvdiff,boxfilt_length) < closediff_cutoff);
      
   %dot-multiply flag mask
   dtfm = ones(size(flagged));    %ones where good
   dtfm(find(flagged ~= 0)) = NaN;  %nans where bad
                                    %from alookit.m

   figure(1);whitebg(gcf,'w');clf
   alookit_raw

   figure(3)
   apuv(data, config, topo_clev, mvec_scale, pfc);  
   paused
   
end
