SUBROUTINE CUASCN2TL &
 & ( KIDIA,    KFDIA,    KLON,   KLEV,&
 & PTEN5,    PTENH5,   PQENH5,&
 & PGEOH5,   PQEN5,    PQSEN5,&
 & PAPH5,    PLGLAC5,  PQPRCV5,&
 & PBUOH5,   PWUBASE5, LDCUM,    KTYPE,&
 & PTU5,     PQU5,     PLU5,&
 & PMFU5,    PMFUB5,&
 & PMFUS5,   PMFUQ5,   PMFUL5,   PLUDE5,   PDMFUP5,&
 & KCBOT,    KCTOP,    KSTUP,&
 & PMFUDE_RATE5, PWMEAN5, PERATEU5,&
 & PTEN,     PTENH,    PQENH,&
 & PGEOH,    PQEN,     PQSEN,&
 & PAPH,     PLGLAC,   PQPRCV,&
 & PBUOH,    PWUBASE,&
 & PTU,      PQU,      PLU,&
 & PMFU,     PMFUB,&
 & PMFUS,    PMFUQ,    PMFUL,    PLUDE,    PDMFUP, &
 & PMFUDE_RATE, PWMEAN, PERATEU )  

!          THIS ROUTINE DOES THE CALCULATIONS OF THE MASS-FLUX PROFILE
!          FOR THE SIMPLIFIED CUMULUS PARAMETERIZATION 
!          (TANGENT LINEAR VERSION)

!          P.LOPEZ           E.C.M.W.F.     May 2002

!          PURPOSE.
!          --------
!          TO PRODUCE MASS-FLUX PROFILE FOR SIMPLIFIED 
!          CONVECTIVE PARAMETRIZATION 

!          INTERFACE
!          ---------

!          THIS ROUTINE IS CALLED FROM *CUMASTRN2TL*.

!          METHOD.
!          --------

!     PARAMETER     DESCRIPTION                                   UNITS
!     ---------     -----------                                   -----
!     INPUT PARAMETERS (INTEGER):

!    *KIDIA*        START POINT
!    *KFDIA*        END POINT
!    *KLON*         NUMBER OF GRID POINTS PER PACKET
!    *KLEV*         NUMBER OF LEVELS
!    *KTYPE*        TYPE OF CONVECTION
!                       1 = PENETRATIVE CONVECTION
!                       2 = SHALLOW CONVECTION
!                       3 = MIDLEVEL CONVECTION
!    *KCBOT*        CLOUD BASE LEVEL
!    *KSTUP*        LEVEL AT WHICH THE UPDRAFT STARTS 

!    *PTEN5*        TEMPERATURE ON FULL LEVELS                  (Trajectory)
!    *PTENH5*       TEMPERATURE ON HALF LEVELS                  (Trajectory) 
!    *PQENH5*       SPECIFIC HUMIDITY ON HALF LEVELS            (Trajectory)
!    *PGEOH5*       GEOPOTENTIAL ON HALF LEVELS                 (Trajectory)
!    *PQEN5*        SPECIFIC HUMIDITY ON FULL LEVELS            (Trajectory) 
!    *PQSEN5*       SATURATION SPECIFIC HUMIDITY ON FULL LEVELS (Trajectory) 
!    *PAPH5*        PROVISIONAL PRESSURE ON HALF LEVELS         (Trajectory)
!    *PLGLAC5*      FROZEN CLOUD WATER CONTENT                  (Trajectory)
!    *PQPRCV5*      CONVECTIVE PRECIPITATION CONTENT            (Trajectory)
!    *PBUOH5*       BUOYANCY ON HALF-LEVELS                     (Trajectory)
!    *PTU5*         TEMPERATURE IN UPDRAFTS                     (Trajectory)
!    *PQU5*         SPEC. HUMIDITY IN UPDRAFTS                  (Trajectory)
!    *PLU5*         LIQUID WATER CONTENT IN UPDRAFTS            (Trajectory)

!    *PTEN*         TEMPERATURE ON FULL LEVELS                   K 
!    *PTENH*        TEMPERATURE ON HALF LEVELS                   K 
!    *PQENH*        SPECIFIC HUMIDITY ON HALF LEVELS             KG/KG
!    *PGEOH*        GEOPOTENTIAL ON HALF LEVELS                  M2/S2
!    *PQEN*         SPECIFIC HUMIDITY ON FULL LEVELS             KG/KG 
!    *PQSEN*        SATURATION SPECIFIC HUMIDITY ON FULL LEVELS  KG/KG 
!    *PAPH*         PROVISIONAL PRESSURE ON HALF LEVELS          Pa
!    *PLGLAC*       FROZEN CLOUD WATER CONTENT                   KG/KG 
!    *PQPRCV*       CONVECTIVE PRECIPITATION CONTENT             KG/KG
!    *PBUOH*        BUOYANCY ON HALF-LEVELS                      M/S2
!    *PTU*          TEMPERATURE IN UPDRAFTS                      K
!    *PQU*          SPEC. HUMIDITY IN UPDRAFTS                   KG/KG
!    *PLU*          LIQUID WATER CONTENT IN UPDRAFTS             KG/KG

!    INPUT PARAMETERS (LOGICAL):

!    *LDCUM*        FLAG: .TRUE. FOR CONVECTIVE POINTS 

!    UPDATED PARAMETERS (INTEGER):

!    *KCTOP*        CLOUD TOP LEVEL

!    OUTPUT PARAMETERS (REAL):

!    *PMFU5*        MASSFLUX IN UPDRAFTS                        (Trajectory)
!    *PMFUB5*       MASSFLUX IN UPDRAFTS AT CLOUD BASE          (Trajectory)
!    *PMFUS5*       FLUX OF DRY STATIC ENERGY IN UPDRAFTS       (Trajectory)
!    *PMFUQ5*       FLUX OF SPEC. HUMIDITY IN UPDRAFTS          (Trajectory)
!    *PMFUL5*       FLUX OF LIQUID WATER IN UPDRAFTS            (Trajectory)
!    *PLUDE5*       DETRAINED LIQUID WATER                      (Trajectory)
!    *PDMFUP5*      FLUX DIFFERENCE OF PRECIP. IN UPDRAFTS      (Trajectory)
!    *PMFUDE_RATE5* UPDRAFT DETRAINMENT RATE                    (Trajectory)
!    *PWMEAN5*      MEAN UPDRAFT VELOCITY                       (Trajectory)
!    *PERATEU5*     UPDRAFT ENTRAINMENT RATE                    (Trajectory)

!    *PMFU*         MASSFLUX IN UPDRAFTS                         KG/(M2*S)
!    *PMFUB*        MASSFLUX IN UPDRAFTS AT CLOUD BASE           KG/(M2*S)
!    *PMFUS*        FLUX OF DRY STATIC ENERGY IN UPDRAFTS         J/(M2*S)
!    *PMFUQ*        FLUX OF SPEC. HUMIDITY IN UPDRAFTS           KG/(M2*S)
!    *PMFUL*        FLUX OF LIQUID WATER IN UPDRAFTS             KG/(M2*S)
!    *PLUDE*        DETRAINED LIQUID WATER                       KG/(M2*S)
!    *PDMFUP*       FLUX DIFFERENCE OF PRECIP. IN UPDRAFTS       KG/(M2*S)
!    *PMFUDE_RATE*  UPDRAFT DETRAINMENT RATE                     KG/(M2*S)
!    *PWMEAN*       MEAN UPDRAFT VELOCITY                         M/S
!    *PERATEU*      UPDRAFT ENTRAINMENT RATE                      

!          EXTERNALS
!          ---------

!          REFERENCE
!          ---------

!          MODIFICATIONS
!          -------------
!        M.Hamrud      01-Oct-2003 CY28 Cleaning.
!        P.Lopez       01-Oct-2005 Changed entrainment/detrainment.
!        P.Lopez       19-Feb-2007 Added LREGCV switch.
!        P.Lopez       19-Oct-2007 Revised version to improve match to 
!                                  Tiedtke scheme.

!----------------------------------------------------------------------

USE PARKIND1  ,ONLY : JPIM     ,JPRB
USE YOMHOOK   ,ONLY : LHOOK,   DR_HOOK

USE YOMCST   , ONLY : RETV,   RG,  RCPD,  RLVTT,  RLSTT,  RTT  
USE YOECUMF2 , ONLY : ENTRPEN2, ENTRSCV2, RPRCON2, NJKT22, ENTRORG2
USE YOETHF   , ONLY : R2ES     ,R3LES    ,R3IES    ,R4LES    ,&
 & R4IES    ,R5LES    ,R5IES   ,R5ALVCP  ,R5ALSCP  ,&
 & RALVDCP  ,RALSDCP  ,RALFDCP ,RTWAT    ,RTICE    ,RTICECU  ,&
 & RTWAT_RTICE_R      ,RTWAT_RTICECU_R    ,RTBER    ,RTBERCU  
USE YOMCUMFS , ONLY : LREGCV

IMPLICIT NONE

INTEGER(KIND=JPIM),INTENT(IN)    :: KLON 
INTEGER(KIND=JPIM),INTENT(IN)    :: KLEV 
INTEGER(KIND=JPIM),INTENT(IN)    :: KIDIA 
INTEGER(KIND=JPIM),INTENT(IN)    :: KFDIA 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PTEN5(KLON,KLEV)
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PTENH5(KLON,KLEV)
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PQENH5(KLON,KLEV)
REAL(KIND=JPRB)   ,INTENT(IN)    :: PGEOH5(KLON,KLEV+1) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PQEN5(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PQSEN5(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PAPH5(KLON,KLEV+1)
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PLGLAC5(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PQPRCV5(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PBUOH5(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PWUBASE5(KLON) 
LOGICAL           ,INTENT(INOUT) :: LDCUM(KLON) 
INTEGER(KIND=JPIM),INTENT(INOUT) :: KTYPE(KLON) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PTU5(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PQU5(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PLU5(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PMFU5(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PMFUB5(KLON) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PMFUS5(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PMFUQ5(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PMFUL5(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PLUDE5(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PDMFUP5(KLON,KLEV) 
INTEGER(KIND=JPIM),INTENT(INOUT) :: KCBOT(KLON) 
INTEGER(KIND=JPIM),INTENT(INOUT) :: KCTOP(KLON) 
INTEGER(KIND=JPIM),INTENT(INOUT) :: KSTUP(KLON) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PTEN(KLON,KLEV)
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PTENH(KLON,KLEV)
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PQENH(KLON,KLEV)
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PMFUDE_RATE5(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PWMEAN5(KLON) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PERATEU5(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PGEOH(KLON,KLEV+1) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PQEN(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PQSEN(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PAPH(KLON,KLEV+1)
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PLGLAC(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PQPRCV(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PBUOH(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PWUBASE(KLON) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PTU(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PQU(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PLU(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PMFU(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PMFUB(KLON) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PMFUS(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PMFUQ(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PMFUL(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PLUDE(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PDMFUP(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PMFUDE_RATE(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PWMEAN(KLON) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PERATEU(KLON,KLEV) 

!     LOCAL SCALAR ARRAYS
REAL(KIND=JPRB) ::  ZWU2H (KLON,KLEV), ZWU2H5(KLON,KLEV)
REAL(KIND=JPRB) ::  ZSUH (KLON,KLEV),  ZSUH5(KLON,KLEV)
REAL(KIND=JPRB) ::  ZSENH (KLON,KLEV), ZSENH5(KLON,KLEV)
REAL(KIND=JPRB) ::  ZERATE5(KLON,KLEV), ZERATE (KLON,KLEV)
REAL(KIND=JPRB) ::  ZDERATE5(KLON,KLEV), ZDERATE (KLON,KLEV)
REAL(KIND=JPRB) ::  ZDPMEAN5(KLON), ZDPMEAN (KLON)
REAL(KIND=JPRB) ::  ZQOLD5(KLON), ZPH5(KLON), ZRATQS5(KLON)
REAL(KIND=JPRB) ::  ZQOLD (KLON), ZPH (KLON), ZRATQS (KLON)
REAL(KIND=JPRB) ::  ZENT5(KLON), ZDET5(KLON), ZEPSORG5(KLON), ZDZ5(KLON)
REAL(KIND=JPRB) ::  ZENT (KLON), ZDET (KLON), ZEPSORG (KLON), ZDZ (KLON)

LOGICAL :: LLTEST(KLON)

INTEGER(KIND=JPIM) :: JK, JL, IKB, JKT2, IK, ICALL

REAL(KIND=JPRB) :: ZEPS5, ZBUOF5, ZDEL5, ZLUOLD5, ZFACTQS5
REAL(KIND=JPRB) :: ZEPS , ZBUOF , ZDEL , ZZORG , ZLUOLD , ZFACTQS 
REAL(KIND=JPRB) :: ZPRCON5, ZDT5, ZZCO5, ZC5, ZRHFACT5
REAL(KIND=JPRB) :: ZPRCON , ZDT , ZZCO , ZC , ZRHFACT
REAL(KIND=JPRB) :: ZDFI5, ZDT15, ZLCRIT5, ZEXP5
REAL(KIND=JPRB) :: ZLCRIT , ZDFI , ZDT1 , ZLCRITI
REAL(KIND=JPRB) :: ZD5, ZCOND5, ZINT5, ZLNEW5, ZCBF5, ZWU5, ZWU05, Z1ZD5
REAL(KIND=JPRB) :: ZD , ZCOND , ZINT , ZLNEW , ZCBF , ZWU
REAL(KIND=JPRB) :: ZLMAX5, ZTVENH5, ZTVUH5, ZRH5, ZRATW5, ZDETNEW5
REAL(KIND=JPRB) :: ZLMAX , ZTVENH , ZTVUH , ZRH , ZRATW , ZDETNEW

REAL(KIND=JPRB) :: ZFACT1, ZFACT2, ZFACT3, ZFACT4, ZFACT5, ZFACT25, ZSQRT5
REAL(KIND=JPRB) :: ZCBF5I, ZLCRIT5I, ZFACT22, ZFACT7

! Constants
REAL(KIND=JPRB) :: ZAW, ZBW, ZRCPD, Z_CPRC2, ZPRCDGW, ZRG, ZFAC
REAL(KIND=JPRB) :: ZQCMAX, Z_CLCRIT

REAL(KIND=JPRB) :: ZHOOK_HANDLE

#include "cuadjtqstl.intfb.h"

#include "fcttre.h"
#include "fcttretl.h"
!----------------------------------------------------------------------

IF (LHOOK) CALL DR_HOOK('CUASCN2TL',0,ZHOOK_HANDLE)

!*    1.           SPECIFY PARAMETERS
!                  ------------------

ZAW=0.5_JPRB/(1.0_JPRB+0.5_JPRB)
ZBW=1.0_JPRB+(3._JPRB/8._JPRB)*0.506_JPRB/0.2_JPRB
ZQCMAX=5.E-03_JPRB
ZPRCDGW=RPRCON2/RG
Z_CLCRIT=0.5E-3_JPRB
Z_CPRC2=0.5_JPRB
ZRCPD=1.0_JPRB/RCPD
ZRG=1.0_JPRB/RG

JKT2=NJKT22

!----------------------------------------------------------------------

!     2.           SET DEFAULT VALUES
!                  ------------------

DO JL=KIDIA,KFDIA
  IF(.NOT.LDCUM(JL)) THEN
    KCBOT(JL)=-1
    KCTOP(JL)=-1
    KTYPE(JL)=0
    KSTUP(JL)=-1
  ENDIF
  ZEPSORG5(JL) = 0.0_JPRB
  ZEPSORG (JL) = 0.0_JPRB
ENDDO

! initialize various quantities

DO JK=1,KLEV
  DO JL=KIDIA,KFDIA
    PMFU5(JL,JK)=0.0_JPRB
    PMFU(JL,JK)=0.0_JPRB
    PMFUS5(JL,JK)=0.0_JPRB
    PMFUS(JL,JK)=0.0_JPRB
    PMFUQ5(JL,JK)=0.0_JPRB
    PMFUQ(JL,JK)=0.0_JPRB
  ENDDO
ENDDO
DO JK=1,KLEV
  DO JL=KIDIA,KFDIA
    PMFUL5(JL,JK)=0.0_JPRB
    PMFUL(JL,JK)=0.0_JPRB
    PLUDE5(JL,JK)=0.0_JPRB
    PLUDE(JL,JK)=0.0_JPRB
    PDMFUP5(JL,JK)=0.0_JPRB
    PDMFUP(JL,JK)=0.0_JPRB
  ENDDO
ENDDO
DO JK=1,KLEV
  DO JL=KIDIA,KFDIA
    ZWU2H5(JL,JK)=0.0_JPRB
    ZWU2H(JL,JK)=0.0_JPRB
    PMFUDE_RATE5(JL,JK)=0.0_JPRB
    PMFUDE_RATE(JL,JK)=0.0_JPRB
    ZSENH5(JL,JK)=RCPD*PTENH5(JL,JK)+PGEOH5(JL,JK)
    ZSENH (JL,JK)=RCPD*PTENH (JL,JK)+PGEOH (JL,JK)
  ENDDO
ENDDO
DO JK=1,KLEV
  DO JL=KIDIA,KFDIA
    ZSUH5(JL,JK)=0.0_JPRB
    ZSUH (JL,JK)=0.0_JPRB
    PERATEU5(JL,JK)=0.0_JPRB
    PERATEU (JL,JK)=0.0_JPRB
    ZERATE5 (JL,JK)=0.0_JPRB
    ZERATE  (JL,JK)=0.0_JPRB
    ZDERATE5(JL,JK)=0.0_JPRB
    ZDERATE (JL,JK)=0.0_JPRB
  ENDDO
ENDDO

!----------------------------------------------------------------------

!     3.0          INITIALIZE VALUES AT cloud base LEVEL
!                  -------------------------------------

DO JL=KIDIA,KFDIA
  KCTOP(JL)=KCBOT(JL)
  PWMEAN5(JL)=0.0_JPRB
  PWMEAN (JL)=0.0_JPRB
  ZDPMEAN5(JL)=0.0_JPRB
  ZDPMEAN (JL)=0.0_JPRB
  IF (LDCUM(JL)) THEN
    IKB=KCBOT(JL)
    ZWU2H5(JL,IKB)=PWUBASE5(JL)**2
    ZWU2H(JL,IKB)=2.0_JPRB*PWUBASE(JL)*PWUBASE5(JL)
    PMFU5(JL,IKB)=PMFUB5(JL)
    PMFU(JL,IKB)=PMFUB(JL)
    PMFUS5(JL,IKB)=PTU5(JL,IKB)
    PMFUS (JL,IKB)=PTU (JL,IKB)
    PMFUQ5(JL,IKB)=PQU5(JL,IKB)
    PMFUQ (JL,IKB)=PQU (JL,IKB)
    PMFUL5(JL,IKB)=PLU5(JL,IKB)
    PMFUL (JL,IKB)=PLU (JL,IKB)
    PDMFUP5(JL,IKB)=PQPRCV5(JL,IKB)*PMFU5(JL,IKB)
    PDMFUP (JL,IKB)=PQPRCV (JL,IKB)*PMFU5(JL,IKB) &
                 & +PQPRCV5(JL,IKB)*PMFU (JL,IKB)  
    ZSUH5(JL,IKB)=RCPD*PTU5(JL,IKB)+PGEOH5(JL,IKB)
    ZSUH (JL,IKB)=RCPD*PTU (JL,IKB)+PGEOH (JL,IKB)
    DO JK=1,IKB-1
      PLU5(JL,JK)=0.0_JPRB
      PLU (JL,JK)=0.0_JPRB
      PLGLAC5(JL,JK)=0.0_JPRB 
      PLGLAC (JL,JK)=0.0_JPRB 
      PQPRCV5(JL,JK)=0.0_JPRB 
      PQPRCV (JL,JK)=0.0_JPRB 
      PBUOH5(JL,JK)=0.0_JPRB 
      PBUOH (JL,JK)=0.0_JPRB 
    ENDDO 
!LLL Initialise buoyancy to zero at cloud base to mimic Tietdke scheme
    PBUOH5(JL,IKB)=0.0_JPRB 
    PBUOH (JL,IKB)=0.0_JPRB 
  ENDIF
ENDDO

!----------------------------------------------------------------------

!     4.0          COMPUTE MASS-FLUX PROFILE
!                  -------------------------

DO JK=KLEV-1,JKT2,-1
  DO JL=KIDIA,KFDIA
    LLTEST(JL)=(LDCUM(JL) .AND. JK < KCBOT(JL) .AND. &
             & PMFU5(JL,JK+1) > 0.0_JPRB .AND. ZWU2H5(JL,JK+1) > 0.0_JPRB)
    IF (LLTEST(JL)) THEN  

      IKB=KCBOT(JL)

      ZDZ5(JL) = (PGEOH5(JL,JK) - PGEOH5(JL,JK+1))*ZRG
      ZDZ(JL)  = (PGEOH (JL,JK) - PGEOH (JL,JK+1))*ZRG

      IF (KTYPE(JL) == 2) THEN
        ZEPS5 = ENTRSCV2
        ZEPS  = 0.0_JPRB        
        ZEPSORG5(JL) = 0.0_JPRB
        ZEPSORG (JL) = 0.0_JPRB
      ELSE      
        ZEPS5 = ENTRPEN2
        ZEPS  = 0.0_JPRB

        IF (JK == KCBOT(JL)-1) THEN
          ZFACT1 = 1.0_JPRB/PQSEN5(JL,JK)
          ZRH5 = PQEN5(JL,JK)*ZFACT1
          ZRH  = (PQEN (JL,JK) - PQSEN (JL,JK)*PQEN5(JL,JK)*ZFACT1)*ZFACT1

          IF (ZRH5 < 1.0_JPRB) THEN
            ZEPSORG5(JL)=-RG*ENTRORG2*(ZRH5-1.0_JPRB)*ZDZ5(JL)
            ZEPSORG (JL)=-RG*ENTRORG2*(ZDZ5(JL)*ZRH + (ZRH5-1.0_JPRB)*ZDZ (JL))
          ELSE
            ZEPSORG5(JL)=0.0_JPRB
            ZEPSORG (JL)=0.0_JPRB
          ENDIF

          IF (ZEPSORG5(JL) > 0.4_JPRB) THEN
            ZEPSORG5(JL)=0.4_JPRB
            ZEPSORG (JL)=0.0_JPRB
          ENDIF
          IF (LREGCV) ZEPSORG(JL) = ZEPSORG(JL) * 0.1_JPRB
        ENDIF
      ENDIF

      ZDEL  = ZEPS  * 1.2_JPRB
      ZDEL5 = ZEPS5 * 1.2_JPRB

      ZFACT7=1.0_JPRB/PQSEN5(JL,IKB)
      ZRATQS5(JL) = PQSEN5(JL,JK)*ZFACT7
      IF (ZRATQS5(JL) < 1.0_JPRB) THEN
        ZRATQS(JL) = (PQSEN (JL,JK) - ZRATQS5(JL) * PQSEN (JL,IKB))*ZFACT7
!LLL        IF (LREGCV .AND. ABS(ZRATQS5(JL)-1.0_JPRB) < 0.5_JPRB) THEN
        IF (LREGCV) THEN
          ZRATQS(JL) = 0.0_JPRB
        ENDIF
        ZEPS  = 4.0_JPRB * ZRATQS5(JL) *(ZRATQS5(JL) * ZEPS + 2.0_JPRB * ZEPS5 * ZRATQS (JL))
        ZEPS5 = 4.0_JPRB * ZEPS5 * ZRATQS5(JL)**2
      ELSE
        ZEPS  = 4.0_JPRB * ZEPS
        ZEPS5 = 4.0_JPRB * ZEPS5 
      ENDIF

      ZENT5(JL) = ZDZ5(JL)*ZEPS5 + ZEPSORG5(JL)
      ZENT (JL) = ZDZ5(JL)*ZEPS  + ZDZ (JL)*ZEPS5 + ZEPSORG (JL)

      ZDET5(JL) = ZDZ5(JL)*ZDEL5
      ZDET (JL) = ZDZ5(JL)*ZDEL + ZDZ (JL)*ZDEL5

      PQU5(JL,JK) = PQU5(JL,JK+1) * (1.0_JPRB-ZENT5(JL)) + PQENH5(JL,JK+1) * ZENT5(JL)
      PQU (JL,JK) = PQU (JL,JK+1) * (1.0_JPRB-ZENT5(JL)) + PQENH (JL,JK+1) * ZENT5(JL) &
                & + (PQENH5(JL,JK+1) - PQU5(JL,JK+1)) * ZENT (JL)

      ZSUH5(JL,JK) = ZSUH5(JL,JK+1) * (1.0_JPRB-ZENT5(JL)) + ZSENH5(JL,JK+1) * ZENT5(JL)
      ZSUH (JL,JK) = ZSUH (JL,JK+1) * (1.0_JPRB-ZENT5(JL)) + ZSENH (JL,JK+1) * ZENT5(JL) &
                 & + (ZSENH5(JL,JK+1) - ZSUH5(JL,JK+1)) * ZENT (JL)

      ZQOLD5(JL)  = PQU5(JL,JK)
      ZQOLD (JL)  = PQU (JL,JK)

      PTU5(JL,JK) = (ZSUH5(JL,JK)-PGEOH5(JL,JK))*ZRCPD
      PTU (JL,JK) = (ZSUH (JL,JK)-PGEOH (JL,JK))*ZRCPD

      ZPH5(JL) = PAPH5(JL,JK)
      ZPH (JL) = PAPH (JL,JK)

    ENDIF
  ENDDO

  IK=JK
  ICALL=1
  CALL CUADJTQSTL &
   & ( KIDIA,    KFDIA,    KLON,    KLEV,&
   &   IK,&
   &   ZPH5,     PTU5,     PQU5,&
   &   ZPH,      PTU,      PQU,      LLTEST,   ICALL)  


  DO JL=KIDIA,KFDIA
    IF (LLTEST(JL)) THEN  

! condensation 

      ZCOND5=MAX(ZQOLD5(JL)-PQU5(JL,JK),0.0_JPRB)
      IF (ZQOLD5(JL)-PQU5(JL,JK) > 0.0_JPRB) THEN
        ZCOND=ZQOLD(JL)-PQU(JL,JK)
      ELSE
        ZCOND=0.0_JPRB
      ENDIF

! microphysics

      ZLUOLD5=PLU5(JL,JK+1)
      ZLUOLD=PLU(JL,JK+1)
      ZLMAX5=MAX(ZLUOLD5+ZCOND5,0.0_JPRB)
      IF (ZLUOLD5+ZCOND5 > 0.0_JPRB) THEN
        ZLMAX=ZLUOLD+ZCOND
      ELSE
        ZLMAX=0.0_JPRB
      ENDIF

      IF(ZLMAX5 > 3.E-04_JPRB) THEN

        ZWU05=SQRT(ZWU2H5(JL,JK+1))
        ZWU5=MIN(15._JPRB,MAX(0.447_JPRB,ZWU05))
        IF (ZWU05 > 0.447_JPRB .AND. ZWU05 < 15.0_JPRB) THEN
          ZWU=0.5_JPRB*ZWU2H(JL,JK+1)/ZWU05
          IF (LREGCV) THEN  
            IF (ZWU05 < 0.1_JPRB) THEN
              ZWU=0.0_JPRB  
            ELSE      
              ZWU=ZWU*0.1_JPRB   
            ENDIF     
          ENDIF
        ELSE
          ZWU=0.0_JPRB
        ENDIF

        ZPRCON5= ZPRCDGW/(0.75_JPRB*ZWU5)
        ZPRCON =-ZPRCDGW*ZWU/(0.75_JPRB*ZWU5**2)

        ZDT15=RTBER-PTU5(JL,JK)
        ZDT1 =-PTU(JL,JK)

        ZDT5=MIN(RTBERCU-RTICECU,MAX(ZDT15,0.0_JPRB))
        IF (ZDT15 > 0.0_JPRB .AND. ZDT15 < RTBERCU-RTICECU) THEN
          ZDT=ZDT1
        ELSE
          ZDT=0.0_JPRB
        ENDIF

        ZSQRT5=SQRT(ZDT5)
        ZCBF5=1.0_JPRB+Z_CPRC2*ZSQRT5
        IF (ZDT5 > 0.0_JPRB) THEN
          ZCBF=0.5_JPRB*Z_CPRC2*ZDT/ZSQRT5
        ELSE
          ZCBF=0.0_JPRB
        ENDIF

        ZZCO5=ZPRCON5*ZCBF5
        ZZCO =ZPRCON *ZCBF5 + ZPRCON5*ZCBF

        ZCBF5I=1.0_JPRB/ZCBF5
        ZLCRIT5=Z_CLCRIT*ZCBF5I
        ZLCRIT =-ZCBF*ZLCRIT5*ZCBF5I

        ZDFI5=PGEOH5(JL,JK)-PGEOH5(JL,JK+1)
        ZDFI =PGEOH (JL,JK)-PGEOH (JL,JK+1)

        ZC5=ZLMAX5-ZLUOLD5
        ZC =ZLMAX -ZLUOLD

        ZLCRIT5I=1.0_JPRB/ZLCRIT5
        ZEXP5=EXP(-(ZLMAX5*ZLCRIT5I)**2)
        ZD5=ZZCO5*ZDFI5*(1.0_JPRB-ZEXP5)
        ZD =(ZZCO *ZDFI5+ZZCO5*ZDFI )*(1.0_JPRB-ZEXP5) &
          &+ ZZCO5*ZDFI5*2.0_JPRB*ZEXP5*ZLMAX5*(ZLCRIT5I**2) &
          &*(ZLMAX-ZLCRIT*ZLMAX5*ZLCRIT5I)

        ZINT5=EXP(-ZD5)
        ZINT =-ZD*ZINT5

        Z1ZD5=1.0_JPRB/ZD5
        ZLNEW5=ZLUOLD5*ZINT5+ZC5*Z1ZD5*(1.0_JPRB-ZINT5)
        ZLNEW =ZLUOLD *ZINT5+ZLUOLD5*ZINT +(ZC*(1.0_JPRB-ZINT5) &
            & -ZC5*(ZINT+ZD*(1.0_JPRB-ZINT5)*Z1ZD5))*Z1ZD5

        IF (ZLMAX5 < ZLNEW5) THEN
          IF (ZLMAX5 > 0.0_JPRB) THEN
            ZLNEW=ZLMAX
          ELSE
            ZLNEW=0.0_JPRB
          ENDIF
        ELSE
          IF (ZLNEW5 <= 0.0_JPRB) ZLNEW=0.0_JPRB
        ENDIF
        ZLNEW5=MAX(0.0_JPRB,MIN(ZLMAX5,ZLNEW5))

      ELSE
        ZLNEW5=ZLMAX5
        ZLNEW =ZLMAX
      ENDIF

      IF (ZLNEW5 > ZQCMAX) THEN
        ZLNEW=0.0_JPRB
      ENDIF
      ZLNEW5=MIN(ZQCMAX,ZLNEW5)

      PQPRCV5(JL,JK)=MAX(0.0_JPRB,ZLMAX5-ZLNEW5)
      IF (ZLMAX5-ZLNEW5 > 0.0_JPRB) THEN
        PQPRCV(JL,JK)=ZLMAX-ZLNEW
      ELSE
        PQPRCV(JL,JK)=0.0_JPRB
      ENDIF
      PLU5(JL,JK)=ZLNEW5
      PLU(JL,JK)=ZLNEW

! frozen water

      PLGLAC5(JL,JK)= ZCOND5*((1.0_JPRB-FOEALFCU(PTU5(JL,JK))) &
                  & -         (1.0_JPRB-FOEALFCU(PTU5(JL,JK+1))))  
      PLGLAC (JL,JK)= ZCOND5*(-FOEALFCUTL(PTU (JL,JK),PTU5(JL,JK)) &
                  & +          FOEALFCUTL(PTU (JL,JK+1),PTU5(JL,JK+1))) &
                  & + ZCOND *((1.0_JPRB-FOEALFCU(PTU5(JL,JK))) &
                  & -         (1.0_JPRB-FOEALFCU(PTU5(JL,JK+1)))) 
                  
! update dry static energy after condensation + freezing

      ZSUH5(JL,JK) = RCPD*(PTU5(JL,JK)+RALFDCP*PLGLAC5(JL,JK))+PGEOH5(JL,JK)
      ZSUH (JL,JK) = RCPD*(PTU (JL,JK)+RALFDCP*PLGLAC (JL,JK))+PGEOH (JL,JK)
      
! Buoyancy on half and full levels
         
      ZTVUH5 = PTU5(JL,JK)*(1.0_JPRB+RETV*PQU5(JL,JK)-PLU5(JL,JK+1)-PQPRCV5(JL,JK+1))&
           & + RALFDCP*PLGLAC5(JL,JK)  
      ZTVUH  = PTU5(JL,JK)*(         RETV*PQU (JL,JK)-PLU (JL,JK+1)-PQPRCV (JL,JK+1))&
           & + PTU (JL,JK)*(1.0_JPRB+RETV*PQU5(JL,JK)-PLU5(JL,JK+1)-PQPRCV5(JL,JK+1))&
           & + RALFDCP*PLGLAC (JL,JK)  
      ZTVENH5 = PTENH5(JL,JK)*(1.0_JPRB+RETV*PQENH5(JL,JK))
      ZTVENH  = PTENH (JL,JK)*(1.0_JPRB+RETV*PQENH5(JL,JK)) &
            & + PTENH5(JL,JK)*          RETV*PQENH (JL,JK)
      ZFACT2 = 1.0_JPRB/ZTVENH5
      ZFACT22 = ZFACT2
      PBUOH5(JL,JK) = RG*(ZTVUH5-ZTVENH5)*ZFACT2
      PBUOH (JL,JK) = RG*(ZTVUH -ZTVENH *ZTVUH5*ZFACT2)*ZFACT2

      IF (PBUOH5(JL,JK) < 0.0_JPRB .AND. PLU5(JL,JK) > 0.0_JPRB) THEN
        PTENH5(JL,JK) = 0.5_JPRB*(PTEN5(JL,JK)+PTEN5(JL,JK-1))
        PTENH (JL,JK) = 0.5_JPRB*(PTEN (JL,JK)+PTEN (JL,JK-1))
        PQENH5(JL,JK) = 0.5_JPRB*(PQEN5(JL,JK)+PQEN5(JL,JK-1))
        PQENH (JL,JK) = 0.5_JPRB*(PQEN (JL,JK)+PQEN (JL,JK-1))
        ZSENH5(JL,JK) = RCPD*PTENH5(JL,JK)+PGEOH5(JL,JK)
        ZSENH (JL,JK) = RCPD*PTENH (JL,JK)+PGEOH (JL,JK)
        ZTVENH5 = PTENH5(JL,JK)*(1.0_JPRB+RETV*PQENH5(JL,JK))
        ZTVENH  = PTENH (JL,JK)*(1.0_JPRB+RETV*PQENH5(JL,JK)) &
              & + PTENH5(JL,JK)*          RETV*PQENH (JL,JK)
        ZFACT22 = 1.0_JPRB/ZTVENH5
        PBUOH5(JL,JK) = RG*(ZTVUH5-ZTVENH5)*ZFACT22
        PBUOH (JL,JK) = RG*(ZTVUH -ZTVENH *ZTVUH5*ZFACT22)*ZFACT22
      ENDIF 

! Buoyancy on full levels

      ZBUOF5 = (PBUOH5(JL,JK) + PBUOH5(JL,JK+1))*0.5_JPRB
      ZBUOF  = (PBUOH(JL,JK)  + PBUOH(JL,JK+1)) *0.5_JPRB

! Reduce buoyancy perturbation if required
      IF (LREGCV) THEN
        ZBUOF=ZBUOF*0.33_JPRB
      ENDIF

! Solve kinetic energy equation

      ZWU2H5(JL,JK) = (ZWU2H5(JL,JK+1)*(1.0_JPRB-ZBW*ZENT5(JL))&
       & + 2.0_JPRB*ZAW*ZBUOF5*ZDZ5(JL))/(1.0_JPRB+ZBW*ZENT5(JL))  
      ZWU2H(JL,JK) = (ZWU2H(JL,JK+1)*(1.0_JPRB-ZBW*ZENT5(JL)) &
       & - (ZWU2H5(JL,JK+1)+ZWU2H5(JL,JK))*ZBW*ZENT(JL) &
       & + 2.0_JPRB*ZAW*(ZBUOF*ZDZ5(JL)+ZBUOF5*ZDZ(JL))) &
       & / (1.0_JPRB+ZBW*ZENT5(JL))  

! Accumulate updraught kinetic energy in the vertical

      PWMEAN5(JL)  = PWMEAN5(JL)  + ZWU2H5(JL,JK)*(PAPH5(JL,JK+1) - PAPH5(JL,JK))
      PWMEAN (JL)  = PWMEAN (JL)  + ZWU2H (JL,JK)*(PAPH5(JL,JK+1) - PAPH5(JL,JK)) &
                 & +                ZWU2H5(JL,JK)*(PAPH (JL,JK+1) - PAPH (JL,JK))

      ZDPMEAN5(JL) = ZDPMEAN5(JL) + PAPH5(JL,JK+1) - PAPH5(JL,JK)
      ZDPMEAN (JL) = ZDPMEAN (JL) + PAPH (JL,JK+1) - PAPH (JL,JK)
 
! Entrainment and detrainment according to variation of kinetic energy
! on the vertical.

      IF (ZWU2H5(JL,JK) >= ZWU2H5(JL,JK+1)) THEN
        PMFU5(JL,JK) = PMFU5(JL,JK+1)*(1.0_JPRB+ZENT5(JL)-ZDET5(JL))
        PMFU (JL,JK) = PMFU (JL,JK+1)*(1.0_JPRB+ZENT5(JL)-ZDET5(JL)) &
         &           + PMFU5(JL,JK+1)*(ZENT(JL) -ZDET(JL) )
        PLUDE5(JL,JK) = ZDET5(JL)*PLU5(JL,JK+1)
        PLUDE (JL,JK) = ZDET5(JL)*PLU (JL,JK+1) + ZDET (JL)*PLU5(JL,JK+1)
        PMFUDE_RATE5(JL,JK) = ZDET5(JL)*PMFU5(JL,JK+1)
        PMFUDE_RATE (JL,JK) = ZDET(JL) *PMFU5(JL,JK+1) + ZDET5(JL)*PMFU (JL,JK+1)
      ELSE

! Organised detrainment
        IF (PBUOH5(JL,JK) < 0.0_JPRB .AND. PLU5(JL,JK) > 0.0_JPRB) THEN
          ZFACT3 = 1.0_JPRB/ZWU2H5(JL,JK+1)
          ZRATW5=ZWU2H5(JL,JK)*ZFACT3
          ZRATW =ZWU2H (JL,JK)*ZFACT3 - ZWU2H (JL,JK+1)*ZWU2H5(JL,JK)*ZFACT3**2
!LLL          IF (LREGCV .AND. ABS(ABS(ZRATW5)-1.0_JPRB) < 0.5_JPRB) THEN
          IF (LREGCV) THEN
            ZRATW=0.0_JPRB
          ENDIF
          IF (ZRATW5 > 0.0_JPRB) THEN
            ZDETNEW5=1.0_JPRB-ZRATW5
            ZDETNEW =-ZRATW
          ELSE
            ZDETNEW5=1.0_JPRB
            ZDETNEW =0.0_JPRB
          ENDIF
          IF (ZDET5(JL) < ZDETNEW5) THEN
            ZDET5(JL)=ZDETNEW5
            ZDET (JL)=ZDETNEW
          ENDIF     
        ENDIF

        IF (ZWU2H5(JL,JK) > 0.0_JPRB) THEN
          PMFU5(JL,JK) = PMFU5(JL,JK+1)*(1.0_JPRB+ZENT5(JL)-ZDET5(JL))
          PMFU (JL,JK) = PMFU (JL,JK+1)*(1.0_JPRB+ZENT5(JL)-ZDET5(JL)) &
           &           + PMFU5(JL,JK+1)*(ZENT(JL) -ZDET(JL) )
          PLUDE5(JL,JK) = ZDET5(JL)*PLU5(JL,JK+1)
          PLUDE (JL,JK) = ZDET5(JL)*PLU (JL,JK+1) + ZDET(JL)*PLU5(JL,JK+1)
          PMFUDE_RATE5(JL,JK) = ZDET5(JL)*PMFU5(JL,JK+1)
          PMFUDE_RATE (JL,JK) = ZDET(JL) *PMFU5(JL,JK+1) + ZDET5(JL)*PMFU (JL,JK+1)
        ENDIF
      ENDIF

      IF (PMFU5(JL,JK) <= 0.0_JPRB .OR. ZWU2H5(JL,JK) <= 0.0_JPRB &
        & .OR. ZBUOF5 == 0.0_JPRB) THEN
        KCTOP(JL)=JK+1
        PMFU5(JL,JK)=0.0_JPRB
        PMFU (JL,JK)=0.0_JPRB
        PLUDE5(JL,JK) = PLU5(JL,JK+1)
        PLUDE (JL,JK) = PLU (JL,JK+1)
        ZDET5(JL)=1.0_JPRB
        ZDET (JL)=0.0_JPRB
        PMFUDE_RATE5(JL,JK) = PMFU5(JL,JK+1)
        PMFUDE_RATE (JL,JK) = PMFU (JL,JK+1)
      ENDIF

! Store entrainment and detrainment rates for momentum computations
      ZERATE5 (JL,JK)=ZENT5(JL)
      ZERATE  (JL,JK)=ZENT (JL)
      ZDERATE5(JL,JK)=ZDET5(JL)
      ZDERATE (JL,JK)=ZDET (JL)

! Organised entrainment for next level
      IF (KTYPE(JL) /= 2 .AND. ZBUOF5 > -0.2_JPRB*RG*ZFACT22 .AND. &
        & PLU5(JL,JK+1) > 0.0_JPRB) THEN

        ZFACTQS5=MIN(1.0_JPRB,ZRATQS5(JL))**3
        IF (ZRATQS5(JL) < 1.0_JPRB) THEN
          ZFACTQS  = 3.0_JPRB*(ZRATQS5(JL)**2)*ZRATQS (JL)
        ELSE
          ZFACTQS  = 0.0_JPRB
        ENDIF
          
        ZFACT4 = 1.0_JPRB/PQSEN5(JL,JK)
        ZRH5 = PQEN5(JL,JK)*ZFACT4
        ZRH  = (PQEN (JL,JK) - PQSEN (JL,JK)*PQEN5(JL,JK)*ZFACT4)*ZFACT4

        IF (ZRH5 < 1.0_JPRB) THEN
          ZRHFACT5 = 0.30_JPRB - (ZRH5-1.0_JPRB)
          ZRHFACT  = -ZRH
        ELSE
          ZRHFACT5 = 0.30_JPRB
          ZRHFACT  = 0.0_JPRB
        ENDIF

        ZEPSORG5(JL) = RG*ENTRORG2*ZRHFACT5*ZDZ5(JL)*ZFACTQS5
        ZEPSORG (JL) = RG*ENTRORG2*(ZRHFACT *ZDZ5(JL)*ZFACTQS5 &
                   & +              ZRHFACT5*ZDZ (JL)*ZFACTQS5 &
                   & +              ZRHFACT5*ZDZ5(JL)*ZFACTQS ) 

        IF (ZEPSORG5(JL) > 0.4_JPRB) THEN
          ZEPSORG5(JL)=0.4_JPRB
          ZEPSORG (JL)=0.0_JPRB
        ENDIF
        IF (LREGCV) ZEPSORG(JL) = ZEPSORG(JL) * 0.1_JPRB
      ELSE
        ZEPSORG5(JL)=0.0_JPRB
        ZEPSORG (JL)=0.0_JPRB
      ENDIF

      PMFUS5 (JL,JK)=PTU5(JL,JK)
      PMFUS  (JL,JK)=PTU (JL,JK)
      PMFUQ5 (JL,JK)=PQU5(JL,JK)
      PMFUQ  (JL,JK)=PQU (JL,JK)
      PMFUL5 (JL,JK)=PLU5(JL,JK)
      PMFUL  (JL,JK)=PLU (JL,JK)
      PDMFUP5(JL,JK)=PQPRCV5(JL,JK)*PMFU5(JL,JK)
      PDMFUP (JL,JK)=PQPRCV5(JL,JK)*PMFU (JL,JK) &
                  & +PQPRCV (JL,JK)*PMFU5(JL,JK)  
    ENDIF
  ENDDO
ENDDO

! Average updraught velocity
DO JL=KIDIA,KFDIA
  IF(LDCUM(JL)) THEN
    IF (ZDPMEAN5(JL) > 1.0_JPRB) THEN
      ZFACT25=1.0_JPRB/ZDPMEAN5(JL)
      PWMEAN (JL)=(PWMEAN (JL) - ZDPMEAN (JL)*PWMEAN5(JL)*ZFACT25)*ZFACT25
      PWMEAN5(JL)=PWMEAN5(JL)*ZFACT25
    ENDIF

    IF (PWMEAN5(JL) < 1.E-2_JPRB) THEN
      PWMEAN5(JL)= 1.E-2_JPRB
      PWMEAN (JL)= 0.0_JPRB
    ENDIF
     
    ZSQRT5=SQRT(PWMEAN5(JL))
    PWMEAN (JL)=0.5_JPRB*PWMEAN (JL)/ZSQRT5
    PWMEAN5(JL)=ZSQRT5
  ENDIF
ENDDO

! Disregard single layer convective clouds
! to avoid problem in CAPE closure.
DO JL=KIDIA,KFDIA
  IF (LDCUM(JL) .AND. KCTOP(JL) == KCBOT(JL)) THEN
    LDCUM(JL)=.FALSE.
    KCTOP(JL)=-2
    KCBOT(JL)=-2
    KTYPE(JL)=0
    PWMEAN5(JL)=0.0_JPRB
    PWMEAN (JL)=0.0_JPRB
    DO JK=1,KLEV
      ZERATE5(JL,JK)=0.0_JPRB
      ZERATE (JL,JK)=0.0_JPRB
      ZDERATE5(JL,JK)=0.0_JPRB
      ZDERATE (JL,JK)=0.0_JPRB
    ENDDO
  ENDIF
ENDDO

! Updraught modified entrainment rates for momentum computations
DO JK=1,KLEV
  DO JL=KIDIA,KFDIA
    IF (LDCUM(JL)) THEN
      ZFAC=0.0_JPRB
      IF (KTYPE(JL) == 1 .OR. KTYPE(JL) == 3) ZFAC=2.0_JPRB
      IF (KTYPE(JL) == 1 .AND. JK <= KCTOP(JL)+2) ZFAC=3.0_JPRB
      PERATEU5(JL,JK)=ZERATE5(JL,JK)+ZFAC*ZDERATE5(JL,JK)
      PERATEU (JL,JK)=ZERATE (JL,JK)+ZFAC*ZDERATE (JL,JK)
    ENDIF
  ENDDO
ENDDO

IF (LHOOK) CALL DR_HOOK('CUASCN2TL',1,ZHOOK_HANDLE)
END SUBROUTINE CUASCN2TL
