!OPTIONS XOPT(NOEVAL)
SUBROUTINE ACTSECTL ( KIDIA,KFDIA,KLON,KTDIA,KLEV,&
 !-----------------------------------------------------------------------
 ! - INPUT  2D .
 & PAPHI5,PAPHIF5,PAPRS5,PAPRSF5,PQ5,PT5,PU5,PV5,&
 & PAPHI,PAPHIF,PAPRS,PAPRSF,PQ,PT,PU,PV,&
 ! - INPUT  1D .
 & PQS,PTS,PGZ0,&
 ! - OUTPUT 2D .
 & PKTROV5,PKUROV5,PXTROV5,PXUROV5,&
 & PKTROV,PKUROV,PXTROV,PXUROV,&
 ! - OUTPUT 1D .
 & PCDROV5,PCHROV5,PXDROV5,PXHROV5,&
 & PCDROV,PCHROV,PXDROV,PXHROV,&
 ! - LOCK ARGUMENTS .
 & CDLOCK)  

!**** *ACTSECTL* - TANGENT LINEAR OF VERTICAL TURBULENT
!                  AND SURFACE EXCHANGE COEFFICIENTS.

!     Subject.
!     --------
!     Tangent linear of:
!     - COMPUTATION OF VERTICAL TURBULENT EXCHANGE COEFFICIENTS
!       (DIMENSION (DP/(G*DT)) AND OF STATIC STABILITY (DIMENSION
!       (U/DP)**2), AS WELL AS OF THE "ANTI-FIBRILLATION" AMPLIFICATION
!       FACTORS OF THE FORMERS .
!     - COMPUTATION OF SURFACE EXCHANGE COEFFICIENTS PLUS THEIR
!       AMPLIFICATION FACTOR IF "ANTI-FIBRILLATION" IS ACTIVATED .

!**   Interface.
!     ----------
!        *CALL* *ACTSECTL*

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

! -   ARGUMENTS FOR INPUT
!     -------------------

! - DIMENSIONAL PARAMETERS OF PHYSICS.

! KIDIA      : START OF HORIZONTAL LOOP (IST in CPG)
! KFDIA      : END OF HORIZONTAL LOOP.
! KLON       : HORIZONTAL DIMENSION.
! KTDIA      : START OF THE VERTICAL LOOP IN THE PHYSICS (1 IN GENERAL)
! KLEV       : END OF VERTICAL LOOP IN THE PHYSICS (1 IN GENERAL)

! - THE NAME OF THE PHYSICAL VARIABLES.

! PAPHI      : GEOPOTENTIAL ON HALF LEVELS.
! PAPRS      : PRESSURE ON HALF LEVELS.

! The same but for trajectory
! ---------------------------
! PAPHI5     : GEOPOTENTIAL ON HALF LEVELS.
! PAPRS5     : PRESSURE ON HALF LEVELS.

! - 2D (1:KLEV) .

! PAPHIF     : GEOPOTENTIAL ON FULL LEVELS.
! PQ         : SPECIFIC HUMIDITY OF WATER VAPOR.
! PT         : TEMPERATURE.
! PU         : X - COMPONENT OF WIND.
! PV         : Y - COMPONENT OF WIND.

! The same but for trajectory
! ---------------------------
! PAPHIF5    : GEOPOTENTIAL ON FULL LEVELS.
! PQ5        : SPECIFIC HUMIDITY OF WATER VAPOR.
! PT5        : TEMPERATURE.
! PU5        : X - COMPONENT OF WIND.
! PV5        : Y - COMPONENT OF WIND.

! - 1D (PROGNOSTIC) .

! PTP        : DEEP LAYER TEMPERATURE.
!     (KCSS)
! PTS        : SURFACE TEMPERATURE.
! PQS        : SURFACE SPECIFIC HUMIDITY

! - 1D (GEOGRAPHIC) .

! PGZ0       : GRAVITY * ROUGHNESS LENGTH.

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

! -   ARGUMENTS FOR OUTPUT.
!     ---------------------

! - 2D (0:KLEV) .

! PKTROV     : VERTICAL EXCHANGE COEFFICIENT OF T AND Q IN KG/(M*M*S).
! PKUROV     : VERTICAL EXCHANGE COEFFICIENT OF U AND V IN KG/(M*M*S).
! PXTROV     : "ANTI-FIBRILLATION" MULTIPLICATOR OF PKTROV.
! PXUROV     : "ANTI-FIBRILLATION" MULTIPLICATOR OF PKUROV.

! The same but for trajectory
! ---------------------------
! PKTROV5    : VERTICAL EXCHANGE COEFFICIENT OF T AND Q IN KG/(M*M*S).
! PKUROV5    : VERTICAL EXCHANGE COEFFICIENT OF U AND V IN KG/(M*M*S).
! PXTROV5    : "ANTI-FIBRILLATION" MULTIPLICATOR OF PKTROV.
! PXUROV5    : "ANTI-FIBRILLATION" MULTIPLICATOR OF PKUROV.

! - 1D (DIAGNOSTIC) .

! PCDROV     : PCD RENORME EN DENSITE FOIS VITESSE.
! PCHROV     : PCH RENORME EN DENSITE FOIS VITESSE.
! PXDROV     : "ANTI-FIBRILLATION" MULTIPLICATOR OF PCDROV.
! PXHROV     : "ANTI-FIBRILLATION" MULTIPLICATOR OF PCHROV.

! The same but for trajectory
! ---------------------------
! PCDROV5    : PCD RENORME EN DENSITE FOIS VITESSE.
! PCHROV5    : PCH RENORME EN DENSITE FOIS VITESSE.
! PXDROV5    : "ANTI-FIBRILLATION" MULTIPLICATOR OF PCDROV.
! PXHROV5    : "ANTI-FIBRILLATION" MULTIPLICATOR OF PCHROV.

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

! -   IMPLICIT ARGUMENTS.
!     -------------------

! COMMON/YOMPHY /
! COMMON/YOMCST /
! COMMON/YOMPHY0/
! COMMON/YOMPHY1/
! COMMON/FCTTRM /
! COMMON/FCTTRMTL/

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

!     Externals.
!     ----------

!     Methode.
!     --------

!     Authors
!     -------
!        95-11, M.Janiskova

!     Modifications.
!     --------------
!        97-08, introduce CDLOCK - J.M. Piriou.
!        97-11, modified smoothing - M. Janiskova
!        98-11, adopted modifications for anti-fibrillation
!               and shallow convection - M. Janiskova
!        99-01, code optimization - M. Janiskova
!        M.Hamrud      01-Oct-2003 CY28 Cleaning
!        03-12, introduction of USURID,USURIDE,USURICE et USURICL - C Loo
!        03-12, remove of "Girard-Delage" anti-fibrillation - C Loo
!        04-06, introduction of EDK for Fm and Fh in stable case - F Bouyssel
!        07-01, optimisation liee a LSMOOTHA - F Bouyssel - C Loo
!-----------------------------------------------------------------------
USE PARKIND1  ,ONLY : JPIM     ,JPRB
USE YOMHOOK   ,ONLY : LHOOK,   DR_HOOK

USE YOMPHY   , ONLY : LCVPP    ,LNEIGE
USE YOMCST   , ONLY : RG       ,RD       ,RV       ,RCPD     ,&
 & RCPV     ,RKAPPA   ,RETV     ,RCW      ,RCS      ,&
 & RLVTT    ,RLSTT    ,RTT      ,RALPW    ,RBETW    ,&
 & RGAMW    ,RALPS    ,RBETS    ,RGAMS    ,RALPD    ,&
 & RBETD    ,RGAMD  
USE YOMPHY0  , ONLY : ALMAV    ,BEDIFV   ,EDB      ,EDC      ,&
 & EDD      ,UHDIFV   ,USURIC   ,VKARMN   ,GRCVPP   ,&
 & USURICL  ,USURICE  ,USURIDE  ,USURID   ,EDK
USE YOMSIMPHL, ONLY : LSMOOTHA

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 
INTEGER(KIND=JPIM),INTENT(IN)    :: KTDIA 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PAPHI5(KLON,0:KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PAPHIF5(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PAPRS5(KLON,0:KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PAPRSF5(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PQ5(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PT5(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PU5(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PV5(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PAPHI(KLON,0:KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PAPHIF(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PAPRS(KLON,0:KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PAPRSF(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PQ(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PT(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PU(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PV(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PQS(KLON) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PTS(KLON) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PGZ0(KLON) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PKTROV5(KLON,0:KLEV) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PKUROV5(KLON,0:KLEV) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PXTROV5(KLON,0:KLEV) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PXUROV5(KLON,0:KLEV) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PKTROV(KLON,0:KLEV) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PKUROV(KLON,0:KLEV) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PXTROV(KLON,0:KLEV) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PXUROV(KLON,0:KLEV) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PCDROV5(KLON) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PCHROV5(KLON) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PXDROV5(KLON) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PXHROV5(KLON) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PCDROV(KLON) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PCHROV(KLON) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PXDROV(KLON) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PXHROV(KLON) 
CHARACTER(LEN=7)  ,INTENT(IN)    :: CDLOCK 
REAL(KIND=JPRB) :: ZLSCPE(KLON,KLEV),ZQSAT(KLON,KLEV),ZLH(KLON,KLEV),ZR(KLON,KLEV)
REAL(KIND=JPRB) :: ZCDNH(KLON),ZDPHI(KLON),ZRTI(KLON),ZSTA(KLON)&
 & ,ZU(KLON),ZRS(KLON),ZSTAB(KLON),ZSTAC(KLON)&
 & ,ZCP(KLON),ZPCD(KLON),ZPCDN(KLON),ZPCH(KLON)&
 & ,ZSTAH(KLON),ZSTACH(KLON)  

REAL(KIND=JPRB) :: ZLSCPE5(KLON,KLEV),ZQSAT5(KLON,KLEV),ZLH5(KLON,KLEV),ZR5(KLON,KLEV)
REAL(KIND=JPRB) :: ZCDNH5(KLON),ZDPHI5(KLON),ZRTI5(KLON),ZSTA5(KLON)&
 & ,ZU5(KLON),ZSTAB5(KLON),ZSTAC5(KLON)&
 & ,ZCP5(KLON),ZPCD5(KLON),ZPCDN5(KLON),ZPCH5(KLON)&
 & ,ZSTAH5(KLON),ZSTACH5(KLON)  

INTEGER(KIND=JPIM) :: JLEV, JLON

REAL(KIND=JPRB) :: Z2B, Z3B, Z3BC, Z3BCF, ZAUX, ZAUX5, &
 & ZCD, ZCD5, ZCH, ZCH5, ZCIS, ZCIS5, ZCK, ZCK5, &
 & ZDELTA, ZDID, ZDID5, ZDIDP, ZDIDP5, ZDIFV, ZDIH, ZDIH5, &
 & ZDIHP, ZDIHP5, ZDS, ZDS5, ZDTETA, ZDTETA5, ZEPS1, &
 & ZESP1, ZESP15, ZEW1, ZEW15, ZGLMT2, ZGLMT25, &
 & ZGLMU2, ZGLMU25, ZGLT, ZGLU, ZIS, ZLOI, ZLOI5, &
 & ZLOS, ZLOS5, ZPFD, ZPFD5, ZRCVPP, ZRLTLU, ZRVMD, ZRZD, &
 & ZRZD5, ZRZH, ZRZH5, ZXX, ZZ, ZZ5, ZZB, ZZC, ZZC5, ZZD, ZZD5, &
 & ZEDIFV, ZDIFT, ZZUSURIC, ZZIXP, ZHS, ZHS5, ZZT, ZZT5, &
 & ZPFH, ZPFH5, ZUSURIC, ZUSURIC5, ZUSURID, ZUSURID5, ZIXP, ZIXP5  
REAL(KIND=JPRB) :: ZHOOK_HANDLE

#include "abor1.intfb.h"

#include "fcttrm.h"
#include "fcttrmtl.h"

!     CHECK RELIABILITY OF INPUT ARGUMENTS.

IF (LHOOK) CALL DR_HOOK('ACTSECTL',0,ZHOOK_HANDLE)
IF(CDLOCK /= 'TSECTL ') CALL ABOR1('BAD NUMBER OF ARGUMENTS!')

!     ----------------------------------------------------------------
IF (LSMOOTHA) THEN
!     ----------------------------------------------------------------

!*
!     ------------------------------------------------------------------
!     I - AUXILIARY CONSTANTS.

ZRVMD=RV-RD

!*
!     ------------------------------------------------------------------
!     II - COMPUTATION OF DERIVED PARAMETERS AND SECURITY CONSTANT (FOR
!     THE SQUARE OF THE WIND SHEAR).

Z2B=2.0_JPRB*EDB
Z3B=3._JPRB*EDB
Z3BC=3._JPRB*EDB*EDC
Z3BCF=EDB*EDC*VKARMN**2/SQRT(3._JPRB)
ZEDIFV=BEDIFV/SQRT(3._JPRB)
ZRLTLU=1.5_JPRB*EDD
ZDIFV=UHDIFV/(RG*VKARMN)
ZDIFT=ZDIFV/SQRT(3._JPRB)
ZRCVPP=1.0_JPRB/GRCVPP
ZZUSURIC=USURIC*USURICL

IF(USURID == 0.0_JPRB) THEN
  ZEDIFV=BEDIFV
  ZZIXP=1.0_JPRB
ELSE
  ZZIXP=3._JPRB
ENDIF

ZEPS1=1.E-04_JPRB

!*
!     ----------------------------------------------------------------
!     III - COMPUTATION OF SPECIFIC HUMIDITY OF SATURATION AND
!     EFFECTIVE RATIO OF L AND Cp FOR CONDENSATION/EVAPORATION
!     COMPUTATION OF GASS CONSTANT FOR AIR

! - TEMPORARY(S) 2D (1:KLEV) .

! ZLH5      : LATENT HEAT
! ZQSAT5    : SPECIFIC HUMIDITY OF SATURATION
! ZLSCPE5   : EFFECTIVE RATIO OF L AND Cp FOR CONDENSATION/EVAPORATION
! ZR5      : GASS CONSTANT FOR AIR

! - TEMPORARY 1D

! ZCP5      : VALUE OF ATMOSPHERIC Cp

DO JLEV=KTDIA,KLEV
  DO JLON=KIDIA,KFDIA

    ZCP5(JLON)=RCPD*(1.0_JPRB-PQ5(JLON,JLEV))+RCPV*PQ5(JLON,JLEV)
    ZR5(JLON,JLEV)=RD*(1.0_JPRB-PQ5(JLON,JLEV))+RV*PQ5(JLON,JLEV)

!     SNOW OPTION DEPENDENT COMPUTATIONS.

    IF (LNEIGE) THEN
      ZDELTA=MAX(0.0_JPRB,SIGN(1.0_JPRB,RTT-PT5(JLON,JLEV)))
    ELSE
      ZDELTA=0.0_JPRB
    ENDIF

!     CALL TO THE DEFINED FUNCTION TO COMPUTE LH.

    ZLH5(JLON,JLEV)= FOLH (PT5(JLON,JLEV),ZDELTA)

!     COMPUTATION OF EFFECTIVE RATIO OF L AND Cp FOR COND./EVAP.

    ZLSCPE5(JLON,JLEV)=ZLH5(JLON,JLEV)/ZCP5(JLON)

!     COMPUTATION OF Qsat(PT)

    ZEW15= FOEW (PT5(JLON,JLEV),ZDELTA)
    ZESP15=ZEW15/PAPRSF5(JLON,JLEV)
    ZQSAT5(JLON,JLEV)= FOQS (ZESP15)

  ENDDO
ENDDO

!*
!     ------------------------------------------------------------------
!     IV - COMPUTATION OF SURFACE EXCHANGE COEFFICIENTS PLUS THEIR
!     AMPLIFICATION  FACTOR IF "ANTI-FIBRILLATION" IS ACTIVATED .

!*
!          COMPUTATION OF THE THICKNESS OF THE SBL (IN GEOPOTENTIAL).

! - TEMPORARY(S) 2D .

! ZDPHI     : GEOPOTENTIAL THICKNESS OF THE SURFACE LEVEL.

DO JLON=KIDIA,KFDIA
  ZDPHI5(JLON)=PAPHIF5(JLON,KLEV)-PAPHI5(JLON,KLEV)
ENDDO

!*
!          EFFECTIVE CALCULATIONS OF THE SURFACE CHARACTERISTICS.

! - TEMPORARY(S) 1D .

! ZRS       : GASS CONSTANT FOR AIR AT THE SURFACE.
! ZPCDN5    : EXCHANGE COEF. AT SURFACE LEVEL IN NEUTRAL CONDITION.

DO JLON=KIDIA,KFDIA

  ZRS(JLON)=RD+ZRVMD*PQS(JLON)

!     GEOMETRIC CALCULATIONS.

  ZRZD5=1.0_JPRB+ZDPHI5(JLON)/PGZ0(JLON)
  ZPCDN5(JLON)=(VKARMN/LOG(ZRZD5))**2

!     PRELIMINARY COMPUTATIONS NECESSARY FOR THE DETERMINATION OF
!     EXCHANGE COEFFICIENTS CD AND CH

! - TEMPORARY(S) 1D .

! ZCDNH5    : NEUTRAL SURFACE THERMAL EXCHANGE COEFFICIENT.

  ZRZH5=ZRZD5
  ZCDNH5(JLON)=ZPCDN5(JLON)
  ZCD5=1.0_JPRB
  ZCH5=1.0_JPRB

!     WIND SHEAR.

! - TEMPORARY(S) 1D .

! ZU5    : SURFACE WIND SPEED.
! ZPCD5     : EXCHANGE COEFFICIENT AT SURFACE LEVEL FOR U AND V.

  ZCIS5=MAX(ZEPS1,PU5(JLON,KLEV)**2+PV5(JLON,KLEV)**2)
  ZU5(JLON)=SQRT(ZCIS5)

!     STABILITY COMPUTATION.

! - TEMPORARY(S) 1D .

! ZRTI5    : INVERSE OF R*T.
! ZSTA5     : APPROXIMATION OF DELTA(PHI)*DELTA(LN(THETA)).

  ZRTI5(JLON)=2.0_JPRB/(ZR5(JLON,KLEV)*PT5(JLON,KLEV)&
   & +RKAPPA*ZDPHI5(JLON)+ZRS(JLON)*PTS(JLON))  
  ZSTA5(JLON)=ZDPHI5(JLON)*(ZR5(JLON,KLEV)*PT5(JLON,KLEV)&
   & +RKAPPA*ZDPHI5(JLON)-ZRS(JLON)*PTS(JLON))&
   & *ZRTI5(JLON)  
  ZSTAH5(JLON)=ZSTA5(JLON)/(1.0_JPRB+ZZIXP*ZZUSURIC&
   & *MAX(0.0_JPRB,ZSTA5(JLON))/ZCIS5)**(1.0_JPRB/ZZIXP)  
  ZSTA5(JLON)=ZSTA5(JLON)/(1.0_JPRB+MAX(0.0_JPRB,ZSTA5(JLON))*ZZUSURIC/ZCIS5)
  ZSTAB5(JLON)=MAX(0.0_JPRB,SIGN(1.0_JPRB,ZSTA5(JLON)))
  ZSTAC5(JLON)=ABS(ZSTA5(JLON))
  ZSTACH5(JLON)=ABS(ZSTAH5(JLON))

!     COMMON COMPUTATIONS FOR MOMENTUM AND ENERGY.

  ZDS5=SQRT(ZCIS5+(EDD/EDK)*ZSTAC5(JLON))
  ZHS5=SQRT(ZCIS5+EDD*EDK*ZSTACH5(JLON))
  ZDIDP5=ZU5(JLON)+ZCD5*Z3BC*ZPCDN5(JLON)*SQRT(ZSTAC5(JLON)*ZRZD5)
  ZDID5=1.0_JPRB/ZDIDP5
  ZDIHP5=ZU5(JLON)+ZCH5*Z3BC*ZCDNH5(JLON)*SQRT(ZSTAC5(JLON)*ZRZH5)
  ZDIH5=1.0_JPRB/ZDIHP5

!     COMPUTATIONS FOR MOMENTUM OF CD AND OF ITS PRODUCT BY DENSITY
!     TIME WIND SPEED.

  ZLOS5=ZCIS5*ZDS5/(ZU5(JLON)*ZDS5+Z2B*ZSTAC5(JLON))
  ZLOI5=ZU5(JLON)-Z2B*ZSTA5(JLON)*ZDID5
  ZPCD5(JLON)=(ZLOI5+ZSTAB5(JLON)*(ZLOS5-ZLOI5))*ZPCDN5(JLON)/ZU5(JLON)

!     THE SAME FOR TEMPERATURE AND HUMIDITY.

  ZLOS5=ZCIS5**2/(ZU5(JLON)*ZCIS5+Z3B*ZSTACH5(JLON)*ZHS5)
  ZLOI5=ZU5(JLON)-Z3B*ZSTA5(JLON)*ZDIH5
  ZPCH5(JLON)=(ZLOI5+ZSTAB5(JLON)*(ZLOS5-ZLOI5))*ZCDNH5(JLON)/ZU5(JLON)

ENDDO

DO JLON=KIDIA,KFDIA

!     COMPUTATION OF THE EXCHANGE COEFFICIENTS MULTIPLIED BY DENSITY
!     AND WIND SPEED.

  PCDROV5(JLON)=ZPCD5(JLON)*ZU5(JLON)*PAPRS5(JLON,KLEV)*ZRTI5(JLON)
  PCHROV5(JLON)=ZPCH5(JLON)*ZU5(JLON)*PAPRS5(JLON,KLEV)*ZRTI5(JLON)
  PCDROV(JLON)=0.0_JPRB
  PCHROV(JLON)=0.0_JPRB

!     NO ANTI-FIBRILLATION.

  PXDROV5(JLON)=1.0_JPRB
  PXHROV5(JLON)=1.0_JPRB
  PXDROV(JLON)=0.0_JPRB
  PXHROV(JLON)=0.0_JPRB

ENDDO

!*
!     ------------------------------------------------------------------
!     V - COMPUTATION OF VERTICAL EXCHANGE COEFFICIENTS,
!     AS WELL AS OF THE "ANTI-FIBRILLATION" AMPLIFICATION
!     FACTORS OF THE FORMERS .

!*
!          GOING TO GEOPOTENTIAL FOR ASYMPTOTIC MIXING LENGTHS.

ZGLU=RG*ALMAV
ZGLT=ZGLU*ZRLTLU

!*
!           PASSIVE LOOP ON VERTICAL LEVELS.

DO JLEV=KTDIA,KLEV-1

!*
!          EFFECTIVE CALCULATIONS.

  DO JLON=KIDIA,KFDIA

!     GEOMETRIC COMPUTATIONS, THE MULTIPLYING FACTOR ZPFD (POTENTIALLY
!     DIFFERENT OF 1) FOR THE DIFFUSION'S VERTICAL PROFILE DEPENDS UPON
!     THE CHOICE OF UHDIFV AND BEDIFV.

    ZZ5=VKARMN*(0.5_JPRB*(PAPHIF5(JLON,JLEV)+PAPHIF5(JLON,JLEV+1))&
     & -PAPHI5(JLON,KLEV)+PGZ0(JLON))  
    ZZT5=VKARMN*(0.5_JPRB*(PAPHIF5(JLON,JLEV)+PAPHIF5(JLON,JLEV+1))&
     & -PAPHI5(JLON,KLEV)+PGZ0(JLON))  
    ZPFD5=MAX(0.0_JPRB,BEDIFV+(1.0_JPRB-BEDIFV)/(1.0_JPRB+(ZDIFV*ZZ5)**2))
    ZPFH5=MAX(0.0_JPRB,ZEDIFV+(1.0_JPRB-ZEDIFV)/(1.0_JPRB+(ZDIFT*ZZT5)**2))
    ZGLMU25=(ZZ5*ZGLU*ZPFD5/(ZGLU+ZZ5))**2
    ZGLMT25=(ZZT5*ZGLT*ZPFH5/(ZGLT+ZZT5))*(ZZ5*ZGLU*ZPFD5/(ZGLU+ZZ5))
    ZCK5=Z3BCF*(ZGLT*ZPFH5/(ZGLT+ZZT5))*(ZGLU*ZPFD5/(ZGLU+ZZ5))
    ZDPHI5(JLON)=PAPHIF5(JLON,JLEV)-PAPHIF5(JLON,JLEV+1)

!     WIND SHEAR.

    ZCIS5=MAX(ZEPS1,(PU5(JLON,JLEV)-PU5(JLON,JLEV+1))**2 &
     & +(PV5(JLON,JLEV)-PV5(JLON,JLEV+1))**2)  
    ZU5(JLON)=SQRT(ZCIS5)

!     PRELIMINARY STABILITY COMPUTATION.

    ZDTETA5=ZR5(JLON,JLEV)*PT5(JLON,JLEV)&
     & -ZR5(JLON,JLEV+1)*PT5(JLON,JLEV+1)&
     & +RKAPPA*ZDPHI5(JLON)  

!     CORRECTION FOR SHALLOW CONVECTION (OPTIONAL).

    IF (LCVPP) THEN
      ZAUX5=ZRCVPP*MIN(0.0_JPRB,PQ5(JLON,JLEV)-ZQSAT5(JLON,JLEV)&
       & -PQ5(JLON,JLEV+1)&
       & +ZQSAT5(JLON,JLEV+1))*(0.5_JPRB*(ZLSCPE5(JLON,JLEV)&
       & +ZLSCPE5(JLON,JLEV+1)))*MAX(0.0_JPRB,SIGN(1.0_JPRB,RD &
       & *(PQ5(JLON,JLEV+1)-PQ5(JLON,JLEV))&
       & *(0.5_JPRB*(ZLSCPE5(JLON,JLEV)&
       & +ZLSCPE5(JLON,JLEV+1)))-ZDTETA5))  
    ELSE
      ZAUX5=0.0_JPRB
    ENDIF

!     STABILITY COMPUTATION.

    ZRTI5(JLON)=2.0_JPRB/(ZR5(JLON,JLEV)*PT5(JLON,JLEV)+ZR5(JLON,JLEV+1)&
     & *PT5(JLON,JLEV+1))  
    ZSTA5(JLON)=ZDPHI5(JLON)*(ZDTETA5+RD*ZAUX5)*ZRTI5(JLON)
    ZUSURIC5=USURIC*(1.0_JPRB+(USURICL-1.0_JPRB)*((ZGLT*ZPFH5)/(ZGLT+ZZT5))**USURICE)
    ZUSURID5=USURID*(1.0_JPRB+1.0_JPRB/((ZZT5*ZDIFT)*(ZZ5*ZDIFV)))**USURIDE
    ZIXP5=(1.0_JPRB+3._JPRB*ZUSURID5*MAX(0.0_JPRB,ZSTA5(JLON))/ZCIS5) &
     & /(1.0_JPRB+ZUSURID5*MAX(0.0_JPRB,ZSTA5(JLON))/ZCIS5)  
    ZSTAH5(JLON)=ZSTA5(JLON)/(1.0_JPRB+ZIXP5*ZUSURIC5 &
     & *MAX(0.0_JPRB,ZSTA5(JLON))/ZCIS5)**(1.0_JPRB/ZIXP5)  
    ZSTA5(JLON)=ZSTA5(JLON)/(1.0_JPRB+MAX(0.0_JPRB,ZSTA5(JLON))*ZUSURIC5/ZCIS5)
    ZIS=MAX(0.0_JPRB,SIGN(1.0_JPRB,ZSTA5(JLON)))
    ZSTAC5(JLON)=ABS(ZSTA5(JLON))
    ZSTACH5(JLON)=ABS(ZSTAH5(JLON))
    
!     COMMON COMPUTATIONS FOR MOMENTUM AND ENERGY.

    ZDS5=SQRT(ZCIS5+(EDD/EDK)*ZSTAC5(JLON))
    ZHS5=SQRT(ZCIS5+EDD*EDK*ZSTACH5(JLON))

!     COMPUTATIONS FOR THE WIND COMPONENTS.

    ZLOS5=ZCIS5*ZDS5/(ZU5(JLON)*ZDS5+Z2B*ZSTAC5(JLON))
    ZLOI5=ZU5(JLON)-Z2B*ZSTA5(JLON)/(ZU5(JLON)+ZCK5*SQRT(ZSTAC5(JLON)))
    PKUROV5(JLON,JLEV)=(ZLOI5+ZIS*(ZLOS5-ZLOI5))*ZGLMU25 &
     & *PAPRS5(JLON,JLEV)*ZRTI5(JLON)/ZDPHI5(JLON)**2  

!     COMPUTATIONS FOR TEMPERATURE AND HUMIDITY.

    ZLOS5=ZCIS5**2/(ZU5(JLON)*ZCIS5+Z3B*ZSTACH5(JLON)*ZHS5)
    ZLOI5=ZU5(JLON)-Z3B*ZSTA5(JLON)/(ZU5(JLON)+ZCK5*SQRT(ZSTAC5(JLON)))
    PKTROV5(JLON,JLEV)=(ZLOI5+ZIS*(ZLOS5-ZLOI5))*ZGLMT25 &
     & *PAPRS5(JLON,JLEV)*ZRTI5(JLON)/ZDPHI5(JLON)**2  

    PKUROV(JLON,JLEV)=0.0_JPRB
    PKTROV(JLON,JLEV)=0.0_JPRB

!     NO ANTI-FIBRILLATION.

    PXUROV5(JLON,JLEV)=1.0_JPRB
    PXTROV5(JLON,JLEV)=1.0_JPRB
    PXUROV(JLON,JLEV)=0.0_JPRB
    PXTROV(JLON,JLEV)=0.0_JPRB

  ENDDO

ENDDO

!     ----------------------------------------------------------------
ELSE
!     ----------------------------------------------------------------

!*
!     ------------------------------------------------------------------
!     I - AUXILIARY CONSTANTS.

ZRVMD=RV-RD

!*
!     ------------------------------------------------------------------
!     II - COMPUTATION OF DERIVED PARAMETERS AND SECURITY CONSTANT (FOR
!     THE SQUARE OF THE WIND SHEAR).

Z2B=2.0_JPRB*EDB
Z3B=3._JPRB*EDB
Z3BC=3._JPRB*EDB*EDC
Z3BCF=EDB*EDC*VKARMN**2/SQRT(3._JPRB)
ZEDIFV=BEDIFV/SQRT(3._JPRB)
ZRLTLU=1.5_JPRB*EDD
ZDIFV=UHDIFV/(RG*VKARMN)
ZDIFT=ZDIFV/SQRT(3._JPRB)
ZRCVPP=1.0_JPRB/GRCVPP
ZZUSURIC=USURIC*USURICL

IF(USURID == 0.0_JPRB) THEN
  ZEDIFV=BEDIFV
  ZZIXP=1.0_JPRB
ELSE
  ZZIXP=3._JPRB
ENDIF

ZEPS1=1.E-04_JPRB

!*
!     ----------------------------------------------------------------
!     III - COMPUTATION OF SPECIFIC HUMIDITY OF SATURATION AND
!     EFFECTIVE RATIO OF L AND Cp FOR CONDENSATION/EVAPORATION
!     COMPUTATION OF GASS CONSTANT FOR AIR

! - TEMPORARY(S) 2D (1:KLEV) .

! ZLH       : LATENT HEAT
! ZQSAT     : SPECIFIC HUMIDITY OF SATURATION
! ZLSCPE    : EFFECTIVE RATIO OF L AND Cp FOR CONDENSATION/EVAPORATION
! ZR       : GASS CONSTANT FOR AIR

! - TEMPORARY 1D

! ZCP       : VALUE OF ATMOSPHERIC Cp

! The same but for trajectory
! ---------------------------
! - TEMPORARY(S) 2D (1:KLEV) .

! ZLH5      : LATENT HEAT
! ZQSAT5    : SPECIFIC HUMIDITY OF SATURATION
! ZLSCPE5   : EFFECTIVE RATIO OF L AND Cp FOR CONDENSATION/EVAPORATION
! ZR5      : GASS CONSTANT FOR AIR

! - TEMPORARY 1D

! ZCP5      : VALUE OF ATMOSPHERIC Cp

DO JLEV=KTDIA,KLEV
  DO JLON=KIDIA,KFDIA

    ZCP5(JLON)=RCPD*(1.0_JPRB-PQ5(JLON,JLEV))+RCPV*PQ5(JLON,JLEV)
    ZCP(JLON)=RCPD*(-PQ(JLON,JLEV))+RCPV*PQ(JLON,JLEV)

    ZR5(JLON,JLEV)=RD*(1.0_JPRB-PQ5(JLON,JLEV))+RV*PQ5(JLON,JLEV)
    ZR(JLON,JLEV)=RD*(-PQ(JLON,JLEV))+RV*PQ(JLON,JLEV)

!     SNOW OPTION DEPENDENT COMPUTATIONS.

    IF (LNEIGE) THEN
      ZDELTA=MAX(0.0_JPRB,SIGN(1.0_JPRB,RTT-PT5(JLON,JLEV)))
    ELSE
      ZDELTA=0.0_JPRB
    ENDIF

!     CALL TO THE DEFINED FUNCTION TO COMPUTE LH.

    ZLH5(JLON,JLEV)= FOLH (PT5(JLON,JLEV),ZDELTA)
    ZLH(JLON,JLEV)= FOLHTL (PT(JLON,JLEV),ZDELTA)

!     COMPUTATION OF EFFECTIVE RATIO OF L AND Cp FOR COND./EVAP.

    ZLSCPE5(JLON,JLEV)=ZLH5(JLON,JLEV)/ZCP5(JLON)
    ZLSCPE(JLON,JLEV)=ZLH(JLON,JLEV)/ZCP5(JLON)&
     & -(ZLH5(JLON,JLEV)/ZCP5(JLON)**2)*ZCP(JLON)  

!     COMPUTATION OF Qsat(PT)

    ZEW15= FOEW (PT5(JLON,JLEV),ZDELTA)
    ZEW1= FOEWTL (PT(JLON,JLEV),PT5(JLON,JLEV),ZDELTA)

    ZESP15=ZEW15/PAPRSF5(JLON,JLEV)
    ZESP1=ZEW1/PAPRSF5(JLON,JLEV)&
     & -(ZEW15/PAPRSF5(JLON,JLEV)**2)*PAPRSF(JLON,JLEV)  

    ZQSAT5(JLON,JLEV)= FOQS (ZESP15)
    IF ((1.0_JPRB-ZESP15) > 0.0_JPRB) THEN
      ZQSAT(JLON,JLEV)= FOQSTL1 (ZESP1,ZESP15)
    ELSE
      ZQSAT(JLON,JLEV)= FOQSTL2 (ZESP1,ZESP15)
    ENDIF

  ENDDO
ENDDO

!*
!     ------------------------------------------------------------------
!     IV - COMPUTATION OF SURFACE EXCHANGE COEFFICIENTS PLUS THEIR
!     AMPLIFICATION  FACTOR IF "ANTI-FIBRILLATION" IS ACTIVATED .

!*
!          COMPUTATION OF THE THICKNESS OF THE SBL (IN GEOPOTENTIAL).

! - TEMPORARY(S) 2D .

! ZDPHI     : GEOPOTENTIAL THICKNESS OF THE SURFACE LEVEL.

DO JLON=KIDIA,KFDIA
  ZDPHI5(JLON)=PAPHIF5(JLON,KLEV)-PAPHI5(JLON,KLEV)
  ZDPHI(JLON)=PAPHIF(JLON,KLEV)-PAPHI(JLON,KLEV)
ENDDO

!*
!          EFFECTIVE CALCULATIONS OF THE SURFACE CHARACTERISTICS.

! - TEMPORARY(S) 1D .

! ZPCDN     : EXCHANGE COEF. AT SURFACE LEVEL IN NEUTRAL CONDITION.
! ZRS       : GASS CONSTANT FOR AIR AT THE SURFACE.

! The same but for the trajectory
! -------------------------------
! ZPCDN5    : EXCHANGE COEF. AT SURFACE LEVEL IN NEUTRAL CONDITION.

DO JLON=KIDIA,KFDIA

  ZRS(JLON)=RD+ZRVMD*PQS(JLON)

!     GEOMETRIC CALCULATIONS.

  ZRZD5=1.0_JPRB+ZDPHI5(JLON)/PGZ0(JLON)
  ZRZD=ZDPHI(JLON)/PGZ0(JLON)

  ZPCDN5(JLON)=(VKARMN/LOG(ZRZD5))**2
  ZPCDN(JLON)=-(2.0_JPRB*VKARMN**2/(ZRZD5*LOG(ZRZD5)**3))*ZRZD

!     PRELIMINARY COMPUTATIONS NECESSARY FOR THE DETERMINATION OF
!     EXCHANGE COEFFICIENTS CD AND CH

! - TEMPORARY(S) 1D .

! ZCDNH     : NEUTRAL SURFACE THERMAL EXCHANGE COEFFICIENT.

! The same but for trajectory
! ---------------------------
! ZCDNH5    : NEUTRAL SURFACE THERMAL EXCHANGE COEFFICIENT.

  ZRZH5=ZRZD5
  ZRZH=ZRZD

  ZCDNH5(JLON)=ZPCDN5(JLON)
  ZCDNH(JLON)=ZPCDN(JLON)

  ZCD5=1.0_JPRB
  ZCD=0.0_JPRB
  ZCH5=1.0_JPRB
  ZCH=0.0_JPRB

!     WIND SHEAR.

! - TEMPORARY(S) 1D .

! ZU        : SURFACE WIND SPEED.
! ZPCD      : EXCHANGE COEFFICIENT AT SURFACE LEVEL FOR U AND V.

! The same but for trajectory
! ---------------------------
! ZU5    : SURFACE WIND SPEED.
! ZPCD5     : EXCHANGE COEFFICIENT AT SURFACE LEVEL FOR U AND V.

  ZCIS5=MAX(ZEPS1,PU5(JLON,KLEV)**2+PV5(JLON,KLEV)**2)
  IF ((PU5(JLON,KLEV)**2+PV5(JLON,KLEV)**2) > ZEPS1) THEN
    ZCIS=2.0_JPRB*PU5(JLON,KLEV)*PU(JLON,KLEV)&
     & +2.0_JPRB*PV5(JLON,KLEV)*PV(JLON,KLEV)  
  ELSE
    ZCIS=0.0_JPRB
  ENDIF

  ZU5(JLON)=SQRT(ZCIS5)
  ZU(JLON)=ZCIS/(2.0_JPRB*SQRT(ZCIS5))

!     STABILITY COMPUTATION.

! - TEMPORARY(S) 1D .

! ZRTI      : INVERSE OF R*T.
! ZSTA      : APPROXIMATION OF DELTA(PHI)*DELTA(LN(THETA)).

! The same but for trajectory
! ---------------------------
! ZRTI5    : INVERSE OF R*T.
! ZSTA5     : APPROXIMATION OF DELTA(PHI)*DELTA(LN(THETA)).

  ZRTI5(JLON)=2.0_JPRB/(ZR5(JLON,KLEV)*PT5(JLON,KLEV)&
   & +RKAPPA*ZDPHI5(JLON)+ZRS(JLON)*PTS(JLON))  
  ZRTI(JLON)=(-2.0_JPRB*ZR5(JLON,KLEV)*PT(JLON,KLEV)&
   & -2.0_JPRB*PT5(JLON,KLEV)*ZR(JLON,KLEV)&
   & -2.0_JPRB*RKAPPA*ZDPHI(JLON))&
   & /(ZR5(JLON,KLEV)*PT5(JLON,KLEV)&
   & +RKAPPA*ZDPHI5(JLON)+ZRS(JLON)*PTS(JLON))**2  

  ZSTA5(JLON)=ZDPHI5(JLON)*(ZR5(JLON,KLEV)*PT5(JLON,KLEV)&
   & +RKAPPA*ZDPHI5(JLON)-ZRS(JLON)*PTS(JLON))&
   & *ZRTI5(JLON)  
  ZSTA(JLON)=(ZR5(JLON,KLEV)*PT5(JLON,KLEV)&
   & +RKAPPA*ZDPHI5(JLON)-ZRS(JLON)*PTS(JLON))&
   & *ZRTI5(JLON)*ZDPHI(JLON)&
   & +ZDPHI5(JLON)*ZR5(JLON,KLEV)*ZRTI5(JLON)&
   & *PT(JLON,KLEV)&
   & +ZDPHI5(JLON)*PT5(JLON,KLEV)*ZRTI5(JLON)&
   & *ZR(JLON,KLEV)&
   & +RKAPPA*ZDPHI5(JLON)*ZRTI5(JLON)*ZDPHI(JLON)&
   & +(ZR5(JLON,KLEV)*PT5(JLON,KLEV)&
   & +RKAPPA*ZDPHI5(JLON)-ZRS(JLON)*PTS(JLON))&
   & *ZDPHI5(JLON)*ZRTI(JLON)  

  IF (ZSTA5(JLON) > 0.0_JPRB) THEN
    ZSTAH(JLON)=ZSTA(JLON) &
     & /(1.0_JPRB+ZZIXP*ZZUSURIC*ZSTA5(JLON)/ZCIS5)**(1.0_JPRB/ZZIXP) &
     & -ZSTA5(JLON)*ZZUSURIC*((ZSTA(JLON)*ZCIS5-ZSTA5(JLON)*ZCIS)/ZCIS5**2) &
     & /(1.0_JPRB+ZZIXP*ZZUSURIC*ZSTA5(JLON)/ZCIS5)**(1.0_JPRB+1.0_JPRB/ZZIXP)  
  ELSE
    ZSTAH(JLON)=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

  ZPCH5(JLON)=(ZLOI5+ZSTAB5(JLON)*(ZLOS5-ZLOI5))*ZCDNH5(JLON)/ZU5(JLON)
  ZPCH(JLON)=((1.0_JPRB-ZSTAB5(JLON))*ZCDNH5(JLON)/ZU5(JLON))*ZLOI &
   & +((ZLOS5-ZLOI5)*ZCDNH5(JLON)/ZU5(JLON))*ZSTAB(JLON)&
   & +(ZSTAB5(JLON)*ZCDNH5(JLON)/ZU5(JLON))*ZLOS &
   & +((ZLOI5+ZSTAB5(JLON)*(ZLOS5-ZLOI5))/ZU5(JLON))&
   & *ZCDNH(JLON)&
   & -((ZLOI5+ZSTAB5(JLON)*(ZLOS5-ZLOI5))*ZCDNH5(JLON)&
   & /ZU5(JLON)**2)*ZU(JLON)  

!     NO ANTI-FIBRILLATION.

  PXDROV5(JLON)=1.0_JPRB
  PXDROV(JLON)=0.0_JPRB

  PXHROV5(JLON)=1.0_JPRB
  PXHROV(JLON)=0.0_JPRB

ENDDO

DO JLON=KIDIA,KFDIA

!     COMPUTATION OF THE EXCHANGE COEFFICIENTS MULTIPLIED BY DENSITY
!     AND WIND SPEED.

  PCDROV5(JLON)=ZPCD5(JLON)*ZU5(JLON)*PAPRS5(JLON,KLEV)*ZRTI5(JLON)
  PCDROV(JLON)=ZU5(JLON)*PAPRS5(JLON,KLEV)*ZRTI5(JLON)&
   & *ZPCD(JLON)&
   & +ZPCD5(JLON)*PAPRS5(JLON,KLEV)*ZRTI5(JLON)&
   & *ZU(JLON)&
   & +ZPCD5(JLON)*ZU5(JLON)*PAPRS5(JLON,KLEV)&
   & *ZRTI(JLON)&
   & +ZPCD5(JLON)*ZU5(JLON)*ZRTI5(JLON)&
   & *PAPRS(JLON,KLEV)  

  PCHROV5(JLON)=ZPCH5(JLON)*ZU5(JLON)*PAPRS5(JLON,KLEV)*ZRTI5(JLON)
  PCHROV(JLON)=ZU5(JLON)*PAPRS5(JLON,KLEV)*ZRTI5(JLON)&
   & *ZPCH(JLON)&
   & +ZPCH5(JLON)*PAPRS5(JLON,KLEV)*ZRTI5(JLON)&
   & *ZU(JLON)&
   & +ZPCH5(JLON)*ZU5(JLON)*PAPRS5(JLON,KLEV)&
   & *ZRTI(JLON)&
   & +ZPCH5(JLON)*ZU5(JLON)*ZRTI5(JLON)&
   & *PAPRS(JLON,KLEV)  

ENDDO

!*
!     ------------------------------------------------------------------
!     V - COMPUTATION OF VERTICAL EXCHANGE COEFFICIENTS,
!     AS WELL AS OF THE "ANTI-FIBRILLATION" AMPLIFICATION
!     FACTORS OF THE FORMERS .

!*
!          GOING TO GEOPOTENTIAL FOR ASYMPTOTIC MIXING LENGTHS.

ZGLU=RG*ALMAV
ZGLT=ZGLU*ZRLTLU

!*
!           PASSIVE LOOP ON VERTICAL LEVELS.

DO JLEV=KTDIA,KLEV-1

!*
!          EFFECTIVE CALCULATIONS.

  DO JLON=KIDIA,KFDIA

!     GEOMETRIC COMPUTATIONS, THE MULTIPLYING FACTOR ZPFD (POTENTIALLY
!     DIFFERENT OF 1) FOR THE DIFFUSION'S VERTICAL PROFILE DEPENDS UPON
!     THE CHOICE OF UHDIFV AND BEDIFV.

    ZZ5=VKARMN*(0.5_JPRB*(PAPHIF5(JLON,JLEV)+PAPHIF5(JLON,JLEV+1))&
     & -PAPHI5(JLON,KLEV)+PGZ0(JLON))  
    ZZ=VKARMN*(0.5_JPRB*PAPHIF(JLON,JLEV)+0.5_JPRB*PAPHIF(JLON,JLEV+1)&
     & -PAPHI(JLON,KLEV))  

    ZZT5=VKARMN*(0.5_JPRB*(PAPHIF5(JLON,JLEV)+PAPHIF5(JLON,JLEV+1))&
     & -PAPHI5(JLON,KLEV)+PGZ0(JLON))  
    ZZT=VKARMN*(0.5_JPRB*PAPHIF(JLON,JLEV)+0.5_JPRB*PAPHIF(JLON,JLEV+1)&
     & -PAPHI(JLON,KLEV))  

    ZPFD5=MAX(0.0_JPRB,BEDIFV+(1.0_JPRB-BEDIFV)/(1.0_JPRB+(ZDIFV*ZZ5)**2))
    IF ((BE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ZGLU+ZZ5))
    ZCK=Z3BCF*ZGLT*ZGLU &
     & *(((ZPFH*(ZGLT+ZZT5)-ZPFH5*ZZT)/(ZGLT+ZZT5)**2)*(ZPFD5/(ZGLU+ZZ5)) &
     & +((ZPFD*(ZGLU+ZZ5)-ZPFD5*ZZ)/(ZGLU+ZZ5)**2)*(ZPFH5/(ZGLT+ZZT5)))  

    ZDPHI5(JLON)=PAPHIF5(JLON,JLEV)-PAPHIF5(JLON,JLEV+1)
    ZDPHI(JLON)=PAPHIF(JLON,JLEV)-PAPHIF(JLON,JLEV+1)

!     WIND SHEAR.

    ZCIS5=MAX(ZEPS1,(PU5(JLON,JLEV)-PU5(JLON,JLEV+1))**2 &
     & +(PV5(JLON,JLEV)-PV5(JLON,JLEV+1))**2)  
    ZXX=(PU5(JLON,JLEV)-PU5(JLON,JLEV+1))**2 &
     & +(PV5(JLON,JLEV)-PV5(JLON,JLEV+1))**2  
    IF (ZXX > ZEPS1) THEN
      ZCIS=2.0_JPRB*(PU5(JLON,JLEV)-PU5(JLON,JLEV+1))*PU(JLON,JLEV)&
       & -2.0_JPRB*(PU5(JLON,JLEV)-PU5(JLON,JLEV+1))*PU(JLON,JLEV+1)&
       & +2.0_JPRB*(PV5(JLON,JLEV)-PV5(JLON,JLEV+1))*PV(JLON,JLEV)&
       & -2.0_JPRB*(PV5(JLON,JLEV)-PV5(JLON,JLEV+1))*PV(JLON,JLEV+1)  
    ELSE
      ZCIS=0.0_JPRB
    ENDIF

    ZU5(JLON)=SQRT(ZCIS5)
    ZU(JLON)=ZCIS/(2.0_JPRB*SQRT(ZCIS5))

!     PRELIMINARY STABILITY COMPUTATION.

    ZDTETA5=ZR5(JLON,JLEV)*PT5(JLON,JLEV)&
     & -ZR5(JLON,JLEV+1)*PT5(JLON,JLEV+1)&
     & +RKAPPA*ZDPHI5(JLON)  
    ZDTETA=ZR5(JLON,JLEV)*PT(JLON,JLEV)&
     & +PT5(JLON,JLEV)*ZR(JLON,JLEV)&
     & -ZR5(JLON,JLEV+1)*PT(JLON,JLEV+1)&
     & -PT5(JLON,JLEV+1)*ZR(JLON,JLEV+1)&
     & +RKAPPA*ZDPHI(JLON)  

!     CORRECTION FOR SHALLOW CONVECTION (OPTIONAL).

    IF (LCVPP) THEN
      ZAUX5=ZRCVPP*MIN(0.0_JPRB,PQ5(JLON,JLEV)-ZQSAT5(JLON,JLEV)&
       & -PQ5(JLON,JLEV+1)&
       & +ZQSAT5(JLON,JLEV+1))*(0.5_JPRB*(ZLSCPE5(JLON,JLEV)&
       & +ZLSCPE5(JLON,JLEV+1)))*MAX(0.0_JPRB,SIGN(1.0_JPRB,RD &
       & *(PQ5(JLON,JLEV+1)-PQ5(JLON,JLEV))&
       & *(0.5_JPRB*(ZLSCPE5(JLON,JLEV)&
       & +ZLSCPE5(JLON,JLEV+1)))-ZDTETA5))  

      ZZB=MAX(0.0_JPRB,SIGN(1.0_JPRB,RD*(PQ5(JLON,JLEV+1)-PQ5(JLON,JLEV))&
       & *(0.5_JPRB*(ZLSCPE5(JLON,JLEV)&
       & +ZLSCPE5(JLON,JLEV+1)))-ZDTETA5))  

      ZZC5=PQ5(JLON,JLEV)-ZQSAT5(JLON,JLEV)-PQ5(JLON,JLEV+1)&
       & +ZQSAT5(JLON,JLEV+1)  
      ZZC=PQ(JLON,JLEV)-ZQSAT(JLON,JLEV)-PQ(JLON,JLEV+1)+ZQSAT(JLON,JLEV+1)
      IF (ZZC5 < 0.0_JPRB) THEN
        ZZD5=ZZC5
        ZZD=ZZC
      ELSE
        ZZD5=0.0_JPRB
        ZZD=0.0_JPRB
      ENDIF

      ZAUX=0.5_JPRB*ZRCVPP*ZZB*ZZD5 &
       & *(ZLSCPE(JLON,JLEV)+ZLSCPE(JLON,JLEV+1))&
       & +0.5_JPRB*ZRCVPP*ZZB &
       & *(ZLSCPE5(JLON,JLEV)+ZLSCPE5(JLON,JLEV+1))*ZZD  
    ELSE
      ZAUX5=0.0_JPRB
      ZAUX=0.0_JPRB
    ENDIF

!     STABILITY COMPUTATION.

    ZRTI5(JLON)=2.0_JPRB/(ZR5(JLON,JLEV)*PT5(JLON,JLEV)+ZR5(JLON,JLEV+1)&
     & *PT5(JLON,JLEV+1))  
    ZRTI(JLON)=(-2.0_JPRB*ZR5(JLON,JLEV)*PT(JLON,JLEV)&
     & -2.0_JPRB*PT5(JLON,JLEV)*ZR(JLON,JLEV)&
     & -2.0_JPRB*ZR5(JLON,JLEV+1)*PT(JLON,JLEV+1)&
     & -2.0_JPRB*PT5(JLON,JLEV+1)*ZR(JLON,JLEV+1))&
     & /(ZR5(JLON,JLEV)*PT5(JLON,JLEV)+ZR5(JLON,JLEV+1)&
     & *PT5(JLON,JLEV+1))**2  

    ZSTA5(JLON)=ZDPHI5(JLON)*(ZDTETA5+RD*ZAUX5)*ZRTI5(JLON)
    ZSTA(JLON)=(ZDTETA5+RD*ZAUX5)*ZRTI5(JLON)*ZDPHI(JLON)&
     & +ZDPHI5(JLON)*ZRTI5(JLON)*ZDTETA &
     & +RD*ZDPHI5(JLON)*ZRTI5(JLON)*ZAUX &
     & +(ZDTETA5+RD*ZAUX5)*ZDPHI5(JLON)*ZRTI(JLON)  

    ZUSURIC5=USURIC*(1.0_JPRB+(USURICL-1.0_JPRB)*((ZGLT*ZPFH5)/(ZGLT+ZZT5))**USURICE)
    ZUSURIC=USURIC*(USURICL-1.0_JPRB) &
     & *USURICE*((ZGLT*ZPFH5)/(ZGLT+ZZT5))**(USURICE-1.0_JPRB) &
     & *ZGLT*(ZPFH*(ZGLT+ZZT5)-ZPFH5*ZZT)/(ZGLT+ZZT5)**2  

    ZUSURID5=USURID*(1.0_JPRB+1.0_JPRB/((ZZT5*ZDIFT)*(ZZ5*ZDIFV)))**USURIDE
    ZUSURID=-1.0_JPRB*USURID*USURIDE*(1.0_JPRB+1.0_JPRB/((ZZT5*ZDIFT)*(ZZ5*ZDIFV)))&
     & **(USURIDE-1.0_JPRB)*(ZZ*ZZT5+ZZT*ZZ5)/((ZDIFT*ZDIFV)*(ZZT5*ZZ5)**2)  

    IF (ZSTA5(JLON) > 0.0_JPRB) THEN
      ZIXP=2.0_JPRB/(1.0_JPRB+ZUSURID5*ZSTA5(JLON)/ZCIS5)**2 &
       & *((ZUSURID*ZSTA5(JLON)+ZUSURID5*ZSTA(JLON))*ZCIS5 &
       & -ZUSURID5*ZSTA5(JLON)*ZCIS)/ZCIS5**2  
    ELSE
      ZIXP=0.0_JPRB
    ENDIF
    ZIXP5=(1.0_JPRB+3._JPRB*ZUSURID5*MAX(0.0_JPRB,ZSTA5(JLON))/ZCIS5) &
     & /(1.0_JPRB+ZUSURID5*MAX(0.0_JPRB,ZSTA5(JLON))/ZCIS5)  

    IF (ZSTA5(JLON) > 0.0_JPRB) THEN
      ZSTAH(JLON)=(1.0_JPRB+ZIXP5*ZUSURIC5*ZSTA5(JLON)/ZCIS5)**(-1.0_JPRB/ZIXP5) &
       & *(ZSTA(JLON)+ZSTA5(JLON)*ZIXP/ZIXP5**2 &
       & *LOG(1.0_JPRB+ZIXP5*ZUSURIC5*ZSTA5(JLON)/ZCIS5) &
       & -ZSTA5(JLON)/ZIXP5*(ZIXP*ZUSURIC5*ZSTA5(JLON) &
       & +ZIXP5*ZUSURIC*ZSTA5(JLON)+ZIXP5*ZUSURIC5*ZSTA(JLON) &
       & -ZCIS*ZIXP5*ZUSURIC5*ZSTA5(JLON)/ZCIS5) &
       & /(ZCIS5+ZIXP5*ZUSURIC5*ZSTA5(JLON)))  
    ELSE
      ZSTAH(JLON)=ZSTA(JLON)
    ENDIF
    ZSTAH5(JLON)=ZSTA5(JLON)/(1.0_JPRB+ZIXP5*ZUSURIC5 &
     & *MAX(0.0_JPRB,ZSTA5(JLON))/ZCIS5)**(1.0_JPRB/ZIXP5)  

    IF (ZSTA5(JLON) > 0.0_JPRB) THEN
      ZSTA(JLON)=(ZCIS5**2*ZSTA(JLON)-ZCIS5*ZSTA5(JLON)**2*ZUSURIC &
       & +ZSTA5(JLON)**2*ZUSURIC5*ZCIS)/(ZCIS5+ZSTA5(JLON)*ZUSURIC5)**2  
    ENDIF
    ZSTA5(JLON)=ZSTA5(JLON)/(1.0_JPRB+MAX(0.0_JPRB,ZSTA5(JLON))*ZUSURIC5/ZCIS5)

    ZIS=MAX(0.0_JPRB,SIGN(1.0_JPRB,ZSTA5(JLON)))

    IF (ZSTA5(JLON) > 0.0_JPRB) THEN
      ZSTAC(JLON)=ZSTA(JLON)
    ELSE
      ZSTAC(JLON)=-ZSTA(JLON)
    ENDIF
    ZSTAC5(JLON)=ABS(ZSTA5(JLON))

    IF (ZSTAH5(JLON) > 0.0_JPRB) THEN
      ZSTACH(JLON)=ZSTAH(JLON)
    ELSE
      ZSTACH(JLON)=-ZSTAH(JLON)
    ENDIF
    ZSTACH5(JLON)=ABS(ZSTAH5(JLON))
    
!     COMMON COMPUTATIONS FOR MOMENTUM AND ENERGY.

    ZDS5=SQRT(ZCIS5+(EDD/EDK)*ZSTAC5(JLON))
    ZDS=0.5_JPRB*(ZCIS+(EDD/EDK)*ZSTAC(JLON))/SQRT(ZCIS5+(EDD/EDK)*ZSTAC5(JLON))

    ZHS5=SQRT(ZCIS5+EDD*EDK*ZSTACH5(JLON))
    ZHS=0.5_JPRB*(ZCIS+EDD*EDK*ZSTACH(JLON))/SQRT(ZCIS5+EDD*EDK*ZSTACH5(JLON))

!     COMPUTATIONS FOR THE WIND COMPONENTS.

    ZLOS5=ZCIS5*ZDS5/(ZU5(JLON)*ZDS5+Z2B*ZSTAC5(JLON))
    ZLOS=(ZDS5/(ZU5(JLON)*ZDS5+Z2B*ZSTAC5(JLON)))*ZCIS &
     & +(Z2B*ZSTAC5(JLON)*ZCIS5*ZDS &
     & -ZCIS5*ZDS5**2*ZU(JLON)&
     & -Z2B*ZCIS5*ZDS5*ZSTAC(JLON))&
     & /(ZU5(JLON)*ZDS5+Z2B*ZSTAC5(JLON))**2  

    ZLOI5=ZU5(JLON)-Z2B*ZSTA5(JLON)/(ZU5(JLON)+ZCK5*SQRT(ZSTAC5(JLON)))
    ZLOI=ZU(JLON)&
     & -(Z2B/(ZU5(JLON)+ZCK5*SQRT(ZSTAC5(JLON))))*ZSTA(JLON)&
     & +(Z2B*ZSTA5(JLON)/(ZU5(JLON)+ZCK5*SQRT(ZSTAC5(JLON)))**2)&
     & *ZU(JLON)&
     & +(Z2B*ZSTA5(JLON)*SQRT(ZSTAC5(JLON))&
     & /(ZU5(JLON)+ZCK5*SQRT(ZSTAC5(JLON)))**2)*ZCK &
     & +(0.5_JPRB*Z2B*ZSTA5(JLON)*ZCK5/(SQRT(ZSTAC5(JLON))&
     & *(ZU5(JLON)+ZCK5*SQRT(ZSTAC5(JLON)))**2))*ZSTAC(JLON)  

    PKUROV5(JLON,JLEV)=(ZLOI5+ZIS*(ZLOS5-ZLOI5))*ZGLMU25 &
     & *PAPRS5(JLON,JLEV)*ZRTI5(JLON)/ZDPHI5(JLON)**2  
    PKUROV(JLON,JLEV)=((1.0_JPRB-ZIS)*ZGLMU25*PAPRS5(JLON,JLEV)*&
     & ZRTI5(JLON)&
     & /ZDPHI5(JLON)**2)*ZLOI &
     & +(ZIS*ZGLMU25*PAPRS5(JLON,JLEV)*ZRTI5(JLON)&
     & /ZDPHI5(JLON)**2)*ZLOS &
     & +((ZLOI5+ZIS*(ZLOS5-ZLOI5))*PAPRS5(JLON,JLEV)&
     & *ZRTI5(JLON)/ZDPHI5(JLON)**2)*ZGLMU2 &
     & +((ZLOI5+ZIS*(ZLOS5-ZLOI5))*ZGLMU25 &
     & *PAPRS5(JLON,JLEV)/ZDPHI5(JLON)**2)*ZRTI(JLON)&
     & +((ZLOI5+ZIS*(ZLOS5-ZLOI5))*ZGLMU25 &
     & *ZRTI5(JLON)/ZDPHI5(JLON)**2)*PAPRS(JLON,JLEV)&
     & -(2.0_JPRB*(ZLOI5+ZIS*(ZLOS5-ZLOI5))*ZGLMU25 &
     & *PAPRS5(JLON,JLEV)*ZRTI5(JLON)&
     & /ZDPHI5(JLON)**3)*ZDPHI(JLON)  

!     COMPUTATIONS FOR TEMPERATURE AND HUMIDITY.

    ZLOS5=ZCIS5**2/(ZU5(JLON)*ZCIS5+Z3B*ZSTACH5(JLON)*ZHS5)
    ZLOS=(ZCIS5*(ZCIS5*ZU5(JLON)+2.0_JPRB*Z3B*ZSTACH5(JLON)*ZHS5)*ZCIS &
     & -ZCIS5**3*ZU(JLON)&
     & -Z3B*ZCIS5**2*ZHS5*ZSTACH(JLON)&
     & -Z3B*ZCIS5**2*ZSTACH5(JLON)*ZHS)&
     & /(ZU5(JLON)*ZCIS5+Z3B*ZSTACH5(JLON)*ZHS5)**2  

    ZLOI5=ZU5(JLON)-Z3B*ZSTA5(JLON)/(ZU5(JLON)+ZCK5*SQRT(ZSTAC5(JLON)))
    ZLOI=ZU(JLON)&
     & -(Z3B/(ZU5(JLON)+ZCK5*SQRT(ZSTAC5(JLON))))*ZSTA(JLON)&
     & +(Z3B*ZSTA5(JLON)/(ZU5(JLON)+ZCK5*SQRT(ZSTAC5(JLON)))**2)&
     & *ZU(JLON)&
     & +(Z3B*ZSTA5(JLON)*SQRT(ZSTAC5(JLON))&
     & /(ZU5(JLON)+ZCK5*SQRT(ZSTAC5(JLON)))**2)*ZCK &
     & +(0.5_JPRB*Z3B*ZSTA5(JLON)*ZCK5/(SQRT(ZSTAC5(JLON))&
     & *(ZU5(JLON)+ZCK5*SQRT(ZSTAC5(JLON)))**2))*ZSTAC(JLON)  

    PKTROV5(JLON,JLEV)=(ZLOI5+ZIS*(ZLOS5-ZLOI5))*ZGLMT25 &
     & *PAPRS5(JLON,JLEV)*ZRTI5(JLON)/ZDPHI5(JLON)**2  
    PKTROV(JLON,JLEV)=((1.0_JPRB-ZIS)*ZGLMT25*PAPRS5(JLON,JLEV)*&
     & ZRTI5(JLON)&
     & /ZDPHI5(JLON)**2)*ZLOI &
     & +(ZIS*ZGLMT25*PAPRS5(JLON,JLEV)*ZRTI5(JLON)&
     & /ZDPHI5(JLON)**2)*ZLOS &
     & +((ZLOI5+ZIS*(ZLOS5-ZLOI5))*PAPRS5(JLON,JLEV)&
     & *ZRTI5(JLON)/ZDPHI5(JLON)**2)*ZGLMT2 &
     & +((ZLOI5+ZIS*(ZLOS5-ZLOI5))*ZGLMT25 &
     & *PAPRS5(JLON,JLEV)/ZDPHI5(JLON)**2)*ZRTI(JLON)&
     & +((ZLOI5+ZIS*(ZLOS5-ZLOI5))*ZGLMT25 &
     & *ZRTI5(JLON)/ZDPHI5(JLON)**2)*PAPRS(JLON,JLEV)&
     & -(2.0_JPRB*(ZLOI5+ZIS*(ZLOS5-ZLOI5))*ZGLMT25 &
     & *PAPRS5(JLON,JLEV)*ZRTI5(JLON)&
     & /ZDPHI5(JLON)**3)*ZDPHI(JLON)  

!     NO ANTI-FIBRILLATION.

    PXUROV5(JLON,JLEV)=1.0_JPRB
    PXUROV(JLON,JLEV)=0.0_JPRB

    PXTROV5(JLON,JLEV)=1.0_JPRB
    PXTROV(JLON,JLEV)=0.0_JPRB

  ENDDO

ENDDO

!     ----------------------------------------------------------------
ENDIF
!     ----------------------------------------------------------------

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