%exploring MLD differences (with and without eddies)
%dmld = ref-noed, hence
% positive dmld values denote: Eddies deepen MLD
% negative dmld values deonte: Eddies shallow MLD 

 addpath('funct')

if exist('../data/processed/both/mld_max.mat')~=2
%some ini
  T=[]; n=0;
 D=dir('/Volumes/scratch/baedw/data/mod/noed/out/mld/*.nc');

 for i=1:length(D)
  %load data
   ncload(['/Volumes/scratch/baedw/data/mod/ref/out/mld/' D(i).name]);
   ref=hblt_max;
   ncload(['/Volumes/scratch/baedw/data/mod/noed/out/mld/' D(i).name]);
   noed=hblt_max;
  %axis information
   t = get_calendar_date((time./24)  + get_julian_day(1987,1,1,0));
   T = [T; t];
   x=xt_ocean; clear xt_ocean;
   y=yt_ocean; clear yt_ocean;
   I=find(ref<-1e10); ref(I)=NaN; noed(I)=NaN;
  %calculations
   dmld = ref-noed;;
   for l=1:length(t)
    n=n+1;;
    tmp = dmld(l,:,:);   DMLDa(n)   = meannan(tmp(:));
    tmp = ref(l,:,:);     REFa(n)   = meannan(tmp(:));
    tmp = noed(l,:,:);    NOEDa(n)  = meannan(tmp(:));
   end
  %some late ini
    if i==1
     DMLD = zeros(12,length(y),length(x)); REF=DMLD; NOED=DMLD;
    end
   %more calculations
    mo=t(1,2);
    DMLD(mo,:,:)  = DMLD(mo,:,:)  + mean(dmld(:,:,:));
    REF(mo,:,:)   = REF(mo,:,:)   + mean(ref(:,:,:));
    NOED(mo,:,:)  = NOED(mo,:,:)  + mean(noed(:,:,:));
 end

   %final calulations
    DMLD=DMLD./(length(D)./12);
    REF=REF./(length(D)./12);
    NOED=NOED./(length(D)./12);

save ../data/processed/both/mld_max.mat DMLD REF NOED DMLDa REFa NOEDa x y t
else
load ../data/processed/both/mld_max.mat DMLD REF NOED DMLDa REFa NOEDa x y t
end
%climatological MLD differences
display('plot')
  figure(1)
   subplot(2,1,1); set(gca,'box','on','linewidth',1.2,'tickdir','out','fontsize',12, ...
                           'xgrid','on','ygrid','on','nextplot','add','ylim',[-2 1],'xlim',[1 length(DMLDa)])
   plot(DMLDa,'k','linewidth',1.5)
   xlabel('days')
   ylabel('\Delta MLD [m]')
   print -depsc ../ps/dMLDmax_ancy.eps

 figure 
%  draw_diffsst(x,y,DMLD(7,:,:),[-1:0.1:1],'July',[12.5 max(x(:))],[min(y(:)) max(y(:))],0)
  draw_diffp(x,y,DMLD(7,:,:),[-1:0.1:1],'July',[12.5 max(x(:))],[min(y(:)) max(y(:))],2)
  print -depsc -r300 ../ps/dMLDmax_jul.eps
  print -dtiff -r500 ../ps/dMLDmax_jul.tiff

 figure
  draw_diffp(x,y,DMLD(11,:,:),[-10:1:10],'November',[12.5 max(x(:))],[min(y(:)) max(y(:))],2)
  print -depsc -r300 ../ps/dMLDmax_nov.eps
  print -dtiff -r500 ../ps/dMLDmax_nov.tiff

keyboard
%climatological MLD in run ref
  figure
   subplot(2,1,1); set(gca,'box','on','linewidth',1.2,'tickdir','out','fontsize',12, ...
                           'xgrid','on','ygrid','on','nextplot','add','ylim',[0 40],'xlim',[1 length(DMLDa)])
   plot(REFa,'k','linewidth',1.5)
   xlabel('days')
   ylabel('MLD [m]')
   print -depsc ../ps/REFMLDmax_ancy.eps

  draw_diffsst(x,y,REF(7,:,:),[0:1:15],'July',[12.5 max(x(:))],[min(y(:)) max(y(:))],0)
  print -depsc -r300 ../ps/REFMLDmax_jul.eps

  draw_diffsst(x,y,REF(3,:,:),[0:3:60],'November',[12.5 max(x(:))],[min(y(:)) max(y(:))],0)
  print -depsc -r300 ../ps/REFMLDmax_nov.eps



