

   clear all; close all;

   addpath ./utils

   config='peru12_nemo';
   name='p12n_bdy_tr12n_quik';
   time='time_average_1mo';
   grid='roms12nemo';
   rep='20030101_20031231';
   dirfile=['/loceanfs/pulsation/cholod/' config '/outputs/' name '/' rep '/'];
   temp='thetao';
   season=1;  % bidon

   grd=rnt_gridload_xa(grid);

   MfiletCARS='/loceanfs/pulsation/cholod/data/CARS/cars_mon_clim_MEAN_PERU12.nc';
   ctlMtCARS=rnt_timectl({MfiletCARS}, 'time_counter');

   MfiletCARS2='/loceanfs/pulsation/cholod/data/CARS/cars_clim_ann_woaformat_PERU12.nc';
   ctlMtCARS2=rnt_timectl({MfiletCARS2}, 'time_counter');

   MfiletLEVITUS='/loceanfs/pulsation/cholod/data/LEVITUS/levitus_annual_mean_PERU12.nc';
   ctlMtLEVITUS=rnt_timectl({MfiletLEVITUS}, 'time_counter');

   Mfileu=[dirfile name '_1s_' rep '_grid_U_3D.nc']
   Mfilev=[dirfile name '_1s_' rep '_grid_V_3D.nc']
   ctlMu=rnt_timectl({Mfileu}, time);
   ctlMv=rnt_timectl({Mfilev}, time);
   
   figname=['peru_OBS_Climato'];
   vname='r2v';  prename='along_'; dist=3e5;
   colaxis=[-0.1 0.1];  
   latpm=3;
   latsec=-10;
   %%latsec=[-10 -25 -31 ];
   
   nc=netcdf(MfiletCARS,'r');
   zl=-1*nc{'deptht'}(:);
   close(nc);
   NN=length(zl);


   for k=1:length(latsec)
      latmin=latsec(k)-latpm; latmax=latsec(k)+latpm;
      [MTempCARS,Mmask,Mh,distx]=get_section_meanlongshore_nemo(grd,ctlMu,ctlMv,ctlMtCARS,temp,season,dist,latmin,latmax,NN);
      [MTempCARS2,Mmask,Mh,distx]=get_section_meanlongshore_nemo(grd,ctlMu,ctlMv,ctlMtCARS2,temp,season,dist,latmin,latmax,NN);
      [MTempLEVITUS,Mmask,Mh,distx]=get_section_meanlongshore_nemo(grd,ctlMu,ctlMv,ctlMtLEVITUS,temp,season,dist,latmin,latmax,NN);
      
% plot temperature profondeur 0-300m 
      minmax=3;
      division=0.25;
      Tmin=8; Tmax=22; Tinc=1;
      figure(1);
      plot(distx/1000,-Mh,'k');
      [ctt,htt]=contourf(distx/1000,zl,MTempCARS-MTempLEVITUS,[-minmax:division:minmax]);
      shading flat;
      hold on
%     contour(distx/1000,zl,MTempCARS-MTempLEVITUS,[-minmax:division:minmax]);

      [cttCARS,httCARS]=contour(distx/1000,zl,MTempCARS,[Tmin:Tinc:Tmax]); set(httCARS,'LineColor',[1.0 0.0 0.0]);
      clabel(cttCARS,httCARS,'FontS',12,'LabelSpacing',300,'Color',[1.0 0.0 0.0]);
      [cttCARS2,httCARS2]=contour(distx/1000,zl,MTempCARS2,[Tmin:Tinc:Tmax]); set(httCARS2,'LineColor',[0.0 1.0 0.0]);
      clabel(cttCARS2,httCARS2,'FontS',12,'LabelSpacing',300,'Color',[0.0 1.0 0.0]);
      [cttLEVITUS,httLEVITUS]=contour(distx/1000,zl,MTempLEVITUS,[Tmin:Tinc:Tmax]); set(httLEVITUS,'LineColor',[0.0 0.0 1.0]);
      clabel(cttLEVITUS,httLEVITUS,'FontS',12,'LabelSpacing',300,'Color',[0.0 0.0 1.0]);

      axis([-250 0 -300 0]);
      caxis([-minmax minmax]); 
      ncolor=minmax*2/division;
      cc=colormap(redblue(ncolor+2));
      borne=minmax/division;
      cc1=cc(1:borne,:);
      cc2=cc(borne+3:end,:);
      ccc=vertcat(cc1,cc2);
      colormap(ccc);
      hy=ylabel('Depth [m]'); set(hy,'FontS',12); hx=xlabel('Distance [km]'); set(hx,'FontS',12);
      set(gca,'FontS',12); set(gca,'PlotBoxAspectRatio',[0.7 1 1]); wysiwyg; box on;
      legend('CARSmon-LEVITUS','CARSmon','CARSann','LEVITUS','Location','eastoutside','Orientation','vertical') 
      title('Climato Temperature (C)', 'FontSize',12);
            
      figname2=[prename figname '_lat' num2str(latsec(k)) '_0-300m'];
      print ('-dpng',figname2);
         

% plot temperature 75 niveaux 
      Tmin=0; Tmax=22; Tinc=1;
      layers=[1:75];
      figure(2);
      [ctt,htt]=contourf(distx/1000,layers,MTempCARS2-MTempLEVITUS,[-minmax:division:minmax]);
      shading flat;
      hold on

      [cttCARS,httCARS]=contour(distx/1000,layers,MTempCARS,[Tmin:Tinc:Tmax]); set(httCARS,'LineColor',[1.0 0.0 0.0]);
      clabel(cttCARS,httCARS,'FontS',12,'LabelSpacing',300,'Color',[1.0 0.0 0.0]);
      [cttCARS2,httCARS2]=contour(distx/1000,layers,MTempCARS2,[Tmin:Tinc:Tmax]); set(httCARS2,'LineColor',[0.0 1.0 0.0]);
      clabel(cttCARS2,httCARS2,'FontS',12,'LabelSpacing',300,'Color',[0.0 1.0 0.0]);
      [cttLEVITUS,httLEVITUS]=contour(distx/1000,layers,MTempLEVITUS,[Tmin:Tinc:Tmax]); set(httLEVITUS,'LineColor',[0.0 0.0 1.0]);
      clabel(cttLEVITUS,httLEVITUS,'FontS',12,'LabelSpacing',300,'Color',[0.0 0.0 1.0]);

      set (gca,'YDir','reverse')
      caxis([-minmax minmax]); 
      ncolor=minmax*2/division;
      cc=colormap(redblue(ncolor+2));
      borne=minmax/division;
      cc1=cc(1:borne,:);
      cc2=cc(borne+3:end,:);
      ccc=vertcat(cc1,cc2);
      colormap(ccc);
      hy=ylabel('Layers'); set(hy,'FontS',12); hx=xlabel('Distance [km]'); set(hx,'FontS',12);
      set(gca,'FontS',12); set(gca,'PlotBoxAspectRatio',[0.7 1 1]); wysiwyg; box on;
      legend('CARSann-LEVITUS','CARSmon','CARSann','LEVITUS','Location','eastoutside','Orientation','vertical') 
      title('Climato Temperature (C)', 'FontSize',12);
            
      figname2=[prename figname '_lat' num2str(latsec(k)) '_L75'];
      print ('-dpng',figname2);
         
   end  % end of latsec loop
   

