clear all


clear
load colorbars
mask=load('~/grilles_lmdz/mask1deg.txt');
latitude=load('~/grilles_lmdz/lat_mid_CFMIP1.txt');
longitude=load('~/grilles_lmdz/lon_mid_CFMIP1.txt');
mask=mask';

%figure

fid=fopen('/homedata/gcesana/DEPOL_restore/DEPOL/GEWEX/listcaptphab');
 c=textscan(fid,'%s','delimiter','');
 list=c{1};

fid=fopen('/homedata/gcesana/DEPOL_restore/DEPOL/GEWEX/listcaptpha2b');
 c=textscan(fid,'%s','delimiter','');
 list2=c{1};


map=colormap(jet(length(list)));
%map(5,:)=map(6,:);
%map(6,:)=[1 0.4 0.4];

for i = 1:length(list)


fid=fopen('/homedata/gcesana/DEPOL_restore/DEPOL/GEWEX/listvar2');
 c=textscan(fid,'%s','delimiter','');
 listvar=c{1};

clear a_CT a_CAI a_CAW tot tot2
for j = 1:length(listvar)
  ncload5(['/bdd/ARA/GEWEX_CA_ftp/netcdf_data_v2/',[list{i}],'/2007/',[listvar{j}],'_',[list2{i}]])
['/bdd/ARA/GEWEX_CA_ftp/netcdf_data_v2/',[list{i}],'/2007/',[listvar{j}],'_',[list2{i}]],['a_',[listvar{j}]]
end

list2{i}

a_CT(a_CT==-999 | a_CT==-777)=nan;
%CA=squeeze(nanmean(a_CA,1));
a_CAI(a_CAI==-999 | a_CAI==-777)=nan;
%CAI=squeeze(nanmean(a_CAI,1));
a_CAW(a_CAW==-999 | a_CAW==-777)=nan;
%CAW=squeeze(nanmean(a_CAW,1));
%tmp(1,:,:,:)=a_CAW;
%tmp(2,:,:,:)=a_CAI;
%a_TRA=a_CAI./squeeze(nansum(tmp,1));
%TRA=squeeze(nanmean(a_TRA,1));


%ncload /bdd/ARA/GEWEX_CA_ftp/netcdf_data_v2/MODIS-CE/2007/CT_MODIS-CE_AQU_0130AM_2007.nc a_CT  
%ncload /bdd/ARA/GEWEX_CA_ftp/netcdf_data_v2/MODIS-CE/2007/CAW_MODIS-CE_AQU_0130AM_2007.nc a_CAW  
%ncload /bdd/ARA/GEWEX_CA_ftp/netcdf_data_v2/MODIS-CE/2007/CAI_MODIS-CE_AQU_0130AM_2007.nc a_CAI
%ncload /bdd/ARA/GEWEX_CA_ftp/netcdf_data_v2/ISCCP/2007/CAI_ISCCP_D1_0300AM_2007.nc a_CAI
%ncload /bdd/ARA/GEWEX_CA_ftp/netcdf_data_v2/ISCCP/2007/CT_ISCCP_D1_0300AM_2007.nc a_CT
%ncload /bdd/ARA/GEWEX_CA_ftp/netcdf_data_v2/ISCCP/2007/CAW_ISCCP_D1_0300AM_2007.nc a_CAW

parlow=[0:0.05:1];
a_CAI(a_CAI==-999)=nan;
a_CAW(a_CAW==-999)=nan;
a_CAI(a_CAI==-777)=nan;
a_CAW(a_CAW==-777)=nan;
a_CT(a_CT==-999)=nan;
a_CT(a_CT==-777)=nan;
a_CT(a_CT<228.15)=nan;
a_CT(a_CT>278.15)=nan;
%load /home/gcesana/grilles_lmdz/mask1deg
%mask=mask';

figure(2)
subplot(2,3,i)
pcolor(squeeze(nanmean(a_CAI,3))');shading flat;

for w=1:12
caitmp=squeeze(a_CAI(:,:,w));
caitmp(mask==1)=nan;
a_CAI(:,:,w)=caitmp;

cawtmp=squeeze(a_CAW(:,:,w));
cawtmp(mask==1)=nan;
a_CAW(:,:,w)=cawtmp;
clear caitmp cawtmp
end

tot(1,:,:,:)=a_CAI;
tot(2,:,:,:)=a_CAW;
tot=squeeze(nansum(tot,1));
tot2=a_CAI./tot;




array1=a_CT(:);
array2=tot2(:);
validdata1 = ~isnan(array1);
validdata2 = ~isnan(array2);
validdataBoth = validdata1 & validdata2;
keep1 = array1(validdataBoth) ;
keep2 = array2(validdataBoth) ;

eq=polyfit(keep2, keep1, 3);
perlow=polyval(eq,parlow);
figure(1)
plot(perlow,parlow,'-.','color',map(i,:),'linewidth',2)
hold on

tatax(i,:)=perlow;
tatay(i,:)=parlow;

end


grid on
set(gca,'yminortick','on')
set(gca,'xminortick','on')
set(gcf,'color','white')
box on
set(gca,'xtick',[273.15-45:5:273.15+10],'xticklabel',[-45:5:10],'fontname','times','fontsize',14)
set(gca,'ytick',[0:0.1:1],'yticklabel',[0:10:100],'fontname','times','fontsize',14)
axis([273.15-45 273.15+10 0 1])
set(gca,'color','none')
set(gcf,'color','none')
set(gcf,'renderer','zbuffer') 

break
clear tot
%%%%% GOCCP GEWEX  %%%%%%%%%
ncload /bdd/CFMIP/GOCCP/GEWEX/MapLowMidHigh_Phase330m_2007_night_CFMIP1_sat_2.92.nc
ncload /bdd/CFMIP/GOCCP/GEWEX/MapLowMidHigh330m_2007_night_CFMIP1_sat_2.92.nc CTcalipso   

CTcalipso(CTcalipso==-9999)=nan;               
cltcalipso_liq(cltcalipso_liq==-9999)=nan;
cltcalipso_ice(cltcalipso_ice==-9999)=nan;
CTcalipso(CTcalipso<228.15)=nan;
CTcalipso(CTcalipso>278.15)=nan;

tot(1,:,:,:)=cltcalipso_ice;
tot(2,:,:,:)=cltcalipso_liq;

tot=squeeze(nansum(tot,1));
tot2=cltcalipso_ice./tot;


array1=CTcalipso(:);
array2=tot2(:);
validdata1 = ~isnan(array1);
validdata2 = ~isnan(array2);
validdataBoth = validdata1 & validdata2;
keep1 = array1(validdataBoth) ;
keep2 = array2(validdataBoth) ;

eq=polyfit(keep2, keep1, 3);
perlow=polyval(eq,parlow);
plot(perlow,parlow,'color','red','linewidth',4)
hold on


%%%%%%%%%% JAXA %%%%%%%%%%%%%
load /homedata/gcesana/phasetempgewex/jaxa_phasetemp_2007CFMIP1.mat
plot(jaxa(1,:)+273.15,jaxa(2,:),'--','color',[1 0.7 0.7],'linewidth',4)


%%%%%%%%%%   STANDARD GOCCP %%%%%%%%%%%%
load /homedata/gcesana/DEPOL_restore/DEPOL/phasetemperature2007CFMIP1.mat
tempmid=[-91.5:3:21.5];
parlow=[0:0.05:1];
%plot(tempmid+273.15,icefrac,'red-')
  icefrac(18)=1;
%  icefrac(19)=1;
  icefrac(31)=0;

array1=tempmid(18:31)';
array2=icefrac(18:31);
validdata1 = ~isnan(array1);
validdata2 = ~isnan(array2);
validdataBoth = validdata1 & validdata2;
keep1 = array1(validdataBoth) ;
keep2 = array2(validdataBoth) ;

eq=polyfit(keep2, keep1, 3);
perlow=polyval(eq,parlow);
%figure
plot(perlow+273.15,parlow,'red--','linewidth',4)
hold on



%%%%%%%% INSITU %%%%%%%%%%
clear tot
load /homedata/gcesana/insitu/tot.mat
tot(18)=1;
plot(tempmid(18:32)+273.15,tot(18:32),'.-','color','magenta','linewidth',2)



%%%%%%%%%% LMDZ PARAM %%%%%%%%%%%
  plot([258.15 273.15],[1 0],'black--','linewidth',2)

%plot([273 273],[0 1],'black--')
%plot([233 233],[0 1],'black--')
%plot([210 290],[0.5 0.5],'black--')


  axis([228 278 0 1])
  set(gca,'xtick',[223.15:5:283.15],'xticklabel',[-50:5:10])
  set(gca,'tickdir','out')
  legend('MODIS-ST','MODIS-CE','PATMOSX','AIRS','ISCCP','CALIPSO-ST','CALIPSO-GOCCP','CALIPSO-RIAM','CALIPSO-GOCCP','InSitu','LMDZ5B param')


