Index: /LMDZ5/trunk/libf/phylmd/calwake.F90
===================================================================
--- /LMDZ5/trunk/libf/phylmd/calwake.F90	(revision 2158)
+++ /LMDZ5/trunk/libf/phylmd/calwake.F90	(revision 2159)
@@ -233,206 +233,2 @@
   RETURN
 END SUBROUTINE calwake
-
-SUBROUTINE calwake_scal(paprs, pplay, dtime, t, q, omgb, dt_dwn, dq_dwn, &
-    m_dwn, m_up, dt_a, dq_a, sigd, wdt_pbl, wdq_pbl, udt_pbl, udq_pbl, &
-    wake_deltat, wake_deltaq, wake_dth, wake_h, wake_s, wake_dens, wake_pe, &
-    wake_fip, wake_gfl, dt_wake, dq_wake, wake_k, undi_t, undi_q, &
-    wake_omgbdth, wake_dp_omgb, wake_dtke, wake_dqke, wake_dtpbl, wake_dqpbl, &
-    wake_omg, wake_dp_deltomg, wake_spread, wake_cstar, wake_d_deltat_gw, &
-    wake_ddeltat, wake_ddeltaq)
-  ! **************************************************************
-  ! *
-  ! CALWAKE                                                     *
-  ! interface avec le schema de calcul de la poche    *
-  ! froide                                            *
-  ! *
-  ! written by   : CHERUY Frederique, 13/03/2000, 10.31.05      *
-  ! modified by :  ROEHRIG Romain,    01/30/2007                *
-  ! **************************************************************
-
-  USE dimphy
-  IMPLICIT NONE
-  ! ======================================================================
-
-  include "dimensions.h"
-  ! ccc#include "dimphy.h"
-  include "YOMCST.h"
-
-  ! Arguments
-  ! ----------
-
-  INTEGER i, l, ktopw
-  REAL dtime
-
-  REAL paprs(klon, klev+1), pplay(klon, klev)
-  REAL t(klon, klev), q(klon, klev), omgb(klon, klev)
-  REAL dt_dwn(klon, klev), dq_dwn(klon, klev), m_dwn(klon, klev)
-  REAL m_up(klon, klev)
-  REAL dt_a(klon, klev), dq_a(klon, klev)
-  REAL wdt_pbl(klon, klev), wdq_pbl(klon, klev)
-  REAL udt_pbl(klon, klev), udq_pbl(klon, klev)
-  REAL wake_deltat(klon, klev), wake_deltaq(klon, klev)
-  REAL dt_wake(klon, klev), dq_wake(klon, klev)
-  REAL wake_d_deltat_gw(klon, klev)
-  REAL wake_h(klon), wake_s(klon)
-  REAL wake_dth(klon, klev)
-  REAL wake_pe(klon), wake_fip(klon), wake_gfl(klon)
-  REAL undi_t(klon, klev), undi_q(klon, klev)
-  REAL wake_omgbdth(klon, klev), wake_dp_omgb(klon, klev)
-  REAL wake_dtke(klon, klev), wake_dqke(klon, klev)
-  REAL wake_dtpbl(klon, klev), wake_dqpbl(klon, klev)
-  REAL wake_omg(klon, klev+1), wake_dp_deltomg(klon, klev)
-  REAL wake_spread(klon, klev), wake_cstar(klon)
-  REAL wake_ddeltat(klon, klev), wake_ddeltaq(klon, klev)
-  REAL d_deltatw(klev), d_deltaqw(klev)
-  INTEGER wake_k(klon)
-  REAL sigd(klon)
-  REAL wake_dens(klon)
-
-  ! Variable internes
-  ! -----------------
-
-  REAL aire
-  REAL p(klev), ph(klev+1), pi(klev)
-  REAL te(klev), qe(klev), omgbe(klev), dtdwn(klev), dqdwn(klev)
-  REAL dta(klev), dqa(klev)
-  REAL wdtpbl(klev), wdqpbl(klev)
-  REAL udtpbl(klev), udqpbl(klev)
-  REAL amdwn(klev), amup(klev)
-  REAL dtw(klev), dqw(klev), dth(klev), d_deltat_gw(klev)
-  REAL dtls(klev), dqls(klev)
-  REAL tu(klev), qu(klev)
-  REAL hw, sigmaw, wape, fip, gfl
-  REAL omgbdth(klev), dp_omgb(klev)
-  REAL dtke(klev), dqke(klev)
-  REAL dtpbl(klev), dqpbl(klev)
-  REAL omg(klev+1), dp_deltomg(klev), spread(klev), cstar
-  REAL sigd0, wdens
-
-  REAL rdcp
-
-  ! print *, '-> calwake, wake_s ', wake_s(1)
-
-  rdcp = 1./3.5
-
-  ! -----------------------------------------------------------
-  DO i = 1, klon ! a vectoriser
-    ! ----------------------------------------------------------
-
-
-    DO l = 1, klev
-      p(l) = pplay(i, l)
-      ph(l) = paprs(i, l)
-      pi(l) = (pplay(i,l)/100000.)**rdcp
-
-      te(l) = t(i, l)
-      qe(l) = q(i, l)
-      omgbe(l) = omgb(i, l)
-
-      dtdwn(l) = dt_dwn(i, l)
-      dqdwn(l) = dq_dwn(i, l)
-      dta(l) = dt_a(i, l)
-      dqa(l) = dq_a(i, l)
-      wdtpbl(l) = wdt_pbl(i, l)
-      wdqpbl(l) = wdq_pbl(i, l)
-      udtpbl(l) = udt_pbl(i, l)
-      udqpbl(l) = udq_pbl(i, l)
-    END DO
-
-    sigd0 = sigd(i)
-    ! print*, 'sigd0,sigd', sigd0, sigd(i)
-    ph(klev+1) = 0.
-
-    ktopw = wake_k(i)
-
-    DO l = 1, klev
-      dtw(l) = wake_deltat(i, l)
-      dqw(l) = wake_deltaq(i, l)
-    END DO
-
-    DO l = 1, klev
-      dtls(l) = dt_wake(i, l)
-      dqls(l) = dq_wake(i, l)
-    END DO
-
-    hw = wake_h(i)
-    sigmaw = wake_s(i)
-
-    ! fkc les flux de masses sont evalues aux niveaux et valent 0 a la
-    ! surface
-    ! fkc  on veut le flux de masse au milieu des couches
-
-    DO l = 1, klev - 1
-      amdwn(l) = 0.5*(m_dwn(i,l)+m_dwn(i,l+1))
-      amdwn(l) = (m_dwn(i,l+1))
-    END DO
-
-    ! au sommet le flux de masse est nul
-
-    amdwn(klev) = 0.5*m_dwn(i, klev)
-
-    DO l = 1, klev
-      amup(l) = m_up(i, l)
-    END DO
-
-    CALL wake_scal(p, ph, pi, dtime, sigd0, te, qe, omgbe, dtdwn, dqdwn, &
-      amdwn, amup, dta, dqa, wdtpbl, wdqpbl, udtpbl, udqpbl, dtw, dqw, dth, &
-      hw, sigmaw, wape, fip, gfl, dtls, dqls, ktopw, omgbdth, dp_omgb, wdens, &
-      tu, qu, dtke, dqke, dtpbl, dqpbl, omg, dp_deltomg, spread, cstar, &
-      d_deltat_gw, d_deltatw, d_deltaqw)
-
-    IF (ktopw>0) THEN
-      DO l = 1, klev
-        wake_deltat(i, l) = dtw(l)
-        wake_deltaq(i, l) = dqw(l)
-        wake_d_deltat_gw(i, l) = d_deltat_gw(l)
-        wake_omgbdth(i, l) = omgbdth(l)
-        wake_dp_omgb(i, l) = dp_omgb(l)
-        wake_dtke(i, l) = dtke(l)
-        wake_dqke(i, l) = dqke(l)
-        wake_dtpbl(i, l) = dtpbl(l)
-        wake_dqpbl(i, l) = dqpbl(l)
-        wake_omg(i, l) = omg(l)
-        wake_dp_deltomg(i, l) = dp_deltomg(l)
-        wake_spread(i, l) = spread(l)
-        wake_dth(i, l) = dth(l)
-        dt_wake(i, l) = dtls(l)
-        dq_wake(i, l) = dqls(l)
-        undi_t(i, l) = tu(l)
-        undi_q(i, l) = qu(l)
-        wake_ddeltat(i, l) = d_deltatw(l)
-        wake_ddeltaq(i, l) = d_deltaqw(l)
-      END DO
-    ELSE
-      DO l = 1, klev
-        wake_deltat(i, l) = 0.
-        wake_deltaq(i, l) = 0.
-        wake_d_deltat_gw(i, l) = 0.
-        wake_omgbdth(i, l) = 0.
-        wake_dp_omgb(i, l) = 0.
-        wake_dtke(i, l) = 0.
-        wake_dqke(i, l) = 0.
-        wake_omg(i, l) = 0.
-        wake_dp_deltomg(i, l) = 0.
-        wake_spread(i, l) = 0.
-        wake_dth(i, l) = 0.
-        dt_wake(i, l) = 0.
-        dq_wake(i, l) = 0.
-        undi_t(i, l) = te(l)
-        undi_q(i, l) = qe(l)
-      END DO
-    END IF
-
-    wake_h(i) = hw
-    wake_s(i) = sigmaw
-    wake_pe(i) = wape
-    wake_fip(i) = fip
-    wake_gfl(i) = gfl
-    wake_k(i) = ktopw
-    wake_cstar(i) = cstar
-    wake_dens(i) = wdens
-
-  END DO
-
-  RETURN
-END SUBROUTINE calwake_scal
Index: /LMDZ5/trunk/libf/phylmd/climb_hq_mod.F90
===================================================================
--- /LMDZ5/trunk/libf/phylmd/climb_hq_mod.F90	(revision 2158)
+++ /LMDZ5/trunk/libf/phylmd/climb_hq_mod.F90	(revision 2159)
@@ -30,7 +30,10 @@
   SUBROUTINE climb_hq_down(knon, coefhq, paprs, pplay, &
        delp, temp, q, dtime, &
+!!! nrlmd le 02/05/2011
+       Ccoef_H_out, Ccoef_Q_out, Dcoef_H_out, Dcoef_Q_out, &
+       Kcoef_hq_out, gama_q_out, gama_h_out, &
+!!!
        Acoef_H_out, Acoef_Q_out, Bcoef_H_out, Bcoef_Q_out)
 
-    INCLUDE "YOMCST.h"
 ! This routine calculates recursivly the coefficients C and D
 ! for the quantity X=[Q,H] in equation X(k) = C(k) + D(k)*X(k-1), where k is
@@ -54,4 +57,14 @@
     REAL, DIMENSION(klon), INTENT(OUT)       :: Bcoef_Q_out
 
+!!! nrlmd le 02/05/2011
+    REAL, DIMENSION(klon,klev), INTENT(OUT)  :: Ccoef_H_out
+    REAL, DIMENSION(klon,klev), INTENT(OUT)  :: Ccoef_Q_out
+    REAL, DIMENSION(klon,klev), INTENT(OUT)  :: Dcoef_H_out
+    REAL, DIMENSION(klon,klev), INTENT(OUT)  :: Dcoef_Q_out
+    REAL, DIMENSION(klon,klev), INTENT(OUT)  :: Kcoef_hq_out
+    REAL, DIMENSION(klon,klev), INTENT(OUT)  :: gama_q_out
+    REAL, DIMENSION(klon,klev), INTENT(OUT)  :: gama_h_out
+!!!
+
 ! Local variables
 !****************************************************************************************
@@ -65,4 +78,5 @@
 ! Include
 !****************************************************************************************
+    INCLUDE "YOMCST.h"
     INCLUDE "compbl.h"    
 
@@ -186,4 +200,32 @@
     Bcoef_Q_out = Bcoef_Q
 
+!****************************************************************************************
+! 7)
+! If Pbl is split, return also the other layers in output variables
+!
+!****************************************************************************************
+!!! jyg le 07/02/2012
+       IF (mod(iflag_pbl_split,2) .eq.1) THEN
+!!! nrlmd le 02/05/2011
+    DO k= 1, klev
+      DO i= 1, klon
+        Ccoef_H_out(i,k) = Ccoef_H(i,k)
+        Dcoef_H_out(i,k) = Dcoef_H(i,k)
+        Ccoef_Q_out(i,k) = Ccoef_Q(i,k)
+        Dcoef_Q_out(i,k) = Dcoef_Q(i,k)
+        Kcoef_hq_out(i,k) = Kcoefhq(i,k)
+          IF (k.eq.1) THEN
+            gama_h_out(i,k)  = 0.
+            gama_q_out(i,k)  = 0.
+          ELSE
+            gama_h_out(i,k)  = gamah(i,k)
+            gama_q_out(i,k)  = gamaq(i,k)
+          ENDIF
+      ENDDO
+    ENDDO
+!!!      
+       ENDIF  ! (mod(iflag_pbl_split,2) .eq.1)
+!!!
+
   END SUBROUTINE climb_hq_down
 !
@@ -252,6 +294,4 @@
        Bcoef(i) = -1. * RG / buf
     END DO
-    acoef(knon+1: klon) = 0.
-    bcoef(knon+1: klon) = 0.
 
   END SUBROUTINE calc_coef
@@ -261,4 +301,9 @@
   SUBROUTINE climb_hq_up(knon, dtime, t_old, q_old, &
        flx_q1, flx_h1, paprs, pplay, &
+!!! nrlmd le 02/05/2011
+       Acoef_H_in, Acoef_Q_in, Bcoef_H_in, Bcoef_Q_in, &
+       Ccoef_H_in, Ccoef_Q_in, Dcoef_H_in, Dcoef_Q_in, &
+       Kcoef_hq_in, gama_q_in, gama_h_in, &
+!!!
        flux_q, flux_h, d_q, d_t)
 ! 
@@ -269,5 +314,5 @@
 ! C and D are known from before and k is index of the vertical layer.
 !   
-    INCLUDE "YOMCST.h"
+
 ! Input arguments
 !****************************************************************************************
@@ -279,4 +324,10 @@
     REAL, DIMENSION(klon,klev), INTENT(IN)   :: pplay
 
+!!! nrlmd le 02/05/2011
+    REAL, DIMENSION(klon), INTENT(IN)        :: Acoef_H_in,Acoef_Q_in, Bcoef_H_in, Bcoef_Q_in
+    REAL, DIMENSION(klon,klev), INTENT(IN)   :: Ccoef_H_in, Ccoef_Q_in, Dcoef_H_in, Dcoef_Q_in
+    REAL, DIMENSION(klon,klev), INTENT(IN)   :: Kcoef_hq_in, gama_q_in, gama_h_in
+!!!
+
 ! Output arguments
 !****************************************************************************************
@@ -289,4 +340,9 @@
     REAL, DIMENSION(klon)                    :: psref         
     INTEGER                                  :: k, i, ierr
+ 
+! Include
+!****************************************************************************************
+    INCLUDE "YOMCST.h"
+    INCLUDE "compbl.h"    
 
 !****************************************************************************************
@@ -301,4 +357,30 @@
 
     psref(1:knon) = paprs(1:knon,1)  
+
+!!! jyg le 07/02/2012
+       IF (mod(iflag_pbl_split,2) .eq.1) THEN
+!!! nrlmd le 02/05/2011
+    DO i = 1, knon
+      Acoef_H(i)=Acoef_H_in(i)
+      Acoef_Q(i)=Acoef_Q_in(i)
+      Bcoef_H(i)=Bcoef_H_in(i)
+      Bcoef_Q(i)=Bcoef_Q_in(i)
+    ENDDO
+    DO k = 1, klev
+      DO i = 1, knon
+        Ccoef_H(i,k)=Ccoef_H_in(i,k)
+        Ccoef_Q(i,k)=Ccoef_Q_in(i,k)
+        Dcoef_H(i,k)=Dcoef_H_in(i,k)
+        Dcoef_Q(i,k)=Dcoef_Q_in(i,k)
+        Kcoefhq(i,k)=Kcoef_hq_in(i,k)
+          IF (k.gt.1) THEN
+            gamah(i,k)=gama_h_in(i,k)
+            gamaq(i,k)=gama_q_in(i,k)
+          ENDIF
+      ENDDO
+    ENDDO
+!!!      
+       ENDIF  ! (mod(iflag_pbl_split,2) .eq.1)
+!!!
 
 !****************************************************************************************
Index: /LMDZ5/trunk/libf/phylmd/climb_wind_mod.F90
===================================================================
--- /LMDZ5/trunk/libf/phylmd/climb_wind_mod.F90	(revision 2158)
+++ /LMDZ5/trunk/libf/phylmd/climb_wind_mod.F90	(revision 2159)
@@ -44,5 +44,5 @@
 
     ALLOCATE(alf1(klon), stat=ierr)
-    IF (ierr /= 0) CALL abort_gcm(modname,'Pb in allocate alf2',1)
+    IF (ierr /= 0) CALL abort_gcm(modname,'Pb in allocate alf1',1)
 
     ALLOCATE(alf2(klon), stat=ierr)
@@ -74,4 +74,8 @@
 !
   SUBROUTINE climb_wind_down(knon, dtime, coef_in, pplay, paprs, temp, delp, u_old, v_old, &
+!!! nrlmd le 02/05/2011
+       Ccoef_U_out, Ccoef_V_out, Dcoef_U_out, Dcoef_V_out, &
+       Kcoef_m_out, alf_1_out, alf_2_out, &
+!!!
        Acoef_U_out, Acoef_V_out, Bcoef_U_out, Bcoef_V_out)
 !
@@ -81,5 +85,5 @@
 !
 !
-    INCLUDE "YOMCST.h"
+
 ! Input arguments
 !****************************************************************************************
@@ -101,4 +105,14 @@
     REAL, DIMENSION(klon), INTENT(OUT)       :: Bcoef_V_out
 
+!!! nrlmd le 02/05/2011
+    REAL, DIMENSION(klon,klev), INTENT(OUT)  :: Ccoef_U_out
+    REAL, DIMENSION(klon,klev), INTENT(OUT)  :: Ccoef_V_out
+    REAL, DIMENSION(klon,klev), INTENT(OUT)  :: Dcoef_U_out
+    REAL, DIMENSION(klon,klev), INTENT(OUT)  :: Dcoef_V_out
+    REAL, DIMENSION(klon,klev), INTENT(OUT)  :: Kcoef_m_out
+    REAL, DIMENSION(klon), INTENT(OUT)       :: alf_1_out
+    REAL, DIMENSION(klon), INTENT(OUT)       :: alf_2_out
+!!!
+
 ! Local variables
 !****************************************************************************************
@@ -106,4 +120,8 @@
     INTEGER                                  :: k, i
 
+! Include
+!****************************************************************************************
+    INCLUDE "YOMCST.h"
+    INCLUDE "compbl.h"    
 
 !****************************************************************************************
@@ -148,4 +166,29 @@
     Bcoef_V_out = Bcoef_V
 
+!****************************************************************************************
+! 7)
+! If Pbl is split, return also the other layers in output variables
+!
+!****************************************************************************************
+!!! jyg le 07/02/2012
+       IF (mod(iflag_pbl_split,2) .eq.1) THEN
+!!! nrlmd le 02/05/2011
+    DO k= 1, klev
+      DO i= 1, klon
+        Ccoef_U_out(i,k) = Ccoef_U(i,k)
+        Ccoef_V_out(i,k) = Ccoef_V(i,k)
+        Dcoef_U_out(i,k) = Dcoef_U(i,k)
+        Dcoef_V_out(i,k) = Dcoef_V(i,k)
+        Kcoef_m_out(i,k) = Kcoefm(i,k)
+      ENDDO
+    ENDDO
+    DO i= 1, klon
+      alf_1_out(i)   = alf1(i)
+      alf_2_out(i)   = alf2(i)
+    ENDDO
+!!!      
+       ENDIF  ! (mod(iflag_pbl_split,2) .eq.1)
+!!!
+
   END SUBROUTINE climb_wind_down
 !
@@ -209,6 +252,4 @@
        Bcoef(i) = -RG/buf
     END DO
-    acoef(knon+1: klon) = 0.
-    bcoef(knon+1: klon) = 0.
 
   END SUBROUTINE calc_coef
@@ -218,4 +259,9 @@
 
   SUBROUTINE climb_wind_up(knon, dtime, u_old, v_old, flx_u1, flx_v1,  &
+!!! nrlmd le 02/05/2011
+       Acoef_U_in, Acoef_V_in, Bcoef_U_in, Bcoef_V_in, &
+       Ccoef_U_in, Ccoef_V_in, Dcoef_U_in, Dcoef_V_in, &
+       Kcoef_m_in, &
+!!!
        flx_u_new, flx_v_new, d_u_new, d_v_new)
 !
@@ -228,5 +274,4 @@
 !
 !****************************************************************************************
-    INCLUDE "YOMCST.h"
 
 ! Input arguments
@@ -238,4 +283,10 @@
     REAL, DIMENSION(klon), INTENT(IN)       :: flx_u1, flx_v1 ! momentum flux
 
+!!! nrlmd le 02/05/2011
+    REAL, DIMENSION(klon), INTENT(IN)       :: Acoef_U_in,Acoef_V_in, Bcoef_U_in, Bcoef_V_in
+    REAL, DIMENSION(klon,klev), INTENT(IN)  :: Ccoef_U_in, Ccoef_V_in, Dcoef_U_in, Dcoef_V_in
+    REAL, DIMENSION(klon,klev), INTENT(IN)  :: Kcoef_m_in
+!!!
+
 ! Output arguments
 !****************************************************************************************
@@ -247,7 +298,34 @@
     REAL, DIMENSION(klon,klev)              :: u_new, v_new
     INTEGER                                 :: k, i
+
+! Include
+!****************************************************************************************
+    INCLUDE "YOMCST.h"
+    INCLUDE "compbl.h"    
     
 !
 !****************************************************************************************
+
+!!! jyg le 07/02/2012
+       IF (mod(iflag_pbl_split,2) .eq.1) THEN
+!!! nrlmd le 02/05/2011
+    DO i = 1, knon
+      Acoef_U(i)=Acoef_U_in(i)
+      Acoef_V(i)=Acoef_V_in(i)
+      Bcoef_U(i)=Bcoef_U_in(i)
+      Bcoef_V(i)=Bcoef_V_in(i)
+    ENDDO
+    DO k = 1, klev
+      DO i = 1, knon
+        Ccoef_U(i,k)=Ccoef_U_in(i,k)
+        Ccoef_V(i,k)=Ccoef_V_in(i,k)
+        Dcoef_U(i,k)=Dcoef_U_in(i,k)
+        Dcoef_V(i,k)=Dcoef_V_in(i,k)
+        Kcoefm(i,k)=Kcoef_m_in(i,k)
+      ENDDO
+    ENDDO
+!!!
+       ENDIF  ! (mod(iflag_pbl_split,2) .eq.1)
+!!!
 
 ! Niveau 1
Index: /LMDZ5/trunk/libf/phylmd/compbl.h
===================================================================
--- /LMDZ5/trunk/libf/phylmd/compbl.h	(revision 2158)
+++ /LMDZ5/trunk/libf/phylmd/compbl.h	(revision 2159)
@@ -2,5 +2,9 @@
       ! $Header$
       !
-      integer iflag_pbl
-      common/compbl/iflag_pbl
+!jyg+nrlmd<
+!!!      integer iflag_pbl
+!!!      common/compbl/iflag_pbl
+      integer iflag_pbl,iflag_pbl_split
+      common/compbl/iflag_pbl,iflag_pbl_split
+!>jyg+nrlmd
 !$OMP THREADPRIVATE(/compbl/)
Index: /LMDZ5/trunk/libf/phylmd/conf_phys_m.F90
===================================================================
--- /LMDZ5/trunk/libf/phylmd/conf_phys_m.F90	(revision 2158)
+++ /LMDZ5/trunk/libf/phylmd/conf_phys_m.F90	(revision 2159)
@@ -164,4 +164,5 @@
     REAL, SAVE ::  fmagic_omp, pmagic_omp
     INTEGER,SAVE :: iflag_pbl_omp,lev_histhf_omp,lev_histday_omp,lev_histmth_omp
+    INTEGER,SAVE :: iflag_pbl_split_omp
     Integer, save :: lev_histins_omp, lev_histLES_omp 
     INTEGER, SAVE :: lev_histdayNMC_omp
@@ -1198,4 +1199,12 @@
     iflag_pbl_omp = 1
     call getin('iflag_pbl',iflag_pbl_omp)
+    !
+    !Config Key  = iflag_pbl_split
+    !Config Desc = binary flag: least signif bit = split vdf; next bit = split thermals
+    !Config Def  = 0
+    !Config Help = 0-> no splitting; 1-> vdf splitting; 2-> thermals splitting; 3-> full splitting
+    !
+    iflag_pbl_split_omp = 0
+    call getin('iflag_pbl_split',iflag_pbl_split_omp)
     !
     !Config Key  = iflag_thermals
@@ -1854,4 +1863,5 @@
     pmagic = pmagic_omp
     iflag_pbl = iflag_pbl_omp
+    iflag_pbl_split = iflag_pbl_split_omp
     lev_histhf = lev_histhf_omp
     lev_histday = lev_histday_omp
@@ -2110,4 +2120,5 @@
     write(lunout,*)' freq_calNMC = ',freq_calNMC
     write(lunout,*)' iflag_pbl = ', iflag_pbl
+    write(lunout,*)' iflag_pbl_split = ', iflag_pbl_split
     write(lunout,*)' iflag_thermals = ', iflag_thermals
     write(lunout,*)' iflag_thermals_ed = ', iflag_thermals_ed
Index: /LMDZ5/trunk/libf/phylmd/hbtm2l.F90
===================================================================
--- /LMDZ5/trunk/libf/phylmd/hbtm2l.F90	(revision 2159)
+++ /LMDZ5/trunk/libf/phylmd/hbtm2l.F90	(revision 2159)
@@ -0,0 +1,702 @@
+
+! $Header$
+
+SUBROUTINE hbtm2l(knon, paprs, pplay, t2m, t10m, q2m, q10m, ustar, flux_t, flux_q, u, v, t, q, pblh, therm, plcl, cape, &
+    cin, eauliq, ctei, d_qt, d_thv, dlt_2, xhis, posint, omega, diagok)
+  USE dimphy
+  IMPLICIT NONE
+
+  ! ***************************************************************
+  ! *                                                             *
+  ! * HBTM2L   D'apres Holstag&Boville et Troen&Mahrt             *
+  ! *                 JAS 47              BLM                     *
+  ! * Algorithmes These Anne Mathieu                              *
+  ! * Critere d'Entrainement Peter Duynkerke (JAS 50)             *
+  ! * written by  : Anne MATHIEU & Alain LAHELLEC, 22/11/99       *
+  ! * features : implem. exces Mathieu                            *
+  ! ***************************************************************
+  ! * mods : decembre 99 passage th a niveau plus bas. voir fixer *
+  ! ***************************************************************
+  ! * fin therm a la HBTM passage a forme Mathieu 12/09/2001      *
+  ! ***************************************************************
+  ! AM Fev 2003 Adaptation a LMDZ version couplee                 *
+  ! *
+  ! Pour le moment on fait passer en argument les grdeurs de surface :
+  ! flux, t,q2m, t,q10m, on va utiliser systematiquement les grdeurs a 2m ms
+  ! on garde la possibilite de changer si besoin est (jusqu'a present la
+  ! forme de HB avec le 1er niveau modele etait conservee)       *
+  ! ***************************************************************
+  ! * re-ecriture complete Alain Mars 2012 dans LMDZ5V5           *
+  ! ***************************************************************
+  ! ym#include "dimensions.h"
+  ! ym#include "dimphy.h"
+  include "YOMCST.h"
+  REAL rlvcp, reps
+  ! Arguments:
+
+  INTEGER knon ! nombre de points a calculer
+  ! AM
+  REAL t2m(klon), t10m(klon) ! temperature a 2 et 10m
+  REAL q2m(klon), q10m(klon) ! q a 2 et 10m
+  REAL ustar(klon)
+  REAL paprs(klon, klev+1) ! pression a inter-couche (Pa)
+  REAL pplay(klon, klev) ! pression au milieu de couche (Pa)
+  REAL flux_t(klon, klev), flux_q(klon, klev) ! Flux
+  REAL u(klon, klev) ! vitesse U (m/s)
+  REAL v(klon, klev) ! vitesse V (m/s)
+  REAL t(klon, klev) ! temperature (K)
+  REAL q(klon, klev) ! vapeur d'eau (kg/kg)
+
+  INTEGER isommet
+  REAL vk
+  PARAMETER (vk=0.35) ! Von Karman => passer a .41 ! cf U.Olgstrom
+  REAL ricr
+  PARAMETER (ricr=0.4)
+  REAL fak
+  PARAMETER (fak=8.5) ! b calcul du Prandtl et de dTetas
+  REAL fakn
+  PARAMETER (fakn=7.2) ! a
+  REAL onet
+  PARAMETER (onet=1.0/3.0)
+  REAL betam
+  PARAMETER (betam=15.0) ! pour Phim / h dans la S.L stable
+  REAL betah
+  PARAMETER (betah=15.0)
+  REAL betas
+  PARAMETER (betas=5.0) ! Phit dans la S.L. stable (mais 2 formes / z/OBL<>1
+  REAL sffrac
+  PARAMETER (sffrac=0.1) ! S.L. = z/h < .1
+  REAL binm
+  PARAMETER (binm=betam*sffrac)
+  REAL binh
+  PARAMETER (binh=betah*sffrac)
+
+  REAL q_star, t_star
+  REAL b1, b2, b212, b2sr ! Lambert correlations T' q' avec T* q*
+  PARAMETER (b1=70., b2=20.) ! b1 entre 70 et 100
+
+  REAL z(klon, klev)
+  ! AM
+  REAL zref, dt0
+  PARAMETER (zref=2.) ! Niveau de ref a 2m
+  PARAMETER (dt0=0.1) ! convergence do while
+
+  INTEGER i, k, j
+  REAL khfs(klon) ! surface kinematic heat flux [mK/s]
+  REAL kqfs(klon) ! sfc kinematic constituent flux [m/s]
+  REAL heatv(klon) ! surface virtual heat flux
+  REAL rhino(klon, klev) ! bulk Richardon no. mais en Theta_v
+  LOGICAL unstbl(klon) ! pts w/unstbl pbl (positive virtual ht flx)
+  LOGICAL check(klon) ! True=>chk if Richardson no.>critcal
+  LOGICAL omegafl(klon) ! flag de prolongement cape pour pt Omega
+  REAL obklen(klon) ! Monin-Obukhov lengh
+
+  REAL pblh(klon) ! PBL H               (m)
+  REAL therm(klon) ! exces du thermique  (K)
+  REAL plcl(klon) ! Lifted Cnd Level (Pa)
+  REAL cape(klon) ! Cape
+  REAL cin(klon) ! Inhibition
+  REAL eauliq(klon) ! Eau Liqu integree
+  REAL ctei(klon) ! Cld Top Entr. Instab.
+  REAL d_qt(klon) ! Saut de qT a l'inversion
+  REAL d_thv(klon) !         Theta_e
+  REAL dlt_2(klon) ! Ordonnee a gauche de courbe de melange
+  REAL xhis(klon) ! fraction de melange pour flottab nulle
+  REAL posint(klon) ! partie positive de l'int. de Peter
+  REAL omega(klon) ! point ultime de l'ascention du thermique
+  REAL diagok(klon) ! pour traiter les sous-mailles sans info
+  ! Algorithme thermique
+  REAL s(klon, klev) ! [P/Po]^Kappa milieux couches
+  REAL th_th(klon) ! potential temperature of thermal
+  REAL the_th(klon) ! equivalent potential temperature of thermal
+  REAL qt_th(klon) ! total water of thermal
+  REAL tbef(klon) ! T thermique niveau ou calcul precedent
+  LOGICAL zsat(klon) ! le thermique est sature
+  LOGICAL zcin(klon) ! calcul d'inhibition
+  REAL kape(klon) ! Cape locale
+  REAL kin(klon) ! Cin locale
+  ! calcul de CTEI etc
+  REAL the1, the2, aa, bb, zthvd, zthvu, qsat, chi, rh, zxt, zdu2
+  REAL rnum, denom, th1, th2, tv1, tv2, thv1, thv2, ql1, ql2, dt
+  REAL dqsat_dt, qsat2, qt1, q1, q2, t1, t2, tl1, te2, xnull, delt_the
+  REAL delt_qt, quadsat, spblh, reduc
+  ! diag      REAL dTv21(klon,klev)
+
+  REAL phiminv(klon) ! inverse phi function for momentum
+  REAL phihinv(klon) ! inverse phi function for heat
+  REAL wm(klon) ! turbulent velocity scale for momentum
+  REAL zm(klon) ! current level height
+  REAL zp(klon) ! current level height + one level up
+  REAL zcor, zdelta, zcvm5
+  REAL fac, pblmin
+  REAL missing_val
+
+  include "YOETHF.h"
+  include "FCTTRE.h"
+
+  ! c      missing_val=nf90_fill_real (avec include netcdf)
+  missing_val = 0.
+
+  ! initialisations (Anne)
+  isommet = klev
+  b212 = sqrt(b1*b2)
+  b2sr = sqrt(b2)
+
+  ! Initialisation thermo
+  rlvcp = rlvtt/rcpd
+  reps = rd/rv
+  ! raz
+  q_star = 0.
+  t_star = 0.
+  cape(:) = missing_val
+  kape(:) = 0.
+  cin(:) = missing_val
+  eauliq(:) = missing_val
+  ctei(:) = missing_val
+  d_qt(:) = missing_val
+  d_thv(:) = missing_val
+  dlt_2(:) = missing_val
+  xhis(:) = missing_val
+  posint(:) = missing_val
+  kin(:) = missing_val
+  omega(:) = missing_val
+  diagok(:) = 0.
+  ! diag      dTv21(:,:)= missing_val
+
+  ! Calculer les hauteurs de chaque couche
+  DO i = 1, knon
+    z(i, 1) = rd*t(i, 1)/(0.5*(paprs(i,1)+pplay(i,1)))*(paprs(i,1)-pplay(i,1))/rg
+    s(i, 1) = (pplay(i,1)/paprs(i,1))**rkappa
+  END DO
+  ! s(k) = [pplay(k)/ps]^kappa
+  ! + + + + + + + + + pplay  <-> s(k)   t  dp=pplay(k-1)-pplay(k)
+
+  ! -----------------  paprs <-> sig(k)
+
+  ! + + + + + + + + + pplay  <-> s(k-1)
+
+
+  ! + + + + + + + + + pplay  <-> s(1)   t  dp=paprs-pplay   z(1)
+
+  ! -----------------  paprs <-> sig(1)
+
+  DO k = 2, klev
+    DO i = 1, knon
+      z(i, k) = z(i, k-1) + rd*0.5*(t(i,k-1)+t(i,k))/paprs(i, k)*(pplay(i,k-1)-pplay(i,k))/rg
+      s(i, k) = (pplay(i,k)/paprs(i,1))**rkappa
+    END DO
+  END DO
+  ! ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+  ! ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+  ! +++  Determination des grandeurs de surface  +++++++++++++++++++++
+  ! ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+  ! ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+  DO i = 1, knon
+    ! AM Niveau de ref choisi a 2m
+    zxt = t2m(i)
+
+    ! ***************************************************
+    ! attention, il doit s'agir de <w'theta'>
+    ! ;Calcul de tcls virtuel et de w'theta'virtuel
+    ! ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+    ! tcls=tcls*(1+.608*qcls)
+
+    ! ;Pour avoir w'theta',
+    ! ; il faut diviser par ro.Cp
+    ! Cp=Cpd*(1+0.84*qcls)
+    ! fcs=fcs/(ro_surf*Cp)
+    ! ;On transforme w'theta' en w'thetav'
+    ! Lv=(2.501-0.00237*(tcls-273.15))*1.E6
+    ! xle=xle/(ro_surf*Lv)
+    ! fcsv=fcs+.608*xle*tcls
+    ! ***************************************************
+    ! dif khfs est deja w't'_v / heatv(i) = khfs(i) + RETV*zxt*kqfs(i)
+    ! AM calcul de Ro = paprs(i,1)/Rd zxt
+    ! AM convention >0 vers le bas ds lmdz
+    khfs(i) = -flux_t(i, 1)*zxt*rd/(rcpd*paprs(i,1))
+    kqfs(i) = -flux_q(i, 1)*zxt*rd/(paprs(i,1))
+    ! AM   verifier que khfs et kqfs sont bien de la forme w'l'
+    heatv(i) = khfs(i) + retv*zxt*kqfs(i)
+    ! a comparer aussi aux sorties de clqh : flux_T/RoCp et flux_q/RoLv
+    ! AM ustar est en entree (calcul dans stdlevvar avec t2m q2m)
+    ! Theta et qT du thermique sans exces
+    qt_th(i) = q2m(i)
+    ! Al1 Th_th restera la Theta du thermique sans exces jusqu'au 3eme calcul
+    th_th(i) = t2m(i)
+  END DO
+
+  DO i = 1, knon
+    rhino(i, 1) = 0.0 ! Global Richardson
+    check(i) = .TRUE.
+    pblh(i) = z(i, 1) ! on initialise pblh a l'altitude du 1er niveau
+    ! Attention Plcl est pression ou altitude ?
+    ! plcl(i) = 6000. ! m
+    plcl(i) = 200. ! hPa
+    IF (heatv(i)>0.0001) THEN
+      ! Lambda = -u*^3 / (alpha.g.kvon.<w'Theta'v>
+      obklen(i) = -t(i, 1)*ustar(i)**3/(rg*vk*heatv(i))
+    ELSE
+      ! set pblh to the friction high (cf + bas)
+      pblh(i) = 700.0*ustar(i)
+      check(i) = .FALSE.
+    END IF
+  END DO
+
+
+  ! ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+  ! PBL height calculation:
+  ! Search for level of pbl. Scan upward until the Richardson number between
+  ! the first level and the current level exceeds the "critical" value.
+  ! (bonne idee Nu de separer le Ric et l'exces de temp du thermique)
+  ! ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+  fac = 100.0
+  DO k = 2, isommet
+    DO i = 1, knon
+      IF (check(i)) THEN
+        zdu2 = u(i, k)**2 + v(i, k)**2
+        zdu2 = max(zdu2, 1.0E-20)
+        ! Theta_v environnement
+        zthvd = t(i, k)/s(i, k)*(1.+retv*q(i,k))
+        zthvu = th_th(i)*(1.+retv*qt_th(i))
+        ! Le Ri bulk par Theta_v
+        rhino(i, k) = (z(i,k)-zref)*rg*(zthvd-zthvu)/(zdu2*0.5*(zthvd+zthvu))
+
+        IF (rhino(i,k)>=ricr) THEN
+          pblh(i) = z(i, k-1) + (z(i,k-1)-z(i,k))*(ricr-rhino(i,k-1))/(rhino(i,k-1)-rhino(i,k))
+          ! test04 (la pblh est encore ici sous-estime'e)
+          pblh(i) = pblh(i) + 100.
+          ! pblT(i) = t(i,k-1) + (t(i,k)-t(i,k-1)) *
+          ! .              (pblh(i)-z(i,k-1))/(z(i,k)-z(i,k-1))
+          check(i) = .FALSE.
+        END IF
+      END IF
+    END DO
+  END DO
+
+
+  ! Set pbl height to maximum value where computation exceeds number of
+  ! layers allowed
+
+  DO i = 1, knon
+    IF (check(i)) pblh(i) = z(i, isommet)
+  END DO
+
+  ! Improve estimate of pbl height for the unstable points.
+  ! Find unstable points (sensible heat flux is upward):
+
+  DO i = 1, knon
+    IF (heatv(i)>0.) THEN
+      unstbl(i) = .TRUE.
+      check(i) = .TRUE.
+    ELSE
+      unstbl(i) = .FALSE.
+      check(i) = .FALSE.
+    END IF
+  END DO
+
+  ! For the unstable case, compute velocity scale and the
+  ! convective temperature excess:
+
+  DO i = 1, knon
+    IF (check(i)) THEN
+      phiminv(i) = (1.-binm*pblh(i)/obklen(i))**onet
+      ! ***************************************************
+      ! Wm ? et W* ? c'est la formule pour z/h < .1
+      ! ;Calcul de w* ;;
+      ! ;;;;;;;;;;;;;;;;
+      ! w_star=((g/tcls)*fcsv*z(ind))^(1/3.) [ou prendre la premiere approx de h)
+      ! ;; CALCUL DE wm ;;
+      ! ;;;;;;;;;;;;;;;;;;
+      ! ; Ici on considerera que l'on est dans la couche de surf jusqu'a 100m
+      ! ; On prend svt couche de surface=0.1*h mais on ne connait pas h
+      ! ;;;;;;;;;;;Dans la couche de surface
+      ! if (z(ind) le 20) then begin
+      ! Phim=(1.-15.*(z(ind)/L))^(-1/3.)
+      ! wm=u_star/Phim
+      ! ;;;;;;;;;;;En dehors de la couche de surface
+      ! endif else if (z(ind) gt 20) then begin
+      ! wm=(u_star^3+c1*w_star^3)^(1/3.)
+      ! endif
+      ! ***************************************************
+      wm(i) = ustar(i)*phiminv(i)
+      ! ======================================================================
+      ! valeurs de Dominique Lambert de la campagne SEMAPHORE :
+      ! <T'^2> = 100.T*^2; <q'^2> = 20.q*^2 a 10m
+      ! <Tv'^2> = (1+1.2q).100.T* + 1.2Tv.sqrt(20*100).T*.q* + (.608*Tv)^2*20.q*^2;
+      ! et dTetavS = sqrt(<Tv'^2>) ainsi calculee.
+      ! avec : T*=<w'T'>_s/w* et q*=<w'q'>/w*
+      ! !!! on peut donc utiliser w* pour les fluctuations <-> Lambert
+      ! (leur corellation pourrait dependre de beta par ex)
+      ! if fcsv(i,j) gt 0 then begin
+      ! dTetavs=b1*(1.+2.*.608*q_10(i,j))*(fcs(i,j)/wm(i,j))^2+$
+      ! (.608*Thetav_10(i,j))^2*b2*(xle(i,j)/wm(i,j))^2+$
+      ! 2.*.608*thetav_10(i,j)*sqrt(b1*b2)*(xle(i,j)/wm(i,j))*(fcs(i,j)/wm(i,j))
+      ! dqs=b2*(xle(i,j)/wm(i,j))^2
+      ! theta_s(i,j)=thetav_10(i,j)+sqrt(dTetavs)
+      ! q_s(i,j)=q_10(i,j)+sqrt(dqs)
+      ! endif else begin
+      ! Theta_s(i,j)=thetav_10(i,j)
+      ! q_s(i,j)=q_10(i,j)
+      ! endelse
+      ! leur reference est le niveau a 10m, mais on prend 2m ici.
+      ! ======================================================================
+      ! Premier calcul de l'exces tu thermique
+      ! ======================================================================
+      ! HBTM        therm(i) = heatv(i)*fak/wm(i)
+      ! forme Mathieu :
+      q_star = max(0., kqfs(i)/wm(i))
+      t_star = max(0., khfs(i)/wm(i))
+      ! Al1 Houston, we have a problem : il arrive en effet que heatv soit
+      ! positif (=thermique instable) mais pas t_star : avec evaporation
+      ! importante, il se peut qu'on refroidisse la 2m Que faire alors ?
+      ! Garder le seul terme en q_star^2 ? ou rendre negatif le t_star^2 ?
+      therm(i) = sqrt(b1*(1.+2.*retv*qt_th(i))*t_star**2+(retv*th_th(i))**2*b2*q_star*q_star+2.*retv*th_th(i)*b212* &
+        q_star*t_star)
+
+      ! Theta et qT du thermique (forme H&B) avec exces
+      ! (attention, on ajoute therm(i) qui est virtuelle ...)
+      ! pourquoi pas sqrt(b1)*t_star ?
+      ! dqs = b2sr*kqfs(i)/wm(i)
+      qt_th(i) = qt_th(i) + b2sr*q_star
+      rhino(i, 1) = 0.0
+    END IF
+  END DO
+
+  ! +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+  ! ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+  ! ++ Improve pblh estimate for unstable conditions using the +++++++
+  ! ++          convective temperature excess :                +++++++
+  ! ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+  ! +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+
+  DO k = 2, isommet
+    DO i = 1, knon
+      IF (check(i)) THEN
+        ! test     zdu2 = (u(i,k)-u(i,1))**2+(v(i,k)-v(i,1))**2+fac*ustar(i)**2
+        zdu2 = u(i, k)**2 + v(i, k)**2
+        zdu2 = max(zdu2, 1.0E-20)
+        ! Theta_v environnement
+        zthvd = t(i, k)/s(i, k)*(1.+retv*q(i,k))
+
+        ! et therm Theta_v (avec hypothese de constance de H&B,
+        ! qui assimile qT a vapeur)
+        zthvu = th_th(i)*(1.+retv*qt_th(i)) + therm(i)
+
+
+        ! Le Ri par Theta_v
+        ! AM Niveau de ref 2m
+        rhino(i, k) = (z(i,k)-zref)*rg*(zthvd-zthvu)/(zdu2*0.5*(zthvd+zthvu))
+
+        ! Niveau critique atteint
+        IF (rhino(i,k)>=ricr) THEN
+          pblh(i) = z(i, k-1) + (z(i,k-1)-z(i,k))*(ricr-rhino(i,k-1))/(rhino(i,k-1)-rhino(i,k))
+          ! test04
+          pblh(i) = pblh(i) + 100.
+          ! pblT(i) = t(i,k-1) + (t(i,k)-t(i,k-1)) *
+          ! .              (pblh(i)-z(i,k-1))/(z(i,k)-z(i,k-1))
+          check(i) = .FALSE.
+        END IF
+      END IF
+    END DO
+  END DO
+
+  ! Set pbl height to maximum value where computation exceeds number of
+  ! layers allowed (H&B)
+
+  DO i = 1, knon
+    IF (check(i)) pblh(i) = z(i, isommet)
+  END DO
+
+  ! PBL height must be greater than some minimum mechanical mixing depth
+  ! Several investigators have proposed minimum mechanical mixing depth
+  ! relationships as a function of the local friction velocity, u*.  We
+  ! make use of a linear relationship of the form h = c u* where c=700.
+  ! The scaling arguments that give rise to this relationship most often
+  ! represent the coefficient c as some constant over the local coriolis
+  ! parameter.  Here we make use of the experimental results of Koracin
+  ! and Berkowicz (1988) [BLM, Vol 43] for wich they recommend 0.07/f
+  ! where f was evaluated at 39.5 N and 52 N.  Thus we use a typical mid
+  ! latitude value for f so that c = 0.07/f = 700.  (H&B)
+  ! Al1 calcul de pblT dans ce cas
+  DO i = 1, knon
+    pblmin = 700.0*ustar(i)
+    IF (pblh(i)<pblmin) check(i) = .TRUE.
+  END DO
+  DO i = 1, knon
+    IF (check(i)) THEN
+      pblh(i) = 700.0*ustar(i)
+      ! et par exemple :
+      ! pblT(i) = t(i,2) + (t(i,3)-t(i,2)) *
+      ! .              (pblh(i)-z(i,2))/(z(i,3)-z(i,2))
+    END IF
+  END DO
+
+  ! ********************************************************************
+  ! pblh is now available; do preparation for final calculations :
+  ! ********************************************************************
+  DO i = 1, knon
+    check(i) = .TRUE.
+    zsat(i) = .FALSE.
+    zcin(i) = .FALSE.
+    ! omegafl utilise pour prolongement CAPE
+    omegafl(i) = .FALSE.
+
+    ! Do additional preparation for unstable cases only, set temperature
+    ! and moisture perturbations depending on stability.
+    ! Rq: les formules sont prises dans leur forme Couche de Surface
+    IF (unstbl(i)) THEN
+      ! Al pblh a change', on recalcule :
+      zxt = (th_th(i)-zref*0.5*rg/rcpd/(1.+rvtmp2*qt_th(i)))*(1.+retv*qt_th(i))
+      phiminv(i) = (1.-binm*pblh(i)/obklen(i))**onet
+      phihinv(i) = sqrt(1.-binh*pblh(i)/obklen(i))
+      wm(i) = ustar(i)*phiminv(i)
+    END IF
+  END DO
+
+
+  ! =======================================================
+  ! last upward integration
+  ! For all unstable layers, compute integral info and CTEI
+  ! =======================================================
+
+  ! 1/Recompute surface characteristics with the improved pblh
+  ! ----------------------------------------------------------
+  DO i = 1, knon
+    IF (unstbl(i)) THEN
+      diagok(i) = 1.
+      ! from missing_value to zero
+      cape(i) = 0.
+      cin(i) = 0.
+      eauliq(i) = 0.
+      ctei(i) = 0.
+      d_qt(i) = 0.
+      d_thv(i) = 0.
+      dlt_2(i) = 0.
+      xhis(i) = 0.
+      posint(i) = 0.
+      kin(i) = 0.
+      omega(i) = 0.
+
+      phiminv(i) = (1.-binm*pblh(i)/obklen(i))**onet
+      wm(i) = ustar(i)*phiminv(i)
+      q_star = max(0., kqfs(i)/wm(i))
+      t_star = max(0., khfs(i)/wm(i))
+      therm(i) = sqrt(b1*(1.+2.*retv*qt_th(i))*t_star**2+(retv*th_th(i))**2*b2*q_star*q_star+2.*retv*th_th(i)*b212* &
+        q_star*t_star)
+      ! Al1diag
+      ! trmb1(i) = b1*(1.+2.*RETV*qT_th(i))*t_star**2
+      ! trmb2(i) = (RETV*Th_th(i))**2*b2*q_star*q_star
+      ! trmb3(i) = 2.*RETV*Th_th(i)*b212*q_star*t_star
+
+      ! Th_th will now be the thermal-theta (including exces)
+      ! c         Th_th(i) = Th_th(i)+sqrt(b1)*max(0.,khfs(i)/wm(i))
+      th_th(i) = th_th(i) + therm(i)
+      ! al1diag
+      ! trmb2(i) = wm(i)
+      ! trmb3(i) = phiminv(i)
+      ! and computes Theta_e for thermal
+      the_th(i) = th_th(i) + rlvcp*qt_th(i)
+    END IF ! unstbl
+    ! Al1 compute a first guess of Plcl with the Bolton/Emanuel formula
+    t2 = th_th(i)
+    ! thermodyn functions
+    zdelta = max(0., sign(1.,rtt-t2))
+    qsat = r2es*foeew(t2, zdelta)/paprs(i, 1)
+    qsat = min(0.5, qsat)
+    zcor = 1./(1.-retv*qsat)
+    qsat = qsat*zcor
+    ! relative humidity of thermal at 2m
+    rh = qt_th(i)/qsat
+    chi = t2/(1669.0-122.0*rh-t2)
+    plcl(i) = paprs(i, 1)*(rh**chi)
+    ! al1diag
+    ! ctei(i) = Plcl(i)
+    ! cape(i) = T2
+    ! trmb1(i)= Chi
+    ! select unstable columns (=thermals)
+    check(i) = .FALSE.
+    IF (heatv(i)>0.) check(i) = .TRUE.
+    ! diag
+    ! dTv21(i,1) = T2*(1+RETV*qT_th(i))-t(i,1)*(1+RETV*q(i,1))
+  END DO
+  ! ----------------------------------
+  ! 2/ upward integration for thermals
+  ! ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ k loop
+  DO k = 2, isommet
+    DO i = 1, knon
+      IF (check(i) .OR. omegafl(i)) THEN
+        ! CC         if (pplay(i,k) .le. plcl(i)) then
+        zm(i) = z(i, k-1)
+        zp(i) = z(i, k)
+        ! Environnement : calcul de Tv1 a partir de t(:,:)== T liquide
+        ! ==============
+        tl1 = t(i, k)
+        t1 = tl1
+        zdelta = max(0., sign(1.,rtt-t1))
+        qsat = r2es*foeew(t1, zdelta)/pplay(i, k)
+        qsat = min(0.5, qsat)
+        zcor = 1./(1.-retv*qsat)
+        qsat = qsat*zcor
+        q1 = min(q(i,k), qsat)
+        ql1 = max(0., q(i,k)-q1)
+        ! thermodyn function (Tl2Tql)
+        dt = rlvcp*ql1
+        DO WHILE (abs(dt)>=dt0)
+          t1 = t1 + dt
+          zdelta = max(0., sign(1.,rtt-t1))
+          zcvm5 = r5les*(1.-zdelta) + r5ies*zdelta
+          qsat = r2es*foeew(t1, zdelta)/pplay(i, k)
+          qsat = min(0.5, qsat)
+          zcor = 1./(1.-retv*qsat)
+          qsat = qsat*zcor
+          dqsat_dt = foede(t1, zdelta, zcvm5, qsat, zcor)
+          ! correction lineaire pour conserver Tl env
+          ! << Tl = T1 + DT - RLvCp*(ql1 - dqsat/dT*DT >>
+          denom = 1. + rlvcp*dqsat_dt
+          q1 = min(q(i,k), qsat)
+          ql1 = q(i, k) - q1 ! can be negative
+          rnum = tl1 - t1 + rlvcp*ql1
+          dt = rnum/denom
+        END DO
+        ql1 = max(0., ql1)
+        tv1 = t1*(1.+retv*q1-ql1)
+        ! Thermique    : on atteint le seuil B/E de condensation
+        ! ==============
+
+        IF (.NOT. zsat(i)) THEN
+          ! first guess from The_th(i) = Th_th(i) + RLvCp* [qv=qT_th(i)]
+          t2 = s(i, k)*the_th(i) - rlvcp*qt_th(i)
+          zdelta = max(0., sign(1.,rtt-t2))
+          qsat = r2es*foeew(t2, zdelta)/pplay(i, k)
+          qsat = min(0.5, qsat)
+          zcor = 1./(1.-retv*qsat)
+          qsat = qsat*zcor
+          q2 = min(qt_th(i), qsat)
+          ql2 = max(0., qt_th(i)-q2)
+          IF (ql2>0.0001) zsat(i) = .TRUE.
+          tbef(i) = t2
+          ! a PBLH non sature
+          IF (zm(i)<pblh(i) .AND. zp(i)>=pblh(i)) THEN
+            reduc = (pblh(i)-zm(i))/(zp(i)-zm(i))
+            spblh = s(i, k-1) + reduc*(s(i,k)-s(i,k-1))
+            ! lmdz : qT1 et Thv1
+            t1 = (t(i,k-1)+reduc*(t(i,k)-t(i,k-1)))
+            thv1 = t1*(1.+retv*q(i,k))/spblh
+            ! on calcule pour le cas sans nuage un ctei en Delta Thv
+            thv2 = t2/spblh*(1.+retv*qt_th(i))
+            ctei(i) = thv1 - thv2
+            tv2 = t2*(1.+retv*q2-ql2)
+            ! diag
+            ! dTv21(i,k) = Tv2-Tv1
+            check(i) = .FALSE.
+            omegafl(i) = .TRUE.
+          END IF
+        END IF
+
+        IF (zsat(i)) THEN
+          ! thermodyn functions (Te2Tqsat)
+          t2 = tbef(i)
+          dt = 1.
+          te2 = s(i, k)*the_th(i)
+          DO WHILE (abs(dt)>=dt0)
+            zdelta = max(0., sign(1.,rtt-t2))
+            zcvm5 = r5les*(1.-zdelta) + r5ies*zdelta
+            qsat = r2es*foeew(t2, zdelta)/pplay(i, k)
+            qsat = min(0.5, qsat)
+            zcor = 1./(1.-retv*qsat)
+            qsat = qsat*zcor
+            dqsat_dt = foede(t2, zdelta, zcvm5, qsat, zcor)
+            ! correction lineaire pour conserver Te_th
+            ! << Te = T2 + DT + RLvCp*(qsatbef + dq/dT*DT >>
+            denom = 1. + rlvcp*dqsat_dt
+            rnum = te2 - t2 - rlvcp*qsat
+            dt = rnum/denom
+            t2 = t2 + dt
+          END DO
+          q2 = min(qt_th(i), qsat)
+          ql2 = max(0., qt_th(i)-q2)
+          ! jusqu'a PBLH y compris
+          IF (zm(i)<pblh(i)) THEN
+
+            ! mais a PBLH, interpolation et complements
+            IF (zp(i)>=pblh(i)) THEN
+              reduc = (pblh(i)-zm(i))/(zp(i)-zm(i))
+              spblh = s(i, k-1) + reduc*(s(i,k)-s(i,k-1))
+              ! CAPE et EauLiq a pblH
+              cape(i) = kape(i) + reduc*(zp(i)-zm(i))*rg*.5/(tv2+tv1)*max(0., (tv2-tv1))
+              eauliq(i) = eauliq(i) + reduc*(paprs(i,k-1)-paprs(i,k))*ql2/rg
+              ! CTEI
+              the2 = (t2+rlvcp*q2)/spblh
+              ! T1 est en realite la Tl env (on a donc strict The1)
+              t1 = (t(i,k-1)+reduc*(t(i,k)-t(i,k-1)))
+              the1 = (t1+rlvcp*q(i,k))/spblh
+              ! Calcul de la Cloud Top Entrainement Instability
+              ! cf Mathieu Lahellec QJRMS (2005) Comments to DYCOMS-II
+              ! saut a l'inversion :
+              delt_the = the1 - the2 ! negatif
+              delt_qt = q(i, k) - qt_th(i) ! negatif
+              d_qt(i) = -delt_qt
+              dlt_2(i) = .63*delt_the - the2*delt_qt
+              ! init ctei(i)
+              ctei(i) = dlt_2(i)
+              IF (dlt_2(i)<-0.1) THEN
+                ! integrale de Peter :
+                aa = delt_the - delt_qt*(rlvcp-retv*the2)
+                bb = (rlvcp-(1.+retv)*the2)*ql2
+                d_thv(i) = aa - bb
+                ! approx de Xhi_s et de l'integrale Xint=ctei(i)
+                xhis(i) = bb/(aa-dlt_2(i))
+                ! trmb1(i) = xhis
+                ! trmb3(i) = dlt_2
+                xnull = bb/aa
+                IF (xhis(i)>0.1) THEN
+                  ctei(i) = dlt_2(i)*xhis(i) + aa*(1.-xhis(i)) + bb*alog(xhis(i))
+                ELSE
+                  ctei(i) = .5*(dlt_2(i)+aa-bb)
+                END IF
+                IF (xnull>0.) THEN
+                  posint(i) = aa - bb + bb*alog(xnull)
+                ELSE
+                  posint(i) = 0.
+                END IF
+              ELSE
+                ctei(i) = 1.
+                posint(i) = 1.
+              END IF
+              check(i) = .FALSE.
+              omegafl(i) = .TRUE.
+            END IF ! end a pblh
+            IF (check(i)) eauliq(i) = eauliq(i) + (paprs(i,k)-paprs(i,k+1))*ql2/rg
+          END IF
+
+        END IF ! Zsat
+
+        ! KAPE : thermique / environnement
+        tv2 = t2*(1.+retv*q2-ql2)
+        ! diag
+        ! dTv21(i,k) = Tv2-Tv1
+        ! Kape courante
+        kape(i) = kape(i) + (zp(i)-zm(i))*rg*.5/(tv2+tv1)*max(0., (tv2-tv1))
+        ! Cin
+        IF (zcin(i) .AND. tv2-tv1>0.) THEN
+          zcin(i) = .FALSE.
+          cin(i) = kin(i)
+        END IF
+        IF (.NOT. zcin(i) .AND. tv2-tv1<0.) THEN
+          zcin(i) = .TRUE.
+          kin(i) = kin(i) + (zp(i)-zm(i))*rg*.5/(tv2+tv1)*min(0., (tv2-tv1))
+        END IF
+        IF (kape(i)+kin(i)<0.) THEN
+          omega(i) = zm(i)
+          ! trmb3(i) = paprs(i,k)
+          omegafl(i) = .FALSE.
+          ! diag
+          ! print*,'Tv2-Tv1 (k): ',i,(dTv21(i,j),j=1,k)
+        END IF
+        ! CC         EndIf !plcl
+      END IF ! check(i)
+    END DO
+  END DO ! end of level loop
+  ! ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ end k loop
+  RETURN
+END SUBROUTINE hbtm2l
Index: /LMDZ5/trunk/libf/phylmd/limit_netcdf.F90
===================================================================
--- /LMDZ5/trunk/libf/phylmd/limit_netcdf.F90	(revision 2158)
+++ /LMDZ5/trunk/libf/phylmd/limit_netcdf.F90	(revision 2159)
@@ -126,5 +126,6 @@
   ELSE
      WRITE(lunout,*) 'ERROR! No sea-ice input file was found.'
-     WRITE(lunout,*) 'One of following files must be availible : ',trim(famipsic),', ',trim(fcpldsic),', ',trim(fhistsic), trim(feraici)
+     WRITE(lunout,*) 'One of following files must be availible : ',trim(famipsic),', ',trim(fcpldsic),', ', &
+                      trim(fhistsic), trim(feraici)
      CALL abort_gcm('limit_netcdf','No sea-ice file was found',1)
   END IF
Index: /LMDZ5/trunk/libf/phylmd/pbl_surface_mod.F90
===================================================================
--- /LMDZ5/trunk/libf/phylmd/pbl_surface_mod.F90	(revision 2158)
+++ /LMDZ5/trunk/libf/phylmd/pbl_surface_mod.F90	(revision 2159)
@@ -174,4 +174,9 @@
        rain_f,    snow_f,    solsw_m,  sollw_m,       &
        t,         q,         u,        v,             &
+!!! nrlmd+jyg le 02/05/2011 et le 20/02/2012
+!!       t_x,       q_x,       t_w,      q_w,           &
+       wake_dlt,             wake_dlq,                &
+       wake_cstar,           wake_s,                  &
+!!!
        pplay,     paprs,     pctsrf,                  &
        ts,        alb1, alb2,ustar, u10m, v10m,wstar, &
@@ -181,6 +186,20 @@
        zxtsol,    zxfluxlat, zt2m,     qsat2m,        &
        d_t,       d_q,       d_u,      d_v, d_t_diss, & 
+!!! nrlmd+jyg le 02/05/2011 et le 20/02/2012
+       d_t_w,     d_q_w,                              &
+       d_t_x,     d_q_x,                              & 
+!!       d_wake_dlt,d_wake_dlq,                         &
+       zxsens_x,  zxfluxlat_x,zxsens_w,zxfluxlat_w,   &
+!!!
+!!! nrlmd le 13/06/2011
+       delta_tsurf,wake_dens,cdragh_x,cdragh_w,       &
+       cdragm_x,cdragm_w,kh,kh_x,kh_w,                &
+!!!
        zcoefh,    zcoefm,    slab_wfbils,             &
        qsol_d,    zq2m,      s_pblh,   s_plcl,        &
+!!!
+!!! jyg le 08/02/2012
+       s_pblh_x, s_plcl_x,   s_pblh_w, s_plcl_w,      &
+!!!
        s_capCL,   s_oliqCL,  s_cteiCL, s_pblT,        &
        s_therm,   s_trmb1,   s_trmb2,  s_trmb3,       &
@@ -191,5 +210,10 @@
        wfbils,    wfbilo,    flux_t,   flux_u, flux_v,&
        dflux_t,   dflux_q,   zxsnow,                  &
-       zxfluxt,   zxfluxq,   q2m,      flux_q, tke    )
+       zxfluxt,   zxfluxq,   q2m,      flux_q, tke,   &
+!!! nrlmd+jyg le 02/05/2011 et le 20/02/2012
+!!        tke_x,     tke_w                              &
+       wake_dltke                                     &
+!!!
+                        )
 !****************************************************************************************
 ! Auteur(s) Z.X. Li (LMD/CNRS) date: 19930818
@@ -221,4 +245,8 @@
 ! u--------input-R- vitesse u
 ! v--------input-R- vitesse v
+! wake_dlt-input-R- temperatre difference between (w) and (x) (K)
+! wake_dlq-input-R- humidity difference between (w) and (x) (kg/kg)
+!wake_cstar-input-R- wake gust front speed (m/s)
+! wake_s---input-R- wake fractionnal area
 ! ts-------input-R- temperature du sol (en Kelvin)
 ! paprs----input-R- pression a intercouche (Pa)
@@ -240,4 +268,5 @@
 !                    (orientation positive vers le bas)
 ! tke---input/output-R- tke (kg/m**2/s)
+! wake_dltke-input/output-R- tke difference between (w) and (x) (kg/m**2/s)
 ! flux_q---output-R- flux de vapeur d'eau (kg/m**2/s)
 ! flux_u---output-R- tension du vent X: (kg m/s)/(m**2 s) ou Pascal
@@ -299,7 +328,21 @@
 ! Martin
 
+!!! nrlmd+jyg le 02/05/2011 et le 20/02/2012
+!!    REAL, DIMENSION(klon,klev),   INTENT(IN)        :: t_x       ! Température hors poche froide
+!!    REAL, DIMENSION(klon,klev),   INTENT(IN)        :: t_w       ! Température dans la poches froide
+!!    REAL, DIMENSION(klon,klev),   INTENT(IN)        :: q_x       ! 
+!!    REAL, DIMENSION(klon,klev),   INTENT(IN)        :: q_w       ! Pareil pour l'humidité
+    REAL, DIMENSION(klon,klev),   INTENT(IN)        :: wake_dlt  !temperature difference between (w) and (x) (K)
+    REAL, DIMENSION(klon,klev),   INTENT(IN)        :: wake_dlq  !humidity difference between (w) and (x) (K)
+    REAL, DIMENSION(klon),        INTENT(IN)        :: wake_s    ! Fraction de poches froides
+    REAL, DIMENSION(klon),        INTENT(IN)        :: wake_cstar! Vitesse d'expansion des poches froides
+    REAL, DIMENSION(klon),        INTENT(IN)        :: wake_dens
+!!!
+
 ! Input/Output variables
 !****************************************************************************************
     REAL, DIMENSION(klon, nbsrf), INTENT(INOUT)     :: ts      ! temperature at surface (K)
+    REAL, DIMENSION(klon, nbsrf), INTENT(INOUT)     :: delta_tsurf !surface temperature difference between
+                                                                   !wake and off-wake regions
     REAL, DIMENSION(klon, nbsrf), INTENT(INOUT)     :: alb1    ! albedo in visible SW interval
     REAL, DIMENSION(klon, nbsrf), INTENT(INOUT)     :: alb2    ! albedo in near infra-red SW interval
@@ -309,4 +352,9 @@
     REAL, DIMENSION(klon, nbsrf), INTENT(INOUT)     :: v10m    ! v speed at 10m
     REAL, DIMENSION(klon, klev+1, nbsrf+1), INTENT(INOUT) :: tke 
+
+!!! nrlmd+jyg le 02/05/2011 et le 20/02/2012
+    REAL, DIMENSION(klon, klev+1, nbsrf), INTENT(INOUT) :: wake_dltke ! TKE_w - TKE_x
+!!!
+
 ! Output variables
 !****************************************************************************************
@@ -325,4 +373,10 @@
     REAL, DIMENSION(klon),        INTENT(OUT)       :: zxevap     ! water vapour flux at surface, positiv upwards
     REAL, DIMENSION(klon),        INTENT(OUT)       :: zxtsol     ! temperature at surface, mean for each grid point
+!!! jyg le ???
+    REAL, DIMENSION(klon,klev),   INTENT(OUT)       :: d_t_w      !   !
+    REAL, DIMENSION(klon,klev),   INTENT(OUT)       :: d_q_w      !      !  Tendances dans les poches
+    REAL, DIMENSION(klon,klev),   INTENT(OUT)       :: d_t_x      !   !
+    REAL, DIMENSION(klon,klev),   INTENT(OUT)       :: d_q_x      !      !  Tendances hors des poches
+!!! jyg
     REAL, DIMENSION(klon),        INTENT(OUT)       :: zxfluxlat  ! latent flux, mean for each grid point
     REAL, DIMENSION(klon),        INTENT(OUT)       :: zt2m       ! temperature at 2m, mean for each grid point
@@ -340,10 +394,34 @@
     ! coef for turbulent diffusion of U and V (?), mean for each grid point
 
+!!! nrlmd+jyg le 02/05/2011 et le 20/02/2012
+    REAL, DIMENSION(klon),        INTENT(OUT)       :: zxsens_x   ! Flux sensible hors poche
+    REAL, DIMENSION(klon),        INTENT(OUT)       :: zxsens_w   ! Flux sensible dans la poche
+    REAL, DIMENSION(klon),        INTENT(OUT)       :: zxfluxlat_x! Flux latent hors poche
+    REAL, DIMENSION(klon),        INTENT(OUT)       :: zxfluxlat_w! Flux latent dans la poche
+!!    REAL, DIMENSION(klon,klev),   INTENT(OUT)       :: d_wake_dlt
+!!    REAL, DIMENSION(klon,klev),   INTENT(OUT)       :: d_wake_dlq
+
 ! Output only for diagnostics
+    REAL, DIMENSION(klon),        INTENT(OUT)       :: cdragh_x
+    REAL, DIMENSION(klon),        INTENT(OUT)       :: cdragh_w
+    REAL, DIMENSION(klon),        INTENT(OUT)       :: cdragm_x
+    REAL, DIMENSION(klon),        INTENT(OUT)       :: cdragm_w
+    REAL, DIMENSION(klon),        INTENT(OUT)       :: kh
+    REAL, DIMENSION(klon),        INTENT(OUT)       :: kh_x
+    REAL, DIMENSION(klon),        INTENT(OUT)       :: kh_w
+!!! 
     REAL, DIMENSION(klon),        INTENT(OUT)       :: slab_wfbils! heat balance at surface only for slab at ocean points
     REAL, DIMENSION(klon),        INTENT(OUT)       :: qsol_d     ! water height in the soil (mm)
     REAL, DIMENSION(klon),        INTENT(OUT)       :: zq2m       ! water vapour at 2m, mean for each grid point
     REAL, DIMENSION(klon),        INTENT(OUT)       :: s_pblh     ! height of the planetary boundary layer(HPBL)
+!!! jyg le 08/02/2012
+    REAL, DIMENSION(klon),        INTENT(OUT)       :: s_pblh_x   ! height of the PBL in the off-wake region
+    REAL, DIMENSION(klon),        INTENT(OUT)       :: s_pblh_w   ! height of the PBL in the wake region
+!!!
     REAL, DIMENSION(klon),        INTENT(OUT)       :: s_plcl     ! condensation level
+!!! jyg le 08/02/2012
+    REAL, DIMENSION(klon),        INTENT(OUT)       :: s_plcl_x   ! condensation level in the off-wake region
+    REAL, DIMENSION(klon),        INTENT(OUT)       :: s_plcl_w   ! condensation level in the wake region
+!!!
     REAL, DIMENSION(klon),        INTENT(OUT)       :: s_capCL    ! CAPE of PBL
     REAL, DIMENSION(klon),        INTENT(OUT)       :: s_oliqCL   ! liquid water intergral of PBL
@@ -409,8 +487,10 @@
 ! Other local variables
 !****************************************************************************************
+    INTEGER                            :: iflag_split 
     INTEGER                            :: i, k, nsrf 
     INTEGER                            :: knon, j
     INTEGER                            :: idayref
     INTEGER , DIMENSION(klon)          :: ni
+    REAL                               :: yt1_new
     REAL                               :: zx_alf1, zx_alf2 !valeur ambiante par extrapola
     REAL                               :: amn, amx
@@ -419,5 +499,5 @@
     REAL, DIMENSION(klon)              :: yts, yrugos, ypct, yz0_new
     REAL, DIMENSION(klon)              :: yalb, yalb1, yalb2
-    REAL, DIMENSION(klon)              :: yu1, yv1,ytoto
+    REAL, DIMENSION(klon)              :: yu1, yv1
     REAL, DIMENSION(klon)              :: ysnow, yqsurf, yagesno, yqsol
     REAL, DIMENSION(klon)              :: yrain_f, ysnow_f
@@ -474,6 +554,192 @@
     LOGICAL, PARAMETER                 :: zxli=.FALSE. ! utiliser un jeu de fonctions simples
     LOGICAL, PARAMETER                 :: check=.FALSE.
-    REAL, DIMENSION(klon)              :: Kech_h       ! Coefficient d'echange pour l'energie
+
+!!! nrlmd le 02/05/2011
+!!! jyg le 07/02/2012
+    REAL, DIMENSION(klon)              :: ywake_s, ywake_cstar, ywake_dens
+!!!
+    REAL, DIMENSION(klon,klev+1)       :: ytke_x, ytke_w
+    REAL, DIMENSION(klon,klev+1)       :: ywake_dltke
+    REAL, DIMENSION(klon,klev)         :: yu_x, yv_x, yu_w, yv_w
+    REAL, DIMENSION(klon,klev)         :: yt_x, yq_x, yt_w, yq_w
+    REAL, DIMENSION(klon,klev)         :: ycoefh_x, ycoefm_x, ycoefh_w, ycoefm_w
+    REAL, DIMENSION(klon,klev)         :: ycoefq_x, ycoefq_w
+    REAL, DIMENSION(klon)              :: ycdragh_x, ycdragm_x, ycdragh_w, ycdragm_w
+    REAL, DIMENSION(klon)              :: AcoefH_x, AcoefQ_x, BcoefH_x, BcoefQ_x
+    REAL, DIMENSION(klon)              :: AcoefH_w, AcoefQ_w, BcoefH_w, BcoefQ_w
+    REAL, DIMENSION(klon)              :: AcoefU_x, AcoefV_x, BcoefU_x, BcoefV_x
+    REAL, DIMENSION(klon)              :: AcoefU_w, AcoefV_w, BcoefU_w, BcoefV_w
+    REAL, DIMENSION(klon)              :: y_flux_t1_x, y_flux_q1_x, y_flux_t1_w, y_flux_q1_w
+    REAL, DIMENSION(klon)              :: y_flux_u1_x, y_flux_v1_x, y_flux_u1_w, y_flux_v1_w
+    REAL, DIMENSION(klon,klev)         :: y_flux_t_x, y_flux_q_x, y_flux_t_w, y_flux_q_w
+    REAL, DIMENSION(klon,klev)         :: y_flux_u_x, y_flux_v_x, y_flux_u_w, y_flux_v_w
+    REAL, DIMENSION(klon)              :: yfluxlat_x, yfluxlat_w
+    REAL, DIMENSION(klon,klev)         :: y_d_t_x, y_d_q_x, y_d_t_w, y_d_q_w
+    REAL, DIMENSION(klon,klev)         :: y_d_t_diss_x, y_d_t_diss_w
+    REAL, DIMENSION(klon,klev)         :: d_t_diss_x, d_t_diss_w
+    REAL, DIMENSION(klon,klev)         :: y_d_u_x, y_d_v_x, y_d_u_w, y_d_v_w
+    REAL, DIMENSION(klon, klev, nbsrf) :: flux_t_x, flux_q_x, flux_t_w, flux_q_w
+    REAL, DIMENSION(klon, klev, nbsrf) :: flux_u_x, flux_v_x, flux_u_w, flux_v_w
+    REAL, DIMENSION(klon, nbsrf)       :: fluxlat_x, fluxlat_w
+    REAL, DIMENSION(klon, klev)        :: zxfluxt_x, zxfluxq_x, zxfluxt_w, zxfluxq_w
+    REAL, DIMENSION(klon, klev)        :: zxfluxu_x, zxfluxv_x, zxfluxu_w, zxfluxv_w
+    REAL                               :: zx_qs_surf, zcor_surf, zdelta_surf
+    REAL, DIMENSION(klon)              :: ytsurf_th, yqsatsurf
+    REAL, DIMENSION(klon)              :: ybeta
+    REAL, DIMENSION(klon, klev)        :: d_u_x
+    REAL, DIMENSION(klon, klev)        :: d_u_w
+    REAL, DIMENSION(klon, klev)        :: d_v_x
+    REAL, DIMENSION(klon, klev)        :: d_v_w 
+
+    REAL, DIMENSION(klon,klev)         :: CcoefH, CcoefQ, DcoefH, DcoefQ
+    REAL, DIMENSION(klon,klev)         :: CcoefU, CcoefV, DcoefU, DcoefV
+    REAL, DIMENSION(klon,klev)         :: CcoefH_x, CcoefQ_x, DcoefH_x, DcoefQ_x
+    REAL, DIMENSION(klon,klev)         :: CcoefH_w, CcoefQ_w, DcoefH_w, DcoefQ_w
+    REAL, DIMENSION(klon,klev)         :: CcoefU_x, CcoefV_x, DcoefU_x, DcoefV_x
+    REAL, DIMENSION(klon,klev)         :: CcoefU_w, CcoefV_w, DcoefU_w, DcoefV_w
+    REAL, DIMENSION(klon,klev)         :: Kcoef_hq, Kcoef_m, gama_h, gama_q
+    REAL, DIMENSION(klon,klev)         :: Kcoef_hq_x, Kcoef_m_x, gama_h_x, gama_q_x
+    REAL, DIMENSION(klon,klev)         :: Kcoef_hq_w, Kcoef_m_w, gama_h_w, gama_q_w
+    REAL, DIMENSION(klon)              :: alf_1, alf_2, alf_1_x, alf_2_x, alf_1_w, alf_2_w
+!!!
+!!!jyg le 08/02/2012
+    REAL, DIMENSION(klon, nbsrf)       :: t2m_x
+    REAL, DIMENSION(klon, nbsrf)       :: q2m_x
+    REAL, DIMENSION(klon)              :: rh2m_x
+    REAL, DIMENSION(klon)              :: qsat2m_x
+    REAL, DIMENSION(klon, nbsrf)       :: u10m_x
+    REAL, DIMENSION(klon, nbsrf)       :: v10m_x
+    REAL, DIMENSION(klon, nbsrf)       :: ustar_x
+    REAL, DIMENSION(klon, nbsrf)       :: wstar_x
+!              
+    REAL, DIMENSION(klon, nbsrf)       :: pblh_x
+    REAL, DIMENSION(klon, nbsrf)       :: plcl_x
+    REAL, DIMENSION(klon, nbsrf)       :: capCL_x
+    REAL, DIMENSION(klon, nbsrf)       :: oliqCL_x
+    REAL, DIMENSION(klon, nbsrf)       :: cteiCL_x
+    REAL, DIMENSION(klon, nbsrf)       :: pblt_x
+    REAL, DIMENSION(klon, nbsrf)       :: therm_x
+    REAL, DIMENSION(klon, nbsrf)       :: trmb1_x
+    REAL, DIMENSION(klon, nbsrf)       :: trmb2_x
+    REAL, DIMENSION(klon, nbsrf)       :: trmb3_x
+!
+    REAL, DIMENSION(klon, nbsrf)       :: t2m_w
+    REAL, DIMENSION(klon, nbsrf)       :: q2m_w
+    REAL, DIMENSION(klon)              :: rh2m_w
+    REAL, DIMENSION(klon)              :: qsat2m_w
+    REAL, DIMENSION(klon, nbsrf)       :: u10m_w
+    REAL, DIMENSION(klon, nbsrf)       :: v10m_w
+    REAL, DIMENSION(klon, nbsrf)       :: ustar_w
+    REAL, DIMENSION(klon, nbsrf)       :: wstar_w
+!                           
+    REAL, DIMENSION(klon, nbsrf)       :: pblh_w
+    REAL, DIMENSION(klon, nbsrf)       :: plcl_w
+    REAL, DIMENSION(klon, nbsrf)       :: capCL_w
+    REAL, DIMENSION(klon, nbsrf)       :: oliqCL_w
+    REAL, DIMENSION(klon, nbsrf)       :: cteiCL_w
+    REAL, DIMENSION(klon, nbsrf)       :: pblt_w
+    REAL, DIMENSION(klon, nbsrf)       :: therm_w
+    REAL, DIMENSION(klon, nbsrf)       :: trmb1_w
+    REAL, DIMENSION(klon, nbsrf)       :: trmb2_w
+    REAL, DIMENSION(klon, nbsrf)       :: trmb3_w
+!
+    REAL, DIMENSION(klon)       :: yt2m_x
+    REAL, DIMENSION(klon)       :: yq2m_x
+    REAL, DIMENSION(klon)       :: yt10m_x
+    REAL, DIMENSION(klon)       :: yq10m_x
+    REAL, DIMENSION(klon)       :: yu10m_x
+    REAL, DIMENSION(klon)       :: yv10m_x
+    REAL, DIMENSION(klon)       :: yustar_x
+    REAL, DIMENSION(klon)       :: ywstar_x
+!              
+    REAL, DIMENSION(klon)       :: ypblh_x
+    REAL, DIMENSION(klon)       :: ylcl_x
+    REAL, DIMENSION(klon)       :: ycapCL_x
+    REAL, DIMENSION(klon)       :: yoliqCL_x
+    REAL, DIMENSION(klon)       :: ycteiCL_x
+    REAL, DIMENSION(klon)       :: ypblt_x
+    REAL, DIMENSION(klon)       :: ytherm_x
+    REAL, DIMENSION(klon)       :: ytrmb1_x
+    REAL, DIMENSION(klon)       :: ytrmb2_x
+    REAL, DIMENSION(klon)       :: ytrmb3_x
+!
+    REAL, DIMENSION(klon)       :: yt2m_w
+    REAL, DIMENSION(klon)       :: yq2m_w
+    REAL, DIMENSION(klon)       :: yt10m_w
+    REAL, DIMENSION(klon)       :: yq10m_w
+    REAL, DIMENSION(klon)       :: yu10m_w
+    REAL, DIMENSION(klon)       :: yv10m_w
+    REAL, DIMENSION(klon)       :: yustar_w
+    REAL, DIMENSION(klon)       :: ywstar_w
+!                       
+    REAL, DIMENSION(klon)       :: ypblh_w
+    REAL, DIMENSION(klon)       :: ylcl_w
+    REAL, DIMENSION(klon)       :: ycapCL_w
+    REAL, DIMENSION(klon)       :: yoliqCL_w
+    REAL, DIMENSION(klon)       :: ycteiCL_w
+    REAL, DIMENSION(klon)       :: ypblt_w
+    REAL, DIMENSION(klon)       :: ytherm_w
+    REAL, DIMENSION(klon)       :: ytrmb1_w
+    REAL, DIMENSION(klon)       :: ytrmb2_w
+    REAL, DIMENSION(klon)       :: ytrmb3_w
+!
+    REAL, DIMENSION(klon)              :: uzon_x, vmer_x
+    REAL, DIMENSION(klon)              :: zgeo1_x, tair1_x, qair1_x, tairsol_x
+!
+    REAL, DIMENSION(klon)              :: uzon_w, vmer_w
+    REAL, DIMENSION(klon)              :: zgeo1_w, tair1_w, qair1_w, tairsol_w
+
+!!! jyg le 25/03/2013
+!!    Variables intermediaires pour le raccord des deux colonnes à la surface
+    REAL   ::   dd_Ch
+    REAL   ::   dd_Cm
+    REAL   ::   dd_Kh
+    REAL   ::   dd_Km
+    REAL   ::   dd_u 
+    REAL   ::   dd_v 
+    REAL   ::   dd_t 
+    REAL   ::   dd_q 
+    REAL   ::   dd_AH
+    REAL   ::   dd_AQ
+    REAL   ::   dd_AU
+    REAL   ::   dd_AV
+    REAL   ::   dd_BH
+    REAL   ::   dd_BQ
+    REAL   ::   dd_BU
+    REAL   ::   dd_BV
+
+    REAL   ::   dd_KHp
+    REAL   ::   dd_KQp
+    REAL   ::   dd_KUp
+    REAL   ::   dd_KVp
+
+!!!
+!!! nrlmd le 13/06/2011
+    REAL, DIMENSION(klon)              :: y_delta_flux_t1, y_delta_flux_q1, y_delta_flux_u1, y_delta_flux_v1
+    REAL, DIMENSION(klon)              :: y_delta_tsurf,delta_coef,tau_eq
+    REAL, PARAMETER                    :: facteur=2./sqrt(3.14)
+    REAL, PARAMETER                    :: effusivity=2000.
+    REAL, DIMENSION(klon)              :: ytsurf_th_x,ytsurf_th_w,yqsatsurf_x,yqsatsurf_w
+    REAL, DIMENSION(klon)              :: ydtsurf_th
+    REAL                               :: zdelta_surf_x,zdelta_surf_w,zx_qs_surf_x,zx_qs_surf_w
+    REAL                               :: zcor_surf_x,zcor_surf_w
+    REAL                               :: mod_wind_x, mod_wind_w
+    REAL                               :: rho1
+    REAL, DIMENSION(klon)              :: Kech_h           ! Coefficient d'echange pour l'energie
+    REAL, DIMENSION(klon)              :: Kech_h_x, Kech_h_w 
+    REAL, DIMENSION(klon)              :: Kech_m
+    REAL, DIMENSION(klon)              :: Kech_m_x, Kech_m_w 
+    REAL, DIMENSION(klon)              :: yts_x,yts_w
+    REAL, DIMENSION(klon)              :: Kech_Hp, Kech_H_xp, Kech_H_wp
+    REAL, DIMENSION(klon)              :: Kech_Qp, Kech_Q_xp, Kech_Q_wp
+    REAL, DIMENSION(klon)              :: Kech_Up, Kech_U_xp, Kech_U_wp
+    REAL, DIMENSION(klon)              :: Kech_Vp, Kech_V_xp, Kech_V_wp
+
     REAL                               :: vent
+
+
+
+
+!!!
 
 ! For debugging with IOIPSL
@@ -514,8 +780,10 @@
 
 !****************************************************************************************
-
 ! End of declarations
 !****************************************************************************************
 
+      IF (prt_level >=10) print *,' -> pbl_surface, itap ',itap
+!
+      iflag_split = mod(iflag_pbl_split,2)
 
 !****************************************************************************************
@@ -594,5 +862,26 @@
     ypphi = 0.0   ; ycldt = 0.0      ; yrmu0 = 0.0
     ! Martin
-    
+
+!!! nrlmd+jyg le 02/05/2011 et le 20/02/2012
+    ytke_x=0.     ; ytke_w=0.        ; ywake_dltke=0.
+    y_d_t_x=0.    ; y_d_t_w=0.       ; y_d_q_x=0.      ; y_d_q_w=0.
+    d_t_w=0.      ; d_q_w=0.         
+    d_t_x=0.      ; d_q_x=0.
+    d_t_diss_x = 0. ; d_t_diss_w = 0.
+!!    d_wake_dlt=0.    ; d_wake_dlq=0.
+    d_u_x=0.      ; d_u_w=0.         ; d_v_x=0.        ; d_v_w=0.
+    flux_t_x=0.   ; flux_t_w=0.      ; flux_q_x=0.     ; flux_q_w=0.
+    yfluxlat_x=0. ; yfluxlat_w=0.
+    ywake_s=0.    ; ywake_cstar=0.   ;ywake_dens=0.
+!!!
+!!! nrlmd le 13/06/2011
+    tau_eq=0.     ; delta_coef=0.
+    y_delta_flux_t1=0.
+    ydtsurf_th=0.
+    yts_x=0.      ; yts_w=0.
+    y_delta_tsurf=0.
+    cdragh_x=0.   ; cdragh_w=0.      ; cdragm_x=0.     ;cdragm_w=0.
+    kh=0.         ; kh_x=0.          ; kh_w=0.
+!!!
     tke(:,:,is_ave)=0.
     IF (iflag_pbl<20.or.iflag_pbl>=30) THEN
@@ -607,6 +896,27 @@
     ytsoil = 999999. 
 
+!!! jyg le 23/02/2013
+    pblh(:,:)      = 999999.     ! pblh,plcl,cteiCL are meaningfull only over sub-surfaces
+    plcl(:,:)      = 999999.     ! actually present in the grid cell.
+    cteiCL(:,:)    = 999999.
+    pblh_x(:,:)      = 999999.  
+    plcl_x(:,:)      = 999999.  
+    cteiCL_x(:,:)    = 999999.  
+    pblh_w(:,:)      = 999999.   
+    plcl_w(:,:)      = 999999.   
+    cteiCL_w(:,:)    = 999999.   
+!
+    t2m(:,:)       = 999999.     ! t2m and q2m are meaningfull only over sub-surfaces
+    q2m(:,:)       = 999999.     ! actually present in the grid cell.
+!!!
     rh2m(:)        = 0.
     qsat2m(:)      = 0.
+!!!
+!!! jyg le 10/02/2012
+    rh2m_x(:)        = 0.
+    qsat2m_x(:)      = 0.
+    rh2m_w(:)        = 0.
+    qsat2m_w(:)      = 0.
+!!!
 !****************************************************************************************
 ! 3) - Calculate pressure thickness of each layer
@@ -699,9 +1009,10 @@
 ! 4) Loop over different surfaces
 !
-! Only points containing a fraction of the sub surface will be threated.
+! Only points containing a fraction of the sub surface will be treated.
 ! 
 !****************************************************************************************
    
     loop_nbsrf: DO nsrf = 1, nbsrf
+       IF (prt_level >=10) print *,' Loop nsrf ',nsrf
 
 ! Search for index(ni) and size(knon) of domaine to treat
@@ -714,4 +1025,11 @@
           ENDIF
        ENDDO
+
+!!! jyg le 19/08/2012
+       IF (knon <= 0) THEN
+         IF (prt_level >= 10) print *,' no grid point for nsrf= ',nsrf
+         cycle loop_nbsrf
+       ENDIF
+!!!
 
        ! write index, with IOIPSL
@@ -758,4 +1076,7 @@
           yrmu0(j)   = rmu0(i)
           ! Martin
+!!! nrlmd le 13/06/2011
+          y_delta_tsurf(j)=delta_tsurf(i,nsrf)
+!!!
        END DO
 
@@ -766,4 +1087,10 @@
              ypplay(j,k) = pplay(i,k)
              ydelp(j,k)  = delp(i,k)
+          ENDDO
+       ENDDO
+!!! jyg le 07/02/2012 et le 10/04/2013
+        DO k = 1, klev
+          DO j = 1, knon
+             i = ni(j)
              ytke(j,k)   = tke(i,k,nsrf)
              yu(j,k) = u(i,k)
@@ -772,6 +1099,49 @@
              yq(j,k) = q(i,k)
           ENDDO
-       ENDDO
-
+        ENDDO
+!
+       IF (iflag_split .eq.1) THEN
+!!! nrlmd le 02/05/2011
+        DO k = 1, klev
+          DO j = 1, knon
+             i = ni(j)
+             yu_x(j,k) = u(i,k)
+             yv_x(j,k) = v(i,k)
+             yt_x(j,k) = t(i,k)-wake_s(i)*wake_dlt(i,k)
+             yq_x(j,k) = q(i,k)-wake_s(i)*wake_dlq(i,k)
+             yu_w(j,k) = u(i,k)
+             yv_w(j,k) = v(i,k)
+             yt_w(j,k) = t(i,k)+(1.-wake_s(i))*wake_dlt(i,k)
+             yq_w(j,k) = q(i,k)+(1.-wake_s(i))*wake_dlq(i,k)
+!!!
+          ENDDO
+        ENDDO
+!!! nrlmd le 02/05/2011
+        DO k = 1, klev+1
+          DO j = 1, knon
+             i = ni(j)
+             ytke_x(j,k) = tke(i,k,nsrf)-wake_s(i)*wake_dltke(i,k,nsrf)
+             ytke_w(j,k) = tke(i,k,nsrf)+(1.-wake_s(i))*wake_dltke(i,k,nsrf)
+             ywake_dltke(j,k) = wake_dltke(i,k,nsrf)
+             ytke(j,k)     = tke(i,k,nsrf)
+          ENDDO
+        ENDDO
+!!!
+!!! jyg le 07/02/2012
+        DO j = 1, knon
+          i = ni(j)
+          ywake_s(j)=wake_s(i)
+          ywake_cstar(j)=wake_cstar(i)
+          ywake_dens(j)=wake_dens(i)
+        ENDDO
+!!!
+!!! nrlmd le 13/06/2011
+        DO j=1,knon
+         yts_x(j)=yts(j)-ywake_s(j)*y_delta_tsurf(j)
+         yts_w(j)=yts(j)+(1.-ywake_s(j))*y_delta_tsurf(j)
+        ENDDO
+!!!
+       ENDIF  ! (iflag_split .eq.1)
+!!!
        DO k = 1, nsoilmx
           DO j = 1, knon
@@ -794,5 +1164,9 @@
 !****************************************************************************************
 
-       CALL clcdrag( knon, nsrf, ypaprs, ypplay, &
+!!! jyg le 07/02/2012
+       IF (iflag_split .eq.0) THEN
+!!!
+!!! nrlmd & jyg les 02/05/2011, 13/06/2011, 05/02/2012
+        CALL clcdrag( knon, nsrf, ypaprs, ypplay, &
             yu(:,1), yv(:,1), yt(:,1), yq(:,1), &
             yts, yqsurf, yrugos, &
@@ -810,15 +1184,64 @@
       ENDDO
      ENDIF
-
-
-!****************************************************************************************
-! 6b) Calculate coefficients for turbulent diffusion in the atmosphere, ycoefm et ycoefm.
-!
-!****************************************************************************************
-
-       CALL coef_diff_turb(dtime, nsrf, knon, ni,  &
+        IF (prt_level >=10) print *,'clcdrag -> ycdragh ', ycdragh
+       ELSE  !(iflag_split .eq.0)
+        CALL clcdrag( knon, nsrf, ypaprs, ypplay, &
+            yu_x(:,1), yv_x(:,1), yt_x(:,1), yq_x(:,1), &
+            yts_x, yqsurf, yrugos, &
+            ycdragm_x, ycdragh_x )
+! --- special Dice. JYG+MPL 25112013
+        IF (ok_prescr_ust) then
+         DO i = 1, knon
+          print *,'ycdragm_x avant=',ycdragm_x(i)
+          vent= sqrt(yu_x(i,1)*yu_x(i,1)+yv_x(i,1)*yv_x(i,1))
+          ycdragm_x(i) = ust*ust/(1.+vent)/vent
+          print *,'ycdragm_x ust yu yv apres=',ycdragm_x(i),ust,yu_x(i,1),yv_x(i,1)
+         ENDDO
+        ENDIF
+        IF (prt_level >=10) print *,'clcdrag -> ycdragh_x ', ycdragh_x
+!
+        CALL clcdrag( knon, nsrf, ypaprs, ypplay, &
+            yu_w(:,1), yv_w(:,1), yt_w(:,1), yq_w(:,1), &
+            yts_w, yqsurf, yrugos, &
+            ycdragm_w, ycdragh_w )
+! --- special Dice. JYG+MPL 25112013
+        IF (ok_prescr_ust) then
+         DO i = 1, knon
+          print *,'ycdragm_w avant=',ycdragm_w(i)
+          vent= sqrt(yu_w(i,1)*yu_w(i,1)+yv_w(i,1)*yv_w(i,1))
+          ycdragm_w(i) = ust*ust/(1.+vent)/vent
+          print *,'ycdragm_w ust yu yv apres=',ycdragm_w(i),ust,yu_w(i,1),yv_w(i,1)
+         ENDDO
+        ENDIF
+        IF (prt_level >=10) print *,'clcdrag -> ycdragh_w ', ycdragh_w
+!!!
+       ENDIF  ! (iflag_split .eq.0)
+!!!
+       
+
+!****************************************************************************************
+! 6b) Calculate coefficients for turbulent diffusion in the atmosphere, ycoefh et ycoefm.
+!
+!****************************************************************************************
+
+!!! jyg le 07/02/2012
+       IF (iflag_split .eq.0) THEN
+!!!
+!!! nrlmd & jyg les 02/05/2011, 13/06/2011, 05/02/2012
+      IF (prt_level >=10) THEN
+      print *,' args coef_diff_turb: yu ',  yu  
+      print *,' args coef_diff_turb: yv ',  yv  
+      print *,' args coef_diff_turb: yq ',  yq  
+      print *,' args coef_diff_turb: yt ',  yt  
+      print *,' args coef_diff_turb: yts ', yts  
+      print *,' args coef_diff_turb: yrugos ', yrugos  
+      print *,' args coef_diff_turb: yqsurf ', yqsurf  
+      print *,' args coef_diff_turb: ycdragm ', ycdragm
+      print *,' args coef_diff_turb: ycdragh ', ycdragh
+      print *,' args coef_diff_turb: ytke ', ytke
+       ENDIF
+        CALL coef_diff_turb(dtime, nsrf, knon, ni,  &
             ypaprs, ypplay, yu, yv, yq, yt, yts, yrugos, yqsurf, ycdragm, &
             ycoefm, ycoefh, ytke)
-
        IF (iflag_pbl>=20.AND.iflag_pbl<30) THEN
 ! In this case, coef_diff_turb is called for the Cd only
@@ -831,4 +1254,73 @@
        ENDDO
        ENDIF
+        IF (prt_level >=10) print *,'coef_diff_turb -> ycoefh ',ycoefh
+!
+       ELSE  !(iflag_split .eq.0)
+      IF (prt_level >=10) THEN
+      print *,' args coef_diff_turb: yu_x ',  yu_x  
+      print *,' args coef_diff_turb: yv_x ',  yv_x  
+      print *,' args coef_diff_turb: yq_x ',  yq_x  
+      print *,' args coef_diff_turb: yt_x ',  yt_x  
+      print *,' args coef_diff_turb: yts_x ', yts_x  
+      print *,' args coef_diff_turb: yrugos ', yrugos  
+      print *,' args coef_diff_turb: yqsurf ', yqsurf  
+      print *,' args coef_diff_turb: ycdragm_x ', ycdragm_x
+      print *,' args coef_diff_turb: ycdragh_x ', ycdragh_x
+      print *,' args coef_diff_turb: ytke_x ', ytke_x
+       ENDIF
+        CALL coef_diff_turb(dtime, nsrf, knon, ni,  &
+            ypaprs, ypplay, yu_x, yv_x, yq_x, yt_x, yts_x, yrugos, yqsurf, ycdragm_x, &
+            ycoefm_x, ycoefh_x, ytke_x)
+       IF (iflag_pbl>=20.AND.iflag_pbl<30) THEN
+! In this case, coef_diff_turb is called for the Cd only
+       DO k = 2, klev
+          DO j = 1, knon
+             i = ni(j)
+             ycoefh_x(j,k)   = zcoefh(i,k,nsrf)
+             ycoefm_x(j,k)   = zcoefm(i,k,nsrf)
+          ENDDO
+       ENDDO
+       ENDIF
+        IF (prt_level >=10) print *,'coef_diff_turb -> ycoefh_x ',ycoefh_x
+!
+      IF (prt_level >=10) THEN
+      print *,' args coef_diff_turb: yu_w ',  yu_w  
+      print *,' args coef_diff_turb: yv_w ',  yv_w  
+      print *,' args coef_diff_turb: yq_w ',  yq_w  
+      print *,' args coef_diff_turb: yt_w ',  yt_w  
+      print *,' args coef_diff_turb: yts_w ', yts_w  
+      print *,' args coef_diff_turb: yrugos ', yrugos  
+      print *,' args coef_diff_turb: yqsurf ', yqsurf  
+      print *,' args coef_diff_turb: ycdragm_w ', ycdragm_w
+      print *,' args coef_diff_turb: ycdragh_w ', ycdragh_w
+      print *,' args coef_diff_turb: ytke_w ', ytke_w
+       ENDIF
+        CALL coef_diff_turb(dtime, nsrf, knon, ni,  &
+            ypaprs, ypplay, yu_w, yv_w, yq_w, yt_w, yts_w, yrugos, yqsurf, ycdragm_w, &
+            ycoefm_w, ycoefh_w, ytke_w)
+       IF (iflag_pbl>=20.AND.iflag_pbl<30) THEN
+! In this case, coef_diff_turb is called for the Cd only
+       DO k = 2, klev
+          DO j = 1, knon
+             i = ni(j)
+             ycoefh_w(j,k)   = zcoefh(i,k,nsrf)
+             ycoefm_w(j,k)   = zcoefm(i,k,nsrf)
+          ENDDO
+       ENDDO
+       ENDIF
+        IF (prt_level >=10) print *,'coef_diff_turb -> ycoefh_w ',ycoefh_w
+!
+!!!jyg le 10/04/2013
+!!   En attendant de traiter le transport des traceurs dans les poches froides, formule
+!!   arbitraire pour ycoefh et ycoefm
+      DO k = 2,klev
+        DO j = 1,knon
+         ycoefh(j,k) = ycoefh_x(j,k) + ywake_s(j)*(ycoefh_w(j,k) - ycoefh_x(j,k))
+         ycoefm(j,k) = ycoefm_x(j,k) + ywake_s(j)*(ycoefm_w(j,k) - ycoefm_x(j,k))
+        ENDDO
+      ENDDO
+!!!
+       ENDIF  ! (iflag_split .eq.0)
+!!!
        
 !****************************************************************************************
@@ -843,12 +1335,62 @@
 
 ! - Calculate the coefficients Ccoef_H, Ccoef_Q, Dcoef_H and Dcoef_Q 
-       CALL climb_hq_down(knon, ycoefh, ypaprs, ypplay, &
+!!! jyg le 07/02/2012
+       IF (iflag_split .eq.0) THEN
+!!!
+!!! nrlmd & jyg les 02/05/2011, 13/06/2011, 05/02/2012
+        CALL climb_hq_down(knon, ycoefh, ypaprs, ypplay, &
             ydelp, yt, yq, dtime, &
+!!! jyg le 09/05/2011
+            CcoefH, CcoefQ, DcoefH, DcoefQ, &
+            Kcoef_hq, gama_q, gama_h, &
+!!!
             AcoefH, AcoefQ, BcoefH, BcoefQ)
+       ELSE  !(iflag_split .eq.0)
+        CALL climb_hq_down(knon, ycoefh_x, ypaprs, ypplay, &
+            ydelp, yt_x, yq_x, dtime, &
+!!! nrlmd le 02/05/2011
+            CcoefH_x, CcoefQ_x, DcoefH_x, DcoefQ_x, &
+            Kcoef_hq_x, gama_q_x, gama_h_x, &
+!!!
+            AcoefH_x, AcoefQ_x, BcoefH_x, BcoefQ_x)
+!
+        CALL climb_hq_down(knon, ycoefh_w, ypaprs, ypplay, &
+            ydelp, yt_w, yq_w, dtime, &
+!!! nrlmd le 02/05/2011
+            CcoefH_w, CcoefQ_w, DcoefH_w, DcoefQ_w, &
+            Kcoef_hq_w, gama_q_w, gama_h_w, &
+!!!
+            AcoefH_w, AcoefQ_w, BcoefH_w, BcoefQ_w)
+!!!
+       ENDIF  ! (iflag_split .eq.0)
+!!!
 
 ! - Calculate the coefficients Ccoef_U, Ccoef_V, Dcoef_U and Dcoef_V
-       CALL climb_wind_down(knon, dtime, ycoefm, ypplay, ypaprs, yt, ydelp, yu, yv, &
+!!! jyg le 07/02/2012
+       IF (iflag_split .eq.0) THEN
+!!! nrlmd & jyg les 02/05/2011, 13/06/2011, 05/02/2012
+        CALL climb_wind_down(knon, dtime, ycoefm, ypplay, ypaprs, yt, ydelp, yu, yv, &
+!!! jyg le 09/05/2011
+            CcoefU, CcoefV, DcoefU, DcoefV, &
+            Kcoef_m, alf_1, alf_2, &
+!!!
             AcoefU, AcoefV, BcoefU, BcoefV)
-      
+       ELSE  ! (iflag_split .eq.0)
+        CALL climb_wind_down(knon, dtime, ycoefm_x, ypplay, ypaprs, yt_x, ydelp, yu_x, yv_x, &
+!!! nrlmd le 02/05/2011
+            CcoefU_x, CcoefV_x, DcoefU_x, DcoefV_x, &
+            Kcoef_m_x, alf_1_x, alf_2_x, &
+!!!
+            AcoefU_x, AcoefV_x, BcoefU_x, BcoefV_x)
+!
+        CALL climb_wind_down(knon, dtime, ycoefm_w, ypplay, ypaprs, yt_w, ydelp, yu_w, yv_w, &
+!!! nrlmd le 02/05/2011
+            CcoefU_w, CcoefV_w, DcoefU_w, DcoefV_w, &
+            Kcoef_m_w, alf_1_w, alf_2_w, &
+!!!
+            AcoefU_w, AcoefV_w, BcoefU_w, BcoefV_w)
+!!!      
+       ENDIF  ! (iflag_split .eq.0)
+!!!
 
 !****************************************************************************************
@@ -870,4 +1412,134 @@
        END IF
 
+!!! nrlmd le 13/06/2011
+!----- On finit le calcul des coefficients d'échange:on multiplie le cdrag par le module du vent et la densité dans la première couche 
+!          Kech_h_x(j) = ycdragh_x(j) * &
+!             (1.0+SQRT(yu_x(j,1)**2+yv_x(j,1)**2)) * &
+!             ypplay(j,1)/(RD*yt_x(j,1))
+!          Kech_h_w(j) = ycdragh_w(j) * &
+!             (1.0+SQRT(yu_w(j,1)**2+yv_w(j,1)**2)) * &
+!             ypplay(j,1)/(RD*yt_w(j,1))
+!          Kech_h(j) = (1.-ywake_s(j))*Kech_h_x(j)+ywake_s(j)*Kech_h_w(j)
+! 
+!          Kech_m_x(j) = ycdragm_x(j) * &
+!             (1.0+SQRT(yu_x(j,1)**2+yv_x(j,1)**2)) * &
+!             ypplay(j,1)/(RD*yt_x(j,1))
+!          Kech_m_w(j) = ycdragm_w(j) * &
+!             (1.0+SQRT(yu_w(j,1)**2+yv_w(j,1)**2)) * &
+!             ypplay(j,1)/(RD*yt_w(j,1))
+!          Kech_m(j) = (1.-ywake_s(j))*Kech_m_x(j)+ywake_s(j)*Kech_m_w(j)
+!!!
+
+!!! nrlmd le 02/05/2011  -----------------------On raccorde les 2 colonnes dans la couche 1 
+!----------------------------------------------------------------------------------------
+!!! jyg le 07/02/2012
+       IF (iflag_split .eq.1) THEN
+!!!
+!!! jyg le 09/04/2013 ; passage aux nouvelles expressions en differences
+
+        DO j=1,knon
+!
+! Calcul des coefficients d echange
+         mod_wind_x = 1.0+SQRT(yu_x(j,1)**2+yv_x(j,1)**2)
+         mod_wind_w = 1.0+SQRT(yu_w(j,1)**2+yv_w(j,1)**2)
+         rho1 = ypplay(j,1)/(RD*yt(j,1))
+         Kech_h_x(j) = ycdragh_x(j) * mod_wind_x * rho1
+         Kech_h_w(j) = ycdragh_w(j) * mod_wind_w * rho1
+         Kech_m_x(j) = ycdragm_x(j) * mod_wind_x * rho1
+         Kech_m_w(j) = ycdragm_w(j) * mod_wind_w * rho1
+!
+         dd_Kh = Kech_h_w(j) - Kech_h_x(j)
+         dd_Km = Kech_m_w(j) - Kech_m_x(j)
+         IF (prt_level >=10) THEN
+          print *,' mod_wind_x, mod_wind_w ', mod_wind_x, mod_wind_w
+          print *,' rho1 ',rho1
+          print *,' ycdragh_x(j),ycdragm_x(j) ',ycdragh_x(j),ycdragm_x(j)
+          print *,' ycdragh_w(j),ycdragm_w(j) ',ycdragh_w(j),ycdragm_w(j)
+          print *,' dd_Kh: ',dd_KH
+         ENDIF
+!
+         Kech_h(j) = Kech_h_x(j) + ywake_s(j)*dd_Kh
+         Kech_m(j) = Kech_m_x(j) + ywake_s(j)*dd_Km
+!
+! Calcul des coefficients d echange corriges des retroactions
+        Kech_H_xp(j) = Kech_h_x(j)/(1.-BcoefH_x(j)*Kech_h_x(j)*dtime)
+        Kech_H_wp(j) = Kech_h_w(j)/(1.-BcoefH_w(j)*Kech_h_w(j)*dtime)
+        Kech_Q_xp(j) = Kech_h_x(j)/(1.-BcoefQ_x(j)*Kech_h_x(j)*dtime)
+        Kech_Q_wp(j) = Kech_h_w(j)/(1.-BcoefQ_w(j)*Kech_h_w(j)*dtime)
+        Kech_U_xp(j) = Kech_m_x(j)/(1.-BcoefU_x(j)*Kech_m_x(j)*dtime)
+        Kech_U_wp(j) = Kech_m_w(j)/(1.-BcoefU_w(j)*Kech_m_w(j)*dtime)
+        Kech_V_xp(j) = Kech_m_x(j)/(1.-BcoefV_x(j)*Kech_m_x(j)*dtime)
+        Kech_V_wp(j) = Kech_m_w(j)/(1.-BcoefV_w(j)*Kech_m_w(j)*dtime)
+!
+         dd_KHp = Kech_H_wp(j) - Kech_H_xp(j)
+         dd_KQp = Kech_Q_wp(j) - Kech_Q_xp(j)
+         dd_KUp = Kech_U_wp(j) - Kech_U_xp(j)
+         dd_KVp = Kech_V_wp(j) - Kech_V_xp(j)
+!
+        Kech_Hp(j) = Kech_H_xp(j) + ywake_s(j)*dd_KHp
+        Kech_Qp(j) = Kech_Q_xp(j) + ywake_s(j)*dd_KQp
+        Kech_Up(j) = Kech_U_xp(j) + ywake_s(j)*dd_KUp
+        Kech_Vp(j) = Kech_V_xp(j) + ywake_s(j)*dd_KVp
+!
+! Calcul des differences w-x
+       dd_CM = ycdragm_w(j) - ycdragm_x(j)
+       dd_CH = ycdragh_w(j) - ycdragh_x(j)
+       dd_u = yu_w(j,1) - yu_x(j,1)
+       dd_v = yv_w(j,1) - yv_x(j,1)
+       dd_t = yt_w(j,1) - yt_x(j,1)
+       dd_q = yq_w(j,1) - yq_x(j,1)
+       dd_AH = AcoefH_w(j) - AcoefH_x(j)
+       dd_AQ = AcoefQ_w(j) - AcoefQ_x(j)
+       dd_AU = AcoefU_w(j) - AcoefU_x(j)
+       dd_AV = AcoefV_w(j) - AcoefV_x(j)
+       dd_BH = BcoefH_w(j) - BcoefH_x(j)
+       dd_BQ = BcoefQ_w(j) - BcoefQ_x(j)
+       dd_BU = BcoefU_w(j) - BcoefU_x(j)
+       dd_BV = BcoefV_w(j) - BcoefV_x(j)
+!
+       IF (prt_level >=10) THEN
+          print *,'Variables pour la fusion : Kech_H_xp(j)' ,Kech_H_xp(j)
+          print *,'Variables pour la fusion : Kech_H_wp(j)' ,Kech_H_wp(j)
+          print *,'Variables pour la fusion : Kech_Hp(j)' ,Kech_Hp(j)
+          print *,'Variables pour la fusion : Kech_h(j)' ,Kech_h(j)
+       ENDIF
+!
+! Calcul des coef A, B équivalents dans la couche 1
+!
+       AcoefH(j) = AcoefH_x(j) + ywake_s(j)*(Kech_H_wp(j)/Kech_Hp(j))*dd_AH
+       AcoefQ(j) = AcoefQ_x(j) + ywake_s(j)*(Kech_Q_wp(j)/Kech_Qp(j))*dd_AQ
+       AcoefU(j) = AcoefU_x(j) + ywake_s(j)*(Kech_U_wp(j)/Kech_Up(j))*dd_AU
+       AcoefV(j) = AcoefV_x(j) + ywake_s(j)*(Kech_V_wp(j)/Kech_Vp(j))*dd_AV
+!
+       BcoefH(j) = BcoefH_x(j) + ywake_s(j)*BcoefH_x(j)*(dd_Kh/Kech_h(j))*(1.+Kech_H_wp(j)/Kech_Hp(j)) &
+                               + ywake_s(j)*(Kech_H_wp(j)/Kech_Hp(j))*(Kech_h_w(j)/Kech_h(j))*dd_BH
+
+       BcoefQ(j) = BcoefQ_x(j) + ywake_s(j)*BcoefQ_x(j)*(dd_Kh/Kech_h(j))*(1.+Kech_Q_wp(j)/Kech_Qp(j)) &
+                               + ywake_s(j)*(Kech_Q_wp(j)/Kech_Qp(j))*(Kech_h_w(j)/Kech_h(j))*dd_BQ
+
+       BcoefU(j) = BcoefU_x(j) + ywake_s(j)*BcoefU_x(j)*(dd_Km/Kech_h(j))*(1.+Kech_U_wp(j)/Kech_Up(j)) &
+                               + ywake_s(j)*(Kech_U_wp(j)/Kech_Up(j))*(Kech_m_w(j)/Kech_m(j))*dd_BU
+
+       BcoefV(j) = BcoefV_x(j) + ywake_s(j)*BcoefV_x(j)*(dd_Km/Kech_h(j))*(1.+Kech_V_wp(j)/Kech_Vp(j)) &
+                               + ywake_s(j)*(Kech_V_wp(j)/Kech_Vp(j))*(Kech_m_w(j)/Kech_m(j))*dd_BV
+
+!
+! Calcul des cdrag équivalents dans la couche 
+!
+       ycdragm(j) = ycdragm_x(j) + ywake_s(j)*dd_CM
+       ycdragh(j) = ycdragh_x(j) + ywake_s(j)*dd_CH
+!
+! Calcul de T, q, u et v équivalents dans la couche 1
+       yt(j,1) = yt_x(j,1) + ywake_s(j)*(Kech_h_w(j)/Kech_h(j))*dd_t
+       yq(j,1) = yq_x(j,1) + ywake_s(j)*(Kech_h_w(j)/Kech_h(j))*dd_q
+       yu(j,1) = yu_x(j,1) + ywake_s(j)*(Kech_m_w(j)/Kech_m(j))*dd_u
+       yv(j,1) = yv_x(j,1) + ywake_s(j)*(Kech_m_w(j)/Kech_m(j))*dd_v
+
+
+        ENDDO
+!!!
+       ENDIF  ! (iflag_split .eq.1)
+!!!
+
 !****************************************************************************************
 !
@@ -893,5 +1565,5 @@
 !****************************************************************************************
 !
-! 10) Switch selon current surface
+! 10) Switch according to current surface
 !     It is necessary to start with the continental surfaces because the ocean
 !     needs their run-off.
@@ -992,4 +1664,19 @@
                ytsurf_new, y_dflux_t, y_dflux_q, slab_wfbils, &
                y_flux_u1, y_flux_v1)
+      IF (prt_level >=10) THEN
+          print *,'arg de surf_ocean: ycdragh ',ycdragh
+          print *,'arg de surf_ocean: ycdragm ',ycdragm
+          print *,'arg de surf_ocean: yt ', yt
+          print *,'arg de surf_ocean: yq ', yq
+          print *,'arg de surf_ocean: yts ', yts
+          print *,'arg de surf_ocean: AcoefH ',AcoefH
+          print *,'arg de surf_ocean: AcoefQ ',AcoefQ
+          print *,'arg de surf_ocean: BcoefH ',BcoefH
+          print *,'arg de surf_ocean: BcoefQ ',BcoefQ
+          print *,'arg de surf_ocean: yevap ',yevap
+          print *,'arg de surf_ocean: yfluxsens ',yfluxsens
+          print *,'arg de surf_ocean: yfluxlat ',yfluxlat
+          print *,'arg de surf_ocean: ytsurf_new ',ytsurf_new
+       ENDIF
           
        CASE(is_sic)
@@ -1036,31 +1723,178 @@
 !
 !****************************************************************************************
-! H and Q
-       IF (ok_flux_surf) THEN
-          PRINT *,'pbl_surface: fsens flat RLVTT=',fsens,flat,RLVTT
+
+!!!
+!!! jyg le 10/04/2013
+!!!
+        IF (ok_flux_surf) THEN
+          IF (prt_level >=10) THEN
+           PRINT *,'pbl_surface: fsens flat RLVTT=',fsens,flat,RLVTT
+          ENDIF
           y_flux_t1(:) =  fsens
           y_flux_q1(:) =  flat/RLVTT
           yfluxlat(:) =  flat
-
-          Kech_h(:) = ycdragh(:) * (1.0+SQRT(yu(:,1)**2+yv(:,1)**2)) * &
-               ypplay(:,1)/(RD*yt(:,1))
-          ytoto(:)=(1./RCPD)*(AcoefH(:)+BcoefH(:)*y_flux_t1(:)*dtime)
-          ytsurf_new(:)=ytoto(:)-y_flux_t1(:)/(Kech_h(:)*RCPD)
+!
+          IF (iflag_split .eq.0) THEN
+             Kech_h(:) = ycdragh(:) * (1.0+SQRT(yu(:,1)**2+yv(:,1)**2)) * &
+                  ypplay(:,1)/(RD*yt(:,1))
+          ENDIF ! (iflag_split .eq.0)
+
+          DO j = 1, knon
+            yt1_new=(1./RCPD)*(AcoefH(j)+BcoefH(j)*yfluxsens(j)*dtime)
+            ytsurf_new(j)=yt1_new-yfluxsens(j)/(Kech_h(j)*RCPD)
+          ENDDO
+
           y_d_ts(:) = ytsurf_new(:) - yts(:) 
 
-       ELSE
+        ELSE ! (ok_flux_surf)
           y_flux_t1(:) =  yfluxsens(:)
           y_flux_q1(:) = -yevap(:)
+        ENDIF
+
+       IF (prt_level >=10) THEN
+        DO j=1,knon
+         print*,'y_flux_t1,yfluxlat,wakes' &
+ &             ,  y_flux_t1(j), yfluxlat(j), ywake_s(j)
+         print*,'beta,ytsurf_new', ybeta(j), ytsurf_new(j)
+         print*,'effusivity,facteur,cstar', effusivity, facteur,wake_cstar(j)
+        ENDDO
        ENDIF
 
-       CALL climb_hq_up(knon, dtime, yt, yq, &
+!!! jyg le 07/02/2012 puis le 10/04/2013
+       IF (iflag_split .eq.1) THEN
+!!!
+        DO j=1,knon
+         y_delta_flux_t1(j) = ( Kech_H_wp(j)*Kech_H_xp(j)*(AcoefH_w(j)-AcoefH_x(j)) + &
+                                y_flux_t1(j)*(Kech_H_wp(j)-Kech_H_xp(j)) ) / Kech_Hp(j)
+         y_delta_flux_q1(j) = ( Kech_Q_wp(j)*Kech_Q_xp(j)*(AcoefQ_w(j)-AcoefQ_x(j)) + &
+                                y_flux_q1(j)*(Kech_Q_wp(j)-Kech_Q_xp(j)) ) / Kech_Qp(j)
+         y_delta_flux_u1(j) = ( Kech_U_wp(j)*Kech_U_xp(j)*(AcoefU_w(j)-AcoefU_x(j)) + &
+                                y_flux_u1(j)*(Kech_U_wp(j)-Kech_U_xp(j)) ) / Kech_Up(j)
+         y_delta_flux_v1(j) = ( Kech_V_wp(j)*Kech_V_xp(j)*(AcoefV_w(j)-AcoefV_x(j)) + &
+                                y_flux_v1(j)*(Kech_V_wp(j)-Kech_V_xp(j)) ) / Kech_Vp(j)
+!
+         y_flux_t1_x(j)=y_flux_t1(j) - ywake_s(j)*y_delta_flux_t1(j)
+         y_flux_t1_w(j)=y_flux_t1(j) + (1.-ywake_s(j))*y_delta_flux_t1(j)
+         y_flux_q1_x(j)=y_flux_q1(j) - ywake_s(j)*y_delta_flux_q1(j)
+         y_flux_q1_w(j)=y_flux_q1(j) + (1.-ywake_s(j))*y_delta_flux_q1(j)
+         y_flux_u1_x(j)=y_flux_u1(j) - ywake_s(j)*y_delta_flux_u1(j)
+         y_flux_u1_w(j)=y_flux_u1(j) + (1.-ywake_s(j))*y_delta_flux_u1(j)
+         y_flux_v1_x(j)=y_flux_v1(j) - ywake_s(j)*y_delta_flux_v1(j)
+         y_flux_v1_w(j)=y_flux_v1(j) + (1.-ywake_s(j))*y_delta_flux_v1(j)
+!
+         yfluxlat_x(j)=y_flux_q1_x(j)*RLVTT
+         yfluxlat_w(j)=y_flux_q1_w(j)*RLVTT
+
+        ENDDO
+!
+ 
+!!jyg!!   A reprendre apres reflexion   ===============================================
+!!jyg!!
+!!jyg!!        DO j=1,knon
+!!jyg!!!!! nrlmd le 13/06/2011
+!!jyg!!
+!!jyg!!!----Diffusion dans le sol dans le cas continental seulement
+!!jyg!!       IF (nsrf.eq.is_ter) THEN
+!!jyg!!!----Calcul du coefficient delta_coeff
+!!jyg!!          tau_eq(j)=(ywake_s(j)/2.)*(1./max(wake_cstar(j),0.01))*sqrt(0.4/(3.14*max(wake_dens(j),8e-12)))
+!!jyg!!
+!!jyg!!!          delta_coef(j)=dtime/(effusivity*sqrt(tau_eq(j)))
+!!jyg!!          delta_coef(j)=facteur*sqrt(tau_eq(j))/effusivity
+!!jyg!!!          delta_coef(j)=0.
+!!jyg!!       ELSE 
+!!jyg!!         delta_coef(j)=0.
+!!jyg!!       ENDIF
+!!jyg!!
+!!jyg!!!----Calcul de delta_tsurf
+!!jyg!!         y_delta_tsurf(j)=delta_coef(j)*y_delta_flux_t1(j)
+!!jyg!!
+!!jyg!!!----Si il n'y a pas des poches...
+!!jyg!!         IF (wake_cstar(j).le.0.01) THEN
+!!jyg!!           y_delta_tsurf(j)=0.
+!!jyg!!           y_delta_flux_t1(j)=0.
+!!jyg!!         ENDIF
+!!jyg!!
+!!jyg!!!-----Calcul de ybeta (evap_réelle/evap_potentielle)
+!!jyg!!!!!!! jyg le 23/02/2012
+!!jyg!!!!!!!
+!!jyg!!!!        ybeta(j)=y_flux_q1(j)   /    &
+!!jyg!!!! &        (Kech_h(j)*(yq(j,1)-yqsatsurf(j)))
+!!jyg!!!!!!        ybeta(j)=-1.*yevap(j)   /    &
+!!jyg!!!!!! &        (ywake_s(j)*Kech_h_w(j)*(yq_w(j,1)-yqsatsurf_w(j))+(1.-ywake_s(j))*Kech_h_x(j)*(yq_x(j,1)-yqsatsurf_x(j)))
+!!jyg!!!!!!! fin jyg
+!!jyg!!!!!
+!!jyg!!
+!!jyg!!       ENDDO
+!!jyg!!
+!!jyg!!!!! fin nrlmd le 13/06/2011
+!!jyg!!
+       IF (prt_level >=10) THEN
+        DO j = 1, knon
+         print*,'Chx,Chw,Ch', ycdragh_x(j), ycdragh_w(j), ycdragh(j)
+         print*,'Khx,Khw,Kh', Kech_h_x(j), Kech_h_w(j), Kech_h(j)
+!         print*,'tsurf_x,tsurf_w,tsurf,t1', ytsurf_th_x(j), ytsurf_th_w(j), ytsurf_th(j), yt(j,1)
+         print*,'tsurf_x,t1x,tsurf_w,t1w,tsurf,t1,t1_ancien', &
+ &               ytsurf_th_x(j), yt_x(j,1), ytsurf_th_w(j), yt_w(j,1), ytsurf_th(j), yt(j,1),t(j,1)
+         print*,'qsatsurf,qsatsurf_x,qsatsurf_w', yqsatsurf(j), yqsatsurf_x(j), yqsatsurf_w(j)
+         print*,'delta_coef,delta_flux,delta_tsurf,tau', delta_coef(j), y_delta_flux_t1(j), y_delta_tsurf(j), tau_eq(j) 
+        ENDDO
+
+        DO j=1,knon
+         print*,'fluxT_x, fluxT_w, y_flux_t1, fluxQ_x, fluxQ_w, yfluxlat, wakes' &
+ &             , y_flux_t1_x(j), y_flux_t1_w(j), y_flux_t1(j), y_flux_q1_x(j)*RLVTT, y_flux_q1_w(j)*RLVTT, yfluxlat(j), ywake_s(j)
+         print*,'beta,ytsurf_new,yqsatsurf', ybeta(j), ytsurf_new(j), yqsatsurf(j)
+         print*,'effusivity,facteur,cstar', effusivity, facteur,wake_cstar(j)
+        ENDDO
+       ENDIF
+
+!!! jyg le 07/02/2012
+       ENDIF  ! (iflag_split .eq.1)
+!!!
+
+!!! jyg le 07/02/2012
+       IF (iflag_split .eq.0) THEN
+!!!
+!!! nrlmd & jyg les 02/05/2011, 13/06/2011, 05/02/2012
+        CALL climb_hq_up(knon, dtime, yt, yq, &
             y_flux_q1, y_flux_t1, ypaprs, ypplay, &
+!!! jyg le 07/02/2012
+            AcoefH, AcoefQ, BcoefH, BcoefQ, &
+            CcoefH, CcoefQ, DcoefH, DcoefQ, &
+            Kcoef_hq, gama_q, gama_h, &
+!!!
             y_flux_q(:,:), y_flux_t(:,:), y_d_q(:,:), y_d_t(:,:))    
-       
-
-       CALL climb_wind_up(knon, dtime, yu, yv, y_flux_u1, y_flux_v1, &
+       ELSE  !(iflag_split .eq.0)
+        CALL climb_hq_up(knon, dtime, yt_x, yq_x, &
+            y_flux_q1_x, y_flux_t1_x, ypaprs, ypplay, &
+!!! nrlmd le 02/05/2011
+            AcoefH_x, AcoefQ_x, BcoefH_x, BcoefQ_x, &
+            CcoefH_x, CcoefQ_x, DcoefH_x, DcoefQ_x, &
+            Kcoef_hq_x, gama_q_x, gama_h_x, &
+!!!
+            y_flux_q_x(:,:), y_flux_t_x(:,:), y_d_q_x(:,:), y_d_t_x(:,:))    
+!
+       CALL climb_hq_up(knon, dtime, yt_w, yq_w, &
+            y_flux_q1_w, y_flux_t1_w, ypaprs, ypplay, &
+!!! nrlmd le 02/05/2011
+            AcoefH_w, AcoefQ_w, BcoefH_w, BcoefQ_w, &
+            CcoefH_w, CcoefQ_w, DcoefH_w, DcoefQ_w, &
+            Kcoef_hq_w, gama_q_w, gama_h_w, &
+!!!
+            y_flux_q_w(:,:), y_flux_t_w(:,:), y_d_q_w(:,:), y_d_t_w(:,:))    
+!!!
+       ENDIF  ! (iflag_split .eq.0)
+!!!
+
+!!! jyg le 07/02/2012
+       IF (iflag_split .eq.0) THEN
+!!!
+!!! nrlmd & jyg les 02/05/2011, 13/06/2011, 05/02/2012
+        CALL climb_wind_up(knon, dtime, yu, yv, y_flux_u1, y_flux_v1, &
+!!! jyg le 07/02/2012
+            AcoefU, AcoefV, BcoefU, BcoefV, &
+            CcoefU, CcoefV, DcoefU, DcoefV, &
+            Kcoef_m, &
+!!!
             y_flux_u, y_flux_v, y_d_u, y_d_v)
-
-
      y_d_t_diss(:,:)=0.
      IF (iflag_pbl>=20 .and. iflag_pbl<30) THEN
@@ -1071,8 +1905,51 @@
 !     print*,'yamada_c OK'
 
-       DO j = 1, knon
+       ELSE  !(iflag_split .eq.0)
+        CALL climb_wind_up(knon, dtime, yu_x, yv_x, y_flux_u1_x, y_flux_v1_x, &
+!!! nrlmd le 02/05/2011
+            AcoefU_x, AcoefV_x, BcoefU_x, BcoefV_x, &
+            CcoefU_x, CcoefV_x, DcoefU_x, DcoefV_x, &
+            Kcoef_m_x, &
+!!!
+            y_flux_u_x, y_flux_v_x, y_d_u_x, y_d_v_x)
+!
+     y_d_t_diss_x(:,:)=0.
+     IF (iflag_pbl>=20 .and. iflag_pbl<30) THEN
+        CALL yamada_c(knon,dtime,ypaprs,ypplay &
+    &   ,yu_x,yv_x,yt_x,y_d_u_x,y_d_v_x,y_d_t_x,ycdragm_x,ytke_x,ycoefm_x,ycoefh_x &
+        ,ycoefq_x,y_d_t_diss_x,yustar_x &
+    &   ,iflag_pbl,nsrf)
+     ENDIF
+!     print*,'yamada_c OK'
+
+        CALL climb_wind_up(knon, dtime, yu_w, yv_w, y_flux_u1_w, y_flux_v1_w, &
+!!! nrlmd le 02/05/2011
+            AcoefU_w, AcoefV_w, BcoefU_w, BcoefV_w, &
+            CcoefU_w, CcoefV_w, DcoefU_w, DcoefV_w, &
+            Kcoef_m_w, &
+!!!
+            y_flux_u_w, y_flux_v_w, y_d_u_w, y_d_v_w)
+!!!
+     y_d_t_diss_w(:,:)=0.
+     IF (iflag_pbl>=20 .and. iflag_pbl<30) THEN
+        CALL yamada_c(knon,dtime,ypaprs,ypplay &
+    &   ,yu_w,yv_w,yt_w,y_d_u_w,y_d_v_w,y_d_t_w,ycdragm_w,ytke_w,ycoefm_w,ycoefh_w &
+        ,ycoefq_w,y_d_t_diss_w,yustar_w &
+    &   ,iflag_pbl,nsrf)
+     ENDIF
+!     print*,'yamada_c OK'
+!
+        IF (prt_level >=10) THEN
+         print *, 'After climbing up, lfuxlat_x, fluxlat_w ', &
+               yfluxlat_x, yfluxlat_w
+        ENDIF
+!
+       ENDIF  ! (iflag_split .eq.0)
+!!!
+
+        DO j = 1, knon
           y_dflux_t(j) = y_dflux_t(j) * ypct(j)
           y_dflux_q(j) = y_dflux_q(j) * ypct(j)
-       ENDDO
+        ENDDO
 
 !****************************************************************************************
@@ -1084,6 +1961,10 @@
 !****************************************************************************************
 
-       DO k = 1, klev
-          DO j = 1, knon
+
+!!! jyg le 07/02/2012
+       IF (iflag_split .eq.0) THEN
+!!!
+        DO k = 1, klev
+           DO j = 1, knon
              i = ni(j)
              y_d_t_diss(j,k)  = y_d_t_diss(j,k) * ypct(j)
@@ -1099,6 +1980,74 @@
 
 
+           ENDDO
+        ENDDO
+
+
+       ELSE  !(iflag_split .eq.0)
+
+! Tendances hors poches
+        DO k = 1, klev
+          DO j = 1, knon
+            i = ni(j)
+            y_d_t_diss_x(j,k)  = y_d_t_diss_x(j,k) * ypct(j)
+            y_d_t_x(j,k)  = y_d_t_x(j,k) * ypct(j)
+            y_d_q_x(j,k)  = y_d_q_x(j,k) * ypct(j)
+            y_d_u_x(j,k)  = y_d_u_x(j,k) * ypct(j)
+            y_d_v_x(j,k)  = y_d_v_x(j,k) * ypct(j)
+
+            flux_t_x(i,k,nsrf) = y_flux_t_x(j,k)
+            flux_q_x(i,k,nsrf) = y_flux_q_x(j,k)
+            flux_u_x(i,k,nsrf) = y_flux_u_x(j,k)
+            flux_v_x(i,k,nsrf) = y_flux_v_x(j,k)
           ENDDO
-       ENDDO
+        ENDDO
+
+! Tendances dans les poches
+        DO k = 1, klev
+          DO j = 1, knon
+            i = ni(j)
+            y_d_t_diss_w(j,k)  = y_d_t_diss_w(j,k) * ypct(j)
+            y_d_t_w(j,k)  = y_d_t_w(j,k) * ypct(j)
+            y_d_q_w(j,k)  = y_d_q_w(j,k) * ypct(j)
+            y_d_u_w(j,k)  = y_d_u_w(j,k) * ypct(j)
+            y_d_v_w(j,k)  = y_d_v_w(j,k) * ypct(j)
+
+            flux_t_w(i,k,nsrf) = y_flux_t_w(j,k)
+            flux_q_w(i,k,nsrf) = y_flux_q_w(j,k)
+            flux_u_w(i,k,nsrf) = y_flux_u_w(j,k)
+            flux_v_w(i,k,nsrf) = y_flux_v_w(j,k)
+          ENDDO
+        ENDDO
+
+! Flux, tendances et Tke moyenne dans la maille
+        DO k = 1, klev
+          DO j = 1, knon
+            i = ni(j)
+            flux_t(i,k,nsrf) = flux_t_x(i,k,nsrf)+ywake_s(j)*(flux_t_w(i,k,nsrf)-flux_t_x(i,k,nsrf))
+            flux_q(i,k,nsrf) = flux_q_x(i,k,nsrf)+ywake_s(j)*(flux_q_w(i,k,nsrf)-flux_q_x(i,k,nsrf))
+            flux_u(i,k,nsrf) = flux_u_x(i,k,nsrf)+ywake_s(j)*(flux_u_w(i,k,nsrf)-flux_u_x(i,k,nsrf))
+            flux_v(i,k,nsrf) = flux_v_x(i,k,nsrf)+ywake_s(j)*(flux_v_w(i,k,nsrf)-flux_v_x(i,k,nsrf))
+          ENDDO
+        ENDDO
+        DO j=1,knon
+          yfluxlat(j)=yfluxlat_x(j)+ywake_s(j)*(yfluxlat_w(j)-yfluxlat_x(j))
+        ENDDO
+        IF (prt_level >=10) THEN
+          print *,' nsrf, flux_t(:,1,nsrf), flux_t_x(:,1,nsrf), flux_t_w(:,1,nsrf) ', &
+                    nsrf, flux_t(:,1,nsrf), flux_t_x(:,1,nsrf), flux_t_w(:,1,nsrf)
+        ENDIF
+
+        DO k = 1, klev
+          DO j = 1, knon
+            y_d_t_diss(j,k) = y_d_t_diss_x(j,k)+ywake_s(j)*(y_d_t_diss_w(j,k) -y_d_t_diss_x(j,k))
+            y_d_t(j,k) = y_d_t_x(j,k)+ywake_s(j)*(y_d_t_w(j,k) -y_d_t_x(j,k))
+            y_d_q(j,k) = y_d_q_x(j,k)+ywake_s(j)*(y_d_q_w(j,k) -y_d_q_x(j,k))
+            y_d_u(j,k) = y_d_u_x(j,k)+ywake_s(j)*(y_d_u_w(j,k) -y_d_u_x(j,k))
+            y_d_v(j,k) = y_d_v_x(j,k)+ywake_s(j)*(y_d_v_w(j,k) -y_d_v_x(j,k))
+          ENDDO
+        ENDDO
+
+       ENDIF  ! (iflag_split .eq.0)
+!!!
 
 !      print*,'Dans pbl OK1'
@@ -1130,11 +2079,74 @@
 !      print*,'Dans pbl OK2'
 
+!!! jyg le 07/02/2012
+       IF (iflag_split .eq.1) THEN
+!!!
+!!! nrlmd le 02/05/2011
+        fluxlat_x(:,nsrf) = 0.
+        fluxlat_w(:,nsrf) = 0.
+        DO j = 1, knon
+          i = ni(j)
+          fluxlat_x(i,nsrf) = yfluxlat_x(j)
+          fluxlat_w(i,nsrf) = yfluxlat_w(j)
+!!!
+!!! nrlmd le 13/06/2011
+          delta_tsurf(i,nsrf)=y_delta_tsurf(j)*ypct(j)
+          cdragh_x(i) = cdragh_x(i) + ycdragh_x(j)*ypct(j)
+          cdragh_w(i) = cdragh_w(i) + ycdragh_w(j)*ypct(j)
+          cdragm_x(i) = cdragm_x(i) + ycdragm_x(j)*ypct(j)
+          cdragm_w(i) = cdragm_w(i) + ycdragm_w(j)*ypct(j)
+          kh(i) = kh(i) + Kech_h(j)*ypct(j)
+          kh_x(i) = kh_x(i) + Kech_h_x(j)*ypct(j)
+          kh_w(i) = kh_w(i) + Kech_h_w(j)*ypct(j)
+!!!
+        END DO
+!!!      
+       ENDIF  ! (iflag_split .eq.1)
+!!!
+!!! nrlmd le 02/05/2011
+!!jyg le 20/02/2011
+!!        tke_x(:,:,nsrf)=0.
+!!        tke_w(:,:,nsrf)=0.
+!!jyg le 20/02/2011
+!!        DO k = 1, klev+1
+!!          DO j = 1, knon
+!!            i = ni(j)
+!!            wake_dltke(i,k,nsrf) = ytke_w(j,k) - ytke_x(j,k)
+!!            tke(i,k,nsrf)   = ytke_x(j,k) + ywake_s(j)*wake_dltke(i,k,nsrf)
+!!          ENDDO
+!!        ENDDO
+!!jyg le 20/02/2011
+!!        DO k = 1, klev+1
+!!          DO j = 1, knon
+!!            i = ni(j)
+!!            tke(i,k,nsrf)=(1.-ywake_s(j))*tke_x(i,k,nsrf)+ywake_s(j)*tke_w(i,k,nsrf)
+!!          ENDDO
+!!        ENDDO
+!!!
+       IF (iflag_split .eq.0) THEN
+        DO k = 2, klev
+           DO j = 1, knon
+              i = ni(j)
+              tke(i,k,nsrf)    = ytke(j,k)
+              tke(i,k,is_ave) = tke(i,k,is_ave) + ytke(j,k)*ypct(j)
+           END DO
+        END DO
+
+       ELSE
+        DO k = 2, klev
+          DO j = 1, knon
+            i = ni(j)
+            wake_dltke(i,k,nsrf) = ytke_w(j,k) - ytke_x(j,k)
+            tke(i,k,nsrf)   = ytke_x(j,k) + ywake_s(j)*wake_dltke(i,k,nsrf)
+            tke(i,k,is_ave) = tke(i,k,is_ave) + tke(i,k,nsrf)*ypct(j)
+          ENDDO
+        ENDDO
+       ENDIF  ! (iflag_split .eq.0)
+!!!
        DO k = 2, klev
           DO j = 1, knon
              i = ni(j)
-             tke(i,k,nsrf)    = ytke(j,k)
              zcoefh(i,k,nsrf) = ycoefh(j,k)
              zcoefm(i,k,nsrf) = ycoefm(j,k)
-             tke(i,k,is_ave) = tke(i,k,is_ave) + ytke(j,k)*ypct(j)
              zcoefh(i,k,is_ave) = zcoefh(i,k,is_ave) + ycoefh(j,k)*ypct(j)
              zcoefm(i,k,is_ave) = zcoefm(i,k,is_ave) + ycoefm(j,k)*ypct(j)
@@ -1159,4 +2171,30 @@
        END DO
        
+!!! jyg le 07/02/2012
+       IF (iflag_split .eq.1) THEN
+!!!
+!!! nrlmd+jyg le 02/05/2011 et le 20/02/2012
+        DO k = 1, klev
+          DO j = 1, knon
+           i = ni(j)
+           d_t_diss_x(i,k) = d_t_diss_x(i,k) + y_d_t_diss_x(j,k)
+           d_t_x(i,k) = d_t_x(i,k) + y_d_t_x(j,k)
+           d_q_x(i,k) = d_q_x(i,k) + y_d_q_x(j,k)
+           d_u_x(i,k) = d_u_x(i,k) + y_d_u_x(j,k)
+           d_v_x(i,k) = d_v_x(i,k) + y_d_v_x(j,k)
+!
+           d_t_diss_w(i,k) = d_t_diss_w(i,k) + y_d_t_diss_w(j,k)
+           d_t_w(i,k) = d_t_w(i,k) + y_d_t_w(j,k)
+           d_q_w(i,k) = d_q_w(i,k) + y_d_q_w(j,k)
+           d_u_w(i,k) = d_u_w(i,k) + y_d_u_w(j,k)
+           d_v_w(i,k) = d_v_w(i,k) + y_d_v_w(j,k)
+!
+!!           d_wake_dlt(i,k) = d_wake_dlt(i,k) + y_d_t_w(i,k)-y_d_t_x(i,k)
+!!           d_wake_dlq(i,k) = d_wake_dlq(i,k) + y_d_q_w(i,k)-y_d_q_x(i,k)
+          END DO
+        END DO
+!!!
+       ENDIF  ! (iflag_split .eq.1)
+!!!
        
        DO k = 1, klev
@@ -1173,6 +2211,11 @@
 !      print*,'Dans pbl OK4'
 
-!****************************************************************************************
-! 14) Calculate the temperature et relative humidity at 2m and the wind at 10m 
+       IF (prt_level >=10) THEN
+         print *, 'pbl_surface tendencies for w: d_t_w, d_t_x, d_t ', &
+          d_t_w(:,1), d_t_x(:,1), d_t(:,1)
+       ENDIF
+
+!****************************************************************************************
+! 14) Calculate the temperature and relative humidity at 2m and the wind at 10m 
 !     Call HBTM
 !
@@ -1184,4 +2227,5 @@
        u10m(:,nsrf)   = 0.
        v10m(:,nsrf)   = 0.
+
        pblh(:,nsrf)   = 0.        ! Hauteur de couche limite
        plcl(:,nsrf)   = 0.        ! Niveau de condensation de la CLA
@@ -1194,5 +2238,46 @@
        trmb2(:,nsrf)  = 0.        ! inhibition 
        trmb3(:,nsrf)  = 0.        ! Point Omega
-
+!
+!!! jyg le 07/02/2012
+       IF (iflag_split .eq.1) THEN
+       t2m_x(:,nsrf)    = 0. 
+       q2m_x(:,nsrf)    = 0. 
+       ustar_x(:,nsrf)   = 0.
+       wstar_x(:,nsrf)   = 0.
+       u10m_x(:,nsrf)   = 0. 
+       v10m_x(:,nsrf)   = 0. 
+                           
+       pblh_x(:,nsrf)   = 0.      ! Hauteur de couche limite
+       plcl_x(:,nsrf)   = 0.      ! Niveau de condensation de la CLA
+       capCL_x(:,nsrf)  = 0.      ! CAPE de couche limite
+       oliqCL_x(:,nsrf) = 0.      ! eau_liqu integree de couche limite
+       cteiCL_x(:,nsrf) = 0.      ! cloud top instab. crit. couche limite
+       pblt_x(:,nsrf)   = 0.      ! T a la Hauteur de couche limite
+       therm_x(:,nsrf)  = 0.      
+       trmb1_x(:,nsrf)  = 0.      ! deep_cape
+       trmb2_x(:,nsrf)  = 0.      ! inhibition 
+       trmb3_x(:,nsrf)  = 0.      ! Point Omega
+!
+       t2m_w(:,nsrf)    = 0. 
+       q2m_w(:,nsrf)    = 0. 
+       ustar_w(:,nsrf)   = 0.
+       wstar_w(:,nsrf)   = 0.
+       u10m_w(:,nsrf)   = 0. 
+       v10m_w(:,nsrf)   = 0. 
+                           
+       pblh_w(:,nsrf)   = 0.      ! Hauteur de couche limite
+       plcl_w(:,nsrf)   = 0.      ! Niveau de condensation de la CLA
+       capCL_w(:,nsrf)  = 0.      ! CAPE de couche limite
+       oliqCL_w(:,nsrf) = 0.      ! eau_liqu integree de couche limite
+       cteiCL_w(:,nsrf) = 0.      ! cloud top instab. crit. couche limite
+       pblt_w(:,nsrf)   = 0.      ! T a la Hauteur de couche limite
+       therm_w(:,nsrf)  = 0.      
+       trmb1_w(:,nsrf)  = 0.      ! deep_cape
+       trmb2_w(:,nsrf)  = 0.      ! inhibition 
+       trmb3_w(:,nsrf)  = 0.      ! Point Omega
+!!!      
+       ENDIF  ! (iflag_split .eq.1)
+!!!
+!
 #undef T2m     
 #define T2m     
@@ -1203,6 +2288,7 @@
 !      print*,'tair1,yt(:,1),y_d_t(:,1)'
 !      print*, tair1,yt(:,1),y_d_t(:,1)
-       DO j=1, knon
-          i = ni(j)
+!!! jyg le 07/02/2012
+       IF (iflag_split .eq.0) THEN
+        DO j=1, knon
           uzon(j) = yu(j,1) + y_d_u(j,1)
           vmer(j) = yv(j,1) + y_d_v(j,1)
@@ -1212,4 +2298,33 @@
                * (ypaprs(j,1)-ypplay(j,1))
           tairsol(j) = yts(j) + y_d_ts(j)
+          qairsol(j) = yqsurf(j)
+        END DO
+       ELSE  ! (iflag_split .eq.0)
+        DO j=1, knon
+          uzon_x(j) = yu_x(j,1) + y_d_u_x(j,1)
+          vmer_x(j) = yv_x(j,1) + y_d_v_x(j,1)
+          tair1_x(j) = yt_x(j,1) + y_d_t_x(j,1) + y_d_t_diss_x(j,1)
+          qair1_x(j) = yq_x(j,1) + y_d_q_x(j,1)
+          zgeo1_x(j) = RD * tair1_x(j) / (0.5*(ypaprs(j,1)+ypplay(j,1))) &
+               * (ypaprs(j,1)-ypplay(j,1))
+          tairsol(j) = yts(j) + y_d_ts(j)
+          tairsol_x(j) = tairsol(j) - ywake_s(j)*y_delta_tsurf(j)
+          qairsol(j) = yqsurf(j)
+        END DO
+        DO j=1, knon
+          uzon_w(j) = yu_w(j,1) + y_d_u_w(j,1)
+          vmer_w(j) = yv_w(j,1) + y_d_v_w(j,1)
+          tair1_w(j) = yt_w(j,1) + y_d_t_w(j,1) + y_d_t_diss_w(j,1)
+          qair1_w(j) = yq_w(j,1) + y_d_q_w(j,1)
+          zgeo1_w(j) = RD * tair1_w(j) / (0.5*(ypaprs(j,1)+ypplay(j,1))) &
+               * (ypaprs(j,1)-ypplay(j,1))
+          tairsol_w(j) = tairsol(j) + (1.- ywake_s(j))*y_delta_tsurf(j)
+          qairsol(j) = yqsurf(j)
+        END DO
+!!!      
+       ENDIF  ! (iflag_split .eq.0)
+!!!
+       DO j=1, knon
+          i = ni(j)
           rugo1(j) = yrugos(j)
           IF(nsrf.EQ.is_oce) THEN
@@ -1218,5 +2333,4 @@
           psfce(j)=ypaprs(j,1)
           patm(j)=ypplay(j,1)
-          qairsol(j) = yqsurf(j)
        END DO
        
@@ -1226,21 +2340,59 @@
 
 ! Calculate the temperature et relative humidity at 2m and the wind at 10m 
-       CALL stdlevvar(klon, knon, nsrf, zxli, &
+!!! jyg le 07/02/2012
+       IF (iflag_split .eq.0) THEN
+        CALL stdlevvar(klon, knon, nsrf, zxli, &
             uzon, vmer, tair1, qair1, zgeo1, &
             tairsol, qairsol, rugo1, psfce, patm, &
             yt2m, yq2m, yt10m, yq10m, yu10m, yustar)
-!      print*,'Dans pbl OK42B'
-
-       DO j=1, knon
+       ELSE  !(iflag_split .eq.0)
+        CALL stdlevvar(klon, knon, nsrf, zxli, &
+            uzon_x, vmer_x, tair1_x, qair1_x, zgeo1_x, &
+            tairsol_x, qairsol, rugo1, psfce, patm, &
+            yt2m_x, yq2m_x, yt10m_x, yq10m_x, yu10m_x, yustar_x)
+        CALL stdlevvar(klon, knon, nsrf, zxli, &
+            uzon_w, vmer_w, tair1_w, qair1_w, zgeo1_w, &
+            tairsol_w, qairsol, rugo1, psfce, patm, &
+            yt2m_w, yq2m_w, yt10m_w, yq10m_w, yu10m_w, yustar_w)
+!!!
+       ENDIF  ! (iflag_split .eq.0)
+!!!
+!!! jyg le 07/02/2012
+       IF (iflag_split .eq.0) THEN
+        DO j=1, knon
           i = ni(j)
           t2m(i,nsrf)=yt2m(j)
           q2m(i,nsrf)=yq2m(j)
-          
-          ! u10m, v10m : composantes du vent a 10m sans spirale de Ekman
+     ! u10m, v10m : composantes du vent a 10m sans spirale de Ekman
           ustar(i,nsrf)=yustar(j)
           u10m(i,nsrf)=(yu10m(j) * uzon(j))/SQRT(uzon(j)**2+vmer(j)**2)
           v10m(i,nsrf)=(yu10m(j) * vmer(j))/SQRT(uzon(j)**2+vmer(j)**2)
-
-       END DO
+        END DO
+       ELSE  !(iflag_split .eq.0)
+        DO j=1, knon
+          i = ni(j)
+          t2m_x(i,nsrf)=yt2m_x(j)
+          q2m_x(i,nsrf)=yq2m_x(j)
+     ! u10m, v10m : composantes du vent a 10m sans spirale de Ekman
+          ustar_x(i,nsrf)=yustar_x(j)
+          u10m_x(i,nsrf)=(yu10m_x(j) * uzon_x(j))/SQRT(uzon_x(j)**2+vmer_x(j)**2)
+          v10m_x(i,nsrf)=(yu10m_x(j) * vmer_x(j))/SQRT(uzon_x(j)**2+vmer_x(j)**2)
+        END DO
+        DO j=1, knon
+          i = ni(j)
+          t2m_w(i,nsrf)=yt2m_w(j)
+          q2m_w(i,nsrf)=yq2m_w(j)
+     ! u10m, v10m : composantes du vent a 10m sans spirale de Ekman
+          ustar_w(i,nsrf)=yustar_w(j)
+          u10m_w(i,nsrf)=(yu10m_w(j) * uzon_w(j))/SQRT(uzon_w(j)**2+vmer_w(j)**2)
+          v10m_w(i,nsrf)=(yu10m_w(j) * vmer_w(j))/SQRT(uzon_w(j)**2+vmer_w(j)**2)
+!
+          ustar(i,nsrf) = ustar_x(i,nsrf) + wake_s(i)*(ustar_w(i,nsrf)-ustar_x(i,nsrf))
+          u10m(i,nsrf) = u10m_x(i,nsrf) + wake_s(i)*(u10m_w(i,nsrf)-u10m_x(i,nsrf))
+          v10m(i,nsrf) = v10m_x(i,nsrf) + wake_s(i)*(v10m_w(i,nsrf)-v10m_x(i,nsrf))
+        END DO
+!!!
+       ENDIF  ! (iflag_split .eq.0)
+!!!
 
 !      print*,'Dans pbl OK43'
@@ -1248,4 +2400,6 @@
 !IM Ajoute dependance type surface
        IF (thermcep) THEN
+!!! jyg le 07/02/2012
+       IF (iflag_split .eq.0) THEN
           DO j = 1, knon
              i=ni(j)
@@ -1259,14 +2413,91 @@
              qsat2m(i) = qsat2m(i) + zx_qs1  * pctsrf(i,nsrf)
           END DO
+       ELSE  ! (iflag_split .eq.0)
+          DO j = 1, knon
+             i=ni(j)
+             zdelta1 = MAX(0.,SIGN(1., rtt-yt2m_x(j) ))
+             zx_qs1  = r2es * FOEEW(yt2m_x(j),zdelta1)/paprs(i,1)
+             zx_qs1  = MIN(0.5,zx_qs1)
+             zcor1   = 1./(1.-RETV*zx_qs1)
+             zx_qs1  = zx_qs1*zcor1
+             
+             rh2m_x(i)   = rh2m_x(i)   + yq2m_x(j)/zx_qs1 * pctsrf(i,nsrf)
+             qsat2m_x(i) = qsat2m_x(i) + zx_qs1  * pctsrf(i,nsrf)
+          END DO
+          DO j = 1, knon
+             i=ni(j)
+             zdelta1 = MAX(0.,SIGN(1., rtt-yt2m_w(j) ))
+             zx_qs1  = r2es * FOEEW(yt2m_w(j),zdelta1)/paprs(i,1)
+             zx_qs1  = MIN(0.5,zx_qs1)
+             zcor1   = 1./(1.-RETV*zx_qs1)
+             zx_qs1  = zx_qs1*zcor1
+             
+             rh2m_w(i)   = rh2m_w(i)   + yq2m_w(j)/zx_qs1 * pctsrf(i,nsrf)
+             qsat2m_w(i) = qsat2m_w(i) + zx_qs1  * pctsrf(i,nsrf)
+          END DO
+!!!      
+       ENDIF  ! (iflag_split .eq.0)
+!!!
        END IF
+!
+       IF (prt_level >=10) THEN
+         print *, 'T2m, q2m, RH2m ', &
+          t2m, q2m, rh2m
+       ENDIF
 
 !   print*,'OK pbl 5'
-       CALL hbtm(knon, ypaprs, ypplay, &
+!
+!!! jyg le 07/02/2012
+       IF (iflag_split .eq.0) THEN
+        CALL hbtm(knon, ypaprs, ypplay, &
             yt2m,yt10m,yq2m,yq10m,yustar,ywstar, &
             y_flux_t,y_flux_q,yu,yv,yt,yq, &
             ypblh,ycapCL,yoliqCL,ycteiCL,ypblT, &
             ytherm,ytrmb1,ytrmb2,ytrmb3,ylcl)
+          IF (prt_level >=10) THEN
+       print *,' Arg. de HBTM: yt2m ',yt2m
+       print *,' Arg. de HBTM: yt10m ',yt10m
+       print *,' Arg. de HBTM: yq2m ',yq2m
+       print *,' Arg. de HBTM: yq10m ',yq10m
+       print *,' Arg. de HBTM: yustar ',yustar
+       print *,' Arg. de HBTM: y_flux_t ',y_flux_t
+       print *,' Arg. de HBTM: y_flux_q ',y_flux_q
+       print *,' Arg. de HBTM: yu ',yu
+       print *,' Arg. de HBTM: yv ',yv
+       print *,' Arg. de HBTM: yt ',yt
+       print *,' Arg. de HBTM: yq ',yq
+          ENDIF
+       ELSE  ! (iflag_split .eq.0)
+        CALL HBTM(knon, ypaprs, ypplay, &
+            yt2m_x,yt10m_x,yq2m_x,yq10m_x,yustar_x,ywstar_x, &
+            y_flux_t_x,y_flux_q_x,yu_x,yv_x,yt_x,yq_x, &
+            ypblh_x,ycapCL_x,yoliqCL_x,ycteiCL_x,ypblT_x, &
+            ytherm_x,ytrmb1_x,ytrmb2_x,ytrmb3_x,ylcl_x)
+          IF (prt_level >=10) THEN
+       print *,' Arg. de HBTM: yt2m_x ',yt2m_x
+       print *,' Arg. de HBTM: yt10m_x ',yt10m_x
+       print *,' Arg. de HBTM: yq2m_x ',yq2m_x
+       print *,' Arg. de HBTM: yq10m_x ',yq10m_x
+       print *,' Arg. de HBTM: yustar_x ',yustar_x
+       print *,' Arg. de HBTM: y_flux_t_x ',y_flux_t_x
+       print *,' Arg. de HBTM: y_flux_q_x ',y_flux_q_x
+       print *,' Arg. de HBTM: yu_x ',yu_x
+       print *,' Arg. de HBTM: yv_x ',yv_x
+       print *,' Arg. de HBTM: yt_x ',yt_x
+       print *,' Arg. de HBTM: yq_x ',yq_x
+          ENDIF
+        CALL HBTM(knon, ypaprs, ypplay, &
+            yt2m_w,yt10m_w,yq2m_w,yq10m_w,yustar_w,ywstar_w, &
+            y_flux_t_w,y_flux_q_w,yu_w,yv_w,yt_w,yq_w, &
+            ypblh_w,ycapCL_w,yoliqCL_w,ycteiCL_w,ypblT_w, &
+            ytherm_w,ytrmb1_w,ytrmb2_w,ytrmb3_w,ylcl_w)
+!!!      
+       ENDIF  ! (iflag_split .eq.0)
+!!!
        
-       DO j=1, knon
+!!! jyg le 07/02/2012
+       IF (iflag_split .eq.0) THEN
+!!!
+        DO j=1, knon
           i = ni(j)
           pblh(i,nsrf)   = ypblh(j)
@@ -1281,6 +2512,53 @@
           trmb2(i,nsrf)  = ytrmb2(j)
           trmb3(i,nsrf)  = ytrmb3(j)
-       END DO
-       
+        END DO
+        IF (prt_level >=10) THEN
+          print *, 'After HBTM: pblh ', pblh
+          print *, 'After HBTM: plcl ', plcl
+          print *, 'After HBTM: cteiCL ', cteiCL
+        ENDIF
+       ELSE  !(iflag_split .eq.0)
+        DO j=1, knon
+          i = ni(j)
+          pblh_x(i,nsrf)   = ypblh_x(j)
+          wstar_x(i,nsrf)  = ywstar_x(j)
+          plcl_x(i,nsrf)   = ylcl_x(j)
+          capCL_x(i,nsrf)  = ycapCL_x(j)
+          oliqCL_x(i,nsrf) = yoliqCL_x(j)
+          cteiCL_x(i,nsrf) = ycteiCL_x(j)
+          pblT_x(i,nsrf)   = ypblT_x(j)
+          therm_x(i,nsrf)  = ytherm_x(j)
+          trmb1_x(i,nsrf)  = ytrmb1_x(j)
+          trmb2_x(i,nsrf)  = ytrmb2_x(j)
+          trmb3_x(i,nsrf)  = ytrmb3_x(j)
+        END DO
+        IF (prt_level >=10) THEN
+          print *, 'After HBTM: pblh_x ', pblh_x
+          print *, 'After HBTM: plcl_x ', plcl_x
+          print *, 'After HBTM: cteiCL_x ', cteiCL_x
+        ENDIF
+        DO j=1, knon
+          i = ni(j)
+          pblh_w(i,nsrf)   = ypblh_w(j)
+          wstar_w(i,nsrf)  = ywstar_w(j)
+          plcl_w(i,nsrf)   = ylcl_w(j)
+          capCL_w(i,nsrf)  = ycapCL_w(j)
+          oliqCL_w(i,nsrf) = yoliqCL_w(j)
+          cteiCL_w(i,nsrf) = ycteiCL_w(j)
+          pblT_w(i,nsrf)   = ypblT_w(j)
+          therm_w(i,nsrf)  = ytherm_w(j)
+          trmb1_w(i,nsrf)  = ytrmb1_w(j)
+          trmb2_w(i,nsrf)  = ytrmb2_w(j)
+          trmb3_w(i,nsrf)  = ytrmb3_w(j)
+        END DO
+        IF (prt_level >=10) THEN
+          print *, 'After HBTM: pblh_w ', pblh_w
+          print *, 'After HBTM: plcl_w ', plcl_w
+          print *, 'After HBTM: cteiCL_w ', cteiCL_w
+        ENDIF
+!!!
+       ENDIF  ! (iflag_split .eq.0)
+!!!
+
 !   print*,'OK pbl 6'
 #else 
@@ -1297,5 +2575,5 @@
 
 !****************************************************************************************
-! 16) Calculate the mean value over all sub-surfaces for som variables
+! 16) Calculate the mean value over all sub-surfaces for some variables
 !
 !****************************************************************************************
@@ -1304,4 +2582,38 @@
     zxfluxt(:,:) = 0.0 ; zxfluxq(:,:) = 0.0
     zxfluxu(:,:) = 0.0 ; zxfluxv(:,:) = 0.0
+    zxfluxt_x(:,:) = 0.0 ; zxfluxq_x(:,:) = 0.0
+    zxfluxu_x(:,:) = 0.0 ; zxfluxv_x(:,:) = 0.0
+    zxfluxt_w(:,:) = 0.0 ; zxfluxq_w(:,:) = 0.0
+    zxfluxu_w(:,:) = 0.0 ; zxfluxv_w(:,:) = 0.0
+
+!!! jyg le 07/02/2012
+       IF (iflag_split .eq.1) THEN
+!!!
+!!! nrlmd & jyg les 02/05/2011, 05/02/2012
+
+        DO nsrf = 1, nbsrf
+          DO k = 1, klev
+            DO i = 1, klon
+              zxfluxt_x(i,k) = zxfluxt_x(i,k) + flux_t_x(i,k,nsrf) * pctsrf(i,nsrf)
+              zxfluxq_x(i,k) = zxfluxq_x(i,k) + flux_q_x(i,k,nsrf) * pctsrf(i,nsrf)
+              zxfluxu_x(i,k) = zxfluxu_x(i,k) + flux_u_x(i,k,nsrf) * pctsrf(i,nsrf)
+              zxfluxv_x(i,k) = zxfluxv_x(i,k) + flux_v_x(i,k,nsrf) * pctsrf(i,nsrf)
+!
+              zxfluxt_w(i,k) = zxfluxt_w(i,k) + flux_t_w(i,k,nsrf) * pctsrf(i,nsrf)
+              zxfluxq_w(i,k) = zxfluxq_w(i,k) + flux_q_w(i,k,nsrf) * pctsrf(i,nsrf)
+              zxfluxu_w(i,k) = zxfluxu_w(i,k) + flux_u_w(i,k,nsrf) * pctsrf(i,nsrf)
+              zxfluxv_w(i,k) = zxfluxv_w(i,k) + flux_v_w(i,k,nsrf) * pctsrf(i,nsrf)
+            END DO
+          END DO
+        END DO
+
+    DO i = 1, klon
+      zxsens_x(i) = - zxfluxt_x(i,1)
+      zxsens_w(i) = - zxfluxt_w(i,1)
+    END DO
+!!!
+       ENDIF  ! (iflag_split .eq.1)
+!!!
+
     DO nsrf = 1, nbsrf
        DO k = 1, klev
@@ -1315,5 +2627,4 @@
     END DO
 
-!   print*,'OK pbl 8'
     DO i = 1, klon
        zxsens(i)     = - zxfluxt(i,1) ! flux de chaleur sensible au sol
@@ -1321,4 +2632,5 @@
        fder_print(i) = fder(i) + dflux_t(i) + dflux_q(i)
     ENDDO
+!!!
    
 !
@@ -1329,4 +2641,8 @@
     zustar(:)=0.0 ; zu10m(:) = 0.0   ; zv10m(:) = 0.0
     s_pblh(:) = 0.0  ; s_plcl(:) = 0.0 
+!!! jyg le 07/02/2012
+     s_pblh_x(:) = 0.0  ; s_plcl_x(:) = 0.0 
+     s_pblh_w(:) = 0.0  ; s_plcl_w(:) = 0.0 
+!!!
     s_capCL(:) = 0.0 ; s_oliqCL(:) = 0.0
     s_cteiCL(:) = 0.0; s_pblT(:) = 0.0
@@ -1336,4 +2652,8 @@
     
 !   print*,'OK pbl 9'
+    
+!!! nrlmd le 02/05/2011
+    zxfluxlat_x(:) = 0.0  ;  zxfluxlat_w(:) = 0.0
+!!!
     
     DO nsrf = 1, nbsrf
@@ -1348,5 +2668,11 @@
           zxtsol(i)    = zxtsol(i)    + ts(i,nsrf)      * pctsrf(i,nsrf)
           zxfluxlat(i) = zxfluxlat(i) + fluxlat(i,nsrf) * pctsrf(i,nsrf)
+       END DO
+    END DO
           
+!!! jyg le 07/02/2012
+       IF (iflag_split .eq.0) THEN
+        DO nsrf = 1, nbsrf
+         DO i = 1, klon          
           zt2m(i)  = zt2m(i)  + t2m(i,nsrf)  * pctsrf(i,nsrf)
           zq2m(i)  = zq2m(i)  + q2m(i,nsrf)  * pctsrf(i,nsrf)
@@ -1366,7 +2692,49 @@
           s_trmb2(i)  = s_trmb2(i)  + trmb2(i,nsrf) * pctsrf(i,nsrf)
           s_trmb3(i)  = s_trmb3(i)  + trmb3(i,nsrf) * pctsrf(i,nsrf)
-       END DO
-    END DO
-!   print*,'OK pbl 10'
+         END DO
+        END DO
+       ELSE  !(iflag_split .eq.0)
+        DO nsrf = 1, nbsrf
+         DO i = 1, klon          
+!!! nrlmd le 02/05/2011
+          zxfluxlat_x(i) = zxfluxlat_x(i) + fluxlat_x(i,nsrf) * pctsrf(i,nsrf)
+          zxfluxlat_w(i) = zxfluxlat_w(i) + fluxlat_w(i,nsrf) * pctsrf(i,nsrf)
+!!!
+!!! jyg le 08/02/2012
+!!  Pour le moment, on sort les valeurs dans (x) et (w) de pblh et de plcl ; 
+!!  pour zt2m, on fait la moyenne surfacique sur les sous-surfaces ;
+!!  pour qsat2m, on fait la moyenne surfacique sur (x) et (w) ;
+!!  pour les autres variables, on sort les valeurs de la region (x).
+          zt2m(i)  = zt2m(i)  + (t2m_x(i,nsrf)+wake_s(i)*(t2m_w(i,nsrf)-t2m_x(i,nsrf))) * pctsrf(i,nsrf)
+          zq2m(i)  = zq2m(i)  + q2m_x(i,nsrf)  * pctsrf(i,nsrf)
+          zustar(i) = zustar(i) + ustar_x(i,nsrf) * pctsrf(i,nsrf)
+          wstar(i,is_ave)=wstar(i,is_ave)+wstar_x(i,nsrf)*pctsrf(i,nsrf)
+          zu10m(i) = zu10m(i) + u10m_x(i,nsrf) * pctsrf(i,nsrf)
+          zv10m(i) = zv10m(i) + v10m_x(i,nsrf) * pctsrf(i,nsrf)
+!
+          s_pblh(i)     = s_pblh(i)     + pblh_x(i,nsrf)  * pctsrf(i,nsrf)
+          s_pblh_x(i)   = s_pblh_x(i)   + pblh_x(i,nsrf)  * pctsrf(i,nsrf)
+          s_pblh_w(i)   = s_pblh_w(i)   + pblh_w(i,nsrf)  * pctsrf(i,nsrf)
+!
+          s_plcl(i)     = s_plcl(i)     + plcl_x(i,nsrf)  * pctsrf(i,nsrf)
+          s_plcl_x(i)   = s_plcl_x(i)   + plcl_x(i,nsrf)  * pctsrf(i,nsrf)
+          s_plcl_w(i)   = s_plcl_w(i)   + plcl_w(i,nsrf)  * pctsrf(i,nsrf)
+!
+          s_capCL(i)  = s_capCL(i)  + capCL_x(i,nsrf) * pctsrf(i,nsrf)
+          s_oliqCL(i) = s_oliqCL(i) + oliqCL_x(i,nsrf)* pctsrf(i,nsrf)
+          s_cteiCL(i) = s_cteiCL(i) + cteiCL_x(i,nsrf)* pctsrf(i,nsrf)
+          s_pblT(i)   = s_pblT(i)   + pblT_x(i,nsrf)  * pctsrf(i,nsrf)
+          s_therm(i)  = s_therm(i)  + therm_x(i,nsrf) * pctsrf(i,nsrf)
+          s_trmb1(i)  = s_trmb1(i)  + trmb1_x(i,nsrf) * pctsrf(i,nsrf)
+          s_trmb2(i)  = s_trmb2(i)  + trmb2_x(i,nsrf) * pctsrf(i,nsrf)
+          s_trmb3(i)  = s_trmb3(i)  + trmb3_x(i,nsrf) * pctsrf(i,nsrf)
+         END DO
+        END DO
+        DO i = 1, klon          
+          qsat2m(i)= qsat2m_x(i)+ wake_s(i)*(qsat2m_x(i)-qsat2m_w(i))
+        END DO
+!!!
+       ENDIF  ! (iflag_split .eq.0)
+!!!
 
     IF (check) THEN
Index: /LMDZ5/trunk/libf/phylmd/phyetat0.F90
===================================================================
--- /LMDZ5/trunk/libf/phylmd/phyetat0.F90	(revision 2158)
+++ /LMDZ5/trunk/libf/phylmd/phyetat0.F90	(revision 2159)
@@ -14,5 +14,7 @@
        rlat, rlon, rnebcon, rugoro, sig1, snow_fall, solaire_etat0, sollw, &
        solsw, t_ancien, u_ancien, v_ancien, w01, wake_cstar, wake_deltaq, &
-       wake_deltat, wake_fip, wake_pe, wake_s, zgam, zmax0, zmea, zpic, zsig, &
+       wake_deltat, wake_delta_pbl_TKE, delta_tsurf, wake_fip, wake_pe, &
+       wake_s, zgam, &
+       zmax0, zmea, zpic, zsig, &
        zstd, zthe, zval, ale_bl, ale_bl_trig, alp_bl
   USE iostart, ONLY : close_startphy, get_field, get_var, open_startphy
@@ -794,7 +796,59 @@
            ENDDO
         ENDDO
-        PRINT*, 'Temperature du sol TKE**:', nsrf, xmin, xmax
-     ENDDO
-  ENDIF
+        PRINT*, 'Turbulent kinetic energyl TKE**:', nsrf, xmin, xmax
+     ENDDO
+  ENDIF
+
+! Lecture de l'ecart de TKE (w) - (x)
+!
+  IF (iflag_pbl>1 .AND. iflag_wake>=1  &
+           .AND. iflag_pbl_split >=1 ) then
+    DO nsrf = 1, nbsrf
+      IF (nsrf.GT.99) THEN
+        PRINT*, "Trop de sous-mailles"
+        call abort_gcm("phyetat0", "", 1)
+      ENDIF
+      WRITE(str2,'(i2.2)') nsrf
+      CALL get_field("DELTATKE"//str2, &
+                    wake_delta_pbl_tke(:,1:klev+1,nsrf),found)
+      IF (.NOT. found) THEN
+        PRINT*, "phyetat0: <DELTATKE"//str2//"> est absent"
+        wake_delta_pbl_tke(:,:,nsrf)=0.
+      ENDIF
+      xmin = 1.0E+20
+      xmax = -1.0E+20
+      DO k = 1, klev+1
+        DO i = 1, klon
+          xmin = MIN(wake_delta_pbl_tke(i,k,nsrf),xmin)
+          xmax = MAX(wake_delta_pbl_tke(i,k,nsrf),xmax)
+        ENDDO
+      ENDDO
+      PRINT*,'TKE difference (w)-(x) DELTATKE**:', nsrf, xmin, xmax
+    ENDDO
+
+  ! delta_tsurf
+
+    DO nsrf = 1, nbsrf
+       IF (nsrf.GT.99) THEN
+         PRINT*, "Trop de sous-mailles"
+         call abort_gcm("phyetat0", "", 1)
+       ENDIF
+       WRITE(str2,'(i2.2)') nsrf
+     CALL get_field("DELTA_TSURF"//str2, delta_tsurf(:,nsrf), found)
+     IF (.NOT. found) THEN
+        PRINT*, "phyetat0: Le champ <DELTA_TSURF"//str2//"> est absent"
+        PRINT*, "Depart legerement fausse. Mais je continue"
+        delta_tsurf(:,nsrf)=0.
+     ELSE
+        xmin = 1.0E+20
+        xmax = -1.0E+20
+         DO i = 1, klon
+            xmin = MIN(delta_tsurf(i, nsrf), xmin)
+            xmax = MAX(delta_tsurf(i, nsrf), xmax)
+         ENDDO
+        PRINT*, 'delta_tsurf:', xmin, xmax
+     ENDIF
+    ENDDO  ! nsrf = 1, nbsrf
+  ENDIF   !(iflag_pbl>1 .AND. iflag_wake>=1 .AND. iflag_pbl_split >=1 )
 
   ! zmax0
Index: /LMDZ5/trunk/libf/phylmd/phys_local_var_mod.F90
===================================================================
--- /LMDZ5/trunk/libf/phylmd/phys_local_var_mod.F90	(revision 2158)
+++ /LMDZ5/trunk/libf/phylmd/phys_local_var_mod.F90	(revision 2159)
@@ -41,4 +41,10 @@
       REAL, SAVE, ALLOCATABLE :: d_u_ajs(:,:), d_v_ajs(:,:)
       !$OMP THREADPRIVATE(d_u_ajs, d_v_ajs)
+!nrlmd<
+      REAL, SAVE, ALLOCATABLE :: d_t_ajs_w(:,:), d_q_ajs_w(:,:)
+      !$OMP THREADPRIVATE(d_t_ajs_w, d_q_ajs_w)
+      REAL, SAVE, ALLOCATABLE :: d_t_ajs_x(:,:), d_q_ajs_x(:,:)
+      !$OMP THREADPRIVATE(d_t_ajs_x, d_q_ajs_x)
+!>nrlmd
       REAL, SAVE, ALLOCATABLE :: d_t_eva(:,:),d_q_eva(:,:)
       !$OMP THREADPRIVATE(d_t_eva,d_q_eva)
@@ -58,4 +64,10 @@
       REAL, SAVE, ALLOCATABLE :: d_u_vdf(:,:), d_v_vdf(:,:)
       !$OMP THREADPRIVATE(d_u_vdf, d_v_vdf)
+!nrlmd+jyg<
+      REAL, SAVE, ALLOCATABLE :: d_t_vdf_w(:,:), d_q_vdf_w(:,:)
+      !$OMP THREADPRIVATE( d_t_vdf_w, d_q_vdf_w)
+      REAL, SAVE, ALLOCATABLE :: d_t_vdf_x(:,:), d_q_vdf_x(:,:)
+      !$OMP THREADPRIVATE( d_t_vdf_x, d_q_vdf_x)
+!>nrlmd+jyg
       REAL, SAVE, ALLOCATABLE :: d_t_oro(:,:)
       !$OMP THREADPRIVATE(d_t_oro)
@@ -216,5 +228,5 @@
 !$OMP THREADPRIVATE(toplwad0_aerop, sollwad0_aerop)
 
-!Ajout de celles nécessaires au phys_output_write_mod
+!Ajout de celles nÃ©cessaires au phys_output_write_mod
       REAL, SAVE, ALLOCATABLE :: slp(:)
 !$OMP THREADPRIVATE(slp)
@@ -237,4 +249,12 @@
       REAL,ALLOCATABLE,SAVE,DIMENSION(:) :: s_lcl, s_pblh, s_pblt, s_therm
 !$OMP THREADPRIVATE(s_lcl, s_pblh, s_pblt, s_therm)
+!
+!nrlmd+jyg<
+      REAL,ALLOCATABLE,SAVE,DIMENSION(:) :: s_pblh_x, s_pblh_w
+!$OMP THREADPRIVATE(s_pblh_x, s_pblh_w)
+      REAL,ALLOCATABLE,SAVE,DIMENSION(:) :: s_lcl_x, s_lcl_w
+!$OMP THREADPRIVATE(s_lcl_x, s_lcl_w)
+!>nrlmd+jyg
+!
       REAL,ALLOCATABLE,SAVE,DIMENSION(:) :: slab_wfbils
 !$OMP THREADPRIVATE(slab_wfbils)
@@ -247,4 +267,43 @@
       REAL,ALLOCATABLE,SAVE,DIMENSION(:) :: zxqsurf, rain_lsc
 !$OMP THREADPRIVATE(zxqsurf, rain_lsc)
+!
+!jyg+nrlmd<
+!!!ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
+!                                                                          c
+!       Declarations liees a la couche limite differentiee w-x             c
+!                                                                          c
+!!!ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
+      REAL,ALLOCATABLE,SAVE,DIMENSION(:) :: sens_x, sens_w
+!$OMP THREADPRIVATE(sens_x, sens_w)
+      REAL,ALLOCATABLE,SAVE,DIMENSION(:) :: zxfluxlat_x, zxfluxlat_w
+!$OMP THREADPRIVATE(zxfluxlat_x, zxfluxlat_w)
+! Entrées supplémentaires couche-limite
+      REAL,ALLOCATABLE,SAVE,DIMENSION(:,:) :: t_x, t_w
+!$OMP THREADPRIVATE(t_x, t_w)
+      REAL,ALLOCATABLE,SAVE,DIMENSION(:,:) :: q_x, q_w
+!$OMP THREADPRIVATE(q_x, q_w)
+! Sorties ferret
+      REAL,ALLOCATABLE,SAVE,DIMENSION(:,:) :: dtvdf_x, dtvdf_w
+!$OMP THREADPRIVATE(dtvdf_x, dtvdf_w)
+      REAL,ALLOCATABLE,SAVE,DIMENSION(:,:) :: dqvdf_x, dqvdf_w
+!$OMP THREADPRIVATE(dqvdf_x, dqvdf_w)
+      REAL,ALLOCATABLE,SAVE,DIMENSION(:,:) :: undi_tke, wake_tke
+!$OMP THREADPRIVATE(undi_tke, wake_tke)
+! Variables supplémentaires dans physiq.F relative au splitting de la surface
+      REAL,ALLOCATABLE,SAVE,DIMENSION(:,:,:) :: pbl_tke_input
+!$OMP THREADPRIVATE(pbl_tke_input)
+! Entree supplementaire Thermiques :
+      REAL,ALLOCATABLE,SAVE,DIMENSION(:,:) :: t_therm, q_therm
+!$OMP THREADPRIVATE(t_therm, q_therm)
+      REAL,ALLOCATABLE,SAVE,DIMENSION(:) :: cdragh_x, cdragh_w
+!$OMP THREADPRIVATE(cdragh_x, cdragh_w)
+      REAL,ALLOCATABLE,SAVE,DIMENSION(:) :: cdragm_x, cdragm_w
+!$OMP THREADPRIVATE(cdragm_x, cdragm_w)
+      REAL,ALLOCATABLE,SAVE,DIMENSION(:) :: kh, kh_x, kh_w
+!$OMP THREADPRIVATE(kh, kh_x, kh_w)
+!!!
+!!!ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
+!>jyg+nrlmd
+  !
       REAL,ALLOCATABLE,SAVE,DIMENSION(:) :: wake_h, wbeff, zmax_th, zq2m, zt2m
 !$OMP THREADPRIVATE(wake_h, wbeff, zmax_th, zq2m, zt2m)
@@ -335,4 +394,8 @@
       allocate(d_t_ajsb(klon,klev),d_q_ajsb(klon,klev))
       allocate(d_t_ajs(klon,klev),d_q_ajs(klon,klev))
+!nrlmd<
+      allocate(d_t_ajs_w(klon,klev),d_q_ajs_w(klon,klev))
+      allocate(d_t_ajs_x(klon,klev),d_q_ajs_x(klon,klev))
+!>nrlmd
       allocate(d_u_ajs(klon,klev),d_v_ajs(klon,klev))
       allocate(d_t_eva(klon,klev),d_q_eva(klon,klev))
@@ -341,4 +404,8 @@
       allocate(plul_st(klon),plul_th(klon))
       allocate(d_t_vdf(klon,klev),d_q_vdf(klon,klev),d_t_diss(klon,klev))
+!nrlmd+jyg<
+      allocate(d_t_vdf_w(klon,klev),d_q_vdf_w(klon,klev))
+      allocate(d_t_vdf_x(klon,klev),d_q_vdf_x(klon,klev))
+!>nrlmd+jyg
       allocate(d_u_vdf(klon,klev),d_v_vdf(klon,klev))
       allocate(d_t_oli(klon,klev),d_t_oro(klon,klev))
@@ -380,9 +447,9 @@
       allocate(lcc3dcon(klon, klev))
       allocate(lcc3dstra(klon, klev))
-      allocate(od550aer(klon))	 
-      allocate(od865aer(klon))	 
-      allocate(absvisaer(klon))	 
+      allocate(od550aer(klon))
+      allocate(od865aer(klon))
+      allocate(absvisaer(klon))
       allocate(ec550aer(klon,klev))
-      allocate(od550lt1aer(klon))	 	 
+      allocate(od550lt1aer(klon))
       allocate(sconcso4(klon))
       allocate(sconcno3(klon))
@@ -423,5 +490,5 @@
       ALLOCATE(toplwad0_aerop(klon), sollwad0_aerop(klon))
 
-! FH Ajout de celles nécessaires au phys_output_write_mod
+! FH Ajout de celles nÃ©cessaires au phys_output_write_mod
 
       ALLOCATE(slp(klon))
@@ -435,9 +502,30 @@
       ALLOCATE(s_lcl(klon))
       ALLOCATE(s_pblh(klon), s_pblt(klon), s_therm(klon))
+!
+!nrlmd+jyg<
+      ALLOCATE(s_pblh_x(klon), s_pblh_w(klon))
+      ALLOCATE(s_lcl_x(klon), s_lcl_w(klon))
+!>nrlmd+jyg
+!
       ALLOCATE(slab_wfbils(klon), tpot(klon), tpote(klon), ue(klon))
       ALLOCATE(uq(klon), ve(klon), vq(klon), zxffonte(klon))
       ALLOCATE(zxfqcalving(klon), zxfluxlat(klon), zxrugs(klon))
       ALLOCATE(zxtsol(klon), snow_lsc(klon), zxfqfonte(klon), zxqsurf(klon))
-      ALLOCATE(rain_lsc(klon), wake_h(klon), wbeff(klon), zmax_th(klon))
+      ALLOCATE(rain_lsc(klon))
+!
+      ALLOCATE(sens_x(klon), sens_w(klon))
+      ALLOCATE(zxfluxlat_x(klon), zxfluxlat_w(klon))
+      ALLOCATE(t_x(klon,klev), t_w(klon,klev))
+      ALLOCATE(q_x(klon,klev), q_w(klon,klev))
+      ALLOCATE(dtvdf_x(klon,klev), dtvdf_w(klon,klev))
+      ALLOCATE(dqvdf_x(klon,klev), dqvdf_w(klon,klev))
+      ALLOCATE(undi_tke(klon,klev), wake_tke(klon,klev))
+      ALLOCATE(pbl_tke_input(klon,klev+1,nbsrf))
+      ALLOCATE(t_therm(klon,klev), q_therm(klon,klev))
+      ALLOCATE(cdragh_x(klon), cdragh_w(klon))
+      ALLOCATE(cdragm_x(klon), cdragm_w(klon))
+      ALLOCATE(kh(klon), kh_x(klon), kh_w(klon))
+!
+      ALLOCATE(wake_h(klon), wbeff(klon), zmax_th(klon))
       ALLOCATE(zq2m(klon), zt2m(klon), weak_inversion(klon))
       ALLOCATE(zt2m_min_mon(klon), zt2m_max_mon(klon))
@@ -510,4 +598,8 @@
       deallocate(d_t_ajsb,d_q_ajsb)
       deallocate(d_t_ajs,d_q_ajs)
+!nrlmd<
+      deallocate(d_t_ajs_w,d_q_ajs_w)
+      deallocate(d_t_ajs_x,d_q_ajs_x)
+!>nrlmd
       deallocate(d_u_ajs,d_v_ajs)
       deallocate(d_t_eva,d_q_eva)
@@ -516,4 +608,8 @@
       deallocate(plul_st,plul_th)
       deallocate(d_t_vdf,d_q_vdf,d_t_diss)
+!nrlmd+jyg<
+      deallocate(d_t_vdf_w,d_q_vdf_w)
+      deallocate(d_t_vdf_x,d_q_vdf_x)
+!>nrlmd+jyg
       deallocate(d_u_vdf,d_v_vdf)
       deallocate(d_t_oli,d_t_oro)
@@ -546,5 +642,5 @@
       deallocate(lcc3dcon)
       deallocate(lcc3dstra)
-      deallocate(od550aer)	 
+      deallocate(od550aer)
       deallocate(od865aer)
       deallocate(absvisaer)
@@ -591,5 +687,5 @@
       deallocate(toplwad0_aerop, sollwad0_aerop)
 
-! FH Ajout de celles nécessaires au phys_output_write_mod
+! FH Ajout de celles nÃ©cessaires au phys_output_write_mod
       DEALLOCATE(slp)
       DEALLOCATE(ale_wake, alp_wake, bils)
@@ -600,9 +696,30 @@
       DEALLOCATE(prw, zustar, zu10m, zv10m, rh2m, s_lcl)
       DEALLOCATE(s_pblh, s_pblt, s_therm)
+!
+!nrlmd+jyg<
+      DEALLOCATE(s_pblh_x, s_pblh_w)
+      DEALLOCATE(s_lcl_x, s_lcl_w)
+!>nrlmd+jyg
+!
       DEALLOCATE(slab_wfbils, tpot, tpote, ue)
       DEALLOCATE(uq, ve, vq, zxffonte)
       DEALLOCATE(zxfqcalving, zxfluxlat, zxrugs)
       DEALLOCATE(zxtsol, snow_lsc, zxfqfonte, zxqsurf)
-      DEALLOCATE(rain_lsc, wake_h, wbeff, zmax_th)
+      DEALLOCATE(rain_lsc)
+!
+      DEALLOCATE(sens_x, sens_w)
+      DEALLOCATE(zxfluxlat_x, zxfluxlat_w)
+      DEALLOCATE(t_x, t_w)
+      DEALLOCATE(q_x, q_w)
+      DEALLOCATE(dtvdf_x, dtvdf_w)
+      DEALLOCATE(dqvdf_x, dqvdf_w)
+      DEALLOCATE(undi_tke, wake_tke)
+      DEALLOCATE(pbl_tke_input)
+      DEALLOCATE(t_therm, q_therm)
+      DEALLOCATE(cdragh_x, cdragh_w)
+      DEALLOCATE(cdragm_x, cdragm_w)
+      DEALLOCATE(kh, kh_x, kh_w)
+!
+      DEALLOCATE(wake_h, wbeff, zmax_th)
       DEALLOCATE(zq2m, zt2m, weak_inversion)
       DEALLOCATE(zt2m_min_mon, zt2m_max_mon)
Index: /LMDZ5/trunk/libf/phylmd/phys_output_ctrlout_mod.F90
===================================================================
--- /LMDZ5/trunk/libf/phylmd/phys_output_ctrlout_mod.F90	(revision 2158)
+++ /LMDZ5/trunk/libf/phylmd/phys_output_ctrlout_mod.F90	(revision 2159)
@@ -477,4 +477,42 @@
   TYPE(ctrl_out), SAVE :: o_alp_wk = ctrl_out((/ 1, 1, 1, 10, 10, 10, 11, 11, 11 /), &
     'alp_wk', 'ALP WK', 'm2/s2', (/ ('', i=1, 9) /))
+!!!
+!nrlmd+jyg<
+  type(ctrl_out),save :: o_dtvdf_x        = ctrl_out((/ 1, 1, 1, 10, 10, 10, 11, 11, 11 /), &
+    'dtvdf_x', ' dtvdf off_wake','K/s', (/ ('', i=1, 9) /))
+  type(ctrl_out),save :: o_dtvdf_w        = ctrl_out((/ 1, 1, 1, 10, 10, 10, 11, 11, 11 /), &
+    'dtvdf_w', ' dtvdf within_wake','K/s', (/ ('', i=1, 9) /))
+  type(ctrl_out),save :: o_dqvdf_x        = ctrl_out((/ 1, 1, 1, 10, 10, 10, 11, 11, 11 /), &
+    'dqvdf_x', ' dqvdf off_wake','kg/kg/s', (/ ('', i=1, 9) /))
+  type(ctrl_out),save :: o_dqvdf_w        = ctrl_out((/ 1, 1, 1, 10, 10, 10, 11, 11, 11 /), &
+    'dqvdf_w', ' dqvdf within_wake','kg/kg/s', (/ ('', i=1, 9) /))
+!!
+  type(ctrl_out),save :: o_sens_x        = ctrl_out((/ 1, 10, 10, 10, 10, 10, 11, 11, 11 /), &
+'sens_x', 'ALP WK', 'm2/s2', (/ ('', i=1, 9) /))
+  type(ctrl_out),save :: o_sens_w        = ctrl_out((/ 1, 10, 10, 10, 10, 10, 11, 11, 11 /), &
+'sens_w', 'ALP WK', 'm2/s2', (/ ('', i=1, 9) /))                                                                                   
+  type(ctrl_out),save :: o_flat_x        = ctrl_out((/ 1, 10, 10, 10, 10, 10, 11, 11, 11 /), &
+'flat_x', 'ALP WK', 'm2/s2', (/ ('', i=1, 9) /))                                                                                   
+  type(ctrl_out),save :: o_flat_w        = ctrl_out((/ 1, 10, 10, 10, 10, 10, 11, 11, 11 /), &
+'flat_w', 'ALP WK', 'm2/s2', (/ ('', i=1, 9) /))
+!!
+  type(ctrl_out),save :: o_delta_tsurf    = ctrl_out((/ 1, 10, 10, 10, 10, 10, 11, 11, 11 /), &
+'delta_tsurf', 'Temperature difference (w-x)', 'K', (/ ('', i=1, 9) /))                                                                               
+  type(ctrl_out),save :: o_cdragh_x       = ctrl_out((/ 1, 10, 10, 10, 10, 10, 11, 11, 11 /), &
+'cdragh_x', 'cdragh off-wake', '', (/ ('', i=1, 9) /))
+  type(ctrl_out),save :: o_cdragh_w       = ctrl_out((/ 1, 10, 10, 10, 10, 10, 11, 11, 11 /), &
+'cdragh_w', 'cdragh within-wake', '', (/ ('', i=1, 9) /))                                                                                  
+  type(ctrl_out),save :: o_cdragm_x       = ctrl_out((/ 1, 10, 10, 10, 10, 10, 11, 11, 11 /), &
+'cdragm_x', 'cdragm off-wake', '', (/ ('', i=1, 9) /))
+  type(ctrl_out),save :: o_cdragm_w       = ctrl_out((/ 1, 10, 10, 10, 10, 10, 11, 11, 11 /), &
+'cdragm_w', 'cdrgam within-wake', '', (/ ('', i=1, 9) /))                                                                                  
+  type(ctrl_out),save :: o_kh             = ctrl_out((/ 1, 10, 10, 10, 10, 10, 11, 11, 11 /), &
+'kh', 'Kh', 'kg/s/m2', (/ ('', i=1, 9) /))                                                                                        
+  type(ctrl_out),save :: o_kh_x           = ctrl_out((/ 1, 10, 10, 10, 10, 10, 11, 11, 11 /), &
+'kh_x', 'Kh off-wake', 'kg/s/m2', (/ ('', i=1, 9) /))                                                                                      
+  type(ctrl_out),save :: o_kh_w           = ctrl_out((/ 1, 10, 10, 10, 10, 10, 11, 11, 11 /), &
+'kh_w', 'Kh within-wake', 'kg/s/m2', (/ ('', i=1, 9) /))
+!>nrlmd+jyg
+!!!
   TYPE(ctrl_out), SAVE :: o_ale = ctrl_out((/ 1, 1, 1, 10, 10, 10, 11, 11, 11 /), &
     'ale', 'ALE', 'm2/s2', (/ ('', i=1, 9) /))
@@ -693,4 +731,14 @@
       (/ "t_max(X)", "t_max(X)", "t_max(X)", "t_max(X)", "t_max(X)", &
          "t_max(X)", "t_max(X)", "t_max(X)", "t_max(X)" /)) /)
+
+  TYPE(ctrl_out), SAVE, DIMENSION(4) :: o_dltpbltke_srf      = (/             &
+      ctrl_out((/ 10, 4, 10, 10, 10, 10, 11, 11, 11 /),'dltpbltke_ter',       &
+      "TKE difference (w - x) "//clnsurf(1),"-", (/ ('', i=1, 9) /)), &
+      ctrl_out((/ 10, 4, 10, 10, 10, 10, 11, 11, 11 /),'dltpbltke_lic',       &
+      "TKE difference (w - x) "//clnsurf(2),"-", (/ ('', i=1, 9) /)), &
+      ctrl_out((/ 10, 4, 10, 10, 10, 10, 11, 11, 11 /),'dltpbltke_oce',       &
+      "TKE difference (w - x) "//clnsurf(3),"-", (/ ('', i=1, 9) /)), &
+      ctrl_out((/ 10, 4, 10, 10, 10, 10, 11, 11, 11 /),'dltpbltke_sic',       &
+      "TKE difference (w - x) "//clnsurf(4),"-", (/ ('', i=1, 9) /)) /)
 
   TYPE(ctrl_out), SAVE :: o_kz = ctrl_out((/ 4, 10, 10, 10, 10, 10, 11, 11, 11 /), &
Index: /LMDZ5/trunk/libf/phylmd/phys_output_mod.F90
===================================================================
--- /LMDZ5/trunk/libf/phylmd/phys_output_mod.F90	(revision 2158)
+++ /LMDZ5/trunk/libf/phylmd/phys_output_mod.F90	(revision 2159)
@@ -27,5 +27,5 @@
   SUBROUTINE phys_output_open(rlon,rlat,pim,tabij,ipt,jpt,plon,plat, &
        jjmp1,nlevSTD,clevSTD,rlevSTD, dtime, ok_veget, &
-       type_ocean, iflag_pbl,ok_mensuel,ok_journe, &
+       type_ocean, iflag_pbl,iflag_pbl_split,ok_mensuel,ok_journe, &
        ok_hf,ok_instan,ok_LES,ok_ade,ok_aie, read_climoz, &
        phys_out_filestations, &
@@ -102,4 +102,5 @@
     LOGICAL                               :: ok_veget
     INTEGER                               :: iflag_pbl
+    INTEGER                               :: iflag_pbl_split
     CHARACTER(LEN=4)                      :: bb2
     CHARACTER(LEN=2)                      :: bb3
Index: /LMDZ5/trunk/libf/phylmd/phys_output_write_mod.F90
===================================================================
--- /LMDZ5/trunk/libf/phylmd/phys_output_write_mod.F90	(revision 2158)
+++ /LMDZ5/trunk/libf/phylmd/phys_output_write_mod.F90	(revision 2159)
@@ -57,5 +57,5 @@
          o_sens_srf, o_lat_srf, o_flw_srf, &
          o_fsw_srf, o_wbils_srf, o_wbilo_srf, &
-         o_tke_srf, o_tke_max_srf, o_wstar, &
+         o_tke_srf, o_tke_max_srf,o_dltpbltke_srf, o_wstar, &
          o_cdrm, o_cdrh, o_cldl, o_cldm, o_cldh, &
          o_cldt, o_JrNt, o_cldljn, o_cldmjn, &
@@ -160,5 +160,6 @@
          radsol, sollw0, sollwdown, sollw, &
          sollwdownclr, lwdn0, ftsol, ustar, u10m, &
-         v10m, pbl_tke, wstar, cape, ema_pcb, ema_pct, &
+         v10m, pbl_tke, wake_delta_pbl_TKE, &
+         wstar, cape, ema_pcb, ema_pct, &
          ema_cbmf, Ma, fm_therm, ale_bl, alp_bl, ale, &
          alp, cin, wake_pe, wake_s, wake_deltat, &
@@ -561,4 +562,9 @@
              CALL histwrite_phy(o_tke_max_srf(nsrf),  pbl_tke(:,1:klev,nsrf))
           ENDIF
+!jyg<
+          IF (iflag_pbl > 1) THEN
+             CALL histwrite_phy(o_dltpbltke_srf(nsrf), wake_delta_pbl_TKE(:,1:klev,nsrf))
+          ENDIF
+!>jyg
 
        ENDDO
Index: /LMDZ5/trunk/libf/phylmd/phys_state_var_mod.F90
===================================================================
--- /LMDZ5/trunk/libf/phylmd/phys_state_var_mod.F90	(revision 2158)
+++ /LMDZ5/trunk/libf/phylmd/phys_state_var_mod.F90	(revision 2159)
@@ -66,4 +66,8 @@
       REAL, ALLOCATABLE, SAVE :: coefm(:,:,:) ! Kz momentum
 !$OMP THREADPRIVATE(pbl_tke, coefh,coefm)
+!nrlmd<
+      REAL, ALLOCATABLE, SAVE :: delta_tsurf(:,:) ! Surface temperature difference inside-outside cold pool
+!$OMP THREADPRIVATE(delta_tsurf)
+!>nrlmd
       REAL, ALLOCATABLE, SAVE :: zmax0(:), f0(:) ! 
 !$OMP THREADPRIVATE(zmax0,f0)
@@ -230,4 +234,12 @@
 !$OMP THREADPRIVATE(dq_wake)
 !
+!jyg<
+! variables related to the spitting of the PBL between wake and 
+! off-wake regions.
+! wake_delta_pbl_TKE : difference TKE_w - TKE_x
+      REAL,ALLOCATABLE,SAVE :: wake_delta_pbl_TKE(:,:,:)
+!$OMP THREADPRIVATE(wake_delta_pbl_TKE)
+!>jyg
+!
 ! pfrac_impa : Produits des coefs lessivage impaction
 ! pfrac_nucl : Produits des coefs lessivage nucleation
@@ -406,4 +418,7 @@
       ALLOCATE(ratqs(klon,klev))
       ALLOCATE(pbl_tke(klon,klev+1,nbsrf+1))
+!nrlmd<
+      ALLOCATE(delta_tsurf(klon,nbsrf))
+!>nrlmd
       ALLOCATE(coefh(klon,klev+1,nbsrf+1))
       ALLOCATE(coefm(klon,klev+1,nbsrf+1))
@@ -475,4 +490,7 @@
       ALLOCATE(wake_pe(klon), wake_fip(klon))
       ALLOCATE(dt_wake(klon,klev), dq_wake(klon,klev))
+!jyg<
+      ALLOCATE(wake_delta_pbl_TKE(klon,klev+1,nbsrf))
+!>jyg
       ALLOCATE(pfrac_impa(klon,klev), pfrac_nucl(klon,klev))
       ALLOCATE(pfrac_1nucl(klon,klev))
@@ -551,4 +569,7 @@
       deallocate(        tr_ancien)                           !RomP
       deallocate(ratqs, pbl_tke,coefh,coefm)
+!nrlmd<
+      deallocate(delta_tsurf)
+!>nrlmd
       deallocate(zmax0, f0)
       deallocate(sig1, w01)
@@ -601,4 +622,7 @@
       deallocate(wake_Cstar, wake_s, wake_pe, wake_fip)
       deallocate(dt_wake, dq_wake)
+!jyg<
+      deallocate(wake_delta_pbl_TKE)
+!>jyg
       deallocate(pfrac_impa, pfrac_nucl)
       deallocate(pfrac_1nucl)
Index: /LMDZ5/trunk/libf/phylmd/physiq.F90
===================================================================
--- /LMDZ5/trunk/libf/phylmd/physiq.F90	(revision 2158)
+++ /LMDZ5/trunk/libf/phylmd/physiq.F90	(revision 2159)
@@ -371,6 +371,7 @@
   REAL q_undi(klon,klev)               ! humidite moyenne dans la zone non perturbee
   !
-  !jyg
+  !jyg<
   !cc      REAL wake_pe(klon)              ! Wake potential energy - WAPE 
+  !>jyg
 
   REAL wake_gfl(klon)             ! Gust Front Length
@@ -392,4 +393,12 @@
   !$OMP THREADPRIVATE(alp_offset)
 
+!!!
+!=================================================================
+!         PROVISOIRE : DECOUPLAGE PBL/WAKE
+!         --------------------------------
+      REAL wake_deltat_sav(klon,klev)
+      REAL wake_deltaq_sav(klon,klev)
+!=================================================================
+
   !
   !RR:fin declarations poches froides
@@ -409,5 +418,5 @@
   real w0(klon)                                          ! Vitesse des thermiques au LCL
   real w_conv(klon)                                      ! Vitesse verticale de grande \'echelle au LCL
-  real tke0(klon,klev+1)                                 ! TKE au début du pas de temps
+  real tke0(klon,klev+1)                                 ! TKE au dÃ©but du pas de temps
   real therm_tke_max0(klon)                              ! TKE dans les thermiques au LCL 
   real env_tke_max0(klon)                                ! TKE dans l'environnement au LCL 
@@ -418,5 +427,4 @@
   !--------Statistical Boundary Layer Closure: ALP_BL--------
   !---Profils de TKE dans et hors du thermique
-  real pbl_tke_input(klon,klev+1,nbsrf)
   real therm_tke_max(klon,klev)                          ! Profil de TKE dans les thermiques
   real env_tke_max(klon,klev)                            ! Profil de TKE dans l'environnement
@@ -1239,5 +1247,5 @@
           iGCM,jGCM,lonGCM,latGCM, &
           jjmp1,nlevSTD,clevSTD,rlevSTD, dtime,ok_veget, &
-          type_ocean,iflag_pbl,ok_mensuel,ok_journe, &
+          type_ocean,iflag_pbl,iflag_pbl_split,ok_mensuel,ok_journe, &
           ok_hf,ok_instan,ok_LES,ok_ade,ok_aie,  &
           read_climoz, phys_out_filestations, &
@@ -1651,5 +1659,5 @@
         else
 
-!CR: on ré-évapore eau liquide et glace
+!CR: on rÃ©-Ã©vapore eau liquide et glace
 
 !        zdelta = MAX(0.,SIGN(1.,RTT-t_seri(i,k)))
@@ -1663,5 +1671,5 @@
         q_seri(i,k) = q_seri(i,k) + zb
         ql_seri(i,k) = 0.0
-!on évapore la glace
+!on Ã©vapore la glace
         qs_seri(i,k) = 0.0
         d_t_eva(i,k) = za
@@ -1774,4 +1782,20 @@
   if (iflag_pbl/=0) then
 
+!jyg+nrlmd<
+      IF (prt_level .ge. 2 .and. mod(iflag_pbl_split,2) .eq. 1) THEN
+        print *,'debut du splitting de la PBL'
+      ENDIF
+!!!
+!=================================================================
+!         PROVISOIRE : DECOUPLAGE PBL/WAKE
+!         --------------------------------
+!
+!!      wake_deltat_sav(:,:)=wake_deltat(:,:)
+!!      wake_deltaq_sav(:,:)=wake_deltaq(:,:)
+!!      wake_deltat(:,:)=0.
+!!      wake_deltaq(:,:)=0.
+!=================================================================
+!>jyg+nrlmd
+!
      CALL pbl_surface(  &
           dtime,     date0,     itap,    days_elapsed+1, &
@@ -1781,4 +1805,7 @@
           rain_fall, snow_fall, solsw,   sollw,     &
           t_seri,    q_seri,    u_seri,  v_seri,    &
+!nrlmd+jyg<
+          wake_deltat, wake_deltaq, wake_cstar, wake_s, &
+!>nrlmd+jyg
           pplay,     paprs,     pctsrf,             &
           ftsol,falb1,falb2,ustar,u10m,v10m,wstar, &
@@ -1788,7 +1815,20 @@
           zxtsol,    zxfluxlat, zt2m,    qsat2m,  &
           d_t_vdf,   d_q_vdf,   d_u_vdf, d_v_vdf, d_t_diss, &
+!nrlmd<
+  !jyg<
+          d_t_vdf_w, d_q_vdf_w, &
+          d_t_vdf_x, d_q_vdf_x, &
+          sens_x, zxfluxlat_x, sens_w, zxfluxlat_w, &
+  !>jyg
+          delta_tsurf,wake_dens, &
+          cdragh_x,cdragh_w,cdragm_x,cdragm_w, &
+          kh,kh_x,kh_w, &
+!>nrlmd
           coefh(1:klon,1:klev,1:nbsrf+1),     coefm(1:klon,1:klev,1:nbsrf+1), &
           slab_wfbils,                 &
           qsol,      zq2m,      s_pblh,  s_lcl, &
+!jyg<
+          s_pblh_x, s_lcl_x, s_pblh_w, s_lcl_w, &
+!>jyg
           s_capCL,   s_oliqCL,  s_cteiCL,s_pblT, &
           s_therm,   s_trmb1,   s_trmb2, s_trmb3, &
@@ -1799,5 +1839,21 @@
           wfbils,    wfbilo,    fluxt,   fluxu,  fluxv, &
           dsens,     devap,     zxsnow, &
-          zxfluxt,   zxfluxq,   q2m,     fluxq, pbl_tke )
+          zxfluxt,   zxfluxq,   q2m,     fluxq, pbl_tke, &
+!nrlmd+jyg<
+          wake_delta_pbl_TKE &
+!>nrlmd+jyg
+                      )
+!
+!=================================================================
+!         PROVISOIRE : DECOUPLAGE PBL/WAKE
+!         --------------------------------
+!
+!!      wake_deltat(:,:)=wake_deltat_sav(:,:)
+!!      wake_deltaq(:,:)=wake_deltaq_sav(:,:)
+!=================================================================
+!
+!  Add turbulent diffusion tendency to the wake difference variables
+    wake_deltat(:,:) = wake_deltat(:,:) + (d_t_vdf_w(:,:)-d_t_vdf_x(:,:))
+    wake_deltaq(:,:) = wake_deltaq(:,:) + (d_q_vdf_w(:,:)-d_q_vdf_x(:,:))
 
 
@@ -2270,19 +2326,56 @@
   !pour la couche limite diffuse pour l instant
   !
+  !
+  !!! nrlmd le 22/03/2011---Si on met les poches hors des thermiques il faut rajouter cette
+  !------------------------- tendance calculée hors des poches froides
+  !
   if (iflag_wake>=1) then
      DO k=1,klev
         DO i=1,klon
            dt_dwn(i,k)  = ftd(i,k) 
-           wdt_PBL(i,k) = 0.
            dq_dwn(i,k)  = fqd(i,k) 
-           wdq_PBL(i,k) = 0.
            M_dwn(i,k)   = dnwd0(i,k)
            M_up(i,k)    = upwd(i,k)
            dt_a(i,k)    = d_t_con(i,k)/dtime - ftd(i,k) 
-           udt_PBL(i,k) = 0.
            dq_a(i,k)    = d_q_con(i,k)/dtime - fqd(i,k)
-           udq_PBL(i,k) = 0.
         ENDDO
      ENDDO
+!nrlmd+jyg<
+     DO k=1,klev
+        DO i=1,klon
+          wdt_PBL(i,k) =  0.
+          wdq_PBL(i,k) =  0.
+          udt_PBL(i,k) =  0.
+          udq_PBL(i,k) =  0.
+        ENDDO
+     ENDDO
+!
+     IF (mod(iflag_pbl_split,2) .EQ. 1) THEN
+       DO k=1,klev
+        DO i=1,klon
+       wdt_PBL(i,k) = wdt_PBL(i,k) + d_t_vdf_w(i,k)/dtime
+       wdq_PBL(i,k) = wdq_PBL(i,k) + d_q_vdf_w(i,k)/dtime
+       udt_PBL(i,k) = udt_PBL(i,k) + d_t_vdf_x(i,k)/dtime
+       udq_PBL(i,k) = udq_PBL(i,k) + d_q_vdf_x(i,k)/dtime
+!!        dt_dwn(i,k)  = dt_dwn(i,k) + d_t_vdf_w(i,k)/dtime
+!!        dq_dwn(i,k)  = dq_dwn(i,k) + d_q_vdf_w(i,k)/dtime
+!!        dt_a  (i,k)    = dt_a(i,k) + d_t_vdf_x(i,k)/dtime
+!!        dq_a  (i,k)    = dq_a(i,k) + d_q_vdf_x(i,k)/dtime
+        ENDDO
+       ENDDO
+      ENDIF
+      IF (mod(iflag_pbl_split/2,2) .EQ. 1) THEN
+       DO k=1,klev
+        DO i=1,klon
+!!        dt_dwn(i,k)  = dt_dwn(i,k) + 0.
+!!        dq_dwn(i,k)  = dq_dwn(i,k) + 0.
+!!        dt_a(i,k)   = dt_a(i,k)   + d_t_ajs(i,k)/dtime
+!!        dq_a(i,k)   = dq_a(i,k)   + d_q_ajs(i,k)/dtime
+        udt_PBL(i,k)   = udt_PBL(i,k)   + d_t_ajs(i,k)/dtime
+        udq_PBL(i,k)   = udq_PBL(i,k)   + d_q_ajs(i,k)/dtime
+        ENDDO
+       ENDDO
+      ENDIF
+!>nrlmd+jyg
 
      IF (iflag_wake==2) THEN
@@ -2299,5 +2392,5 @@
            DO i=1,klon
               IF (rneb(i,k)==0.) THEN
-! On ne tient compte des tendances qu'en dehors des nuages (c'est �|  dire
+! On ne tient compte des tendances qu'en dehors des nuages (c'est ï¿½|  dire
 ! a priri dans une region ou l'eau se reevapore).
                 dt_dwn(i,k)= dt_dwn(i,k)+ &
@@ -2339,5 +2432,5 @@
      !------------------------------------------------------------------------
 
-  endif
+  endif  ! (iflag_wake>=1)
   !
   !===================================================================
@@ -2407,7 +2500,27 @@
 
      if (iflag_thermals>=1) then
+!jyg<
+         IF (mod(iflag_pbl_split/2,2) .EQ. 1) THEN
+!  Appel des thermiques avec les profils exterieurs aux poches
+          DO k=1,klev
+           DO i=1,klon
+            t_therm(i,k) = t_seri(i,k) - wake_s(i)*wake_deltat(i,k)
+            q_therm(i,k) = q_seri(i,k) - wake_s(i)*wake_deltaq(i,k)
+           ENDDO
+          ENDDO
+         ELSE
+!  Appel des thermiques avec les profils moyens
+          DO k=1,klev
+           DO i=1,klon
+            t_therm(i,k) = t_seri(i,k)
+            q_therm(i,k) = q_seri(i,k)
+           ENDDO
+          ENDDO
+         ENDIF
+!>jyg
         call calltherm(pdtphys &
              ,pplay,paprs,pphi,weak_inversion &
-             ,u_seri,v_seri,t_seri,q_seri,zqsat,debut &
+!!             ,u_seri,v_seri,t_seri,q_seri,zqsat,debut &  !jyg
+             ,u_seri,v_seri,t_therm,q_therm,zqsat,debut &  !jyg
              ,d_u_ajs,d_v_ajs,d_t_ajs,d_q_ajs &
              ,fm_therm,entr_therm,detr_therm &
@@ -2426,4 +2539,33 @@
              !cc fin nrlmd le 10/04/2012
              ,zqla,ztva )
+!
+!jyg<
+         IF (mod(iflag_pbl_split/2,2) .EQ. 1) THEN
+!  Si les thermiques ne sont presents que hors des poches, la tendance moyenne
+!  associée doit etre multipliee par la fraction surfacique qu'ils couvrent.
+          DO k=1,klev
+           DO i=1,klon
+!
+            wake_deltat(i,k) = wake_deltat(i,k) - d_t_ajs(i,k)
+            wake_deltaq(i,k) = wake_deltaq(i,k) - d_q_ajs(i,k)
+            t_seri(i,k) = t_therm(i,k) + wake_s(i)*wake_deltat(i,k)
+            q_seri(i,k) = q_therm(i,k) + wake_s(i)*wake_deltaq(i,k)
+!
+            d_u_ajs(i,k) = d_u_ajs(i,k)*(1.-wake_s(i)) 
+            d_v_ajs(i,k) = d_v_ajs(i,k)*(1.-wake_s(i)) 
+            d_t_ajs(i,k) = d_t_ajs(i,k)*(1.-wake_s(i)) 
+            d_q_ajs(i,k) = d_q_ajs(i,k)*(1.-wake_s(i)) 
+!
+           ENDDO
+          ENDDO
+         ELSE
+          DO k=1,klev
+           DO i=1,klon
+            t_seri(i,k) = t_therm(i,k)
+            q_seri(i,k) = q_therm(i,k)
+           ENDDO
+          ENDDO
+         ENDIF
+!>jyg
 
         !cc nrlmd le 10/04/2012
@@ -2545,5 +2687,7 @@
         ! Couplage Thermiques/Emanuel seulement si T<0
         if (iflag_coupl==2) then
+         IF (prt_level .GE. 10) THEN
            print*,'Couplage Thermiques/Emanuel seulement si T<0'
+         ENDIF
            do i=1,klon
               if (t_seri(i,lmax_th(i))>273.) then
@@ -2637,7 +2781,7 @@
   !-------------------------------------------------------------------------
   IF (prt_level .GE.10) THEN
-     print *,' ->fisrtilp '
+     print *,'itap, ->fisrtilp ',itap
   ENDIF
-  !-------------------------------------------------------------------------
+  !
   CALL fisrtilp(dtime,paprs,pplay, &
        t_seri, q_seri,ptconv,ratqs, &
@@ -2649,5 +2793,5 @@
        zqasc, fraca,ztv,zpspsk,ztla,zthl,iflag_cldcon, &
        iflag_ice_thermo)
-
+  !
   WHERE (rain_lsc < 0) rain_lsc = 0.
   WHERE (snow_lsc < 0) snow_lsc = 0.
@@ -2808,5 +2952,7 @@
      !--updates tausum_aero,tau_aero,piz_aero,cg_aero
      IF (flag_aerosol_strat) THEN
-        PRINT *,'appel a readaerosolstrat', mth_cur
+        IF (prt_level .GE.10) THEN
+         PRINT *,'appel a readaerosolstrat', mth_cur
+        ENDIF
         IF (iflag_rrtm.EQ.0) THEN
            CALL readaerosolstrato(debut)
@@ -3529,5 +3675,7 @@
      IF (itap.eq.1.or.MOD(itap,NINT(freq_cosp/dtime)).EQ.0) THEN
 
+      IF (prt_level .GE.10) THEN
         print*,'freq_cosp',freq_cosp
+      ENDIF
         mr_ozone=wo(:, :, 1) * dobson_u * 1e3 / zmasse
         !       print*,'Dans physiq.F avant appel cosp ref_liq,ref_ice=',
Index: /LMDZ5/trunk/libf/phylmd/thermcell_plume.F90
===================================================================
--- /LMDZ5/trunk/libf/phylmd/thermcell_plume.F90	(revision 2158)
+++ /LMDZ5/trunk/libf/phylmd/thermcell_plume.F90	(revision 2159)
@@ -1160,5 +1160,5 @@
            linter(ig)=(l*(f_star(ig,l+1)-f_star(ig,l))  &
      &               -f_star(ig,l))/(f_star(ig,l+1)-f_star(ig,l))
-           print*,"linter plume", linter(ig)
+!           print*,"linter plume", linter(ig)
            zw2(ig,l+1)=0.
         endif
