%exploring air-sea heat flux differences (with and without eddies)
% dheat = refHeatF - noedHeatF
% heatfluxes: positive values denote oceanic warming
%hence, negative values for dheat denote: Eddies lead to heat fluxes cooling the ocean
%       positive values for dheat denote: Eddies lead to heat fluxes warming the ocean 
%some ini
 addpath('funct')
  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=sfc_hflux_total;
   ncload(['/Volumes/scratch/baedw/data/mod/noed/out/forcing/' D(i).name]);
   noed=sfc_hflux_total;
  %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/Dheaf.mat DMLD REF NOED DMLDa REFa NOEDa x y t

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',[-10 10],'xlim',[1 length(DMLDa)])
   plot(DMLDa,'k','linewidth',1.5)
   xlabel('days')
   ylabel('\Delta Heat Flux [W/m^2]')
   print -depsc ../ps/dHEAF_ancy.eps

% climatological monthly sst differences (REF - noED) + => eddies warm || - => eddies cool
 figure 
  draw_diffsst(x,y,DMLD(7,:,:),[-10:1:10],'July',[12.5 max(x(:))],[min(y(:)) max(y(:))],2)
  print -depsc -r300 ../ps/dHEAF_jul.eps
  print -dtiff -r500 ../ps/dHEAF_jul.tiff

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



