pingpath = '../raw/adcp_pings';
filelist = dirs(fullfile(pingpath, '*.raw'));

cfg.time_path =      '../gbinfiles/time';
cfg.position_path =  '../gbinfiles/pcode';
cfg.ashtech_path =   '../gbinfiles/adu2';
cfg.gyro_path =      '../gbinfiles/gyro';
cfg.sound_path =      '../gbinfiles/sndspd';

cfg.time_ext =      'tim';
cfg.position_ext =  'pos';
cfg.ashtech_ext =   'adu';
cfg.gyro_ext =      'hdg';
cfg.sound_ext =     'spd';


dirtype = {'time', 'position', 'ashtech', 'gyro', 'sound'};

finfo = cell(1,6);

count = 1;
for filei = 1:length(filelist)
   count
   fname = filelist(filei).name;
   rawfilebase = [fname(1:end-4)];
   finfo{count,1} =  rawfilebase;

   for typei = 1:length(dirtype)
      eval(sprintf('bpath = cfg.%s_path;', dirtype{typei}))
      eval(sprintf('bext = cfg.%s_ext;', dirtype{typei}))      
      eval(sprintf('file = ''%s/%s.%s.gbin'';', bpath, rawfilebase, bext))
      bindata = read_bin(file);      
      finfo{count,typei + 1} = length(bindata(1,:));
   end
   count = count+1;
end


clg
colors = 'rgbky';
for typei = 1:5
   array = NaN*ones(length(finfo(:,1)),1);
   for ii=1:length(finfo(:,1))
      array(ii) = finfo{ii,typei+1};
   end
   eval(sprintf('array%d = array;', typei))
end

maxarray = max([array1 array2 array3 array4 array5]')';

for typei = 1:5
   eval(sprintf('array = array%d;', typei))
   badi = find(maxarray > array);
   if (~isempty(badi))
      for filei = 1:length(badi)
         eval(sprintf('bpath = cfg.%s_path;', dirtype{typei}))
         eval(sprintf('bext = cfg.%s_ext;', dirtype{typei}))      
         fname = filelist(badi(filei)).name;
         rawfilebase = [fname(1:end-4)];
         eval(sprintf('file = ''%s/%s.%s.gbin'';', bpath, rawfilebase, bext))
         fprintf('need to redo %s\n',file)
      end
   end
end
