!OPTIONS XOPT(NOEVAL)
SUBROUTINE ACCONVAD ( KIDIA,KFDIA,KLON,KTDIA,KLEV,&
 !-----------------------------------------------------------------------
 ! - INPUT  2D .
 & PAPHIF5,PAPRS5,PAPRSF5,PCVGQ5,&
 & PDELP5,PQ5,PRDELP5,PT5,PU5,PV5,&
 & PAPHIF,PAPRS,PAPRSF,PCVGQ,&
 & PDELP,PQ,PRDELP,PT,PU,PV,&
 ! - INPUT  1D .
 & PTS,&
 ! - OUTPUT 2D .
 & PDIFCQ5,PDIFCS5,PFPLCL5,PFPLCN5,PSTRCU5,&
 & PSTRCV5,&
 & PDIFCQ,PDIFCS,PFPLCL,PFPLCN,PSTRCU,PSTRCV,&
 ! - LOCK ARGUMENTS .
 & CDLOCK)  

!**** *ACCONVAD * - ADJOINT COMPUTATION OF MASS-FLUX DEEP
!                   CONVECTION SCHEME.

!     Subject.
!     -------
!     Adjoint computation of:
!     - MASS-FLUX DEEP CONVECTION SCHEME, COMPUTING CONVECTIVE
!       PRECIPITATIONS AND "SUB-GRID SCALE" ASSOCIATED FLUXES .
!     - COMPUTATION OF ENTHALPY FLUXES LINKED TO CONVECT. PRECIPITATIONS
!              (WATER AND SNOW) .

!**   Interface.
!     ----------
!        *CALL* *ACCONVAD*

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

! - DIMENSIONAL PARAMETERS OF PHYSICS.

! KIDIA      : START OF HORIZONTAL LOOP (IST in CPG).
! KFDIA      : END OF HORIZONTAL LOOP (IEND in CPG).
! KLON       : HORIZONTAL DIMENSIONAL.
! KTDIA      : START OF THE VERTICAL LOOP IN THE PHYSIC (1 IN GENERAL).
! KLEV       : END OF VERTICAL LOOP AND VERTICAL DIMENSION "FULL LEVEL".
!              (NFLEVG in CPG).

! - THE NAME OF THE PHYSICAL VARIABLES

! - 2D (0:KLEV) .

! PAPRS      : PRESSURE ON HALF LEVELS.

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

! - 2D (1:KLEV) .

! PAPHIF     : GEOPOTENTIAL ON FULL LEVELS.
! PAPRSF     : PRESSURE ON FULL LEVELS.
! PCVGQ      : CONVERGENCE OF THE HUMIDITY ("KUO" CONDITION).
! PDELP      : LAYER THICKNESS IN PRESSURE UNITS.
! PQ         : SPECIFIC HUMIDITY OF WATER VAPOUR.
! PRDELP     : INVERSE OF LAYER THICKNESS IN PRESSURE UNITS.
! PT         : TEMPERATURE.
! PU         : X COMPONENT OF WIND.
! PV         : Y COMPONENT OF WIND.

! The same but for trajectory
! ---------------------------
! PAPHIF5    : GEOPOTENTIAL ON FULL LEVELS.
! PAPRSF5    : PRESSURE ON FULL LEVELS.
! PCVGQ5     : CONVERGENCE OF THE HUMIDITY ("KUO" CONDITION).
! PDELP5     : LAYER THICKNESS IN PRESSURE UNITS.
! PQ5        : SPECIFIC HUMIDITY OF WATER VAPOUR.
! PRDELP5    : INVERSE OF LAYER THICKNESS IN PRESSURE UNITS.
! PT5        : TEMPERATURE.
! PU5        : X COMPONENT OF WIND.
! PV5        : Y COMPONENT OF WIND.

! - 1D

! PTS        : SURFACE TEMPERATURE.

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

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

! - 2D (0:KLEV) .

! PDIFCQ     : CONVECTIVE FLUX OF SPECIFIC HUMIDITY (NOT RAIN/SNOW).
! PDIFCS     : CONVECTIVE FLUX OF ENTHALPY (NOT RAIN/SNOW).
! PFPLCL     : CONVECTIVE PRECIPITATION AS RAIN.
! PFPLCN     : CONVECTIVE PRECIPITATION AS SNOW.
! PSTRCU     : CONVECTIVE FLUX OF MOMENTUM "U".
! PSTRCV     : CONVECTIVE FLUX OF MOMENTUM "V".

! The same but for trajectory
! ---------------------------
! PDIFCQ5    : CONVECTIVE FLUX OF SPECIFIC HUMIDITY (NOT RAIN/SNOW).
! PDIFCS5    : CONVECTIVE FLUX OF ENTHALPY (NOT RAIN/SNOW).
! PFPLCL5    : CONVECTIVE PRECIPITATION AS RAIN.
! PFPLCN5    : CONVECTIVE PRECIPITATION AS SNOW.
! PSTRCU5    : CONVECTIVE FLUX OF MOMENTUM "U".
! PSTRCV5    : CONVECTIVE FLUX OF MOMENTUM "V".

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

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

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

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

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

!     Method.
!     -------

!     Author
!     -------
!        97-02   -   M. Janiskova
!     Modifications.
!     --------------
!        97-08, introduce CDLOCK - J.M. Piriou.
!        97-12, modifications in stability criterium and
!               Newton loop - M. Janiskova.
!        99-01, code optimization - M. Janiskova
!        99-12, modification in the condition related to negative
!               precipitations at the surface -  F. Bouyssel.
!        99-12, perturbations of mass, entrainment and detrainment fluxes
!               are set to zero (if LSMOOTHB=.T.) - F. Bouyssel.
!        M.Hamrud      01-Oct-2003 CY28 Cleaning

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

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

USE YOMPHY   , ONLY : NBITER   ,LNEIGE
USE YOMCST   , ONLY : RG       ,RD       ,RV       ,RCPD     ,&
 & RCPV     ,RETV     ,RCW      ,RCS      ,RLVTT    ,&
 & RLSTT    ,RTT      ,RALPW    ,RBETW    ,RGAMW    ,&
 & RALPS    ,RBETS    ,RGAMS    ,RALPD    ,RBETD    ,&
 & RGAMD  
USE YOMPHY0  , ONLY : ECMNP    ,SCO      ,USDMLT
USE YOMPHY2  , ONLY : TSPHY
USE YOMSIMPHL, ONLY : LSMOOTHB

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)    :: 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)    :: PCVGQ5(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PDELP5(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PQ5(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PRDELP5(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(INOUT) :: PAPHIF(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PAPRS(KLON,0:KLEV) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PAPRSF(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PCVGQ(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PDELP(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PQ(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PRDELP(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PT(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PU(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PV(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PTS(KLON) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PDIFCQ5(KLON,0:KLEV) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PDIFCS5(KLON,0:KLEV) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PFPLCL5(KLON,0:KLEV) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PFPLCN5(KLON,0:KLEV) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PSTRCU5(KLON,0:KLEV) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PSTRCV5(KLON,0:KLEV) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PDIFCQ(KLON,0:KLEV) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PDIFCS(KLON,0:KLEV) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PFPLCL(KLON,0:KLEV) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PFPLCN(KLON,0:KLEV) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PSTRCU(KLON,0:KLEV) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PSTRCV(KLON,0:KLEV) 
CHARACTER(LEN=7)  ,INTENT(IN)    :: CDLOCK 
INTEGER(KIND=JPIM) :: I_KNLAB(KLON,KLEV),I_KNND(KLON)

REAL(KIND=JPRB) :: ZSNP(KLON,0:KLEV),ZLHN(KLON,0:KLEV),ZLHL(KLON,0:KLEV)&
 & ,ZFORM(KLON,0:KLEV),ZZLHP(KLON,0:KLEV)  
REAL(KIND=JPRB) :: ZCP(KLON,KLEV),ZLHE(KLON,KLEV),ZDSE(KLON,KLEV)&
 & ,ZQW(KLON,KLEV),ZTW(KLON,KLEV),ZMSE(KLON,KLEV)&
 & ,ZMSEU(KLON,KLEV),ZF(KLON,KLEV),ZMFC(KLON,KLEV)&
 & ,ZCORU(KLON,KLEV),ZCORV(KLON,KLEV),ZCORQ(KLON,KLEV)&
 & ,ZCORS(KLON,KLEV),ZFQSC(KLON,KLEV)&
 & ,ZFUSC(KLON,KLEV),ZFVSC(KLON,KLEV),ZFSSC(KLON,KLEV)&
 & ,ZQDN(KLON,KLEV),ZPOID(KLON,KLEV),ZIPOI(KLON,KLEV)&
 & ,ZMSEC(KLON,KLEV),ZPHI(KLON,KLEV)  
REAL(KIND=JPRB) :: ZLHSB(KLON),ZTN(KLON),ZQN(KLON),ZS1(KLON),ZS2(KLON)&
 & ,ZPOII(KLON),ZALF(KLON),ZLN(KLON),ZUN(KLON),ZVN(KLON)&
 & ,ZMSEN(KLON),ZDFMDQ(KLON),ZDFMDU(KLON),ZDFMDV(KLON)&
 & ,ZDFMDS(KLON),ZDSEN(KLON),ZENTR(KLON),ZDETR(KLON)&
 & ,ZPOIL(KLON)  

REAL(KIND=JPRB) :: ZSNP5(KLON,0:KLEV),ZLHN5(KLON,0:KLEV),ZLHL5(KLON,0:KLEV)&
 & ,ZFORM5(KLON,0:KLEV),ZZLHP5(KLON,0:KLEV)  
REAL(KIND=JPRB) :: ZCP5(KLON,KLEV),ZLHE5(KLON,KLEV),ZDSE5(KLON,KLEV)&
 & ,ZMSE5(KLON,KLEV)&
 & ,ZMSEU5(KLON,KLEV),ZF5(KLON,KLEV),ZMFC5(KLON,KLEV)&
 & ,ZCORU5(KLON,KLEV),ZCORV5(KLON,KLEV),ZCORQ5(KLON,KLEV)&
 & ,ZCORS5(KLON,KLEV),ZFQSC5(KLON,KLEV)&
 & ,ZFUSC5(KLON,KLEV),ZFVSC5(KLON,KLEV),ZFSSC5(KLON,KLEV)&
 & ,ZQDN5(KLON,KLEV),ZPOID5(KLON,KLEV),ZIPOI5(KLON,KLEV)&
 & ,ZMSEC5(KLON,KLEV),ZPHI5(KLON,KLEV)  
REAL(KIND=JPRB) :: ZLHSB5(KLON),ZS15(KLON),ZS25(KLON),ZALF5(KLON)

REAL(KIND=JPRB) :: ZQW5(KLON,KLEV,NBITER),ZTW5(KLON,KLEV,NBITER)&
 & ,ZEW5(KLON,KLEV,NBITER),ZESP5(KLON,KLEV,NBITER)&
 & ,ZZQW5(KLON,KLEV,NBITER),ZDLEW5(KLON,KLEV,NBITER)&
 & ,ZDQW5(KLON,KLEV,NBITER),ZDELQ5(KLON,KLEV,NBITER)&
 & ,ZDELT5(KLON,KLEV,NBITER)  
REAL(KIND=JPRB) :: ZZSN5(KLON,KLEV),ZTQ5(KLON,0:KLEV),ZTI5(KLON,KLEV)&
 & ,ZDELTA5(KLON,KLEV),ZPOII5(KLON,KLEV),ZZFO5(KLON,KLEV)&
 & ,ZZPO5(KLON,KLEV),ZZPO15(KLON,KLEV),ZZPO25(KLON,KLEV)&
 & ,ZMSEP5(KLON,KLEV),ZFORM15(KLON,KLEV),ZZFO15(KLON,KLEV)&
 & ,ZMSEU15(KLON,KLEV),ZQW15(KLON,KLEV),ZTW15(KLON,KLEV)&
 & ,ZQN5(KLON,KLEV),ZLN5(KLON,KLEV),ZUN5(KLON,KLEV)&
 & ,ZVN5(KLON,KLEV),ZMSEN5(KLON,KLEV),ZDSEN5(KLON,KLEV)&
 & ,ZTN5(KLON,KLEV),ZF15(KLON,KLEV),ZENTR5(KLON,KLEV)&
 & ,ZDETR5(KLON,KLEV),ZENTR15(KLON,KLEV),ZENTR25(KLON,KLEV)&
 & ,ZPOIL5(KLON,KLEV),ZMFC15(KLON,KLEV),ZDETR15(KLON,KLEV)&
 & ,ZMSEPR5(KLON,KLEV),ZZZL5(KLON,KLEV),ZIV15(KLON,KLEV)&
 & ,ZIV5(KLON,KLEV),ZDFMDU5(KLON,KLEV),ZDFMDV5(KLON,KLEV)&
 & ,ZDFMDQ5(KLON,KLEV),ZDFMDS5(KLON,KLEV),ZFMDU5(KLON,KLEV)&
 & ,ZFMDV5(KLON,KLEV),ZFMDQ5(KLON,KLEV),ZFMDS5(KLON,KLEV)&
 & ,ZFTOTQ5(KLON,KLEV),ZFCORQ5(KLON,KLEV),ZFTOTS5(KLON,KLEV)  
REAL(KIND=JPRB) :: ZSTRCU5(KLON,0:KLEV),ZSTRCV5(KLON,0:KLEV)&
 & ,ZDIFCQ5(KLON,0:KLEV),ZDIFCS5(KLON,0:KLEV)&
 & ,ZFPLCL5(KLON,0:KLEV),ZFPLCN5(KLON,0:KLEV)  
REAL(KIND=JPRB) :: ZZSN15(KLON),ZZSN25(KLON),ZZAL15(KLON),ZZAL25(KLON)

INTEGER(KIND=JPIM) :: ISUM, ITOP, JIT, JJ, JLEV, JLON

LOGICAL :: LL_LCLOSN

REAL(KIND=JPRB) :: ZCORIN, ZCPSMD, ZCPVMS, ZCPVMW, ZCPWMD, ZCVMCD,&
 & ZDELQ, ZDELT, ZDELTA, ZDETC, ZDLEW, ZDQW, &
 & ZEPS1, ZEPS2, ZEPS3, ZEPS4, ZEPS5, ZEPS6, &
 & ZEPS7, ZESP, ZEW, ZFCORQ, ZFMDQ, ZFMDS, ZFMDU, &
 & ZFMDV, ZFTOTQ, ZFTOTS, ZGDT, ZGDTI, ZINSTA, &
 & ZIV, ZIV1, ZMSEP, ZMSEPR, ZRVMD, ZTI, ZTQ, &
 & ZZAL1, ZZAL2, ZZFO, ZZM5, ZZPO1, ZZPO2, ZZQW, &
 & ZZSN, ZZSN1, ZZSN2, ZZZL, ZZZS, ZZVAL  
REAL(KIND=JPRB) :: ZHOOK_HANDLE

#include "abor1.intfb.h"

#include "fcttrm.h"
#include "fcttrmad.h"

!     CHECK RELIABILITY OF INPUT ARGUMENTS.

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

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

LL_LCLOSN=.FALSE.

ZRVMD=RV-RD
ZCPVMW=RCPV-RCW
ZCPVMS=RCPV-RCS
ZCPWMD=RCW-RCPD
ZCPSMD=RCS-RCPD
ZCVMCD=RCPV-RCPD

!*
!     ------------------------------------------------------------------
!     II - COMPUTATION OF DERIVED PARAMETERS, SECURITY CONSTANTS
!     AND INVERSE OF A CRITICAL ARGUMENT (TO AVOID "UNDERFLOW" IN
!     LIQUID (OR ICE) WATER CALCULATIONS FOR SUSTENTATION IN CLOUDY
!     ASCENTS).

ZGDT=RG*TSPHY
ZGDTI=1.0_JPRB/ZGDT

ZEPS1=1.E-01_JPRB
ZEPS2=1.E+01_JPRB
ZEPS3=1.E-01_JPRB
ZEPS4=1.E-04_JPRB

ZEPS5=1.E-06_JPRB
ZEPS6=1.E-07_JPRB
ZEPS7=1.E-05_JPRB

ZDETC=0.0_JPRB
ZCORIN=0.0_JPRB

!*
!     ------------------------------------------------------------------
!     0. 3 - Computation of value of atmospheric Cp,
!     setting all fluxes to zero (for the case without convection)
!     and preliminary calculations of dry static energy, of effective
!     latent heat (depending upon the option whether surface pressure is
!     varying or not with the surface water fluxes), of level pressure
!     thicknesses divided by G*DT and of their inverses at all levels as
!     well as of imposed proportions of snow precipitation in function
!     of temperature and pressure.

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

! ZCP5      : VALUE OF ATMOSPHERIC Cp
! ZPOID5    : DP/(RG*DT) FOR A GIVEN LEVEL AND A GIVEN TIME STEP.
! ZIPOI5    : INVERSE OF ZPOID.
! ZDSE5     : LOCAL ARRAY FOR DRY STATIC ENERGY.
! ZMSE5     : LOCAL ARRAY FOR MOIST STATIC ENERGY.
! ZLHE5     : LOCAL ARRAY FOR EFFECTIVE LATENT HEATS.

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

! ZSNP5     : PROPORTION OF SNOW PRECIPITATION.
! ZLHL5     : MINUS THE LATENT HEAT OF CONSERVATION OF LIQUID ENTHALPY.
! ZLHN5     : MINUS THE LATENT HEAT OF CONSERVATION OF SOLID ENTHALPY.

!     Computation of value of atmospheric Cp

DO JLEV=KTDIA,KLEV
  DO JLON=KIDIA,KFDIA
    ZCP5(JLON,JLEV)=RCPD*(1.0_JPRB-PQ5(JLON,JLEV))+RCPV*PQ5(JLON,JLEV)
  ENDDO
ENDDO

!     Snow option dependent calculations.

DO JLON=KIDIA,KFDIA

  IF (LNEIGE) THEN
    ZSNP5(JLON,KTDIA-1)=1.0_JPRB-MIN(1.0_JPRB,USDMLT*MAX(0.0_JPRB,PT5(JLON,KTDIA)&
     & -RTT)**2/MAX(1.E-03_JPRB,PAPRS5(JLON,KTDIA-1)))  
    IF (PAPRS5(JLON,KTDIA-1) > 1.E-03_JPRB) THEN
      ZZSN15(JLON)=PAPRS5(JLON,KTDIA-1)
    ELSE
      ZZSN15(JLON)=1.E-03_JPRB
    ENDIF
    IF ((PT5(JLON,KTDIA)-RTT) > 0.0_JPRB) THEN
      ZZSN25(JLON)=PT5(JLON,KTDIA)-RTT
    ELSE
      ZZSN25(JLON)=0.0_JPRB
    ENDIF
  ELSE
    ZSNP5(JLON,KTDIA-1)=0.0_JPRB
  ENDIF

ENDDO

!     Snow option dependent calculations.

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

    IF (LNEIGE) THEN
      ZSNP5(JLON,JLEV)=1.0_JPRB-MIN(1.0_JPRB,USDMLT*MAX(0.0_JPRB,0.5_JPRB*(PT5(JLON, &
       & JLEV)&
       & +PT5(JLON,JLEV+1))-RTT)**2/PAPRS5(JLON,JLEV))  
      IF ((0.5_JPRB*(PT5(JLON,JLEV)+PT5(JLON,JLEV+1))-RTT) > 0.0_JPRB) THEN
        ZZSN5(JLON,JLEV)=0.5_JPRB*(PT5(JLON,JLEV)+PT5(JLON,JLEV+1))-RTT
      ELSE
        ZZSN5(JLON,JLEV)=0.0_JPRB
      ENDIF
    ELSE
      ZSNP5(JLON,JLEV)=0.0_JPRB
    ENDIF

  ENDDO
ENDDO

!     Snow option dependent calculations.

DO JLON=KIDIA,KFDIA

  IF (LNEIGE) THEN
    ZSNP5(JLON,KLEV)=1.0_JPRB-MIN(1.0_JPRB,USDMLT*MAX(0.0_JPRB,PTS(JLON)-RTT)**2 &
     & /PAPRS5(JLON,KLEV))  
  ELSE
    ZSNP5(JLON,KLEV)=0.0_JPRB
  ENDIF

ENDDO

!     "Flux latent heat" arrays initialization.

! --- Computation at the top
!     ----------------------
DO JLON=KIDIA,KFDIA
  ZTQ5(JLON,0)=ZCVMCD*PT5(JLON,KTDIA)
  ZLHL5(JLON,0)=-(FOLH(PT5(JLON,KTDIA),0.0_JPRB)-ZTQ5(JLON,0))
  ZLHN5(JLON,0)=-(FOLH(PT5(JLON,KTDIA),1.0_JPRB)-ZTQ5(JLON,0))
ENDDO

! --- Computation for levels
!     ----------------------
DO JLEV = KTDIA , KLEV-1
  DO JLON = KIDIA , KFDIA
    ZTI5(JLON,JLEV)=0.5_JPRB*(PT5(JLON,JLEV)+PT5(JLON,JLEV+1))
    ZTQ5(JLON,JLEV)=ZCVMCD*ZTI5(JLON,JLEV)
    ZLHL5(JLON,JLEV)=-(FOLH(ZTI5(JLON,JLEV),0.0_JPRB)-ZTQ5(JLON,JLEV))
    ZLHN5(JLON,JLEV)=-(FOLH(ZTI5(JLON,JLEV),1.0_JPRB)-ZTQ5(JLON,JLEV))
  ENDDO
ENDDO

! --- Surface computation
!     --------------------
DO JLON=KIDIA,KFDIA
  ZTQ5(JLON,KLEV)=ZCVMCD*PTS(JLON)
  ZLHL5(JLON,KLEV)=-(FOLH(PTS(JLON),0.0_JPRB)-ZTQ5(JLON,KLEV))
  ZLHN5(JLON,KLEV)=-(FOLH(PTS(JLON),1.0_JPRB)-ZTQ5(JLON,KLEV))
ENDDO

DO JLON=KIDIA,KFDIA

!     Call to the defined function to compute the reference of effective
!     latent heat at the surface.

! For the trajectory
! ------------------
! - TEMPORARY(S) 1D .

! ZLHSB5    : BUDGET LATENT HEAT AS COMPUTED AT THE SURFACE.

  ZLHSB5(JLON)=-ZLHL5(JLON,KLEV)-ZSNP5(JLON,KLEV)&
   & *(ZLHN5(JLON,KLEV)-ZLHL5(JLON,KLEV))  

!     Setting to zero fluxes at the top.

  PFPLCL5(JLON,KTDIA-1)=0.0_JPRB
  PFPLCN5(JLON,KTDIA-1)=0.0_JPRB
  PDIFCQ5(JLON,KTDIA-1)=0.0_JPRB
  PDIFCS5(JLON,KTDIA-1)=0.0_JPRB
  PSTRCU5(JLON,KTDIA-1)=0.0_JPRB
  PSTRCV5(JLON,KTDIA-1)=0.0_JPRB

  ZFPLCL5(JLON,KTDIA-1)=0.0_JPRB
  ZFPLCN5(JLON,KTDIA-1)=0.0_JPRB
  ZDIFCQ5(JLON,KTDIA-1)=0.0_JPRB
  ZDIFCS5(JLON,KTDIA-1)=0.0_JPRB
  ZSTRCU5(JLON,KTDIA-1)=0.0_JPRB
  ZSTRCV5(JLON,KTDIA-1)=0.0_JPRB
ENDDO

!     Computations at all levels. Beware, the defined function FOLH will
!     be called with values that are not necessarily 0 or 1 for its
!     second argument !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

DO JLEV=KTDIA,KLEV
  DO JLON=KIDIA,KFDIA
    ZPOID5(JLON,JLEV)=PDELP5(JLON,JLEV)*ZGDTI
    ZIPOI5(JLON,JLEV)=PRDELP5(JLON,JLEV)*ZGDT
    ZDSE5(JLON,JLEV)=ZCP5(JLON,JLEV)*PT5(JLON,JLEV)+PAPHIF5(JLON,JLEV)
    ZDELTA5(JLON,JLEV)=0.5_JPRB*(ZSNP5(JLON,JLEV-1)+ZSNP5(JLON,JLEV))
    ZLHE5(JLON,JLEV)=FOLH(PT5(JLON,JLEV),ZDELTA5(JLON,JLEV))&
     & +(ZCPWMD+ZDELTA5(JLON,JLEV)&
     & *(ZCPSMD-ZCPWMD))*(PT5(JLON,JLEV)-PTS(JLON))  
    ZMSE5(JLON,JLEV)=ZCP5(JLON,JLEV)*PT5(JLON,JLEV)&
     & +ZLHE5(JLON,JLEV)*PQ5(JLON,JLEV)&
     & +PAPHIF5(JLON,JLEV)  
    ZMSEC5(JLON,JLEV)=ZCP5(JLON,JLEV)*PT5(JLON,JLEV)&
     & +ZLHSB5(JLON)*PQ5(JLON,JLEV)&
     & +PAPHIF5(JLON,JLEV)  

!     Setting fluxes to zero.

    PFPLCL5(JLON,JLEV)=0.0_JPRB
    PFPLCN5(JLON,JLEV)=0.0_JPRB
    PDIFCQ5(JLON,JLEV)=0.0_JPRB
    PDIFCS5(JLON,JLEV)=0.0_JPRB
    PSTRCU5(JLON,JLEV)=0.0_JPRB
    PSTRCV5(JLON,JLEV)=0.0_JPRB

    ZFPLCL5(JLON,JLEV)=0.0_JPRB
    ZFPLCN5(JLON,JLEV)=0.0_JPRB
    ZDIFCQ5(JLON,JLEV)=0.0_JPRB
    ZDIFCS5(JLON,JLEV)=0.0_JPRB
    ZSTRCU5(JLON,JLEV)=0.0_JPRB
    ZSTRCV5(JLON,JLEV)=0.0_JPRB
  ENDDO
ENDDO

!*
!     ------------------------------------------------------------------
!     0. 4 - Computation of profile of mass flux and normalization
!     factor for this profile connected with the "Kuo-type" closure

!     Active characteristics of the cloud at the bottom

! For the trajectory
! ------------------
! - TEMPORARY(S) 2D (0:KLEV) .

! ZFORM5    : PROFILE OF MASS FLUX AND LATER MASS FLUX TIME DT.

! - TEMPORARY(S) 1D .

! ZS15      : INTEGRAL OF HUMIDITY CONVERGENCE
! ZS25      : INTEGRAL OF BUOYANCY

IF (.NOT.LL_LCLOSN) THEN
  DO JLON=KIDIA,KFDIA
    ZMSEU5(JLON,KLEV)=ZMSE5(JLON,KLEV)
    ZMSEU15(JLON,KLEV)=ZMSE5(JLON,KLEV)
    ZFORM5(JLON,KLEV)=0.0_JPRB
    ZFORM15(JLON,KLEV)=0.0_JPRB

    ZS15(JLON)=0.0_JPRB
    ZS25(JLON)=0.0_JPRB
  ENDDO

!       Computation for levels

  DO JLEV=KLEV-1,KTDIA,-1
    DO JLON=KIDIA,KFDIA
      ZINSTA=MAX(0.0_JPRB,SIGN(1.0_JPRB,ZMSEU15(JLON,JLEV+1)-ZMSE5(JLON,JLEV)&
       & -ZCORIN))  
      ZMSEU5(JLON,JLEV)=ZINSTA*ZMSEU15(JLON,JLEV+1)&
       & +(1.0_JPRB-ZINSTA)*ZMSE5(JLON,JLEV)  
      ZFORM5(JLON,JLEV)=ZINSTA*SQRT(MAX(0.0_JPRB,ZMSEU5(JLON,JLEV)&
       & +ZMSEU15(JLON,JLEV+1)&
       & -ZMSE5(JLON,JLEV)-ZMSE5(JLON,JLEV+1))&
       & *PAPRS5(JLON,JLEV)&
       & /(PT5(JLON,JLEV)+PT5(JLON,JLEV+1)))  
      ZZFO5(JLON,JLEV)=ZMSEU5(JLON,JLEV)+ZMSEU15(JLON,JLEV+1)&
       & -ZMSE5(JLON,JLEV)-ZMSE5(JLON,JLEV+1)  

      ZPOII5(JLON,JLEV)=MIN(1.0_JPRB,MAX(0.0_JPRB,(1.0_JPRB+ZDETC &
       & *PDELP5(JLON,JLEV+1))&
       & *ZFORM5(JLON,JLEV)-ZFORM15(JLON,JLEV+1))&
       & /MAX(ZEPS7,ZFORM5(JLON,JLEV)))  
      ZZPO5(JLON,JLEV)=(1.0_JPRB+ZDETC*PDELP5(JLON,JLEV+1))&
       & *ZFORM5(JLON,JLEV)-ZFORM15(JLON,JLEV+1)  
      IF (ZZPO5(JLON,JLEV) > 0.0_JPRB) THEN
        ZZPO15(JLON,JLEV)=ZZPO5(JLON,JLEV)
      ELSE
        ZZPO15(JLON,JLEV)=0.0_JPRB
      ENDIF
      IF (ZFORM5(JLON,JLEV) > ZEPS7) THEN
        ZZPO25(JLON,JLEV)=ZFORM5(JLON,JLEV)
      ELSE
        ZZPO25(JLON,JLEV)=ZEPS7
      ENDIF

      ZMSEP5(JLON,JLEV)=ZPOII5(JLON,JLEV)*ZMSE5(JLON,JLEV+1)&
       & +(1.0_JPRB-ZPOII5(JLON,JLEV))*ZMSEU15(JLON,JLEV+1)  

      ZINSTA=MAX(0.0_JPRB,SIGN(1.0_JPRB,ZMSEP5(JLON,JLEV)-ZMSE5(JLON,JLEV)&
       & -ZCORIN))  
      ZMSEU15(JLON,JLEV)=ZINSTA*ZMSEP5(JLON,JLEV)&
       & +(1.0_JPRB-ZINSTA)*ZMSE5(JLON,JLEV)  

      ZFORM15(JLON,JLEV)=ZINSTA*SQRT(MAX(0.0_JPRB,ZMSEU15(JLON,JLEV)&
       & +ZMSEU15(JLON,JLEV+1)&
       & -ZMSE5(JLON,JLEV)-ZMSE5(JLON,JLEV+1))&
       & *PAPRS5(JLON,JLEV)&
       & /(PT5(JLON,JLEV)+PT5(JLON,JLEV+1)))  
      ZZFO15(JLON,JLEV)=ZMSEU15(JLON,JLEV)+ZMSEU15(JLON,JLEV+1)&
       & -ZMSE5(JLON,JLEV)-ZMSE5(JLON,JLEV+1)  

      ZS15(JLON)=ZS15(JLON)+PCVGQ5(JLON,JLEV+1)*PDELP5(JLON,JLEV+1)*ZINSTA
      ZS25(JLON)=ZS25(JLON)+(PQ5(JLON,JLEV+1)&
       & -PQ5(JLON,JLEV))*ZFORM15(JLON,JLEV)  
    ENDDO
  ENDDO

  DO JLON=KIDIA,KFDIA
    ZALF5(JLON)=(MAX(0.0_JPRB,ZS15(JLON))/MAX(ZEPS6,ZS25(JLON)))&
     & *MAX(0.0_JPRB,SIGN(1.0_JPRB,ZS25(JLON)-ZEPS6))  
    IF (ZS15(JLON) > 0.0_JPRB) THEN
      ZZAL15(JLON)=ZS15(JLON)
    ELSE
      ZZAL15(JLON)=0.0_JPRB
    ENDIF
    IF (ZS25(JLON) > ZEPS6) THEN
      ZZAL25(JLON)=ZS25(JLON)
    ELSE
      ZZAL25(JLON)=ZEPS6
    ENDIF
  ENDDO
ENDIF

!*
!     ------------------------------------------------------------------
!     0. 5 - Bottom initialisation. The cloud profile will eventualy be
!     characterised by its total humidity and its detraining dry static
!     energy as well as by a stability index (one at both ends of any
!     convective slab (from model layer to the adjacent one) and zero
!     elsewhere).

DO JLON=KIDIA,KFDIA

!     Initialization of the variables in the Newton loop,
!     the iterative Tw and Qw having to evolve.

! For trajectory
! --------------
! - TEMPORARY 3D

! ZQW5        : SPECIFIC WET BULB HUMIDITY.
! ZTW5       : WET BULB TEMPERATURE.

  ZQW5(JLON,KLEV,1)=PQ5(JLON,KLEV)
  ZTW5(JLON,KLEV,1)=PT5(JLON,KLEV)

  ZQW15(JLON,KLEV)=PQ5(JLON,KLEV)
  ZTW15(JLON,KLEV)=PT5(JLON,KLEV)
ENDDO

!     Newton loop for the "wet bulb" point.

DO JIT=1,NBITER
  DO JLON=KIDIA,KFDIA

    IF (JIT == 1) THEN
      JJ=0
    ELSE
      JJ=1
    ENDIF

!     Snow option dependent computations.

    IF (LNEIGE) THEN
      ZDELTA=MAX(0.0_JPRB,SIGN(1.0_JPRB,RTT-ZTW5(JLON,KLEV,JIT-JJ)))
    ELSE
      ZDELTA=0.0_JPRB
    ENDIF

!     Saturation calculations using the defined functions

    ZEW5(JLON,KLEV,JIT)= FOEW (ZTW5(JLON,KLEV,JIT-JJ),ZDELTA)
    ZESP5(JLON,KLEV,JIT)=ZEW5(JLON,KLEV,JIT)/PAPRSF5(JLON,KLEV)
    ZZQW5(JLON,KLEV,JIT)= FOQS (ZESP5(JLON,KLEV,JIT))

    ZDLEW5(JLON,KLEV,JIT)=FODLEW (ZTW5(JLON,KLEV,JIT-JJ),ZDELTA)
    ZDQW5(JLON,KLEV,JIT)=&
     & FODQS (ZZQW5(JLON,KLEV,JIT),ZESP5(JLON,KLEV,JIT)&
     & ,ZDLEW5(JLON,KLEV,JIT))  

!     Incrementations.

    ZDELQ5(JLON,KLEV,JIT)=&
     & (ZZQW5(JLON,KLEV,JIT)-ZQW5(JLON,KLEV,JIT-JJ))&
     & *ZCP5(JLON,KLEV)/(ZCP5(JLON,KLEV)&
     & +ZLHSB5(JLON)*ZDQW5(JLON,KLEV,JIT))  
    ZDELT5(JLON,KLEV,JIT)=-ZDELQ5(JLON,KLEV,JIT)*ZLHSB5(JLON)/ZCP5(JLON,KLEV)
    ZQW5(JLON,KLEV,JIT)=ZQW5(JLON,KLEV,JIT-JJ)+ZDELQ5(JLON,KLEV,JIT)
    ZTW5(JLON,KLEV,JIT)=ZTW5(JLON,KLEV,JIT-JJ)+ZDELT5(JLON,KLEV,JIT)
  ENDDO

ENDDO

DO JLON=KIDIA,KFDIA

!     Thermodynamic characteristics of the cloud.

! For trajectory
! --------------
! - TEMPORARY(S) 2D .

! ZTN5      : TEMPERATURE OF THE CLOUDY ASCENT.
! ZQN5      : WATER VAPOUR SPECIFIC HUMIDITY OF THE CLOUDY ASCENT.
! ZLN5      : CONDENSED SPECIFIC HUMIDITY OF THE CLOUDY ASCENT.
! ZUN5      : U-WIND COMPONENT OF THE CLOUDY ASCENT.
! ZVN5      : V-WIND COMPONENT OF THE CLOUDY ASCENT.
! ZMSEN5    : MOIST STATIC ENERGY OF THE CLOUDY ASCENT.
! ZDSEN5    : DRY STATIC ENERGY OF THE CLOUDY ASCENT.

  ZTN5(JLON,KLEV)=ZTW5(JLON,KLEV,NBITER)
  ZQN5(JLON,KLEV)=ZQW5(JLON,KLEV,NBITER)
  ZUN5(JLON,KLEV)=PU5(JLON,KLEV)
  ZVN5(JLON,KLEV)=PV5(JLON,KLEV)
  ZMSEN5(JLON,KLEV)=ZCP5(JLON,KLEV)*ZTN5(JLON,KLEV)&
   & +ZLHSB5(JLON)*ZQN5(JLON,KLEV)+PAPHIF5(JLON,KLEV)  
  ZDSEN5(JLON,KLEV)=ZCP5(JLON,KLEV)*ZTN5(JLON,KLEV)+PAPHIF5(JLON,KLEV)
  ZLN5(JLON,KLEV)=0.0_JPRB

!     Active other characteristics of the cloud.

! For trajectory
! --------------
! - TEMPORARY(S) 2D (1:KLEV)

! ZMCF5     : MASS FLUX IN CLOUD
! ZQDN5     : TOTAL CLOUD HUMIDITY

  ZMFC5(JLON,KLEV)=0.0_JPRB
  ZQDN5(JLON,KLEV)=ZQN5(JLON,KLEV)

  I_KNLAB(JLON,KLEV)=0
  I_KNND(JLON)=0

ENDDO

!*
!     ------------------------------------------------------------------
!     0. 6 - First vertical loop (upwards) including the saturated
!     adiabatic type calculation of the cloud profile.

!     Initialization of the parameter that shall eventually help
!     avoiding unnecessary computations in the upper part of the
!     atmosphere and start of the vertical loop.

ITOP=KLEV+1

!     Optional computation according chosen closure assumption
!     computation of values of detrainment and entrainment, test
!     of stability, computation of the second term of the basic equation,
!     computation of values u,v,q,h in cloud

! For trajectory
! --------------
! - TEMPORARY(S) 2D (1:KLEV)

!   ZCORU5  : THE SECOND TERM OF THE BASIC EQUATION FOR U-WIND COMP.
!   ZCORV5  : THE SECOND TERM OF THE BASIC EQUATION FOR V-WIND COMP.
!   ZCORQ5  : THE SECOND TERM OF THE BASIC EQUATION FOR SPEC.HUMIDITY
!   ZCORS5  : THE SECOND TERM OF THE BASIC EQUATION FOR DRY STATIC
!             ENERGY

DO JLEV=KLEV-1,KTDIA,-1

  DO JLON=KIDIA,KFDIA

!     Optional computation according chosen closure assumption
!     if LCLOSN=TRUE new closure assumption of simplified physics
!     will be used

    IF (LL_LCLOSN) THEN
      ZF15(JLON,JLEV+1)=PCVGQ5(JLON,JLEV+1)/MAX(ZEPS5,PQ5(JLON,JLEV+1))
    ELSE
      ZF15(JLON,JLEV+1)=ZALF5(JLON)*(ZFORM15(JLON,JLEV)&
       & -ZFORM15(JLON,JLEV+1))/PDELP5(JLON,JLEV+1)  
    ENDIF
    ZF5(JLON,JLEV+1)=ZF15(JLON,JLEV+1)&
     & /(1.0_JPRB+MAX(0.0_JPRB,ZF15(JLON,JLEV+1))*TSPHY)  

    ZMFC15(JLON,JLEV)=MAX(0.0_JPRB,ZMFC5(JLON,JLEV+1)&
     & +ZF5(JLON,JLEV+1)*PDELP5(JLON,JLEV+1))  

!     Computation of detrainment and entrainment

    ZENTR15(JLON,JLEV)=(MAX(0.0_JPRB,ZF5(JLON,JLEV+1)&
     & +ZDETC*ZMFC15(JLON,JLEV)))*PDELP5(JLON,JLEV+1)  
    ZENTR25(JLON,JLEV)=MIN(ZENTR15(JLON,JLEV),ZMFC15(JLON,JLEV))
    ZDETR15(JLON,JLEV)=ZENTR25(JLON,JLEV)+ZMFC5(JLON,JLEV+1)&
     & -ZMFC15(JLON,JLEV)  
    ZPOIL5(JLON,JLEV)=ZENTR25(JLON,JLEV)/MAX(ZEPS4,ZMFC15(JLON,JLEV))

!     Stability test

    ZMSEPR5(JLON,JLEV)=ZPOIL5(JLON,JLEV)*ZMSEC5(JLON,JLEV+1)&
     & +(1.0_JPRB-ZPOIL5(JLON,JLEV))*ZMSEN5(JLON,JLEV+1)  
    I_KNLAB(JLON,JLEV)=NINT(MAX(0.0_JPRB,-SIGN(1.0_JPRB,&
     & -(ZMSEPR5(JLON,JLEV)-ZMSEC5(JLON,JLEV))))&
     & *MAX(MAX(0.0_JPRB,SIGN(1.0_JPRB,&
     & ZDSE5(JLON,JLEV)-ZDSE5(JLON,JLEV+1))),&
     & MAX(0.0_JPRB,-SIGN(1.0_JPRB,0.0_JPRB-ZMFC5(JLON,JLEV+1)))))  
    I_KNLAB(JLON,JLEV+1)=MAX(I_KNLAB(JLON,JLEV+1),I_KNLAB(JLON,JLEV))
    I_KNND(JLON)=MAX(I_KNND(JLON),I_KNLAB(JLON,JLEV))

    ZMFC5(JLON,JLEV)=I_KNLAB(JLON,JLEV)*ZMFC15(JLON,JLEV)
    ZDETR5(JLON,JLEV)=I_KNLAB(JLON,JLEV)*ZDETR15(JLON,JLEV)&
     & +(1-I_KNLAB(JLON,JLEV))*ZMFC5(JLON,JLEV+1)  
    ZENTR5(JLON,JLEV)=I_KNLAB(JLON,JLEV)*ZENTR25(JLON,JLEV)

!     Computation of the second term of the basic equation

    ZCORU5(JLON,JLEV+1)=ZENTR5(JLON,JLEV)*PU5(JLON,JLEV+1)&
     & -ZDETR5(JLON,JLEV)*ZUN5(JLON,JLEV+1)  
    ZCORV5(JLON,JLEV+1)=ZENTR5(JLON,JLEV)*PV5(JLON,JLEV+1)&
     & -ZDETR5(JLON,JLEV)*ZVN5(JLON,JLEV+1)  
    ZCORQ5(JLON,JLEV+1)=ZENTR5(JLON,JLEV)*PQ5(JLON,JLEV+1)&
     & -ZDETR5(JLON,JLEV)*(ZQN5(JLON,JLEV+1)+ZLN5(JLON,JLEV+1))  
    ZCORS5(JLON,JLEV+1)=ZENTR5(JLON,JLEV)*ZDSE5(JLON,JLEV+1)&
     & -ZDETR5(JLON,JLEV)*(ZDSEN5(JLON,JLEV+1)&
     & -ZLHSB5(JLON)*ZLN5(JLON,JLEV+1))  

!     Computation of values u,v,h,q,T in the cloud

    ZUN5(JLON,JLEV)=I_KNLAB(JLON,JLEV)&
     & *(ZPOIL5(JLON,JLEV)*PU5(JLON,JLEV+1)&
     & +(1.0_JPRB-ZPOIL5(JLON,JLEV))*ZUN5(JLON,JLEV+1))&
     & +(1-I_KNLAB(JLON,JLEV))*PU5(JLON,JLEV)  
    ZVN5(JLON,JLEV)=I_KNLAB(JLON,JLEV)&
     & *(ZPOIL5(JLON,JLEV)*PV5(JLON,JLEV+1)&
     & +(1.0_JPRB-ZPOIL5(JLON,JLEV))*ZVN5(JLON,JLEV+1))&
     & +(1-I_KNLAB(JLON,JLEV))*PV5(JLON,JLEV)  
    ZQW5(JLON,JLEV,1)=I_KNLAB(JLON,JLEV)&
     & *(ZPOIL5(JLON,JLEV)*PQ5(JLON,JLEV+1)&
     & +(1.0_JPRB-ZPOIL5(JLON,JLEV))*ZQN5(JLON,JLEV+1))&
     & +(1-I_KNLAB(JLON,JLEV))*PQ5(JLON,JLEV)  
    ZDSEN5(JLON,JLEV)=I_KNLAB(JLON,JLEV)*(ZPOIL5(JLON,JLEV)&
     & *ZDSE5(JLON,JLEV+1)&
     & +(1.0_JPRB-ZPOIL5(JLON,JLEV))*ZDSEN5(JLON,JLEV+1))&
     & +(1-I_KNLAB(JLON,JLEV))*ZDSE5(JLON,JLEV)  
    ZMSEN5(JLON,JLEV)=I_KNLAB(JLON,JLEV)*ZMSEPR5(JLON,JLEV)&
     & +(1-I_KNLAB(JLON,JLEV))*ZMSEC5(JLON,JLEV)  

!     Initialization of the variables in the Newton loop,
!     the iterative Tw and Qw having to evolve.

    ZTW5(JLON,JLEV,1)=(ZDSEN5(JLON,JLEV)-PAPHIF5(JLON,JLEV))/ZCP5(JLON,JLEV)
    ZTW15(JLON,JLEV)=ZTW5(JLON,JLEV,1)
    ZQW15(JLON,JLEV)=ZQW5(JLON,JLEV,1)

  ENDDO

!     Newton loop for the "wet bulb" point.

  DO JIT=1,NBITER
    DO JLON=KIDIA,KFDIA

      IF (JIT == 1) THEN
        JJ=0
      ELSE
        JJ=1
      ENDIF

!     Snow option dependent computations.

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

!     Saturation calculations using the defined functions

      ZEW5(JLON,JLEV,JIT)= FOEW (ZTW5(JLON,JLEV,JIT-JJ),ZDELTA)
      ZESP5(JLON,JLEV,JIT)=ZEW5(JLON,JLEV,JIT)/PAPRSF5(JLON,JLEV)
      ZZQW5(JLON,JLEV,JIT)= FOQS (ZESP5(JLON,JLEV,JIT))

      ZDLEW5(JLON,JLEV,JIT)=FODLEW (ZTW5(JLON,JLEV,JIT-JJ),ZDELTA)
      ZDQW5(JLON,JLEV,JIT)=&
       & FODQS (ZZQW5(JLON,JLEV,JIT),ZESP5(JLON,JLEV,JIT)&
       & ,ZDLEW5(JLON,JLEV,JIT))  

!     Incrementations.

      ZDELQ5(JLON,JLEV,JIT)=&
       & (ZZQW5(JLON,JLEV,JIT)-ZQW5(JLON,JLEV,JIT-JJ))&
       & *ZCP5(JLON,JLEV)/(ZCP5(JLON,JLEV)+ZLHSB5(JLON)&
       & *ZDQW5(JLON,JLEV,JIT))  
      ZDELT5(JLON,JLEV,JIT)=&
       & -ZDELQ5(JLON,JLEV,JIT)*ZLHSB5(JLON)/ZCP5(JLON,JLEV)  
      ZQW5(JLON,JLEV,JIT)=ZQW5(JLON,JLEV,JIT-JJ)+ZDELQ5(JLON,JLEV,JIT)
      ZTW5(JLON,JLEV,JIT)=ZTW5(JLON,JLEV,JIT-JJ)+ZDELT5(JLON,JLEV,JIT)
    ENDDO

  ENDDO

  DO JLON=KIDIA,KFDIA
    ZPHI5(JLON,JLEV)=PAPHIF5(JLON,JLEV)-PAPHIF5(JLON,JLEV+1)

    ZZZL5(JLON,JLEV)=ZLN5(JLON,JLEV+1)*(1.0_JPRB-ZPOIL5(JLON,JLEV)&
     & /(1.0_JPRB+ZPOIL5(JLON,JLEV)))&
     & *(1.0_JPRB-ZPHI5(JLON,JLEV)/ECMNP)&
     & -(ZQW5(JLON,JLEV,NBITER)-ZQN5(JLON,JLEV+1)&
     & -(ZPOIL5(JLON,JLEV)/(1.0_JPRB+ZPOIL5(JLON,JLEV)))&
     & *(PQ5(JLON,JLEV+1)-ZQN5(JLON,JLEV+1)))  
    IF (ZZZL5(JLON,JLEV) > 0.0_JPRB) THEN
      ZLN5(JLON,JLEV)=ZZZL5(JLON,JLEV)*I_KNLAB(JLON,JLEV)
    ELSE
      ZLN5(JLON,JLEV)=0.0_JPRB
    ENDIF

    ZQN5(JLON,JLEV)=ZQW5(JLON,JLEV,NBITER)
    ZQDN5(JLON,JLEV)=ZQN5(JLON,JLEV)+ZLN5(JLON,JLEV)
    ZTN5(JLON,JLEV)=ZTW5(JLON,JLEV,NBITER)
  ENDDO

!     Verification of the presence of at least one cloud along the
!     "JLON" vector and modification of ITOP if necessary.

  ISUM=0
  DO JLON=KIDIA,KFDIA
    ISUM=ISUM+I_KNLAB(JLON,JLEV)+I_KNLAB(JLON,JLEV+1)
  ENDDO

  IF (ISUM /= 0) THEN
    ITOP=JLEV
  ENDIF

ENDDO

!     Calculation at the top of the atmosphere

DO JLON=KIDIA,KFDIA

  ZCORU5(JLON,KTDIA)=-ZMFC5(JLON,KTDIA)*ZUN5(JLON,KTDIA)
  ZCORV5(JLON,KTDIA)=-ZMFC5(JLON,KTDIA)*ZVN5(JLON,KTDIA)
  ZCORQ5(JLON,KTDIA)=-ZMFC5(JLON,KTDIA)*(ZQN5(JLON,KTDIA)+ZLN5(JLON,KTDIA))
  ZCORS5(JLON,KTDIA)=-ZMFC5(JLON,KTDIA)*(ZDSEN5(JLON,KTDIA)&
   & -ZLHSB5(JLON)*ZLN5(JLON,KTDIA))  
ENDDO

! ----------------------------------------------------------------------
!     Quitting in case of no convection everywhere. The "IF THEN /
!     ENDIF" encompassed sequence will not be indented given its length
!     and its special character (pseudo "RETURN" statement).

IF (ITOP < KLEV+1) THEN
! ----------------------------------------------------------------------

!*
!     ------------------------------------------------------------------
!     0. 7 - Second vertical loop (downwards) to solve the implicit
!     algorithm for compensating subsidence advection. One will at the
!     same time store provisional final values for humidity, moist
!     static energy and for the two wind components.
!     Straightforward elimination-type solution of the linear system
!     (bi-diagonal matrix).

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

! ZFQSC5    : FINAL Q VALUE (AT FIRST ONLY COMPENSATING SUBSIDENCE).
! ZFSSC5    : FINAL S VALUE (AT FIRST ONLY COMPENSATING SUBSIDENCE).
! ZFUSC5    : FINAL U VALUE (AT FIRST ONLY COMPENSATING SUBSIDENCE).
! ZFVSC5    : FINAL V VALUE (AT FIRST ONLY COMPENSATING SUBSIDENCE).

! ZDFMDS5  :  HALF THE MASS FLUX TIME THE JUMP IN S.
! ZDFMDU5  :  HALF THE MASS FLUX TIME THE JUMP IN U.
! ZDFMDV5  :  HALF THE MASS FLUX TIME THE JUMP IN V.
! ZDFMDQ5  :  HALF THE MASS FLUX TIME THE JUMP IN Q.

!     Special case of the first level.

  DO JLON=KIDIA,KFDIA

    ZIV15(JLON,ITOP)=PDELP5(JLON,ITOP)/TSPHY
    ZIV5(JLON,ITOP)=1.0_JPRB/(ZIV15(JLON,ITOP)+ZMFC5(JLON,ITOP))

    ZDFMDU5(JLON,ITOP)=0.5_JPRB*ZMFC5(JLON,ITOP)&
     & *(PU5(JLON,ITOP+1)-PU5(JLON,ITOP))  
    ZDFMDV5(JLON,ITOP)=0.5_JPRB*ZMFC5(JLON,ITOP)&
     & *(PV5(JLON,ITOP+1)-PV5(JLON,ITOP))  
    ZDFMDQ5(JLON,ITOP)=0.5_JPRB*ZMFC5(JLON,ITOP)&
     & *(PQ5(JLON,ITOP+1)-PQ5(JLON,ITOP))  
    ZDFMDS5(JLON,ITOP)=0.5_JPRB*ZMFC5(JLON,ITOP)*(ZDSE5(JLON,ITOP+1)&
     & -ZDSE5(JLON,ITOP))  

    ZFUSC5(JLON,ITOP)=(PU5(JLON,ITOP)*ZIV15(JLON,ITOP)&
     & -ZCORU5(JLON,ITOP)-ZDFMDU5(JLON,ITOP))*ZIV5(JLON,ITOP)  
    ZFVSC5(JLON,ITOP)=(PV5(JLON,ITOP)*ZIV15(JLON,ITOP)&
     & -ZCORV5(JLON,ITOP)-ZDFMDV5(JLON,ITOP))*ZIV5(JLON,ITOP)  
    ZFQSC5(JLON,ITOP)=(PQ5(JLON,ITOP)*ZIV15(JLON,ITOP)&
     & -ZCORQ5(JLON,ITOP)-ZDFMDQ5(JLON,ITOP))*ZIV5(JLON,ITOP)  
    ZFSSC5(JLON,ITOP)=(ZDSE5(JLON,ITOP)*ZIV15(JLON,ITOP)&
     & -ZCORS5(JLON,ITOP)-ZDFMDS5(JLON,ITOP))*ZIV5(JLON,ITOP)  
  ENDDO

!     Vertical loop with using the results from previous upper level.

  DO JLEV=ITOP+1,KLEV-1
    DO JLON=KIDIA,KFDIA
      ZIV15(JLON,JLEV)=PDELP5(JLON,JLEV)/TSPHY
      ZIV5(JLON,JLEV)=1.0_JPRB/(ZIV15(JLON,JLEV)+ZMFC5(JLON,JLEV))

      ZFMDU5(JLON,JLEV)=0.5_JPRB*ZMFC5(JLON,JLEV)&
       & *(PU5(JLON,JLEV+1)-PU5(JLON,JLEV))  
      ZFMDV5(JLON,JLEV)=0.5_JPRB*ZMFC5(JLON,JLEV)&
       & *(PV5(JLON,JLEV+1)-PV5(JLON,JLEV))  
      ZFMDQ5(JLON,JLEV)=0.5_JPRB*ZMFC5(JLON,JLEV)&
       & *(PQ5(JLON,JLEV+1)-PQ5(JLON,JLEV))  
      ZFMDS5(JLON,JLEV)=0.5_JPRB*ZMFC5(JLON,JLEV)&
       & *(ZDSE5(JLON,JLEV+1)-ZDSE5(JLON,JLEV))  

      ZFUSC5(JLON,JLEV)=(PU5(JLON,JLEV)*ZIV15(JLON,JLEV)&
       & -ZCORU5(JLON,JLEV)&
       & +ZMFC5(JLON,JLEV-1)*ZFUSC5(JLON,JLEV-1)&
       & -(ZFMDU5(JLON,JLEV)-ZDFMDU5(JLON,JLEV-1)))&
       & *ZIV5(JLON,JLEV)  
      ZFVSC5(JLON,JLEV)=(PV5(JLON,JLEV)*ZIV15(JLON,JLEV)&
       & -ZCORV5(JLON,JLEV)&
       & +ZMFC5(JLON,JLEV-1)*ZFVSC5(JLON,JLEV-1)&
       & -(ZFMDV5(JLON,JLEV)-ZDFMDV5(JLON,JLEV-1)))&
       & *ZIV5(JLON,JLEV)  
      ZFQSC5(JLON,JLEV)=(PQ5(JLON,JLEV)*ZIV15(JLON,JLEV)&
       & -ZCORQ5(JLON,JLEV)&
       & +ZMFC5(JLON,JLEV-1)*ZFQSC5(JLON,JLEV-1)&
       & -(ZFMDQ5(JLON,JLEV)-ZDFMDQ5(JLON,JLEV-1)))&
       & *ZIV5(JLON,JLEV)  
      ZFSSC5(JLON,JLEV)=(ZDSE5(JLON,JLEV)*ZIV15(JLON,JLEV)&
       & -ZCORS5(JLON,JLEV)&
       & +ZMFC5(JLON,JLEV-1)*ZFSSC5(JLON,JLEV-1)&
       & -(ZFMDS5(JLON,JLEV)-ZDFMDS5(JLON,JLEV-1)))&
       & *ZIV5(JLON,JLEV)  

      ZDFMDU5(JLON,JLEV)=ZFMDU5(JLON,JLEV)
      ZDFMDV5(JLON,JLEV)=ZFMDV5(JLON,JLEV)
      ZDFMDQ5(JLON,JLEV)=ZFMDQ5(JLON,JLEV)
      ZDFMDS5(JLON,JLEV)=ZFMDS5(JLON,JLEV)

    ENDDO
  ENDDO

!     Special case of the last level.

  IF (ITOP /= KLEV) THEN
    DO JLON=KIDIA,KFDIA
      ZIV5(JLON,KLEV)=1.0_JPRB/(PDELP5(JLON,KLEV)/TSPHY)

      ZFUSC5(JLON,KLEV)=PU5(JLON,KLEV)+(ZMFC5(JLON,KLEV-1)&
       & *ZFUSC5(JLON,KLEV-1)-ZCORU5(JLON,KLEV)&
       & +ZDFMDU5(JLON,KLEV-1))*ZIV5(JLON,KLEV)  
      ZFVSC5(JLON,KLEV)=PV5(JLON,KLEV)+(ZMFC5(JLON,KLEV-1)&
       & *ZFVSC5(JLON,KLEV-1)-ZCORV5(JLON,KLEV)&
       & +ZDFMDV5(JLON,KLEV-1))*ZIV5(JLON,KLEV)  
      ZFQSC5(JLON,KLEV)=PQ5(JLON,KLEV)+(ZMFC5(JLON,KLEV-1)&
       & *ZFQSC5(JLON,KLEV-1)-ZCORQ5(JLON,KLEV)&
       & +ZDFMDQ5(JLON,KLEV-1))*ZIV5(JLON,KLEV)  
      ZFSSC5(JLON,KLEV)=ZDSE5(JLON,KLEV)+(ZMFC5(JLON,KLEV-1)&
       & *ZFSSC5(JLON,KLEV-1)-ZCORS5(JLON,KLEV)&
       & +ZDFMDS5(JLON,KLEV-1))*ZIV5(JLON,KLEV)  
    ENDDO
  ENDIF

!*
!     ------------------------------------------------------------------
!     0. 8 - Flux computation

!     Diffusive humidity flux and interpolated latent heat of fluxes.

! For trajectory
! --------------
! - TEMPORARY(S) 2D (0:KLEV) .

! ZZLHP5    : FICTITIOUS PRECIPITATION FLUX LATENT HEAT.

  DO JLON=KIDIA,KFDIA
    ZZLHP5(JLON,ITOP-1)=-ZLHL5(JLON,ITOP-1)-ZSNP5(JLON,ITOP-1)&
     & *(ZLHN5(JLON,ITOP-1)-ZLHL5(JLON,ITOP-1))  

  ENDDO
  DO JLEV=ITOP,KLEV-1
    DO JLON=KIDIA,KFDIA
      ZDIFCQ5(JLON,JLEV)=ZMFC5(JLON,JLEV)*0.5_JPRB*(ZFQSC5(JLON,JLEV)&
       & +ZFQSC5(JLON,JLEV+1)-ZQDN5(JLON,JLEV)&
       & -ZQDN5(JLON,JLEV+1))/RG  
      ZZLHP5(JLON,JLEV)=-ZLHL5(JLON,JLEV)-ZSNP5(JLON,JLEV)&
       & *(ZLHN5(JLON,JLEV)-ZLHL5(JLON,JLEV))  
    ENDDO
  ENDDO

  DO JLON=KIDIA,KFDIA
    ZZLHP5(JLON,KLEV)=ZLHSB5(JLON)
  ENDDO

!     Final computation of fluxes with security against negative
!     precipitation.

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

!     Diffusive momentum fluxes.

      ZSTRCU5(JLON,JLEV)=ZSTRCU5(JLON,JLEV-1)-ZPOID5(JLON,JLEV)&
       & *(ZFUSC5(JLON,JLEV)-PU5(JLON,JLEV))  
      ZSTRCV5(JLON,JLEV)=ZSTRCV5(JLON,JLEV-1)-ZPOID5(JLON,JLEV)&
       & *(ZFVSC5(JLON,JLEV)-PV5(JLON,JLEV))  

!     Humidity fluxes (total and precipitating).

      ZFTOTQ5(JLON,JLEV)=ZDIFCQ5(JLON,JLEV-1)&
       & +ZFPLCL5(JLON,JLEV-1)+ZFPLCN5(JLON,JLEV-1)&
       & -(ZPOID5(JLON,JLEV)*(ZFQSC5(JLON,JLEV)-PQ5(JLON,JLEV)) )  
      ZFCORQ5(JLON,JLEV)=MAX(0.0_JPRB,ZDIFCQ5(JLON,JLEV)-ZFTOTQ5(JLON,JLEV))

      ZFPLCL5(JLON,JLEV)=(ZFCORQ5(JLON,JLEV)&
       & -(ZDIFCQ5(JLON,JLEV)-ZFTOTQ5(JLON,JLEV)))&
       & *(1.0_JPRB-ZSNP5(JLON,JLEV))  
      ZFPLCN5(JLON,JLEV)=(ZFCORQ5(JLON,JLEV)-(ZDIFCQ5(JLON,JLEV)&
       & -ZFTOTQ5(JLON,JLEV)))*ZSNP5(JLON,JLEV)  

!     Enthalpy fluxes (total and diffusive).

      ZFTOTS5(JLON,JLEV)=ZDIFCS5(JLON,JLEV-1)-ZZLHP5(JLON,JLEV-1)&
       & *(ZFPLCL5(JLON,JLEV-1)+ZFPLCN5(JLON,JLEV-1))&
       & -ZPOID5(JLON,JLEV)*(ZFSSC5(JLON,JLEV)-ZDSE5(JLON,JLEV))  
      ZDIFCS5(JLON,JLEV)=ZFTOTS5(JLON,JLEV)-ZLHSB5(JLON)&
       & *ZFCORQ5(JLON,JLEV)+ZZLHP5(JLON,JLEV)&
       & *(ZFPLCL5(JLON,JLEV)+ZFPLCN5(JLON,JLEV))  

    ENDDO
  ENDDO

!     Setting all results to zero in case of negative precipitations at
!     the surface .

  DO JLON=KIDIA,KFDIA
    ZZVAL=ZFPLCL5(JLON,KLEV)+ZFPLCN5(JLON,KLEV)-SCO
    I_KNND(JLON)=I_KNND(JLON)*MAX(0.0_JPRB,-SIGN(1.0_JPRB,0.0_JPRB-ZZVAL))
  ENDDO
  DO JLEV=ITOP,KLEV
    DO JLON=KIDIA,KFDIA
      PFPLCL5(JLON,JLEV)=I_KNND(JLON)*ZFPLCL5(JLON,JLEV)
      PFPLCN5(JLON,JLEV)=I_KNND(JLON)*ZFPLCN5(JLON,JLEV)
      PDIFCQ5(JLON,JLEV)=I_KNND(JLON)*ZDIFCQ5(JLON,JLEV)
      PDIFCS5(JLON,JLEV)=I_KNND(JLON)*ZDIFCS5(JLON,JLEV)
      PSTRCU5(JLON,JLEV)=I_KNND(JLON)*ZSTRCU5(JLON,JLEV)
      PSTRCV5(JLON,JLEV)=I_KNND(JLON)*ZSTRCV5(JLON,JLEV)
    ENDDO
  ENDDO

!*
!     Return from the pseudo-return situated after loop 67.

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

!*
!     INITIALIZATION OF THE LOCAL VARIABLES

ZLHSB(:)=0.0_JPRB
ZTN(:)=0.0_JPRB
ZQN(:)=0.0_JPRB
ZS1(:)=0.0_JPRB
ZS2(:)=0.0_JPRB
ZPOII(:)=0.0_JPRB
ZALF(:)=0.0_JPRB
ZLN(:)=0.0_JPRB
ZUN(:)=0.0_JPRB
ZVN(:)=0.0_JPRB
ZMSEN(:)=0.0_JPRB
ZDFMDQ(:)=0.0_JPRB
ZDFMDU(:)=0.0_JPRB
ZDFMDV(:)=0.0_JPRB
ZDFMDS(:)=0.0_JPRB
ZDSEN(:)=0.0_JPRB
ZENTR(:)=0.0_JPRB
ZDETR(:)=0.0_JPRB
ZPOIL(:)=0.0_JPRB

ZCP(:,:)=0.0_JPRB
ZLHE(:,:)=0.0_JPRB
ZDSE(:,:)=0.0_JPRB
ZQW(:,:)=0.0_JPRB
ZTW(:,:)=0.0_JPRB
ZMSE(:,:)=0.0_JPRB
ZMSEU(:,:)=0.0_JPRB
ZF(:,:)=0.0_JPRB
ZMFC(:,:)=0.0_JPRB
ZCORU(:,:)=0.0_JPRB
ZCORV(:,:)=0.0_JPRB
ZCORQ(:,:)=0.0_JPRB
ZCORS(:,:)=0.0_JPRB
ZFQSC(:,:)=0.0_JPRB
ZFUSC(:,:)=0.0_JPRB
ZFVSC(:,:)=0.0_JPRB
ZFSSC(:,:)=0.0_JPRB
ZQDN(:,:)=0.0_JPRB
ZPOID(:,:)=0.0_JPRB
ZIPOI(:,:)=0.0_JPRB
ZMSEC(:,:)=0.0_JPRB
ZPHI(:,:)=0.0_JPRB

ZSNP(:,:)=0.0_JPRB
ZLHN(:,:)=0.0_JPRB
ZLHL(:,:)=0.0_JPRB
ZFORM(:,:)=0.0_JPRB
ZZLHP(:,:)=0.0_JPRB

! ----------------------------------------------------------------------
!     QUITTING IN CASE OF NO CONVECTION EVERYWHERE. THE "IF THEN /
!     ENDIF" ENCOMPASSED SEQUENCE WILL NOT BE INDENTED GIVEN ITS LENGTH
!     AND ITS SPECIAL CHARACTER (PSEUDO "RETURN" STATEMENT).

IF (ITOP < KLEV+1) THEN
! ----------------------------------------------------------------------
!*
!     ------------------------------------------------------------------
!     VIII - FLUX COMPUTATION

!     SETTING ALL RESULTS TO ZERO IN CASE OF NEGATIVE PRECIPITATIONS AT
!     THE SURFACE .

  DO JLEV=ITOP,KLEV
    DO JLON=KIDIA,KFDIA
      PSTRCV(JLON,JLEV)=I_KNND(JLON)*PSTRCV(JLON,JLEV)
      PSTRCU(JLON,JLEV)=I_KNND(JLON)*PSTRCU(JLON,JLEV)
      PDIFCS(JLON,JLEV)=I_KNND(JLON)*PDIFCS(JLON,JLEV)
      PDIFCQ(JLON,JLEV)=I_KNND(JLON)*PDIFCQ(JLON,JLEV)
      PFPLCN(JLON,JLEV)=I_KNND(JLON)*PFPLCN(JLON,JLEV)
      PFPLCL(JLON,JLEV)=I_KNND(JLON)*PFPLCL(JLON,JLEV)
    ENDDO
  ENDDO

!     FINAL COMPUTATION OF FLUXES WITH SECURITY AGAINST NEGATIVE
!     PRECIPITATION.

  DO JLEV=KLEV,ITOP,-1
    DO JLON=KIDIA,KFDIA
      ZFTOTS=0.0_JPRB
      ZFCORQ=0.0_JPRB
      ZFTOTQ=0.0_JPRB

!     ENTHALPY FLUXES (TOTAL AND DIFFUSIVE).

      ZFTOTS=ZFTOTS+PDIFCS(JLON,JLEV)
      ZFCORQ=ZFCORQ-ZLHSB5(JLON)*PDIFCS(JLON,JLEV)
      ZLHSB(JLON)=ZLHSB(JLON)-ZFCORQ5(JLON,JLEV)*PDIFCS(JLON,JLEV)
      ZZLHP(JLON,JLEV)=ZZLHP(JLON,JLEV)+(ZFPLCL5(JLON,JLEV)&
       & +ZFPLCN5(JLON,JLEV))*PDIFCS(JLON,JLEV)  
      PFPLCL(JLON,JLEV)=PFPLCL(JLON,JLEV)+ZZLHP5(JLON,JLEV)*PDIFCS(JLON,JLEV)
      PFPLCN(JLON,JLEV)=PFPLCN(JLON,JLEV)+ZZLHP5(JLON,JLEV)*PDIFCS(JLON,JLEV)
      PDIFCS(JLON,JLEV)=0.0_JPRB

      PDIFCS(JLON,JLEV-1)=PDIFCS(JLON,JLEV-1)+ZFTOTS
      ZZLHP(JLON,JLEV-1)=ZZLHP(JLON,JLEV-1)&
       & -(ZFPLCL5(JLON,JLEV-1)+ZFPLCN5(JLON,JLEV-1))*ZFTOTS  
      PFPLCL(JLON,JLEV-1)=PFPLCL(JLON,JLEV-1)-ZZLHP5(JLON,JLEV-1)*ZFTOTS
      PFPLCN(JLON,JLEV-1)=PFPLCN(JLON,JLEV-1)-ZZLHP5(JLON,JLEV-1)*ZFTOTS
      ZPOID(JLON,JLEV)=ZPOID(JLON,JLEV)&
       & -(ZFSSC5(JLON,JLEV)-ZDSE5(JLON,JLEV))*ZFTOTS  
      ZFSSC(JLON,JLEV)=ZFSSC(JLON,JLEV)-ZPOID5(JLON,JLEV)*ZFTOTS
      ZDSE(JLON,JLEV)=ZDSE(JLON,JLEV)+ZPOID5(JLON,JLEV)*ZFTOTS

!     HUMIDITY FLUXES (TOTAL AND PRECIPITATING).

      ZSNP(JLON,JLEV)=ZSNP(JLON,JLEV)+(ZFCORQ5(JLON,JLEV)&
       & -ZDIFCQ5(JLON,JLEV)+ZFTOTQ5(JLON,JLEV))&
       & *PFPLCN(JLON,JLEV)  
      ZFCORQ=ZFCORQ+ZSNP5(JLON,JLEV)*PFPLCN(JLON,JLEV)
      PDIFCQ(JLON,JLEV)=PDIFCQ(JLON,JLEV)-ZSNP5(JLON,JLEV)*PFPLCN(JLON,JLEV)
      ZFTOTQ=ZFTOTQ+ZSNP5(JLON,JLEV)*PFPLCN(JLON,JLEV)
      PFPLCN(JLON,JLEV)=0.0_JPRB

      ZSNP(JLON,JLEV)=ZSNP(JLON,JLEV)-(ZFCORQ5(JLON,JLEV)&
       & -ZDIFCQ5(JLON,JLEV)+ZFTOTQ5(JLON,JLEV))&
       & *PFPLCL(JLON,JLEV)  
      ZFCORQ=ZFCORQ+(1.0_JPRB-ZSNP5(JLON,JLEV))*PFPLCL(JLON,JLEV)
      PDIFCQ(JLON,JLEV)=PDIFCQ(JLON,JLEV)&
       & -(1.0_JPRB-ZSNP5(JLON,JLEV))*PFPLCL(JLON,JLEV)  
      ZFTOTQ=ZFTOTQ+(1.0_JPRB-ZSNP5(JLON,JLEV))*PFPLCL(JLON,JLEV)
      PFPLCL(JLON,JLEV)=0.0_JPRB

      IF ((ZDIFCQ5(JLON,JLEV)-ZFTOTQ5(JLON,JLEV)) > 0.0_JPRB) THEN
        PDIFCQ(JLON,JLEV)=PDIFCQ(JLON,JLEV)+ZFCORQ
        ZFTOTQ=ZFTOTQ-ZFCORQ
      ENDIF

      PDIFCQ(JLON,JLEV-1)=PDIFCQ(JLON,JLEV-1)+ZFTOTQ
      PFPLCL(JLON,JLEV-1)=PFPLCL(JLON,JLEV-1)+ZFTOTQ
      PFPLCN(JLON,JLEV-1)=PFPLCN(JLON,JLEV-1)+ZFTOTQ
      ZPOID(JLON,JLEV)=ZPOID(JLON,JLEV)&
       & -(ZFQSC5(JLON,JLEV)-PQ5(JLON,JLEV))*ZFTOTQ  
      ZFQSC(JLON,JLEV)=ZFQSC(JLON,JLEV)-ZPOID5(JLON,JLEV)*ZFTOTQ
      PQ(JLON,JLEV)=PQ(JLON,JLEV)+ZPOID5(JLON,JLEV)*ZFTOTQ

!     DIFFUSIVE MOMENTUM FLUXES.

      PSTRCV(JLON,JLEV-1)=PSTRCV(JLON,JLEV-1)+PSTRCV(JLON,JLEV)
      ZPOID(JLON,JLEV)=ZPOID(JLON,JLEV)&
       & -(ZFVSC5(JLON,JLEV)-PV5(JLON,JLEV))*PSTRCV(JLON,JLEV)  
      ZFVSC(JLON,JLEV)=ZFVSC(JLON,JLEV)-ZPOID5(JLON,JLEV)*PSTRCV(JLON,JLEV)
      PV(JLON,JLEV)=PV(JLON,JLEV)+ZPOID5(JLON,JLEV)*PSTRCV(JLON,JLEV)
      PSTRCV(JLON,JLEV)=0.0_JPRB

      PSTRCU(JLON,JLEV-1)=PSTRCU(JLON,JLEV-1)+PSTRCU(JLON,JLEV)
      ZPOID(JLON,JLEV)=ZPOID(JLON,JLEV)&
       & -(ZFUSC5(JLON,JLEV)-PU5(JLON,JLEV))*PSTRCU(JLON,JLEV)  
      ZFUSC(JLON,JLEV)=ZFUSC(JLON,JLEV)-ZPOID5(JLON,JLEV)*PSTRCU(JLON,JLEV)
      PU(JLON,JLEV)=PU(JLON,JLEV)+ZPOID5(JLON,JLEV)*PSTRCU(JLON,JLEV)
      PSTRCU(JLON,JLEV)=0.0_JPRB

    ENDDO
  ENDDO

!     DIFFUSIVE HUMIDITY FLUX AND INTERPOLATED LATENT HEAT OF FLUXES.

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

! ZZLHP     : FICTITIOUS PRECIPITATION FLUX LATENT HEAT.

  DO JLON=KIDIA,KFDIA
    ZLHSB(JLON)=ZLHSB(JLON)+ZZLHP(JLON,KLEV)
    ZZLHP(JLON,KLEV)=0.0_JPRB
  ENDDO

  DO JLEV=KLEV-1,ITOP,-1
    DO JLON=KIDIA,KFDIA
      ZLHL(JLON,JLEV)=ZLHL(JLON,JLEV)+(ZSNP5(JLON,JLEV)-1.0_JPRB)&
       & *ZZLHP(JLON,JLEV)  
      ZSNP(JLON,JLEV)=ZSNP(JLON,JLEV)-(ZLHN5(JLON,JLEV)&
       & -ZLHL5(JLON,JLEV))*ZZLHP(JLON,JLEV)  
      ZLHN(JLON,JLEV)=ZLHN(JLON,JLEV)-ZSNP5(JLON,JLEV)*ZZLHP(JLON,JLEV)
      ZZLHP(JLON,JLEV)=0.0_JPRB

      ZMFC(JLON,JLEV)=ZMFC(JLON,JLEV)+(0.5_JPRB/RG)&
       & *(ZFQSC5(JLON,JLEV)+ZFQSC5(JLON,JLEV+1)&
       & -ZQDN5(JLON,JLEV)-ZQDN5(JLON,JLEV+1))&
       & *PDIFCQ(JLON,JLEV)  
      ZFQSC(JLON,JLEV)=ZFQSC(JLON,JLEV)+(0.5_JPRB/RG)&
       & *ZMFC5(JLON,JLEV)*PDIFCQ(JLON,JLEV)  
      ZFQSC(JLON,JLEV+1)=ZFQSC(JLON,JLEV+1)+(0.5_JPRB/RG)&
       & *ZMFC5(JLON,JLEV)*PDIFCQ(JLON,JLEV)  
      ZQDN(JLON,JLEV)=ZQDN(JLON,JLEV)-(0.5_JPRB/RG)&
       & *ZMFC5(JLON,JLEV)*PDIFCQ(JLON,JLEV)  
      ZQDN(JLON,JLEV+1)=ZQDN(JLON,JLEV+1)-(0.5_JPRB/RG)&
       & *ZMFC5(JLON,JLEV)*PDIFCQ(JLON,JLEV)  
      PDIFCQ(JLON,JLEV)=0.0_JPRB
    ENDDO
  ENDDO
  DO JLON=KIDIA,KFDIA
    ZLHL(JLON,ITOP-1)=ZLHL(JLON,ITOP-1)+(ZSNP5(JLON,ITOP-1)-1.0_JPRB)&
     & *ZZLHP(JLON,ITOP-1)  
    ZSNP(JLON,ITOP-1)=ZSNP(JLON,ITOP-1)-(ZLHN5(JLON,ITOP-1)&
     & -ZLHL5(JLON,ITOP-1))*ZZLHP(JLON,ITOP-1)  
    ZLHN(JLON,ITOP-1)=ZLHN(JLON,ITOP-1)-ZSNP5(JLON,ITOP-1)*ZZLHP(JLON,ITOP-1)
    ZZLHP(JLON,ITOP-1)=0.0_JPRB
  ENDDO

!*
!     ------------------------------------------------------------------
!     VII - SECOND VERTICAL LOOP (DOWNWARDS) TO SOLVE THE IMPLICIT
!     ALGORITHM FOR COMPENSATING SUBSIDENCE ADVECTION. ONE WILL AT THE
!     SAME TIME STORE PROVISIONAL FINAL VALUES FOR HUMIDITY, MOIST
!     STATIC ENERGY AND FOR THE TWO WIND COMPONENTS.
!     STRAIGHTFORWARD ELIMINATION-TYPE SOLUTION OF THE LINEAR SYSTEM
!     (BI-DIAGONAL MATRIX).

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

! ZFQSC     : FINAL Q VALUE (AT FIRST ONLY COMPENSATING SUBSIDENCE).
! ZFSSC     : FINAL S VALUE (AT FIRST ONLY COMPENSATING SUBSIDENCE).
! ZFUSC     : FINAL U VALUE (AT FIRST ONLY COMPENSATING SUBSIDENCE).
! ZFVSC     : FINAL V VALUE (AT FIRST ONLY COMPENSATING SUBSIDENCE).

! - TEMPORARY(S) 1D .

! ZDFMDS   :  HALF THE MASS FLUX TIME THE JUMP IN S.
! ZDFMDU   :  HALF THE MASS FLUX TIME THE JUMP IN U.
! ZDFMDV   :  HALF THE MASS FLUX TIME THE JUMP IN V.
! ZDFMDQ   :  HALF THE MASS FLUX TIME THE JUMP IN Q.

!     SPECIAL CASE OF THE LAST LEVEL.

  IF (ITOP /= KLEV) THEN
    DO JLON=KIDIA,KFDIA
      ZIV=0.0_JPRB
      ZDSE(JLON,KLEV)=ZDSE(JLON,KLEV)+ZFSSC(JLON,KLEV)
      ZIV=ZIV+(ZMFC5(JLON,KLEV-1)*ZFSSC5(JLON,KLEV-1)&
       & -ZCORS5(JLON,KLEV)+ZDFMDS5(JLON,KLEV-1))*ZFSSC(JLON,KLEV)  
      ZFSSC(JLON,KLEV-1)=ZFSSC(JLON,KLEV-1)+ZIV5(JLON,KLEV)&
       & *ZMFC5(JLON,KLEV-1)*ZFSSC(JLON,KLEV)  
      ZMFC(JLON,KLEV-1)=ZMFC(JLON,KLEV-1)+ZIV5(JLON,KLEV)&
       & *ZFSSC5(JLON,KLEV-1)*ZFSSC(JLON,KLEV)  
      ZCORS(JLON,KLEV)=ZCORS(JLON,KLEV)-ZIV5(JLON,KLEV)*ZFSSC(JLON,KLEV)
      ZDFMDS(JLON)=ZDFMDS(JLON)+ZIV5(JLON,KLEV)*ZFSSC(JLON,KLEV)
      ZFSSC(JLON,KLEV)=0.0_JPRB

      PQ(JLON,KLEV)=PQ(JLON,KLEV)+ZFQSC(JLON,KLEV)
      ZIV=ZIV+(ZMFC5(JLON,KLEV-1)*ZFQSC5(JLON,KLEV-1)&
       & -ZCORQ5(JLON,KLEV)+ZDFMDQ5(JLON,KLEV-1))*ZFQSC(JLON,KLEV)  
      ZFQSC(JLON,KLEV-1)=ZFQSC(JLON,KLEV-1)+ZIV5(JLON,KLEV)&
       & *ZMFC5(JLON,KLEV-1)*ZFQSC(JLON,KLEV)  
      ZMFC(JLON,KLEV-1)=ZMFC(JLON,KLEV-1)+ZIV5(JLON,KLEV)&
       & *ZFQSC5(JLON,KLEV-1)*ZFQSC(JLON,KLEV)  
      ZCORQ(JLON,KLEV)=ZCORQ(JLON,KLEV)-ZIV5(JLON,KLEV)*ZFQSC(JLON,KLEV)
      ZDFMDQ(JLON)=ZDFMDQ(JLON)+ZIV5(JLON,KLEV)*ZFQSC(JLON,KLEV)
      ZFQSC(JLON,KLEV)=0.0_JPRB

      PV(JLON,KLEV)=PV(JLON,KLEV)+ZFVSC(JLON,KLEV)
      ZIV=ZIV+(ZMFC5(JLON,KLEV-1)*ZFVSC5(JLON,KLEV-1)&
       & -ZCORV5(JLON,KLEV)+ZDFMDV5(JLON,KLEV-1))*ZFVSC(JLON,KLEV)  
      ZFVSC(JLON,KLEV-1)=ZFVSC(JLON,KLEV-1)+ZIV5(JLON,KLEV)&
       & *ZMFC5(JLON,KLEV-1)*ZFVSC(JLON,KLEV)  
      ZMFC(JLON,KLEV-1)=ZMFC(JLON,KLEV-1)+ZIV5(JLON,KLEV)&
       & *ZFVSC5(JLON,KLEV-1)*ZFVSC(JLON,KLEV)  
      ZCORV(JLON,KLEV)=ZCORV(JLON,KLEV)-ZIV5(JLON,KLEV)*ZFVSC(JLON,KLEV)
      ZDFMDV(JLON)=ZDFMDV(JLON)+ZIV5(JLON,KLEV)*ZFVSC(JLON,KLEV)
      ZFVSC(JLON,KLEV)=0.0_JPRB

      PU(JLON,KLEV)=PU(JLON,KLEV)+ZFUSC(JLON,KLEV)
      ZIV=ZIV+(ZMFC5(JLON,KLEV-1)*ZFUSC5(JLON,KLEV-1)&
       & -ZCORU5(JLON,KLEV)+ZDFMDU5(JLON,KLEV-1))*ZFUSC(JLON,KLEV)  
      ZFUSC(JLON,KLEV-1)=ZFUSC(JLON,KLEV-1)+ZIV5(JLON,KLEV)&
       & *ZMFC5(JLON,KLEV-1)*ZFUSC(JLON,KLEV)  
      ZMFC(JLON,KLEV-1)=ZMFC(JLON,KLEV-1)+ZIV5(JLON,KLEV)&
       & *ZFUSC5(JLON,KLEV-1)*ZFUSC(JLON,KLEV)  
      ZCORU(JLON,KLEV)=ZCORU(JLON,KLEV)-ZIV5(JLON,KLEV)*ZFUSC(JLON,KLEV)
      ZDFMDU(JLON)=ZDFMDU(JLON)+ZIV5(JLON,KLEV)*ZFUSC(JLON,KLEV)
      ZFUSC(JLON,KLEV)=0.0_JPRB

      PDELP(JLON,KLEV)=PDELP(JLON,KLEV)-(TSPHY/PDELP5(JLON,KLEV)**2)*ZIV
    ENDDO
  ENDIF

!     VERTICAL LOOP WITH USING THE RESULTS FROM PREVIOUS UPPER LEVEL.

  DO JLEV=KLEV-1,ITOP+1,-1
    DO JLON=KIDIA,KFDIA
      ZFMDS=0.0_JPRB
      ZFMDQ=0.0_JPRB
      ZFMDV=0.0_JPRB
      ZFMDU=0.0_JPRB
      ZIV=0.0_JPRB
      ZIV1=0.0_JPRB

      ZFMDS=ZFMDS+ZDFMDS(JLON)
      ZDFMDS(JLON)=0.0_JPRB

      ZFMDQ=ZFMDQ+ZDFMDQ(JLON)
      ZDFMDQ(JLON)=0.0_JPRB

      ZFMDV=ZFMDV+ZDFMDV(JLON)
      ZDFMDV(JLON)=0.0_JPRB

      ZFMDU=ZFMDU+ZDFMDU(JLON)
      ZDFMDU(JLON)=0.0_JPRB

      ZIV=ZIV+(ZDSE5(JLON,JLEV)*ZIV15(JLON,JLEV)-ZCORS5(JLON,JLEV)&
       & +ZMFC5(JLON,JLEV-1)*ZFSSC5(JLON,JLEV-1)&
       & -(ZFMDS5(JLON,JLEV)-ZDFMDS5(JLON,JLEV-1)))*ZFSSC(JLON,JLEV)  
      ZIV1=ZIV1+ZIV5(JLON,JLEV)*ZDSE5(JLON,JLEV)*ZFSSC(JLON,JLEV)
      ZDSE(JLON,JLEV)=ZDSE(JLON,JLEV)+ZIV5(JLON,JLEV)&
       & *ZIV15(JLON,JLEV)*ZFSSC(JLON,JLEV)  
      ZCORS(JLON,JLEV)=ZCORS(JLON,JLEV)-ZIV5(JLON,JLEV)*ZFSSC(JLON,JLEV)
      ZFSSC(JLON,JLEV-1)=ZFSSC(JLON,JLEV-1)+ZIV5(JLON,JLEV)&
       & *ZMFC5(JLON,JLEV-1)*ZFSSC(JLON,JLEV)  
      ZMFC(JLON,JLEV-1)=ZMFC(JLON,JLEV-1)+ZIV5(JLON,JLEV)&
       & *ZFSSC5(JLON,JLEV-1)*ZFSSC(JLON,JLEV)  
      ZFMDS=ZFMDS-ZIV5(JLON,JLEV)*ZFSSC(JLON,JLEV)
      ZDFMDS(JLON)=ZDFMDS(JLON)+ZIV5(JLON,JLEV)*ZFSSC(JLON,JLEV)
      ZFSSC(JLON,JLEV)=0.0_JPRB

      ZIV=ZIV+(PQ5(JLON,JLEV)*ZIV15(JLON,JLEV)-ZCORQ5(JLON,JLEV)&
       & +ZMFC5(JLON,JLEV-1)*ZFQSC5(JLON,JLEV-1)&
       & -(ZFMDQ5(JLON,JLEV)-ZDFMDQ5(JLON,JLEV-1)))*ZFQSC(JLON,JLEV)  
      ZIV1=ZIV1+ZIV5(JLON,JLEV)*PQ5(JLON,JLEV)*ZFQSC(JLON,JLEV)
      PQ(JLON,JLEV)=PQ(JLON,JLEV)+ZIV5(JLON,JLEV)*ZIV15(JLON,JLEV)&
       & *ZFQSC(JLON,JLEV)  
      ZCORQ(JLON,JLEV)=ZCORQ(JLON,JLEV)-ZIV5(JLON,JLEV)*ZFQSC(JLON,JLEV)
      ZFQSC(JLON,JLEV-1)=ZFQSC(JLON,JLEV-1)+ZIV5(JLON,JLEV)&
       & *ZMFC5(JLON,JLEV-1)*ZFQSC(JLON,JLEV)  
      ZMFC(JLON,JLEV-1)=ZMFC(JLON,JLEV-1)+ZIV5(JLON,JLEV)&
       & *ZFQSC5(JLON,JLEV-1)*ZFQSC(JLON,JLEV)  
      ZFMDQ=ZFMDQ-ZIV5(JLON,JLEV)*ZFQSC(JLON,JLEV)
      ZDFMDQ(JLON)=ZDFMDQ(JLON)+ZIV5(JLON,JLEV)*ZFQSC(JLON,JLEV)
      ZFQSC(JLON,JLEV)=0.0_JPRB

      ZIV=ZIV+(PV5(JLON,JLEV)*ZIV15(JLON,JLEV)-ZCORV5(JLON,JLEV)&
       & +ZMFC5(JLON,JLEV-1)*ZFVSC5(JLON,JLEV-1)&
       & -(ZFMDV5(JLON,JLEV)-ZDFMDV5(JLON,JLEV-1)))*ZFVSC(JLON,JLEV)  
      ZIV1=ZIV1+ZIV5(JLON,JLEV)*PV5(JLON,JLEV)*ZFVSC(JLON,JLEV)
      PV(JLON,JLEV)=PV(JLON,JLEV)+ZIV5(JLON,JLEV)*ZIV15(JLON,JLEV)&
       & *ZFVSC(JLON,JLEV)  
      ZCORV(JLON,JLEV)=ZCORV(JLON,JLEV)-ZIV5(JLON,JLEV)*ZFVSC(JLON,JLEV)
      ZFVSC(JLON,JLEV-1)=ZFVSC(JLON,JLEV-1)+ZIV5(JLON,JLEV)&
       & *ZMFC5(JLON,JLEV-1)*ZFVSC(JLON,JLEV)  
      ZMFC(JLON,JLEV-1)=ZMFC(JLON,JLEV-1)+ZIV5(JLON,JLEV)&
       & *ZFVSC5(JLON,JLEV-1)*ZFVSC(JLON,JLEV)  
      ZFMDV=ZFMDV-ZIV5(JLON,JLEV)*ZFVSC(JLON,JLEV)
      ZDFMDV(JLON)=ZDFMDV(JLON)+ZIV5(JLON,JLEV)*ZFVSC(JLON,JLEV)
      ZFVSC(JLON,JLEV)=0.0_JPRB

      ZIV=ZIV+(PU5(JLON,JLEV)*ZIV15(JLON,JLEV)-ZCORU5(JLON,JLEV)&
       & +ZMFC5(JLON,JLEV-1)*ZFUSC5(JLON,JLEV-1)&
       & -(ZFMDU5(JLON,JLEV)-ZDFMDU5(JLON,JLEV-1)))*ZFUSC(JLON,JLEV)  
      ZIV1=ZIV1+ZIV5(JLON,JLEV)*PU5(JLON,JLEV)*ZFUSC(JLON,JLEV)
      PU(JLON,JLEV)=PU(JLON,JLEV)+ZIV5(JLON,JLEV)*ZIV15(JLON,JLEV)&
       & *ZFUSC(JLON,JLEV)  
      ZCORU(JLON,JLEV)=ZCORU(JLON,JLEV)-ZIV5(JLON,JLEV)*ZFUSC(JLON,JLEV)
      ZFUSC(JLON,JLEV-1)=ZFUSC(JLON,JLEV-1)+ZIV5(JLON,JLEV)&
       & *ZMFC5(JLON,JLEV-1)*ZFUSC(JLON,JLEV)  
      ZMFC(JLON,JLEV-1)=ZMFC(JLON,JLEV-1)+ZIV5(JLON,JLEV)&
       & *ZFUSC5(JLON,JLEV-1)*ZFUSC(JLON,JLEV)  
      ZFMDU=ZFMDU-ZIV5(JLON,JLEV)*ZFUSC(JLON,JLEV)
      ZDFMDU(JLON)=ZDFMDU(JLON)+ZIV5(JLON,JLEV)*ZFUSC(JLON,JLEV)
      ZFUSC(JLON,JLEV)=0.0_JPRB

      ZMFC(JLON,JLEV)=ZMFC(JLON,JLEV)+0.5_JPRB*(ZDSE5(JLON,JLEV+1)&
       & -ZDSE5(JLON,JLEV))*ZFMDS  
      ZDSE(JLON,JLEV+1)=ZDSE(JLON,JLEV+1)+0.5_JPRB*ZMFC5(JLON,JLEV)*ZFMDS
      ZDSE(JLON,JLEV)=ZDSE(JLON,JLEV)-0.5_JPRB*ZMFC5(JLON,JLEV)*ZFMDS

      ZMFC(JLON,JLEV)=ZMFC(JLON,JLEV)+0.5_JPRB*(PQ5(JLON,JLEV+1)&
       & -PQ5(JLON,JLEV))*ZFMDQ  
      PQ(JLON,JLEV+1)=PQ(JLON,JLEV+1)+0.5_JPRB*ZMFC5(JLON,JLEV)*ZFMDQ
      PQ(JLON,JLEV)=PQ(JLON,JLEV)-0.5_JPRB*ZMFC5(JLON,JLEV)*ZFMDQ

      ZMFC(JLON,JLEV)=ZMFC(JLON,JLEV)+0.5_JPRB*(PV5(JLON,JLEV+1)&
       & -PV5(JLON,JLEV))*ZFMDV  
      PV(JLON,JLEV+1)=PV(JLON,JLEV+1)+0.5_JPRB*ZMFC5(JLON,JLEV)*ZFMDV
      PV(JLON,JLEV)=PV(JLON,JLEV)-0.5_JPRB*ZMFC5(JLON,JLEV)*ZFMDV

      ZMFC(JLON,JLEV)=ZMFC(JLON,JLEV)+0.5_JPRB*(PU5(JLON,JLEV+1)&
       & -PU5(JLON,JLEV))*ZFMDU  
      PU(JLON,JLEV+1)=PU(JLON,JLEV+1)+0.5_JPRB*ZMFC5(JLON,JLEV)*ZFMDU
      PU(JLON,JLEV)=PU(JLON,JLEV)-0.5_JPRB*ZMFC5(JLON,JLEV)*ZFMDU

      ZIV1=ZIV1-ZIV/(ZIV15(JLON,JLEV)+ZMFC5(JLON,JLEV))**2
      ZMFC(JLON,JLEV)=ZMFC(JLON,JLEV)-ZIV &
       & /(ZIV15(JLON,JLEV)+ZMFC5(JLON,JLEV))**2  

      PDELP(JLON,JLEV)=PDELP(JLON,JLEV)+ZIV1/TSPHY

    ENDDO
  ENDDO

!     SPECIAL CASE OF THE FIRST LEVEL.

  DO JLON=KIDIA,KFDIA
    ZIV=0.0_JPRB
    ZIV1=0.0_JPRB

    ZIV=ZIV+(ZDSE5(JLON,ITOP)*ZIV15(JLON,ITOP)-ZCORS5(JLON,ITOP)&
     & -ZDFMDS5(JLON,ITOP))*ZFSSC(JLON,ITOP)  
    ZIV1=ZIV1+ZIV5(JLON,ITOP)*ZDSE5(JLON,ITOP)*ZFSSC(JLON,ITOP)
    ZDSE(JLON,ITOP)=ZDSE(JLON,ITOP)+ZIV5(JLON,ITOP)&
     & *ZIV15(JLON,ITOP)*ZFSSC(JLON,ITOP)  
    ZCORS(JLON,ITOP)=ZCORS(JLON,ITOP)-ZIV5(JLON,ITOP)*ZFSSC(JLON,ITOP)
    ZDFMDS(JLON)=ZDFMDS(JLON)-ZIV5(JLON,ITOP)*ZFSSC(JLON,ITOP)
    ZFSSC(JLON,ITOP)=0.0_JPRB

    ZIV=ZIV+(PQ5(JLON,ITOP)*ZIV15(JLON,ITOP)-ZCORQ5(JLON,ITOP)&
     & -ZDFMDQ5(JLON,ITOP))*ZFQSC(JLON,ITOP)  
    ZIV1=ZIV1+ZIV5(JLON,ITOP)*PQ5(JLON,ITOP)*ZFQSC(JLON,ITOP)
    PQ(JLON,ITOP)=PQ(JLON,ITOP)+ZIV5(JLON,ITOP)*ZIV15(JLON,ITOP)&
     & *ZFQSC(JLON,ITOP)  
    ZCORQ(JLON,ITOP)=ZCORQ(JLON,ITOP)-ZIV5(JLON,ITOP)*ZFQSC(JLON,ITOP)
    ZDFMDQ(JLON)=ZDFMDQ(JLON)-ZIV5(JLON,ITOP)*ZFQSC(JLON,ITOP)
    ZFQSC(JLON,ITOP)=0.0_JPRB

    ZIV=ZIV+(PV5(JLON,ITOP)*ZIV15(JLON,ITOP)-ZCORV5(JLON,ITOP)&
     & -ZDFMDV5(JLON,ITOP))*ZFVSC(JLON,ITOP)  
    ZIV1=ZIV1+ZIV5(JLON,ITOP)*PV5(JLON,ITOP)*ZFVSC(JLON,ITOP)
    PV(JLON,ITOP)=PV(JLON,ITOP)+ZIV5(JLON,ITOP)*ZIV15(JLON,ITOP)&
     & *ZFVSC(JLON,ITOP)  
    ZCORV(JLON,ITOP)=ZCORV(JLON,ITOP)-ZIV5(JLON,ITOP)*ZFVSC(JLON,ITOP)
    ZDFMDV(JLON)=ZDFMDV(JLON)-ZIV5(JLON,ITOP)*ZFVSC(JLON,ITOP)
    ZFVSC(JLON,ITOP)=0.0_JPRB

    ZIV=ZIV+(PU5(JLON,ITOP)*ZIV15(JLON,ITOP)-ZCORU5(JLON,ITOP)&
     & -ZDFMDU5(JLON,ITOP))*ZFUSC(JLON,ITOP)  
    ZIV1=ZIV1+ZIV5(JLON,ITOP)*PU5(JLON,ITOP)*ZFUSC(JLON,ITOP)
    PU(JLON,ITOP)=PU(JLON,ITOP)+ZIV5(JLON,ITOP)*ZIV15(JLON,ITOP)&
     & *ZFUSC(JLON,ITOP)  
    ZCORU(JLON,ITOP)=ZCORU(JLON,ITOP)-ZIV5(JLON,ITOP)*ZFUSC(JLON,ITOP)
    ZDFMDU(JLON)=ZDFMDU(JLON)-ZIV5(JLON,ITOP)*ZFUSC(JLON,ITOP)
    ZFUSC(JLON,ITOP)=0.0_JPRB

    ZMFC(JLON,ITOP)=ZMFC(JLON,ITOP)+0.5_JPRB*(ZDSE5(JLON,ITOP+1)&
     & -ZDSE5(JLON,ITOP))*ZDFMDS(JLON)  
    ZDSE(JLON,ITOP+1)=ZDSE(JLON,ITOP+1)+0.5_JPRB*ZMFC5(JLON,ITOP)*ZDFMDS(JLON)
    ZDSE(JLON,ITOP)=ZDSE(JLON,ITOP)-0.5_JPRB*ZMFC5(JLON,ITOP)*ZDFMDS(JLON)
    ZDFMDS(JLON)=0.0_JPRB

    ZMFC(JLON,ITOP)=ZMFC(JLON,ITOP)+0.5_JPRB*(PQ5(JLON,ITOP+1)&
     & -PQ5(JLON,ITOP))*ZDFMDQ(JLON)  
    PQ(JLON,ITOP+1)=PQ(JLON,ITOP+1)+0.5_JPRB*ZMFC5(JLON,ITOP)*ZDFMDQ(JLON)
    PQ(JLON,ITOP)=PQ(JLON,ITOP)-0.5_JPRB*ZMFC5(JLON,ITOP)*ZDFMDQ(JLON)
    ZDFMDQ(JLON)=0.0_JPRB

    ZMFC(JLON,ITOP)=ZMFC(JLON,ITOP)+0.5_JPRB*(PV5(JLON,ITOP+1)&
     & -PV5(JLON,ITOP))*ZDFMDV(JLON)  
    PV(JLON,ITOP+1)=PV(JLON,ITOP+1)+0.5_JPRB*ZMFC5(JLON,ITOP)*ZDFMDV(JLON)
    PV(JLON,ITOP)=PV(JLON,ITOP)-0.5_JPRB*ZMFC5(JLON,ITOP)*ZDFMDV(JLON)
    ZDFMDV(JLON)=0.0_JPRB

    ZMFC(JLON,ITOP)=ZMFC(JLON,ITOP)+0.5_JPRB*(PU5(JLON,ITOP+1)&
     & -PU5(JLON,ITOP))*ZDFMDU(JLON)  
    PU(JLON,ITOP+1)=PU(JLON,ITOP+1)+0.5_JPRB*ZMFC5(JLON,ITOP)*ZDFMDU(JLON)
    PU(JLON,ITOP)=PU(JLON,ITOP)-0.5_JPRB*ZMFC5(JLON,ITOP)*ZDFMDU(JLON)
    ZDFMDU(JLON)=0.0_JPRB

    ZIV1=ZIV1-ZIV/(ZIV15(JLON,ITOP)+ZMFC5(JLON,ITOP))**2
    ZMFC(JLON,ITOP)=ZMFC(JLON,ITOP)-ZIV &
     & /(ZIV15(JLON,ITOP)+ZMFC5(JLON,ITOP))**2  

    PDELP(JLON,ITOP)=PDELP(JLON,ITOP)+ZIV1/TSPHY
  ENDDO

!*
!     RETURN FROM THE PSEUDO-RETURN SITUATED AFTER LOOP 670.

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

!*
!     ------------------------------------------------------------------
!     VI - FIRST VERTICAL LOOP (UPWARDS) INCLUDING THE SATURATED
!     ADIABATIC TYPE CALCULATION OF THE CLOUD PROFILE.

!     CALCULATION AT THE TOP OF THE ATMOSPHERE

DO JLON=KIDIA,KFDIA

  ZMFC(JLON,KTDIA)=ZMFC(JLON,KTDIA)-(ZDSEN5(JLON,KTDIA)&
   & -ZLHSB5(JLON)*ZLN5(JLON,KTDIA))*ZCORS(JLON,KTDIA)  
  ZDSEN(JLON)=ZDSEN(JLON)-ZMFC5(JLON,KTDIA)*ZCORS(JLON,KTDIA)
  ZLN(JLON)=ZLN(JLON)+ZMFC5(JLON,KTDIA)*ZLHSB5(JLON)*ZCORS(JLON,KTDIA)
  ZLHSB(JLON)=ZLHSB(JLON)+ZMFC5(JLON,KTDIA)*ZLN5(JLON,KTDIA)&
   & *ZCORS(JLON,KTDIA)  
  ZCORS(JLON,KTDIA)=0.0_JPRB

  ZMFC(JLON,KTDIA)=ZMFC(JLON,KTDIA)-(ZQN5(JLON,KTDIA)&
   & +ZLN5(JLON,KTDIA))*ZCORQ(JLON,KTDIA)  
  ZQN(JLON)=ZQN(JLON)-ZMFC5(JLON,KTDIA)*ZCORQ(JLON,KTDIA)
  ZLN(JLON)=ZLN(JLON)-ZMFC5(JLON,KTDIA)*ZCORQ(JLON,KTDIA)
  ZCORQ(JLON,KTDIA)=0.0_JPRB

  ZVN(JLON)=ZVN(JLON)-ZMFC5(JLON,KTDIA)*ZCORV(JLON,KTDIA)
  ZMFC(JLON,KTDIA)=ZMFC(JLON,KTDIA)-ZVN5(JLON,KTDIA)*ZCORV(JLON,KTDIA)
  ZCORV(JLON,KTDIA)=0.0_JPRB

  ZUN(JLON)=ZUN(JLON)-ZMFC5(JLON,KTDIA)*ZCORU(JLON,KTDIA)
  ZMFC(JLON,KTDIA)=ZMFC(JLON,KTDIA)-ZUN5(JLON,KTDIA)*ZCORU(JLON,KTDIA)
  ZCORU(JLON,KTDIA)=0.0_JPRB

ENDDO

DO JLEV=KTDIA,KLEV-1

  DO JLON=KIDIA,KFDIA
    ZZZL=0.0_JPRB
    I_KNLAB(JLON,JLEV)=NINT(MAX(0.0_JPRB,-SIGN(1.0_JPRB,&
     & -(ZMSEPR5(JLON,JLEV)-ZMSEC5(JLON,JLEV))))&
     & *MAX(MAX(0.0_JPRB,SIGN(1.0_JPRB,&
     & ZDSE5(JLON,JLEV)-ZDSE5(JLON,JLEV+1))),&
     & MAX(0.0_JPRB,-SIGN(1.0_JPRB,0.0_JPRB-ZMFC5(JLON,JLEV+1)))))  

    ZTW(JLON,JLEV)=ZTW(JLON,JLEV)+ZTN(JLON)
    ZTN(JLON)=0.0_JPRB

    ZQN(JLON)=ZQN(JLON)+ZQDN(JLON,JLEV)
    ZLN(JLON)=ZLN(JLON)+ZQDN(JLON,JLEV)
    ZQDN(JLON,JLEV)=0.0_JPRB

    ZQW(JLON,JLEV)=ZQW(JLON,JLEV)+ZQN(JLON)
    ZQN(JLON)=0.0_JPRB

    IF (ZZZL5(JLON,JLEV) > 0.0_JPRB) THEN
      ZZZL=ZZZL+ZLN(JLON)*I_KNLAB(JLON,JLEV)
      ZLN(JLON)=0.0_JPRB
    ELSE
      ZLN(JLON)=0.0_JPRB
    ENDIF

    ZLN(JLON)=ZLN(JLON)+(1.0_JPRB-ZPOIL5(JLON,JLEV)&
     & /(1.0_JPRB+ZPOIL5(JLON,JLEV)))*(1.0_JPRB-ZPHI5(JLON,JLEV)/ECMNP)&
     & *ZZZL  
    ZPHI(JLON,JLEV)=ZPHI(JLON,JLEV)-ZLN5(JLON,JLEV+1)&
     & *(1.0_JPRB-ZPOIL5(JLON,JLEV)/(1.0_JPRB+ZPOIL5(JLON,JLEV)))&
     & *ZZZL/ECMNP  
    ZPOIL(JLON)=ZPOIL(JLON)-(ZLN5(JLON,JLEV+1)&
     & *(1.0_JPRB-ZPHI5(JLON,JLEV)/ECMNP)&
     & /(1.0_JPRB+ZPOIL5(JLON,JLEV))**2)*ZZZL  
    ZQW(JLON,JLEV)=ZQW(JLON,JLEV)-ZZZL
    ZQN(JLON)=ZQN(JLON)+ZZZL
    PQ(JLON,JLEV+1)=PQ(JLON,JLEV+1)+(ZPOIL5(JLON,JLEV)&
     & /(1.0_JPRB+ZPOIL5(JLON,JLEV)))*ZZZL  
    ZQN(JLON)=ZQN(JLON)-(ZPOIL5(JLON,JLEV)/(1.0_JPRB+ZPOIL5(JLON,JLEV)))*ZZZL
    ZPOIL(JLON)=ZPOIL(JLON)&
     & +((PQ5(JLON,JLEV+1)-ZQN5(JLON,JLEV+1))&
     & /(1.0_JPRB+ZPOIL5(JLON,JLEV))**2)*ZZZL  

    PAPHIF(JLON,JLEV)=PAPHIF(JLON,JLEV)+ZPHI(JLON,JLEV)
    PAPHIF(JLON,JLEV+1)=PAPHIF(JLON,JLEV+1)-ZPHI(JLON,JLEV)
    ZPHI(JLON,JLEV)=0.0_JPRB
  ENDDO

!     NEWTON LOOP FOR THE "WET BULB" POINT.

  DO JIT=NBITER,1,-1
    DO JLON=KIDIA,KFDIA
      ZDELT=0.0_JPRB
      ZDELQ=0.0_JPRB
      ZZQW=0.0_JPRB
      ZDQW=0.0_JPRB
      ZESP=0.0_JPRB
      ZDLEW=0.0_JPRB
      ZEW=0.0_JPRB

      IF (JIT == 1) THEN
        JJ=0
      ELSE
        JJ=1
      ENDIF

!     SNOW OPTION DEPENDENT COMPUTATIONS.

      IF (LNEIGE) THEN
        IF (JIT == 1) THEN
          ZDELTA=MAX(0.0_JPRB,SIGN(1.0_JPRB,RTT-ZTW15(JLON,JLEV)))
        ELSE
          ZDELTA=MAX(0.0_JPRB,SIGN(1.0_JPRB,RTT-ZTW5(JLON,JLEV,JIT-JJ)))
        ENDIF
      ELSE
        ZDELTA=0.0_JPRB
      ENDIF

!     INCREMENTATIONS.

      ZDELT=ZDELT+ZTW(JLON,JLEV)

      ZDELQ=ZDELQ+ZQW(JLON,JLEV)

      ZDELQ=ZDELQ-(ZLHSB5(JLON)/ZCP5(JLON,JLEV))*ZDELT
      ZLHSB(JLON)=ZLHSB(JLON)-(ZDELQ5(JLON,JLEV,JIT)/ZCP5(JLON,JLEV))*ZDELT
      ZCP(JLON,JLEV)=ZCP(JLON,JLEV)+ZDELQ5(JLON,JLEV,JIT)&
       & *ZLHSB5(JLON)*ZDELT/ZCP5(JLON,JLEV)**2  

      IF (JIT == 1) THEN
        ZZQW=ZZQW+ZCP5(JLON,JLEV)*ZDELQ &
         & /(ZCP5(JLON,JLEV)+ZLHSB5(JLON)*ZDQW5(JLON,JLEV,JIT))  
        ZQW(JLON,JLEV)=ZQW(JLON,JLEV)-ZCP5(JLON,JLEV)*ZDELQ &
         & /(ZCP5(JLON,JLEV)+ZLHSB5(JLON)*ZDQW5(JLON,JLEV,JIT))  
        ZCP(JLON,JLEV)=ZCP(JLON,JLEV)&
         & +(ZZQW5(JLON,JLEV,JIT)-ZQW15(JLON,JLEV))*ZDELQ &
         & /(ZCP5(JLON,JLEV)+ZLHSB5(JLON)*ZDQW5(JLON,JLEV,JIT))  
        ZCP(JLON,JLEV)=ZCP(JLON,JLEV)&
         & -(ZZQW5(JLON,JLEV,JIT)-ZQW15(JLON,JLEV))&
         & *ZCP5(JLON,JLEV)*ZDELQ/(ZCP5(JLON,JLEV)&
         & +ZLHSB5(JLON)*ZDQW5(JLON,JLEV,JIT))**2  
        ZLHSB(JLON)=ZLHSB(JLON)&
         & -(ZZQW5(JLON,JLEV,JIT)-ZQW15(JLON,JLEV))&
         & *ZCP5(JLON,JLEV)*ZDQW5(JLON,JLEV,JIT)*ZDELQ &
         & /(ZCP5(JLON,JLEV)+ZLHSB5(JLON)&
         & *ZDQW5(JLON,JLEV,JIT))**2  
        ZDQW=ZDQW-(ZZQW5(JLON,JLEV,JIT)-ZQW15(JLON,JLEV))&
         & *ZCP5(JLON,JLEV)*ZLHSB5(JLON)*ZDELQ &
         & /(ZCP5(JLON,JLEV)&
         & +ZLHSB5(JLON)*ZDQW5(JLON,JLEV,JIT))**2  

!     SATURATION CALCULATIONS USING THE DEFINED FUNCTIONS

        ZZQW=ZZQW &
         & +FODQSAD1(ZDQW,ZZQW5(JLON,JLEV,JIT),ZESP5(JLON,JLEV,JIT)&
         & ,ZDLEW5(JLON,JLEV,JIT))  
        ZESP=ZESP &
         & +FODQSAD2(ZZQW5(JLON,JLEV,JIT),ZDQW,ZESP5(JLON,JLEV,JIT)&
         & ,ZDLEW5(JLON,JLEV,JIT))  
        ZDLEW=ZDLEW &
         & +FODQSAD3(ZZQW5(JLON,JLEV,JIT),ZESP5(JLON,JLEV,JIT)&
         & ,ZDQW,ZDLEW5(JLON,JLEV,JIT))  

        ZTW(JLON,JLEV)=ZTW(JLON,JLEV)+FODLEWAD(ZDLEW,ZTW15(JLON,JLEV),ZDELTA)

        IF ((1.0_JPRB-ZESP5(JLON,JLEV,JIT)) > 0.0_JPRB) THEN
          ZESP=ZESP+FOQSAD1(ZZQW,ZESP5(JLON,JLEV,JIT))
        ELSE
          ZESP=ZESP+FOQSAD2(ZZQW,ZESP5(JLON,JLEV,JIT))
        ENDIF

        ZEW=ZEW+ZESP/PAPRSF5(JLON,JLEV)
        PAPRSF(JLON,JLEV)=PAPRSF(JLON,JLEV)&
         & -(ZEW5(JLON,JLEV,JIT)&
         & /PAPRSF5(JLON,JLEV)**2)*ZESP  

        ZTW(JLON,JLEV)=ZTW(JLON,JLEV)+FOEWAD(ZEW,ZTW15(JLON,JLEV),ZDELTA)

      ELSE

        ZZQW=ZZQW+ZCP5(JLON,JLEV)*ZDELQ &
         & /(ZCP5(JLON,JLEV)+ZLHSB5(JLON)*ZDQW5(JLON,JLEV,JIT))  
        ZQW(JLON,JLEV)=ZQW(JLON,JLEV)-ZCP5(JLON,JLEV)*ZDELQ &
         & /(ZCP5(JLON,JLEV)&
         & +ZLHSB5(JLON)*ZDQW5(JLON,JLEV,JIT))  
        ZCP(JLON,JLEV)=ZCP(JLON,JLEV)&
         & +(ZZQW5(JLON,JLEV,JIT)-ZQW5(JLON,JLEV,JIT-JJ))*ZDELQ &
         & /(ZCP5(JLON,JLEV)+ZLHSB5(JLON)*ZDQW5(JLON,JLEV,JIT))  
        ZCP(JLON,JLEV)=ZCP(JLON,JLEV)&
         & -(ZZQW5(JLON,JLEV,JIT)-ZQW5(JLON,JLEV,JIT-JJ))&
         & *ZCP5(JLON,JLEV)*ZDELQ/(ZCP5(JLON,JLEV)+ZLHSB5(JLON)&
         & *ZDQW5(JLON,JLEV,JIT))**2  
        ZLHSB(JLON)=ZLHSB(JLON)&
         & -(ZZQW5(JLON,JLEV,JIT)-ZQW5(JLON,JLEV,JIT-JJ))&
         & *ZCP5(JLON,JLEV)*ZDQW5(JLON,JLEV,JIT)*ZDELQ &
         & /(ZCP5(JLON,JLEV)+ZLHSB5(JLON)&
         & *ZDQW5(JLON,JLEV,JIT))**2  
        ZDQW=ZDQW-(ZZQW5(JLON,JLEV,JIT)-ZQW5(JLON,JLEV,JIT-JJ))&
         & *ZCP5(JLON,JLEV)*ZLHSB5(JLON)*ZDELQ &
         & /(ZCP5(JLON,JLEV)+ZLHSB5(JLON)*ZDQW5(JLON,JLEV,JIT))**2  

!     SATURATION CALCULATIONS USING THE DEFINED FUNCTIONS

        ZZQW=ZZQW &
         & +FODQSAD1(ZDQW,ZZQW5(JLON,JLEV,JIT),ZESP5(JLON,JLEV,JIT)&
         & ,ZDLEW5(JLON,JLEV,JIT))  
        ZESP=ZESP &
         & +FODQSAD2(ZZQW5(JLON,JLEV,JIT),ZDQW,ZESP5(JLON,JLEV,JIT)&
         & ,ZDLEW5(JLON,JLEV,JIT))  
        ZDLEW=ZDLEW &
         & +FODQSAD3(ZZQW5(JLON,JLEV,JIT),ZESP5(JLON,JLEV,JIT)&
         & ,ZDQW,ZDLEW5(JLON,JLEV,JIT))  

        ZTW(JLON,JLEV)=ZTW(JLON,JLEV)&
         & +FODLEWAD(ZDLEW,ZTW5(JLON,JLEV,JIT-JJ),ZDELTA)  

        IF ((1.0_JPRB-ZESP5(JLON,JLEV,JIT)) > 0.0_JPRB) THEN
          ZESP=ZESP+FOQSAD1(ZZQW,ZESP5(JLON,JLEV,JIT))
        ELSE
          ZESP=ZESP+FOQSAD2(ZZQW,ZESP5(JLON,JLEV,JIT))
        ENDIF

        ZEW=ZEW+ZESP/PAPRSF5(JLON,JLEV)
        PAPRSF(JLON,JLEV)=PAPRSF(JLON,JLEV)&
         & -(ZEW5(JLON,JLEV,JIT)&
         & /PAPRSF5(JLON,JLEV)**2)*ZESP  

        ZTW(JLON,JLEV)=ZTW(JLON,JLEV)&
         & +FOEWAD(ZEW,ZTW5(JLON,JLEV,JIT-JJ),ZDELTA)  

      ENDIF

    ENDDO

  ENDDO

!     INITIALIZATION OF THE VARIABLES IN THE NEWTON LOOP,
!     THE ITERATIVE TW AND QW VALUES HAVING TO EVOLVE.

  DO JLON=KIDIA,KFDIA
    ZMSEPR=0.0_JPRB

    ZDSEN(JLON)=ZDSEN(JLON)+ZTW(JLON,JLEV)/ZCP5(JLON,JLEV)
    PAPHIF(JLON,JLEV)=PAPHIF(JLON,JLEV)-ZTW(JLON,JLEV)/ZCP5(JLON,JLEV)
    ZCP(JLON,JLEV)=ZCP(JLON,JLEV)&
     & -((ZDSEN5(JLON,JLEV)-PAPHIF5(JLON,JLEV))&
     & /ZCP5(JLON,JLEV)**2)*ZTW(JLON,JLEV)  
    ZTW(JLON,JLEV)=0.0_JPRB

!     COMPUTATION OF VALUES u,v,h,q,T IN THE CLOUD

    ZMSEPR=ZMSEPR+I_KNLAB(JLON,JLEV)*ZMSEN(JLON)
    ZMSEC(JLON,JLEV)=ZMSEC(JLON,JLEV)+(1-I_KNLAB(JLON,JLEV))*ZMSEN(JLON)
    ZMSEN(JLON)=0.0_JPRB

    ZDSE(JLON,JLEV+1)=ZDSE(JLON,JLEV+1)+I_KNLAB(JLON,JLEV)&
     & *ZPOIL5(JLON,JLEV)*ZDSEN(JLON)  
    ZPOIL(JLON)=ZPOIL(JLON)+I_KNLAB(JLON,JLEV)*(ZDSE5(JLON,JLEV+1)&
     & -ZDSEN5(JLON,JLEV+1))*ZDSEN(JLON)  
    ZDSE(JLON,JLEV)=ZDSE(JLON,JLEV)+(1-I_KNLAB(JLON,JLEV))*ZDSEN(JLON)
    ZDSEN(JLON)=I_KNLAB(JLON,JLEV)*(1.0_JPRB-ZPOIL5(JLON,JLEV))*ZDSEN(JLON)

    PQ(JLON,JLEV+1)=PQ(JLON,JLEV+1)+I_KNLAB(JLON,JLEV)&
     & *ZPOIL5(JLON,JLEV)*ZQW(JLON,JLEV)  
    ZPOIL(JLON)=ZPOIL(JLON)+I_KNLAB(JLON,JLEV)*(PQ5(JLON,JLEV+1)&
     & -ZQN5(JLON,JLEV+1))*ZQW(JLON,JLEV)  
    ZQN(JLON)=ZQN(JLON)+I_KNLAB(JLON,JLEV)&
     & *(1.0_JPRB-ZPOIL5(JLON,JLEV))*ZQW(JLON,JLEV)  
    PQ(JLON,JLEV)=PQ(JLON,JLEV)+(1-I_KNLAB(JLON,JLEV))*ZQW(JLON,JLEV)
    ZQW(JLON,JLEV)=0.0_JPRB

    PV(JLON,JLEV+1)=PV(JLON,JLEV+1)+I_KNLAB(JLON,JLEV)&
     & *ZPOIL5(JLON,JLEV)*ZVN(JLON)  
    ZPOIL(JLON)=ZPOIL(JLON)+I_KNLAB(JLON,JLEV)*(PV5(JLON,JLEV+1)&
     & -ZVN5(JLON,JLEV+1))*ZVN(JLON)  
    PV(JLON,JLEV)=PV(JLON,JLEV)+(1-I_KNLAB(JLON,JLEV))*ZVN(JLON)
    ZVN(JLON)=I_KNLAB(JLON,JLEV)*(1.0_JPRB-ZPOIL5(JLON,JLEV))*ZVN(JLON)

    PU(JLON,JLEV+1)=PU(JLON,JLEV+1)+I_KNLAB(JLON,JLEV)&
     & *ZPOIL5(JLON,JLEV)*ZUN(JLON)  
    ZPOIL(JLON)=ZPOIL(JLON)+I_KNLAB(JLON,JLEV)*(PU5(JLON,JLEV+1)&
     & -ZUN5(JLON,JLEV+1))*ZUN(JLON)  
    PU(JLON,JLEV)=PU(JLON,JLEV)+(1-I_KNLAB(JLON,JLEV))*ZUN(JLON)
    ZUN(JLON)=I_KNLAB(JLON,JLEV)*(1.0_JPRB-ZPOIL5(JLON,JLEV))*ZUN(JLON)

!     COMPUTATION OF THE SECOND TERM OF THE BASIC EQUATION

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

!   ZCORU   : THE SECOND TERM OF THE BASIC EQUATION FOR U-WIND COMP.
!   ZCORV   : THE SECOND TERM OF THE BASIC EQUATION FOR V-WIND COMP.
!   ZCORQ   : THE SECOND TERM OF THE BASIC EQUATION FOR SPEC.HUMIDITY
!   ZCORS   : THE SECOND TERM OF THE BASIC EQUATION FOR DRY STATIC
!             ENERGY

    ZDSE(JLON,JLEV+1)=ZDSE(JLON,JLEV+1)+ZENTR5(JLON,JLEV)*ZCORS(JLON,JLEV+1)
    ZENTR(JLON)=ZENTR(JLON)+ZDSE5(JLON,JLEV+1)*ZCORS(JLON,JLEV+1)
    ZDETR(JLON)=ZDETR(JLON)-(ZDSEN5(JLON,JLEV+1)-ZLHSB5(JLON)&
     & *ZLN5(JLON,JLEV+1))*ZCORS(JLON,JLEV+1)  
    ZDSEN(JLON)=ZDSEN(JLON)-ZDETR5(JLON,JLEV)*ZCORS(JLON,JLEV+1)
    ZLN(JLON)=ZLN(JLON)+ZDETR5(JLON,JLEV)*ZLHSB5(JLON)*ZCORS(JLON,JLEV+1)
    ZLHSB(JLON)=ZLHSB(JLON)+ZDETR5(JLON,JLEV)*ZLN5(JLON,JLEV+1)&
     & *ZCORS(JLON,JLEV+1)  
    ZCORS(JLON,JLEV+1)=0.0_JPRB

    PQ(JLON,JLEV+1)=PQ(JLON,JLEV+1)+ZENTR5(JLON,JLEV)*ZCORQ(JLON,JLEV+1)
    ZENTR(JLON)=ZENTR(JLON)+PQ5(JLON,JLEV+1)*ZCORQ(JLON,JLEV+1)
    ZDETR(JLON)=ZDETR(JLON)-(ZQN5(JLON,JLEV+1)+ZLN5(JLON,JLEV+1))&
     & *ZCORQ(JLON,JLEV+1)  
    ZQN(JLON)=ZQN(JLON)-ZDETR5(JLON,JLEV)*ZCORQ(JLON,JLEV+1)
    ZLN(JLON)=ZLN(JLON)-ZDETR5(JLON,JLEV)*ZCORQ(JLON,JLEV+1)
    ZCORQ(JLON,JLEV+1)=0.0_JPRB

    PV(JLON,JLEV+1)=PV(JLON,JLEV+1)+ZENTR5(JLON,JLEV)*ZCORV(JLON,JLEV+1)
    ZENTR(JLON)=ZENTR(JLON)+PV5(JLON,JLEV+1)*ZCORV(JLON,JLEV+1)
    ZVN(JLON)=ZVN(JLON)-ZDETR5(JLON,JLEV)*ZCORV(JLON,JLEV+1)
    ZDETR(JLON)=ZDETR(JLON)-ZVN5(JLON,JLEV+1)*ZCORV(JLON,JLEV+1)
    ZCORV(JLON,JLEV+1)=0.0_JPRB

    PU(JLON,JLEV+1)=PU(JLON,JLEV+1)+ZENTR5(JLON,JLEV)*ZCORU(JLON,JLEV+1)
    ZENTR(JLON)=ZENTR(JLON)+PU5(JLON,JLEV+1)*ZCORU(JLON,JLEV+1)
    ZUN(JLON)=ZUN(JLON)-ZDETR5(JLON,JLEV)*ZCORU(JLON,JLEV+1)
    ZDETR(JLON)=ZDETR(JLON)-ZUN5(JLON,JLEV+1)*ZCORU(JLON,JLEV+1)
    ZCORU(JLON,JLEV+1)=0.0_JPRB

!     STABILTY TEST

    ZENTR(JLON)=I_KNLAB(JLON,JLEV)*ZENTR(JLON)

    ZMFC(JLON,JLEV+1)=ZMFC(JLON,JLEV+1)+(1-I_KNLAB(JLON,JLEV))*ZDETR(JLON)
    ZDETR(JLON)=I_KNLAB(JLON,JLEV)*ZDETR(JLON)

    ZMFC(JLON,JLEV)=I_KNLAB(JLON,JLEV)*ZMFC(JLON,JLEV)

    ZMSEC(JLON,JLEV+1)=ZMSEC(JLON,JLEV+1)+ZPOIL5(JLON,JLEV)*ZMSEPR
    ZPOIL(JLON)=ZPOIL(JLON)+(ZMSEC5(JLON,JLEV+1)-ZMSEN5(JLON,JLEV+1))*ZMSEPR
    ZMSEN(JLON)=ZMSEN(JLON)+(1.0_JPRB-ZPOIL5(JLON,JLEV))*ZMSEPR

!     COMPUTATION OF DETRAINMENT AND ENTRAINMENT

    IF (ZMFC15(JLON,JLEV) > ZEPS4) THEN
      ZENTR(JLON)=ZENTR(JLON)+ZPOIL(JLON)/ZMFC15(JLON,JLEV)
      ZMFC(JLON,JLEV)=ZMFC(JLON,JLEV)-(ZENTR25(JLON,JLEV)&
       & /ZMFC15(JLON,JLEV)**2)*ZPOIL(JLON)  
      ZPOIL(JLON)=0.0_JPRB
    ELSE
      ZENTR(JLON)=ZENTR(JLON)+ZPOIL(JLON)/ZEPS4
      ZPOIL(JLON)=0.0_JPRB
    ENDIF

    IF (LSMOOTHB) THEN
      ZMFC(JLON,JLEV)=0.0_JPRB
      ZENTR(JLON)=0.0_JPRB
      ZDETR(JLON)=0.0_JPRB
    ENDIF

    ZENTR(JLON)=ZENTR(JLON)+ZDETR(JLON)
    ZMFC(JLON,JLEV+1)=ZMFC(JLON,JLEV+1)+ZDETR(JLON)
    ZMFC(JLON,JLEV)=ZMFC(JLON,JLEV)-ZDETR(JLON)
    ZDETR(JLON)=0.0_JPRB

    IF (ZENTR15(JLON,JLEV) >= ZMFC15(JLON,JLEV)) THEN
      ZMFC(JLON,JLEV)=ZMFC(JLON,JLEV)+ZENTR(JLON)
      ZENTR(JLON)=0.0_JPRB
    ENDIF

    IF ((ZF5(JLON,JLEV+1)+ZDETC*ZMFC15(JLON,JLEV)) > 0.0_JPRB) THEN
      PDELP(JLON,JLEV+1)=PDELP(JLON,JLEV+1)+(ZF5(JLON,JLEV+1)&
       & +ZDETC*ZMFC15(JLON,JLEV))*ZENTR(JLON)  
      ZF(JLON,JLEV+1)=ZF(JLON,JLEV+1)+PDELP5(JLON,JLEV+1)*ZENTR(JLON)
      ZMFC(JLON,JLEV)=ZMFC(JLON,JLEV)+ZDETC*PDELP5(JLON,JLEV+1)*ZENTR(JLON)
      ZENTR(JLON)=0.0_JPRB
    ELSE
      ZENTR(JLON)=0.0_JPRB
    ENDIF

!     OPTIONAL COMPUTATION ACCORDING CHOSEN CLOSURE ASSUMPTION
!     IF LCLOSN=TRUE NEW CLOSURE ASSUMPTION OF SIMPLIFIED PHYSICS
!     WILL BE USED

    ZZM5=ZMFC5(JLON,JLEV+1)+ZF5(JLON,JLEV+1)*PDELP5(JLON,JLEV+1)
    IF (ZZM5 > 0.0_JPRB) THEN
      ZMFC(JLON,JLEV+1)=ZMFC(JLON,JLEV+1)+ZMFC(JLON,JLEV)
      PDELP(JLON,JLEV+1)=PDELP(JLON,JLEV+1)+ZF5(JLON,JLEV+1)*ZMFC(JLON,JLEV)
      ZF(JLON,JLEV+1)=ZF(JLON,JLEV+1)+PDELP5(JLON,JLEV+1)*ZMFC(JLON,JLEV)
      ZMFC(JLON,JLEV)=0.0_JPRB
    ELSE
      ZMFC(JLON,JLEV)=0.0_JPRB
    ENDIF

    IF (ZF15(JLON,JLEV+1) > 0.0_JPRB) THEN
      ZF(JLON,JLEV+1)=ZF(JLON,JLEV+1)/(1.0_JPRB+TSPHY*ZF15(JLON,JLEV+1))**2
    ENDIF

    IF (LL_LCLOSN) THEN
      IF (PQ5(JLON,JLEV+1) > ZEPS5) THEN
        PCVGQ(JLON,JLEV+1)=PCVGQ(JLON,JLEV+1)&
         & +ZF(JLON,JLEV+1)/PQ5(JLON,JLEV+1)  
        PQ(JLON,JLEV+1)=PQ(JLON,JLEV+1)-(PCVGQ5(JLON,JLEV+1)&
         & /PQ5(JLON,JLEV+1)**2)*ZF(JLON,JLEV+1)  
        ZF(JLON,JLEV+1)=0.0_JPRB
      ELSE
        PCVGQ(JLON,JLEV+1)=PCVGQ(JLON,JLEV+1)+ZF(JLON,JLEV+1)/ZEPS5
        ZF(JLON,JLEV+1)=0.0_JPRB
      ENDIF
    ELSE
      ZALF(JLON)=ZALF(JLON)+((ZFORM15(JLON,JLEV)&
       & -ZFORM15(JLON,JLEV+1))/PDELP5(JLON,JLEV+1))&
       & *ZF(JLON,JLEV+1)  
      ZFORM(JLON,JLEV)=ZFORM(JLON,JLEV)+(ZALF5(JLON)&
       & /PDELP5(JLON,JLEV+1))*ZF(JLON,JLEV+1)  
      ZFORM(JLON,JLEV+1)=ZFORM(JLON,JLEV+1)-(ZALF5(JLON)&
       & /PDELP5(JLON,JLEV+1))*ZF(JLON,JLEV+1)  
      PDELP(JLON,JLEV+1)=PDELP(JLON,JLEV+1)-(ZALF5(JLON)&
       & *(ZFORM15(JLON,JLEV)-ZFORM15(JLON,JLEV+1))&
       & /PDELP5(JLON,JLEV+1)**2)*ZF(JLON,JLEV+1)  
      ZF(JLON,JLEV+1)=0.0_JPRB
    ENDIF

  ENDDO
ENDDO

!*
!     ------------------------------------------------------------------
!     V - BOTTOM INITIALISATION. THE CLOUD PROFILE WILL EVENTUALY BE
!     CHARACTERISED BY ITS TOTAL HUMIDITY AND ITS DETRAINING DRY STATIC
!     ENERGY AS WELL AS BY A STABILITY INDEX (ONE AT BOTH ENDS OF ANY
!     CONVECTIVE SLAB (FROM MODEL LAYER TO THE ADJACENT ONE) AND ZERO
!     ELSEWHERE).

!     ACTIVE OTHER CHARACTERISTICS OF THE CLOUD.

DO JLON=KIDIA,KFDIA

  ZQN(JLON)=ZQN(JLON)+ZQDN(JLON,KLEV)
  ZQDN(JLON,KLEV)=0.0_JPRB

  ZMFC(JLON,KLEV)=0.0_JPRB

!     THERMODYNAMIC CHARACTERISTICS OF THE CLOUD.

! - TEMPORARY(S) 1D .

! ZTN       : TEMPERATURE OF THE CLOUDY ASCENT.
! ZQN       : WATER VAPOUR SPECIFIC HUMIDITY OF THE CLOUDY ASCENT.
! ZLN       : CONDENSED SPECIFIC HUMIDITY OF THE CLOUDY ASCENT.
! ZUN       : U-WIND COMPONENT OF THE CLOUDY ASCENT.
! ZVN       : V-WIND COMPONENT OF THE CLOUDY ASCENT.
! ZMSEN     : MOIST STATIC ENERGY OF THE CLOUDY ASCENT.
! ZDSEN     : DRY STATIC ENERGY OF THE CLOUDY ASCENT.

  ZLN(JLON)=0.0_JPRB

  ZTN(JLON)=ZTN(JLON)+ZCP5(JLON,KLEV)*ZDSEN(JLON)
  ZCP(JLON,KLEV)=ZCP(JLON,KLEV)+ZTN5(JLON,KLEV)*ZDSEN(JLON)
  PAPHIF(JLON,KLEV)=PAPHIF(JLON,KLEV)+ZDSEN(JLON)
  ZDSEN(JLON)=0.0_JPRB

  ZTN(JLON)=ZTN(JLON)+ZCP5(JLON,KLEV)*ZMSEN(JLON)
  ZCP(JLON,KLEV)=ZCP(JLON,KLEV)+ZTN5(JLON,KLEV)*ZMSEN(JLON)
  ZQN(JLON)=ZQN(JLON)+ZLHSB5(JLON)*ZMSEN(JLON)
  ZLHSB(JLON)=ZLHSB(JLON)+ZQN5(JLON,KLEV)*ZMSEN(JLON)
  PAPHIF(JLON,KLEV)=PAPHIF(JLON,KLEV)+ZMSEN(JLON)
  ZMSEN(JLON)=0.0_JPRB

  PV(JLON,KLEV)=PV(JLON,KLEV)+ZVN(JLON)
  ZVN(JLON)=0.0_JPRB

  PU(JLON,KLEV)=PU(JLON,KLEV)+ZUN(JLON)
  ZUN(JLON)=0.0_JPRB

  ZQW(JLON,KLEV)=ZQW(JLON,KLEV)+ZQN(JLON)
  ZQN(JLON)=0.0_JPRB

  ZTW(JLON,KLEV)=ZTW(JLON,KLEV)+ZTN(JLON)
  ZTN(JLON)=0.0_JPRB

ENDDO

!     NEWTON LOOP FOR THE "WET BULB" POINT.

DO JIT=NBITER,1,-1
  DO JLON=KIDIA,KFDIA
    ZDELT=0.0_JPRB
    ZDELQ=0.0_JPRB
    ZZQW=0.0_JPRB
    ZDQW=0.0_JPRB
    ZESP=0.0_JPRB
    ZDLEW=0.0_JPRB
    ZEW=0.0_JPRB

    IF (JIT == 1) THEN
      JJ=0
    ELSE
      JJ=1
    ENDIF

!     SNOW OPTION DEPENDENT COMPUTATIONS.

    IF (LNEIGE) THEN
      IF (JIT == 1) THEN
        ZDELTA=MAX(0.0_JPRB,SIGN(1.0_JPRB,RTT-ZTW15(JLON,KLEV)))
      ELSE
        ZDELTA=MAX(0.0_JPRB,SIGN(1.0_JPRB,RTT-ZTW5(JLON,KLEV,JIT-JJ)))
      ENDIF
    ELSE
      ZDELTA=0.0_JPRB
    ENDIF

!     INCREMENTATIONS.

    ZDELT=ZDELT+ZTW(JLON,KLEV)

    ZDELQ=ZDELQ+ZQW(JLON,KLEV)

    ZDELQ=ZDELQ-(ZLHSB5(JLON)/ZCP5(JLON,KLEV))*ZDELT
    ZLHSB(JLON)=ZLHSB(JLON)-(ZDELQ5(JLON,KLEV,JIT)/ZCP5(JLON,KLEV))*ZDELT
    ZCP(JLON,KLEV)=ZCP(JLON,KLEV)+ZDELQ5(JLON,KLEV,JIT)&
     & *ZLHSB5(JLON)*ZDELT/ZCP5(JLON,KLEV)**2  

    IF (JIT == 1) THEN
      ZZQW=ZZQW+ZCP5(JLON,KLEV)*ZDELQ &
       & /(ZCP5(JLON,KLEV)+ZLHSB5(JLON)*ZDQW5(JLON,KLEV,JIT))  
      ZQW(JLON,KLEV)=ZQW(JLON,KLEV)-ZCP5(JLON,KLEV)*ZDELQ &
       & /(ZCP5(JLON,KLEV)+ZLHSB5(JLON)*ZDQW5(JLON,KLEV,JIT))  
      ZCP(JLON,KLEV)=ZCP(JLON,KLEV)&
       & +(ZZQW5(JLON,KLEV,JIT)-ZQW15(JLON,KLEV))*ZDELQ &
       & /(ZCP5(JLON,KLEV)+ZLHSB5(JLON)*ZDQW5(JLON,KLEV,JIT))  
      ZCP(JLON,KLEV)=ZCP(JLON,KLEV)&
       & -(ZZQW5(JLON,KLEV,JIT)-ZQW15(JLON,KLEV))&
       & *ZCP5(JLON,KLEV)*ZDELQ/(ZCP5(JLON,KLEV)+ZLHSB5(JLON)&
       & *ZDQW5(JLON,KLEV,JIT))**2  
      ZLHSB(JLON)=ZLHSB(JLON)&
       & -(ZZQW5(JLON,KLEV,JIT)-ZQW15(JLON,KLEV))&
       & *ZCP5(JLON,KLEV)*ZDQW5(JLON,KLEV,JIT)*ZDELQ &
       & /(ZCP5(JLON,KLEV)+ZLHSB5(JLON)&
       & *ZDQW5(JLON,KLEV,JIT))**2  
      ZDQW=ZDQW-(ZZQW5(JLON,KLEV,JIT)-ZQW15(JLON,KLEV))&
       & *ZCP5(JLON,KLEV)*ZLHSB5(JLON)*ZDELQ &
       & /(ZCP5(JLON,KLEV)+ZLHSB5(JLON)&
       & *ZDQW5(JLON,KLEV,JIT))**2  

!     SATURATION CALCULATIONS USING THE DEFINED FUNCTIONS

      ZZQW=ZZQW &
       & +FODQSAD1(ZDQW,ZZQW5(JLON,KLEV,JIT),ZESP5(JLON,KLEV,JIT)&
       & ,ZDLEW5(JLON,KLEV,JIT))  
      ZESP=ZESP &
       & +FODQSAD2(ZZQW5(JLON,KLEV,JIT),ZDQW,ZESP5(JLON,KLEV,JIT)&
       & ,ZDLEW5(JLON,KLEV,JIT))  
      ZDLEW=ZDLEW &
       & +FODQSAD3(ZZQW5(JLON,KLEV,JIT),ZESP5(JLON,KLEV,JIT)&
       & ,ZDQW,ZDLEW5(JLON,KLEV,JIT))  

      ZTW(JLON,KLEV)=ZTW(JLON,KLEV)+FODLEWAD(ZDLEW,ZTW15(JLON,KLEV),ZDELTA)

      IF ((1.0_JPRB-ZESP5(JLON,KLEV,JIT)) > 0.0_JPRB) THEN
        ZESP=ZESP+FOQSAD1(ZZQW,ZESP5(JLON,KLEV,JIT))
      ELSE
        ZESP=ZESP+FOQSAD2(ZZQW,ZESP5(JLON,KLEV,JIT))
      ENDIF

      ZEW=ZEW+ZESP/PAPRSF5(JLON,KLEV)
      PAPRSF(JLON,KLEV)=PAPRSF(JLON,KLEV)&
       & -(ZEW5(JLON,KLEV,JIT)&
       & /PAPRSF5(JLON,KLEV)**2)*ZESP  

      ZTW(JLON,KLEV)=ZTW(JLON,KLEV)+FOEWAD(ZEW,ZTW15(JLON,KLEV),ZDELTA)

    ELSE

      ZZQW=ZZQW+ZCP5(JLON,KLEV)*ZDELQ &
       & /(ZCP5(JLON,KLEV)+ZLHSB5(JLON)*ZDQW5(JLON,KLEV,JIT))  
      ZQW(JLON,KLEV)=ZQW(JLON,KLEV)-ZCP5(JLON,KLEV)*ZDELQ &
       & /(ZCP5(JLON,KLEV)&
       & +ZLHSB5(JLON)*ZDQW5(JLON,KLEV,JIT))  
      ZCP(JLON,KLEV)=ZCP(JLON,KLEV)&
       & +(ZZQW5(JLON,KLEV,JIT)-ZQW5(JLON,KLEV,JIT-JJ))*ZDELQ &
       & /(ZCP5(JLON,KLEV)+ZLHSB5(JLON)*ZDQW5(JLON,KLEV,JIT))  
      ZCP(JLON,KLEV)=ZCP(JLON,KLEV)&
       & -(ZZQW5(JLON,KLEV,JIT)-ZQW5(JLON,KLEV,JIT-JJ))&
       & *ZCP5(JLON,KLEV)*ZDELQ/(ZCP5(JLON,KLEV)+ZLHSB5(JLON)&
       & *ZDQW5(JLON,KLEV,JIT))**2  
      ZLHSB(JLON)=ZLHSB(JLON)&
       & -(ZZQW5(JLON,KLEV,JIT)-ZQW5(JLON,KLEV,JIT-JJ))&
       & *ZCP5(JLON,KLEV)*ZDQW5(JLON,KLEV,JIT)*ZDELQ &
       & /(ZCP5(JLON,KLEV)+ZLHSB5(JLON)&
       & *ZDQW5(JLON,KLEV,JIT))**2  
      ZDQW=ZDQW-(ZZQW5(JLON,KLEV,JIT)-ZQW5(JLON,KLEV,JIT-JJ))&
       & *ZCP5(JLON,KLEV)*ZLHSB5(JLON)*ZDELQ &
       & /(ZCP5(JLON,KLEV)+ZLHSB5(JLON)*ZDQW5(JLON,KLEV,JIT))**2  

!     SATURATION CALCULATIONS USING THE DEFINED FUNCTIONS

      ZZQW=ZZQW &
       & +FODQSAD1(ZDQW,ZZQW5(JLON,KLEV,JIT),ZESP5(JLON,KLEV,JIT)&
       & ,ZDLEW5(JLON,KLEV,JIT))  
      ZESP=ZESP &
       & +FODQSAD2(ZZQW5(JLON,KLEV,JIT),ZDQW,ZESP5(JLON,KLEV,JIT)&
       & ,ZDLEW5(JLON,KLEV,JIT))  
      ZDLEW=ZDLEW &
       & +FODQSAD3(ZZQW5(JLON,KLEV,JIT),ZESP5(JLON,KLEV,JIT)&
       & ,ZDQW,ZDLEW5(JLON,KLEV,JIT))  

      ZTW(JLON,KLEV)=ZTW(JLON,KLEV)&
       & +FODLEWAD(ZDLEW,ZTW5(JLON,KLEV,JIT-JJ),ZDELTA)  

      IF ((1.0_JPRB-ZESP5(JLON,KLEV,JIT)) > 0.0_JPRB) THEN
        ZESP=ZESP+FOQSAD1(ZZQW,ZESP5(JLON,KLEV,JIT))
      ELSE
        ZESP=ZESP+FOQSAD2(ZZQW,ZESP5(JLON,KLEV,JIT))
      ENDIF

      ZEW=ZEW+ZESP/PAPRSF5(JLON,KLEV)
      PAPRSF(JLON,KLEV)=PAPRSF(JLON,KLEV)&
       & -(ZEW5(JLON,KLEV,JIT)&
       & /PAPRSF5(JLON,KLEV)**2)*ZESP  

      ZTW(JLON,KLEV)=ZTW(JLON,KLEV)+FOEWAD(ZEW,ZTW5(JLON,KLEV,JIT-JJ),ZDELTA)

    ENDIF

  ENDDO

ENDDO

DO JLON=KIDIA,KFDIA

!     INITIALIZATION OF THE VARIABLES IN THE NEWTON LOOP,
!     THE ITERATIVE TW AND QW VALUES HAVING TO EVOLVE.

! - TEMPORARY 2D (1:KLEV)

! ZQW        : SPECIFIC WET BULB HUMIDITY.
! ZTW        : WET BULB TEMPERATURE.

  PT(JLON,KLEV)=PT(JLON,KLEV)+ZTW(JLON,KLEV)
  ZTW(JLON,KLEV)=0.0_JPRB

  PQ(JLON,KLEV)=PQ(JLON,KLEV)+ZQW(JLON,KLEV)
  ZQW(JLON,KLEV)=0.0_JPRB

ENDDO

!*
!     ------------------------------------------------------------------
!     IV - COMPUTATION OF PROFILE OF MASS FLUX AND NORMALIZATION
!     FACTOR FOR THIS PROFILE CONNECTED WITH THE "KUO-TYPE" CLOSURE

!     ACTIVE CHARACTERISTICS OF THE CLOUD AT THE BOTTOM

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

! ZFORM     : PROFILE OF MASS FLUX AND LATER MASS FLUX TIME DT.

! - TEMPORARY(S) 1D .

! ZS1       : INTEGRAL OF HUMIDITY CONVERGENCE
! ZS2       : INTEGRAL OF BUOYANCY

IF (.NOT.LL_LCLOSN) THEN

!       COMPUTATION FOR LEVELS

  DO JLON=KIDIA,KFDIA
    ZZAL1=0.0_JPRB
    ZZAL2=0.0_JPRB
    ZZAL1=ZZAL1+(MAX(0.0_JPRB,SIGN(1.0_JPRB,ZS25(JLON)-ZEPS6))/ZZAL25(JLON))&
     & *ZALF(JLON)  
    ZZAL2=ZZAL2-MAX(0.0_JPRB,SIGN(1.0_JPRB,ZS25(JLON)-ZEPS6))&
     & *(ZZAL15(JLON)/ZZAL25(JLON)**2)*ZALF(JLON)  
    ZALF(JLON)=0.0_JPRB

    IF (ZS25(JLON) > ZEPS6) THEN
      ZS2(JLON)=ZS2(JLON)+ZZAL2
    ENDIF

    IF (ZS15(JLON) > 0.0_JPRB) THEN
      ZS1(JLON)=ZS1(JLON)+ZZAL1
    ENDIF

  ENDDO

  DO JLEV=KTDIA,KLEV-1
    DO JLON=KIDIA,KFDIA
      ZZFO=0.0_JPRB
      ZMSEP=0.0_JPRB
      ZZPO1=0.0_JPRB
      ZZPO2=0.0_JPRB
      ZINSTA=MAX(0.0_JPRB,SIGN(1.0_JPRB,ZMSEP5(JLON,JLEV)-ZMSE5(JLON,JLEV)&
       & -ZCORIN))  

      ZFORM(JLON,JLEV)=ZFORM(JLON,JLEV)&
       & +(PQ5(JLON,JLEV+1)-PQ5(JLON,JLEV))*ZS2(JLON)  
      PQ(JLON,JLEV+1)=PQ(JLON,JLEV+1)+ZFORM15(JLON,JLEV)*ZS2(JLON)
      PQ(JLON,JLEV)=PQ(JLON,JLEV)-ZFORM15(JLON,JLEV)*ZS2(JLON)

      PDELP(JLON,JLEV+1)=PDELP(JLON,JLEV+1)&
       & +ZINSTA*PCVGQ5(JLON,JLEV+1)*ZS1(JLON)  
      PCVGQ(JLON,JLEV+1)=PCVGQ(JLON,JLEV+1)&
       & +ZINSTA*PDELP5(JLON,JLEV+1)*ZS1(JLON)  

      IF (ZZFO15(JLON,JLEV) > 0.0_JPRB) THEN
        PAPRS(JLON,JLEV)=PAPRS(JLON,JLEV)&
         & +(0.5_JPRB*ZINSTA*ZZFO15(JLON,JLEV)&
         & /(SQRT(ZZFO15(JLON,JLEV)*PAPRS5(JLON,JLEV)&
         & *(PT5(JLON,JLEV)+PT5(JLON,JLEV+1)))))&
         & *ZFORM(JLON,JLEV)  
        ZZFO=ZZFO+(0.5_JPRB*ZINSTA*PAPRS5(JLON,JLEV)&
         & /(SQRT(ZZFO15(JLON,JLEV)*PAPRS5(JLON,JLEV)&
         & *(PT5(JLON,JLEV)+PT5(JLON,JLEV+1)))))*ZFORM(JLON,JLEV)  
        PT(JLON,JLEV)=PT(JLON,JLEV)-(0.5_JPRB*ZINSTA &
         & *SQRT(ZZFO15(JLON,JLEV)*PAPRS5(JLON,JLEV)&
         & *(PT5(JLON,JLEV)+PT5(JLON,JLEV+1)))&
         & /(PT5(JLON,JLEV)+PT5(JLON,JLEV+1))**2)&
         & *ZFORM(JLON,JLEV)  
        PT(JLON,JLEV+1)=PT(JLON,JLEV+1)-(0.5_JPRB*ZINSTA &
         & *SQRT(ZZFO15(JLON,JLEV)*PAPRS5(JLON,JLEV)&
         & *(PT5(JLON,JLEV)+PT5(JLON,JLEV+1)))&
         & /(PT5(JLON,JLEV)+PT5(JLON,JLEV+1))**2)&
         & *ZFORM(JLON,JLEV)  
        ZFORM(JLON,JLEV)=0.0_JPRB
      ELSE
        ZFORM(JLON,JLEV)=0.0_JPRB
      ENDIF

      ZMSEU(JLON,JLEV)=ZMSEU(JLON,JLEV)+ZZFO
      ZMSEU(JLON,JLEV+1)=ZMSEU(JLON,JLEV+1)+ZZFO
      ZMSE(JLON,JLEV)=ZMSE(JLON,JLEV)-ZZFO
      ZMSE(JLON,JLEV+1)=ZMSE(JLON,JLEV+1)-ZZFO
      ZZFO=0.0_JPRB

      ZMSEP=ZMSEP+ZINSTA*ZMSEU(JLON,JLEV)
      ZMSE(JLON,JLEV)=ZMSE(JLON,JLEV)+(1.0_JPRB-ZINSTA)*ZMSEU(JLON,JLEV)
      ZMSEU(JLON,JLEV)=0.0_JPRB

      ZINSTA=MAX(0.0_JPRB,SIGN(1.0_JPRB,ZMSEU15(JLON,JLEV+1)&
       & -ZMSE5(JLON,JLEV)-ZCORIN))  

      ZMSE(JLON,JLEV+1)=ZMSE(JLON,JLEV+1)+ZPOII5(JLON,JLEV)*ZMSEP
      ZPOII(JLON)=ZPOII(JLON)+ZMSE5(JLON,JLEV+1)*ZMSEP
      ZMSEU(JLON,JLEV+1)=ZMSEU(JLON,JLEV+1)+(1.0_JPRB-ZPOII5(JLON,JLEV))*ZMSEP
      ZPOII(JLON)=ZPOII(JLON)-ZMSEU15(JLON,JLEV+1)*ZMSEP

      IF ((ZZPO15(JLON,JLEV)/ZZPO25(JLON,JLEV)) < 1.0_JPRB) THEN
        ZZPO1=ZZPO1+ZPOII(JLON)/ZZPO25(JLON,JLEV)
        ZZPO2=ZZPO2-(ZZPO15(JLON,JLEV)/ZZPO25(JLON,JLEV)**2)*ZPOII(JLON)
        ZPOII(JLON)=0.0_JPRB
      ELSE
        ZPOII(JLON)=0.0_JPRB
      ENDIF

      IF (ZFORM5(JLON,JLEV) > ZEPS7) THEN
        ZFORM(JLON,JLEV)=ZFORM(JLON,JLEV)+ZZPO2
      ENDIF

      IF (ZZPO5(JLON,JLEV) > 0.0_JPRB) THEN
        ZFORM(JLON,JLEV)=ZFORM(JLON,JLEV)&
         & +(1.0_JPRB+ZDETC*PDELP5(JLON,JLEV+1))*ZZPO1  
        PDELP(JLON,JLEV+1)=PDELP(JLON,JLEV+1)+ZDETC*ZFORM5(JLON,JLEV)*ZZPO1
        ZFORM(JLON,JLEV+1)=ZFORM(JLON,JLEV+1)-ZZPO1
      ENDIF

      IF (ZZFO5(JLON,JLEV) > 0.0_JPRB) THEN
        PAPRS(JLON,JLEV)=PAPRS(JLON,JLEV)+(0.5_JPRB*ZINSTA &
         & *ZZFO5(JLON,JLEV)&
         & /(SQRT(ZZFO5(JLON,JLEV)*PAPRS5(JLON,JLEV)&
         & *(PT5(JLON,JLEV)+PT5(JLON,JLEV+1)))))&
         & *ZFORM(JLON,JLEV)  
        ZZFO=ZZFO+(0.5_JPRB*ZINSTA*PAPRS5(JLON,JLEV)&
         & /(SQRT(ZZFO5(JLON,JLEV)*PAPRS5(JLON,JLEV)&
         & *(PT5(JLON,JLEV)+PT5(JLON,JLEV+1)))))*ZFORM(JLON,JLEV)  
        PT(JLON,JLEV)=PT(JLON,JLEV)-(0.5_JPRB*ZINSTA &
         & *SQRT(ZZFO5(JLON,JLEV)*PAPRS5(JLON,JLEV)&
         & *(PT5(JLON,JLEV)+PT5(JLON,JLEV+1)))&
         & /(PT5(JLON,JLEV)+PT5(JLON,JLEV+1))**2)&
         & *ZFORM(JLON,JLEV)  
        PT(JLON,JLEV+1)=PT(JLON,JLEV+1)-(0.5_JPRB*ZINSTA &
         & *SQRT(ZZFO5(JLON,JLEV)*PAPRS5(JLON,JLEV)&
         & *(PT5(JLON,JLEV)+PT5(JLON,JLEV+1)))&
         & /(PT5(JLON,JLEV)+PT5(JLON,JLEV+1))**2)&
         & *ZFORM(JLON,JLEV)  
        ZFORM(JLON,JLEV)=0.0_JPRB
      ELSE
        ZFORM(JLON,JLEV)=0.0_JPRB
      ENDIF

      ZMSEU(JLON,JLEV)=ZMSEU(JLON,JLEV)+ZZFO
      ZMSEU(JLON,JLEV+1)=ZMSEU(JLON,JLEV+1)+ZZFO
      ZMSE(JLON,JLEV)=ZMSE(JLON,JLEV)-ZZFO
      ZMSE(JLON,JLEV+1)=ZMSE(JLON,JLEV+1)-ZZFO

      ZMSEU(JLON,JLEV+1)=ZMSEU(JLON,JLEV+1)+ZINSTA*ZMSEU(JLON,JLEV)
      ZMSE(JLON,JLEV)=ZMSE(JLON,JLEV)+(1.0_JPRB-ZINSTA)*ZMSEU(JLON,JLEV)
      ZMSEU(JLON,JLEV)=0.0_JPRB

    ENDDO
  ENDDO

  DO JLON=KIDIA,KFDIA
    ZS2(JLON)=0.0_JPRB
    ZS1(JLON)=0.0_JPRB
    ZFORM(JLON,KLEV)=0.0_JPRB

    ZMSE(JLON,KLEV)=ZMSE(JLON,KLEV)+ZMSEU(JLON,KLEV)
    ZMSEU(JLON,KLEV)=0.0_JPRB
  ENDDO

ENDIF

!*
!     ------------------------------------------------------------------
!     III - COMPUTATION OF VALUE OF ATMOSPHERIC Cp,
!     SETTING ALL FLUXES TO ZERO (FOR THE CASE WITHOUT CONVECTION)
!     AND PRELIMINARY CALCULATIONS OF DRY STATIC ENERGY, OF EFFECTIVE
!     LATENT HEAT (DEPENDING UPON THE OPTION WHETHER SURFACE PRESSURE IS
!     VARYING OR NOT WITH THE SURFACE WATER FLUXES), OF LEVEL PRESSURE
!     THICKNESSES DIVIDED BY G*DT AND OF THEIR INVERSES AT ALL LEVELS AS
!     WELL AS OF IMPOSED PROPORTIONS OF SNOW PRECIPITATION IN FUNCTION
!     OF TEMPERATURE AND PRESSURE.

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

! ZCP        : VALUE OF ATMOSPHERIC Cp
! ZPOID     : DP/(RG*DT) FOR A GIVEN LEVEL AND A GIVEN TIME STEP.
! ZIPOI     : INVERSE OF ZPOID.
! ZDSE      : LOCAL ARRAY FOR DRY STATIC ENERGY.
! ZMSE      : LOCAL ARRAY FOR MOIST STATIC ENERGY.
! ZLHE      : LOCAL ARRAY FOR EFFECTIVE LATENT HEATS.

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

! ZSNP      : PROPORTION OF SNOW PRECIPITATION.
! ZLHL      : MINUS THE LATENT HEAT OF CONSERVATION OF LIQUID ENTHALPY.
! ZLHN      : MINUS THE LATENT HEAT OF CONSERVATION OF SOLID ENTHALPY.

!     COMPUTATIONS AT ALL LEVELS. BEWARE, THE DEFINED FUNCTION FOLH WILL
!     BE CALLED WITH VALUES THAT ARE NOT NECESSARILY 0 OR 1 FOR ITS
!     SECOND ARGUMENT !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

DO JLEV=KLEV,KTDIA,-1
  DO JLON=KIDIA,KFDIA
    ZDELTA=0.0_JPRB

!     SETTING FLUXES TO ZERO.

    PSTRCV(JLON,JLEV)=0.0_JPRB
    PSTRCU(JLON,JLEV)=0.0_JPRB
    PDIFCS(JLON,JLEV)=0.0_JPRB
    PDIFCQ(JLON,JLEV)=0.0_JPRB
    PFPLCN(JLON,JLEV)=0.0_JPRB
    PFPLCL(JLON,JLEV)=0.0_JPRB

    PT(JLON,JLEV)=PT(JLON,JLEV)+ZCP5(JLON,JLEV)*ZMSEC(JLON,JLEV)
    ZCP(JLON,JLEV)=ZCP(JLON,JLEV)+PT5(JLON,JLEV)*ZMSEC(JLON,JLEV)
    PQ(JLON,JLEV)=PQ(JLON,JLEV)+ZLHSB5(JLON)*ZMSEC(JLON,JLEV)
    ZLHSB(JLON)=ZLHSB(JLON)+PQ5(JLON,JLEV)*ZMSEC(JLON,JLEV)
    PAPHIF(JLON,JLEV)=PAPHIF(JLON,JLEV)+ZMSEC(JLON,JLEV)
    ZMSEC(JLON,JLEV)=0.0_JPRB

    PT(JLON,JLEV)=PT(JLON,JLEV)+ZCP5(JLON,JLEV)*ZMSE(JLON,JLEV)
    ZCP(JLON,JLEV)=ZCP(JLON,JLEV)+PT5(JLON,JLEV)*ZMSE(JLON,JLEV)
    PQ(JLON,JLEV)=PQ(JLON,JLEV)+ZLHE5(JLON,JLEV)*ZMSE(JLON,JLEV)
    ZLHE(JLON,JLEV)=ZLHE(JLON,JLEV)+PQ5(JLON,JLEV)*ZMSE(JLON,JLEV)
    PAPHIF(JLON,JLEV)=PAPHIF(JLON,JLEV)+ZMSE(JLON,JLEV)
    ZMSE(JLON,JLEV)=0.0_JPRB

    ZDELTA=ZDELTA+RV*RBETD*ZLHE(JLON,JLEV)
    PT(JLON,JLEV)=PT(JLON,JLEV)-RV*(RGAMW+ZDELTA5(JLON,JLEV)&
     & *RGAMD)*ZLHE(JLON,JLEV)  
    ZDELTA=ZDELTA-RV*RGAMD*PT5(JLON,JLEV)*ZLHE(JLON,JLEV)
    PT(JLON,JLEV)=PT(JLON,JLEV)+(ZCPWMD+ZDELTA5(JLON,JLEV)&
     & *(ZCPSMD-ZCPWMD))*ZLHE(JLON,JLEV)  
    ZDELTA=ZDELTA+(PT5(JLON,JLEV)-PTS(JLON))*(ZCPSMD-ZCPWMD)*ZLHE(JLON,JLEV)
    ZLHE(JLON,JLEV)=0.0_JPRB

    ZSNP(JLON,JLEV-1)=ZSNP(JLON,JLEV-1)+0.5_JPRB*ZDELTA
    ZSNP(JLON,JLEV)=ZSNP(JLON,JLEV)+0.5_JPRB*ZDELTA

    PT(JLON,JLEV)=PT(JLON,JLEV)+ZCP5(JLON,JLEV)*ZDSE(JLON,JLEV)
    ZCP(JLON,JLEV)=ZCP(JLON,JLEV)+PT5(JLON,JLEV)*ZDSE(JLON,JLEV)
    PAPHIF(JLON,JLEV)=PAPHIF(JLON,JLEV)+ZDSE(JLON,JLEV)
    ZDSE(JLON,JLEV)=0.0_JPRB

    PRDELP(JLON,JLEV)=PRDELP(JLON,JLEV)+ZGDT*ZIPOI(JLON,JLEV)
    ZIPOI(JLON,JLEV)=0.0_JPRB

    PDELP(JLON,JLEV)=PDELP(JLON,JLEV)+ZGDTI*ZPOID(JLON,JLEV)
    ZPOID(JLON,JLEV)=0.0_JPRB
  ENDDO
ENDDO

DO JLON=KIDIA,KFDIA

!     SETTING TO ZERO FLUXES AT THE TOP.

  PSTRCV(JLON,KTDIA-1)=0.0_JPRB
  PSTRCU(JLON,KTDIA-1)=0.0_JPRB
  PDIFCS(JLON,KTDIA-1)=0.0_JPRB
  PDIFCQ(JLON,KTDIA-1)=0.0_JPRB
  PFPLCN(JLON,KTDIA-1)=0.0_JPRB
  PFPLCL(JLON,KTDIA-1)=0.0_JPRB

!     CALL TO THE DEFINED FUNCTION TO COMPUTE THE REFERENCE OF EFFECTIVE
!     LATENT HEAT AT THE SURFACE.

! - TEMPORARY(S) 1D .

! ZLHSB     : BUDGET LATENT HEAT AS COMPUTED AT THE SURFACE.

  ZLHL(JLON,KLEV)=ZLHL(JLON,KLEV)-ZLHSB(JLON)
  ZSNP(JLON,KLEV)=ZSNP(JLON,KLEV)&
   & -(ZLHN5(JLON,KLEV)-ZLHL5(JLON,KLEV))*ZLHSB(JLON)  
  ZLHN(JLON,KLEV)=ZLHN(JLON,KLEV)-ZSNP5(JLON,KLEV)*ZLHSB(JLON)
  ZLHL(JLON,KLEV)=ZLHL(JLON,KLEV)+ZSNP5(JLON,KLEV)*ZLHSB(JLON)
  ZLHSB(JLON)=0.0_JPRB
ENDDO

!     "FLUX LATENT HEAT" ARRAYS INITIALIZATION.

! --- SURFACE COMPUTATION
!     --------------------
DO JLON=KIDIA,KFDIA
  ZLHN(JLON,KLEV)=0.0_JPRB
  ZLHL(JLON,KLEV)=0.0_JPRB
ENDDO

! --- COMPUTATION FOR LEVELS
!     ----------------------
DO JLEV = KLEV-1,KTDIA,-1
  DO JLON = KIDIA , KFDIA
    ZTI=0.0_JPRB
    ZTQ=0.0_JPRB
    ZTI=ZTI-FOLHAD(ZLHN(JLON,JLEV),1.0_JPRB)
    ZTQ=ZTQ+ZLHN(JLON,JLEV)
    ZLHN(JLON,JLEV)=0.0_JPRB

    ZTI=ZTI-FOLHAD(ZLHL(JLON,JLEV),0.0_JPRB)
    ZTQ=ZTQ+ZLHL(JLON,JLEV)
    ZLHL(JLON,JLEV)=0.0_JPRB

    ZTI=ZTI+ZCVMCD*ZTQ

    PT(JLON,JLEV)=PT(JLON,JLEV)+0.5_JPRB*ZTI
    PT(JLON,JLEV+1)=PT(JLON,JLEV+1)+0.5_JPRB*ZTI
  ENDDO
ENDDO

! --- COMPUTATION AT THE TOP
!     ----------------------
DO JLON=KIDIA,KFDIA
  ZTQ=0.0_JPRB
  PT(JLON,KTDIA)=PT(JLON,KTDIA)-FOLHAD(ZLHN(JLON,0),1.0_JPRB)
  ZTQ=ZTQ+ZLHN(JLON,0)
  ZLHN(JLON,0)=0.0_JPRB

  PT(JLON,KTDIA)=PT(JLON,KTDIA)-FOLHAD(ZLHL(JLON,0),0.0_JPRB)
  ZTQ=ZTQ+ZLHL(JLON,0)
  ZLHL(JLON,0)=0.0_JPRB

  PT(JLON,KTDIA)=PT(JLON,KTDIA)+ZCVMCD*ZTQ
ENDDO

!     SNOW OPTION DEPENDENT CALCULATIONS.

DO JLON=KIDIA,KFDIA

  IF (LNEIGE) THEN
    ZZZS=USDMLT*MAX(0.0_JPRB,PTS(JLON)-RTT)**2
    IF ((ZZZS/PAPRS5(JLON,KLEV)) < 1.0_JPRB) THEN
      PAPRS(JLON,KLEV)=PAPRS(JLON,KLEV)&
       & +(ZZZS/PAPRS5(JLON,KLEV)**2)*ZSNP (JLON,KLEV)  
      ZSNP (JLON,KLEV)=0.0_JPRB
    ELSE
      ZSNP (JLON,KLEV)=0.0_JPRB
    ENDIF
  ELSE
    ZSNP (JLON,KLEV)=0.0_JPRB
  ENDIF
ENDDO

!     SNOW OPTION DEPENDENT CALCULATIONS.

DO JLEV=KLEV-1,KTDIA,-1
  DO JLON=KIDIA,KFDIA
    ZZSN=0.0_JPRB

    IF (LNEIGE) THEN
      IF ((USDMLT*ZZSN5(JLON,JLEV)**2/PAPRS5(JLON,JLEV)) < 1.0_JPRB)THEN
        ZZSN=ZZSN-(2*USDMLT*ZZSN5(JLON,JLEV)/PAPRS5(JLON,JLEV))&
         & *ZSNP (JLON,JLEV)  
        PAPRS(JLON,JLEV)=PAPRS(JLON,JLEV)&
         & +(USDMLT*ZZSN5(JLON,JLEV)**2 &
         & /PAPRS5(JLON,JLEV)**2)*ZSNP (JLON,JLEV)  
        ZSNP (JLON,JLEV)=0.0_JPRB
      ELSE
        ZSNP (JLON,JLEV)=0.0_JPRB
      ENDIF
      IF ((0.5_JPRB*(PT5(JLON,JLEV)+PT5(JLON,JLEV+1))-RTT) > 0.0_JPRB) THEN
        PT(JLON,JLEV)=PT(JLON,JLEV)+0.5_JPRB*ZZSN
        PT(JLON,JLEV+1)=PT(JLON,JLEV+1)+0.5_JPRB*ZZSN
      ENDIF
    ELSE
      ZSNP (JLON,JLEV)=0.0_JPRB
    ENDIF
  ENDDO
ENDDO

!     SNOW OPTION DEPENDENT CALCULATIONS.

DO JLON=KIDIA,KFDIA
  ZZSN1=0.0_JPRB
  ZZSN2=0.0_JPRB

  IF (LNEIGE) THEN
    IF ((USDMLT*ZZSN25(JLON)**2/ZZSN15(JLON)) < 1.0_JPRB) THEN
      ZZSN2=ZZSN2-(2*USDMLT*ZZSN25(JLON)/ZZSN15(JLON))*ZSNP(JLON,KTDIA-1)
      ZZSN1=ZZSN1+(USDMLT*ZZSN25(JLON)**2/ZZSN15(JLON)**2)*ZSNP(JLON,KTDIA-1)
      ZSNP(JLON,KTDIA-1)=0.0_JPRB
    ELSE
      ZSNP(JLON,KTDIA-1)=0.0_JPRB
    ENDIF
    IF ((PT5(JLON,KTDIA)-RTT) > 0.0_JPRB) THEN
      PT(JLON,KTDIA)=PT(JLON,KTDIA)+ZZSN2
    ENDIF
    IF (PAPRS5(JLON,KTDIA-1) > 1.E-03_JPRB) THEN
      PAPRS(JLON,KTDIA-1)=PAPRS(JLON,KTDIA-1)+ZZSN1
    ENDIF
  ELSE
    ZSNP(JLON,KTDIA-1)=0.0_JPRB
  ENDIF
ENDDO
DO JLEV=KTDIA,KLEV
  DO JLON=KIDIA,KFDIA
    PQ(JLON,JLEV)=PQ(JLON,JLEV)-RCPD*ZCP(JLON,JLEV)
    PQ(JLON,JLEV)=PQ(JLON,JLEV)+RCPV*ZCP(JLON,JLEV)
    ZCP(JLON,JLEV)=0.0_JPRB
  ENDDO
ENDDO

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