Index: /LMDZ5/trunk/libf/phylmd/fisrtilp.F90
===================================================================
--- /LMDZ5/trunk/libf/phylmd/fisrtilp.F90	(revision 1506)
+++ /LMDZ5/trunk/libf/phylmd/fisrtilp.F90	(revision 1507)
@@ -387,5 +387,5 @@
            if (iflag_cldcon <= 4) then
               lognormale = .true.
-           elseif (iflag_cldcon == 6) then
+           elseif (iflag_cldcon >= 6) then
               ! lognormale en l'absence des thermiques
               lognormale = fraca(:,k) < 1e-10
Index: /LMDZ5/trunk/libf/phylmd/phys_local_var_mod.F90
===================================================================
--- /LMDZ5/trunk/libf/phylmd/phys_local_var_mod.F90	(revision 1506)
+++ /LMDZ5/trunk/libf/phylmd/phys_local_var_mod.F90	(revision 1507)
@@ -40,4 +40,10 @@
       REAL, SAVE, ALLOCATABLE :: d_t_eva(:,:),d_q_eva(:,:)
       !$OMP THREADPRIVATE(d_t_eva,d_q_eva)
+      REAL, SAVE, ALLOCATABLE :: d_t_lscst(:,:),d_q_lscst(:,:)
+      !$OMP THREADPRIVATE(d_t_lscst,d_q_lscst)
+      REAL, SAVE, ALLOCATABLE :: d_t_lscth(:,:),d_q_lscth(:,:)
+      !$OMP THREADPRIVATE(d_t_lscth,d_q_lscth)
+      REAL, SAVE, ALLOCATABLE :: plul_th(:),plul_st(:)
+      !$OMP THREADPRIVATE(plul_th,plul_st)
 !tendances dues a oro et lif
       REAL, SAVE, ALLOCATABLE :: d_t_oli(:,:)
@@ -188,4 +194,7 @@
       allocate(d_u_ajs(klon,klev),d_v_ajs(klon,klev))
       allocate(d_t_eva(klon,klev),d_q_eva(klon,klev))
+      allocate(d_t_lscst(klon,klev),d_q_lscst(klon,klev))
+      allocate(d_t_lscth(klon,klev),d_q_lscth(klon,klev))
+      allocate(plul_st(klon),plul_th(klon))
       allocate(d_t_vdf(klon,klev),d_q_vdf(klon,klev))
       allocate(d_u_vdf(klon,klev),d_v_vdf(klon,klev))
@@ -265,4 +274,7 @@
       deallocate(d_u_ajs,d_v_ajs)
       deallocate(d_t_eva,d_q_eva)
+      deallocate(d_t_lscst,d_q_lscst)
+      deallocate(d_t_lscth,d_q_lscth)
+      deallocate(plul_th,plul_th)
       deallocate(d_t_vdf,d_q_vdf)
       deallocate(d_u_vdf,d_v_vdf)
Index: /LMDZ5/trunk/libf/phylmd/phys_output_mod.F90
===================================================================
--- /LMDZ5/trunk/libf/phylmd/phys_output_mod.F90	(revision 1506)
+++ /LMDZ5/trunk/libf/phylmd/phys_output_mod.F90	(revision 1507)
@@ -499,4 +499,17 @@
   type(ctrl_out),save :: o_dteva        = ctrl_out((/ 4, 10, 10, 10, 10 /),'dteva')
   type(ctrl_out),save :: o_dqeva        = ctrl_out((/ 4, 10, 10, 10, 10 /),'dqeva')
+
+!!!!!!!!!!!!!!!! Specifique thermiques
+  type(ctrl_out),save :: o_dqlscth        = ctrl_out((/ 10, 10, 10, 10, 10 /),'dqlscth')
+  type(ctrl_out),save :: o_dqlscst        = ctrl_out((/ 10, 10, 10, 10, 10 /),'dqlscst')
+  type(ctrl_out),save :: o_dtlscth        = ctrl_out((/ 10, 10, 10, 10, 10 /),'dtlscth')
+  type(ctrl_out),save :: o_dtlscst        = ctrl_out((/ 10, 10, 10, 10, 10 /),'dtlscst')
+  type(ctrl_out),save :: o_plulth        = ctrl_out((/ 10, 10, 10, 10, 10 /),'plulth')
+  type(ctrl_out),save :: o_plulst        = ctrl_out((/ 10, 10, 10, 10, 10 /),'plulst')
+  type(ctrl_out),save :: o_lmaxth        = ctrl_out((/ 10, 10, 10, 10, 10 /),'lmaxth')
+  type(ctrl_out),save :: o_ptconvth        = ctrl_out((/ 10, 10, 10, 10, 10 /),'ptconvth')
+!!!!!!!!!!!!!!!!!!!!!!!!
+
+
   type(ctrl_out),save :: o_ptconv       = ctrl_out((/ 4, 10, 10, 10, 10 /),'ptconv')
   type(ctrl_out),save :: o_ratqs        = ctrl_out((/ 4, 10, 10, 10, 10 /),'ratqs')
@@ -1161,5 +1174,5 @@
 ! Wakes
  IF(iflag_con.EQ.3) THEN
- IF (iflag_wake == 1) THEN
+ IF (iflag_wake >= 1) THEN
    CALL histdef2d(iff,o_ale_wk%flag,o_ale_wk%name, "ALE WK", "m2/s2")
    CALL histdef2d(iff,o_alp_wk%flag,o_alp_wk%name, "ALP WK", "m2/s2")
@@ -1193,4 +1206,12 @@
 
 if(iflag_thermals.gt.1) THEN
+ CALL histdef3d(iff,o_dqlscth%flag,o_dqlscth%name, "dQ therm.", "(kg/kg)/s")
+ CALL histdef3d(iff,o_dqlscst%flag,o_dqlscst%name, "dQ strat.", "(kg/kg)/s")
+ CALL histdef3d(iff,o_dtlscth%flag,o_dtlscth%name, "dQ therm.", "K/s")
+ CALL histdef3d(iff,o_dtlscst%flag,o_dtlscst%name, "dQ strat.", "K/s")
+ CALL histdef2d(iff,o_plulth%flag,o_plulth%name, "Rainfall therm.", "K/s")
+ CALL histdef2d(iff,o_plulst%flag,o_plulst%name, "Rainfall strat.", "K/s")
+ CALL histdef2d(iff,o_lmaxth%flag,o_lmaxth%name, "Upper level thermals", "")
+ CALL histdef3d(iff,o_ptconvth%flag,o_ptconvth%name, "POINTS CONVECTIFS therm.", " ")
  CALL histdef3d(iff,o_f_th%flag,o_f_th%name, "Thermal plume mass flux", "K/s")
  CALL histdef3d(iff,o_e_th%flag,o_e_th%name,"Thermal plume entrainment","K/s")
Index: /LMDZ5/trunk/libf/phylmd/phys_output_write.h
===================================================================
--- /LMDZ5/trunk/libf/phylmd/phys_output_write.h	(revision 1506)
+++ /LMDZ5/trunk/libf/phylmd/phys_output_write.h	(revision 1507)
@@ -583,5 +583,5 @@
        IF (o_mc%flag(iff)<=lev_files(iff)) THEN
         if(iflag_thermals.gt.1)then
-         zx_tmp_fi3d=dnwd+dnwd0+upwd+fm_therm
+         zx_tmp_fi3d=dnwd+dnwd0+upwd+fm_therm(:,1:klev)
         else
          zx_tmp_fi3d=dnwd+dnwd0+upwd
@@ -708,5 +708,5 @@
 ! Wakes
       IF (iflag_con.EQ.3) THEN
-      IF (iflag_wake.EQ.1) THEN
+      IF (iflag_wake>=1) THEN
        IF (o_ale_wk%flag(iff)<=lev_files(iff)) THEN
        CALL histwrite_phy(nid_files(iff),o_ale_wk%name,itau_w,ale_wake)
@@ -763,5 +763,5 @@
      &                     o_dqwak%name,itau_w,zx_tmp_fi3d)
         ENDIF
-      ENDIF ! iflag_wake.EQ.1
+      ENDIF ! iflag_wake>=1
 
         IF (o_Vprecip%flag(iff)<=lev_files(iff)) THEN
@@ -1356,4 +1356,66 @@
        ENDIF
 
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+! Sorties specifiques a la separation thermiques/non thermiques
+       if (iflag_thermals>1) then
+
+       IF (o_dtlscth%flag(iff)<=lev_files(iff)) THEN
+      zx_tmp_fi3d(1:klon,1:klev)=d_t_lscth(1:klon,1:klev)/pdtphys
+      CALL 
+     s histwrite_phy(nid_files(iff),o_dtlscth%name,itau_w,zx_tmp_fi3d)
+       ENDIF
+
+       IF (o_dtlscst%flag(iff)<=lev_files(iff)) THEN
+      zx_tmp_fi3d(1:klon,1:klev)=d_t_lscst(1:klon,1:klev)/pdtphys
+      CALL 
+     s histwrite_phy(nid_files(iff),o_dtlscst%name,itau_w,zx_tmp_fi3d)
+       ENDIF
+
+       IF (o_dqlscth%flag(iff)<=lev_files(iff)) THEN
+      zx_tmp_fi3d(1:klon,1:klev)=d_q_lscth(1:klon,1:klev)/pdtphys
+      CALL 
+     s histwrite_phy(nid_files(iff),o_dqlscth%name,itau_w,zx_tmp_fi3d)
+       ENDIF
+
+       IF (o_dqlscst%flag(iff)<=lev_files(iff)) THEN
+      zx_tmp_fi3d(1:klon,1:klev)=d_q_lscst(1:klon,1:klev)/pdtphys
+      CALL 
+     s histwrite_phy(nid_files(iff),o_dqlscst%name,itau_w,zx_tmp_fi3d)
+       ENDIF
+
+       IF (o_plulth%flag(iff)<=lev_files(iff)) THEN
+      CALL histwrite_phy(nid_files(iff),o_plulth%name,itau_w,plul_th)
+       ENDIF
+
+       IF (o_plulst%flag(iff)<=lev_files(iff)) THEN
+      CALL histwrite_phy(nid_files(iff),o_plulst%name,itau_w,plul_st)
+       ENDIF
+
+      do k=1,klev
+      do i=1,klon
+          if (ptconvth(i,k)) then
+           zx_tmp_fi3d(i,k)=1.
+          else
+           zx_tmp_fi3d(i,k)=0.
+          endif
+      enddo
+      enddo
+       IF (o_ptconvth%flag(iff)<=lev_files(iff)) THEN
+      CALL 
+     s  histwrite_phy(nid_files(iff),o_ptconvth%name,itau_w,zx_tmp_fi3d)
+       ENDIF
+
+      do i=1,klon
+           zx_tmp_fi2d(1:klon)=lmax_th(:)
+      enddo
+       IF (o_ptconvth%flag(iff)<=lev_files(iff)) THEN
+      CALL 
+     s histwrite_phy(nid_files(iff),o_lmaxth%name,itau_w,zx_tmp_fi2d)
+       ENDIF
+
+      endif ! iflag_thermals>1
+
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+
        IF (o_dtvdf%flag(iff)<=lev_files(iff)) THEN
       zx_tmp_fi3d(1:klon,1:klev)=d_t_vdf(1:klon,1:klev)/pdtphys
@@ -1433,6 +1495,6 @@
        ENDIF
 
-       IF (o_f0_th%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),o_zmax_th%name,itau_w,zmax0)
+       IF (o_zmax_th%flag(iff)<=lev_files(iff)) THEN
+       CALL histwrite_phy(nid_files(iff),o_zmax_th%name,itau_w,zmax_th)
        ENDIF
 
Index: /LMDZ5/trunk/libf/phylmd/physiq.F
===================================================================
--- /LMDZ5/trunk/libf/phylmd/physiq.F	(revision 1506)
+++ /LMDZ5/trunk/libf/phylmd/physiq.F	(revision 1507)
@@ -173,4 +173,6 @@
       save iflag_ratqs
 c$OMP THREADPRIVATE(iflag_ratqs)
+      real facteur,zfratqs1,zfratqs2
+
       REAL lambda_th(klon,klev),zz,znum,zden
       REAL wmax_th(klon)
@@ -924,5 +926,4 @@
       save fact_cldcon,facttemps
 c$OMP THREADPRIVATE(fact_cldcon,facttemps)
-      real facteur
 
       integer iflag_cldcon
@@ -1440,5 +1441,5 @@
 cCR:04.12.07: initialisations poches froides
 c Controle de ALE et ALP pour la fermeture convective (jyg)
-          if (iflag_wake.eq.1) then
+          if (iflag_wake>=1) then
             CALL ini_wake(0.,0.,it_wape_prescr,wape_prescr,fip_prescr
      s                  ,alp_bl_prescr, ale_bl_prescr)
@@ -1934,4 +1935,5 @@
 ! ajout des tendances de la diffusion turbulente
       CALL add_phys_tend(d_u_vdf,d_v_vdf,d_t_vdf,d_q_vdf,dql0,'vdf')
+
 !-----------------------------------------------------------------------------------------
 
@@ -2054,5 +2056,5 @@
       do k=1,klev
             do i=1,klon
-             if (iflag_wake.eq.1) then
+             if (iflag_wake>=1) then
              t_wake(i,k) = t_seri(i,k)
      .           +(1-wake_s(i))*wake_deltat(i,k)
@@ -2071,4 +2073,5 @@
             enddo
          enddo
+
       
 cc--   Calcul de l'energie disponible ALE (J/kg) et de la puissance disponible ALP (W/m2)
@@ -2081,5 +2084,5 @@
 c
 ccalcul de ale_wake et alp_wake
-       if (iflag_wake.eq.1) then
+       if (iflag_wake>=1) then
          if (itap .le. it_wape_prescr) then
           do i = 1,klon
@@ -2343,5 +2346,5 @@
 cpour la couche limite diffuse pour l instant
 c
-      if (iflag_wake.eq.1) then
+      if (iflag_wake>=1) then
       DO k=1,klev
         DO i=1,klon
@@ -2358,4 +2361,9 @@
         ENDDO
       ENDDO
+
+      if (iflag_wake==2) then
+         dt_dwn(:,:)= dt_dwn(:,:)+(d_t_eva(:,:)+d_t_lsc(:,:))/dtime
+         dq_dwn(:,:)= dq_dwn(:,:)+(d_q_eva(:,:)+d_q_lsc(:,:))/dtime
+      endif
 c
 ccalcul caracteristiques de la poche froide
@@ -2474,4 +2482,8 @@
       endif
 
+      do i=1,klon
+         zmax_th(i)=pphi(i,lmax_th(i))/rg
+      enddo
+
          endif
 
@@ -2604,5 +2616,5 @@
          enddo
 
-      else
+      else if (iflag_ratqs.eq.2) then
 
          do k=1,klev
@@ -2620,4 +2632,17 @@
             enddo
          enddo
+
+      else if (iflag_ratqs==3) then
+         do k=1,klev
+           ratqss(:,k)=ratqsbas+(ratqshaut-ratqsbas)
+     s     *min( ((paprs(:,1)-pplay(:,k))/70000.)**2 , 1. )
+         enddo
+
+      else if (iflag_ratqs==4) then
+         do k=1,klev
+           ratqss(:,k)=ratqsbas+0.5*(ratqshaut-ratqsbas)
+     s     *( tanh( (50000.-pplay(:,k))/20000.) + 1.)
+         enddo
+
       endif
 
@@ -2659,8 +2684,24 @@
 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
          ratqs(:,:)=max(ratqs(:,:),ratqss(:,:))
-      else
+      else if (iflag_cldcon<=6) then
 !   on ne prend que le ratqs stable pour fisrtilp
          ratqs(:,:)=ratqss(:,:)
+      else
+          zfratqs1=exp(-pdtphys/10800.)
+          zfratqs2=exp(-pdtphys/10800.)
+!         print*,'RAPPEL RATQS 1 ',zfratqs1,zfratqs2
+!    s    ,ratqss(1,14),ratqs(1,14),ratqsc(1,14)
+          do k=1,klev
+             do i=1,klon
+                if (ratqsc(i,k).gt.1.e-10) then
+                   ratqs(i,k)=ratqs(i,k)*zfratqs2
+     s             +(iflag_cldcon/100.)*ratqsc(i,k)*(1.-zfratqs2)
+                endif
+                ratqs(i,k)=min(ratqs(i,k)*zfratqs1
+     s          +ratqss(i,k)*(1.-zfratqs1),0.5)
+             enddo
+          enddo
       endif
+
 
 
@@ -2844,5 +2885,7 @@
       if (iflag_cldcon>=5) then
 
-         ptconvth(:,:)=fm_therm(:,:)>0.
+        do k=1,klev
+         ptconvth(:,k)=fm_therm(:,k+1)>0.
+        enddo
 
        if (iflag_coupl==4) then
@@ -2890,4 +2933,12 @@
 
       ENDIF
+
+!     plulsc(:)=0.
+!     do k=1,klev,-1
+!        do i=1,klon
+!              zzz=prfl(:,k)+psfl(:,k)
+!           if (.not.ptconvth.zzz.gt.0.)
+!        enddo prfl, psfl,
+!     enddo
 c
 c 2. NUAGES STARTIFORMES
@@ -3355,5 +3406,5 @@
        IF (MOD(itap,NINT(freq_cosp/dtime)).EQ.0) THEN
 
-!       print*,'freq_cosp',freq_cosp
+       print*,'freq_cosp',freq_cosp
           mr_ozone=wo(:, :, 1) * dobson_u * 1e3 / zmasse
 !       print*,'Dans physiq.F avant appel cosp ref_liq,ref_ice=',
@@ -3714,4 +3765,34 @@
 
 
+
+c=============================================================
+! Separation entre thermiques et non thermiques dans les sorties
+! de fisrtilp
+c=============================================================
+
+      if (iflag_thermals>1) then
+      d_t_lscth=0.
+      d_t_lscst=0.
+      d_q_lscth=0.
+      d_q_lscst=0.
+      do k=1,klev
+         do i=1,klon
+            if (ptconvth(i,k)) then
+                d_t_lscth(i,k)=d_t_eva(i,k)+d_t_lsc(i,k)
+                d_q_lscth(i,k)=d_q_eva(i,k)+d_q_lsc(i,k)
+            else
+                d_t_lscst(i,k)=d_t_eva(i,k)+d_t_lsc(i,k)
+                d_q_lscst(i,k)=d_q_eva(i,k)+d_q_lsc(i,k)
+            endif
+         enddo
+      enddo
+
+      do i=1,klon
+      plul_st(i)=prfl(i,lmax_th(i)+1)+psfl(i,lmax_th(i)+1)
+      plul_th(i)=prfl(i,1)+psfl(i,1)
+      enddo
+      endif
+
+ 
 #include "phys_output_write.h"
 
