% mk_mat_inj.m - make flat ascii files of EDDIES inject

% Scan  Julian_Date   Lat      Lon PUMP1: Time Prod SpdSet RPM P1
% P2 P1-P2  PUMP2: Time Prod SpdSet RPM P1 P2 P1-P2


cast=3;

% build path and file name 
cast_str=int2str(cast);
if cast < 10
  cast_str=['00',cast_str];
elseif cast < 100
  cast_str=['0',cast_str];
end

asc_path=['/mnt/oc415-2a/oc415_2/ctd/INJ',cast_str,'/'];
mat_path=['.'];

% load in the pieces of the cast from the various files a,b,c, etc.
if cast == 3
  file_ltr = ['A','B','C','D','E','F','G','H','I','J','K','L'];
end

fn=['INJ_',cast_str];

data=[];
for ii = 1:length(file_ltr),
  eval(['!tail +2 ',asc_path,fn,file_ltr(ii),'.LOW > xxx'])
  %eval(['load ',asc_path,fn,file_ltr(ii),'.CAL'])
  load xxx
  %eval(['temp=',fn,file_ltr(ii),';'])
  %data = [data' temp']';
  data = [data' xxx']';
end

keyboard
if 0
  % here want to id by hand the indices of up/down/flight
  % setup info for this cast
  if cast == 999
    % sample
    ind_down = [1:22722];          % downcast
    ind_up = [24975:length(data)]; % upcast
    ind_fl = [22723:24975];
  elseif cast == 3
    % inject cast
    ind_down = [1:1062];          % downcast
    ind_up = [40631:length(data)]; % upcast
    ind_fl = [1063:40630];
  else
    disp(['set up indices for cast',cast_str])
    keyboard
  end
else
  sc_low=data(:,1);
  clear spd_1 spd_2 lat lon
  for ii = 107:4062
    aa=find(sc_low(ii) == scan);
    scan_low(aa:aa+9)=sc_low(ii);
    if ~isempty(aa)
      spd_1(aa:aa+9)=data(ii,7);
      spd_2(aa:aa+9)=data(ii,14);
      lat(aa:aa+9)=data(ii,3);
      lon(aa:aa+9)=data(ii,4);
    end
  end
  spd_1(end+1) = data(length(sc_low),7);
  spd_2(end+1) = data(length(sc_low),14);
  lat(end+1) = data(length(sc_low),3);
  lon(end+1) = data(length(sc_low),4);
  
  spd_1;spd_1';
  spd_2;spd_2';
  lat=lat';
  lon=lon';
end

save INJ_003_spd spd_1 spd_2 lat lon



