
 namerun='cpl00';
%namerun='ERAI3';

 year='2007';
%year='1990';

 rep='20070101_20071231';
%year='19900101_19901231';

tsurf='tos';

%root_dir='/L1/cholod/NEMO/PERU12/'
%root_dir=['/net/adonis/usr/adonis/phybiocar/cholod/peru12_now/']
 root_dir=['/loceanfs/pulsation/cholod/peru12_now']

 fs=[root_dir '/outputs/' namerun '/' rep '/peru12_1d_' rep '_grid_T.' namerun '.nc']
%fs='/usr/temp/fclod/peru12_1d_1994_grid_T.erai3b.nc';

%fg=[root_dir '/inputs/data/mesh_mask_PERU12_L46.nc']
 fg=['/loceanfs/pulsation/cholod/peru12_nemo/inputs/grd/mesh_mask_PERU12_L46.nc']
%
nc=netcdf(fs,'r');
ng=netcdf(fg,'r');
mask=ng{'tmask'}(1,1,:,:);
mask(mask==0)=NaN;
lat=ng{'nav_lat'}(:);
lon=ng{'nav_lon'}(:);
%
%%% MAP gradient SST (last day) %%%
sst=nc{tsurf}(end,:,:);
[gx,gy]=gradient(sst);
Gnemo=sqrt(gx.^2+gy.^2);

opengl neverselect % pour pb cartes graphiques

%%%%%%%%
%% PDF
XX=[0:0.015:0.39]; mpdf=zeros(1,length(XX));
for i=1:10:361;
display(num2str(i));
sst=nc{tsurf}(i,:,:);
[gx,gy]=gradient(sst); Gnemo=sqrt(gx.^2+gy.^2);
GrN1=Gnemo(100:300,50:200); GrN1=reshape(GrN1,[1 size(GrN1,1)*size(GrN1,2)]); 
pdfN1=hist(GrN1,XX); 
mpdf=mpdf+pdfN1;
clear sst gx gy Gnemo GrN1 
end;
close(nc); close(ng); 
%%%%
%%%%% PLOT %%%%%
%%figure; hl=semilogx(XX,pdfN1./sum(pdfN1),'r'); hold on; set(hl,'LineW',2);
%
[p,s]=polyfit(XX(4:end-1),log(mpdf(4:end-1)/sum(mpdf)),1); coff=p(1);
%
figure; bar(XX,mpdf./sum(mpdf));
axis([0 0.35 0 0.3]);
set(gca,'FontS',12); grid on;
xlabel('\nabla(SST) (°C)')
%title([namerun ' - ' year ' - PDF - \nabla(SST)']);
title(['PDF \nabla(SST) (°C) - ' namerun ' (mean ' year ')'], 'FontSize',16);
text(0.2,0.25,num2str(coff),'FontS',15);

figname2=['sst_grad_pdf_year_' namerun '_' year]
print ('-dpng',figname2);
%%%%

quit
