
   clear all; close all;

   ys_fich=2003;
   ye_fich=2007;         

   exp(1).config='peru12_nemo';
%  exp(1).names={'p12n_bdy_tr12n_quik' 'p12n_bdy_soda2' 'p12n_bdy_soda2_B' 'erai70b' 'erai74c' 'p12n_bdy_tr12n_quik_ND' 'p12n_bdy_tr12n_quik_blp1'};   
%  exp(1).names={'erai70a' 'erai70b' 'erai70c' 'erai72c' 'erai73c' 'erai73c2' 'erai74c' 'erai75c'};
   exp(1).names={'p12n_bdy_tr12n_quik' 'p12n_bdy_soda2'};   

   exp(2).config='trop12_nemo/peru';
   exp(2).names={'tr12_quik' 'tr12_erainocrt' 'tr12n_n02' 'tr12n_n03'};

   exp(3).config='trop025peru12_nemo/peru';
   exp(3).names={'tr025p12_quik'};

   exp(4).config='/loceanfs/pulsation/cholod/data/TMI-AMSR-E/';
   exp(4).names={'TMI-AMSR-E_PERU12'};

   mini=17;
   maxi=28;

%ZOOM
%   x[210]-82.5 degrees_east	        x[210]-82.4583 degrees_east
%   x[288]-76 degrees_east	        x[288]-75.9583 degrees_east
%   y[214]=-13.5389 degrees_north	y[214]=-13.4984 degrees_north
%   y[299]=-6.5689 degrees_north	y[299]=-6.5275 degrees_north
   lonz1=210;
   lonz2=289;
   latz1=214;
   latz2=299;

% coordonnees des bords du zoom
   lon1 = -79.67;
   lat1 = -7.065;
   lon2 = -76.33;
   lat2 = -13.05;
   lon1b = -82.42;
   lon2b = -79.08;

   exp_dim=size(exp);
%  for ii = 1:exp_dim(2)
   for ii = 1:1                    % config
      config=exp(ii).config;
      names=exp(ii).names;
      names_dim=size(names);

%     for jj = 1:names_dim(2);     % names
      for jj = 1:1
         name=names{jj};
         name_title=regexprep(name,'_','\\_');
         disp([num2str(jj) ' : ' config ' : ' name]);
         rep_fich=[num2str(ys_fich) '0101_' num2str(ye_fich) '1231'];
         dur_plot=[num2str(ys_fich) '-' num2str(ye_fich)];
%        maskfile='/loceanfs/pulsation/cholod/peru12_nemo/inputs/grd/mesh_mask_peru12.L75_from_trop12.nc';
% Pour masker la mer des caraibes poru le calcul du min (eviter la valeur zero)
         maskfile='/loceanfs/pulsation/cholod/peru12_nemo/inputs/grd/mesh_mask_peru12.L75_from_trop12_mask_Caribbean.nc';
         if strcmp(name,'TMI-AMSR-E_PERU12')
            dir_in=config;
            filetos=[dir_in name '_' dur_plot '_mean.nc']
         else
            dir_in=['/loceanfs/pulsation/cholod/' config '/outputs/' name '/' rep_fich '/'];
            filetos=[dir_in name '_1s_' rep_fich '_grid_T_2D.nc']
         end


%%% coord et mask  de la grille
         ng=netcdf(maskfile,'r');
         lon=ng{'glamt'}(:);
         lat=ng{'gphit'}(:);
         mask=squeeze(ng{'tmask'}(:,1,:,:));
         mask(mask==0)=NaN;
         close(ng);

%%% Lecture tos
         nz=netcdf(filetos,'r'); 
         if ii == 4
            tos=nz{'sst'}(:,:);
         else
            tos=nz{'tos'}(5,:,:);
         end
         close(nz);

         mtos=tos(:,1:361).*mask(:,:);

%%%  Impression figure:
         sizefont1=12;sizefont2=12; 
         XX=14;YY=20; % pour figure même proportion que PlotBoxAspectRatio',[0.7 1 1]

%%%  Plot 1
         figure('Units','centimeters',...
               'Position',[1 1 XX YY],...
               'PaperPosition',[1 1 XX YY],...
               'PaperUnits','centimeters')

         pcolor(lon(:,1:361),lat(:,1:361),mtos(:,1:361)); shading flat;
% draw zoom
         line([lon1b lon1],[lat1 lat1],'color','k','LineWidth',1)
         line([lon2b lon2],[lat2 lat2],'color','k','LineWidth',1)
         line([lon1b lon2b],[lat1 lat2],'color','k','LineWidth',1)

         str_min=num2str(min(min(mtos(:,1:361))),'min %.1f');
         str_max=num2str(max(max(mtos(:,1:361))),'max %.1f');
         set(gca,'FontS',sizefont1); set(gca,'PlotBoxAspectRatio',[0.7 1 1]); box on;
         ylabel('Latitude','FontSize',sizefont1)
         xlabel('Longitude','FontSize',sizefont1)
         caxis ([mini maxi]); hcc=colorbar; set(hcc,'FontS',sizefont1);
         title(['sst (C)  ' dur_plot '  ' name_title ],'FontSize',sizefont2,'FontWeight','bold');
	 text(-70.5,10.3,['(',str_min,' , ',str_max,')'], 'HorizontalAlignment','right','VerticalAlignment','Top','FontSize',sizefont1);  
         text(-99.5,-30,[date], 'HorizontalAlignment','left','VerticalAlignment','bottom','FontSize',sizefont1);  
         figname1=['map_sst_mean_' name '_' dur_plot];
         print ('-depsc2','-painters',figname1)
         eval(['!convert -density 400 ',figname1,'.eps -resize 739x883 ',figname1,'.png'])
%        print ('-dpng',figname1)
         eval(['!cp MapSstMean.m ' figname1 '.m'])


%%%  Plot 2  ZOOM
         figure('Units','centimeters',...
               'Position',[1 1 XX YY],...
               'PaperPosition',[1 1 XX YY],...
               'PaperUnits','centimeters')

         pcolor(lon(latz1:latz2,lonz1:lonz2),lat(latz1:latz2,lonz1:lonz2),mtos(latz1:latz2,lonz1:lonz2)); shading flat;
% draw zoom
         line([lon1b lon1],[lat1 lat1],'color','k','LineWidth',1)
         line([lon2b lon2],[lat2 lat2],'color','k','LineWidth',1)
         line([lon1b lon2b],[lat1 lat2],'color','k','LineWidth',1)

         str_minz=num2str(min(min(mtos(latz1:latz2,lonz1:lonz2))),'min %.1f');
         str_maxz=num2str(max(max(mtos(latz1:latz2,lonz1:lonz2))),'max %.1f');
         set(gca,'FontS',sizefont1); set(gca,'PlotBoxAspectRatio',[0.7 1 1]); box on;
         ylabel('Latitude','FontSize',sizefont1)
         xlabel('Longitude','FontSize',sizefont1)
         caxis ([mini maxi]); hcc=colorbar; set(hcc,'FontS',sizefont1);
         title(['sst (C)  ' dur_plot '  ' name_title ],'FontSize',sizefont2,'FontWeight','bold');
         text(-76,-6.95,['(',str_minz,' , ',str_maxz,') '], 'HorizontalAlignment','right','VerticalAlignment','Bottom','FontSize',sizefont1);  
         text(-82.5,-13.35,[date], 'HorizontalAlignment','left','VerticalAlignment','top','FontSize',sizefont1);  
         figname1z=['map_sst_mean_' name '_' dur_plot '_ZOOM'];
         print ('-depsc2','-painters',figname1z)
         eval(['!convert -density 400 ',figname1z,'.eps -resize 739x883 ',figname1z,'.png'])
%        print ('-dpng',figname1z)
         eval(['!cp MapSstMean.m ' figname1z '.m'])
      end
   end
      


