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/arctic/fraction_ST_20070409xia.mat
load colorbars2

%%%% CALIOP L1 %%%
atb532=hdfread('/bdd/CALIPSO/Lidar_L1/CAL_LID_L1.v3.01/2007/2007_04_09/CAL_LID_L1-ValStage1-V3-01.2007-04-09T09-21-04ZD.hdf','Total_Attenuated_Backscatter_532');
alt583=load('~/grilles_lmdz/alt');

%ncload('/homedata/gcesana/insitu/arctic/instant_SR_CR_DR_2007-04-09T09-21-04ZD_day_CFMIP2_2.71.nc');
ncload5('/bdd/CFMIP/GOCCP/instant_SR_CR_DR/temp/instant_SR_CR_DR_2007-04-09T09-21-04ZD_day_CFMIP2_2.90.nc');
toto=load('/homedata/gcesana/insitu/arctic/070409.txt');
titre='b) 2007-04-09';


%%%%%%%%%% OVERPASS CALIPSO AIRCRAFT 10.3075 10h18m45s
%%% -10m +10m

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:41,1:length(latitude))=0;
instant_Cloud(instant_Cloud==7)=1; instant_Cloud(instant_Cloud==6)=1;
instant_Phase(instant_Cloud==8)=-1;
instant_Phase(instant_Cloud==1)=-2;

Phase(1:40,:)=instant_Phase;
Phase(Phase==4)=2;
Phase(Phase==5)=1;
Phase(Phase==6)=2;
Phase(instant_SR==-9999)=nan;
Phase(instant_SR==-888)=nan;
Phase(instant_SR==-777)=nan;

instant_Cloud=instant_Cloud';
instant_Phase=instant_Phase';
Phase=Phase';
instant_SR=instant_SR';
ATB=ATB';
ATB_per=ATB_per';

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;

% longitude CALIPSO comprise entre 6 et 13E et 77 78,6N
% longitude CALIPSO comprise entre 6 et 13E et 77 78,6N
heure(longi>12.8)=nan;
lati(longi>12.8)=nan;
longi(longi>12.8)=nan;

% + ou - 10min autour du croisement de l heure de passage de l avion et du satellite
% over pass a 10.106 = 10h06m36s
longi(heure>10.27)=nan;
lati(heure>10.27)=nan;
heure(heure>10.27)=nan;

longi(heure<9.94)=nan;
lati(heure<9.94)=nan;
heure(heure<9.94)=nan;


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

xx=find(latitude>min(lati) & latitude <max(lati) & longitude > 0 & latitude > 0);

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


figure(2)
subplot(2,2,2)
    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('(b)','fontweight','bold','fontsize',14)
xlabel('2007-04-09','fontweight','bold','fontsize',14)
colormap(coloratb)
%colorbar('west')
 axis([78.17 78.75 0. 1.92 ])
set(gca,'xminortick','on')
set(gca,'yminortick','on')

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


xx2=find(lati>0);
ind=0;
n=0;
for i=1:length(xx2)
 i=xx2(i);
 if ext(i)>0.05
    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','yellow','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_Cloud(instant_SR>1.2 & instant_SR<5)=4;
figure(2)
subplot(2,2,4)
    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])
title('(d)','fontweight','bold','fontsize',12)
colormap(colorinstant)
%ylabel('Height (km)','fontweight','bold','fontsize',12)
%colorbar('west','FontSize',10,'Ytick',[-1.5:1:2.5],'YTickLabel',{'Att','Clear','Cloud','uncert','reject'})
 axis([78.17 78.75 0. 1.92 ])
set(gca,'xminortick','on')
set(gca,'yminortick','on')

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

xx2=find(lati>0);
ind=0;
n=0;
for i=1:length(xx2)
 i=xx2(i);
 if ext(i)>0.05
    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','yellow','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

freezeColors
%cbfreeze('on')


%stop



















colorphase3=[0.8 0.8 0.8;0 0 0; 1 1 1;1 0 0; 0 0 1; 0 0.5 0];

figure(1)
subplot(3,2,2)
    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',[0 0.667 1]);
set(u(12),'color','magenta');

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([78.17 78.75 0.0 1.92 ])
for i =1:41                            
plot([77 79],[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.05
    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','yellow','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



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

%instant_Cloud(instant_SR>1.2 & instant_SR<5)=4;
figure(1)
subplot(3,2,4)
    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([78.17 78.75 0. 1.92 ])

for i =1:41                            
plot([77 79],[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.05
    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','yellow','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/arctic/JAXA_20070409.mat
titi=find(daynight<1);
lat_JAXA(titi)=nan;
xx3=find(lat_JAXA<78.745 & lat_JAXA>78.178);
alt_JAXA=[0:0.240:19.92];
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;


%-1= nan; 0=clear 1=water 2=water 3=ice 4=ice 5=ice 6=undef 7=missing
figure(1)
subplot(3,2,6)
    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([78.17 78.75 0. 1.92 ])

alt=[0:0.48:19.2];
for i =1:41                            
plot([77 79],[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.05
    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','yellow','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




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.05
        n=n+1;

       for k=1:6
	  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=1:6
        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'}]

Nliqiceasym=find(liqiceasym>0.79);
faux_liq_asym=length(Nliqiceasym)/cloudy;
[{''}]
[{''}]
[{'Detection'}]
[{'diff'} (cleardiff+differ)*100/tot ] %% difference de detection
[{'diff Aclear/Ccloud'} cleardiff*100/tot ] %% difference de detection
[{'diff Acloud/Cclear'} differ*100/tot ] %% difference de detection
[{''}]
[{'Ok'} (cloudy+clearok)*100/tot ] %% difference de detection
[{'Ok Acloud/Ccloud'} cloudy*100/tot ] %% difference de detection
[{'Ok Aclear/Cclear'} clearok*100/tot ] %% difference de detection
[{''}]
[{'Undef'} (uncert+clearuncert)*100/tot ] %% difference de detection
[{'Undef Acloud/Cuncert'} uncert*100/tot ] %% difference de detection
[{'Undef 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
[{'Aice/Cliq g>0.79'} 100*faux_liq_asym]

[{''}]
[{'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



Nliqiceasym=find(liqiceasym>0.79);
faux_liq_asym=length(Nliqiceasym)/cloudy;
testundef=find(atbundef>0);
n=0;

for i = 1:length(testundef)
if polyval(eq50new,atbundef(testundef(i))) < atbperpundef(testundef(i))
n=n+1;
end
end



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.05 & asym(i)<0.9 & asym(i)>0.7
        n=n+1;

       for k=1:6
	  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;

tutu(i)=ext(i);
        for k=1:6
        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;
tutu2(i)=ext(i);

              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'}]

Nliqiceasym=find(liqiceasym>0.79);
faux_liq_asym=length(Nliqiceasym)/cloudy;
[{''}]
[{''}]
[{'Detection'}]
[{'diff'} (cleardiff+differ)*100/tot ] %% difference de detection
[{'diff Aclear/Ccloud'} cleardiff*100/tot ] %% difference de detection
[{'diff Acloud/Cclear'} differ*100/tot ] %% difference de detection
[{''}]
[{'Ok'} (cloudy+clearok)*100/tot ] %% difference de detection
[{'Ok Acloud/Ccloud'} cloudy*100/tot ] %% difference de detection
[{'Ok Aclear/Cclear'} clearok*100/tot ] %% difference de detection
[{''}]
[{'Undef'} (uncert+clearuncert)*100/tot ] %% difference de detection
[{'Undef Acloud/Cuncert'} uncert*100/tot ] %% difference de detection
[{'Undef 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
[{'Aice/Cliq g>0.79'} 100*faux_liq_asym]

[{''}]
[{'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.05 & asym(i)<0.9 & asym(i)>0.7
        n=n+1;

       for k=1:10
	  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=1:10
        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)

Nliqiceasym=find(liqiceasym>0.79);
faux_liq_asym=length(Nliqiceasym)/cloudy;
[{''}]
[{''}]
[{'Detection'}]
[{'diff'} (cleardiff+differ)*100/tot ] %% difference de detection
[{'diff Aclear/Ccloud'} cleardiff*100/tot ] %% difference de detection
[{'diff Acloud/Cclear'} differ*100/tot ] %% difference de detection
[{''}]
[{'Ok'} (cloudy+clearok)*100/tot ] %% difference de detection
[{'Ok Acloud/Ccloud'} cloudy*100/tot ] %% difference de detection
[{'Ok Aclear/Cclear'} clearok*100/tot ] %% difference de detection
[{''}]
[{'Undef'} (uncert+clearuncert)*100/tot ] %% difference de detection
[{'Undef Acloud/Cuncert'} uncert*100/tot ] %% difference de detection
[{'Undef 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
[{'Aice/Cliq g>0.79'} 100*faux_liq_asym]

[{''}]
[{'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


