SUBROUTINE LACDYN( &
 ! --- INPUT ------------------------------------------------------------------
 & CDCONF,KST,KPROF,PDT,&
 & PVCRSSA9F,PNHXT9,PVCRSSA0F,PVCASRS0F,PVCASRS0H,PVCW0F,PWDLW0F,&
 & PRDLR0,PRDLR9,PNHXT0,&
 & PRES0,PKAP0,PRDELP0,PEVEL0,PVVEL0,PSDVBC0,PSGRTL,PSGRTM,&
 & PSLHDA,PSLHDD0,PLHU0,PLHV0,&
 & PGM   ,PGNORDL,PGNORDM,PRCORI,PRCORIC,PGOMVRL,PGOMVRM,&
 & POROG ,POROGL,POROGM,&
 & PTNDPD,PTNDVD,PTNDGW,P3DIVG,PD3Y0,PD3Y9,PDBBC,PRDPHI,PGWT0,PGWT9,&
 & PGFL,&
 ! --- INPUT/OUTPUT -----------------------------------------------------------
 & PGMV,PGMVS,PB1,PB2,PGMVT1,PGMVT1S,PGWS)

!**** *LACDYN*   Semi-Lagrangian scheme.
!                Computation of the t and t-dt useful quantities
!                 at grid-points.

!     Purpose.
!     --------

!          Dynamic non-linear computations in grid-point space
!          for hydrostatic and NH primitive equations and SL scheme.

!          Remark (in particular when the thin layer hypothesis is relaxed):
!          input horizontal derivatives are the semi-reduced ones
!          (i.e. rssavnabla X = (rs/a) vnabla X = M vnabla' X, where "M" is
!          the mapping factor and "vnabla'" is the reduced gradient operator
!          available in spectral space); input divergence and
!          vorticity are the semi-reduced ones.

!          Additional remarks:
!          - notation "prehyds" is for hydrostatic surface pressure.
!          - for input and output upper air variables, values are at full levels
!            if no other information is provided.
!          - NH variables: "P variable" is the pressure departure variable
!            (pressure departure equation), i.e. ln(pre/prehyd) if npdvar=2;
!            abbreviation "vwv" stands for "vertical wind variable".
!          - for PC schemes:
!            * this routine is called for nsiter=0.
!            * this routine is called for the predictor of lpc_old.
!            * this routine is called for the predictor of lpc_full.
!            * this routine is called for the corrector of lpc_full.

!          This subroutine fills the semi-Lagrangian buffers to be
!          interpolated.

!**   Interface.
!     ----------
!        *CALL* *LACDYN(..)

!        Explicit arguments :
!        --------------------

!        INPUT:
!          CDCONF      - configuration.
!          KST         - first element of work.
!          KPROF       - depth of work.
!          PDT         - For a leap-frog scheme (three time level scheme):
!                         'dt' at the first time-step, '2 dt' otherwise.
!                        For a 2TL SL scheme: timestep 'dt'.
!          PVCRSSA9F   - "rs/a" at full levels at t-dt.
!          PNHXT9      - "X" at full levels at t-dt, diagnosed in CPG_GP.
!          PVCRSSA0F   - "rs/a" at full levels at t.
!          PVCASRS0F   - "a/rs" at full levels at t.
!          PVCASRS0H   - "a/rs" at half levels at t.
!          PVCW0F      - pseudo-vertical velocity "W = Drs/Dt" at full lev at t.
!          PWDLW0F     - vertical velocity "w = Dr/Dt" at full levels at t.
!          PRDLR0      - array containing "r/a", "a/r", "grad(r/a)" at t.
!          PRDLR9      - array containing "r/a", "a/r" at t-dt.
!          PNHXT0      - "X" at full levels at t, diagnosed in CPG_GP.
!          PRES0       - hydrostatic pressure "prehyd" at half levels at t.
!          PKAP0       - "R/cp" at full levels at t.
!          PRDELP0     - 1/(pressure depth of layers) at t.
!          PEVEL0      - "(etadot d prehyd/d eta)" at half levels at t.
!          PVVEL0      - "omega/prehyd" at full levels at t.
!          PSDVBC0     - vertical integral of divergence computed in "gpcty",
!                        including the "lrubc" and "delta m=1" contributions
!                        of (etadot d prehyd/d eta).
!          PSGRTL      - semi-reduced zonal comp. of the pressure force grad.
!          PSGRTM      - semi-reduced merid. comp. of the pressure force grad.
!          PSLHDA      - Scaling factor of the deformation in f(d) function
!                        (including the model resolution correction)
!          PSLHDD0     - Treshold for deformation tensor enhancement
!          PLHU0       - zonal wind time t at half levels.
!          PLHV0       - meridian wind time t at half levels.
!          PGM         - mapping factor.
!          PGNORDL     - zonal component ("Gnordl") of the unit vector
!                        directed towards the true North pole.
!          PGNORDM     - meridian component ("Gnordm") of the unit vector
!                        directed towards the true North pole.
!          PRCORI      - Coriolis parameter "f = 2 Omega sin(theta)".
!          PRCORIC     - 2 Omega cos(theta).
!          PGOMVRL     - zonal component of "2 Omega vec a k".
!          PGOMVRM     - meridian component of "2 Omega vec a k".
!          POROG       - surface orography.
!          POROGL      - zonal component of the orography semi-reduced gradient
!          POROGM      - merid component of the orography semi-reduced gradient
!          PTNDPD      - [D(pressure departure variable)/Dt]_adiab
!          PTNDVD      - [D(vertical divergence variable)/Dt]_adiab
!          PTNDGW      - [D(gw)/Dt]_adiab
!          P3DIVG      - D3 at t (full levels).
!          PD3Y0       - "Y"(non-linear residual of D3) at full levels at t.
!          PD3Y9       - "Y"(non-linear residual of D3) at full levels at t-dt.
!          PDBBC       - [D(gw)_surf/Dt]_adiab.
!          PRDPHI      - (RT prehyd [Delta log(prehyd)])/pre at t.
!          PGWT0       - [gw] at t (LGWADV=T only; levels: see CPG_GP).
!          PGWT9       - [gw] at t-dt (LGWADV=T only; levels: see CPG_GP).
!          PGFL        - unified_treatment grid-point fields

!        INPUT/OUTPUT:
!          PGMV        - GMV variables at t-dt and t.
!          PGMVS       - GMVS variables at t-dt and t.
!          PB1         - "SLBUF1" buffer for interpolations.
!          PB2         - "SLBUF2" buffer.
!          PGMVT1      - GMV variables at t+dt.
!          PGMVT1S     - GMVS variables at t+dt.
!          PGWS        - [gw]_surf at t.

!        Implicit arguments :
!        --------------------

!     Method.
!     -------
!        See documentation

!     Externals.
!     ----------
!        Called by CPG_DYN.

!     Reference.
!     ----------
!             Arpege documentation about semi-lagrangian scheme.

!     Author.
!     -------
!        K. YESSAD (METEO FRANCE/CNRM/GMAP) after routines
!          CPLGDY1 and LAGSIMP coded by Maurice IMBARD.

! Modifications
! -------------
!   Original : FEBRUARY 1992.
!   D. Giard : 18.05.1992  : no "beta-term" if NNMI iteration
!   D. Giard : 30.10.1992  : CDCONF='M' for diabatic NNMI iteration
!   K. YESSAD and M. HORTAL: NOVEMBER 1992
!   K. YESSAD: DECEMBER 1992 (non interpolating vertical scheme and
!              some cleaning, introduction of a decentering factor
!              in semi-implicit terms and terms averaged along the
!              semi-lagrangian trajectory).
!   K. YESSAD: MARCH 1993 (non interpolating vertical scheme with
!              exact residual advections, option LVADRES=.T.).
!   Modified OCT 1993 by K. YESSAD: semi-implicit computations
!                                   with not reduced divergence.
!   Modified 93-12-14 by K. YESSAD: interpolations at medium point for
!                                 semi-lagrangian temperature equation.
!   Modified 93-12-21 by C. Temperton: interpolations at medium point for
!                                 semi-lagrangian moisture equation.
!   Modified 94-03-23 by M. Hortal: interpolations at medium point for
!                                 semi-lagrangian momentum equation.
!   Modified 94-05-12 by C. Temperton: spectral RT option
!   Modified 94-06-29 by C. Temperton: semi-implicit Coriolis terms
!   Modified 94-09-08 M.Tolstykh: modified decentering in semi-Lag scheme
!   Modified 94-11-12 by C. Temperton: introduction of LADVF switch
!   Modified 95-02-06 by C. Temperton: two-time-level scheme
!   Modified JAN 1995 by K. YESSAD:
!     - Delta m=1: harmonisation of surface
!       values of liquid water, ice and cloudiness with eulerian
!       computations (Z[X]SOL=0 instead of Z[X]SOL=P[X]T0(NFLEVG))
!       -> additional residual advections under switch IDPSFI=1.
!     - Constant part of decentering factor becomes VESLA for explicit
!       terms and vertical residual advections.
!   Modified JAN 1995 by R. BUBNOVA:
!     - Plane geometry in momentum equation.
!   Modified AUGUST 1995 by K. YESSAD:
!     - Modularisation: call to new routines LASURE, LASSIE, LAVENT, 
!       LATTEX, LATTES and LAVAUR + some cleaning and optimisations.
!     - Possibility of having differents decentering coefficients
!       for explicit and SI terms also in the two-time level scheme.
!     - Two-time level SL scheme for NLOSP=1.
!     - Modification in continuity equation to advect: 
!        ln(ps)+zcmslp0*phisol/(Ra*Tref) instead of ln(ps) if NLOSP=0.
!        ps+zcmslp0*(psref*phisol)/(Ra*Tref) instead of ps if NLOSP=1.
!       (after an idea of Tanguay/Ritchie). 
!     - Accurate version of two-time level semi-lagrangian scheme,
!       after Tolstykh and Janousek.
!     - Second-order decentering in two-time level scheme.
!     - Modified formulation of continuity equation according to
!       Tanguay/Ritchie and Temperton.
!     - Completion of F90 norms rewritting for loops. 
!   Modified 96-03-07 by C. Temperton: removal of time-filter in
!       the two-time-level scheme
!   Modified 96-04-16 by C. Temperton: "alternative averaging" in
!       the two-time-level scheme
!   Modified 96-03 by A. Untch : grid-point prognostic ozone (EC).
!   Modified MAY 1996 by M. JANOUSEK and R. BUBNOVA:
!     - Non hydrostatics.
!   Modified 96-08 by M. Hortal: New form of thermodynamic equation
!   Modified 96-10-23 by M. Hortal: L2TLFF passed to LATTEX
!   Modified OCT 1996 by K. YESSAD:
!     - Eulerian treatment of orography for T eqn: SLNI scheme.
!     - Removal of variable uncentering.
!   Modified JULY 1997 by P. Le Moigne:
!     - Dimensioning of OROGLL, OROGLM, OROGMM to NPROMNH
!   Modified November 1997 by R. Bubnova:  
!     - half-level wind computation moved up to CPG
!   Modified May 1998 by K. YESSAD: adaptation of L2TLFF to LAGPHY=.F..
!   Modified July 1998 by K. YESSAD and C. FISCHER: cleaning
!    - removal of options NODEC=2, L2TLAW=T, L2TLAT=T
!    - merge of VESLA and VESL into VESL
!    - reordering dummy arguments in a more convenient and logical way.
!    - (PVIDT9,PVIDT0) renamed into (PDIVT9,PDIVT0).
!    - complete declaration of dummy arguments.
!    - correction of false comments.
!   Modified 98-05-26 by E. Holm: Order of ozone changed in call,
!       and in calls to LATTEX, LAVAUR, and LAVABO.
!   Modified 98-12-18 by I. GOSPODINOV and K. YESSAD: option LELTRA.
!   Modified 98-12-04 by K. YESSAD: New option 'lradvtoro'.
!   Modified 99-03-31 by P. SMOLIKOVA: option LRDAORG (double averaging).
!   Modified 99-06-07 by I. GOSPODINOV and K. YESSAD: physics for LELTRA.
!   Modified 99-08-16 by C. Temperton: removal of NVINTSL, LVADL
!   Modified 99-11-18 by C. Temperton: allow LSPO3 + LSLAG
!   Modified Nov 1999 by K. YESSAD: cleaning
!    - LASSIE and LANHSI rewritten using SI.. routines => less arguments.
!    - removal of useless dummy arguments in "gnhpdvd"
!    - replace "pevel" by "psdvbc" in "lattes" to avoid the re-computation
!      of a vertical integral of divergence already computed in "gpcty".
!   Modified April 2000 by Malgorzata Szczech:
!    - bug corrections for thermodynamical ozon.
!    - add option "lhvo3" for thermodynamical ozon.
!   Modified 00-11-06 by C. Temperton: bugfix for ozone advection.
!   Modified 01-06-22 by K. YESSAD:
!    - relaxation of thin layer hypothesis.
!    - correct false or ambiguous comments.
!   Modified 01-08-30 by K. YESSAD: pruning and some other cleanings.
!   R. El Khatib : 01-08-07 Pruning options
!   J.Vivoda 03-2002 PC schemes for NH dynamics (LPC_XXXX keys)
!   P.Smolikova 02-09-30 : variable d4 in NH
!   Modified 08-2002 C. Smith : use "w" as prognostic variable in the
!    semi-lag advection of vertical divergence in the NH model.
!   P.Smolikova 03-01-31 : variable d4 in 2tl PC NH
!   Modified 2003-03-16 M.Hamrud/M.Hortal - Revised data flow (GFL)
!   F. Vana 03-08-25 : new vertical profile of diffusion.
!   P.Smolikova 08-2003 : option LRDBBC.
!   01-Oct-2003 M. Hamrud  CY28 Cleaning
!   M.Hortal      01-Dec-2003 Extra-fields coming from the dynamics
!   09-Jun-2004 J. Masek   NH cleaning (LPC_NOTR, LFULLIMP, LVSLWBC)
!   01-Jul-2004 K. Yessad  Make clearer the tests for PC scheme.
!   Y.Seity 11-2004 : New arguments in call LASSIE and LANHSI for GPRCP
!   04-11-04 F. Vana: LATTE_DEF --> LATTE_KAPPA
!   12-Jan-2005 K. Yessad: GNHPDVD replaced by GP./GNH. routines in CPG_GP.
!   20-Feb-2005 J. Vivoda  GWADV scheme for PC_FULL (d3,d4)
!   15-Jan-2005 M.Hamrud   Revised GPRCP
!   11-Jul-2005 R. Brozkova cleaning d4 subvariants
!   08-Jun-2006 F. Vana two new arguments to LATTE_KAPPA
!   K. Yessad 07-02-2007: Splitting alti/surf for (gw) in NH+LGWADV.
!   K. Yessad 07-02-2007: Update some comments.
!   K. Yessad 07-03-2007: Remove useless (gw)_surf interpolations in NH+LGWADV.
!   N. Wedi and K. Yessad (Jan 2008): different dev for NH model and PC scheme
!   K. Yessad Aug 2008: rationalisation of dummy argument interfaces
!   09-Sep-2008 J. Masek  Dataflow for flow deformation along pressure levels
!   K. Yessad Nov 2008: rationalisation of dummy argument interfaces
! End Modifications
!------------------------------------------------------------------

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

USE YOMCT0   , ONLY : LTWOTL   ,LNHDYN   ,LPC_OLD  ,LPC_FULL ,LPC_CHEAP
USE YOMCT3   , ONLY : NSTEP
USE YOMDIM   , ONLY : NPROMA   ,NPROMNH  ,NPROMVC  ,NPROMDLW ,NPROMDLR , &
 & NFLEVG   ,NFLSA    ,NFLEN
USE YOMSC2   , ONLY : NFLDSLB1 ,NFLDSLB2
USE YOMGMV   , ONLY : NDIMGMV  ,NDIMGMVS ,YT0      ,YT1      ,YT9
USE YOMDYNA  , ONLY : LGWADV   ,LRDBBC   ,LSLHD    ,LNH_PDVD ,LNH_GEOGW
USE YOMDYN   , ONLY : XIDT     ,LSETTLS  ,NCURRENT_ITER
USE YOM_YGFL , ONLY : YGFL
USE PTRSLB1  , ONLY : MSLB1Y9
USE PTRSLB2  , ONLY : MSLB2Y1
USE PAR_RDLR , ONLY : JP_DIMR0 ,JP_DIMR9

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

IMPLICIT NONE

CHARACTER(LEN=1)  ,INTENT(IN)    :: CDCONF 
INTEGER(KIND=JPIM),INTENT(IN)    :: KST 
INTEGER(KIND=JPIM),INTENT(IN)    :: KPROF 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PDT 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PVCRSSA9F(NPROMVC,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PNHXT9(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PVCRSSA0F(NPROMVC,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PVCASRS0F(NPROMVC,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PVCASRS0H(NPROMVC,0:NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PVCW0F(NPROMVC,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PWDLW0F(NPROMDLW,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PRDLR0(NPROMDLR,0:NFLEVG,JP_DIMR0)
REAL(KIND=JPRB)   ,INTENT(IN)    :: PRDLR9(NPROMDLR,0:NFLEVG,JP_DIMR9)
REAL(KIND=JPRB)   ,INTENT(IN)    :: PNHXT0(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PRES0(NPROMA,0:NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PKAP0(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PRDELP0(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PEVEL0(NPROMA,0:NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PVVEL0(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PSDVBC0(NPROMA,0:NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PSGRTL(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PSGRTM(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PSLHDA(NPROMA) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PSLHDD0(NPROMA)
REAL(KIND=JPRB)   ,INTENT(IN)    :: PLHU0(NPROMA,0:NFLEVG)
REAL(KIND=JPRB)   ,INTENT(IN)    :: PLHV0(NPROMA,0:NFLEVG)
REAL(KIND=JPRB)   ,INTENT(IN)    :: PGM(NPROMA) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PGNORDL(NPROMA) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PGNORDM(NPROMA) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PRCORI(NPROMA) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PRCORIC(NPROMA) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PGOMVRL(NPROMA) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PGOMVRM(NPROMA) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: POROG(NPROMA) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: POROGL(NPROMA) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: POROGM(NPROMA) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PTNDPD(NPROMNH,NFLEVG)
REAL(KIND=JPRB)   ,INTENT(IN)    :: PTNDVD(NPROMNH,NFLEVG)
REAL(KIND=JPRB)   ,INTENT(IN)    :: PTNDGW(NPROMNH,NFLEVG)
REAL(KIND=JPRB)   ,INTENT(IN)    :: P3DIVG(NPROMNH,NFLEVG)
REAL(KIND=JPRB)   ,INTENT(IN)    :: PD3Y0(NPROMNH,NFLEVG)
REAL(KIND=JPRB)   ,INTENT(IN)    :: PD3Y9(NPROMNH,NFLEVG)
REAL(KIND=JPRB)   ,INTENT(IN)    :: PDBBC(NPROMNH)
REAL(KIND=JPRB)   ,INTENT(IN)    :: PRDPHI(NPROMNH,NFLEVG)
REAL(KIND=JPRB)   ,INTENT(IN)    :: PGWT0(NPROMNH,NFLEVG)
REAL(KIND=JPRB)   ,INTENT(IN)    :: PGWT9(NPROMNH,NFLEVG)
REAL(KIND=JPRB)   ,INTENT(IN)    :: PGFL(NPROMA,NFLEVG,YGFL%NDIM) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PGMV(NPROMA,NFLEVG,NDIMGMV)
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PGMVS(NPROMA,NDIMGMVS)
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PB1(NPROMA,NFLDSLB1)
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PB2(NPROMA,NFLDSLB2)
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PGMVT1(NPROMA,NFLEVG,YT1%NDIM)
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PGMVT1S(NPROMA,YT1%NDIMS)
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PGWS(NPROMNH)

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

INTEGER(KIND=JPIM) :: IYLAG

! * computed in LASURE:
REAL(KIND=JPRB) :: ZBETA, ZBT, ZDTS2, ZESGM, ZESGP
REAL(KIND=JPRB) :: ZREDIV(NPROMA)
! * computed in LASSIE or LANHSI:
REAL(KIND=JPRB) :: ZBDT(NPROMA)
REAL(KIND=JPRB) :: ZGAGT0L(NPROMA,NFLEVG),ZGAGT0M(NPROMA,NFLEVG)
REAL(KIND=JPRB) :: ZGAGT9L(NPROMA,NFLEVG),ZGAGT9M(NPROMA,NFLEVG)
REAL(KIND=JPRB) :: ZLPD0(NPROMNH,NFLEVG),ZLPD9(NPROMNH,NFLEVG)
REAL(KIND=JPRB),ALLOCATABLE :: ZDPD0(:,:)
REAL(KIND=JPRB),ALLOCATABLE :: ZDPD9(:,:)
REAL(KIND=JPRB) :: ZSDIV0(NPROMA),ZSDIV9(NPROMA)
REAL(KIND=JPRB) :: ZSPDS0 (NPROMNH,NFLEVG),ZSPDS9(NPROMNH,NFLEVG)
REAL(KIND=JPRB) :: ZTOD0(NPROMA,NFLEVG),ZTOD9(NPROMA,NFLEVG)

LOGICAL :: LL2TLFF1, LLGWADV
REAL(KIND=JPRB) :: ZHOOK_HANDLE

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

#include "lanhsi.intfb.h"
#include "lanhsi_geogw.intfb.h"
#include "lanhsib.intfb.h"
#include "lassie.intfb.h"
#include "lasure.intfb.h"
#include "latte_bbc.intfb.h"
#include "latte_kappa.intfb.h"
#include "lattes.intfb.h"
#include "lattex.intfb.h"
#include "lattey.intfb.h"
#include "lavabo.intfb.h"
#include "lavent.intfb.h"

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

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

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

!*       0.    ALLOCATIONS:
!              ------------

IF( LNHDYN.AND.LGWADV ) ALLOCATE( ZDPD0(NPROMNH,NFLEVG) )
IF( LNHDYN.AND.LGWADV.AND.(.NOT.LTWOTL) ) ALLOCATE( ZDPD9(NPROMNH,NFLEVG) )

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

!*       1.    PRELIMINARY INITIALISATIONS:
!              ----------------------------

CALL LASURE(CDCONF,KST,KPROF,PDT,PGM,&
 & ZDTS2,ZBETA,ZBT,LL2TLFF1,ZBDT,ZREDIV,ZESGP,ZESGM)  

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

!*       2.    COMPUTATION OF THE LINEAR TERMS FOR SEMI-IMPLICIT SCHEME.
!              ---------------------------------------------------------

IF (LNHDYN.AND.LNH_PDVD) THEN
  CALL LANHSI(KST,KPROF,LGWADV,PRCORI,ZREDIV,PGMV,PGMVS,PGFL,&
   & ZSDIV0,ZSDIV9,ZTOD0,ZTOD9,ZGAGT0L,ZGAGT0M,ZGAGT9L,ZGAGT9M,&
   & ZSPDS0,ZSPDS9,ZLPD0,ZLPD9,ZDPD0,ZDPD9)  
ELSEIF (LNHDYN.AND.LNH_GEOGW) THEN
  CALL LANHSI_GEOGW(KST,KPROF,PRCORI,ZREDIV,PGMV,PGMVS,PGFL,&
   & ZSDIV0,ZSDIV9,ZTOD0,ZTOD9,ZGAGT0L,ZGAGT0M,ZGAGT9L,ZGAGT9M,&
   & ZSPDS0,ZSPDS9,ZLPD0,ZLPD9)  
ELSE
  CALL LASSIE(KST,KPROF,PRCORI,PGMV,PGMVS,PGFL,&
   & ZSDIV0,ZSDIV9,ZTOD0,ZTOD9,ZGAGT0L,ZGAGT0M,ZGAGT9L,ZGAGT9M)  
ENDIF

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

!*       3.    COMPUTATION OF THE WIND COMPONENTS NECESSARY FOR SL TRAJECTORY.
!              ---------------------------------------------------------------

IF ((NCURRENT_ITER == 0).OR. &
 & (NCURRENT_ITER > 0 .AND. LPC_FULL .AND.(.NOT.LPC_CHEAP) )) THEN

  CALL LAVENT(KST,KPROF,LL2TLFF1,&
   & PVCASRS0F,PRDLR0,PSGRTL,PSGRTM,ZDTS2,PRCORI,PRCORIC,PGNORDL,PGNORDM,&
   & PRDELP0,PEVEL0,PVCW0F,PWDLW0F,PGMV,PB1,PB2)

ENDIF

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

!*       4.    COMPUTATION OF THE 3D-EQUATIONS RIGHT-HAND SIDE TERMS.
!              ------------------------------------------------------

!        4.1:  general case:

CALL LATTEX(KST,KPROF,ZDTS2,ZBT,ZBDT,ZESGP,ZESGM,&
 & PGNORDL,PGNORDM,PRCORI,PRCORIC,PGOMVRL,PGOMVRM,POROG,POROGL,POROGM,&
 & PVCRSSA0F,PVCASRS0F,PVCRSSA9F,PRDLR0,PRDLR9,PVCW0F,PWDLW0F,&
 & ZGAGT0L,ZGAGT0M,ZTOD0,ZSPDS0,ZLPD0,ZDPD0,&
 & ZGAGT9L,ZGAGT9M,ZTOD9,ZSPDS9,ZLPD9,ZDPD9,&
 & PSGRTL,PSGRTM,PKAP0,PVVEL0,PRDELP0,PEVEL0,P3DIVG,PTNDPD,PTNDVD,PTNDGW,&
 & PNHXT0,PGWT0,PNHXT9,PGWT9,PGFL,&
 & PGMV,PGMVT1,PB1,PB2)

!        4.2:  Additional quantities required in the NH model
!              for option LRDBBC=T:

IF (LNHDYN.AND.LRDBBC.AND.(.NOT.LGWADV)) THEN
  ! * Remarks:
  !   - for LGWADV=T this calculation is not required because
  !     in this case [gw]_surf(t+dt) is computed by a diagnostic relationship
  !     in routine LAPINEB.
  CALL LATTE_BBC(KST,KPROF,ZDTS2,ZESGP,ZESGM,PDBBC,PRDPHI, &
   & PGWS,PGMVS,PGMV,PB1,PB2)
ENDIF

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

!*       5.    COMPUTATION OF THE 2D-EQUATIONS RIGHT-HAND SIDE TERMS.
!              ------------------------------------------------------

CALL LATTES(KST,KPROF,ZDTS2,ZBDT,ZESGP,ZESGM,&
 & PVCRSSA0F,PVCASRS0F,PVCASRS0H,PRDLR0,POROG,POROGL,POROGM,&
 & ZSDIV0,ZSDIV9,PSDVBC0,PRES0,PGMVS,&
 & PGMV,PGMVT1S,PB1,PB2)

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

!*       6.    COMPUTATION OF "KAPPA" AND STORE IT IN  "SLBUF2".
!              -----------------------------------------------------------

IF (LSLHD) THEN
  CALL LATTE_KAPPA(KST,KPROF,ZDTS2,PSLHDA,PSLHDD0,PGMV,PGMVS, &
   & PLHU0,PLHV0,PRES0(1,NFLEVG),PRDELP0,PB2)
ENDIF

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

!*       7.    PREDICTOR-CORRECTOR SCHEME.
!              ---------------------------

IF (LNHDYN.AND.LPC_OLD) THEN

  IYLAG=3
  CALL LATTEY(NPROMA,KST,KPROF,NFLEVG,NFLSA,NFLEN,IYLAG,&
   & ZBT,NSTEP,LTWOTL,LSETTLS,XIDT,&
   & ZESGP,ZESGM,&
   & PD3Y0,PD3Y9,PGMV(1,1,YT9%MYNL),PB1(1,MSLB1Y9),PB2(1,MSLB2Y1))  

ENDIF

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

!*       8.    UPPER AND LOWER LATERAL BOUNDARIES CONDITIONS.
!              ----------------------------------------------

IF ((NCURRENT_ITER == 0).OR. &
 & (NCURRENT_ITER > 0 .AND. LPC_FULL .AND.(.NOT.LPC_CHEAP) )) THEN
  CALL LAVABO(KST,KPROF,LL2TLFF1,PB1)
ENDIF

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

!*       8.    SI TERM COMPUTED WITH d3 OR d4 VARIABLE FOR GWADV 
!              -------------------------------------------------
!*    compute dt L X(t) (+ Xterm)
!*    this quantity is substracted later in GPENDTR

IF (LNH_PDVD.AND.LGWADV)THEN

  LLGWADV=.FALSE.
  CALL LANHSI(KST,KPROF,LLGWADV,PRCORI,ZREDIV,PGMV,PGMVS,PGFL,&
   & ZSDIV0,ZSDIV9,ZTOD0,ZTOD9,ZGAGT0L,ZGAGT0M,ZGAGT9L,ZGAGT9M,&
   & ZSPDS0,ZSPDS9,ZLPD0,ZLPD9,ZDPD0,ZDPD9)  

  CALL LANHSIB(KST,KPROF,ZBT,ZBDT,ZESGP,&
   & ZGAGT0L,ZGAGT0M,ZTOD0,ZSPDS0,ZLPD0,ZSDIV0,PNHXT0,&
   & PGMV,PB1,PB2)

ENDIF

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

!*       9.    DEALLOCATIONS:
!              --------------

IF (ALLOCATED(ZDPD0)) DEALLOCATE(ZDPD0)
IF (ALLOCATED(ZDPD9)) DEALLOCATE(ZDPD9)

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

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