clear all
close all

outDir = 'SeaHorseFiles';
files = dir([outDir '/*.Eng']);


for n = 1:length(files)
    files(n).name
    fid = fopen([outDir '/' files(n).name]);
  
  %Determine appropriate info from text of each file.
  BottomDepth = -1;
  while(BottomDepth<0)
     tline = fgets(fid);
     if(tline == -1)
         break
     end
     k = strfind(tline,'Depth at bottom =');
     if(k>0)
         BottomDepth = sscanf(tline(k+17:end),'%f');
     end
  end
  
  PeakCurrent = -1;
  while(PeakCurrent<0)
     tline = fgets(fid);
     if(tline == -1)
         break
     end
     k = strfind(tline,'Peak current:');
     if(k>0)
         PeakCurrent = sscanf(tline(k+13:end),'%f %*s');
     end
  end
  
  ReleaseTime = -1;
  while(ReleaseTime<0)
     tline = fgets(fid);
     if(tline == -1)
         break
     end
     k = strfind(tline,'Time:');
     if(k>0)
         ReleaseTime = datenum(tline(k+9:end));
     end
  end
  
  
  Battery = -1;
  while(Battery<0)
     tline = fgets(fid);
     if(tline == -1)
         break
     end
     k = strfind(tline,'Battery:');
     if(k>0)
         Battery = sscanf(tline(k+8:end),'%f');
     end
  end
  
  UpVel = -1;
  while(UpVel<0)
     tline = fgets(fid);
     if(tline == -1)
         break
     end
     k = strfind(tline,'Reached top of profile at');
     if(k>0)
        Rate = sscanf(tline(k+25:end),'%f %*s %*s %d');
        TopDepth = Rate(1);
        UpVel = (BottomDepth-TopDepth)/Rate(2);
     end
      k = strfind(tline,'Profile timed out on the way up at');
     if(k>0)
        Rate = sscanf(tline(k+34:end),'%f %*s %*s %d');
        TopDepth = Rate(1);
        UpVel = (BottomDepth-TopDepth)/Rate(2);
     end
  end
  
  CastData.BottomDepth(n) = BottomDepth;
  CastData.BottomPeakCurrent(n) = PeakCurrent;
  CastData.Battery(n) = Battery;
  CastData.ReleaseTime(n) = ReleaseTime;
  CastData.UpVel(n) = UpVel;
  CastData.TopDepth(n) = TopDepth;
 
   PeakCurrent = -1;
  while(PeakCurrent<0)
     tline = fgets(fid);
     if(tline == -1)
         break
     end
     k = strfind(tline,'Peak current:');
     if(k>0)
         PeakCurrent = sscanf(tline(k+13:end),'%f %*s');
     end
  end
  
  
  DownVel = -1;
  while(DownVel<0)
     tline = fgets(fid);
     if(tline == -1)
         break
     end
     k = strfind(tline,'Reached engineering depth cutoff at');
     if(k>0)
        Rate = sscanf(tline(k+35:end),'%f %*s %*s %d');
        DownVel = (Rate(1)-TopDepth)/Rate(2);
     end
     k = strfind(tline,'Profile timed out on the way down at');
     if(k>0)
        Rate = sscanf(tline(k+36:end),'%f %*s %*s %d');
        DownVel = (BottomDepth-Rate(1))/Rate(2);
     end
  end
  
  
  CastData.TopPeakCurrent(n) = PeakCurrent;
  CastData.DownVel(n) = DownVel;
  
  
  fclose(fid);
end


