clear
list=[{'2007-05-16T13-00-47ZD'},{'2007-05-26T11-59-33ZD'},{'2007-05-25T12-55-10ZD'},{'2007-04-09T09-21-04ZD'},{'2007-04-07T09-33-08ZD'},{'2008-04-01T10-21-32ZD'},{'2008-04-10T10-16-30ZD'}];
tempmod=[-93:3:21];
tempmid=[-40.5:3:1.5];

for i=1:length(list)
filename=['/bdd/CFMIP/GOCCP/instant_SR_CR_DR/temp/instant_SR_CR_DR_',list{i},'_day_CFMIP2_2.90.nc']
ncload5(filename);

yya=find(latitude<70);
zza=find(alt_mid>5.2| alt_mid<0.);
zzm=find(alt_mid>12.5 | alt_mid<6.);
yym=find(latitude>55 | latitude<40);

TEMPa=TEMP;
TEMPm=TEMP;

TEMPa(zza,:)=nan;
TEMPa(:,yya)=nan;

TEMPm(zzm,:)=nan;
TEMPm(:,yym)=nan;

indICE=find(instant_Phase==6 | instant_Phase==2 | instant_Phase==4);
indLIQ=find(instant_Phase==5 | instant_Phase==1);

ICEa(:,i)=hist(TEMPa(indICE),tempmid);
LIQa(:,i)=hist(TEMPa(indLIQ),tempmid);


ICEm(:,i)=hist(TEMPm(indICE),tempmid);
LIQm(:,i)=hist(TEMPm(indLIQ),tempmid);

end

icetota=squeeze(nansum(ICEa,2));
liqtota=squeeze(nansum(LIQa,2));

icetotm=squeeze(nansum(ICEm,2));
liqtotm=squeeze(nansum(LIQm,2));

%plot(tempmod,ICE./(ICE+LIQ),'linewidth',2)
tempmid=[-40.5:3:1.5];

hold on
plot(tempmid,icetotm./(icetotm+liqtotm),'red--','linewidth',2)
plot(tempmid,icetota./(icetota+liqtota),'red-','linewidth',2)

%phasegoccp=icetot./(icetot+liqtot);
%save phasegoccp.mat phasegoccp

%%%%%%%%%%%%%% JAXA %%%%%%%%%%%%%%%%%%%
clear

tempmod=[-93:3:21];
tempmid=[-40.5:3:1.5];

list=[{'20070516'},{'20070526'},{'20070525'},{'20070409'},{'20070407'} ,{'20080401'},{'20080410'}];
list2=[{'instant_JAXA_20070516_8.nc'} {'instant_JAXA_20070526_7.nc'} {'instant_JAXA_20070525_8.nc'} {'instant_JAXA_20070409_6.nc'} {'instant_JAXA_20070407_6.nc'} {'instant_JAXA_20080401_4.nc'} {'instant_JAXA_20080410_6.nc'}];
for i=1:length(list)
%if i > 3
%filename=['/homedata/gcesana/insitu/arctic/JAXA_',list{i},'.mat']
%load(filename)
%else
%filename=['/homedata/gcesana/insitu/midlat/JAXA_',list{i},'.mat']
%load(filename)
%end
filename2=['/bdd/CFMIP/GOCCP/temp/',list2{i}]
ncload5(filename2)

alt_mid=0.12:0.24:19.8;
latitude=lat;

instant_JAXA=double(instant_Cloud)';
instant_Temp=instant_Temp';

instant_Cloudj=instant_JAXA; 
 instant_JAXA(instant_Cloudj==2)=1;
 instant_JAXA(instant_Cloudj==5)=2;
 instant_JAXA(instant_Cloudj==4)=2;
 instant_JAXA(instant_Cloudj==3)=2;
 instant_JAXA(instant_Cloudj==6)=3;
 instant_JAXA(instant_Cloudj==7)=-1;

indICE=find(instant_JAXA==2);
indLIQ=find(instant_JAXA==1);

instant_Temp(instant_Temp<0)=nan;
instant_Temp=instant_Temp-273.15;
instant_Temp=instant_Temp';
instant_Temp(daynight<1)=nan;

yya=find(latitude<70);
zza=find(alt_mid>5.2| alt_mid<0.);
zzm=find(alt_mid>12.5 | alt_mid<6.);
yym=find(latitude>55 | latitude<40);

TEMPa=instant_Temp;
TEMPm=instant_Temp;

TEMPa(zza,:)=nan;
TEMPa(:,yya)=nan;

TEMPm(zzm,:)=nan;
TEMPm(:,yym)=nan;

ICEa(:,i)=hist(TEMPa(indICE),tempmid);
LIQa(:,i)=hist(TEMPa(indLIQ),tempmid);

ICEm(:,i)=hist(TEMPm(indICE),tempmid);
LIQm(:,i)=hist(TEMPm(indLIQ),tempmid);

%ICE(:,i)=hist(instant_Temp(indICE),tempmod);
%LIQ(:,i)=hist(instant_Temp(indLIQ),tempmod);
end

icetota=squeeze(nansum(ICEa,2));
liqtota=squeeze(nansum(LIQa,2));

icetotm=squeeze(nansum(ICEm,2));
liqtotm=squeeze(nansum(LIQm,2));

%tempmid=[-91.5:3:22.5];
plot(tempmid,icetotm./(icetotm+liqtotm),'green--','linewidth',2)
plot(tempmid,icetota./(icetota+liqtota),'green-','linewidth',2)


%phasejaxa=icetot./(icetot+liqtot);
%save phasejaxa.mat phasejaxa

%%%%%%%%%%%%%%%% ST %%%%%%%%%%%%%%%%%%
clear
tempmod=[-93:3:21];
tempmid=[-40.5:3:1.5];
alt_mid=0.24:0.48:19.8;

list=[{'20070516'},{'20070526'},{'20070525'},{'20070409'},{'20070407'}, {'20080401'}, {'20080410'}];
list2=[{'2007-05-16T13-00-47ZD'},{'2007-05-26T11-59-33ZD'},{'2007-05-25T12-55-10ZD'},{'2007-04-09T09-21-04ZD'},{'2007-04-07T09-33-08ZD'}, {'2008-04-01T10-21-32ZD'}, {'2008-04-10T10-16-30ZD'}];
list3=[{'2007-05-16T13-00-47_D'},{'2007-05-26T11-59-33_D'},{'2007-05-25T12-55-10_D'},{'2007-04-09T09-21-04_D'},{'2007-04-07T09-33-08_D'}, {'2008-04-01T10-21-32_D'}, {'2008-04-10T10-16-30_D'}];

for i=1:length(list)
%filename2=['/bdd/CFMIP/GOCCP/instant_SR_CR_DR/temp/instant_SR_CR_DR_',list2{i},'_day_CFMIP2_2.90.nc']
%ncload5(filename2);

%if i > 3
filename=['/bdd/CFMIP/GOCCP/upload/CALIPSO_ST/',list3{i},'.nc']
ncload5(filename)
%else
%filename=['/homedata/gcesana/insitu/midlat/',list3{i},'.nc']
%ncload5(filename)
%end
phaseST=ice_cloud_fraction(1:40,:)./(ice_cloud_fraction(1:40,:)+water_cloud_fraction(1:40,:)); 

%if i == 3
%TEMP2=TEMP(:,1:63120);
%else
%TEMP2=TEMP(:,1:63360);
%end

%clear TEMP
TEMP=midlayer_temperature(1:40,:);

tot=ice_cloud_fraction+water_cloud_fraction;
titi=find(ice_cloud_fraction==0 & water_cloud_fraction>0);

ice=ice_cloud_fraction;
ice(titi)=0;
fraction_ST=ice./tot;

fractionnan=isnan(fraction_ST);
fraction_ST(fractionnan==1 & signal_attenuation==0)=nan;
fractionnan2=isnan(fraction_ST);
fraction_ST(fractionnan2==1)=nan;

fraction_ST2=fraction_ST(1:40,:);
clear fraction_ST
fraction_ST=fraction_ST2;

indICE=find(fraction_ST>0.5);
indLIQ=find(fraction_ST<0.5);

%if i == 3
%TEMP2=TEMP(:,1:63120);
%else
%TEMP2=TEMP(:,1:63360);
%end

%clear TEMP
%TEMP=TEMP2;

yya=find(latitude<70);
zza=find(alt_mid>5.2 | alt_mid<0.);
zzm=find(alt_mid>12.5 | alt_mid<6.);
yym=find(latitude>55 | latitude<40);

TEMPa=TEMP;
TEMPm=TEMP;

TEMPa(zza,:)=nan;
TEMPa(:,yya)=nan;

TEMPm(zzm,:)=nan;
TEMPm(:,yym)=nan;

ICEa(:,i)=hist(TEMPa(indICE),tempmid);
LIQa(:,i)=hist(TEMPa(indLIQ),tempmid);

ICEm(:,i)=hist(TEMPm(indICE),tempmid);
LIQm(:,i)=hist(TEMPm(indLIQ),tempmid);
end

icetota=squeeze(nansum(ICEa,2));
liqtota=squeeze(nansum(LIQa,2));

icetotm=squeeze(nansum(ICEm,2));
liqtotm=squeeze(nansum(LIQm,2));


plot(tempmid,icetotm./(icetotm+liqtotm),'blue--','linewidth',2)
plot(tempmid,icetota./(icetota+liqtota),'blue-','linewidth',2)
axis([-45 5 0 1])
%phasest=icetot./(icetot+liqtot);
%save phasest.mat phasest


