
cast = 5
mat_path = '/mnt/oc415-4a/oc415_4/ctd/process/';
if cast <10
  fn = ['oc41540',int2str(cast)];
elseif cast <100
  fn = ['oc4154',int2str(cast)];
end

eval(['load ',mat_path,fn])
sigma = sw_pden(s0,t0,press,0);

if cast == 1
  depths = [140 100 80];
elseif cast == 3
  %depths = [500 850 1000];
  % problem is max pressure is 970. Varies by 20dbar during
  % sampling! Should be 10m above this?
  depths = [500 850 960];
elseif cast == 5

  depths = [20 60 200];
else
  error('set depths for this cast')
end

fid=fopen([mat_path,fn,'_fe.txt'],'w');
fprintf(fid,'\n');
fprintf(fid,'\n');
fprintf(fid,'\n');
fprintf(fid,['    ',fn]);
fprintf(fid,'\n');
fprintf(fid,'\n');
fprintf(fid,['    Depth   Sal_min  Sal_max   Temp_min  Temp_max   Sig_min' ...
	     '   Sig_max\n']);
fprintf(fid,['    -------------------------------------------------------', ...
	     '-----------\n']);

for ii = 1:length(depths)
  aa=find(press>=depths(ii)-.5 & press<= depths(ii)+.5);
  
  smin(ii) = min(s0(aa));
  tmin(ii) = min(t0(aa));
  sigmin(ii) = min(sigma(aa));
  smax(ii) = min(s0(aa));
  tmax(ii) = min(t0(aa));
  sigmax(ii) = min(sigma(aa));
  
  fprintf(fid,'    %3d    %f %f %f %f %f %f\n',depths(ii),smin(ii), ...
	  smax(ii),tmin(ii),tmax(ii),sigmin(ii),sigmax(ii));
end

fclose(fid);