clear
set(0, 'defaultaxesfontname', 'Times');
set(0, 'defaulttextfontname', 'Times');
set(0,'defaultaxesfontsize',12);
set(0,'defaulttextfontsize',12);

C1=3; D1=0.0576;
eq_liq1=[C1 D1 0];

C=1.3919; D=0.0176;
eq_liq=[C D 0];

A=0.2904; B=0   ;  
eq_ice=[A B];

E=0.1667;   F=-0.0100;
eq_hoi=[E F];

parlow=[0:0.001:0.17];
parhigh=[0:0.001:0.06];


load eq50new
load /homedata/gcesana/insitu/midlat/fraction_ST_20070526.mat
load colorbars2

%%% CALIPSO OVERPASS A 13.561 13h33m66
%%% -43s +9m54s
%ncload('/homedata/gcesana/insitu/midlat/instant_SR_CR_DR_2007-05-26T11-59-33ZD_day_CFMIP2_2.71.nc');
ncload('/bdd/CFMIP/GOCCP/instant_SR_CR_DR/temp/instant_SR_CR_DR_2007-05-26T11-59-33ZD_day_CFMIP2_2.90.nc');
toto=load('/homedata/gcesana/insitu/midlat/070526.txt');

titre='c) 2007-05-26';

%%%% CALIOP L1 %%%
atb532=hdfread('/bdd/CALIPSO/Lidar_L1/CAL_LID_L1.v3.01/2007/2007_05_26/CAL_LID_L1-ValStage1-V3-01.2007-05-26T11-59-33ZD.hdf','Total_Attenuated_Backscatter_532');
alt583=load('~/grilles_lmdz/alt');

alt=[0:0.48:19.2];
lat=fix(latitude*10)/10;  


colorphase=[1 1 1; 0 0 0.8; 1 0 0; 0 0.7 0; 0.4 0 0; 0 0.6667 1; 1 1 0; 0.3 0.3 0.3];   

colorphase3=[1 1 1;0 0 0; 0.8 0.8 0.8;0 0 0.8; .8 0 0; 0 0.5 0];
colorinstant=[1 1 1; 0.8 0.8 0.8; 01 0 0; 1 0.6 0.6; 0 0 0];
coloratb=[1 1 1; 0.8 0.8 0.8; 1 0.6 0.6; 1 0 0; 0.5 0 0];
colorphase=[1 1 1; 0 0 0.8; 1 0 0; 0 0.7 0; 0.4 0 0; 0 0.6667 1; 1 1 0; 0.3 0.3 0.3];   
colorphase3=[0.8 0.8 0.8;0 0 0; 1 1 1;0.8 0 0; 0 0 0.8; 0 0.5 0];
colorinstant=[0.8 0.8 0.8; 1 1 1; 01 0 0; 1 0.6 0.6; 0 0 0];
coloratb=[1 1 1; 0.8 0.8 0.8; 1 0.6 0.6; 1 0 0; 0.5 0 0];

%1=LIQ, 2=ICE, 3=UNDEFINED, 4=FALSE LIQ, 5=FALSE ICE, 6=Horizontally Oriented, 7=Unphysical value (NOISE)" ;


%instant_Phase(instant_Phase==0)=nan;
Phase(1:length(latitude),1:41)=0;
instant_Cloud(instant_Cloud==7)=1; instant_Cloud(instant_Cloud==6)=1;
instant_Phase(instant_Cloud==8)=-1;
instant_Phase(instant_SR<-776)=-2;
Phase(:,1:40)=instant_Phase;
Phase(Phase==4)=2;
Phase(Phase==5)=1;
Phase(Phase==6)=2;

lim0=(12+32/60)-1/60;
lim00=(12+32/60)-4/60;


lim1=(12+32/60)+2.5/60;
lim2=(12+32/60)+7.5/60;

asym=toto(:,9);
asym(asym==0)=nan;       
ext=toto(:,8);
temp=toto(:,6);   
 lati=toto(:,3);   
 longi=toto(:,4);   
 alti=toto(:,2);   
 heure=toto(:,1);
heure=heure/3600;

%heure(heure<12.2)=nan;    ok
heure(heure>lim2)=nan;  %   ok
heure(heure<12.2)=nan;  %ok
heure(heure>12.39 & heure<lim00)=nan;
heure(heure>lim0 & heure<lim1)=nan;   %ok
heure(heure>lim2)=nan;  %   ok


%heure(heure<lim1)=nan;    ok
%heure(heure>lim2)=nan;    ok

%%%heure(heure<lim00)=nan; 
%%%heure(heure>lim2)=nan;  %   ok

%heure(heure<lim00)=nan; 


%heure(heure>lim0)=nan;    %ok

%heure(longi>-5.7)=nan;
%heure(longi<-6.1)=nan;

%heure(lati>42.9)=nan;
%heure(lati<41.9)=nan;
heure(lati>48.8)=nan;

heure(heure<(12+32/60-1/6))=nan;
heure(heure>(12+32/60+1/6))=nan;

titi=isnan(heure);
asym(titi==1)=nan;
ext(titi==1)=nan;
temp(titi==1)=nan;
longi(titi==1)=nan;
lati(titi==1)=nan;

xx=find(latitude>min(lati) & latitude <max(lati) & latitude > 0);
xxbis=find(latitude>min(lati)-1 & latitude <max(lati)+1 & latitude > 0);
xx2=find(lati>0);


%%%%%%%%%%%%%%%%%%%%% PROFILES CALIOP %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
figure(1)
subplot(3,3,3)
    plot(0,0,'x','color',[0 0.667 1],'markersize',4)
 hold on
   plot(0,0,'x','color','magenta','markersize',4)
    plot(0,0,'x','color','yellow','markersize',4)
    plot(0,0,'.','color','black','markersize',4)
h=legend('Ice','Liq','Mixed','Clear','location','northeast','fontsize',10);
u=get(h,'Children');
set(u(6),'color','yellow');
set(u(9),'color','magenta');
set(u(12),'color',[0 0.667 1]);

pcolor(latitude(xx),alt,Phase(xx,:)');
shading flat;
set(gca,'tickdir','out')
set(gcf,'color','white')
caxis([-2.1 3.9])
title('(a)','fontweight','bold','fontsize',12)
colormap(colorphase3)
%xlabel('Latitude (\circN)','fontweight','bold','fontsize',12)
colorbar('west','FontSize',10,'Ytick',[-1.5:1:3.5],'YTickLabel',{'Rejected','Attenuated','Clear/Uncert','Liquid','Ice','Undef-Phase'})
axis([48.4 49.15 10 13])
axis([45.900   47.3500    9.5000   12.0000])  
axis([48.2 48.8 8 11.5])


for i =1:41                            
plot([45 50],[alt(i) alt(i)],'black--')   
end

freezecolors
cbfreeze('on')

%%%%%%%%%%%%%%%%%%% AIRCRAFT OVERPASS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
xx2=find(lati>0);
ind=0;
n=0;
for i=1:length(xx2)
 i=xx2(i);
 if ext(i)>0.02 
     n=n+1;
    if asym(i)<0.8 & asym(i)>0.7
        plot(lati(i),alti(i)/1000,'x','color',[0 0.667 1],'markersize',4)
        elseif asym(i)>=0.8  & asym(i)<0.83
        plot(lati(i),alti(i)/1000,'x','color',[0 0.667 1],'markersize',4)
        elseif asym(i)>=0.83  & asym(i)<0.9
        plot(lati(i),alti(i)/1000,'x','color','magenta','markersize',4)
    end
 else
 
          plot(lati(i),alti(i)/1000,'.','color','black','markersize',4)
 end

end





phasest=[0 0 0; 0 0 1; 1 0.55 0; 1 0 0];

%%%%%%%%%%%%%%%%%%%%% SR PROFILES CALIOP %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
figure(1)
subplot(3,3,6)
    plot(0,0,'x','color',[0 0.667 1],'markersize',4)
 hold on
pcolor(latitude(xx),alt(1:40),fraction_ST(xx,1:40)');
shading flat;
set(gca,'tickdir','out')
caxis([-2. 1.5]) 
title('(b)','fontweight','bold','fontsize',12)
load colorbars
colormap(phasest)
ylabel('Height (km)','fontweight','bold','fontsize',12)
colorbar('west','FontSize',10,'Ytick',[-1.5:0.7:1.5],'YTickLabel',{'Att','Clear','Liq','Mixte','Ice'})
axis([48.4 49.15 10 13])
axis([45.900   47.3500    9.5000   12.0000])  
axis([48.2 48.8 8 11.5])

for i =1:41                            
plot([45 50],[alt(i) alt(i)],'black--')   
end


freezecolors
cbfreeze('on')


%%%%%%%%%%%%%%%%%%% AIRCRAFT OVERPASS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
xx2=find(lati>0);
ind=0;
n=0;
for i=1:length(xx2)
 i=xx2(i);
 if ext(i)>0.02
    n=n+1;
    if asym(i)<0.8 & asym(i)>0.7
        plot(lati(i),alti(i)/1000,'x','color',[0 0.667 1],'markersize',4)
        elseif asym(i)>=0.8  & asym(i)<0.83
        plot(lati(i),alti(i)/1000,'x','color',[0 0.667 1],'markersize',4)
        elseif asym(i)>=0.83  & asym(i)<0.9
        ind=ind+1;
        plot(lati(i),alti(i)/1000,'x','color','magenta','markersize',4)
    end
 else
 plot(lati(i),alti(i)/1000,'.','color','black','markersize',4)
 end 
end





load /homedata/gcesana/insitu/midlat/JAXA_20070526.mat
titi=find(daynight<1);
lat_JAXA(titi)=nan;
xx3=find(lat_JAXA<48.8 & lat_JAXA>48.2);
alt_JAXA=[0:0.240:19.92];
instant_Cloudj=instant_JAXA; 

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


%-1= nan; 0=clear 1=water 2=water 3=ice 4=ice 5=ice 6=undef 7=missing
figure(1)
subplot(3,3,9)
    plot(0,0,'x','color',[0 0.667 1],'markersize',4)
 hold on

pcolor(lat_JAXA(xx3),alt_JAXA(1:83),instant_JAXA(xx3,1:83)');
shading flat;
set(gca,'tickdir','out')
caxis([-1 3])
 
title('(c)','fontweight','bold','fontsize',12)
load colorbars
colormap(colorjaxa)
ylabel('Height (km)','fontweight','bold','fontsize',12)
colorbar('west','FontSize',10,'Ytick',[-.5:1:2.5],'YTickLabel',{'Miss','Clear','Liq','Ice','Uncert'})
axis([48.4 49.15 10 13])
axis([45.900   47.3500    9.5000   12.0000])  
axis([48.2 48.8 8 11.5])

for i =1:41                            
plot([45 50],[alt(i) alt(i)],'black--')   
end


freezecolors
cbfreeze('on')





xx2=find(lati>0);
ind=0;
n=0;
for i=1:length(xx2)
 i=xx2(i);
 if ext(i)>0.02 
    n=n+1;
    if asym(i)<0.8 & asym(i)>0.7
        plot(lati(i),alti(i)/1000,'x','color',[0 0.667 1],'markersize',4)
        elseif asym(i)>=0.8  & asym(i)<0.83
        plot(lati(i),alti(i)/1000,'x','color',[0 0.667 1],'markersize',4)
        elseif asym(i)>=0.83  & asym(i)<0.9
        plot(lati(i),alti(i)/1000,'x','color','magenta','markersize',4)
    end
 else
 plot(lati(i),alti(i)/1000,'.','color','black','markersize',4)
 end
 
end

freezecolors
cbfreeze('on')



instant_Phase(instant_SR<0.01 | instant_Cloud==8)=-9999;
%instant_Cloud(instant_SR>1.2 & instant_SR<5)=4;
alt=[0:480:19200];

n=0;
n2=0;

differ=0;   %% difference clear cloud
nanval=0;   %% nanval
check=0;    %% control doit etre 0
cloudy=0;   %% nb de prof en accord nuage
attcld=0;   %% un nuage au dessus
valSR=0;    %% valeur de SR du pixel colloc
uncert=0;
clearuncert=0;
clearnan=0;

liqliq=0;
liqmixed=0;
liqice=0;

iceliq=0;
iceice=0;
icemixed=0;

undefice=0;
undefliq=0;
undefmixed=0;

noiseliq=0;
noiseice=0;
noisemixed=0;

clearok=0;
cleardiff=0;
clearatt=0;


differice=0;
differmix=0;
differliq=0;

liqiceasym=0;
iceliqasym=0;




for i=1:length(xx2) 
i=xx2(i);
for j=1:length(xx)
j=xx(j);
if lati(i)>= latitude(j) & lati(i) < latitude(j+1) 

   if ext(i)>0.02  & asym(i)<0.9 & asym(i)>0.7
        n=n+1;

       for k=18:26
	  if alti(i) > alt(k) & alti(i)<= alt(k+1)
          if instant_Cloud(j,k) ==2  %%% CLEAR
            differ=differ+1;
                 if asym(i)<0.8 & asym(i)>0.7 %% ICE
                    differice=differice+1;
                 elseif asym(i)>=0.8  & asym(i)<0.83  %% MIXED
                    differmix=differmix+1;
                 elseif asym(i)>=0.83  & asym(i)<0.9  %% LIQ
                    differliq=differliq+1;
                 end           
            valSR(n)=instant_SR(j,k);
                if any(instant_Cloud(j,k:40) ==3)
                attcld(n)=1;
                end
          elseif instant_Cloud(j,k) == 1 | instant_Cloud(j,k) == 6 | instant_Cloud(j,k) == 7 | instant_Cloud(j,k) == 8       %%% NAN
            nanval=nanval+1;
          elseif instant_Cloud(j,k) == 4   %%% UNCERT
            uncert=uncert+1;
          elseif instant_Cloud(j,k) == 3   %%% Cloud
            cloudy=cloudy+1;

          if instant_Phase(j,k) == 1 |  instant_Phase(j,k) == 5 %% LIQ
            if asym(i)<0.8 & asym(i)>0.7 %% ICE
              liqice=liqice+1;
	      liqiceasym(n)=asym(i);
              plot(ATB(j,k),ATB_per(j,k),'redx');
             if  asym(i)>0.79
                plot(ATB(j,k),ATB_per(j,k),'blackx');   
              end

            elseif asym(i)>=0.8  & asym(i)<0.83  %% MIXED
              liqmixed=liqmixed+1;
              plot(ATB(j,k),ATB_per(j,k),'.','color',[0 0.8 0]);
            elseif asym(i)>=0.83  & asym(i)<0.9  %% LIQ
              liqliq=liqliq+1;
              plot(ATB(j,k),ATB_per(j,k),'blueo');
            end
          elseif instant_Phase(j,k) == 2 |  instant_Phase(j,k) == 4  |  instant_Phase(j,k) == 6 %% ICE
            if asym(i)<0.8 & asym(i)>0.7 %% ICE
              iceice=iceice+1;
              plot(ATB(j,k),ATB_per(j,k),'redo');
            elseif asym(i)>=0.8  & asym(i)<0.83  %% MIXED
              icemixed=icemixed+1;
              plot(ATB(j,k),ATB_per(j,k),'.','color',[1 1 0]);
            elseif asym(i)>=0.83  & asym(i)<0.9  %% LIQ
              iceliq=iceliq+1;
	      iceliqasym(n)=asym(i);
              plot(ATB(j,k),ATB_per(j,k),'bluex');


            end
          elseif instant_Phase(j,k) == 3  |  instant_Phase(j,k) == 7 %% UNDEF
            if asym(i)<0.8 & asym(i)>0.7 %% ICE
              undefice=undefice+1;
              plot(ATB(j,k),ATB_per(j,k),'red.');
            elseif asym(i)>=0.8  & asym(i)<0.83  %% MIXED
              undefmixed=undefmixed+1;
              plot(ATB(j,k),ATB_per(j,k),'.','color',[1 0.55 0]);
            elseif asym(i)>=0.83  & asym(i)<0.9  %% LIQ
              undefliq=undefliq+1;
              plot(ATB(j,k),ATB_per(j,k),'blue.');
            atbundef(i)=ATB(j,k);
              atbperpundef(i)=ATB_per(j,k);
  
            end
          else
            check=check+1;
          end



          end
          end
       end

   else    %%% AVION CLOUD condition  
     n2=n2+1;
        for k=18:26
        if alti(i) > alt(k) & alti(i)<= alt(k+1)
            if instant_Cloud(j,k) == 3
               cleardiff=cleardiff+1;
               if instant_Cloud(j,k+1) == 3 
                  clearatt=clearatt+1;
               end
            elseif instant_Cloud(j,k) == 2
              clearok=clearok+1;
            elseif instant_Cloud(j,k) == 4
              clearuncert=clearuncert+1;
            else
              clearnan=clearnan+1;
            end
        end
        end

    end  %% cloud aircraft


end
end
end


tot=cloudy+uncert+differ+clearok+clearuncert+cleardiff;
n-(cloudy+nanval+uncert+differ)
n2-(cleardiff+clearnan+clearok+clearuncert)


[{'GOCCP'}]
[{'GOCCP'}]
[{'GOCCP'}]

[{''}]
[{''}]
[{'Detection'}]
[{'diff'} (cleardiff+differ+uncert)*100/tot ] %% difference de detection
[{'diff Aclear/Ccloud'} cleardiff*100/tot ] %% difference de detection
[{'diff Acloud/Cclear'} differ*100/tot ] %% difference de detection
[{'diff Acloud/Cuncert'} uncert*100/tot ] %% difference de detection
[{''}]
[{'Ok'} (cloudy+clearok+clearuncert)*100/tot ] %% difference de detection
[{'Ok Acloud/Ccloud'} cloudy*100/tot ] %% difference de detection
[{'Ok Aclear/Cclear'} clearok*100/tot ] %% difference de detection
[{'Ok Aclear/Cuncert'} clearuncert*100/tot ] %% difference de detection
[{''}]
[{''}]
[{'Phase'}]
[{'Diff'} (liqice+iceliq)*100/(cloudy)]  %% fausse attribution phase
[{'Aliq/Cice'} (iceliq)*100/(cloudy)]  %% fausse attribution phase
[{'Aice/Cliq'} (liqice)*100/(cloudy)]  %% fausse attribution phase
[{''}]
[{'Ok'} (liqliq+iceice+liqmixed+icemixed)*100/cloudy]  %% bonne phase
[{'Liq'} (liqliq)*100/cloudy]  %% bonne phase
[{'Ice'} (iceice)*100/cloudy]  %% bonne phase
[{'MixLiq'} (liqmixed)*100/cloudy]  %% bonne phase
[{'MixIce'} (icemixed)*100/cloudy]  %% bonne phase
[{''}]
[{''}]
[{'Not sure'} (undefice+undefliq+undefmixed)*100/cloudy]  %% bonne phase
[{'Aliq/Cundef'} (undefliq)*100/cloudy]  %% bonne phase
[{'Aice/Cundef'} (undefice)*100/cloudy]  %% bonne phase
[{'Amix/Cundef'} (undefmixed)*100/cloudy]  %% bonne phase








clear instant_Cloud
clear instant_Phase

instant_Cloud=fraction_ST;
instant_Phase=fraction_ST;


alt=[0:480:19200];

n=0;
n2=0;

differ=0;   %% difference clear cloud
nanval=0;   %% nanval
check=0;    %% control doit etre 0
cloudy=0;   %% nb de prof en accord nuage
attcld=0;   %% un nuage au dessus
valSR=0;    %% valeur de SR du pixel colloc
uncert=0;
clearuncert=0;
clearnan=0;

liqliq=0;
liqmixed=0;
liqice=0;

iceliq=0;
iceice=0;
icemixed=0;

undefice=0;
undefliq=0;
undefmixed=0;

noiseliq=0;
noiseice=0;
noisemixed=0;

clearok=0;
cleardiff=0;
clearatt=0;


differice=0;
differmix=0;
differliq=0;

liqiceasym=0;
iceliqasym=0;




for i=1:length(xx2) 
i=xx2(i);
for j=1:length(xx)
j=xx(j);
if lati(i)>= latitude(j) & lati(i) < latitude(j+1) 

   if ext(i)>0.02 & asym(i)<0.9 & asym(i)>0.7
        n=n+1;

       for k=18:26
	  if alti(i) > alt(k) & alti(i)<= alt(k+1)
          if instant_Cloud(j,k) == -1 %%% CLEAR
            differ=differ+1;
                 if asym(i)<0.8 & asym(i)>0.7 %% ICE
                    differice=differice+1;
                 elseif asym(i)>=0.8  & asym(i)<0.83  %% MIXED
                    differmix=differmix+1;
                 elseif asym(i)>=0.83  & asym(i)<0.9  %% LIQ
                    differliq=differliq+1;
                 end           
         %   valSR(n)=instant_SR(j,k);
          elseif instant_Cloud(j,k) == -2  %%% NAN
            nanval=nanval+1;
          elseif instant_Cloud(j,k) == 1 | instant_Cloud(j,k) == 0  | instant_Cloud(j,k) == 0.5 %%% Cloud
            cloudy=cloudy+1;

          if instant_Phase(j,k) == 0 %% LIQ
            if asym(i)<0.8 & asym(i)>0.7 %% ICE
              liqice=liqice+1;
	      liqiceasym(n)=asym(i);
            elseif asym(i)>=0.8  & asym(i)<0.83  %% MIXED
              liqmixed=liqmixed+1;
            elseif asym(i)>=0.83  & asym(i)<0.9  %% LIQ
              liqliq=liqliq+1;
	    else
	       asym(i)
            end
          elseif instant_Phase(j,k) == 1 %% ICE
            if asym(i)<0.8 & asym(i)>0.7 %% ICE
              iceice=iceice+1;
            elseif asym(i)>=0.8  & asym(i)<0.83  %% MIXED
              icemixed=icemixed+1;
            elseif asym(i)>=0.83  & asym(i)<0.9  %% LIQ
              iceliq=iceliq+1;
	      iceliqasym(n)=asym(i);
	    else
	       asym(i)
            end
          elseif instant_Phase(j,k) == 0.5  %% UNDEF
            if asym(i)<0.8 & asym(i)>0.7 %% ICE
              undefice=undefice+1;
            elseif asym(i)>=0.8  & asym(i)<0.83  %% MIXED
              undefmixed=undefmixed+1;
            elseif asym(i)>=0.83  & asym(i)<0.9  %% LIQ
              undefliq=undefliq+1;
	    else
	       asym(i)
            end
          else
            check=check+1;
          end



          end
          end
       end

   else    %%% AVION CLOUD condition  
     n2=n2+1;
        for k=18:26
        if alti(i) > alt(k) & alti(i)<= alt(k+1)
           if instant_Cloud(j,k) == 1 | instant_Cloud(j,k) == 0  | instant_Cloud(j,k) == 0.5 %%% Cloud
               cleardiff=cleardiff+1;
              if instant_Cloud(j,k+1) == 1 | instant_Cloud(j,k+1) == 0  | instant_Cloud(j,k+1) == 0.5 %%% Cloud
                  clearatt=clearatt+1;
               end
            elseif instant_Cloud(j,k) ==-1
              clearok=clearok+1;
            else
              clearnan=clearnan+1;
            end
        end
        end

    end  %% cloud aircraft


end
end
end


tot=cloudy+uncert+differ+clearok+clearuncert+cleardiff;
n-(cloudy+nanval+uncert+differ)
n2-(cleardiff+clearnan+clearok+clearuncert)
[{'ST'}]
[{'ST'}]
[{'ST'}]

[{''}]
[{''}]
[{'Detection'}]
[{'diff'} (cleardiff+differ+uncert)*100/tot ] %% difference de detection
[{'diff Aclear/Ccloud'} cleardiff*100/tot ] %% difference de detection
[{'diff Acloud/Cclear'} differ*100/tot ] %% difference de detection
[{'diff Acloud/Cuncert'} uncert*100/tot ] %% difference de detection
[{''}]
[{'Ok'} (cloudy+clearok+clearuncert)*100/tot ] %% difference de detection
[{'Ok Acloud/Ccloud'} cloudy*100/tot ] %% difference de detection
[{'Ok Aclear/Cclear'} clearok*100/tot ] %% difference de detection
[{'Ok Aclear/Cuncert'} clearuncert*100/tot ] %% difference de detection
[{''}]
[{''}]
[{'Phase'}]
[{'Diff'} (liqice+iceliq)*100/(cloudy)]  %% fausse attribution phase
[{'Aliq/Cice'} (iceliq)*100/(cloudy)]  %% fausse attribution phase
[{'Aice/Cliq'} (liqice)*100/(cloudy)]  %% fausse attribution phase
[{''}]
[{'Ok'} (liqliq+iceice+liqmixed+icemixed)*100/cloudy]  %% bonne phase
[{'Liq'} (liqliq)*100/cloudy]  %% bonne phase
[{'Ice'} (iceice)*100/cloudy]  %% bonne phase
[{'MixLiq'} (liqmixed)*100/cloudy]  %% bonne phase
[{'MixIce'} (icemixed)*100/cloudy]  %% bonne phase
[{''}]
[{''}]
[{'Not sure'} (undefice+undefliq+undefmixed)*100/cloudy]  %% bonne phase
[{'Aliq/Cundef'} (undefliq)*100/cloudy]  %% bonne phase
[{'Aice/Cundef'} (undefice)*100/cloudy]  %% bonne phase
[{'Amix/Cundef'} (undefmixed)*100/cloudy]  %% bonne phase






[{'JAXA'}]
[{'JAXA'}]
[{'JAXA'}]

clear instant_Cloud instant_Phase
instant_Cloud=instant_JAXA;
instant_Phase=instant_JAXA;



alt=[0:240:19920];

n=0;
n2=0;

differ=0;   %% difference clear cloud
nanval=0;   %% nanval
check=0;    %% control doit etre 0
cloudy=0;   %% nb de prof en accord nuage
attcld=0;   %% un nuage au dessus
valSR=0;    %% valeur de SR du pixel colloc
uncert=0;
clearuncert=0;
clearnan=0;

liqliq=0;
liqmixed=0;
liqice=0;

iceliq=0;
iceice=0;
icemixed=0;

undefice=0;
undefliq=0;
undefmixed=0;

noiseliq=0;
noiseice=0;
noisemixed=0;

clearok=0;
cleardiff=0;
clearatt=0;


differice=0;
differmix=0;
differliq=0;

liqiceasym=0;
iceliqasym=0;


%-1= nan; 0=clear 1=water 2=ice 3=undef
for i=1:length(xx2) 
i=xx2(i);
for j=1:length(xx3)
j=xx3(j);

if lati(i)>= lat_JAXA(j) & lati(i) < lat_JAXA(j+1) 

   if ext(i)>0.02 & asym(i)<0.9 & asym(i)>0.7
        n=n+1;

       for k=35:52
	  if alti(i) > alt(k) & alti(i)<= alt(k+1)
          if instant_Cloud(j,k)  == 0 %%% CLEAR
            differ=differ+1;
                 if asym(i)<0.8 & asym(i)>0.7 %% ICE
                    differice=differice+1;
                 elseif asym(i)>=0.8  & asym(i)<0.83  %% MIXED
                    differmix=differmix+1;
                 elseif asym(i)>=0.83  & asym(i)<0.9  %% LIQ
                    differliq=differliq+1;
                 end           
       %     valSR(n)=instant_SR(j,k);
          elseif instant_Cloud(j,k) == -1  %%% NAN
            nanval=nanval+1;
          elseif instant_Cloud(j,k) == 1 | instant_Cloud(j,k) == 2  | instant_Cloud(j,k) == 3 %%% Cloud
            cloudy=cloudy+1;

          if instant_Phase(j,k) == 1 %% LIQ
            if asym(i)<0.8 & asym(i)>0.7 %% ICE
              liqice=liqice+1;
	      liqiceasym(n)=asym(i);
            elseif asym(i)>=0.8  & asym(i)<0.83  %% MIXED
              liqmixed=liqmixed+1;
            elseif asym(i)>=0.83  & asym(i)<0.9  %% LIQ
              liqliq=liqliq+1;
	    else
	       asym(i)
            end
          elseif instant_Phase(j,k) == 2 %% ICE
            if asym(i)<0.8 & asym(i)>0.7 %% ICE
              iceice=iceice+1;
            elseif asym(i)>=0.8  & asym(i)<0.83  %% MIXED
              icemixed=icemixed+1;
            elseif asym(i)>=0.83  & asym(i)<0.9  %% LIQ
              iceliq=iceliq+1;
	      iceliqasym(n)=asym(i);
	    else
	       asym(i)
            end
          elseif instant_Phase(j,k) == 3  %% UNDEF
            if asym(i)<0.8 & asym(i)>0.7 %% ICE
              undefice=undefice+1;
            elseif asym(i)>=0.8  & asym(i)<0.83  %% MIXED
              undefmixed=undefmixed+1;
            elseif asym(i)>=0.83  & asym(i)<0.9  %% LIQ
              undefliq=undefliq+1;
	    else
	       asym(i)
            end
          else
            check=check+1;
          end



          end
          end
       end

   else    %%% AVION CLOUD condition  
     n2=n2+1;
        for k=35:52
        if alti(i) > alt(k) & alti(i)<= alt(k+1)
           if instant_Cloud(j,k) == 1 | instant_Cloud(j,k) == 2  | instant_Cloud(j,k) == 3 %%% Cloud
               cleardiff=cleardiff+1;
              if instant_Cloud(j,k+1) == 2 | instant_Cloud(j,k+1) == 1  | instant_Cloud(j,k+1) == 3 %%% Cloud
                  clearatt=clearatt+1;
               end
            elseif instant_Cloud(j,k) ==0
              clearok=clearok+1;
            else
              clearnan=clearnan+1;
            end
        end
        end

    end  %% cloud aircraft


end
end
end


tot=cloudy+uncert+differ+clearok+clearuncert+cleardiff;
n-(cloudy+nanval+uncert+differ)
n2-(cleardiff+clearnan+clearok+clearuncert)

[{''}]
[{''}]
[{'Detection'}]
[{'diff'} (cleardiff+differ+uncert)*100/tot ] %% difference de detection
[{'diff Aclear/Ccloud'} cleardiff*100/tot ] %% difference de detection
[{'diff Acloud/Cclear'} differ*100/tot ] %% difference de detection
[{'diff Acloud/Cuncert'} uncert*100/tot ] %% difference de detection
[{''}]
[{'Ok'} (cloudy+clearok+clearuncert)*100/tot ] %% difference de detection
[{'Ok Acloud/Ccloud'} cloudy*100/tot ] %% difference de detection
[{'Ok Aclear/Cclear'} clearok*100/tot ] %% difference de detection
[{'Ok Aclear/Cuncert'} clearuncert*100/tot ] %% difference de detection
[{''}]
[{''}]
[{'Phase'}]
[{'Diff'} (liqice+iceliq)*100/(cloudy)]  %% fausse attribution phase
[{'Aliq/Cice'} (iceliq)*100/(cloudy)]  %% fausse attribution phase
[{'Aice/Cliq'} (liqice)*100/(cloudy)]  %% fausse attribution phase
[{''}]
[{'Ok'} (liqliq+iceice+liqmixed+icemixed)*100/cloudy]  %% bonne phase
[{'Liq'} (liqliq)*100/cloudy]  %% bonne phase
[{'Ice'} (iceice)*100/cloudy]  %% bonne phase
[{'MixLiq'} (liqmixed)*100/cloudy]  %% bonne phase
[{'MixIce'} (icemixed)*100/cloudy]  %% bonne phase
[{''}]
[{''}]
[{'Not sure'} (undefice+undefliq+undefmixed)*100/cloudy]  %% bonne phase
[{'Aliq/Cundef'} (undefliq)*100/cloudy]  %% bonne phase
[{'Aice/Cundef'} (undefice)*100/cloudy]  %% bonne phase
[{'Amix/Cundef'} (undefmixed)*100/cloudy]  %% bonne phase


















stop



%%%%%%%%%%%%%%%%%%%%% PROFILES CALIOP %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
figure(2)
hold on
subplot(3,3,9)
    plot(0,0,'x','color',[0 0.667 1],'markersize',4)
 hold on
pcolor(latitude(xx),alt,Phase(xx,:)');
shading flat;
set(gca,'tickdir','out')
set(gcf,'color','white')
caxis([-2.1 3.9])
%title(titre,'fontweight','bold','fontsize',14)
colormap(colorphase3)
%ylabel('Altitude (km)','fontweight','bold','fontsize',14)
axis([48.27 48.63 8 11.5])

for i =1:41                            
plot([48 50],[alt(i) alt(i)],'black--')   
end

freezecolors


%%%%%%%%%%%%%%%%%%% AIRCRAFT OVERPASS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
xx2=find(lati>0);
ind=0;
n=0;
for i=1:length(xx2)
 i=xx2(i);
 if ext(i)>0.02
    n=n+1;
    if asym(i)<0.8 & asym(i)>0.7
        plot(lati(i),alti(i)/1000,'x','color','magenta','markersize',4)
        elseif asym(i)>=0.8  & asym(i)<0.83
        plot(lati(i),alti(i)/1000,'x','color','yellow','markersize',4)
        elseif asym(i)>=0.83  & asym(i)<0.9
        plot(lati(i),alti(i)/1000,'x','color',[0 0.667 1],'markersize',4)
    end
 else
 plot(lati(i),alti(i)/1000,'.','color','black','markersize',4)
 end
 
end




%%%%%%%%%%%%%%%%%%%%% SR PROFILES CALIOP %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
figure(2)
subplot(3,3,6)
    plot(0,0,'x','color',[0 0.667 1],'markersize',4)
 hold on
pcolor(latitude(xx),alt(1:40),instant_Cloud(xx,:)');
shading flat;
set(gca,'tickdir','out')
caxis([1 5])
colormap(colorinstant)
axis([48.27 48.63 8 11.5])

for i =1:41                            
plot([48 50],[alt(i) alt(i)],'black--')   
end

freezecolors


%%%%%%%%%%%%%%%%%%% AIRCRAFT OVERPASS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
xx2=find(lati>0);
ind=0;
n=0;
for i=1:length(xx2)
 i=xx2(i);
 if ext(i)>0.02
    n=n+1;
    if asym(i)<0.8 & asym(i)>0.7
        plot(lati(i),alti(i)/1000,'x','color','magenta','markersize',4)
        elseif asym(i)>=0.8  & asym(i)<0.83
        plot(lati(i),alti(i)/1000,'x','color','yellow','markersize',4)
        elseif asym(i)>=0.83  & asym(i)<0.9
        ind=ind+1;
        plot(lati(i),alti(i)/1000,'x','color',[0 0.667 1],'markersize',4)
    end
 else
 plot(lati(i),alti(i)/1000,'.','color','black','markersize',4)
 end 
end

figure(2)
subplot(3,3,3)
    plot(0,0,'x','color',[0 0.667 1],'markersize',4)
 hold on
pcolor(latitude(xx),alt583,double(atb532(xx,:))');
shading flat;
set(gca,'tickdir','out')
caxis([0 0.01])
%title('(a)','fontweight','bold','fontsize',12)
colormap(coloratb)
axis([48.27 48.63 8 11.5])


for i =1:41                            
plot([48 50],[alt(i) alt(i)],'black--')   
end



axis([48.27 48.63 8 11.5])


%%%%%%%%%%%%%%%%%%% AIRCRAFT OVERPASS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
xx2=find(lati>0);
ind=0;
n=0;
for i=1:length(xx2)
 i=xx2(i);
 if ext(i)>0.02
    n=n+1;
    if asym(i)<0.8 & asym(i)>0.7
        plot(lati(i),alti(i)/1000,'x','color','magenta','markersize',4)
        elseif asym(i)>=0.8  & asym(i)<0.83
        plot(lati(i),alti(i)/1000,'x','color','yellow','markersize',4)
        elseif asym(i)>=0.83  & asym(i)<0.9
        ind=ind+1;
        plot(lati(i),alti(i)/1000,'x','color',[0 0.667 1],'markersize',4)
    end
 else
 plot(lati(i),alti(i)/1000,'.','color','black','markersize',4)
 end 
end

freezecolors

%open('/homedata/gcesana/insitu/arctic/diagphaseall.fig')


%%%%%%%%%%%%%%%%%%%%% DIAGPHASE CALIOP %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
figure(3)
subplot(3,2,2)
hold on
axis([-0.0 0.16 -0.00 0.04])

plot([1 1],[1 1],'blueo','markersize',7);
plot([1 1],[1 1],'redo','markersize',7);
plot([1 1],[1 1], 'bluex');
plot([1 1],[1 1],'redx');
plot([1 1],[1 1],'.','color',[0 0.8 0]);
plot([1 1],[1 1],'.','color',[1 1 0]);
plot([1 1],[1 1],'blue.');
plot([1 1],[1 1],'red.');
plot([1 1],[1 1],'.','color',[1 0.55 0]);

legend('liq curve','ice curve','discri','AirLiq/CalLiq','AirIce/CalIce','AirLiq/CalIce','AirIce/CalLiq','AirMix/CalLiq','AirMix/CalIce','AirLiq/CalUn','AirIce/CalUn','AirMix/CalUn')



instant_Phase(instant_SR<0.01 | instant_Cloud==8)=-9999;
%instant_Cloud(instant_SR>1.2 & instant_SR<5)=4;
alt=[0:480:19200];

n=0;
n2=0;

differ=0;   %% difference clear cloud
nanval=0;   %% nanval
check=0;    %% control doit etre 0
cloudy=0;   %% nb de prof en accord nuage
attcld=0;   %% un nuage au dessus
valSR=0;    %% valeur de SR du pixel colloc
uncert=0;
clearuncert=0;
clearnan=0;

liqliq=0;
liqmixed=0;
liqice=0;

iceliq=0;
iceice=0;
icemixed=0;

undefice=0;
undefliq=0;
undefmixed=0;

noiseliq=0;
noiseice=0;
noisemixed=0;

clearok=0;
cleardiff=0;
clearatt=0;


differice=0;
differmix=0;
differliq=0;

liqiceasym=0;
iceliqasym=0;



for i=1:length(xx2) 
i=xx2(i);
for j=1:length(latitude)-1
if lati(i)>= latitude(j) & lati(i) < latitude(j+1) 

   if ext(i)>0.02
        n=n+1;

       for k=18:26
	  if alti(i) > alt(k) & alti(i)<= alt(k+1)
          if instant_Cloud(j,k) ==2  %%% CLEAR
            differ=differ+1;
                 if asym(i)<0.8 & asym(i)>0.7 %% ICE
                    differice=differice+1;
                 elseif asym(i)>=0.8  & asym(i)<0.83  %% MIXED
                    differmix=differmix+1;
                 elseif asym(i)>=0.83  & asym(i)<0.9  %% LIQ
                    differliq=differliq+1;
                 end           
            valSR(n)=instant_SR(j,k);
                if any(instant_Cloud(j,k:40) ==3)
                attcld(n)=1;
                end
          elseif instant_Cloud(j,k) == 1 | instant_Cloud(j,k) == 6 | instant_Cloud(j,k) == 7 | instant_Cloud(j,k) == 8       %%% NAN
            nanval=nanval+1;
          elseif instant_Cloud(j,k) == 4   %%% UNCERT
            uncert=uncert+1;
          elseif instant_Cloud(j,k) == 3   %%% Cloud
            cloudy=cloudy+1;

          if instant_Phase(j,k) == 1 |  instant_Phase(j,k) == 5 %% LIQ
            if asym(i)<0.8 & asym(i)>0.7 %% ICE
              liqice=liqice+1;
	      liqiceasym(n)=asym(i);
              plot(ATB(j,k),ATB_per(j,k),'redx');
            elseif asym(i)>=0.8  & asym(i)<0.83  %% MIXED
              liqmixed=liqmixed+1;
              plot(ATB(j,k),ATB_per(j,k),'.','color',[0 0.8 0]);
                if temp(i)>-42
                   temp(i)
                 end
              elseif asym(i)>=0.83  & asym(i)<0.9  %% LIQ
              liqliq=liqliq+1;
              plot(ATB(j,k),ATB_per(j,k),'blueo');
            end
          elseif instant_Phase(j,k) == 2 |  instant_Phase(j,k) == 4  |  instant_Phase(j,k) == 6 %% ICE
            if asym(i)<0.8 & asym(i)>0.7 %% ICE
              iceice=iceice+1;
              plot(ATB(j,k),ATB_per(j,k),'redo');
            elseif asym(i)>=0.8  & asym(i)<0.83  %% MIXED
              icemixed=icemixed+1;
                 if temp(i)>-42
                   temp(i)
                 end
              plot(ATB(j,k),ATB_per(j,k),'.','color',[1 1 0]);
            elseif asym(i)>=0.83  & asym(i)<0.9  %% LIQ
              iceliq=iceliq+1;
	      iceliqasym(n)=asym(i);
              plot(ATB(j,k),ATB_per(j,k),'bluex');
            end
          elseif instant_Phase(j,k) == 3  | instant_Phase(j,k) == 7 %% UNDEF
            if asym(i)<0.8 & asym(i)>0.7 %% ICE
              undefice=undefice+1;
              plot(ATB(j,k),ATB_per(j,k),'red.');
            elseif asym(i)>=0.8  & asym(i)<0.83  %% MIXED
              undefmixed=undefmixed+1;
              plot(ATB(j,k),ATB_per(j,k),'.','color',[1 0.55 0]);
                 if temp(i)>-42
                   temp(i)
                 end
             elseif asym(i)>=0.83  & asym(i)<0.9  %% LIQ
              undefliq=undefliq+1;
              plot(ATB(j,k),ATB_per(j,k),'blue.');
            end
          else
            check=check+1;
          end



          end
          end
       end

   else    %%% AVION CLOUD condition  
     n2=n2+1;
        for k=18:26
        if alti(i) > alt(k) & alti(i)<= alt(k+1)
            if instant_Cloud(j,k) == 3
               cleardiff=cleardiff+1;
               if instant_Cloud(j,k+1) == 3 
                  clearatt=clearatt+1;
               end
            elseif instant_Cloud(j,k) == 2
              clearok=clearok+1;
            elseif instant_Cloud(j,k) == 4
              clearuncert=clearuncert+1;
            else
              clearnan=clearnan+1;
            end
        end
        end

    end  %% cloud aircraft


end
end
end


tot=cloudy+uncert+differ+clearok+clearuncert+cleardiff;
n-(cloudy+nanval+uncert+differ)
n2-(cleardiff+clearnan+clearok+clearuncert)

[{''}]
[{''}]
[{'Detection'}]
[{'diff'} (cleardiff+differ+uncert)*100/tot ] %% difference de detection
[{'diff Aclear/Ccloud'} cleardiff*100/tot ] %% difference de detection
[{'diff Acloud/Cclear'} differ*100/tot ] %% difference de detection
[{'diff Acloud/Cuncert'} uncert*100/tot ] %% difference de detection
[{''}]
[{'Ok'} (cloudy+clearok+clearuncert)*100/tot ] %% difference de detection
[{'Ok Acloud/Ccloud'} cloudy*100/tot ] %% difference de detection
[{'Ok Aclear/Cclear'} clearok*100/tot ] %% difference de detection
[{'Ok Aclear/Cuncert'} clearuncert*100/tot ] %% difference de detection
[{''}]
[{''}]
[{'Phase'}]
[{'Diff'} (liqice+iceliq)*100/(cloudy)]  %% fausse attribution phase
[{'Aliq/Cice'} (iceliq)*100/(cloudy)]  %% fausse attribution phase
[{'Aice/Cliq'} (liqice)*100/(cloudy)]  %% fausse attribution phase
[{''}]
[{'Ok'} (liqliq+iceice+liqmixed+icemixed)*100/cloudy]  %% bonne phase
[{'Liq'} (liqliq)*100/cloudy]  %% bonne phase
[{'Ice'} (iceice)*100/cloudy]  %% bonne phase
[{'MixLiq'} (liqmixed)*100/cloudy]  %% bonne phase
[{'MixIce'} (icemixed)*100/cloudy]  %% bonne phase
[{''}]
[{''}]
[{'Not sure'} (undefice+undefliq+undefmixed)*100/cloudy]  %% bonne phase
[{'Aliq/Cundef'} (undefliq)*100/cloudy]  %% bonne phase
[{'Aice/Cundef'} (undefice)*100/cloudy]  %% bonne phase
[{'Amix/Cundef'} (undefmixed)*100/cloudy]  %% bonne phase
