close all, clear all; clc % vider les anciens stockages

% definition des differentes periodes
yearini=0001;
yearfin=0001;
monthini=01;
monthfin=12;
dayini=01;
dayfin=12;

nday=dayfin - dayini + 1;
nyear=yearfin - yearini + 1;
ndayseason=90;

djf1_ini = 1;
djf1_fin = 2;
djf2_ini= 12;
djf2_fin = 12;

mam_ini = 3;
mam_fin = 5;

jja_ini = 6;
jja_fin = 8;

son_ini = 9;
son_fin = 11;

nx=96;   % change here
ny=73;   % change here
nexp = 25; % model simulation experiments
nregion = 11; % number of regions

totday=(1:1:nday);
totseason=(1:1:ndayseason);
totyear=(yearini:1:yearfin);
%filename2 = ['IPSL-CM5A-LR_historical.mon.land.Lmon.r1i1p1.nbp_1980_2005_96x73_cdo_ymonmean'];
filename1 = ['fco2_JENA-s81-V3-6_Oct2014-ext3_1981-2004_monthlymean_XYT_96x73_cdo_ymonmean'];
filename_out = ['synoptic_corr_OM_OS'];

folder1 = ['/data/cpipsl/LI/inversions/'];  %change here
folder2 = ['/data/cpipsl/LI/models/'];  %change here
folder3 = ['/data/sli/regions/'];
folder_out = ['/data/sli/boxplot/data/corr_space/']; 
model_name = ['REF           '; 'BNU-ESM       '; 'CanESM2       '; 'CCSM4         '; 'CESM1-BGC     '; 'CESM1-CAM5    '; 'CESM1-FASTCHEM'; ...
              'CESM1-WACCM   '; 'CNRM-ESM1     '; 'GFDL-ESM2G    '; 'GFDL-ESM2M    '; 'HadGEM2-CC    '; 'HadGEM2-ES    ';  ...
              'inmcm4        '; 'IPSL-CM5A-LR  '; 'IPSL-CM5A-MR  '; 'IPSL-CM5B-LR  '; 'MIROC-ESM-CHEM'; 'MIROC-ESM     '; ...
              'MPI-ESM-LR    '; 'MPI-ESM-MR    '; 'MPI-ESM-P     '; 'MRI-ESM1      '; 'NorESM1-ME    '; 'NorESM1-M     '];
region_name = ['Euras_temp1'; 'Name_bor1  '; 'Same_temp1 '; 'Aust1      '; 'Europe1    '; ...
               'Name_temp1 '; 'Same_trop1 '; 'Euras_bor  '; 'Nafr       '; 'Safr1      '; 'Trop_asia1 ' ];
region_fig_name = ['Euras-temp1'; 'Name-bor1  '; 'Same-temp1 '; 'Aust1      '; 'Europe1    '; ...
                   'Name-temp1 '; 'Same-trop1 '; 'Euras-bor  '; 'Nafr       '; 'Safr1      '; 'Trop-asia1 ' ];


test = 'corr_PC';  %'Mann-Kendall';    % change here
period = '1yr';    %'year';'jja';'djf'; change here

%%
%% reading the region nc file

for iregion=1:nregion
    disp(iregion);
        %cyr=strtrim(ctl(yr,:));
        %ly = isleap(yr);
        %dyinmon = dyinmon_nlp;
    %     ncfile1=dir([folder1,filename1,cyr(2:5),'.nc']);
    %     ncfile2=dir([folder2,filename2,cyr(2:5),'.nc']);

          cregion_name=strtrim(region_name(iregion,:));
          ncfile=dir([folder3,'LEV_regions_aerocarb_lmdz96_',cregion_name, '.nc']);
          filepath=[folder3,ncfile.name];
          disp(folder3);
          disp(cregion_name);
          disp('region_name');

        disp(filepath); 

        ncid1 = netcdf.open(filepath,'NC_NOWRITE');
%         varid_lat=netcdf.inqVarID(ncid1,'latitude');
%         varid_lon=netcdf.inqVarID(ncid1,'logitude');  
        varid_region=netcdf.inqVarID(ncid1,'REGION');     
            
        mask_region_tmp=netcdf.getVar(ncid1,varid_region,[0, 0],[nx, ny]); 
        mask_region(:,:,iregion) = mask_region_tmp;
        mask_region(mask_region==0) = NaN;
        
        netcdf.close(ncid1);
        disp('Successful reading nc file for region:');

%             vari2=cat(3,vari2,vari2_tmp);       
    %         vari2_djf=cat(3,vari2_djf,vari2_tmp(:,:,djf1_ini:djf1_fin),vari2_tmp(:,:,djf2_ini:djf2_fin));
    %         %vari2_djf = cat(3, vari2_djf, vari2_djf_tmp);
    %         vari2_mam=cat(3,vari2_mam,vari2_tmp(:,:,mam_ini:mam_fin));
    %         vari2_jja=cat(3,vari2_jja,vari2_tmp(:,:,jja_ini:jja_fin));
    %         vari2_son=cat(3,vari2_son,vari2_tmp(:,:,son_ini:son_fin)); 
end %for iregion=1:nregion

% read model simulations
for iexp=1:nexp
    disp(iexp);
    for yr=yearini:yearfin
        cyr=num2str(yr+10000);
        %cyr=strtrim(ctl(yr,:));
        %ly = isleap(yr);
        %dyinmon = dyinmon_nlp;
    %     ncfile1=dir([folder1,filename1,cyr(2:5),'.nc']);
    %     ncfile2=dir([folder2,filename2,cyr(2:5),'.nc']);
        if(iexp==1)
            ncfile=dir([folder1,filename1,'.nc']); 
            filepath=[folder1,ncfile.name];
        else
            cmodel_name=strtrim(model_name(iexp,:));
            ncfile=dir([folder2,cmodel_name,'_historical.mon.land.Lmon.r1i1p1.nbp_1981_2004_96x73_cdo_ymonmean.nc']);
            filepath=[folder2,ncfile.name];
            %disp(folder2);
            %disp(model_name(iexp));
            %disp('model_name');
        end

        %filepath=[folder,ncfile.name];
        %filepath2=[folder2,ncfile2.name];

        disp(filepath);    
        %disp(filepath2);

        ncid1 = netcdf.open(filepath,'NC_NOWRITE');
        %ncid2 = netcdf.open(filepath2,'NC_NOWRITE');

        varid_lat=netcdf.inqVarID(ncid1,'latitude');
        varid_lon=netcdf.inqVarID(ncid1,'latitude');   
        
        if(iexp==1)
            varid_vari=netcdf.inqVarID(ncid1,'Terrestrial_flux'); %');
        else
            varid_vari=netcdf.inqVarID(ncid1,'nbp'); %');
        end

        lat=single(netcdf.getVar(ncid1,varid_lat));
        lon=single(netcdf.getVar(ncid1,varid_lon));

        vari_tmp=netcdf.getVar(ncid1,varid_vari,[0, 0, 0],[nx, ny, nday]);
        if(iexp~=1)           
            vari_tmp = vari_tmp * (-1) * 86400 * 365 * 1000; 
        end

        netcdf.close(ncid1);
        %netcdf.close(ncid);
        %disp('Successful reading nc file for year:');
        disp(cyr(2:5));

        if(yr==yearini)
            vari=vari_tmp;      
            vari_djf=cat(3,vari_tmp(:,:,djf1_ini:djf1_fin),vari_tmp(:,:,djf2_ini:djf2_fin));
            vari_mam=vari_tmp(:,:,mam_ini:mam_fin);
            vari_jja=vari_tmp(:,:,jja_ini:jja_fin);
            vari_son=vari_tmp(:,:,son_ini:son_fin); 
        else
            vari=cat(3,vari,vari_tmp);       
            vari_djf=cat(3,vari_djf,vari_tmp(:,:,djf1_ini:djf1_fin),vari1_tmp(:,:,djf2_ini:djf2_fin));
            %vari1_djf = cat(3, vari1_djf, vari1_djf_tmp);
            vari_mam=cat(3,vari_mam,vari_tmp(:,:,mam_ini:mam_fin));
            vari_jja=cat(3,vari_jja,vari_tmp(:,:,jja_ini:jja_fin));
            vari_son=cat(3,vari_son,vari_tmp(:,:,son_ini:son_fin));

%             vari2=cat(3,vari2,vari2_tmp);       
    %         vari2_djf=cat(3,vari2_djf,vari2_tmp(:,:,djf1_ini:djf1_fin),vari2_tmp(:,:,djf2_ini:djf2_fin));
    %         %vari2_djf = cat(3, vari2_djf, vari2_djf_tmp);
    %         vari2_mam=cat(3,vari2_mam,vari2_tmp(:,:,mam_ini:mam_fin));
    %         vari2_jja=cat(3,vari2_jja,vari2_tmp(:,:,jja_ini:jja_fin));
    %         vari2_son=cat(3,vari2_son,vari2_tmp(:,:,son_ini:son_fin));       
        end  % if(yr==yearini) 
    end %for yr=yearini:yearfin
    
        if(iexp==1)
            vari_all=vari;      
            vari_all_djf=vari_djf;
            vari_all_mam=vari_mam;
            vari_all_jja=vari_jja;
            vari_all_son=vari_son; 
        else
            vari_all=cat(4,vari_all,vari);       
            vari_all_djf=cat(4,vari_all_djf,vari_djf);
            %vari1_djf = cat(3, vari1_djf, vari1_djf_tmp);
            vari_all_mam=cat(4,vari_all_mam,vari_mam);
            vari_all_jja=cat(4,vari_all_jja,vari_jja);
            vari_all_son=cat(4,vari_all_son,vari_son);

%             vari2=cat(3,vari2,vari2_tmp);       
    %         vari2_djf=cat(3,vari2_djf,vari2_tmp(:,:,djf1_ini:djf1_fin),vari2_tmp(:,:,djf2_ini:djf2_fin));
    %         %vari2_djf = cat(3, vari2_djf, vari2_djf_tmp);
    %         vari2_mam=cat(3,vari2_mam,vari2_tmp(:,:,mam_ini:mam_fin));
    %         vari2_jja=cat(3,vari2_jja,vari2_tmp(:,:,jja_ini:jja_fin));
    %         vari2_son=cat(3,vari2_son,vari2_tmp(:,:,son_ini:son_fin));       
        end  % if(iexp==1)
        
end %for iexp=1:nexp

disp('calculating the corr');
for ix = 1:nx
    for iy = 1:ny
        for iexp =2:nexp
        vari1_1d = reshape(vari_all(ix,iy,:,1), 1,[]);
        vari2_1d = reshape(vari_all(ix,iy,:,iexp), 1,[]);
        vari1_djf_1d = reshape(vari_all_djf(ix,iy,:,1), 1,[]);
        vari2_djf_1d = reshape(vari_all_djf(ix,iy,:,iexp), 1,[]);
        vari1_mam_1d = reshape(vari_all_mam(ix,iy,:,1), 1,[]);
        vari2_mam_1d = reshape(vari_all_mam(ix,iy,:,iexp), 1,[]);
        vari1_jja_1d = reshape(vari_all_jja(ix,iy,:,1), 1,[]);
        vari2_jja_1d = reshape(vari_all_jja(ix,iy,:,iexp), 1,[]); 
        vari1_son_1d = reshape(vari_all_son(ix,iy,:,1), 1,[]);
        vari2_son_1d = reshape(vari_all_son(ix,iy,:,iexp), 1,[]);
        
        [r_vari1_vari2(ix,iy,iexp-1),     p_vari1_vari2(ix,iy,iexp-1)]     = corr(vari1_1d', vari2_1d', 'rows', 'pairwise');          
        [r_vari1_vari2_djf(ix,iy,iexp-1), p_vari1_vari2_djf(ix,iy,iexp-1)] = corr(vari1_djf_1d', vari2_djf_1d', 'rows', 'pairwise');
        [r_vari1_vari2_mam(ix,iy,iexp-1), p_vari1_vari2_mam(ix,iy,iexp-1)] = corr(vari1_mam_1d', vari2_mam_1d', 'rows', 'pairwise');
        [r_vari1_vari2_jja(ix,iy,iexp-1), p_vari1_vari2_jja(ix,iy,iexp-1)] = corr(vari1_jja_1d', vari2_jja_1d', 'rows', 'pairwise');
        [r_vari1_vari2_son(ix,iy,iexp-1), p_vari1_vari2_son(ix,iy,iexp-1)] = corr(vari1_son_1d', vari2_son_1d', 'rows', 'pairwise');        
        end   
     end
end

%         r_vari1_vari2_mam = r_vari1_vari2_djf;
%         p_vari1_vari2_mam = p_vari1_vari2_djf;  
%         r_vari1_vari2_jja = r_vari1_vari2_djf;
%         p_vari1_vari2_jja = p_vari1_vari2_djf; 
%         r_vari1_vari2_son = r_vari1_vari2_djf;
%         p_vari1_vari2_son = p_vari1_vari2_djf; 

disp('corr OS OM fnished');
          
% %% Regrouper les coefficients en differents groupes, l'interval est de 0.1 ou autrement
% % select the number of variables in the range of (threshold1, threshold2).
% % that is >threshold1 and <threshold2
% % in this example, threshold1 = 2, threshold2 = 6; can change to other values
% threshold1 = -0.1; % change
% threshold2 = 0.1; % change
% variable_threshold = variable;
% variable_threshold(variable_threshold <= threshold1) = NaN;
% variable_threshold(variable_threshold >= threshold2) = NaN;
% % num_variable_threshold is the total number of days
% num_variable_threshold = sum(sum(~isnan(variable_threshold),2));
% disp('num_variable_threshold');
% disp(num_variable_threshold);
% %num_variable_threshold1  and num_variable_threshold2 are the number of
% %days calsulated by dimension 1 and dmension 2
% num_variable_threshold1 = sum(~isnan(variable_threshold),1); %
% num_variable_threshold2 = sum(~isnan(variable_threshold),2); %
% disp('num_variable_threshold1');
% disp(num_variable_threshold1);
% disp('num_variable_threshold2');
% disp(num_variable_threshold2);

%% print the variable into netcdf file

disp('dealing with the mask');    
    %% multiplier avec les 11 regions
  
    for iregion=1:nregion
        for iexp = 1:nexp - 1
            r_vari1_vari2_reg(:,:,iexp,iregion) = r_vari1_vari2(:,:,iexp) .* mask_region(:,:,iregion);
            p_vari1_vari2_reg(:,:,iexp,iregion) = p_vari1_vari2(:,:,iexp) .* mask_region(:,:,iregion);
            r_vari1_vari2_djf_reg(:,:,iexp,iregion) = r_vari1_vari2_djf(:,:,iexp) .* mask_region(:,:,iregion);
            p_vari1_vari2_djf_reg(:,:,iexp,iregion) = p_vari1_vari2_djf(:,:,iexp) .* mask_region(:,:,iregion);  
            r_vari1_vari2_mam_reg(:,:,iexp,iregion) = r_vari1_vari2_mam(:,:,iexp) .* mask_region(:,:,iregion);
            p_vari1_vari2_mam_reg(:,:,iexp,iregion) = p_vari1_vari2_mam(:,:,iexp) .* mask_region(:,:,iregion);  
            r_vari1_vari2_jja_reg(:,:,iexp,iregion) = r_vari1_vari2_jja(:,:,iexp) .* mask_region(:,:,iregion);
            p_vari1_vari2_jja_reg(:,:,iexp,iregion) = p_vari1_vari2_jja(:,:,iexp) .* mask_region(:,:,iregion); 
            r_vari1_vari2_son_reg(:,:,iexp,iregion) = r_vari1_vari2_son(:,:,iexp) .* mask_region(:,:,iregion);
            p_vari1_vari2_son_reg(:,:,iexp,iregion) = p_vari1_vari2_son(:,:,iexp) .* mask_region(:,:,iregion);            
        end
    end   


%% write into netcdf      
%% 
    lon=linspace(-180,176.25,nx); %longitude; 
    %lat=linspace(-1.267606,82.39436,ny); %latitude;
    lat=linspace(-89.375,89.375,ny); %latitude;

    %time=1:netcdf.getConstant('NC_UNLIMITED');
    %[mlat,mlon]=meshgrid(lat,lon);
    disp('Creando file Netcdf...');
    %filenc=[cyr,'nc/','GLEAM_',cyr,cmon(2:3),cdy(2:3),'.nc'];
    %filenc=[folder_out,fname,datyp,'_',cyr,'_',num2str(jdy,'%03i'),'.nc'];
    filenc=[folder_out,filename_out,'_',period,'_',test,'.nc'];
    disp(filenc);
    %ncid = netcdf.create(filenc,'SHARE');
    ncid = netcdf.create(filenc,'NC_CLOBBER');

    % Crear dimensiones
    dimid_lon = netcdf.defDim(ncid,'longitude',nx);
    dimid_lat = netcdf.defDim(ncid,'latitude',ny);
    %dimid_land = netcdf.defDim(ncid,'land',nland);
    dimid_k = netcdf.defDim(ncid,'k',nexp-1);
    dimid_nreg = netcdf.defDim(ncid,'nregion',nregion);
    
    %dimid_time_yr = netcdf.defDim(ncid,'time_yr',netcdf.getConstant('NC_UNLIMITED'));
%   dimid_time_mon = netcdf.defDim(ncid,'time_mon',nyr_max*nmon); 
   %dimid_time_jdy = netcdf.defDim(ncid,'time_jdy',nyr_max*nday); 
    %disp(dimid_time);

    % Crear variables y atributos
    varid_lon = netcdf.defVar(ncid,'longitude','double',dimid_lon);
    netcdf.putAtt(ncid,varid_lon,'long_name','Longitude');
    netcdf.putAtt(ncid,varid_lon,'units','degrees_east');
    % 
    varid_lat = netcdf.defVar(ncid,'latitude','double',dimid_lat);
    netcdf.putAtt(ncid,varid_lat,'long_name','Latitude');
    netcdf.putAtt(ncid,varid_lat,'units','degrees_north');
    % 
    varid_k = netcdf.defVar(ncid,'k','double',dimid_k);
    netcdf.putAtt(ncid,varid_k,'long_name','k');
    netcdf.putAtt(ncid,varid_k,'units','');
    
    varid_nreg = netcdf.defVar(ncid,'nregion','double',dimid_nreg);
    netcdf.putAtt(ncid,varid_nreg,'long_name','nregion');
    netcdf.putAtt(ncid,varid_nreg,'units','');
    
%     varid_time_yr = netcdf.defVar(ncid,'time_yr','double',dimid_time_yr);
%     netcdf.putAtt(ncid,varid_time_yr,'long_name','Time');
%     netcdf.putAtt(ncid,varid_time_yr,'units','Seconds since 1980-01-01 00:00:00');
%     
%     varid_time_jdy = netcdf.defVar(ncid,'time_jdy','double',dimid_time_jdy);
%     netcdf.putAtt(ncid,varid_time_jdy,'long_name','Time');
%     netcdf.putAtt(ncid,varid_time_jdy,'units','Seconds since 1980-01-01 00:00:00');    

    % 
    %% variables, ,,,       
    %% contfrac_reg
%     varid_contfrac = netcdf.defVar(ncid,'contfrac','double',[dimid_lon,dimid_lat]);
%     netcdf.putAtt(ncid,varid_contfrac,'long_name','contfrac');
%     netcdf.putAtt(ncid,varid_contfrac,'units','-');
%     %netcdf.putAtt(ncid,varid_evap,'missing_value',-9999);
%     netcdf.putAtt(ncid,varid_contfrac,'_FillValue',9.9e+15);

    %% r_vari1_vari2 
    %%
    % variables, r,
    %varid_r_vari1_vari2  = netcdf.defVar(ncid,'r_vari1_vari2 ','double',[dimid_lon,dimid_lat,dimid_time_jdy]);
    varid_r_vari1_vari2 = netcdf.defVar(ncid,'r_vari1_vari2','double',[dimid_lon,dimid_lat,dimid_k]);
    netcdf.putAtt(ncid,varid_r_vari1_vari2,'long_name','r_vari1_vari2');
    netcdf.putAtt(ncid,varid_r_vari1_vari2,'units','logical');
    %netcdf.putAtt(ncid,varid_evap,'missing_value',-9999);
    netcdf.putAtt(ncid,varid_r_vari1_vari2,'_FillValue',9.9e+15);

    %% p_vari1_vari2     
    % variables, p,
    %varid_p_vari1_vari2  = netcdf.defVar(ncid,'p_vari1_vari2 ','double',[dimid_lon,dimid_lat,dimid_time_jdy]);
    varid_p_vari1_vari2  = netcdf.defVar(ncid,'p_vari1_vari2','double',[dimid_lon,dimid_lat,dimid_k]);
    netcdf.putAtt(ncid,varid_p_vari1_vari2,'long_name','p_vari1_vari2');
    netcdf.putAtt(ncid,varid_p_vari1_vari2,'units','logical');
    %netcdf.putAtt(ncid,varid_evap,'missing_value',-9999);
    netcdf.putAtt(ncid,varid_p_vari1_vari2,'_FillValue',9.9e+15);
    
    %% r_vari1_vari2_reg
    % variables, r,
    %varid_r_vari1_vari2_reg  = netcdf.defVar(ncid,'r_vari1_vari2_reg ','double',[dimid_lon,dimid_lat,dimid_time_jdy]);
    varid_r_vari1_vari2_reg = netcdf.defVar(ncid,'r_vari1_vari2_reg','double',[dimid_lon,dimid_lat,dimid_k, dimid_nreg]);
    netcdf.putAtt(ncid,varid_r_vari1_vari2_reg,'long_name','r_vari1_vari2_reg');
    netcdf.putAtt(ncid,varid_r_vari1_vari2_reg,'units','logical');
    %netcdf.putAtt(ncid,varid_evap,'missing_value',-9999);
    netcdf.putAtt(ncid,varid_r_vari1_vari2_reg,'_FillValue',9.9e+15);
    
    %% p_vari1_vari2_reg     
    % variables, p,
    %varid_p_vari1_vari2_reg  = netcdf.defVar(ncid,'p_vari1_vari2_reg ','double',[dimid_lon,dimid_lat,dimid_time_jdy]);
    varid_p_vari1_vari2_reg  = netcdf.defVar(ncid,'p_vari1_vari2_reg','double',[dimid_lon,dimid_lat,dimid_k, dimid_nreg]);
    netcdf.putAtt(ncid,varid_p_vari1_vari2_reg,'long_name','p_vari1_vari2_reg');
    netcdf.putAtt(ncid,varid_p_vari1_vari2_reg,'units','logical');
    %netcdf.putAtt(ncid,varid_evap,'missing_value',-9999);
    netcdf.putAtt(ncid,varid_p_vari1_vari2_reg,'_FillValue',9.9e+15);    
   

    % end def
    netcdf.endDef(ncid)
    %%
    disp('Put Variable into Netcdf...');
    % % % Agregar datos de coordenadas
    %disp(size(longitude));
    netcdf.putVar(ncid,varid_lon,lon);
    netcdf.putVar(ncid,varid_lat,lat);
    %netcdf.putVar(ncid,varid_land,land);
    %disp('total record writen in netcdf:');    

    netcdf.putVar(ncid,varid_k,0,nexp-1);

    %netcdf.putVar(ncid,varid_time,0,1);  %  netcdf.putVar(ncid,varid_time,0,nmon_rec,time_mon);
    %netcdf.putVar(ncid,varid_time_yr, 0,nyr(1),time_yr);  %  netcdf.putVar(ncid,varid_time,0,nmon_rec,time_mon);
    %netcdf.putVar(ncid,varid_time_jdy,0,nyr_max*nday,time_jdy_dtasr);  %  netcdf.putVar(ncid,varid_time,0,nmon_rec,time_mon);    
    %netcdf.putVar(ncid,varid_contfrac,[0,0],[nx,ny],landfrac);
    disp('the size of r_vari1_vari2_reg');
    disp(size(r_vari1_vari2_reg));

    netcdf.putVar(ncid,varid_r_vari1_vari2_reg,[0,0,0,0],[nx,ny,nexp-1,nregion],r_vari1_vari2_reg);
    netcdf.putVar(ncid,varid_p_vari1_vari2_reg,[0,0,0,0],[nx,ny,nexp-1,nregion],p_vari1_vari2_reg);
    netcdf.putVar(ncid,varid_r_vari1_vari2,[0,0,0],[nx,ny,nexp-1],r_vari1_vari2);
    netcdf.putVar(ncid,varid_p_vari1_vari2,[0,0,0],[nx,ny,nexp-1],p_vari1_vari2);    

   %% finish writing
    %%
    netcdf.close(ncid) ;
    disp('Successful!');
    
    %%
% break;


%% for boxplot
%%
% to set the position of each figure

width = 0.40;
height = 0.40;
positionVector1 = [0.00, 0.50, width, height];%[left,bottom,width,height]
positionVector2 = [0.50, 0.50, width, height];
positionVector3 = [0.55, 0.75, width, height];
positionVector4 = [0.80, 0.75, width, height];
positionVector5 = [0.05, 0.65, width, height];
positionVector6 = [0.30, 0.65, width, height];
positionVector7 = [0.55, 0.65, width, height];
positionVector8 = [0.80, 0.65, width, height];
positionVector9 = [0.05, 0.45, width, height];

%%
%% start boxplot
figure;

%%
%% boxplot for all the data 80*360
bar_width = 1.0;
nbins = 12;
     
% r_vari1_vari2_1d=reshape(r_vari1_vari2(:,:,:), [], 1); %change
% r_vari1_vari2_1d_99prct = prctile(r_vari1_vari2_1d,99);
% r_vari1_vari2_1d_1prct = prctile(r_vari1_vari2_1d,1);
    
%r_vari1_vari2_allreg_4season_1d(:,1)=reshape(r_vari1_vari2_reg(~isnan(r_vari1_vari2_reg(:,:,:,:))), [], 1); %change
r_vari1_vari2_allreg_4season_1d(:,1)=reshape(r_vari1_vari2_reg(:,:,:,:), [], 1); %change
r_vari1_vari2_allreg_4season_1d_99prct(:,1) = prctile(r_vari1_vari2_allreg_4season_1d(:,1),99);
r_vari1_vari2_allreg_4season_1d_1prct(:,1) = prctile(r_vari1_vari2_allreg_4season_1d(:,1),1);
%r_vari1_vari2_allreg_4season_1d_mean(:,1) = nanmean(r_vari1_vari2_allreg_4season_1d(:,1));

% r_vari1_vari2_reg_tmp1 = r_vari1_vari2_reg(~isnan(r_vari1_vari2_reg(:,:,:,:)));
% disp(size(r_vari1_vari2_reg_tmp1));
% r_vari1_vari2_reg_tmp2 = r_vari1_vari2_djf_reg(~isnan(r_vari1_vari2_djf_reg(:,:,:,:)));
% disp(size(r_vari1_vari2_reg_tmp2));
% r_vari1_vari2_reg_tmp3 = r_vari1_vari2_mam_reg(~isnan(r_vari1_vari2_mam_reg(:,:,:,:)));
% disp(size(r_vari1_vari2_reg_tmp3));
% r_vari1_vari2_reg_tmp4 = r_vari1_vari2_jja_reg(~isnan(r_vari1_vari2_jja_reg(:,:,:,:)));
% disp(size(r_vari1_var_reg_tmp4));
% r_vari1_vari2_reg_tmp5 = r_vari1_vari2_son_reg(~isnan(r_vari1_vari2_son_reg(:,:,:,:)));
% disp(size(r_vari1_vari2_reg_tmp5));

%  r_vari1_vari2_allreg_4season_1d(:,2) = reshape(r_vari1_vari2_djf_reg(~isnan(r_vari1_vari2_djf_reg(:,:,:,:))), [], 1); % DJF
%  r_vari1_vari2_allreg_4season_1d(:,3) = reshape(r_vari1_vari2_mam_reg(~isnan(r_vari1_vari2_mam_reg(:,:,:,:))), [], 1); % MAM
%  r_vari1_vari2_allreg_4season_1d(:,4) = reshape(r_vari1_vari2_jja_reg(~isnan(r_vari1_vari2_jja_reg(:,:,:,:))), [], 1); % JJA
%  r_vari1_vari2_allreg_4season_1d(:,5) = reshape(r_vari1_vari2_son_reg(~isnan(r_vari1_vari2_son_reg(:,:,:,:))), [], 1); % SON
r_vari1_vari2_allreg_4season_1d(:,2) = reshape(r_vari1_vari2_djf_reg(:,:,:,:), [], 1); % DJF
r_vari1_vari2_allreg_4season_1d(:,3) = reshape(r_vari1_vari2_mam_reg(:,:,:,:), [], 1); % MAM
r_vari1_vari2_allreg_4season_1d(:,4) = reshape(r_vari1_vari2_jja_reg(:,:,:,:), [], 1); % JJA
r_vari1_vari2_allreg_4season_1d(:,5) = reshape(r_vari1_vari2_son_reg(:,:,:,:), [], 1); % SON
disp('size of r_vari1_vari2_allreg_4season_1d:');
disp(size(r_vari1_vari2_allreg_4season_1d));

r_vari1_vari2_allreg_4season_1d_99prct(:,2) = prctile(r_vari1_vari2_allreg_4season_1d(:,2),99); % DJF
r_vari1_vari2_allreg_4season_1d_1prct(:,2) = prctile(r_vari1_vari2_allreg_4season_1d(:,2),1);   % DJF

r_vari1_vari2_allreg_4season_1d_99prct(:,3) = prctile(r_vari1_vari2_allreg_4season_1d(:,3),99); % MAM
r_vari1_vari2_allreg_4season_1d_1prct(:,3) = prctile(r_vari1_vari2_allreg_4season_1d(:,3),1);   % MAM

r_vari1_vari2_allreg_4season_1d_99prct(:,4) = prctile(r_vari1_vari2_allreg_4season_1d(:,4),99); % JJA
r_vari1_vari2_allreg_4season_1d_1prct(:,4) = prctile(r_vari1_vari2_allreg_4season_1d(:,4),1);   % JJA

r_vari1_vari2_allreg_4season_1d_99prct(:,5) = prctile(r_vari1_vari2_allreg_4season_1d(:,5),99); % SON
r_vari1_vari2_allreg_4season_1d_1prct(:,5) = prctile(r_vari1_vari2_allreg_4season_1d(:,5),1);   % SON

r_vari1_vari2_allreg_4season_1d_mean = nanmean(r_vari1_vari2_allreg_4season_1d);   % MAM


whisker_length_allvar = 1.5;
nbox = 5;
x = 1:nbox;
%positions = [1 1.5 2.5 3 4 4.5];
%exp_name_dtr=char('OS','OM'); %use this one if there are two datasets for compare, you
%also need to set nbox = 2
box_name=char('Annual', 'DJF', 'MAM', 'JJA', 'SON');

%subplot('Position',positionVector1);
subplot;
%%boxplot(eca_dtr_box,'labels',reg,'positions', positions);
boxplot(r_vari1_vari2_allreg_4season_1d,'outliersize',4,'whisker',whisker_length_allvar,'notch','on'); %,'widths',2) ;
set(findobj(gca,'type','line'),'linew',1);
%,'symbol','o' )%,'positions', positions);
%boxplot(d_dtr_itv_itnv_day_box_sahara)%,'positions', positions); 
%,'whisker',5)
  color = ['y', 'm', 'g', 'c', 'w']; 
  h = findobj(gca,'Tag','Box');
  for j=1:length(h)
      patch(get(h(j),'XData'),get(h(j),'YData'),color(j),'FaceAlpha',.5);
  end
   
%legend({'EXP_8_m_,_L_T_,_T_P','EXP_8_m',},'Location','northwest','FontSize',3);
%xlabel('IT_NV','FontSize',6);
ylabel('Correlation','FontSize',10);
%set(legend,'PlotBoxAspectRatio',[0.5 0.10 1]);
%leg.Position=[0.7247,0.8067,0.1714,0.01];
%set(legend, 'fontsize','Position', [0.1, 0.95, .02, .02])
%set(legend,'PlotBoxAspectRatio',[0.75 0.3 1.0]);  %x,y,z
title('Corr Ref vs. Sim Boxplot (ALL)','FontSize',10); %,15W-35E,15N-25N
axis([0 length(x)+1 -inf inf]);
set(gca, 'XTick',x, 'XTickLabel',box_name,'FontSize',10)
%xticklabel_rotate(x,90,cellstr(exp_name),'interpreter','none','FontSize',6)
 hold on;
 plot(x,r_vari1_vari2_allreg_4season_1d_mean,'b.','MarkerSize',15);
% hold on;
% plot(x,[r_vari1_vari2_allreg_4season_1d_99prct],'rd','MarkerSize',5);
% hold on;
% plot(x,[r_vari1_vari2_allreg_4season_1d_1prct],'rd','MarkerSize',5);
%  hold on;
%  plot(x,[prctile_dtr_ctl_sahara(2) prctile_dtr_exp_sahara(2)],'gd');
% 
axis ([0 6 -1.1 1.1]);
% str_p1st_ctl = [num2str(round(r_vari1_vari2_allreg_4season_1d_1prct*100)/100),''];
% text(1.1,double(r_vari1_vari2_allreg_4season_1d_1prct),str_p1st_ctl,'HorizontalAlignment','left', 'FontSize', 3);
% str_p99th_ctl = [num2str(round(r_vari1_vari2_allreg_4season_1d_99prct*100)/100),''];
% text(1.1,double(r_vari1_vari2_allreg_4season_1d_99prct),str_p99th_ctl,'HorizontalAlignment','left', 'FontSize', 3);

% prctile_dtr_exp_sahara_rel = (prctile_dtr_exp_sahara(1) - prctile_dtr_ctl_sahara(1))/prctile_dtr_ctl_sahara(1)*100.0;
% str_p1st_exp = [num2str(round(prctile_dtr_exp_sahara(1)*100)/100),'K','(',num2str(round(prctile_dtr_exp_sahara_rel*100)/100),'%)'];
% text(2.1,double(prctile_dtr_exp_sahara(1)),str_p1st_exp,'HorizontalAlignment','left', 'FontSize', 3);
% 
% prctile_dtr_exp_sahara_rel = (prctile_dtr_exp_sahara(6) - prctile_dtr_ctl_sahara(6))/prctile_dtr_ctl_sahara(6)*100.0;
% str_p99th_exp = [num2str(round(prctile_dtr_exp_sahara(6)*100)/100),'K','(',num2str(round(prctile_dtr_exp_sahara_rel*100)/100),'%)'];
% text(2.1,double(prctile_dtr_exp_sahara(6)),str_p99th_exp,'HorizontalAlignment','left', 'FontSize', 3);

% ylim_min = min(min(dtr_day_box_sahara)) - min(min(dtr_day_box_sahara)) * 0.2;
% ylim_max = 1.1 * max(max(dtr_day_box_sahara));
% ylim([-1 ylim_max]); %ylim([ylim_min ylim_max]);

% legend({'Corr OMOS','-',},'Location','northwest','FontSize',3,'Orientation','horizontal');
%set(legend,  'fontsize', 3, 'Position', [0.4, 0.7, 0.01, 0.01]);
% set(legend,  'fontsize', 3, 'Position', [0.20, 0.16, 0.01, 0.01]);

pdf_name_all=strcat(folder_out,'r_vari1_vari2_all_4season.pdf');
saveas(gcf,pdf_name_all);
jpg_name_all=strcat(folder_out,'r_vari1_vari2_all_4season.jpg');
saveas(gcf,jpg_name_all);
%close(gcf);

%%
%%

for iexp = 1:nexp-1
%% boxplot for all the data 80*360

r_vari1_vari2_allreg_iexp_1d(:,1)=reshape(r_vari1_vari2_reg(:,:,iexp,:), [], 1); %change
r_vari1_vari2_allreg_iexp_1d_99prct(:,1) = prctile(r_vari1_vari2_allreg_iexp_1d(:,1),99);
r_vari1_vari2_allreg_iexp_1d_1prct(:,1) = prctile(r_vari1_vari2_allreg_iexp_1d(:,1),1);

r_vari1_vari2_allreg_iexp_1d(:,2) = reshape(r_vari1_vari2_djf_reg(:,:,iexp,:), [], 1); % DJF
r_vari1_vari2_allreg_iexp_1d(:,3) = reshape(r_vari1_vari2_mam_reg(:,:,iexp,:), [], 1); % MAM
r_vari1_vari2_allreg_iexp_1d(:,4) = reshape(r_vari1_vari2_jja_reg(:,:,iexp,:), [], 1); % JJA
r_vari1_vari2_allreg_iexp_1d(:,5) = reshape(r_vari1_vari2_son_reg(:,:,iexp,:), [], 1); % SON

r_vari1_vari2_allreg_iexp_1d_99prct(:,2) = prctile(r_vari1_vari2_allreg_iexp_1d(:,2),99); % DJF
r_vari1_vari2_allreg_iexp_1d_1prct(:,2) = prctile(r_vari1_vari2_allreg_iexp_1d(:,2),1);   % DJF

r_vari1_vari2_allreg_iexp_1d_99prct(:,3) = prctile(r_vari1_vari2_allreg_iexp_1d(:,3),99); % MAM
r_vari1_vari2_allreg_iexp_1d_1prct(:,3) = prctile(r_vari1_vari2_allreg_iexp_1d(:,3),1);   % MAM

r_vari1_vari2_allreg_iexp_1d_99prct(:,4) = prctile(r_vari1_vari2_allreg_iexp_1d(:,4),99); % JJA
r_vari1_vari2_allreg_iexp_1d_1prct(:,4) = prctile(r_vari1_vari2_allreg_iexp_1d(:,4),1);   % JJA

r_vari1_vari2_allreg_iexp_1d_99prct(:,5) = prctile(r_vari1_vari2_allreg_iexp_1d(:,5),99); % SON
r_vari1_vari2_allreg_iexp_1d_1prct(:,5) = prctile(r_vari1_vari2_allreg_iexp_1d(:,5),1);   % SON

r_vari1_vari2_allreg_iexp_1d_mean = nanmean(r_vari1_vari2_allreg_iexp_1d);

whisker_length_allvar = 1.5;
nbox = 5;
x = 1:nbox;
%positions = [1 1.5 2.5 3 4 4.5];

box_name=char('Annual', 'DJF', 'MAM', 'JJA', 'SON');
subplot;
%subplot('Position',positionVector1);
boxplot(r_vari1_vari2_allreg_iexp_1d,'outliersize',4,'whisker',whisker_length_allvar,'notch','on');
set(findobj(gca,'type','line'),'linew',1);
  color = ['y', 'm', 'g', 'c', 'w'];  
  h = findobj(gca,'Tag','Box');
  for j=1:length(h)
      patch(get(h(j),'XData'),get(h(j),'YData'),color(j),'FaceAlpha',.5);
  end   

ylabel('Correlation','FontSize',10);

title_name_model=strcat('Corr Ref. vs. Sim Boxplot:',strtrim(model_name(iexp+1,:)));
title(title_name_model,'FontSize',10); %,15W-35E,15N-25N
axis([0 length(x)+1 -inf inf]);
set(gca, 'XTick',x, 'XTickLabel',box_name,'FontSize',10);
 hold on;
 plot(x,r_vari1_vari2_allreg_iexp_1d_mean,'b.','MarkerSize',15);
 axis ([0 6 -1.1 1.1]);
%set(legend,  'fontsize', 3, 'Position', [0.20, 0.16, 0.01, 0.01]);

cregion_name=strtrim(region_name(iregion,:));

pdf_name_exp=strcat(folder_out,'r_vari1_vari2_',strtrim(model_name(iexp+1,:)),'.pdf');
disp(pdf_name_exp);
saveas(gcf,pdf_name_exp);

jpg_name_exp=strcat(folder_out,'r_vari1_vari2_',strtrim(model_name(iexp+1,:)),'.jpg');
saveas(gcf,jpg_name_exp);
end

for iregion = 1: nregion
    
r_vari1_vari2_reg_iexp_1d(:,1)=reshape(r_vari1_vari2_reg(:,:,:,iregion), [], 1); %change
r_vari1_vari2_reg_iexp_1d_99prct(:,1) = prctile(r_vari1_vari2_reg_iexp_1d(:,1),99);
r_vari1_vari2_reg_iexp_1d_1prct(:,1) = prctile(r_vari1_vari2_reg_iexp_1d(:,1),1);

r_vari1_vari2_reg_iexp_1d(:,2) = reshape(r_vari1_vari2_djf_reg(:,:,:,iregion), [], 1); % DJF
r_vari1_vari2_reg_iexp_1d(:,3) = reshape(r_vari1_vari2_mam_reg(:,:,:,iregion), [], 1); % MAM
r_vari1_vari2_reg_iexp_1d(:,4) = reshape(r_vari1_vari2_jja_reg(:,:,:,iregion), [], 1); % JJA
r_vari1_vari2_reg_iexp_1d(:,5) = reshape(r_vari1_vari2_son_reg(:,:,:,iregion), [], 1); % SON

r_vari1_vari2_reg_iexp_1d_99prct(:,2) = prctile(r_vari1_vari2_reg_iexp_1d(:,2),99); % DJF
r_vari1_vari2_reg_iexp_1d_1prct(:,2) = prctile(r_vari1_vari2_reg_iexp_1d(:,2),1);   % DJF

r_vari1_vari2_reg_iexp_1d_99prct(:,3) = prctile(r_vari1_vari2_reg_iexp_1d(:,3),99); % MAM
r_vari1_vari2_reg_iexp_1d_1prct(:,3) = prctile(r_vari1_vari2_reg_iexp_1d(:,3),1);   % MAM

r_vari1_vari2_reg_iexp_1d_99prct(:,4) = prctile(r_vari1_vari2_reg_iexp_1d(:,4),99); % JJA
r_vari1_vari2_reg_iexp_1d_1prct(:,4) = prctile(r_vari1_vari2_reg_iexp_1d(:,4),1);   % JJA

r_vari1_vari2_reg_iexp_1d_99prct(:,5) = prctile(r_vari1_vari2_reg_iexp_1d(:,5),99); % SON
r_vari1_vari2_reg_iexp_1d_1prct(:,5) = prctile(r_vari1_vari2_reg_iexp_1d(:,5),1);   % SON

r_vari1_vari2_reg_iexp_1d_mean = nanmean(r_vari1_vari2_reg_iexp_1d);

whisker_length_allvar = 1.5;
nbox = 5;
x = 1:nbox;
%positions = [1 1.5 2.5 3 4 4.5];

box_name=char('Annual', 'DJF', 'MAM', 'JJA', 'SON');

subplot;
boxplot(r_vari1_vari2_reg_iexp_1d,'outliersize',4,'whisker',whisker_length_allvar,'notch','on');
set(findobj(gca,'type','line'),'linew',1);
  color = ['y', 'm', 'g', 'c', 'w']; 
  h = findobj(gca,'Tag','Box');
  for j=1:length(h)
      patch(get(h(j),'XData'),get(h(j),'YData'),color(j),'FaceAlpha',.5);
  end   

ylabel('Correlation','FontSize',10);

title_name_region=strcat('Corr Ref. vs. Sim Boxplot:',strtrim(region_fig_name(iregion,:)));
title(title_name_region,'FontSize',10); %,15W-35E,15N-25N
axis([0 length(x)+1 -inf inf]);
set(gca, 'XTick',x, 'XTickLabel',box_name,'FontSize',10);
hold on;
plot(x,r_vari1_vari2_reg_iexp_1d_mean,'b.','MarkerSize',15);
 
%set(legend,  'fontsize', 3, 'Position', [0.20, 0.16, 0.01, 0.01]);

%pdf_name_region=strcat('r_vari1_vari2_',strtrim(region_name(iregion,:)),'.pdf');
axis ([0 6 -1.1 1.1]);

pdf_name_region=strcat(folder_out,'r_vari1_vari2_',strtrim(region_fig_name(iregion,:)),'.pdf');
disp(pdf_name_region);
saveas(gcf,pdf_name_region);

jpg_name_region=strcat(folder_out,'r_vari1_vari2_',strtrim(region_fig_name(iregion,:)),'.jpg');
disp(jpg_name_region);
saveas(gcf,jpg_name_region);
end

break;



%%
%%

%% step for box plot
%% boxplot for 4 seasons 80*90 for each season



% variable_mam_1d_99prct = prctile(variable_mam_1d,99);
% variable_mam_1d_1prct = prctile(variable_mam_1d,1);
% variable_jja_1d_99prct = prctile(variable_jja_1d,99);
% variable_jja_1d_1prct = prctile(variable_jja_1d,1);
% variable_son_1d_99prct = prctile(variable_son_1d,99);
% variable_son_1d_1prct = prctile(variable_son_1d,1);

whisker_length_djf = 1.5;
whisker_length_mam = 1.5;
whisker_length_jja = 1.5;
whisker_length_son = 1.5;

nbox = 4;
x = 1:nbox;
%positions = [1 1.5 2.5 3 4 4.5];
%exp_name_dtr=char('OS','OM'); %use this one if there are two datasets for compare, you
%also need to set nbox = 2
box_name=char('DJF', 'MAM', 'JJA', 'SON');

subplot('Position',positionVector2)
%%boxplot(eca_dtr_box,'labels',reg,'positions', positions);
boxplot(r_vari1_vari2_4season_1d,'outliersize',4,'whisker',whisker_length_allvar,'notch','on');
%;,'widths',0.8) 
%,'symbol','o' )%,'positions', positions);
%boxplot(d_dtr_itv_itnv_day_box_sahara)%,'positions', positions); 
%,'whisker',5)
  color = ['y', 'c', 'm', 'g'];
  h = findobj(gca,'Tag','Box');
  for j=1:length(h)
      patch(get(h(j),'XData'),get(h(j),'YData'),color(j),'FaceAlpha',.5);
  end
   
%legend({'EXP_8_m_,_L_T_,_T_P','EXP_8_m',},'Location','northwest','FontSize',3);
%xlabel('IT_NV','FontSize',6);
ylabel('Correlation','FontSize',6);
%set(legend,'PlotBoxAspectRatio',[0.5 0.10 1]);
%leg.Position=[0.7247,0.8067,0.1714,0.01];
%set(legend, 'fontsize','Position', [0.1, 0.95, .02, .02])
%set(legend,'PlotBoxAspectRatio',[0.75 0.3 1.0]);  %x,y,z
title('(a) Corr OS vs. OM Boxplot (ALL)','FontSize',6); %,15W-35E,15N-25N
axis([0 length(x)+1 -inf inf]);
set(gca, 'XTick',x, 'XTickLabel',box_name,'FontSize',6)
%xticklabel_rotate(x,90,cellstr(exp_name),'interpreter','none','FontSize',6)
%hold on;
%plot(x,mean3,'b.','MarkerSize',5);
hold on;
plot(x,[r_vari1_vari2_4season_1d_99prct(1) r_vari1_vari2_4season_1d_99prct(2) r_vari1_vari2_4season_1d_99prct(3) r_vari1_vari2_4season_1d_99prct(4)],'rd','MarkerSize',5);
hold on;
plot(x,[r_vari1_vari2_4season_1d_1prct(1) r_vari1_vari2_4season_1d_1prct(2) r_vari1_vari2_4season_1d_1prct(3) r_vari1_vari2_4season_1d_1prct(4)],'rd','MarkerSize',5);
%  hold on;
%  plot(x,[prctile_dtr_ctl_sahara(2) prctile_dtr_exp_sahara(2)],'gd');

str_p1st_4season = [num2str(round(r_vari1_vari2_4season_1d_1prct(1)*100)/100),''];
text(1.1,double(r_vari1_vari2_4season_1d_1prct(1)),str_p1st_4season,'HorizontalAlignment','left', 'FontSize', 3);
str_p99th_4season = [num2str(round(r_vari1_vari2_4season_1d_99prct(1)*100)/100),''];
text(1.1,double(r_vari1_vari2_4season_1d_99prct(1)),str_p99th_4season,'HorizontalAlignment','left', 'FontSize', 3);

str_p1st_4season = [num2str(round(r_vari1_vari2_4season_1d_1prct(2)*100)/100),''];
text(2.1,double(r_vari1_vari2_4season_1d_1prct(2)),str_p1st_4season,'HorizontalAlignment','left', 'FontSize', 3);
str_p99th_4season = [num2str(round(r_vari1_vari2_4season_1d_99prct(2)*100)/100),''];
text(2.1,double(r_vari1_vari2_4season_1d_99prct(2)),str_p99th_4season,'HorizontalAlignment','left', 'FontSize', 3);

str_p1st_4season = [num2str(round(r_vari1_vari2_4season_1d_1prct(3)*100)/100),''];
text(3.1,double(r_vari1_vari2_4season_1d_1prct(3)),str_p1st_4season,'HorizontalAlignment','left', 'FontSize', 3);
str_p99th_4season = [num2str(round(r_vari1_vari2_4season_1d_99prct(3)*100)/100),''];
text(3.1,double(r_vari1_vari2_4season_1d_99prct(3)),str_p99th_4season,'HorizontalAlignment','left', 'FontSize', 3);

str_p1st_4season = [num2str(round(r_vari1_vari2_4season_1d_1prct(4)*100)/100),''];
text(4.1,double(r_vari1_vari2_4season_1d_1prct(4)),str_p1st_4season,'HorizontalAlignment','left', 'FontSize', 3);
str_p99th_4season = [num2str(round(r_vari1_vari2_4season_1d_99prct(4)*100)/100),''];
text(4.1,double(r_vari1_vari2_4season_1d_99prct(4)),str_p99th_4season,'HorizontalAlignment','left', 'FontSize', 3);

% prctile_dtr_exp_sahara_rel = (prctile_dtr_exp_sahara(1) - prctile_dtr_ctl_sahara(1))/prctile_dtr_ctl_sahara(1)*100.0;
% str_p1st_exp = [num2str(round(prctile_dtr_exp_sahara(1)*100)/100),'K','(',num2str(round(prctile_dtr_exp_sahara_rel*100)/100),'%)'];
% text(2.1,double(prctile_dtr_exp_sahara(1)),str_p1st_exp,'HorizontalAlignment','left', 'FontSize', 3);
% 
% prctile_dtr_exp_sahara_rel = (prctile_dtr_exp_sahara(6) - prctile_dtr_ctl_sahara(6))/prctile_dtr_ctl_sahara(6)*100.0;
% str_p99th_exp = [num2str(round(prctile_dtr_exp_sahara(6)*100)/100),'K','(',num2str(round(prctile_dtr_exp_sahara_rel*100)/100),'%)'];
% text(2.1,double(prctile_dtr_exp_sahara(6)),str_p99th_exp,'HorizontalAlignment','left', 'FontSize', 3);

% ylim_min = min(min(dtr_day_box_sahara)) - min(min(dtr_day_box_sahara)) * 0.2;
% ylim_max = 1.1 * max(max(dtr_day_box_sahara));
% ylim([-1 ylim_max]); %ylim([ylim_min ylim_max]);

%legend({'Corr OMOS','-',},'Location','northwest','FontSize',3,'Orientation','horizontal');
%set(legend,  'fontsize', 3, 'Position', [0.4, 0.7, 0.01, 0.01]);
%set(legend,  'fontsize', 3, 'Position', [0.20, 0.16, 0.01, 0.01]);




%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%





