% gen_mean prof.m - oc415-4 - generate a mean profile from Eddy
% center casts

mat_path='../process/';
%casts = [1 2 3 5 6 7 9 ];
casts = [2 3 5 6 7 9 12:17 19:21 ];

clear meant means

clf
for cast = casts
  disp(int2str(cast))
  if cast <10
    fn = ['doc41540',int2str(cast),'avg'];
  elseif cast <100
    fn = ['doc4154',int2str(cast),'avg'];
  end

  eval(['load ',mat_path,fn])
  %readhdr;
  
  
  %aa=find(press>=50 & press <=150);
  aa=find(press>=15 & press <=150);
  if cast == casts(1)
    meant=t0(aa);
    means=s0(aa);
  else
    meant=meant+t0(aa);
    means=means+s0(aa);
  end
  %plot(s0(aa),press(aa),'.')
  %plot(t0(aa),press(aa),'.')
  sig = sw_pden(s0(aa),t0(aa),press(aa),0);
  plot(sig-1000,press(aa),'.')
  
  if ~ishold, hold on; end
end

meant=meant/length(casts);
means=means/length(casts);

meansig = sw_pden(means,meant,press(aa),0);

return
subplot(1,3,1)
plot(means,press(aa))
axis ij
subplot(1,3,2)
plot(meant,press(aa))
axis ij
subplot(1,3,3)       
plot(meansig-1000,press(aa))
axis ij

diary meansig3
[press(aa) meansig-1000]
diary off               

pr=press(aa);
save ../process/mean_prof meant means meansig pr