%exploring windstress curl differences, i.e., ekman upwelling (with and without eddies)

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

 for i=1:length(D)
  %load data
   ncload(['/Volumes/scratch/baedw/data/mod/ref/out/forcing/' D(i).name]);
   ref=ekman_we*86400;
   ncload(['/Volumes/scratch/baedw/data/mod/noed/out/forcing/' D(i).name]);
   noed=ekman_we*86400;
  %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/Dekm.mat DMLD REF NOED DMLDa REFa NOEDa x y t
else
 load ../data/processed/both/Dekm.mat
end
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','xlim',[1 length(DMLDa)])
   plot(DMLDa,'k','linewidth',1.5)
   xlabel('days')
   ylabel('\Delta MLD [K]')
   print -depsc ../ps/dEKM_ancy.eps

% climatological monthly sst differences (REF - noED) + => eddies warm || - => eddies cool
  draw_diffsst(x,y,DMLD(7,:,:),[-0.2:0.025:0.2],'July',[12.5 max(x(:))],[min(y(:)) max(y(:))],0)
  print -depsc -r300 ../ps/dEKM_jul.eps


  draw_diffsst(x,y,DMLD(11,:,:),[-0.2:0.025:0.2],'November',[12.5 max(x(:))],[min(y(:)) max(y(:))],0)
  print -depsc -r300 ../ps/dEKM_nov.eps


 xlim = [12.75 14.5];
 ylim = [55.15 55.5];
  draw_diffek(x,y,DMLD(7,:,:),[-0.2:0.025:0.2],' ',[12.75 14.5],[55.15 55.5],2)
  print -depsc -r300 ../ps/dEKM_sw_jul.eps
  print -dtiff -r500 ../ps/dEKM_sw_jul.tiff


