!OCL  NOEVAL
SUBROUTINE CPDYDDH (&
 !     INPUT .
 & KPROMA,KPROMNH,KPROMVC,KPROMDLW,KPROMDLR,KSTART,KPROF,KFLEV,&
 & PVCRSSAF,PVCRSSAFL,PVCRSSAFM,PVCRSSAH,PVCASRSF,PVCASRSH,&
 & PVCWF,PVCMUSF,PWDLWF,PRDLR,&
 & PSLAT, PCLAT, PLON,&
 & PNORDL, PNORDM, PRCORI, PRCORIC,&
 & PRATATH,PRATATX,&
 & PDELP, PRDELP, PRR, PRTGR, PSGRTL, PSGRTM,&
 & PCP, PAPHI, PAPHIF, PAPHIFL, PAPHIFM, PVVEL, PSDIV,&
 & PDIV, PDIVDP, PU, PV, PT, PQV, PKENE,&
 & PVOR, PUL, PVL,&
 & PTL, PTM, PQVL, PQVM,&
 & PRTL, PRTM, PORL, PORM, PLNPR,&
 & PSPL, PSPM, PAPRSF, PAPRS,&
 & P3DIVG,PNHPREF,PNHPREH,PQCHAL,PQCHAM, &
 & PEVEL, POMEGA, PFPLCL, PFPLCN, PFPLSL, PFPLSN,&
 & PQVS, PTSFC, PRH, PNEB,&
 & PQL,PQN,PQLL,PQLM,PQNL,PQNM,&
 & PGFL, &
 !     OUTPUT .
 & PUZ, PVM, PDHCV, PENTRA, PENTRV)
!---------------------------------------------------------------------------
!**** *CPDYDDH*  - CALCUL DES VARIABLES ET FLUX/TENDANCES DYNAMIQUES
!                  DIAGNOSTICS PAR DOMAINES HORIZONTAUX (DDH)

!                  COMPUTATION OF VARIABLES AND FLUX/DYNAMICAL TENDENCIES
!                  HORIZONTAL DOMAINS DIAGNOSTICS ("DDH" PACKAGE)
!---------------------------------------------------------------------------
!     BUT/ PURPOSE:
!     -------------

!     Fait les calculs dynamiques pour   |  Does dynamical calculations for
!     les diagnostics "DDH".             |  the DDH package.
!     Principalement, fait le calcul     |  Does principally the computation
!     des variables DDH atmospheriques   |  of DDH atmospheric variables at
!     a l'instant courant.               |  the current instant.

!     Pour une variable X, on part de    |  For a variable X, one starts from
!     la forme flux de l'equation        |  the flux form of its temporal
!     d'evolution temporelle de X, qui   |  evolution equation, which evaluates
!     consiste a evaluer le membre de    |  the RHS of the equation of
!     droite de l'equation de            |
!     thin layer eqns: " (1/g) d ( (d prehyd / d eta) X) / dt ".
!     lvercor=T: " (1/g) d ( (rs**2/a**2) (d prehyd / d eta) X) / dt ".
!     lrwsdlr=T,lrwsdlg=F: " (1/g) d ( (d presim / d eta) X) / dt ".

!     Ce membre de droite fait           |  This RHS involves not only some
!     intervenir, outre des              |  physical contributions (not
!     contributions physiques (pas       |  computed here but in CPPHDDH),
!     traitees ici mais dans CPPHDDH),   |  but also the following dynamical
!     les contributions dynamiques       |  contributions:
!     suivantes:                         |
!     - les divergences des flux         |  - horizontal fluxes divergences.
!       horizontaux.                     |
!     - les divergences des flux         |  - vertical fluxes divergences
!       verticaux (ce qui est stocke ici |    (what is stored are actually
!       ce sont les flux verticaux).     |    vertical fluxes).
!     - les tendances adiabatiques       |  - adiabatic Lagrangian tendencies
!       lagrangiennes "DX/Dt"            |    "DX/Dt".
!     - les termes correctifs en         |  - correction terms containing
!       "d(rs/a)/dt" et "d(rs/a)/d eta"  |    "d(rs/a)/dt" and "d(rs/a)/d eta"
!       lies a l'abandon d'hypothese de  |    due to the relaxation of thin
!       couche mince (qui pour des       |    layer hypothesis (for conveniency
!       raisons de commodite sont        |    they are added to the horizontal
!       regroupes avec les divergences   |    fluxes divergences).
!       des flux horizontaux.            |
!     - les termes lies a "delta m=1"    |  - "delta m=1" additional terms
!       (les vitesses verticales PEVEL   |    (vertical velocities PEVEL and
!       PVVEL sont supposees avoir ete   |    PVVEL are assumed to have been
!       modifiees par la routine         |    modified in routine CPMVVPS).
!       CPMVVPS).                        |
!     Il faut remarquer que ces          |  It has to be noticed that these
!     diagnostics sont pleinement        |  diagnostics are fully consistent
!     coherents avec une formulation     |  with an Eulerian discretisation
!     eulerienne des equations avec      |  of equations with an explicit
!     traitement explicite pour le terme |  treatment of Coriolis term.
!     de Coriolis. Les divergences de    |  Flux divergences related to
!     flux liees a la diffusion          |  horizontal diffusion and semi-
!     horizontale et a la correction de  |  implicit scheme corrections are
!     semi-implicite ne sont pas         |  not available here.
!     disponibles ici.                   |

!     Les variables X traitees ici:      |  Variables diagnosed are:
!      * X = 1 (cf. eq de continuite)    |  * X = 1 (cf. continuity eqn)
!      * X = q                           |  * X = q
!      * X = vec(V), traitee dans un     |  * X = vec(V), in a local repere
!        repere local lie aux lat-lon    |    defined by the true geographical
!        geographiques.                  |    lat-lon coordinates.
!      * X = 0.5*vec(V)*vec(V)           |  * X = 0.5*vec(V)*vec(V)
!        (energie cinetique)             |    (kinetic energy)
!      * X = cp*T                        |  * X = cp*T
!      * X = cp*T +gz +0.5*vec(V)*vec(V) |  * X = cp*T +gz +0.5*vec(V)*vec(V)
!        (enthalpie)                     |    (enthalpy)
!      * X = ql (eau liquide)            |  * X = ql (liquid water)
!      * X = qi (glace)                  |  * X = qi (ice)
!      * X = MT (moment cinetique)       |  * X = MT (kinetic momentum)
!               MT = vec(r) wedge ( vec(Omega) wedge vec(r) + vec(V) )
!        traitee dans un repere fixe     |    in a fixed equatorial repere.
!        equatorial.                     |
!        (vec(r) = rs vec(k))            |    (vec(r) = rs vec(k))
!      * X = S (entropie)                |  * X = S (entropy)
!     Les tendances lagrangiennes        |  Lagrangian adiabatic tendencies
!     adiabatiques "(DX/Dt)_adiab"       |  "(DX/Dt)_adiab" are assumed to be
!     sont supposees etre nulles pour    |  zero for the following variables:
!     les variables suivantes:           |
!      * X = 1 (cf. eq de continuite)    |  * X = 1 (cf. continuity eqn)
!      * X = q                           |  * X = q
!      * X = cp*T +gz +0.5*vec(V)*vec(V) |  * X = cp*T +gz +0.5*vec(V)*vec(V)
!        (enthalpie)                     |    (enthalpy)
!      * X = ql (eau liquide)            |  * X = ql (liquid water)
!      * X = qi (glace)                  |  * X = qi (ice)
!      * X = S (entropie)                |  * X = S (entropy)
!     Pour l'energie cinetique,          |  For kinetic energy,
!     "(D (0.5*vec(V)*vec(V))/Dt)_adiab" |  "(D (0.5*vec(V)*vec(V))/Dt)_adiab"
!     est calcule par:                   |  is computed as:
!     "vec(V)*(D vec(V))/Dt)_adiab"      |  "vec(V)*(D vec(V))/Dt)_adiab"
!     Pour l'equation du vent et de      |  For wind and kinetic energy
!     l'energie cinetique la friction    |  equations, Rayleigh friction is
!     de Rayleigh est ici ignoree.       |  omitted here.

!     Surveiller le positionnement des   |  Check fields positions with the
!     champs au moyen de l'indicateur    |  index integer "IDHCV".
!     "IDHCV".

!     Remarques supplementaires:         |  Additional remarks:

!     LVERCOR=T:
!     L'abandon d'hypothese de couche    |  The thin layer hypothesis
!     mince conduit a adopter les        |  relaxation leads to use the
!     conventions suivantes pour les     |  following conventions for vertical
!     flux verticaux: ce qu'on stocke    |  fluxes: what is actually stored in
!     dans les tableaux contenant les    |  arrays containing "fluxes" are
!     flux ce sont des quantites         |  some additive quantities (for
!     extensives (par exemple une masse  |  example a water vapor mass) by
!     de vapeur d'eau) par unite de      |  "pseudo-surface
!     "pseudo-surface                    |  Delta x_a * Delta y_a" unit.
!     Delta x_a * Delta y_a", la pseudo- |  The pseudo-surface is equal to the 
!     surface etant egale a la vraie     |  true surface on the pressure layer
!     surface sur le niveau de pression  |  where the pseudo-radius "rs" is
!     ou le pseudo-rayon "rs" vaut       |  equal to the mean radius "a".
!     exactement le rayon moyen "a". Ce  |  Thus stored fluxes are not the
!     ne sont donc pas les vrais flux    |  exact fluxes (which have to be 
!     (qui eux devraient etre calcules   |  rescaled by the true surface
!     par rapport a la vraie surface     |
!           "S = Delta x Delta y = (rs/a)**2 Delta x_a * Delta y_a")
!     mais ces pseudo-flux ont           |  but these pseudo-fluxes have the
!     l'avantage de rester des quantites |  advantage to be still additive
!     additives (contrairement aux vrais |  quantities (contrary to the 
!     flux), donc en particulier on peut |  "true fluxes"). In particular one
!     prendre la difference de deux      |  can take the difference of two
!     pseudo-flux a deux niveaux         |  "pseudo-fluxes" at two different
!     differents pour calculer la        |  interlayers to compute the 
!     divergence verticale de flux (et   |  vertical divergence of fluxes
!     donc la tendance), ou additionner  |  (and also the tendency), or add
!     les pseudo-flux pour calculer un   |  "pseudo-fluxes" to compute a mean
!     flux moyen sur une grande surface. |  flux on a bigger surface.
!     C'est cette convention qui         |  This choice reduces at the minimum
!     minimise les modifications a       |  the "thin layer hypothesis
!     apporter dans les DDH (et aussi la |  relaxation" modifications to bring
!     physique) vis a vis de l'abandon   |  to the DDH (and also physics) code.
!     d'hypothese de couche mince.       |  For conveniency these
!     Par abus de langage on appellera   |  "pseudo-fluxes" will still be 
!     "flux" ces pseudo-flux.            |  called "fluxes".

!     LRWSDLR=T:
!     Same conventions as for LVERCOR=T to define fluxes.
!     In most parts of the code (pressure depths for example) this is the
!     integrated-mass coordinate "presim" which appears instead of "prehyd"
!     (for example PDELP contains "delta presim" instead of "delta prehyd")
!     We recall that "d(presim)/d(prehyd)=(r**2/a**2)*(G/g)"
!     The modified code is significantly different from the LVERCOR=T code.
!     For the time being metric terms (r/a) have not been properly taken into
!     account in terms other than Coriolis term.

!     Le codage des termes sous          |  Code for terms under "delta m=1"
!     "delta m=1" semble douteux, le RHS |  seem suspicious, the RHS of
!     de l'equation de membre de gauche  |  equation, the LHS of which is
!             " (1/g) d ( (rs**2/a**2) (d prehyd / d eta) X) / dt ".
!     fait apparaitre "- X d Fp / d eta".|  yields the term "- X d Fp / d eta".
!     La forme discretisee devrait donc  |  Its discretised form then sould
!     faire apparaitre 0 si NDPSFI=0 et  |  yield "0" if NDPSFI=0 and
!     "-X[l] (Fp[lbar]-Fp[lbar-1])"      |  "-X[l] (Fp[lbar]-Fp[lbar-1])"
!     si NDPSFI=1. L'abandon d'hypothese |  if NDPSFI=1. Relaxation of thin
!     de couche mince ne touche pas a ce |  layer hypothesis does not modify
!     terme.                             |  this term.
!     De plus ce code ne semble pas      |  Furthermore this code does not seem
!     convenablement remis a jour vis    |  to have been properly updated
!     a vis des dernieres modifications  |  relatively to the last modifications
!     de la formulation "delta m=1"      |  of the "delta m=1" formulation
!     (introduites dans cy29t3).         |  (introduced in cy29t3).

!     Modele non hydrostatique:          |  Non hydrostatic model:
!     le code a ete mis a jour pour les  |  the code has been updated for
!     variables presentes dans un modele |  the variables present in a
!     hydrostatique, mais les            |  hydrostatic model, but diagnostics
!     diagnostics pour les variables     |  relative to pressure departure
!     liees a "pre-prehyd" et la         |  and vertical divergence variables
!     divergence verticale n'ont pas ete |  have not yet been introduced.
!     encore introduits.                 |

!     Notations:                         |  Notations:
!     * prehyd: pression hydrostatique.  |  * prehyd: hydrostatic pressure.
!     * prehyds: pression hydrostatique  |  * prehyds: surface hydrostatic
!       de surface.                      |    pressure.
!     * pre: pression totale.            |  * pre: total pressure.
!     * grad: operateur gradient         |  * grad: is the semi-reduced
!       horizontal semi-reduit           |    "horizontal gradient" operator:
!                  (grad X = (rs/a) vnabla X = M vnabla' X).
!     * (theta,lambda) sont les          |  * (theta,lambda) are the
!       coordonnees geographiques        |    geographical lat-lon coordinates
!       lat-lon du point.                |    of the grid-point.

!     ARGUMENTS D ENTREE / INPUT
!     --------------------------

!      KPROMA         : horizontal dimension.
!      KPROMNH        : horizontal dimension for arrays used only in NH model.
!      KPROMVC        : horizontal dimension for arrays used only if "lvercor=T"
!      KPROMDLW       : horizontal dimension for arrays used only if "lrswdlw=T"
!      KPROMDLR       : horizontal dimension for arrays used only if "lrswdlr=T"
!      KSTART         : start of work.
!      KPROF          : working length.
!      KFLEV          : number of levels.

!      PVCRSSAF       : "rs/a" on layers.
!      PVCRSSAFL      : zonal component of "grad rs/a" on layers.
!      PVCRSSAFM      : meridian component of "grad rs/a" on layers.
!      PVCRSSAH       : "rs/a" on interlayers.
!      PVCASRSF       : "a/rs" on layers.
!      PVCASRSH       : "a/rs" on interlayers.
!      PVCWF          : " W = (D rs/Dt) " on layers.
!      PVCMUSF        : " mu_s " on layers.
!      PWDLWF         : " w = (D r/Dt) " at full levels.
!      PRDLR          : array containing "r/a" and "a/r".
!      PSLAT, PCLAT   : sine "sin(theta)" and cosine "cos(theta)" of
!                       geographical latitude.
!      PLON           : geographical longitude "lambda".
!      PNORDL, PNORDM : components of the unit vector directed towards the
!                       true North pole.
!      PRCORI         : Coriolis parameter " f = 2 Omega sin(theta) ".
!      PRCORIC        : " 2 Omega cos(theta) ".
!      PRATATH        : the curvature term for the V equation. Is equal to
!                       " 2 tan(theta_bne) / a " ("theta_bne" is the latitude
!                       of the tilted unstretched sphere associated to the
!                       computational sphere) for spherical geometry.
!      PRATATX        : the curvature term for the U equation.
!                       Is equal to zero for spherical geometry.
!      PDELP          : "Delta prehyd" on layers.
!      PRDELP         : "1/(Delta prehyd)" on layers.
!      PRR            : moist air constant "R" on layers.
!      PRTGR          : scalar ratio of vectors "(grad prehyd)/prehyd"
!                       and "grad prehyds" (computed in GPXYB) on layers.
!      PSGRTL, PSGRTM : components of the semi-reduced pressure gradient term,
!                       on layers.
!      PCP            : moist air calorific capacity at constant pressure "cp",
!                       on layers.
!      PAPHI          : geopotential height "gz" on interlayers.
!      PAPHIF         : geopotential height "gz" on layers.
!      PAPHIFL        : zonal component of " grad (gz) " on layers.
!      PAPHIFM        : meridian component of " grad (gz) " on layers.
!      PVVEL          : "omega/prehyd" on layers, including the "lrubc" and
!                       "delta m=1" effects. 
!      PSDIV          : vertical integral of divergence without
!                       "lrubc" and "delta m=1" contributions, on interlayers.
!      PDIV           : semi-reduced divergence "(rs/a) D = M**2 D' " on layers.
!      PDIVDP         : see PDIVDP in GPCTY. 
!      PU             : U-component of the horizontal wind (contravariant comp.)
!                       on layers.
!      PV             : V-component of the horizontal wind (contravariant comp.)
!                       on layers.
!      PT             : temperature "T" on layers.
!      PQV            : vapour specific humidity "q" on layers. 
!      PKENE          : kinetic energy on layers.
!      PVOR           : semi-reduced vorticity "(rs/a) zeta = M**2 zeta' "
!                       on layers.
!      PUL, PVL       : "grad U" and "grad V" on layers. 
!      PTL, PTM       : components of the semi-reduced gradient of temperature
!                       "grad T" on layers.
!      PQVL, PQVM     : components of the semi-reduced gradient of vapour
!                       specific humidity "grad q" on layers.
!      PRTL, PRTM     : components of the semi-reduced gradient "grad RT"
!                       of "RT" on layers.
!      PORL, PORM     : components of the semi-reduced gradient
!                       "grad Phi_s" of orography. 
!      PLNPR          : term "delta" on layers
!                       (= logarithm of ratio of pressure if "ndlnpr=0")
!      PSPL, PSPM     : components of the semi-reduced gradient
!                       "grad prehyds" of surface hydrostatic pressure.
!      PAPRS          : hydrostatic pressure on interlayers.
!      PAPRSF         : hydrostatic pressure on layers.
!      P3DIVG         : D3 at t (full levels).
!      PNHPREF        : "pre" at full levels (time t).
!      PNHPREH        : "pre" at half levels (time t).
!      PQCHAL         : zonal comp grad(log(pre/prehyd)).
!      PQCHAM         : merid comp grad(log(pre/prehyd)).
!      PEVEL          : "etapt d prehyd/d eta",
!                       including the "lrubc" and "delta m=1" effects.
!                       On interlayers (resp. layers) if LVERTFE=F (resp. T).
!      POMEGA         : "omega" on layers, including the "lrubc" and
!                       "delta m=1" effects.
!      PFPLCL         : convective liquid rainfall flux, on interlayers.
!      PFPLCN         : convective solid rainfall flux, on interlayers.
!      PFPLSL         : stratiform liquid rainfall flux, on interlayers.
!      PFPLSN         : stratiform solid rainfall flux, on interlayers.
!      PQVS           : surface vapour specific humidity "q[surf]".
!      PTSFC          : surface temperature "T[surf]".
!      PRH            : relative humidity "RH" on layers.
!      PNEB           : cloud fraction "q_a" on layers.
!      PQL            : liquid water "q_l" on layers.
!      PQN            : ice water "q_i" on layers.
!      PQLL ,PQLM     : components of the semi-reduced gradient of liquid
!                       water "grad q_l" on layers.
!      PQNL ,PQNM     : components of the semi-reduced gradient of ice
!                       water "grad q_i" on layers.

!     SORTIES / OUTPUT
!     ----------------
!       PUZ, PVM      : horizontal wind components in a geographical local
!                       repere (i.e. the unit vector vec(j) is directed towards
!                       the true North pole).
!       PDHCV         : result array containing flux divergences and fluxes.
!                       Entering this routine this array is assumed to be
!                       pre-initialised with zeros.
!       PENTRA        : specific entropy of dry air "Sd", on layers.
!       PENTRV        : specific entropy of water vapour "Sv", on layers.

!     ORIGINAL
!     --------
!     91-03-04, Alain Joly.

!     MODIFICATIONS
!     -------------
!     91-12-11, J.M. Piriou: ajout du terme flux d'enthalpie du aux
!               precipitations, dans le cas masse variable (NDPSFI=1).
!     92-03-01, M. Janousek: diagnostic de l'entropie.
!     92-06-01, M. Janousek: diagnostic du moment cinetique.
!     92-06-01, J.M. Piriou: humidite relative et cumul du champ de masse.
!     92-06-29, J.M. Piriou: modification expression flux enth. du aux precip.
!     92-07-08, V. Ducrocq : introduction of a new curvature term in the U
!      equation
!     94-03-22, J.M. Piriou: suppression du terme flux d'enthalpie
!               precipitations, dans le cas masse variable (NDPSFI=1).
!     Modified 94-06-20 by M.Hamrud : upper air grid-point file
!     00-08-08, K. YESSAD: relaxation of thin layer hypothesis.
!     00-08-08, K. YESSAD: cleanings (dummy arguments, correct false comments)
!     00-08-08, K. YESSAD: bug correction for "delta m=1".
!     R. El Khatib : 01-08-07 Pruning options
!     02-05-21, K. YESSAD: corrections for consistency with LVERTFE=T
!               for cases lvercor=f, ndpsfi=0, lrubc=f.
!        M.Hamrud      01-Oct-2003 CY28 Cleaning
!     30-Aug-2005 K. Yessad  DDH for NH model.
!   2006-04-16, T. Kovacic: AROME DDH.
!   N. Wedi and K. Yessad (Jan 2008): different dev for NH model and PC scheme
!   17-09-08   O. Riviere New data flux for diag. if LFLEXDIA=.TRUE.
!   K. Yessad (Dec 2008): remove dummy CDLOCK
!   K. Yessad (March 2009): correct false comments for LRWSDLG=T
!     ------------------------------------------------------------------

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

USE YOMCST   , ONLY : ROMEGA   ,RA       ,RG       ,RD       ,&
 & RV       ,RCPD     ,RCPV     ,RCW      ,RCS      ,&
 & RTT      ,RATM  
USE YOMRIP   , ONLY : NSSSSS   ,RSTATI
USE YOMLUN   , ONLY : NULOUT
USE YOMGEM   , ONLY : VDELB
USE YOMPHY   , ONLY : NDPSFI, NPHY, JPHYARO, L3MT, LSTRAPRO
USE YOMCT0   , ONLY : LSLAG    ,LNHDYN   ,LVERCOR
USE YOMDYNA  , ONLY : LRWSDLW  ,LRWSDLR 
USE YOMCVER  , ONLY : LVERTFE
USE YOMLDDH  , ONLY : LHDHKS   ,LHDMCI   ,LHDENT   ,LHDLIST,LFLEXDIA

USE YOMMDDH  , ONLY : NDHCVSU  ,NDHVV    ,NDHVHK   ,NDHVMC   ,&
 & NDHAVD   ,NDHAHKD  ,NDHBHKD  ,NDHAMCD  ,NDHBMCD  
USE YOMDIM   , ONLY : NFLEVG   ,NPROMA
USE YOMSDDH  , ONLY : NHDQLNVA ,NHDPASVA ,LHDQLN   
USE YOM_YGFL , ONLY : YGFL, YQ, YL, YI, YR, YS, YG, YTKE
USE PAR_RDLR , ONLY : JP_ASRF  ,JP_RSAF  ,JP_DIMR
USE DDH_MIX,ONLY :ADD_FIELD_3D


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

IMPLICIT NONE

INTEGER(KIND=JPIM),INTENT(IN)    :: KPROMA 
INTEGER(KIND=JPIM),INTENT(IN)    :: KPROMNH
INTEGER(KIND=JPIM),INTENT(IN)    :: KPROMVC 
INTEGER(KIND=JPIM),INTENT(IN)    :: KPROMDLW
INTEGER(KIND=JPIM),INTENT(IN)    :: KPROMDLR
INTEGER(KIND=JPIM),INTENT(IN)    :: KFLEV 
INTEGER(KIND=JPIM),INTENT(IN)    :: KSTART 
INTEGER(KIND=JPIM),INTENT(IN)    :: KPROF 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PVCRSSAF(KPROMVC,KFLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PVCRSSAFL(KPROMVC,KFLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PVCRSSAFM(KPROMVC,KFLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PVCRSSAH(KPROMVC,0:KFLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PVCASRSF(KPROMVC,KFLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PVCASRSH(KPROMVC,0:KFLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PVCWF(KPROMVC,KFLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PVCMUSF(KPROMVC,KFLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PWDLWF(KPROMDLW,KFLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PRDLR(KPROMDLR,0:KFLEV,JP_DIMR)
REAL(KIND=JPRB)   ,INTENT(IN)    :: PSLAT(KPROMA) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PCLAT(KPROMA) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PLON(KPROMA) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PNORDL(KPROMA) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PNORDM(KPROMA) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PRCORI(KPROMA) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PRCORIC(KPROMA) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PRATATH(KPROMA) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PRATATX(KPROMA) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PDELP(KPROMA,KFLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PRDELP(KPROMA,KFLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PRR(KPROMA,KFLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PRTGR(KPROMA,KFLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PSGRTL(KPROMA,KFLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PSGRTM(KPROMA,KFLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PCP(KPROMA,KFLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PAPHI(KPROMA,0:KFLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PAPHIF(KPROMA,KFLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PAPHIFL(KPROMA,KFLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PAPHIFM(KPROMA,KFLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PVVEL(KPROMA,KFLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PSDIV(KPROMA,0:KFLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PDIV(KPROMA,KFLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PDIVDP(KPROMA,KFLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PU(KPROMA,KFLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PV(KPROMA,KFLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PT(KPROMA,KFLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PQV(KPROMA,KFLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PKENE(KPROMA,KFLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PVOR(KPROMA,KFLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PUL(KPROMA,KFLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PVL(KPROMA,KFLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PTL(KPROMA,KFLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PTM(KPROMA,KFLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PQVL(KPROMA,KFLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PQVM(KPROMA,KFLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PRTL(KPROMA,KFLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PRTM(KPROMA,KFLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PORL(KPROMA) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PORM(KPROMA) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PLNPR(KPROMA,KFLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PSPL(KPROMA) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PSPM(KPROMA) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PAPRSF(KPROMA,KFLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PAPRS(KPROMA,0:KFLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: P3DIVG(KPROMNH,KFLEV)
REAL(KIND=JPRB)   ,INTENT(IN)    :: PNHPREF(KPROMNH,KFLEV)
REAL(KIND=JPRB)   ,INTENT(IN)    :: PNHPREH(KPROMNH,0:KFLEV)
REAL(KIND=JPRB)   ,INTENT(IN)    :: PQCHAL(KPROMNH,KFLEV)
REAL(KIND=JPRB)   ,INTENT(IN)    :: PQCHAM(KPROMNH,KFLEV)
REAL(KIND=JPRB)   ,INTENT(IN)    :: PEVEL(KPROMA,0:KFLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: POMEGA(KPROMA,KFLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PFPLCL(KPROMA,0:KFLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PFPLCN(KPROMA,0:KFLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PFPLSL(KPROMA,0:KFLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PFPLSN(KPROMA,0:KFLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PQVS(KPROMA) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PTSFC(KPROMA) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PRH(KPROMA,KFLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PNEB(KPROMA,KFLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PQL(KPROMA,KFLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PQN(KPROMA,KFLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PQLL(KPROMA,KFLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PQLM(KPROMA,KFLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PQNL(KPROMA,KFLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PQNM(KPROMA,KFLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PGFL(NPROMA,NFLEVG,YGFL%NDIM)
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PUZ(KPROMA,KFLEV) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PVM(KPROMA,KFLEV) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PDHCV(KPROMA,0:KFLEV,NDHCVSU) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PENTRA(KPROMA,KFLEV) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PENTRV(KPROMA,KFLEV) 

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

REAL(KIND=JPRB) :: ZCPT(KPROMA,KFLEV)
REAL(KIND=JPRB) :: ZGKEU(KPROMA,KFLEV), ZGKEV(KPROMA,KFLEV)
REAL(KIND=JPRB) :: ZSLON(KPROMA), ZCLON(KPROMA)
REAL(KIND=JPRB) :: ZM1(KPROMA,KFLEV), ZM2(KPROMA,KFLEV), ZM3(KPROMA,KFLEV)
REAL(KIND=JPRB) :: ZRTZON(KPROMA,KFLEV), ZRTMER(KPROMA,KFLEV)
REAL(KIND=JPRB) :: ZPHILZ(KPROMA), ZPHILM(KPROMA)
REAL(KIND=JPRB) :: ZFPSUM(KPROMA,0:KFLEV)
REAL(KIND=JPRB) :: ZFPTOT(KPROMA,0:KFLEV)
REAL(KIND=JPRB) :: ZDELLT(KPROMA,0:KFLEV)
REAL(KIND=JPRB) :: ZENTR(KPROMA,KFLEV)
REAL(KIND=JPRB) :: ZENTRL(KPROMA,0:KFLEV), ZENTRS(KPROMA,0:KFLEV)
REAL(KIND=JPRB) :: ZVCS(KPROMA,KFLEV)
REAL(KIND=JPRB) :: ZDELPREV(KPROMA,KFLEV)
REAL(KIND=JPRB) :: ZRHSK(KPROMA,KFLEV)
REAL(KIND=JPRB) :: ZRHSME(KPROMA)
REAL(KIND=JPRB) :: ZRHSU(KPROMA,KFLEV)
REAL(KIND=JPRB) :: ZRHSV(KPROMA,KFLEV)
REAL(KIND=JPRB) :: ZRHSZO(KPROMA)
REAL(KIND=JPRB) :: ZRS2SA2EVELH(KPROMA,0:KFLEV)
REAL(KIND=JPRB) :: ZRS2SA2TEPH(KPROMA,0:KFLEV)
REAL(KIND=JPRB) :: ZRSF(KPROMA,KFLEV)
REAL(KIND=JPRB) :: ZZDELP(KPROMA,KFLEV)
REAL(KIND=JPRB) :: ZAPRSF(KPROMA,KFLEV)
REAL(KIND=JPRB) :: ZAPRS(KPROMA,0:KFLEV)
REAL(KIND=JPRB) :: ZQCHAL(KPROMA,KFLEV)
REAL(KIND=JPRB) :: ZQCHAM(KPROMA,KFLEV)
REAL(KIND=JPRB) :: Z_CP_TIMES_CONV(KPROMA,KFLEV)
REAL(KIND=JPRB) :: ZTMPAF(KPROMA,KFLEV) 

INTEGER(KIND=JPIM) :: IDHCV,  JLEV, JROF

REAL(KIND=JPRB) :: ZADPHI, ZADVHORRSSA2F, ZADVLNT, ZADVP, ZADVQL, ZADVQN, ZADVQV, &
 & ZADVT, ZADVVERRSSA2F, ZCVMCD, ZDIVDP, &
 & ZDIVPHYFLU1, ZDIVVERFLU1, ZDPREM, ZDPREZ, ZDPSFI, ZENTRA, &
 & ZENTRA0, ZENTRA00, ZENTRAS, ZENTRL0, ZENTRL00, &
 & ZENTRS0, ZENTRS00, ZENTRV, ZENTRV0, ZENTRV00, &
 & ZENTRVS, ZLTBOT, ZLTHL, ZLTTOP, ZORMER, ZORZON, &
 & ZPFIS2, ZPREV, ZPREVS, ZQTHRES, &
 & ZTENDEULRSSA2F, ZTENDLAGRSSA2F, ZTERM1, ZTERM2, &
 & ZUSA, ZUS2RG, ZUSRG  
REAL(KIND=JPRB) :: ZHOOK_HANDLE

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

#include "abor1.intfb.h"

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

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

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

!     CHECK RELIABILITY OF INPUT ARGUMENTS.

IF (NDPSFI==1 .AND. LRWSDLR) THEN
  CALL ABOR1(' CPDYDDH: NDPSFI=1 not coded for LRWSDLR=T!!')
ENDIF

!     ------------------------------------------------------------------
!*    0.- INITIALISATIONS DE SECURITE / SAFETY SET-UP.
!         AFIN DE CONTOURNER LE MESSAGE DE WARNING PRODUIT PAR
!         LE LOGICIEL DE CONTROLE DES INITIALISATIONS DE VARIABLES
!         EN CAS DE VARIABLES INITIALISEES A L'INTERIEUR DE
!         TESTS IF-ENDIF, ON PORTE UNE VALEUR QUELCONQUE
!         DANS LESDITES VARIABLES.

ZENTRA0=0.0_JPRB
ZENTRV0=0.0_JPRB
ZQTHRES=0.0_JPRB
IDHCV=0

! * Calcul de "rs" ou "r" sur les couches.
!   Computation of "rs" or "r" at full levels.

IF (LVERCOR) THEN
  ZRSF(KSTART:KPROF,1:KFLEV)=RA*PVCRSSAF(KSTART:KPROF,1:KFLEV)
ELSEIF (LRWSDLR) THEN
  ZRSF(KSTART:KPROF,1:KFLEV)=RA*PRDLR(KSTART:KPROF,1:KFLEV,JP_RSAF)
ELSE
  ZRSF(KSTART:KPROF,1:KFLEV)=RA
ENDIF

! * Calcul des epaisseurs de pression hydrostatique virtuelle sur les couches:
!   Computation of virtual hydrostatic pressure depths at full levels:
!   lvercor=T: "Delta prehydv = (rs**2/a**2) Delta prehyd".
!   lrwsdlr=T: "Delta prehydv = Delta presim".
!   otherwise: "Delta prehydv = Delta prehyd".

IF (LVERCOR) THEN
  ZDELPREV(KSTART:KPROF,1:KFLEV)=&
   & PVCRSSAF(KSTART:KPROF,1:KFLEV)*PVCRSSAF(KSTART:KPROF,1:KFLEV)*&
   & PDELP(KSTART:KPROF,1:KFLEV)  
ELSE
  ZDELPREV(KSTART:KPROF,1:KFLEV)=PDELP(KSTART:KPROF,1:KFLEV)
ENDIF

! * Variable intermediaire contenant / intermediate variable containing:
!   lvercor=T: "(rs/a) Delta prehyd".
!   lrwsdlr=T: "(a/r) Delta presim".
!   otherwise: "Delta prehyd".

IF (LVERCOR) THEN
  ZZDELP(KSTART:KPROF,1:KFLEV)=PVCRSSAF(KSTART:KPROF,1:KFLEV)*&
   & PDELP(KSTART:KPROF,1:KFLEV)  
ELSE
  ZZDELP(KSTART:KPROF,1:KFLEV)=PDELP(KSTART:KPROF,1:KFLEV)
ENDIF

! * Variable intermediaire contenant / intermediate variable containing:
!   - thin layer equations or Wood and Staniforth (NH) deep layer equations:
!     "(etapt d prehyd/d eta)_[lbar]".
!   - White and Bomley deep layer equations:
!     " (rs**2/a**2)_[lbar] (etapt d prehyd/d eta)_[lbar] " 
IF (LVERTFE) THEN
  ! * Top and surface:
  ZRS2SA2EVELH(KSTART:KPROF,0)=0.0_JPRB     ! lrubc=t, ndpsfi=1 not yet coded
  ZRS2SA2EVELH(KSTART:KPROF,KFLEV)=0.0_JPRB ! lrubc=t, ndpsfi=1 not yet coded
  ! * interlayers 1 to L-1:
  IF (LVERCOR) THEN
    DO JLEV=1,KFLEV-1
      ZRS2SA2EVELH(KSTART:KPROF,JLEV)=&
       & 0.5_JPRB*(&
       & PVCRSSAF(KSTART:KPROF,JLEV)*PVCRSSAF(KSTART:KPROF,JLEV)*&
       & PEVEL(KSTART:KPROF,JLEV) &
       & +PVCRSSAF(KSTART:KPROF,JLEV+1)*PVCRSSAF(KSTART:KPROF,JLEV+1)*&
       & PEVEL(KSTART:KPROF,JLEV+1) )  
    ENDDO
  ELSE
    DO JLEV=1,KFLEV-1
      ZRS2SA2EVELH(KSTART:KPROF,JLEV)=&
       & 0.5_JPRB*(PEVEL(KSTART:KPROF,JLEV)+PEVEL(KSTART:KPROF,JLEV+1))  
    ENDDO
  ENDIF
ELSE
  IF (LVERCOR) THEN
    ZRS2SA2EVELH(KSTART:KPROF,0:KFLEV)=&
     & PVCRSSAH(KSTART:KPROF,0:KFLEV)*PVCRSSAH(KSTART:KPROF,0:KFLEV)*&
     & PEVEL(KSTART:KPROF,0:KFLEV)  
  ELSE
    ZRS2SA2EVELH(KSTART:KPROF,0:KFLEV)=PEVEL(KSTART:KPROF,0:KFLEV)
  ENDIF
ENDIF

! * Total pressure or hydrostatic pressure according to LNHDYN:
IF (LNHDYN) THEN
  ZAPRSF(KSTART:KPROF,1:KFLEV)=PNHPREF(KSTART:KPROF,1:KFLEV)
  ZAPRS(KSTART:KPROF,0:KFLEV)=PNHPREH(KSTART:KPROF,0:KFLEV)
  ZQCHAL(KSTART:KPROF,1:KFLEV)=PQCHAL(KSTART:KPROF,1:KFLEV)
  ZQCHAM(KSTART:KPROF,1:KFLEV)=PQCHAM(KSTART:KPROF,1:KFLEV)
ELSE
  ZAPRSF(KSTART:KPROF,1:KFLEV)=PAPRSF(KSTART:KPROF,1:KFLEV)
  ZAPRS(KSTART:KPROF,0:KFLEV)=PAPRS(KSTART:KPROF,0:KFLEV)
  ZQCHAL(KSTART:KPROF,1:KFLEV)=0.0_JPRB
  ZQCHAM(KSTART:KPROF,1:KFLEV)=0.0_JPRB
ENDIF

! * "cp*(conversion term)" (in the RHS of cp*T equation), i.e.
!   "-RT(cp/cv)*D3" or "RT(omega/prehyd)" according to LNHDYN:
IF (LNHDYN) THEN
  ! * compute -RT(cp/cv)*D3 = -RT(cp/(cp-R))*D3:
  DO JLEV = 1, KFLEV
    DO JROF=KSTART,KPROF
      Z_CP_TIMES_CONV(JROF,JLEV)=-PRR(JROF,JLEV)*PT(JROF,JLEV)* &
       & (PCP(JROF,JLEV)/(PCP(JROF,JLEV)-PRR(JROF,JLEV)))*P3DIVG(JROF,JLEV)
    ENDDO
  ENDDO
ELSE
  ! * compute RT(omega/prehyd):
  DO JLEV = 1, KFLEV
    DO JROF=KSTART,KPROF
      Z_CP_TIMES_CONV(JROF,JLEV)=PRR(JROF,JLEV)*PT(JROF,JLEV)*PVVEL(JROF,JLEV)
    ENDDO
  ENDDO
ENDIF

!     ------------------------------------------------------------------
!*    1.- CALCUL DES VARIABLES DYNAMIQUES / DYNAMICAL VARIABLES COMPUTATIONS.

ZUSA=1.0_JPRB/RA
ZUSRG = 1.0_JPRB/RG
ZCVMCD = RCPV - RCPD
ZDPSFI = REAL(NDPSFI,JPRB)

! * Calcul des composantes du vent geographique dans un repere local lie au
!   vrai pole nord.
!   Computation of geographical wind components in a local repere, the ordinate
!   of which is directed towards the true North pole.

IF ( LHDHKS .OR. LHDMCI .OR. LHDENT ) THEN
  DO JLEV = 1, KFLEV
    DO JROF=KSTART,KPROF
      PUZ(JROF,JLEV) =PNORDM(JROF)*PU(JROF,JLEV)-PNORDL(JROF)*PV(JROF,JLEV)
      PVM(JROF,JLEV) =PNORDL(JROF)*PU(JROF,JLEV)+PNORDM(JROF)*PV(JROF,JLEV)
    ENDDO
  ENDDO
ENDIF

! * Calcul du gradient horizontal "semi-reduit" de l'energie cinetique.
!   Computation of the "semi-reduced" horizontal gradient of kinetic energy.

IF ( LHDHKS ) THEN
  IF ( LSLAG ) THEN
    DO JLEV = 1, KFLEV
      DO JROF=KSTART,KPROF
        ZGKEU(JROF,JLEV) = 0.0_JPRB
        ZGKEV(JROF,JLEV) = 0.0_JPRB
      ENDDO
    ENDDO
  ELSE
    DO JLEV = 1, KFLEV
      DO JROF=KSTART,KPROF
        ZGKEU(JROF,JLEV) = - PV(JROF,JLEV)* PVOR(JROF,JLEV)&
         & + PV(JROF,JLEV)*PVL(JROF,JLEV)&
         & + PU(JROF,JLEV)*PUL(JROF,JLEV)&
         & - PKENE(JROF,JLEV)*PRATATX(JROF)  
        ZGKEV(JROF,JLEV) = PV(JROF,JLEV)* PDIV(JROF,JLEV)&
         & - PV(JROF,JLEV)*PUL(JROF,JLEV)&
         & + PU(JROF,JLEV)*PVL(JROF,JLEV)&
         & + PKENE(JROF,JLEV)*PRATATH(JROF)  
      ENDDO
    ENDDO
  ENDIF
ENDIF

! * Calcul de "cp T" sur les couches.
!   Computation of "cp T" on layers.

IF ( LHDHKS ) THEN
  DO JLEV = 1, KFLEV
    DO JROF=KSTART,KPROF
      ZCPT(JROF,JLEV) = PCP(JROF,JLEV)*PT(JROF,JLEV)
    ENDDO
  ENDDO
ENDIF

! * Calculs relatifs a l'entropie.
!    On calcule d'abord des entropies de reference (variables ZENTR..00
!    et ZENTR..0) puis on calcule:
!    - l'entropie de l'air sec (PENTRA).
!    - l'entropie de la vapeur d'eau (PENTRV).
!    - l'entropie de l'air humide (ZENTR).
!    - l'entropie de l'eau liquide (ZENTRL).
!    - l'entropie de la glace (ZENTRS).
!   Computations involving entropy.
!    One first computes some reference entropies ((variables ZENTR..00
!    and ZENTR..0), one then computes:
!    - dry air entropy (PENTRA).
!    - water vapour entropy (PENTRV).
!    - moist air entropy (ZENTR).
!    - liquid water entropy (ZENTRL).
!    - solid water entropy (ZENTRS).
!   Entropy = cp T + R log(pre), with "pre"=total pressure.

IF ( LHDENT ) THEN
  DO JLEV = 2, KFLEV-1
    DO JROF=KSTART,KPROF
      ZDELLT(JROF,JLEV) = ( PT(JROF,JLEV+1)-PT(JROF,JLEV-1) ) /&
       & (2.0_JPRB*PT(JROF,JLEV))  
    ENDDO
  ENDDO
  DO JROF=KSTART,KPROF
    ZDELLT(JROF,1) = - 0.5_JPRB + PT(JROF,2)/(2.0_JPRB*PT(JROF,1))
    ZDELLT(JROF,KFLEV) = - (0.5_JPRB*PT(JROF,KFLEV-1)-PTSFC(JROF)) /&
     & PT(JROF,KFLEV) - 0.5_JPRB  
  ENDDO
! * THE REFERENCE SPECIFIC ENTROPIES
  ZENTRA00 = 6775._JPRB
  ZENTRV00 = 10320._JPRB
  ZENTRL00 = 3517._JPRB
  ZENTRS00 = 2296._JPRB
  ZENTRA0 = -RCPD*LOG(RTT)+RD*LOG(RATM)+ZENTRA00
  ZENTRV0 = -RCPV*LOG(RTT)+RV*LOG(RATM)+ZENTRV00
  ZENTRL0 = -RCW*LOG(RTT)+ZENTRL00
  ZENTRS0 = -RCS*LOG(RTT)+ZENTRS00
! * THE THRESHOLD VALUE AVOIDING NEGATIVE HUMIDITY
  ZQTHRES = 1.E-12_JPRB
! * CALCULATION OF THE SPECIFIC ENTROPIES
  DO JLEV = 1, KFLEV
    DO JROF=KSTART,KPROF
      ZPREV = MAX(ZQTHRES,PQV(JROF,JLEV))*RV*ZAPRSF(JROF,JLEV)/PRR(JROF,JLEV)
      ZENTRA = RCPD*LOG(PT(JROF,JLEV))-&
       & RD*LOG(ZAPRSF(JROF,JLEV)-ZPREV)+ZENTRA0  
      ZENTRV = RCPV*LOG(PT(JROF,JLEV))-RV*LOG(ZPREV)+ZENTRV0
      ZENTR(JROF,JLEV) = ZENTRA+(ZENTRV-ZENTRA)*PQV(JROF,JLEV)
      PENTRA(JROF,JLEV) = ZENTRA
      PENTRV(JROF,JLEV) = ZENTRV
    ENDDO
  ENDDO
  DO JLEV=1,KFLEV-1
    DO JROF=KSTART,KPROF
      ZLTHL = LOG((PT(JROF,JLEV)+PT(JROF,JLEV))/2.0_JPRB)
      ZENTRL(JROF,JLEV) = RCW*ZLTHL + ZENTRL0
      ZENTRS(JROF,JLEV) = RCS*ZLTHL + ZENTRS0
    ENDDO
  ENDDO
  DO JROF=KSTART,KPROF
    ZLTTOP = LOG(PT(JROF,1))
    ZLTBOT = LOG(PTSFC(JROF))
    ZENTRL(JROF,0) = RCW*ZLTTOP + ZENTRL0
    ZENTRL(JROF,KFLEV) = RCW*ZLTBOT + ZENTRL0
    ZENTRS(JROF,0) = RCS*ZLTBOT + ZENTRS0
    ZENTRS(JROF,KFLEV) = RCS*ZLTBOT + ZENTRS0
  ENDDO
! * TOTAL FLUX OF PRECIPITATIONS
  DO JLEV=0, KFLEV
    DO JROF=KSTART,KPROF
      ZFPTOT(JROF,JLEV) = PFPLCL(JROF,JLEV) + PFPLCN(JROF,JLEV) +&
       & PFPLSL(JROF,JLEV) + PFPLSN(JROF,JLEV)  
    ENDDO
  ENDDO
ENDIF

! * Calcul des trois composantes M1, M2 et M3 du moment angulaire,
!   puis des composantes de "grad (RT)" dans un repere local lie au
!   vrai pole nord.
!   Computation of the three components M1, M2 et M3 of angular moment,
!   then computation of the components of "grad (RT)" in a local repere,
!   the ordinate of which is directed towards the true North pole.

IF ( LHDMCI ) THEN
  DO JROF=KSTART,KPROF
    ZSLON(JROF) = SIN(PLON(JROF)+ROMEGA*(RSTATI-NSSSSS))
    ZCLON(JROF) = COS(PLON(JROF)+ROMEGA*(RSTATI-NSSSSS))
  ENDDO
  DO JLEV=1, KFLEV
    DO JROF=KSTART,KPROF
      ZM1(JROF,JLEV) = ZRSF(JROF,JLEV)*( PVM(JROF,JLEV)*ZSLON(JROF)&
       & -(PUZ(JROF,JLEV)+ZRSF(JROF,JLEV)*ROMEGA*PCLAT(JROF))*&
       & PSLAT(JROF)*ZCLON(JROF) )  
      ZM2(JROF,JLEV) = ZRSF(JROF,JLEV)*( -PVM(JROF,JLEV)*ZCLON(JROF)&
       & -(PUZ(JROF,JLEV)+ZRSF(JROF,JLEV)*ROMEGA*PCLAT(JROF))*&
       & PSLAT(JROF)*ZSLON(JROF) )  
      ZM3(JROF,JLEV) = ZRSF(JROF,JLEV)*(PUZ(JROF,JLEV)&
       & +ZRSF(JROF,JLEV)*ROMEGA*PCLAT(JROF))*PCLAT(JROF)  
      ZRTZON(JROF,JLEV) = PNORDM(JROF)*PRTL(JROF,JLEV) -&
       & PNORDL(JROF)*PRTM(JROF,JLEV)  
      ZRTMER(JROF,JLEV) = PNORDL(JROF)*PRTL(JROF,JLEV) +&
       & PNORDM(JROF)*PRTM(JROF,JLEV)  
    ENDDO
  ENDDO
ENDIF

! * Calcul de "(Delta prehyd) X" ("(rs**2/a**2) (Delta prehyd) X" si lvercor=T,
!   "(Delta presim) X" si lrwsdlr=T) sur les couches, pour
!   X = 1; (-1/g); q; Ugeo; Vgeo; (U**2+V**2)/2; cp*T; g*z; RH; ql; qi; qa;
!   omega; M1; M2; M3; S.
!   Computation of "(Delta prehyd) X"
!   ("(rs**2/a**2) (Delta prehyd) X" if lvercor=T,
!   "(Delta presim) X" if lrwsdlr=T) at full levels,
!   for X = 1; (-1/g); q; Ugeo; Vgeo; (U**2+V**2)/2; cp*T; g*z; RH; ql; qi; qa;
!   omega; M1; M2; M3; S.

IF ( LHDHKS ) THEN
  IF(LFLEXDIA) THEN
     CALL ADD_FIELD_3D(ZDELPREV,'VPP','V','ARP',.TRUE.,.TRUE.)
     ZTMPAF(KSTART:KPROF,1:KFLEV)= &
      & ZDELPREV(KSTART:KPROF,1:KFLEV)*PQV(KSTART:KPROF,1:KFLEV)
     CALL ADD_FIELD_3D(ZTMPAF,'VQV','V','ARP',.TRUE.,.TRUE.)
     ZTMPAF(KSTART:KPROF,1:KFLEV)= &
      & ZDELPREV(KSTART:KPROF,1:KFLEV)*PUZ(KSTART:KPROF,1:KFLEV)
     CALL ADD_FIELD_3D(ZTMPAF,'VUU','V','ARP',.TRUE.,.TRUE.)
     ZTMPAF(KSTART:KPROF,1:KFLEV)= &
      & ZDELPREV(KSTART:KPROF,1:KFLEV)*PVM(KSTART:KPROF,1:KFLEV)
     CALL ADD_FIELD_3D(ZTMPAF,'VVV','V','ARP',.TRUE.,.TRUE.)
     ZTMPAF(KSTART:KPROF,1:KFLEV)= &
      & ZDELPREV(KSTART:KPROF,1:KFLEV)*PKENE(KSTART:KPROF,1:KFLEV)
     CALL ADD_FIELD_3D(ZTMPAF,'VKK','V','ARP',.TRUE.,.TRUE.)
     ZTMPAF(KSTART:KPROF,1:KFLEV)= &
      & ZDELPREV(KSTART:KPROF,1:KFLEV)*ZCPT(KSTART:KPROF,1:KFLEV)
     CALL ADD_FIELD_3D(ZTMPAF,'VCT','V','ARP',.TRUE.,.TRUE.)
     ZTMPAF(KSTART:KPROF,1:KFLEV)= &
      & ZDELPREV(KSTART:KPROF,1:KFLEV)*PAPHIF(KSTART:KPROF,1:KFLEV)
     CALL ADD_FIELD_3D(ZTMPAF,'VEP','V','ARP',.TRUE.,.TRUE.)
     ZTMPAF(KSTART:KPROF,1:KFLEV)= &
      & ZDELPREV(KSTART:KPROF,1:KFLEV)*PRH(KSTART:KPROF,1:KFLEV)
     CALL ADD_FIELD_3D(ZTMPAF,'VHR','V','ARP',.TRUE.,.TRUE.)
  ELSE
    IDHCV=0
    DO JLEV = 1, KFLEV
      DO JROF=KSTART,KPROF
!       VPP
        PDHCV(JROF,JLEV,IDHCV+1) = ZDELPREV(JROF,JLEV)
!       VQV
        PDHCV(JROF,JLEV,IDHCV+2) = PQV(JROF,JLEV)*ZDELPREV(JROF,JLEV)
!       VUU
        PDHCV(JROF,JLEV,IDHCV+3) = PUZ(JROF,JLEV)*ZDELPREV(JROF,JLEV)
!       VVV
        PDHCV(JROF,JLEV,IDHCV+4) = PVM(JROF,JLEV)*ZDELPREV(JROF,JLEV)
!       VKK
        PDHCV(JROF,JLEV,IDHCV+5) = PKENE(JROF,JLEV)*ZDELPREV(JROF,JLEV)
!       VCT
        PDHCV(JROF,JLEV,IDHCV+6) = ZCPT(JROF,JLEV)*ZDELPREV(JROF,JLEV)
!       VEP
        PDHCV(JROF,JLEV,IDHCV+7) = PAPHIF(JROF,JLEV)*ZDELPREV(JROF,JLEV)
!       VHR
        PDHCV(JROF,JLEV,IDHCV+8) = PRH(JROF,JLEV)*ZDELPREV(JROF,JLEV)
      ENDDO
    ENDDO
  ENDIF
    
  SELECT CASE (NPHY)
    CASE(JPHYARO)
      IF (LFLEXDIA) THEN
        ZTMPAF(KSTART:KPROF,1:KFLEV)= &
         & ZDELPREV(KSTART:KPROF,1:KFLEV)*PQL(KSTART:KPROF,1:KFLEV)
        CALL ADD_FIELD_3D(ZTMPAF,'VQL','V','ARP',.TRUE.,.TRUE.)
        ZTMPAF(KSTART:KPROF,1:KFLEV)= &
         & ZDELPREV(KSTART:KPROF,1:KFLEV)*PQN(KSTART:KPROF,1:KFLEV)
        CALL ADD_FIELD_3D(ZTMPAF,'VQI','V','ARP',.TRUE.,.TRUE.)
        ZTMPAF(KSTART:KPROF,1:KFLEV)= &
         & ZDELPREV(KSTART:KPROF,1:KFLEV)*PGFL(KSTART:KPROF,1:KFLEV,YR%MP)
        CALL ADD_FIELD_3D(ZTMPAF,'VQR','V','ARP',.TRUE.,.TRUE.)
        ZTMPAF(KSTART:KPROF,1:KFLEV)= &
         & ZDELPREV(KSTART:KPROF,1:KFLEV)*PGFL(KSTART:KPROF,1:KFLEV,YS%MP)
        CALL ADD_FIELD_3D(ZTMPAF,'VQS','V','ARP',.TRUE.,.TRUE.)
        ZTMPAF(KSTART:KPROF,1:KFLEV)= &
         & ZDELPREV(KSTART:KPROF,1:KFLEV)*PGFL(KSTART:KPROF,1:KFLEV,YG%MP)
        CALL ADD_FIELD_3D(ZTMPAF,'VQG','V','ARP',.TRUE.,.TRUE.)
        ZTMPAF(KSTART:KPROF,1:KFLEV)= &
         & ZDELPREV(KSTART:KPROF,1:KFLEV)*PNEB(KSTART:KPROF,1:KFLEV)
        CALL ADD_FIELD_3D(ZTMPAF,'VNT','V','ARP',.TRUE.,.TRUE.)
        ZTMPAF(KSTART:KPROF,1:KFLEV)= &
         & ZDELPREV(KSTART:KPROF,1:KFLEV)*POMEGA(KSTART:KPROF,1:KFLEV)
        CALL ADD_FIELD_3D(ZTMPAF,'VOM','V','ARP',.TRUE.,.TRUE.)
        ZTMPAF(KSTART:KPROF,1:KFLEV)= &
         & ZDELPREV(KSTART:KPROF,1:KFLEV)*PGFL(KSTART:KPROF,1:KFLEV,YTKE%MP)
        CALL ADD_FIELD_3D(ZTMPAF,'VTE','V','ARP',.TRUE.,.TRUE.)
      ELSE
         DO JLEV = 1, KFLEV
          DO JROF=KSTART,KPROF
!           VQL
            PDHCV(JROF,JLEV,IDHCV+9) = PQL(JROF,JLEV)*ZDELPREV(JROF,JLEV)
!           VQI 
            PDHCV(JROF,JLEV,IDHCV+10) = PQN(JROF,JLEV)*ZDELPREV(JROF,JLEV)
!           VQR
            PDHCV(JROF,JLEV,IDHCV+11) = PGFL(JROF,JLEV,YR%MP)*ZDELPREV(JROF,JLEV)
!           VQS
            PDHCV(JROF,JLEV,IDHCV+12) = PGFL(JROF,JLEV,YS%MP)*ZDELPREV(JROF,JLEV)
!           VQG
            PDHCV(JROF,JLEV,IDHCV+13) = PGFL(JROF,JLEV,YG%MP)*ZDELPREV(JROF,JLEV)
!           VNT
            PDHCV(JROF,JLEV,IDHCV+9+NHDQLNVA+NHDPASVA)&
             & =PNEB(JROF,JLEV)*ZDELPREV(JROF,JLEV)  
!           VOM
!            PDHCV(JROF,JLEV,IDHCV+10+NHDQLNVA+NHDPASVA)&
!             & =POMEGA(JROF,JLEV)*ZDELPREV(JROF,JLEV)  
            PDHCV(JROF,JLEV,IDHCV+10+NHDQLNVA+NHDPASVA)=0.0_JPRB
!           VTE
            PDHCV(JROF,JLEV,IDHCV+11+NHDQLNVA+NHDPASVA)&
             & = PGFL(JROF,JLEV,YTKE%MP)*ZDELPREV(JROF,JLEV)
          ENDDO
        ENDDO
      ENDIF
      
    CASE DEFAULT
      IF(LFLEXDIA) THEN
        IF(LHDQLN) THEN
          !VQL
          ZTMPAF(KSTART:KPROF,1:KFLEV)=&
          &ZDELPREV(KSTART:KPROF,1:KFLEV)*PQL(KSTART:KPROF,1:KFLEV)
          CALL ADD_FIELD_3D(ZTMPAF,'VQL','V','ARP',.TRUE.,.TRUE.) 
          !VQN
          ZTMPAF(KSTART:KPROF,1:KFLEV)=&
          &ZDELPREV(KSTART:KPROF,1:KFLEV)*PQN(KSTART:KPROF,1:KFLEV)
          CALL ADD_FIELD_3D(ZTMPAF,'VQN','V','ARP',.TRUE.,.TRUE.) 
        ENDIF
        IF(L3MT.OR.LSTRAPRO) THEN
          !VQR
          ZTMPAF(KSTART:KPROF,1:KFLEV)=&
          &ZDELPREV(KSTART:KPROF,1:KFLEV)*PGFL(KSTART:KPROF,1:KFLEV,YR%MP)
          CALL ADD_FIELD_3D(ZTMPAF,'VQR','V','ARP',.TRUE.,.TRUE.) 
          !VQS
          ZTMPAF(KSTART:KPROF,1:KFLEV)=&
          &ZDELPREV(KSTART:KPROF,1:KFLEV)*PGFL(KSTART:KPROF,1:KFLEV,YS%MP)
          CALL ADD_FIELD_3D(ZTMPAF,'VQS','V','ARP',.TRUE.,.TRUE.) 
        ENDIF

        !VNT
        ZTMPAF(KSTART:KPROF,1:KFLEV)=&
        &ZDELPREV(KSTART:KPROF,1:KFLEV)*PNEB(KSTART:KPROF,1:KFLEV)
        CALL ADD_FIELD_3D(ZTMPAF,'VNT','V','ARP',.TRUE.,.TRUE.) 

        !VOM
        ZTMPAF(KSTART:KPROF,1:KFLEV)=&
        &ZDELPREV(KSTART:KPROF,1:KFLEV)*POMEGA(KSTART:KPROF,1:KFLEV)
        CALL ADD_FIELD_3D(ZTMPAF,'VOM','V','ARP',.TRUE.,.TRUE.) 

      ELSE
      
        DO JLEV = 1, KFLEV
          DO JROF=KSTART,KPROF
            IF(LHDQLN) THEN
!             VQL
              PDHCV(JROF,JLEV,IDHCV+9) = PQL(JROF,JLEV)*ZDELPREV(JROF,JLEV)
!             VQN
              PDHCV(JROF,JLEV,IDHCV+10) = PQN(JROF,JLEV)*ZDELPREV(JROF,JLEV)
              IF ( L3MT.OR.LSTRAPRO )THEN
!               VQR
                PDHCV(JROF,JLEV,IDHCV+11) = &
                &        PGFL(JROF,JLEV,YR%MP)*ZDELPREV(JROF,JLEV)
!               VQS
                PDHCV(JROF,JLEV,IDHCV+12) = &
                &        PGFL(JROF,JLEV,YS%MP)*ZDELPREV(JROF,JLEV)
              ENDIF
            ENDIF     
!           VNT
            PDHCV(JROF,JLEV,IDHCV+9+NHDQLNVA+NHDPASVA)&
             & =PNEB(JROF,JLEV)*ZDELPREV(JROF,JLEV)  
!           VOM
            PDHCV(JROF,JLEV,IDHCV+10+NHDQLNVA+NHDPASVA)&
            & =POMEGA(JROF,JLEV)*ZDELPREV(JROF,JLEV)  
          ENDDO
        ENDDO
      ENDIF !LFLEXDIA
  END SELECT
ENDIF

IF ( LHDMCI ) THEN
  IDHCV=NDHVHK
  DO JLEV=1, KFLEV
    DO JROF=KSTART,KPROF
!     VA1
      PDHCV(JROF,JLEV,IDHCV+1) = ZM1(JROF,JLEV)*ZDELPREV(JROF,JLEV)
!     VA2
      PDHCV(JROF,JLEV,IDHCV+2) = ZM2(JROF,JLEV)*ZDELPREV(JROF,JLEV)
!     VA3
      PDHCV(JROF,JLEV,IDHCV+3) = ZM3(JROF,JLEV)*ZDELPREV(JROF,JLEV)
    ENDDO
  ENDDO
ENDIF

IF ( LHDENT ) THEN
  IDHCV=NDHVHK+NDHVMC
  DO JLEV = 1, KFLEV
    DO JROF=KSTART,KPROF
!     VSS
      PDHCV(JROF,JLEV,IDHCV+1) = ZENTR(JROF,JLEV)*ZDELPREV(JROF,JLEV)
    ENDDO
  ENDDO
ENDIF

!     ------------------------------------------------------------------
!*    2.- CALCUL DES TENDANCES DYNAMIQUES / DYNAMICAL TENDENCIES COMPUTATIONS

! 2.1/
! * Calcul du flux total de precipitations "Fp" sur les intercouches
!   pour traiter le cas "delta m=1".
! * Computation of the total rainfall flux "Fp" on interlayers
!   to treat the case "delta m=1".

IF(NDPSFI == 1)THEN
  DO JLEV = 0, KFLEV
    DO JROF=KSTART,KPROF
      ZFPSUM(JROF,JLEV) =&
       & ( PFPLCL(JROF,JLEV) + PFPLCN(JROF,JLEV)&
       & + PFPLSL(JROF,JLEV) + PFPLSN(JROF,JLEV) )  
    ENDDO
  ENDDO
ELSE
  DO JLEV = 0, KFLEV
    DO JROF=KSTART,KPROF
      ZFPSUM(JROF,JLEV) = 0.0_JPRB
    ENDDO
  ENDDO
ENDIF

! 2.2/
! * Variable intermediaire contenant/intermediate variable containing:
!   lvercor=T: (d prehyd/d eta)*
!    (d(rs**2/a**2)/dt)-(d prehyd/dt)*(d(rs**2/a**2)/d eta)
!   otherwise: zero.

IF (LVERCOR) THEN
! jlev=1
  DO JROF=KSTART,KPROF
!   (D (rs**2/a**2)/Dt)_[l=1]
    ZTENDLAGRSSA2F=2.0_JPRB*ZUSA*PVCRSSAF(JROF,1)*PVCWF(JROF,1)
!   (vec(V) . vnabla (rs**2/a**2))_[l=1]
    ZADVHORRSSA2F=2.0_JPRB*(PU(JROF,1)*PVCRSSAFL(JROF,1)&
     & +PV(JROF,1)*PVCRSSAFM(JROF,1))  
!   (etapt (d(rs**2/a**2)/d eta))_[l=1]
    ZADVVERRSSA2F=PVCRSSAF(JROF,1)*PRDELP(JROF,1)*&
     & (PEVEL(JROF,1)*(PVCRSSAF(JROF,2)-PVCRSSAF(JROF,1))&
     & +2.0_JPRB*PEVEL(JROF,0)*(PVCRSSAF(JROF,1)-PVCRSSAH(JROF,0)))  
!   (d (rs**2/a**2)/dt)_[l=1]
    ZTENDEULRSSA2F=ZTENDLAGRSSA2F-ZADVHORRSSA2F-ZADVVERRSSA2F
!   (Delta prehyd)_[l=1] * (d (rs**2/a**2)/dt)_[l=1]
    ZTERM1=PDELP(JROF,1)*ZTENDEULRSSA2F
!   (grad ((rs/a)*vec(V)*(Delta prehyd)))_[l=1]
    ZDIVDP=PDIVDP(1,1)
!   ((rs**2/a**2) (etapt d prehyd/d eta))_[lbar=1] -
!   ((rs**2/a**2) (etapt d prehyd/d eta))_[top]
    ZDIVVERFLU1=PVCRSSAH(1,1)*PVCRSSAH(1,1)*PEVEL(1,1)&
     & -PVCRSSAH(1,0)*PVCRSSAH(1,0)*PEVEL(JROF,0)  
!   g (Fp)_[lbar=1] - g (Fp)_[top] if ndpsfi=1.
    ZDIVPHYFLU1=RG*ZFPSUM(JROF,1)
!   ( (d prehyd/dt) (rs**2/a**2) )_[lbar=1].
    ZRS2SA2TEPH(JROF,0)=0.0_JPRB
    ZRS2SA2TEPH(JROF,1)=-ZDIVDP-ZDIVVERFLU1-ZDIVPHYFLU1
!   ( (d prehyd/dt) Delta (rs**2/a**2) )_[l=1].
    ZTERM2=ZRS2SA2TEPH(JROF,1)*(1.0_JPRB&
     & -PVCRSSAF(JROF,1)*PVCRSSAF(JROF,1)*PVCASRSH(JROF,1)*PVCASRSH(JROF,1))  
!   (Delta prehyd)_[l=1] * (d (rs**2/a**2)/dt)_[l=1]
!   - ( (d prehyd/dt) Delta (rs**2/a**2) )_[l=1].
    ZVCS(JROF,1)=ZTERM1-ZTERM2
  ENDDO
! jlev=2 a L-1
  DO JLEV=2,KFLEV-1
    DO JROF=KSTART,KPROF
!     (D (rs**2/a**2)/Dt)_[l]
      ZTENDLAGRSSA2F=2.0_JPRB*ZUSA*PVCRSSAF(JROF,JLEV)*PVCWF(JROF,JLEV)
!     (vec(V) . vnabla (rs**2/a**2))_[l]
      ZADVHORRSSA2F=2.0_JPRB*(PU(JROF,JLEV)*PVCRSSAFL(JROF,JLEV)&
       & +PV(JROF,JLEV)*PVCRSSAFM(JROF,JLEV))  
!     (etapt (d(rs**2/a**2)/d eta))_[l]
      ZADVVERRSSA2F=PVCRSSAF(JROF,JLEV)*PRDELP(JROF,JLEV)*&
       & (PEVEL(JROF,JLEV)*(PVCRSSAF(JROF,JLEV+1)-PVCRSSAF(JROF,JLEV))&
       & +PEVEL(JROF,JLEV-1)*(PVCRSSAF(JROF,JLEV)-PVCRSSAF(JROF,JLEV-1)))  
!     (d (rs**2/a**2)/dt)_[l]
      ZTENDEULRSSA2F=ZTENDLAGRSSA2F-ZADVHORRSSA2F-ZADVVERRSSA2F
!     (Delta prehyd)_[l] * (d (rs**2/a**2)/dt)_[l]
      ZTERM1=PDELP(JROF,JLEV)*ZTENDEULRSSA2F
!     (grad ((rs/a)*vec(V)*(Delta prehyd)))_[l]
      ZDIVDP=PDIVDP(JROF,JLEV)
!     ((rs**2/a**2) (etapt d prehyd/d eta))_[lbar] -
!     ((rs**2/a**2) (etapt d prehyd/d eta))_[lbar-1]
      ZDIVVERFLU1=PVCRSSAH(JROF,JLEV)*PVCRSSAH(JROF,JLEV)*PEVEL(JROF,JLEV)&
       & -PVCRSSAH(JROF,JLEV-1)*PVCRSSAH(JROF,JLEV-1)*PEVEL(JROF,JLEV-1)  
!     g (Fp)_[lbar] - g (Fp)_[lbar-1] if ndpsfi=1.
      ZDIVPHYFLU1=RG*(ZFPSUM(JROF,JLEV)-ZFPSUM(JROF,JLEV-1))
!     ( (d prehyd/dt) (rs**2/a**2) )_[lbar].
      ZRS2SA2TEPH(JROF,JLEV)=-ZDIVDP-ZDIVVERFLU1-ZDIVPHYFLU1
!     ( (d prehyd/dt) Delta (rs**2/a**2) )_[l].
      ZTERM2=ZRS2SA2TEPH(JROF,JLEV)*(1.0_JPRB&
       & -PVCRSSAF(JROF,JLEV)*PVCRSSAF(JROF,JLEV)&
       & *PVCASRSH(JROF,JLEV)*PVCASRSH(JROF,JLEV))&
       & -ZRS2SA2TEPH(JROF,JLEV-1)*(1.0_JPRB&
       & -PVCRSSAF(JROF,JLEV)*PVCRSSAF(JROF,JLEV)&
       & *PVCASRSH(JROF,JLEV-1)*PVCASRSH(JROF,JLEV-1))  
!     (Delta prehyd)_[l] * (d (rs**2/a**2)/dt)_[l]
!     - ( (d prehyd/dt) Delta (rs**2/a**2) )_[l].
      ZVCS(JROF,JLEV)=ZTERM1-ZTERM2
    ENDDO
  ENDDO
! jlev=L
  DO JROF=KSTART,KPROF
!   (D (rs**2/a**2)/Dt)_[l=L]
    ZTENDLAGRSSA2F=2.0_JPRB*ZUSA*PVCRSSAF(JROF,KFLEV)*PVCWF(JROF,KFLEV)
!   (vec(V) . vnabla (rs**2/a**2))_[l=L]
    ZADVHORRSSA2F=2.0_JPRB*(PU(JROF,KFLEV)*PVCRSSAFL(JROF,KFLEV)&
     & +PV(JROF,KFLEV)*PVCRSSAFM(JROF,KFLEV))  
!   (etapt (d(rs**2/a**2)/d eta))_[l=L]
    ZADVVERRSSA2F=PVCRSSAF(JROF,KFLEV)*PRDELP(JROF,KFLEV)*&
     & (2.0_JPRB*PEVEL(JROF,KFLEV)*(PVCRSSAH(JROF,KFLEV)-PVCRSSAF(JROF,KFLEV))&
     & +PEVEL(JROF,KFLEV-1)*(PVCRSSAF(JROF,KFLEV)-PVCRSSAF(JROF,KFLEV-1)))  
!   (d (rs**2/a**2)/dt)_[l=L]
    ZTENDEULRSSA2F=ZTENDLAGRSSA2F-ZADVHORRSSA2F-ZADVVERRSSA2F
!   (Delta prehyd)_[l=L] * (d (rs**2/a**2)/dt)_[l=L]
    ZTERM1=PDELP(JROF,KFLEV)*ZTENDEULRSSA2F
!   (grad ((rs/a)*vec(V)*(Delta prehyd)))_[l=L]
    ZDIVDP=PDIVDP(JROF,KFLEV)
!   ((rs**2/a**2) (etapt d prehyd/d eta))_[surf] -
!   ((rs**2/a**2) (etapt d prehyd/d eta))_[lbar=L-1]
    ZDIVVERFLU1=PVCRSSAH(JROF,KFLEV)*PVCRSSAH(JROF,KFLEV)*PEVEL(JROF,KFLEV)&
     & -PVCRSSAH(JROF,KFLEV-1)*PVCRSSAH(JROF,KFLEV-1)*PEVEL(JROF,KFLEV-1)  
!   g (Fp)_[surf] - g (Fp)_[lbar=L-1] if ndpsfi=1.
    ZDIVPHYFLU1=RG*(ZFPSUM(JROF,KFLEV)-ZFPSUM(JROF,KFLEV-1))
!   ( (d prehyd/dt) (rs**2/a**2) )_[surf].
    ZRS2SA2TEPH(JROF,KFLEV)=-ZDIVDP-ZDIVVERFLU1-ZDIVPHYFLU1
!   ( (d prehyd/dt) Delta (rs**2/a**2) )_[l=L].
    ZTERM2=ZRS2SA2TEPH(JROF,KFLEV)*(1.0_JPRB&
     & -PVCRSSAF(JROF,KFLEV)*PVCRSSAF(JROF,KFLEV)&
     & *PVCASRSH(JROF,KFLEV)*PVCASRSH(JROF,KFLEV))&
     & -ZRS2SA2TEPH(JROF,KFLEV-1)*(1.0_JPRB&
     & -PVCRSSAF(JROF,KFLEV)*PVCRSSAF(JROF,KFLEV)&
     & *PVCASRSH(JROF,KFLEV-1)*PVCASRSH(JROF,KFLEV-1))  
!   (Delta prehyd)_[l=L] * (d (rs**2/a**2)/dt)_[l=L]
!   - ( (d prehyd/dt) Delta (rs**2/a**2) )_[l=L].
    ZVCS(JROF,KFLEV)=ZTERM1-ZTERM2
  ENDDO
ELSE
  ZVCS(KSTART:KPROF,1:KFLEV)=0.0_JPRB
ENDIF

! 2.3/
! * Calcul sur les couches de/ computation at full levels of:
!    lvercor=T: " - (1/g) grad { (rs/a) vec(V) X (Delta prehyd) } "
!    lrwsdlr=T: " - (1/g) [ (a/r) grad { (a/r) vec(V) (Delta presim) } X
!               + (a/r) (Delta presim) vec(V) grad(X) ]
!    otherwise: " - (1/g) grad { vec(V) X (Delta prehyd) } "
!    for X = 1; q; Ugeo; Vgeo; (U**2+V**2)/2; cp*T; g*z; ql; qi; M1; M2; M3; S.
!    (remark for lvercor=T: additional terms
!    " - (1/g) X (d prehyd/d t) (d (rs**2/a**2)/d eta) "
!    and " (1/g) X (d prehyd/d eta) (d (rs**2/a**2)/d t) "
!    are not diagnosed separately but added to the term
!    " - (1/g) grad { (rs/a) vec(V) X (Delta prehyd) } ")
!   Calcul sur les couches de/ computation at full levels of:
!    lvercor=T: " - (1/g) (rs**2/a**2) (Delta prehyd) (DX/Dt)_adiab "
!    lrwsdlr=T: " - (1/g) (Delta presim) (DX/Dt)_adiab "
!    otherwise: " - (1/g) (Delta prehyd) (DX/Dt)_adiab "
!    for X = Ugeo; Vgeo; 0.5*(U**2+V**2); cp*T; M1; M2; M3.

! 2.3.1/
! -- Variables "X" autres que "M1", "M2", "M3" et "S".
!    Variables "X" other than "M1", "M2", "M3" and "S".

IF ( LHDHKS ) THEN
  IDHCV=NDHVV

! 2.3.1.1/
! RHS de l'equation du vent horizontal.
! RHS for horizontal wind equation.

  ZRHSU(KSTART:KPROF,1:KFLEV)=0.0_JPRB
  ZRHSV(KSTART:KPROF,1:KFLEV)=0.0_JPRB

! 2.3.1.1.a/ terme de gradient de pression / pressure gradient term.

  IF (LVERCOR) THEN
    ZRHSU(KSTART:KPROF,1:KFLEV)=ZRHSU(KSTART:KPROF,1:KFLEV) &
     & -PVCASRSF(KSTART:KPROF,1:KFLEV)*PSGRTL(KSTART:KPROF,1:KFLEV)  
    ZRHSV(KSTART:KPROF,1:KFLEV)=ZRHSV(KSTART:KPROF,1:KFLEV) &
     & -PVCASRSF(KSTART:KPROF,1:KFLEV)*PSGRTM(KSTART:KPROF,1:KFLEV)  
  ELSEIF (LRWSDLR) THEN
    ZRHSU(KSTART:KPROF,1:KFLEV)=ZRHSU(KSTART:KPROF,1:KFLEV) &
     & -PRDLR(KSTART:KPROF,1:KFLEV,JP_ASRF)*PSGRTL(KSTART:KPROF,1:KFLEV)  
    ZRHSV(KSTART:KPROF,1:KFLEV)=ZRHSV(KSTART:KPROF,1:KFLEV) &
     & -PRDLR(KSTART:KPROF,1:KFLEV,JP_ASRF)*PSGRTM(KSTART:KPROF,1:KFLEV)  
  ELSE
    ZRHSU(KSTART:KPROF,1:KFLEV)=ZRHSU(KSTART:KPROF,1:KFLEV) &
     & -PSGRTL(KSTART:KPROF,1:KFLEV)  
    ZRHSV(KSTART:KPROF,1:KFLEV)=ZRHSV(KSTART:KPROF,1:KFLEV) &
     & -PSGRTM(KSTART:KPROF,1:KFLEV)  
  ENDIF

! 2.3.1.1.b/ "- 2 vec(Omega) wedge W vec(k)" or "- 2 vec(Omega) wedge w vec(k)"
!            if relevant.

  IF (LVERCOR) THEN
    DO JLEV = 1, KFLEV
      ZRHSU(KSTART:KPROF,JLEV)=ZRHSU(KSTART:KPROF,JLEV) &
       & -PNORDM(KSTART:KPROF)* &
       & PRCORIC(KSTART:KPROF)*PVCWF(KSTART:KPROF,JLEV)  
      ZRHSV(KSTART:KPROF,JLEV)=ZRHSV(KSTART:KPROF,JLEV) &
       & +PNORDL(KSTART:KPROF)* &
       & PRCORIC(KSTART:KPROF)*PVCWF(KSTART:KPROF,JLEV)  
    ENDDO
  ELSEIF (LRWSDLW) THEN
    DO JLEV = 1, KFLEV
      ZRHSU(KSTART:KPROF,JLEV)=ZRHSU(KSTART:KPROF,JLEV) &
       & -PNORDM(KSTART:KPROF)* &
       & PRCORIC(KSTART:KPROF)*PWDLWF(KSTART:KPROF,JLEV)  
      ZRHSV(KSTART:KPROF,JLEV)=ZRHSV(KSTART:KPROF,JLEV) &
       & +PNORDL(KSTART:KPROF)* &
       & PRCORIC(KSTART:KPROF)*PWDLWF(KSTART:KPROF,JLEV)  
    ENDDO
  ENDIF

! 2.3.1.1.c/ "- (W/rs) vec(V)" or "- (w/r) vec(V)" if relevant.

  IF (.NOT.LSLAG) THEN
    IF (LVERCOR) THEN
      ZRHSU(KSTART:KPROF,1:KFLEV)=ZRHSU(KSTART:KPROF,1:KFLEV) &
       & -ZUSA*PVCASRSF(KSTART:KPROF,1:KFLEV)*PVCWF(KSTART:KPROF,1:KFLEV) &
       & *PU(KSTART:KPROF,1:KFLEV)  
      ZRHSV(KSTART:KPROF,1:KFLEV)=ZRHSV(KSTART:KPROF,1:KFLEV) &
       & -ZUSA*PVCASRSF(KSTART:KPROF,1:KFLEV)*PVCWF(KSTART:KPROF,1:KFLEV) &
       & *PV(KSTART:KPROF,1:KFLEV)  
    ELSEIF (LRWSDLW.AND.(.NOT.LRWSDLR)) THEN
      ZRHSU(KSTART:KPROF,1:KFLEV)=ZRHSU(KSTART:KPROF,1:KFLEV) &
       & -ZUSA*PWDLWF(KSTART:KPROF,1:KFLEV)*PU(KSTART:KPROF,1:KFLEV)  
      ZRHSV(KSTART:KPROF,1:KFLEV)=ZRHSV(KSTART:KPROF,1:KFLEV) &
       & -ZUSA*PWDLWF(KSTART:KPROF,1:KFLEV)*PV(KSTART:KPROF,1:KFLEV)  
    ELSEIF (LRWSDLW.AND.LRWSDLR) THEN
      ZRHSU(KSTART:KPROF,1:KFLEV)=ZRHSU(KSTART:KPROF,1:KFLEV) &
       & -ZUSA*PRDLR(KSTART:KPROF,1:KFLEV,JP_ASRF) &
       & *PWDLWF(KSTART:KPROF,1:KFLEV)*PU(KSTART:KPROF,1:KFLEV)  
      ZRHSV(KSTART:KPROF,1:KFLEV)=ZRHSV(KSTART:KPROF,1:KFLEV) &
       & -ZUSA*PRDLR(KSTART:KPROF,1:KFLEV,JP_ASRF) &
       & *PWDLWF(KSTART:KPROF,1:KFLEV)*PV(KSTART:KPROF,1:KFLEV)  
    ENDIF
  ENDIF

! 2.3.1.1.d/ Passer dans un repere local dont l'ordonnee pointe vers le vrai PN.
!            Convert to a local repere, the ordinate of which is directed to PN.

  DO JLEV = 1, KFLEV
    ZRHSZO(KSTART:KPROF)=PNORDM(KSTART:KPROF)*ZRHSU(KSTART:KPROF,JLEV)&
     & -PNORDL(KSTART:KPROF)*ZRHSV(KSTART:KPROF,JLEV)  
    ZRHSME(KSTART:KPROF)=PNORDL(KSTART:KPROF)*ZRHSU(KSTART:KPROF,JLEV)&
     & +PNORDM(KSTART:KPROF)*ZRHSV(KSTART:KPROF,JLEV)  
    ZRHSU(KSTART:KPROF,JLEV)=ZRHSZO(KSTART:KPROF)
    ZRHSV(KSTART:KPROF,JLEV)=ZRHSME(KSTART:KPROF)
  ENDDO

! 2.3.1.1.e/ ajouter/add "- 2 vec(Omega) wedge vec(V)"

  DO JLEV = 1, KFLEV
    ZRHSU(KSTART:KPROF,JLEV)=ZRHSU(KSTART:KPROF,JLEV) &
     & +PRCORI(KSTART:KPROF)*PVM(KSTART:KPROF,JLEV)  
    ZRHSV(KSTART:KPROF,JLEV)=ZRHSV(KSTART:KPROF,JLEV) &
     & -PRCORI(KSTART:KPROF)*PUZ(KSTART:KPROF,JLEV)  
  ENDDO

! 2.3.1.2/
! RHS de l'equation de l'energie cinetique.
! RHS for kinetic energy equation.

  ZRHSK(KSTART:KPROF,1:KFLEV)=0.0_JPRB

! 2.3.1.2.a/ terme de gradient de pression / pressure gradient term.

  IF (LVERCOR) THEN
    ZRHSK(KSTART:KPROF,1:KFLEV)=ZRHSK(KSTART:KPROF,1:KFLEV) &
     & +PVCASRSF(KSTART:KPROF,1:KFLEV)* &
     & (-PU(KSTART:KPROF,1:KFLEV)*PSGRTL(KSTART:KPROF,1:KFLEV) &
     & -PV(KSTART:KPROF,1:KFLEV)*PSGRTM(KSTART:KPROF,1:KFLEV))  
  ELSEIF (LRWSDLR) THEN
    ZRHSK(KSTART:KPROF,1:KFLEV)=ZRHSK(KSTART:KPROF,1:KFLEV) &
     & +PRDLR(KSTART:KPROF,1:KFLEV,JP_ASRF)* &
     & (-PU(KSTART:KPROF,1:KFLEV)*PSGRTL(KSTART:KPROF,1:KFLEV) &
     & -PV(KSTART:KPROF,1:KFLEV)*PSGRTM(KSTART:KPROF,1:KFLEV))  
  ELSE
    ZRHSK(KSTART:KPROF,1:KFLEV)=ZRHSK(KSTART:KPROF,1:KFLEV) &
     & -PU(KSTART:KPROF,1:KFLEV)*PSGRTL(KSTART:KPROF,1:KFLEV) &
     & -PV(KSTART:KPROF,1:KFLEV)*PSGRTM(KSTART:KPROF,1:KFLEV)  
  ENDIF

! 2.3.1.2.b/ "g W mu_s" ("lvercor=T" seulement/only).

  IF (LVERCOR) THEN
    ZRHSK(KSTART:KPROF,1:KFLEV)=ZRHSK(KSTART:KPROF,1:KFLEV) &
     & +RG*PVCWF(KSTART:KPROF,1:KFLEV)*PVCMUSF(KSTART:KPROF,1:KFLEV)  
  ENDIF

! 2.3.1.3/
! Le calcul et stockage des divergences de flux.
! Computation and storage of flux divergences.

! 2.3.1.3.a/ "X"=1.

  DO JLEV = 1, KFLEV
    DO JROF=KSTART,KPROF
!     TPPDIVFLUHOR
      PDHCV(JROF,JLEV,IDHCV+1) = ZUSRG*(ZVCS(JROF,JLEV)-PDIVDP(JROF,JLEV))
    ENDDO
  ENDDO

! 2.3.1.3.b/ "X"=q.

  DO JLEV = 1, KFLEV
    DO JROF=KSTART,KPROF
!     TQVDIVFLUHOR
      IF(YQ%LCDERS) THEN
        ZADVQV =  PU(JROF,JLEV)*PQVL(JROF,JLEV)+PV(JROF,JLEV)*PQVM(JROF,JLEV)
      ELSE
        ZADVQV = 0.0_JPRB
      ENDIF
      PDHCV(JROF,JLEV,IDHCV+2) = ZUSRG*(PQV(JROF,JLEV)*&
       & (ZVCS(JROF,JLEV)-PDIVDP(JROF,JLEV))-ZZDELP(JROF,JLEV)*ZADVQV)  
    ENDDO
  ENDDO

! 2.3.1.3.c/ "X"=vec(V).

  DO JLEV = 1, KFLEV
    DO JROF=KSTART,KPROF
!     TUUDIVFLUHOR
      PDHCV(JROF,JLEV,IDHCV+3) = ZUSRG*(PUZ(JROF,JLEV)*&
       & (ZVCS(JROF,JLEV)-PDIVDP(JROF,JLEV))-ZZDELP(JROF,JLEV)*&
       & (PNORDM(JROF)*ZGKEU(JROF,JLEV)-PNORDL(JROF)*ZGKEV(JROF,JLEV)))  
!     TVVDIVFLUHOR
      PDHCV(JROF,JLEV,IDHCV+4) = ZUSRG*(PVM(JROF,JLEV)*&
       & (ZVCS(JROF,JLEV)-PDIVDP(JROF,JLEV))-ZZDELP(JROF,JLEV)*&
       & (PNORDL(JROF)*ZGKEU(JROF,JLEV)+PNORDM(JROF)*ZGKEV(JROF,JLEV)))  
!     TUUFFVGADPSG
      PDHCV(JROF,JLEV,IDHCV+5) = ZDELPREV(JROF,JLEV)*ZUSRG*ZRHSU(JROF,JLEV)
!     TUUFFVGADPSG
      PDHCV(JROF,JLEV,IDHCV+6) = ZDELPREV(JROF,JLEV)*ZUSRG*ZRHSV(JROF,JLEV)
    ENDDO
  ENDDO

! 2.3.1.3.d/ "X"= 0.5 (U**2+V**2).

  DO JLEV = 1, KFLEV
    DO JROF=KSTART,KPROF
!     TKKDIVFLUHOR
      PDHCV(JROF,JLEV,IDHCV+7) = ZUSRG*(PKENE(JROF,JLEV)*&
       & (ZVCS(JROF,JLEV)-PDIVDP(JROF,JLEV))-ZZDELP(JROF,JLEV)*&
       & (ZGKEU(JROF,JLEV)*PU(JROF,JLEV)+ZGKEV(JROF,JLEV)*PV(JROF,JLEV)))  
!     TKKCONVERSI1
      PDHCV(JROF,JLEV,IDHCV+8) = ZDELPREV(JROF,JLEV)*ZUSRG*ZRHSK(JROF,JLEV)
    ENDDO
  ENDDO

! 2.3.1.3.e/ "X"= cp*T.

  DO JLEV = 1, KFLEV
    DO JROF=KSTART,KPROF
!     TCTDIVFLUHOR
      IF(YQ%LCDERS) THEN
        ZADVQV =  PU(JROF,JLEV)*PQVL(JROF,JLEV)+PV(JROF,JLEV)*PQVM(JROF,JLEV)
      ELSE
        ZADVQV = 0.0_JPRB
      ENDIF
      ZADVT =  PU(JROF,JLEV)*PTL(JROF,JLEV) +PV(JROF,JLEV)*PTM(JROF,JLEV)
      PDHCV(JROF,JLEV,IDHCV+9) = ZUSRG*(ZCPT(JROF,JLEV)*&
       & (ZVCS(JROF,JLEV)-PDIVDP(JROF,JLEV))-ZZDELP(JROF,JLEV)*&
       & (PCP(JROF,JLEV)*ZADVT+PT(JROF,JLEV)*ZCVMCD*ZADVQV))  
!     TCTCONVERSI2
      PDHCV(JROF,JLEV,IDHCV+10) = ZDELPREV(JROF,JLEV)*ZUSRG*&
       & Z_CP_TIMES_CONV(JROF,JLEV)  
    ENDDO
  ENDDO
  IF(NDPSFI == 1) THEN
    ! K.Y.: this code does not seem to have been properly updated
    !       relatively to the last modifications of the "delta m=1"
    !       formulation (introduced in cy29t3).
    DO JLEV = 2, KFLEV-1
      DO JROF=KSTART,KPROF
!       TCTCONVERSI3 for layers 2 to L-1 if "ndpsfi=1".
        PDHCV(JROF,JLEV,IDHCV+11) =&
         & 0.5_JPRB*(ZFPSUM(JROF,JLEV)+ZFPSUM(JROF,JLEV-1))&
         & *(PAPHI(JROF,JLEV)-PAPHI(JROF,JLEV-1)&
         & +0.5_JPRB*(PKENE(JROF,JLEV+1)-PKENE(JROF,JLEV-1)))  
      ENDDO
    ENDDO
    DO JROF=KSTART,KPROF
!     TCTCONVERSI3 for layer l=1 if "ndpsfi=1".
      PDHCV(JROF,1,IDHCV+11) =0.5_JPRB*ZFPSUM(JROF,1)&
       & *(PAPHI(JROF,1)-PAPHI(JROF,0)&
       & +PKENE(JROF,2)-PKENE(JROF,1))  
!     TCTCONVERSI3 for layer l=L if "ndpsfi=1".
      PDHCV(JROF,KFLEV,IDHCV+11) =&
       & 0.5_JPRB*(ZFPSUM(JROF,KFLEV)+ZFPSUM(JROF,KFLEV-1))&
       & *(PAPHI(JROF,KFLEV)-PAPHI(JROF,KFLEV-1)&
       & -2.0_JPRB*PKENE(JROF,KFLEV))  
    ENDDO
  ELSE
    DO JLEV = 1, KFLEV
      DO JROF=KSTART,KPROF
!       TCTCONVERSI3 if "ndpsfi=0".
        PDHCV(JROF,JLEV,IDHCV+11) = 0.0_JPRB
      ENDDO
    ENDDO
  ENDIF

! 2.3.1.3.f/ "X"= gz.

  DO JLEV = 1, KFLEV
    DO JROF=KSTART,KPROF
!     TEPDIVFLUHOR
!     On suppose que c'est "cp*T + gz + 0.5*(U**2+V**2)" qui est la
!     quantite energetique conservee, donc on a besoin de calculer la
!     divergence des flux horizontaux et le gradient horizontal de "gz".
!     One assumes that the energetic quantity which is conserved is
!     "cp*T + gz + 0.5*(U**2+V**2)", so one has to compute the
!     horizontal flux divergence and the horizontal gradient of "gz".
      ZADPHI=PU(JROF,JLEV)*PAPHIFL(JROF,JLEV)+PV(JROF,JLEV)*PAPHIFM(JROF,JLEV)
      PDHCV(JROF,JLEV,IDHCV+12) = ZUSRG*(PAPHIF(JROF,JLEV)*&
       & (ZVCS(JROF,JLEV)-PDIVDP(JROF,JLEV))-ZZDELP(JROF,JLEV)*ZADPHI)  
    ENDDO
  ENDDO

! 2.3.1.3.g/ "X"= 1 (addendum).

  IF (LFLEXDIA) THEN
    ZTMPAF(KSTART:KPROF,1:KFLEV)=ZDELPREV(KSTART:KPROF,1:KFLEV)*ZUSRG
    CALL ADD_FIELD_3D(ZTMPAF,'PPP','T','ARP',.TRUE.,.TRUE.)
  ELSE
    DO JLEV = 1, KFLEV
      DO JROF=KSTART,KPROF
!       PPP
        PDHCV(JROF,JLEV,IDHCV+13) = ZDELPREV(JROF,JLEV)*ZUSRG
      ENDDO
    ENDDO
  ENDIF


! 2.3.1.3.h/ "X"= ql.

  IF(LHDQLN) THEN
    DO JLEV = 1, KFLEV
      DO JROF=KSTART,KPROF
!       TQLDIVFLUHOR
        IF(YL%LCDERS) THEN
          ZADVQL =  PU(JROF,JLEV)*PQLL(JROF,JLEV)+&
           & PV(JROF,JLEV)*PQLM(JROF,JLEV)  
        ELSE
          ZADVQL=0.0_JPRB
        ENDIF
        PDHCV(JROF,JLEV,IDHCV+14) = ZUSRG*(PQL(JROF,JLEV)*&
         & (ZVCS(JROF,JLEV)-PDIVDP(JROF,JLEV))-ZZDELP(JROF,JLEV)*ZADVQL)  
      ENDDO
    ENDDO
  ENDIF

! 2.3.1.3.i/ "X"= qi.

  IF(LHDQLN) THEN
    DO JLEV = 1, KFLEV
      DO JROF=KSTART,KPROF
!       TQNDIVFLUHOR
        IF(YI%LCDERS) THEN
          ZADVQN =  PU(JROF,JLEV)*PQNL(JROF,JLEV)+&
           & PV(JROF,JLEV)*PQNM(JROF,JLEV)  
        ELSE
          ZADVQN=0.0_JPRB
        ENDIF
        PDHCV(JROF,JLEV,IDHCV+15) = ZUSRG*(PQN(JROF,JLEV)*&
         & (ZVCS(JROF,JLEV)-PDIVDP(JROF,JLEV))-ZZDELP(JROF,JLEV)*ZADVQN)  
      ENDDO
    ENDDO
  ENDIF

ENDIF

! 2.3.2/
! -- Variables "X" = "M1", "M2", "M3".
!    Variables "X" = "M1", "M2", "M3".

IF ( LHDMCI ) THEN

! * Remarque: partie non remise a jour pour les equations en couche epaisse 
!   (code peu comprehensible et semblant eloigne des
!   equations, et peu d'utilisateurs declares) et non adaptee au NH.
!   Avec l'hypothese de couche mince on devrait voir code:
!    [D vec(MT) / Dt]_adiab = a * ( vec(V) wedge ( vec(Omega) wedge vec(k) )
!    - vec(k) wedge ( vec(Omega) wedge vec(V) ) )
!    + a vec(k) * ( - vnabla Phi - RT * (vnabla prehyd / prehyd) )
!   En couche epaisse type "lvercor=T", ca conduit a l'expression:
!    [D vec(MT) / Dt]_adiab = rs * ( vec(V) wedge ( vec(Omega) wedge vec(k) )
!    - vec(k) wedge ( vec(Omega) wedge vec(V) ) )
!    + rs vec(k) * (- vnabla Phi - (RT + mu_s Rd Ts) * (vnabla prehyd / prehyd))
!   Etude non faite avec "lrwsdlr=T".
! * Remark: code not updated for deep layer equations.
! * Code not updated for NH model.

  IDHCV=NDHVV+NDHAHKD
  DO JLEV = 1, KFLEV
    DO JROF=KSTART,KPROF
!     DIVERGENCE OF ANGULAR MOMENTUM
!       Only the term M div(v delta p) is computed, the remaining term
!       delta p v.grad M can be computed as soon as the gradient of velocity
!       is available.

!     grad deltaP ON THE REAL SPHERE
      ZDPREZ = VDELB(JLEV)*(PNORDM(JROF)*PSPL(JROF)-PNORDL(JROF)*PSPM(JROF))
      ZDPREM = VDELB(JLEV)*(PNORDL(JROF)*PSPL(JROF)+PNORDM(JROF)*PSPM(JROF))

      PDHCV(JROF,JLEV,IDHCV+1) = - ZUSRG * ZM1(JROF,JLEV)*&
       & (PDIVDP(JROF,JLEV)+ZDPREZ*RA*ROMEGA*PCLAT(JROF))  
      PDHCV(JROF,JLEV,IDHCV+2) = - ZUSRG * ZM2(JROF,JLEV)*&
       & (PDIVDP(JROF,JLEV)+ZDPREZ*RA*ROMEGA*PCLAT(JROF))  
      PDHCV(JROF,JLEV,IDHCV+3) = -ZUSRG * ZM3(JROF,JLEV)*&
       & (PDIVDP(JROF,JLEV)+ZDPREZ*RA*ROMEGA*PCLAT(JROF))  
!     ANGULAR MOMENTUM TENDENCY DUE TO ADJUSTMENT
      PDHCV(JROF,JLEV,IDHCV+4) = ZUSRG * RA * (&
       & - ZSLON(JROF)*(PDELP(JROF,JLEV)*ZRTMER(JROF,JLEV)+&
       & PRR(JROF,JLEV)*PT(JROF,JLEV)*ZDPREM)&
       & + ZCLON(JROF)*PSLAT(JROF)*(PDELP(JROF,JLEV)*ZRTZON(JROF,&
       & JLEV)+&
       & PRR(JROF,JLEV)*PT(JROF,JLEV)*ZDPREZ) )  
      PDHCV(JROF,JLEV,IDHCV+5) = ZUSRG * RA * (&
       & ZCLON(JROF)*(PDELP(JROF,JLEV)*ZRTMER(JROF,JLEV)+&
       & PRR(JROF,JLEV)*PT(JROF,JLEV)*ZDPREM)&
       & + ZSLON(JROF)*PSLAT(JROF)*(PDELP(JROF,JLEV)*ZRTZON(JROF,&
       & JLEV)+&
       & PRR(JROF,JLEV)*PT(JROF,JLEV)*ZDPREZ) )  
      PDHCV(JROF,JLEV,IDHCV+6) = ZUSRG * RA *&
       & PCLAT(JROF)*(-PDELP(JROF,JLEV)*ZRTZON(JROF,JLEV)-&
       & PRR(JROF,JLEV)*PT(JROF,JLEV)*ZDPREZ)  
!     NONAXIAL MOMENTS TENDENCY
      PDHCV(JROF,JLEV,IDHCV+7) =   ZUSRG*PDELP(JROF,JLEV)*RA**2 *&
       & ROMEGA**2 *PSLAT(JROF)*PCLAT(JROF)*ZSLON(JROF)  
      PDHCV(JROF,JLEV,IDHCV+8) = - ZUSRG*PDELP(JROF,JLEV)*RA**2 *&
       & ROMEGA**2 *PSLAT(JROF)*PCLAT(JROF)*ZCLON(JROF)  
    ENDDO
  ENDDO
ENDIF

! 2.3.3/
! -- Variable "X" = "S".

IF ( LHDENT ) THEN
  IDHCV=NDHVV+NDHAHKD+NDHAMCD

  DO JLEV = 1, KFLEV
    DO JROF=KSTART,KPROF
!     HORIZONTAL DIVERGENCE OF ENTROPY
      IF(YQ%LCDERS) THEN
        ZADVQV =  PU(JROF,JLEV)*PQVL(JROF,JLEV)+PV(JROF,JLEV)*PQVM(JROF,JLEV)
      ELSE
        ZADVQV = 0.0_JPRB
      ENDIF
      ZADVLNT =  (PU(JROF,JLEV)*PTL(JROF,JLEV) +&
       & PV(JROF,JLEV)*PTM(JROF,JLEV))/PT(JROF,JLEV)  
      ZADVP = PU(JROF,JLEV)*(PRTGR(JROF,JLEV)*PSPL(JROF)+ZQCHAL(JROF,JLEV)) &
       & +PV(JROF,JLEV)*(PRTGR(JROF,JLEV)*PSPM(JROF)+ZQCHAM(JROF,JLEV))
      PDHCV(JROF,JLEV,IDHCV+1)= ZUSRG*(ZENTR(JROF,JLEV)*&
       & (ZVCS(JROF,JLEV)-PDIVDP(JROF,JLEV))&
       & -ZZDELP(JROF,JLEV)*((PENTRV(JROF,JLEV)-PENTRA(JROF,JLEV))*&
       & ZADVQV+PCP(JROF,JLEV)*ZADVLNT-PRR(JROF,JLEV)*ZADVP))  
    ENDDO
  ENDDO

! TENDENCY OF ENTROPY DUE TO TRANSPORT OF ENERGY BY PRECIPITATION
  IF (NDPSFI == 1) THEN
    ! K.Y.: this code does not seem to have been properly updated
    !       relatively to the last modifications of the "delta m=1"
    !       formulation (introduced in cy29t3).
    DO JLEV = 1, KFLEV
      DO JROF=KSTART,KPROF
        PDHCV(JROF,JLEV,IDHCV+2) = &
         & -(ZFPTOT(JROF,JLEV)+ZFPTOT(JROF,JLEV-1)) *&
         & (PAPHI(JROF,JLEV)-PAPHI(JROF,JLEV-1))/(2.0_JPRB*PT(JROF,JLEV))  
      ENDDO
    ENDDO
  ELSE
    DO JLEV = 1, KFLEV
      DO JROF=KSTART,KPROF
        PDHCV(JROF,JLEV,IDHCV+2) = &
         & ( PENTRA(JROF,JLEV)*(ZFPTOT(JROF,JLEV)-ZFPTOT(JROF,JLEV-1))&
         & + RCPD*0.5_JPRB*ZDELLT(JROF,JLEV)*&
         & (ZFPTOT(JROF,JLEV)+ZFPTOT(JROF,JLEV-1)) )  
      ENDDO
    ENDDO
  ENDIF

ENDIF

!     ------------------------------------------------------------------
!*    3.- CALCUL DES FLUX VERTICAUX DYNAMIQUES
!         DYNAMICAL VERTICAL FLUXES COMPUTATIONS

! * Calcul sur les intercouches de/ computation at half levels of:
!    lvercor=T: " (1/g) X (rs**2/a**2) etapt (d prehyd / d eta) "
!    lrwsdlr=T: " (1/g) X etapt (d presim / d eta) "
!    otherwise: " (1/g) X etapt (d prehyd / d eta) "
!   for X = 1; q; Ugeo; Vgeo; (U**2+V**2)/2; cp*T; ql; qi; M1; M2; M3; S.

! 3.1/
! -- Variables "X" autres que "M1", "M2", "M3" et "S".
!    Variables "X" other than "M1", "M2", "M3" and "S".

IF ( LHDHKS ) THEN
  IDHCV=NDHVV + NDHAVD

! * CONDITION A LA LIMITE INFERIEURE / BOTTOM BOUNDARY CONDITION

!   Hypotheses faites ici / Assumptions for bottom values:
!   (U,V)_[bottom]=(U,V)_[l=L]
!   T_[bottom]=T_[surf]; cp_[bottom]=cpd+(cpv-cpd)*q_[surf]
!   q_[bottom]=q_[surf]; ql_[bottom]=ql_[l=L]; qi_[bottom]=qi_[l=L]

  DO JROF=KSTART,KPROF
!   FPPFLUVERTDYN
    PDHCV(JROF,KFLEV,IDHCV+1) = ZRS2SA2EVELH(JROF,KFLEV)*ZUSRG
!   FQVFLUVERTDYN
    PDHCV(JROF,KFLEV,IDHCV+2) = ZRS2SA2EVELH(JROF,KFLEV)*PQVS(JROF)*ZUSRG
!   FUUFLUVERTDYN
    PDHCV(JROF,KFLEV,IDHCV+3) = 0.0_JPRB
!   FVVFLUVERTDYN
    PDHCV(JROF,KFLEV,IDHCV+4) = 0.0_JPRB
!   FUUFLUDUAPLUI
    PDHCV(JROF,KFLEV,IDHCV+5) = 0.0_JPRB
!   FVVFLUDUAPLUI
    PDHCV(JROF,KFLEV,IDHCV+6) = 0.0_JPRB
!   FKKFLUVERTDYN
    PDHCV(JROF,KFLEV,IDHCV+7) = 0.0_JPRB
!   FKKFLUDUAPLUI
    PDHCV(JROF,KFLEV,IDHCV+8) = 0.0_JPRB
!   FCTFLUVERTDYN
    PDHCV(JROF,KFLEV,IDHCV+9) = ZRS2SA2EVELH(JROF,KFLEV)*&
     & (RCPD + ZCVMCD*PQVS(JROF))*PTSFC(JROF)*ZUSRG  
!   FEPCONVERSIFL
    PDHCV(JROF,KFLEV,IDHCV+10) = - PAPHI(JROF,KFLEV)*PSDIV(JROF,KFLEV)*ZUSRG
    IF(LHDQLN) THEN
!     FQLFLUVERTDYN
      PDHCV(JROF,KFLEV,IDHCV+11) = 0.0_JPRB
!     FQNFLUVERTDYN
      PDHCV(JROF,KFLEV,IDHCV+12) = 0.0_JPRB
    ENDIF
  ENDDO

! * INTERNIVEAUX NORMAUX / HALF LEVELS

  ZUS2RG = 0.5_JPRB*ZUSRG
  ZPFIS2 = 0.5_JPRB*ZDPSFI
  ! K.Y.: lines containing "ZDPSFI":
  !       this code does not seem to have been properly updated
  !       relatively to the last modifications of the "delta m=1"
  !       formulation (introduced in cy29t3).
  DO JLEV = 1, KFLEV-1
    DO JROF=KSTART,KPROF
!     FPPFLUVERTDYN
      PDHCV(JROF,JLEV,IDHCV+1) = ZRS2SA2EVELH(JROF,JLEV)*ZUSRG
!     FQVFLUVERTDYN
      PDHCV(JROF,JLEV,IDHCV+2) = ZUS2RG*( PQV(JROF,JLEV)+&
       & PQV(JROF,JLEV+1) )*ZRS2SA2EVELH(JROF,JLEV)  
!     FUUFLUVERTDYN
      PDHCV(JROF,JLEV,IDHCV+3) = ZUS2RG*( PUZ(JROF,JLEV)+&
       & PUZ(JROF,JLEV+1) )*ZRS2SA2EVELH(JROF,JLEV)  
!     FVVFLUVERTDYN
      PDHCV(JROF,JLEV,IDHCV+4) = ZUS2RG*( PVM(JROF,JLEV)+&
       & PVM(JROF,JLEV+1) )*ZRS2SA2EVELH(JROF,JLEV)  
!     FUUFLUDUAPLUI
      PDHCV(JROF,JLEV,IDHCV+5) = ZPFIS2*( PUZ(JROF,JLEV)+&
       & PUZ(JROF,JLEV+1) )*ZFPSUM(JROF,JLEV)  
!     FVVFLUDUAPLUI
      PDHCV(JROF,JLEV,IDHCV+6) = ZPFIS2*( PVM(JROF,JLEV)+&
       & PVM(JROF,JLEV+1) )*ZFPSUM(JROF,JLEV)  
!     FKKFLUVERTDYN
      PDHCV(JROF,JLEV,IDHCV+7) = ZUS2RG*( PKENE(JROF,JLEV)+&
       & PKENE(JROF,JLEV+1) )*ZRS2SA2EVELH(JROF,JLEV)  
!     FKKFLUDUAPLUI
      PDHCV(JROF,JLEV,IDHCV+8) = ZPFIS2*( PKENE(JROF,JLEV)+&
       & PKENE(JROF,JLEV+1) )*ZFPSUM(JROF,JLEV)  
!     FCTFLUVERTDYN
      PDHCV(JROF,JLEV,IDHCV+9) = ZUS2RG*( ZCPT(JROF,JLEV)+&
       & ZCPT(JROF,JLEV+1) )*ZRS2SA2EVELH(JROF,JLEV)  
!     FEPCONVERSIFL
      PDHCV(JROF,JLEV,IDHCV+10) = -PAPHI(JROF,JLEV)*PSDIV(JROF,JLEV)*ZUSRG
      IF(LHDQLN) THEN
!       FQLFLUVERTDYN
        PDHCV(JROF,JLEV,IDHCV+11) = ZUS2RG*( PQL(JROF,JLEV)+&
         & PQL(JROF,JLEV+1) )*ZRS2SA2EVELH(JROF,JLEV)  
!       FQNFLUVERTDYN
        PDHCV(JROF,JLEV,IDHCV+12) = ZUS2RG*( PQN(JROF,JLEV)+&
         & PQN(JROF,JLEV+1) )*ZRS2SA2EVELH(JROF,JLEV)  
      ENDIF
    ENDDO
  ENDDO

! * CONDITION A LA LIMITE SUPERIEURE (SEMI-IMPOSEE POUR GAGNER DU TEMPS)
!   TOP BOUNDARY CONDITION

!   Hypotheses faites ici / Assumptions for top values:
!   (U,V)_[top]=(U,V)_[l=1]
!   T_[top]=T_[l=1]; q_[top]=q_[l=1]; ql_[top]=ql_[l=1]; qi_[top]=qi_[l=1]

  DO JROF=KSTART,KPROF
!   FPPFLUVERTDYN
    PDHCV(JROF,0,IDHCV+1) = ZRS2SA2EVELH(JROF,0)*ZUSRG
!   AUTRES FLUX VERTICAUX AU SOMMET
!   FQVFLUVERTDYN
    PDHCV(JROF,0,IDHCV+2) = 0.0_JPRB
!   FUUFLUVERTDYN
    PDHCV(JROF,0,IDHCV+3) = 0.0_JPRB
!   FVVFLUVERTDYN
    PDHCV(JROF,0,IDHCV+4) = 0.0_JPRB
!   FUUFLUDUAPLUI
    PDHCV(JROF,0,IDHCV+5) = 0.0_JPRB
!   FVVFLUDUAPLUI
    PDHCV(JROF,0,IDHCV+6) = 0.0_JPRB
!   FKKFLUVERTDYN
    PDHCV(JROF,0,IDHCV+7) = 0.0_JPRB
!   FKKFLUDUAPLUI
    PDHCV(JROF,0,IDHCV+8) = 0.0_JPRB
!   FCTFLUVERTDYN
    PDHCV(JROF,0,IDHCV+9) = 0.0_JPRB
!   FEPCONVERSIFL
    PDHCV(JROF,0,IDHCV+10) = -PAPHI(JROF,0)*PSDIV(JROF,0)*ZUSRG
    IF(LHDQLN) THEN
!     FQLFLUVERTDYN
      PDHCV(JROF,0,IDHCV+11) = 0.0_JPRB
!     FQNFLUVERTDYN
      PDHCV(JROF,0,IDHCV+12) = 0.0_JPRB
    ENDIF
  ENDDO
ENDIF

! 3.2/
! -- Variables "X" = "M1", "M2", "M3".
!    Variables "X" = "M1", "M2", "M3".

IF ( LHDMCI ) THEN
  IDHCV=NDHVV+NDHAVD+NDHBHKD

! * Remarque: partie non remise a jour vis a vis de l'abandon d'hypothese
!   de couche mince, valable pour lvertfe=.false. seulement
!   (code peu comprehensible et semblant eloigne des
!   equations, et peu d'utilisateurs declares).
! * Remark: code not updated for relaxation of thin layer hypothesis;
!   code valid for lvertfe=.false. only.
! * Code not updated for NH model.

! * CONDITION A LA LIMITE INFERIEURE / BOTTOM BOUNDARY CONDITION

  DO JROF=KSTART,KPROF
!   FA1FLUVERTDYN
    PDHCV(JROF,KFLEV,IDHCV+1) = - ZUSRG*RA**2 *ROMEGA*&
     & PSLAT(JROF)*PCLAT(JROF)*ZCLON(JROF)*PEVEL(JROF,KFLEV)  
!   FA2FLUVERTDYN
    PDHCV(JROF,KFLEV,IDHCV+2) = - ZUSRG*RA**2 *ROMEGA*&
     & PSLAT(JROF)*PCLAT(JROF)*ZSLON(JROF)*PEVEL(JROF,KFLEV)  
!   FA3FLUVERTDYN
    PDHCV(JROF,KFLEV,IDHCV+3) =   ZUSRG*RA**2 *ROMEGA*&
     & PCLAT(JROF)*PCLAT(JROF)*PEVEL(JROF,KFLEV)  
!   FA1GRAV
!   FA2GRAV
!   FA3GRAV
    ZORZON = PNORDM(JROF)*PORL(JROF)-PNORDL(JROF)*PORM(JROF)
    ZORMER = PNORDL(JROF)*PORL(JROF)+PNORDM(JROF)*PORM(JROF)
    ZPHILZ(JROF) = ZORZON
    ZPHILM(JROF) = ZORMER
    PDHCV(JROF,KFLEV,IDHCV+4) = ZUSRG*RA*PAPRS(JROF,KFLEV)*&
     & ( ZORMER*ZSLON(JROF)-ZORZON*ZCLON(JROF)*PSLAT(JROF))  
    PDHCV(JROF,KFLEV,IDHCV+5) = ZUSRG*RA*PAPRS(JROF,KFLEV)*&
     & (-ZORMER*ZCLON(JROF)-ZORZON*ZSLON(JROF)*PSLAT(JROF))  
    PDHCV(JROF,KFLEV,IDHCV+6) = ZUSRG*RA*PAPRS(JROF,KFLEV)*ZORZON*PCLAT(JROF)
!   FA1FLUDUAPLUI
!   FA2FLUDUAPLUI
!   FA3FLUDUAPLUI
    PDHCV(JROF,KFLEV,IDHCV+7) = -RA**2 *ROMEGA*ZFPSUM(JROF,KFLEV)*&
     & PSLAT(JROF)*PCLAT(JROF)*ZCLON(JROF)  
    PDHCV(JROF,KFLEV,IDHCV+8) = -RA**2 *ROMEGA*ZFPSUM(JROF,KFLEV)*&
     & PSLAT(JROF)*PCLAT(JROF)*ZSLON(JROF)  
    PDHCV(JROF,KFLEV,IDHCV+9) =  RA**2 *ROMEGA*ZFPSUM(JROF,KFLEV)*&
     & PCLAT(JROF)*PCLAT(JROF)  
  ENDDO

! * INTERNIVEAUX NORMAUX / HALF LEVELS

  DO JLEV = KFLEV-1, 1, -1
    DO JROF=KSTART,KPROF
      ZUS2RG = 0.5_JPRB*ZUSRG
!     FA1FLUVERTDYN
!     FA2FLUVERTDYN
!     FA3FLUVERTDYN
      PDHCV(JROF,JLEV,IDHCV+1) = ZUS2RG*PEVEL(JROF,JLEV)*&
       & (ZM1(JROF,JLEV+1)+ZM1(JROF,JLEV))  
      PDHCV(JROF,JLEV,IDHCV+2) = ZUS2RG*PEVEL(JROF,JLEV)*&
       & (ZM2(JROF,JLEV+1)+ZM2(JROF,JLEV))  
      PDHCV(JROF,JLEV,IDHCV+3) = ZUS2RG*PEVEL(JROF,JLEV)*&
       & (ZM3(JROF,JLEV+1)+ZM3(JROF,JLEV))  
!     FA1GRAV
!     FA2GRAV
!     FA3GRAV
      ZPHILZ(JROF) = ZPHILZ(JROF) +ZRTZON(JROF,JLEV+1)*PLNPR(JROF,JLEV+1)
      ZPHILM(JROF) = ZPHILM(JROF) +ZRTMER(JROF,JLEV+1)*PLNPR(JROF,JLEV+1)
      PDHCV(JROF,JLEV,IDHCV+4) = ZUSRG*RA*PAPRS(JROF,JLEV)*&
       & (ZPHILM(JROF)*ZSLON(JROF)-ZPHILZ(JROF)*ZCLON(JROF)*&
       & PSLAT(JROF))  
      PDHCV(JROF,JLEV,IDHCV+5) = ZUSRG*RA*PAPRS(JROF,JLEV)*&
       & (-ZPHILM(JROF)*ZCLON(JROF)-ZPHILZ(JROF)*ZSLON(JROF)*&
       & PSLAT(JROF))  
      PDHCV(JROF,JLEV,IDHCV+6) = ZUSRG*RA*PAPRS(JROF,JLEV)*&
       & ZPHILZ(JROF)*PCLAT(JROF)  
!     FA1FLUDUAPLUI
!     FA2FLUDUAPLUI
!     FA3FLUDUAPLUI
      PDHCV(JROF,JLEV,IDHCV+7) = 0.5_JPRB*ZFPSUM(JROF,JLEV)*&
       & (ZM1(JROF,JLEV)+ZM1(JROF,JLEV+1))  
      PDHCV(JROF,JLEV,IDHCV+8) = 0.5_JPRB*ZFPSUM(JROF,JLEV)*&
       & (ZM2(JROF,JLEV)+ZM2(JROF,JLEV+1))  
      PDHCV(JROF,JLEV,IDHCV+9) = 0.5_JPRB*ZFPSUM(JROF,JLEV)*&
       & (ZM3(JROF,JLEV)+ZM3(JROF,JLEV+1))  
    ENDDO
  ENDDO

! * CONDITION A LA LIMITE SUPERIEURE (SEMI-IMPOSEE POUR GAGNER DU TEMPS)
!   TOP BOUNDARY CONDITION

!   Hypotheses faites ici / Assumptions for top values:
!   (M1,M2,M3)_[top]=(M1,M2,M3)_[l=1]

  DO JROF=KSTART,KPROF
    PDHCV(JROF,0,IDHCV+1) = 0.0_JPRB
    PDHCV(JROF,0,IDHCV+2) = 0.0_JPRB
    PDHCV(JROF,0,IDHCV+3) = 0.0_JPRB
    PDHCV(JROF,0,IDHCV+4) = 0.0_JPRB
    PDHCV(JROF,0,IDHCV+5) = 0.0_JPRB
    PDHCV(JROF,0,IDHCV+6) = 0.0_JPRB
    PDHCV(JROF,0,IDHCV+7) = 0.0_JPRB
    PDHCV(JROF,0,IDHCV+8) = 0.0_JPRB
    PDHCV(JROF,0,IDHCV+9) = 0.0_JPRB
  ENDDO
ENDIF

! 3.3/
! -- Variable "X" = "S".

IF ( LHDENT ) THEN
  IDHCV=NDHVV+NDHAVD+NDHBHKD+NDHBMCD

! * CONDITION A LA LIMITE INFERIEURE / BOTTOM BOUNDARY CONDITION

!   Hypotheses faites ici / Assumptions for bottom values:
!   S_[bottom]=S_[surf]=Sd_[surf]+(Sv_[surf]-Sd_[surf])*q_[surf]

  DO JROF=KSTART,KPROF
!   FSSFLUVERTDYN
    ZPREVS = MAX(ZQTHRES,PQVS(JROF))&
     & *RV*ZAPRS(JROF,KFLEV)/(RD+(RV-RD)*PQVS(JROF))  
    ZENTRAS = RCPD*LOG(PTSFC(JROF))-RD*LOG(ZAPRS(JROF,KFLEV)-ZPREVS)+ZENTRA0
    ZENTRVS = RCPV*LOG(PTSFC(JROF))-RV*LOG(ZPREVS)+ZENTRV0
    PDHCV(JROF,KFLEV,IDHCV+1) = ZUSRG*ZRS2SA2EVELH(JROF,KFLEV)*&
     & (ZENTRAS+(ZENTRVS-ZENTRAS)*PQVS(JROF))  
!   FSSPRECISS
    PDHCV(JROF,KFLEV,IDHCV+2) =&
     & ZENTRL(JROF,KFLEV)*(PFPLCL(JROF,KFLEV)+PFPLSL(JROF,KFLEV)) +&
     & ZENTRS(JROF,KFLEV)*(PFPLCN(JROF,KFLEV)+PFPLSN(JROF,KFLEV))  
  ENDDO

! * INTERNIVEAUX NORMAUX / HALF LEVELS

  ZUS2RG = 0.5_JPRB*ZUSRG
  DO JLEV = 1, KFLEV-1
    DO JROF=KSTART,KPROF
!     FSSFLUVERTDYN
      PDHCV(JROF,JLEV,IDHCV+1) = ZUS2RG*(ZENTR(JROF,JLEV)+&
       & ZENTR(JROF,JLEV+1))*ZRS2SA2EVELH(JROF,JLEV)  
!     FSSPRECISS
      PDHCV(JROF,JLEV,IDHCV+2) =&
       & ZENTRL(JROF,JLEV)*(PFPLCL(JROF,JLEV)+PFPLSL(JROF,JLEV)) +&
       & ZENTRS(JROF,JLEV)*(PFPLCN(JROF,JLEV)+PFPLSN(JROF,JLEV))  
    ENDDO
  ENDDO

! * CONDITION A LA LIMITE SUPERIEURE (SEMI-IMPOSEE POUR GAGNER DU TEMPS)
!   TOP BOUNDARY CONDITION

!   Hypotheses faites ici / Assumptions for top values:
!   S_[top]=S_[l=1]

  DO JROF=KSTART,KPROF
!   FSSFLUVERTDYN
    PDHCV(JROF,0,IDHCV+1) = 0.0_JPRB
!   FSSPRECISS
    PDHCV(JROF,0,IDHCV+2) = 0.0_JPRB
  ENDDO
ENDIF

!     ------------------------------------------------------------------
!*    4.- VERIFICATION/MAINTENANCE EVENTUELLE
!         ADDITIONAL CHECK

IF ( LHDLIST ) THEN
  WRITE (NULOUT,*) ' DDH * CPDYDDH IDHCV=',IDHCV
ENDIF

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

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