#ifdef VPP
!OCL SCALAR
#endif
SUBROUTINE SUDYN(KULOUT)

!------------------------------------------------------------------------------
!**** *SUDYN*   - Initialize constants and control for the dynamics

!     Purpose.
!     --------
!           Initialize YOMDYN, the common that controls the
!           dynamics of the model. Initialize semi-implicit
!           including computation of vertical structure matrix.
!           Also computes vertical modes .
!**   Interface.
!     ----------
!        *CALL* *SUDYN(KULOUT)

!        Explicit arguments :
!        --------------------
!        KULOUT : Logical unit for the output

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

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

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

!     Called by SU0YOMB.

!     Reference.
!     ----------
!        ECMWF Research Department documentation of the IFS

!     Author.
!     -------
!        Mats Hamrud and Philippe Courtier  *ECMWF*

! Modifications
! -------------
!   Original : 87-10-15
!   CLIVE TEMPERTON: 90-01-30 : ORDER OF VERTICAL MODES REVERSED
!   BILL HECKLEY   : 90-06-06 : FIX SIGNS OF VERTICAL MODES
!   MICHEL DEQUE   : 91-03-31 : HORIZONTAL DIFFUSION
!   PASCAL MARQUET : 91-07-07 : REFGEO and REFHEI
!   DOMINIQUE GIARD: 92-01-09 : NEW SCALING OF VERTICAL MODES
!   GABOR RADNOTI  : 92-12-24 : MOVE HOR. DIFF. TO SEPARATE ROUTINE
!   K. YESSAD      : DEC 1992 : adding decentering factor VESL
!                    and logical LVADL for semi-lag scheme.
!   K. YESSAD      : MAR 1993 : adding logical LVADRES.
!   K. YESSAD      : 08/03/93 : adding HDCRDIV,HDCRVOR,HDCRHV,HDCRSV,
!                    NEXPDHC,FRANDHC (additional horizontal diffusion
!                    in not stretched sphere) and call to SUHDG.
!   R. EL Khatib   : 93-04-02 Set-up defaults controled by LECMWF
!   R. El Khatib   : 93-05-06 Set-up through command line
!   R. El Khatib   : 93-05-10 Spectral brake"
!   C. TEMPERTON   : 93-11-01 : NORMV, VNORM for ECMWF
!   Modified 93-12-14 by K. YESSAD: interpolations at medium point for
!                                 semi-lagrangian temperature equation.
!   C. TEMPERTON   : 93-12-20 : interpolation at mid-point for
!                                 semi-Lagrangian moisture equation
!   M. Hortal   : 94-03-23 : interpolation at mid-point for
!                                 semi-Lagrangian momentum equations
!   Modified by K. YESSAD    : OCTOBER 1993. Semi-implicit scheme with
!                              not reduced divergence.
!   Modified by K. YESSAD and R. EL KHATIB: 18/02/1994:
!                    Harmonisation of enhanced diffusions (LFREIN).
!   K. YESSAD: 18/02/1994. Improvement of format prints.
!              Change definition of constants HDIR(...), HDCR(...),
!               now times.
!   K. YESSAD: APRIL 1994. Unified horizontal diffusion
!                          + some cleaning in default values.
!   J.L. Ricard: 7/06/94. Allocation of the array FTHSOR (Physical fields
!                         for animation)
!   M.Tolstykh: 31/08/94: Modified decentering in semi-Lag. scheme.
!   C. Temperton   : 95-02-06 : Two-time-level scheme
!   K. YESSAD (JAN 1995):
!       - Call to SUCUD to initialise weights RCUDWL and RCUDWM for
!         optimised computation of CUD-5 derivatives.
!       - Default value of LVADL set to .T. at METEO-FRANCE.
!       - Split constant part of decentering factor into
!         VESLA for explicit terms and VESL for semi-implicit terms
!         in semi-lagrangian scheme.
!       - Add prints (value of NVINTSL, NITMP, SIQR, NDLNPR).
!   R. BUBNOVA (JAN 1995):
!       - Add integer NSLTOR.
!   K. YESSAD (MARCH 1995):
!       - Optimisation of semi-implicit scheme if variable decentering.
!       - Use new array NSE0 (YOMLAP) to store coefficients in
!         spectral matricial operators (GMR, SCGMAP, SCVESL,
!         Helmholtz and horizontal diffusion LU decompositions).
!   K. YESSAD (OCTOBER 1995):
!       - Add switches for accurate 2TL SL scheme, second-order
!         decentering for 2TL SL scheme, Tanguay-Ritchie modification
!         for SL scheme.
!       - Rewriting according to F90 norms.
!   C. Temperton   : 95-10-13 : New SITR, SIPR for two-time-level scheme
!               and new treatment of orography in continuity equation
!   K. YESSAD (NOV 1995):
!       - Removal of HDC horizontal diffusion scheme.
!       - NEXPDH changed into REXPDH.
!   C. Temperton : 96-03-07 : Removal of time-filtering
!         in two-time-level scheme
!   C. Temperton : 96-04-16 : "Alternative (2nd-order) averaging"
!         and refinement of Coriolis term, both in two-time-level scheme
!   K. YESSAD (MARCH 1996):
!       - New switch LCORAN.
!   Modified by K. YESSAD (AUGUST 1996):
!       - Hermite cubic vertical interpolations for passive scalars.
!         Not yet coded for plane geometry.
!         Not yet coded for CUD-5 scheme.
!       - New variables VETAON and VETAOX to bound vertical position
!         of the origin point. Equivalent of what existed in the
!         cycle 15 is VETAON=VETAOX=1.
!       - Change for some default values (SL and HDIF schemes).
!       - Removal of variable uncentering.
!   M. TOLSTYKH (OCT 1996): Fourier space horizontal diffusion
!   C. Temperton : 96-10-23 : Default timesteps for 2TL scheme
!                             - also default values for T159, T319
!   B.Edgington : 97-06-05 : Include control of mass correction
!   C. Temperton : 97-05-14 : NVLAG=3 and NWLAG=3 for SWE model
!   D. Giard : 97-04_23 : call to SUSTA even if NFLEVG=1 (conf. 923)
!   C. Temperton : 98-01-19 : 2TL SL scheme for SWE model
!   C. Temperton : 98-03-04 : default values of NITMP; prevent use of
!                             LIMPF with stretched or rotated grid
!   J.Boutahar & R.Elkhatib :97-06-16: NH FULL-POS
!   K. YESSAD (98-05-07): use of L2TLFF also for non lagged physics,
!    NSTTYP=2, 3TLSLI scheme.
!   J. Boutahar : 98-06-15 : LJBENER to FALSE in case LELAM
!   K. YESSAD (98-08-05): cleanings.
!       - Removal of NODEC, L2TLAT, L2TLAW.
!       - Redefinition of NVLAG for 2D model:
!         NVLAG<0: Lagrangian formulation of continuity eqn.
!         NVLAG>0: Conventional formulation of continuity eqn.
!       - Redefinition of NWLAG for 2D model for consistency with 3D:
!         NWLAG=1 becomes NWLAG=2.
!       - Cleaning in some tests.
!       - Add LCUTRA in YOMDYN and NAMDYN.
!       - Removal of VESLA.
!       - LEVGO set to F by default for EUL model (if LECMWF=F).
!   K. YESSAD (98-12-04): new option 'lradvtoro'.
!   L. Gerard   : 98-12-07 : RPRESCR (Lvl from which horiz diff >)
!   K. YESSAD (98-12-18): LELTRA also for:
!       - 3D model (LSETTLS = T or F for RHS equations).
!       - 2D model with LSETTLS = T for RHS equations.
!   C. Temperton : 99-01-05 : NVLAG=2 for SWE model
!   R. El Khatib : 99-03-30 : NRUBC
!    + additional correction of K. YESSAD: BETADT has to be reset to 1
!      for SL2TL even if a value different from 1 is specified
!      in the namelist.
!   Modified 99-03-31 by P. SMOLIKOVA: option LRDAORG (double averaging).
!   R. El Khatib : 99-05-21 default value of BETADT = 1. always. 
!   P. Gauthier  : 99-07-xx additional controls for Jc-dfi
!   C. Temperton : 99-08-16 : Removed redundant NVINTSL,RKROMA,LVADL;
!       check value of NQLAG only if LVENIN is true
!   C. Temperton : 99-08-27 : Allow LIMPF even if NCONF /= 1 !
!   C. Temperton : 99-09-08 : QM defaults true only for NCONF=1
!   C. Temperton : 00-03-24 : NITMP=2 for S/L TL/AD applications
!   C. Temperton : 00-04-11 : Bugfix for ECMWF only: definition of
!       VETAON and VETAOX to be independent of the existence of
!       passive scalars.
!   K. YESSAD : 99-11-17: VMAXTORO expression for ALADIN.
!   M. SZCZECH : 00-04-18: new variables for thermodynamic ozon.
!   D. Giard : 00-07-10 : control of NSITER
!   K. YESSAD:  00-08-07: relaxation of thin layer hypothesis.
!   M. Hortal:  01-11-08: set horizontal diffusion parameters
!   P. Smolikova : 01-03-30: options NPDVAR,NVDVAR for variables in NH.
!   J. PADILLA BARBOSA: 01-03-12: Subroutine SUDFHD
!   J. Masek : 25-05-2002: (NPDVAR, NVDVAR) other than (0, 0) enabled
!   Modified 01-08-30 by K. YESSAD: pruning and some other cleanings.
!   R. El Khatib : 01-08-07 Pruning options
!   K. YESSAD: 02-03-12 Thin layer hyp relaxation for L2TLFF=T.
!   J. Vivoda:    03-2002: PC schemes for NH dynamics
!   P. Smolikova 02-09-30: variable d4 in NH (NVDVAR=4)
!   J. Masek : 12-10-2002: PC bugfix, SUPONG moved to ALADIN version
!                          of CNT3 (sponge disabled for ARPEGE)
!   Modified 08-2002 C. Smith : use "w" as prognostic variable in the
!    semi-lag advection of vertical divergence in the NH model.
!   R. El Khatib : 03-01-14 Remove fullpos aspects (see pos.F90)
!   R. El Khatib : 03-04-17 Use MAXVAL
!   F. Vana      : 03-08-25 setup of YOMSLD
!   M.Hamrud : 03-04-03 GFL
!   C. Fischer: 03-08-19 allocate t9 gfl for predictor/corrector
!    (used to save t0 initial data while processing the corrector step)
!   R. El Khatib : 03-04-17 Use MAXVAL
!   C. Moussy : 03-10-01 LDCOUPLING argument in SET_GFL_ATTR calls 
!   P.BENARD : 03-10-08 New set-up for horiz. diffusions
!   01-Oct-2003 M. Hamrud           CY28 Cleaning
!   05-Mar-2003 Y. Bouteloup        New variables Snow, Rain, Graupel and TKE
!   17-Oct-2003 M. Tudor            add YCPF and YSPF to GFL
!      Dec-2003 K.Yessad            cleaning of horizontal diffusion
!      Dec-2003 K.Yessad            LSIDG moved into YOMDYN.
!      Dec-2003 F. Vana, K. YESSAD  rewriting the SLHD diffusion.
!      Feb-2004 K. Yessad           Monotonic SL interpolations become defaults
!   10-Jun-2004 J. Masek            NH cleaning (LPC_NOTR, LFULLIMP)
!   07-Jul-2004 K. Yessad
!    - Bound the increase of hor diffusion in the upper stratosphere.
!    - LPC_XIDT now in YOMDYN/SUDYN, computed from XIDT.
!    - LSLHD with monotonic interpolations.
!       R. El Khatib : 04-09-30 : No SL features for YCPF/YSPF (diagnostic
!          fields !)
!        M.Hortal      01-Dec-2003 LSVTSM: Stratospheric vertical velocity smoothed
!   March 2005 A. Untch : Aerosols in GFL 
!   April 2005 J. Flemming : Aerosols replaced with GRG in GFL
!   Y. SEITY : 04-11-16 Add new GFL for AROME (SRC)
!   29-Nov-2004 F. Vana  - new setup for diffusions (SLHD and spec)
!                        - new setup for GFL interpolation
!   15-Feb-2005 F. Vana  - Split of the global LSLHD key + 2D spline interp.
!   20-Feb-2005 J. Vivoda  3TL Eul PC scheme, GWADV scheme for PC_FULL
!   15-Sep-2005 F. Vana  - defaults for SLHD
!   K. Yessad (Aug 2005): computation of RKRF now in SURAYFRIC.
!   K. Yessad (Aug 2005): computation of RCORDI... now in SURCORDI.
!   K. Yessad (Aug 2005): SUELDYNB and SUEHDF now called in SUDYN.
!   K. Yessad (Aug 2005): SUALDYNB and SUHDF called only if LELAM=F.
!   12-Oct-2005 Y. Bouteloup : Initialisation of NCOMP_CVGQ
!   K. Yessad (Jan 2006): Set default LREPHD to F (consistency with cy29t2_op2)
!   M. Jidane 13-04-2006 : CY31 (add LDRY_ECMWF : R with or without q varaibles)
!   JJMorcrette 20060512 GEMS variables in cy31
!   B. Sass introduce HIRLAM field YQVA
!   F. Vana 08-Jun-2006 - proper SLHD setup for stretched geometry
!   20-Mar-2006 A. Alias - introduction of YSDSAT and YCVV
!   K. Yessad 15-May-2006: memory optimisations for stretched geometry
!   03-Jul-2006 S. Ivatek-Sahdan: set default LDRY_ECMWF=F for arp/ald
!   F. Bouyssel, F. Vana 30-Oct-2006 - change SLHD setup for stretched geometry
!   25-Jul-2006 A. Alias - bugfix in CSLINT setup of YSDSAT and YCVV
!   29-Sep-2006 M. Bellus: Add prognostic convection variables (ALARO-0)
!   31-Jan-2007 K. Yessad: Modularisation (GFL attributes) and big cleaning.
!   07-Mar-2007 K. Yessad: Remove LREPHD and LVERAVE_HLUV.
!   28-Aug-2007 F. Vana: Remove LRSPLINE_[x] and better setup for supp. diff.
!   K. Yessad Aug-2007: allow to relax the C1 constraint (NDLNPR=0) in NH
!   M. Drusch     22-Jan-2007 introduce nconf 302
!   J. Vivoda and K. Yessad Oct-2007: VFE for NH model
!   N. Wedi and K. Yessad (Jan 2008): different dev for NH model and PC scheme
!   30-Jun-2008 J. Masek   New SLHD interpolators.
!   01-Jun-2008 F. Vana: Timestep check (to recycle SUTSTEP)
!   K. Yessad (Sep 2008): prune enhanced diffusion (lfrein), remove lpc_xidt.
!   F. Vana  13-Jan-2008: corrected setup for SLHD (including TL/AD)
! End Modifications
!------------------------------------------------------------------------------

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

USE YOMPHY   , ONLY : LMPHYS
USE YOMARPHY , ONLY : LMPA
USE YOMARG   , ONLY : UTSTEP
USE YOMDIM   , ONLY : NFLEVG   ,NSMAX    ,NMSMAX
USE YOMGEM   , ONLY : VAH      ,NSTTYP   ,RSTRET   ,NGPTOT   ,VP00     ,RNLGINC
USE YOMLUN   , ONLY : NULNAM
USE YOMCT0   , ONLY : NCONF    ,LSLAG    ,LTWOTL   ,LNHDYN   ,&
 & LELAM    ,LSITRIC  ,NSTOP    ,LRUBC    ,LVERCOR  ,LPC_OLD  ,LPC_NESC ,&
 & LPC_NESCT,LPC_FULL ,N2DINI   ,LPC_CHEAP
USE YOMCT0B  , ONLY : LECMWF
USE YOMDYNA  , ONLY : LSLHD    ,LSLHD_STATIC,LGWADV   ,LSLHD_W  ,&
 & LSLHD_SVD,LNH_PDVD ,LNH_GEOGW,LRWSDLW  ,LRWSDLR  ,NPDVAR   ,&
 & SLHDKMIN ,SLHDKMAX ,LSLHDQUAD
USE YOMDYN   , ONLY : GMR      ,SCGMAP   ,SIVP     ,SITRUB   ,SIPRUB   ,&
 & NVLAG    ,NWLAG    ,NTLAG    ,NSPDLAG  ,NSVDLAG  ,NITMP    ,NSITER   ,&
 & NSREFDH  ,NDLNPR   ,TSTEP    ,TDT      ,REPS1    ,REPS2    ,REPSP1   ,&
 & LNEWHD   ,RRDXTAU  ,REXPDH   ,HDIRVOR  ,HDIRDIV  ,HDIRT    ,&
 & HDIRQ    ,HDIRO3   ,HDIRPD   ,HDIRVD   ,HDIRSP   ,HDTIME_STRHD       ,&
 & HRDIRVOR ,HRDIRDIV ,HRDIRT   ,HRDIRQ   ,HRDIRO3  ,HRDIRPD  ,HRDIRVD  ,&
 & HRDIRSP  ,HDSRDIV  ,HDSRVOR  ,HDSRVD   ,HRDSRDIV ,HRDSRVOR ,HRDSRVD  ,&
 & RDAMPDIV ,RDAMPVOR ,RDAMPT   ,RDAMPQ   ,RDAMPSP  ,RDAMPVD  ,RDAMPPD  ,&
 & RDAMPO3  ,BETADT   ,REFGEO   ,SIPR     ,SITR     ,SITRA    ,SITIME   ,&
 & SIRPRG   ,SIRPRN   ,FRANDH   ,SLEVDH   ,SLEVDH2  ,SLEVDH3  ,VNORM    ,&
 & VMAX1    ,VMAX2    ,VESL     ,REPSM1   ,REPSM2   ,RRFZ1    ,RRFPLM   ,&
 & RCMSLP0  ,XIDT     ,VETAON   ,VETAOX   ,LADVF    ,LIMPF    ,&
 & LQMW     ,LQMHW    ,LQMT     ,LQMHT    ,LQMP     ,LQMHP    ,LQMPD    ,&
 & LQMHPD   ,LQMVD    ,LQMHVD   ,L2TLFF   ,NRUBC    ,LSETTLS  ,&
 & LELTRA   ,RTEMRB   ,RHYDR0   ,&
 & VCAK     ,VCTR     ,VCPR     ,LADVFW   ,RW2TLFF  ,SLHDA0   ,SLHDA    ,&
 & SLHDB    ,SLHDD0   ,SLHDDIV  ,SLHDRATDDIV        ,SLHDHOR  ,LSTRHD   ,&
 & LSIDG    ,RDAMPHDS ,SDRED    ,REXPDHS  ,SLEVDHS  ,SLEVDHS2 ,RDAMPDIVS,&
 & RDAMPVORS,RDAMPVDS ,NCURRENT_ITER      ,NITERHELM,LSETTLST ,&
 & NCOMP_CVGQ ,LDRY_ECMWF,LRHDI_LASTITERPC       ,LSLINLC1 ,&
 & LSLINLC2 ,LSLINL   ,NITPRHS  ,RC_PD1
USE YOMCST   , ONLY : RD
USE YOMJG    , ONLY : LJBENER  ,SIBI
USE YOMPPC   , ONLY : LMOVPH
USE YOMWM    , ONLY : FTHSOR
USE YOEPHY   , ONLY : NEPHYS_PCFULL
USE YOMMASS  , ONLY : LMASDRY, LMASCOR, GMASSI
USE YOMINI   , ONLY : NEINI
USE YOMCVER  , ONLY : LVERTFE  ,LSVTSM   ,LRNHC1   ,LVFE_LAPL,LVFE_LAPL_BC,&
 & LVFE_X_TERM,LVFE_GW,LVFE_Z_TERM,LVFE_GWMPA,LVFE_DERIB,LVFE_DBCS,LVFE_DBCT,&
 & LVFE_DELNHPRE
USE YOMPONG  , ONLY : NSPONGE
USE TRAJECTORY_MOD, ONLY: TSTEP_TRAJ, NSMAX_TRAJ, NSMAX_BACKGR00, NSMAX_BACKGR01, &
 & NSMAX_BACKGR02, NSMAX_BACKGR03
USE YOMSEP   , ONLY : NVSEPC   ,NVSEPL
USE YOMSLD   , ONLY : SLHDP
USE YOM_YGFL , ONLY : YQ       ,YQ_NL    ,YCVGQ
USE YOMGC    , ONLY : GM
USE YOEWCOU  , ONLY : LWCOU
USE YOMLDDH  , ONLY : LSDDH
USE TESTVAR_MIX  , ONLY : SETUP_TESTVAR

!     ------------------------------------------------------------------
IMPLICIT NONE

INTEGER(KIND=JPIM),INTENT(IN)    :: KULOUT 

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

LOGICAL :: LL2D
LOGICAL :: LL2TLFFX_NOVC
LOGICAL :: LL2TLFFX_VC
LOGICAL :: LL2TLFFX
LOGICAL :: LLN2HYD
LOGICAL :: LL2DPLANE
LOGICAL :: LLSTRSG ! .T. => spherical stretched geometry.
LOGICAL :: LLCOMPUTE_CVGQ
LOGICAL :: LPSLHDN  ! .T. preserves SLHD norms with situation before CY31t2

REAL(KIND=JPRB) :: ZEPS, ZSLHDP1, ZSLHDP3, ZLXY, ZTSTEP, ZNOTUSED
REAL(KIND=JPRB) :: SLHDD00

REAL(KIND=JPRB) :: ZHOOK_HANDLE

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

#include "abor1.intfb.h"
#include "posnam.intfb.h"
#include "sualdynb.intfb.h"
#include "sudyn_setgflattr.intfb.h"
#include "suehdf.intfb.h"
#include "sueldynb.intfb.h"
#include "suhdf.intfb.h"
#include "suhdir.intfb.h"
#include "suhdu.intfb.h"
#include "suheg.intfb.h"
#include "sunhsi.intfb.h"
#include "susavtend.intfb.h"
#include "surcordi.intfb.h"
#include "surayfric.intfb.h"
#include "susi.intfb.h"
#include "susmap.intfb.h"
#include "suspgm.intfb.h"
#include "susta.intfb.h"
#include "sustadlr.intfb.h"
#include "sutstep.intfb.h"

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

#include "namdyn.h"

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

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

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

!*       1.    Set default values.
!              -------------------

ZNOTUSED=-9999._JPRB

IF (NCONF/100 == 2.OR. NCONF/10 == 42.OR.NCONF/10  == 52) THEN
  LL2D = .TRUE.
ELSE
  LL2D = .FALSE.
ENDIF

LL2DPLANE = NSMAX==0.OR.NMSMAX==0

!*       1.01  Time step.

IF (UTSTEP > 0) THEN
  TSTEP=UTSTEP
ELSE
  IF(NSMAX == 639) THEN
    IF(LSLAG) THEN
      IF (LTWOTL) THEN
        TSTEP=600._JPRB
      ELSE
        TSTEP=300._JPRB
      ENDIF
    ELSE
      TSTEP=100._JPRB
    ENDIF
  ELSEIF(NSMAX == 319) THEN
    IF(LSLAG) THEN
      IF (LTWOTL) THEN
        TSTEP=1200._JPRB
      ELSE
        TSTEP=600._JPRB
      ENDIF
    ELSE
      TSTEP=300._JPRB
    ENDIF
  ELSEIF(NSMAX == 213) THEN
    IF(LSLAG) THEN
      IF (LTWOTL) THEN
        TSTEP=1200._JPRB
      ELSE
        TSTEP=600._JPRB
      ENDIF
    ELSE
      TSTEP=300._JPRB
    ENDIF
  ELSEIF(NSMAX == 159) THEN
    IF(LSLAG) THEN
      IF (LTWOTL) THEN
        TSTEP=3600._JPRB
      ELSE
        TSTEP=1800._JPRB
      ENDIF
    ELSE
      TSTEP=600._JPRB
    ENDIF
  ELSEIF(NSMAX == 106) THEN
    IF(LSLAG) THEN
      IF (LTWOTL) THEN
        TSTEP=3600._JPRB
      ELSE
        TSTEP=1800._JPRB
      ENDIF
    ELSE
      TSTEP=900._JPRB
    ENDIF
  ELSEIF(NSMAX == 95) THEN
    IF(LSLAG) THEN
      IF (LTWOTL) THEN
        TSTEP=3600._JPRB
      ELSE
        TSTEP=1800._JPRB
      ENDIF
    ELSE
      TSTEP=1350._JPRB
    ENDIF
  ELSEIF(NSMAX == 63) THEN
    IF(LSLAG) THEN
      IF (LTWOTL) THEN
        TSTEP=3600._JPRB
      ELSE
        TSTEP=1800._JPRB
      ENDIF
    ELSE
      TSTEP=1350._JPRB
    ENDIF
  ELSEIF(NSMAX < 63) THEN
    IF(LSLAG) THEN
      IF (LTWOTL) THEN
        TSTEP=3600._JPRB
      ELSE
        TSTEP=1800._JPRB
      ENDIF
    ELSE
      TSTEP=1800._JPRB
    ENDIF
  ENDIF
  IF (NCONF > 899) TSTEP=1._JPRB
ENDIF

TSTEP_TRAJ=-1._JPRB  ! TSTEP can still be modified

!*       1.02  Truncation for trajectory and background.

NSMAX_TRAJ=NSMAX
NSMAX_BACKGR00=NSMAX
NSMAX_BACKGR01=NSMAX
NSMAX_BACKGR02=NSMAX
NSMAX_BACKGR03=NSMAX

!*       1.03  Temporal filter.

IF(LECMWF) THEN
  REPS1=.1_JPRB
  REPS2=.1_JPRB
  REPSP1=.1_JPRB
  REPSM1=.1_JPRB
  REPSM2=.1_JPRB
ELSE
  IF (LSLAG.AND.LTWOTL) THEN
    REPS1=0._JPRB
    REPS2=0._JPRB
    REPSP1=0._JPRB
    REPSM1=0._JPRB
    REPSM2=0._JPRB
  ELSE
    REPS1=.05_JPRB
    REPS2=.05_JPRB
    REPSP1=.05_JPRB
    REPSM1=.05_JPRB
    REPSM2=.05_JPRB
  ENDIF
ENDIF

!*       1.04a Spectral horizontal diffusion.

IF(LECMWF) THEN
  LNEWHD=.FALSE.
  REXPDH=4._JPRB
  FRANDH=0._JPRB
  RRDXTAU=57.32_JPRB
  RDAMPDIV= 1._JPRB
  RDAMPVOR= 1._JPRB
  RDAMPT=1._JPRB
  RDAMPQ=1._JPRB
  RDAMPSP=0._JPRB
  RDAMPO3=0._JPRB
  RDAMPVD=1._JPRB
  RDAMPPD=1._JPRB
  IF(.NOT.LSLAG) THEN
    RRDXTAU=143.3_JPRB
    RDAMPVOR=2.5_JPRB
    RDAMPT  =2.5_JPRB
    RDAMPQ  =2.5_JPRB
  ENDIF
ELSE
  LNEWHD=.FALSE.
  REXPDH=4._JPRB
  FRANDH=0._JPRB
  RRDXTAU=123._JPRB
  RDAMPDIV= 1._JPRB
  RDAMPVOR= 5._JPRB
  RDAMPT=5._JPRB
  RDAMPQ=5._JPRB
  RDAMPSP=0._JPRB
  RDAMPO3=0._JPRB
  IF(LNHDYN) THEN
    RDAMPVD=1._JPRB
    RDAMPPD=5._JPRB
  ELSE
    RDAMPVD=0._JPRB
    RDAMPPD=0._JPRB
  ENDIF
ENDIF

! Security for new HD setting through namelist 
HDIRVOR= ZNOTUSED
HDIRDIV= ZNOTUSED
HDIRT  = ZNOTUSED
HDIRQ  = ZNOTUSED
HDIRO3 = ZNOTUSED
HDIRSP = ZNOTUSED
HDIRPD = ZNOTUSED
HDIRVD = ZNOTUSED

SLEVDH=1._JPRB
SLEVDH2=0.01_JPRB
SLEVDH3=100._JPRB/VP00 ! to be tuned later.
NSREFDH=NSMAX

!*       1.04b Semi Lagrangian diffusion (SLHD)

! * RDAMP[X]S:
RDAMPDIVS= 0._JPRB
RDAMPVORS= 0._JPRB
RDAMPVDS = 0._JPRB
RDAMPHDS = 1._JPRB
IF(LSLHD_W .OR. LSLHD_SVD) RDAMPHDS= 1.5_JPRB - RNLGINC * 0.5_JPRB
IF(LSLHD_W) THEN
  RDAMPDIVS= 1._JPRB
  RDAMPVORS= 5._JPRB
ENDIF
IF(LSLHD_SVD) RDAMPVDS = 15._JPRB

! * Reset RDAMPQ to zero if SLHD is applied on moisture.
IF(YQ_NL%LSLHD) RDAMPQ= 0._JPRB

! * Other quantities:
SLHDA0  =  0.25_JPRB
SLHDB   =  4.0_JPRB
SLHDDIV =  0.0_JPRB
SLHDRATDDIV = 1._JPRB
SLHDHOR     = 0._JPRB
REXPDHS =  6.0_JPRB
SLEVDHS=0.25_JPRB
SLEVDHS2=0.01_JPRB
SDRED=1._JPRB

! The following ones are local in SUDYN and are also present in NAMDYN.
ZSLHDP1 = 1.7_JPRB
ZSLHDP3 = 0.6_JPRB
SLHDD00 = 0.000065_JPRB
LPSLHDN=.FALSE.  ! Doesn't maintain continuity with situation before CY31T2

!*       1.04c Reset some horizontal diffusion coefficients for ECMWF
!              applications (remark: .NOT.LNEWHD is obsolescent and
!              all applications must switch on LNEWHD=T as soon as possible).

IF (LECMWF.AND.(.NOT.LNEWHD)) CALL SUHDIR

!*       1.07  Dynamical quantities:
!         - SI scheme: BETADT,REFGEO,SIPR,SITR,SITRA,NITERHELM,LRNHC1
!         - Coriolis term: LADVF,LIMPF
!         - Advec scheme, SL traj: LELTRA,RW2TLFF,LSETTLST,LSETTLS,NITMP,
!           RCMSLP0,LSVTSM
!         - Uncentering: XIDT,VESL
!         - 2D NH model: LLN2HYD
!         - Discretisation of eqns in SL scheme: N[X]LAG
!         - Change of variable: RC_PD1

REFGEO=100000._JPRB

BETADT=1._JPRB

IF (LECMWF) THEN
  LLN2HYD=.TRUE.
  IF (LL2D) THEN
    XIDT=0.0_JPRB
    LELTRA=.FALSE.
    LADVF=.FALSE.
    RW2TLFF=0.0_JPRB
    LIMPF=.TRUE.
    LSETTLST=LTWOTL
    LSETTLS=LTWOTL
    NITMP=2
  ELSE
    XIDT=0.05_JPRB
    LELTRA=.FALSE.
    RW2TLFF=1.0_JPRB
    LSETTLST=LTWOTL
    LSETTLS=LTWOTL
    IF(LSLAG.AND.LTWOTL) THEN
      LIMPF=.TRUE.
      LADVF=.FALSE.
    ELSE
      LIMPF=.FALSE.
      LADVF=.TRUE.
    ENDIF
    IF (LSETTLST.AND.(NCONF == 1.OR.NCONF == 302)) THEN
      NITMP=3
    ELSE
      NITMP=2
    ENDIF
  ENDIF
  VESL=0._JPRB
  IF (LSLAG) THEN
    RCMSLP0=1._JPRB
  ELSE
    RCMSLP0=0._JPRB
  ENDIF
  IF (LNHDYN) THEN
    IF (LSLAG.AND.LTWOTL) THEN
      ! * for models with top in the mesosphere (above 1hPa)
      IF (0.5_JPRB*VAH(1) < 100.0_JPRB.OR.LVERTFE) THEN
        SITR=350._JPRB
      ELSE
        SITR=300._JPRB
      ENDIF
    ELSE
      SITR=300._JPRB
    ENDIF
    SIPR=85000._JPRB
    SITRA=100._JPRB
    XIDT=0._JPRB
  ELSE
    IF (LSLAG.AND.LTWOTL) THEN
      ! * for models with top in the mesosphere (above 1hPa)
      IF (0.5_JPRB*VAH(1) < 100.0_JPRB.OR.LVERTFE) THEN
        SITR=350._JPRB
        SIPR=100000._JPRB
        XIDT=0._JPRB
      ELSE
        SITR=300._JPRB
        SIPR=100000._JPRB
      ENDIF
    ELSE
      SITR=300._JPRB
      SIPR=80000._JPRB
    ENDIF
    ! ky: SITRA is not used in this case.
    SITRA=SITR
  ENDIF
ELSE
  LIMPF=.FALSE.
  LLN2HYD=.FALSE.
  LELTRA=.FALSE.
  IF (LSLAG.AND.LTWOTL.AND.(.NOT.LL2D)) THEN
    ! * SL2TL scheme, 3D model.
    LADVF=.TRUE.
    RW2TLFF=1._JPRB
    LSETTLST=.TRUE.
    LSETTLS=.TRUE.
    NITMP=3
    RCMSLP0=1._JPRB
    XIDT=0.05_JPRB
    VESL=0._JPRB
    SITR=300._JPRB
    SITRA=50._JPRB
    SIPR=100000._JPRB
  ELSEIF (LSLAG.AND.LTWOTL.AND.LL2D) THEN
    ! * SL2TL scheme, 2D model.
    LADVF=.TRUE.
    RW2TLFF=0._JPRB
    LSETTLST=.TRUE.
    LSETTLS=.TRUE.
    NITMP=3
    RCMSLP0=1._JPRB
    XIDT=0._JPRB
    VESL=0.1_JPRB
    SITR=350._JPRB
    ! ky: SITRA is not used in this case.
    SITRA=SITR
    SIPR=100000._JPRB
  ELSEIF (LSLAG.AND.(.NOT.LTWOTL)) THEN
    ! * SL3TL scheme.
    LADVF=.FALSE.
    RW2TLFF=0._JPRB
    LSETTLST=.FALSE.
    LSETTLS=.FALSE.
    NITMP=3
    RCMSLP0=1._JPRB
    XIDT=0._JPRB
    VESL=0.1_JPRB
    SITR=350._JPRB
    SITRA=100._JPRB
    SIPR=100000._JPRB
  ELSE
    ! * Eulerian scheme.
    LADVF=.FALSE.
    RW2TLFF=0._JPRB
    LSETTLST=.FALSE.
    LSETTLS=.FALSE.
    NITMP=0
    RCMSLP0=0._JPRB
    XIDT=0._JPRB
    VESL=0._JPRB
    SITR=300._JPRB
    SITRA=100._JPRB
    SIPR=80000._JPRB
  ENDIF
ENDIF

NVLAG=3
NTLAG=3
NWLAG=3
NSPDLAG=3
NSVDLAG=3

! * Smoothing of the vertical velocity in the trajectory computation 
!   in pure pressure levels.
IF(LECMWF) THEN
  IF(NSMAX > 500 .AND. (NCONF == 1.OR.NCONF == 302)) THEN
    LSVTSM=.TRUE.
  ELSE
    LSVTSM=.FALSE.
  ENDIF
ELSE
  LSVTSM=.FALSE.
ENDIF

NITERHELM=0
LRNHC1=.FALSE.

IF (LNHDYN.AND.(NPDVAR==2).AND.LRWSDLR) THEN
  RC_PD1=1.0_JPRB
ELSE
  RC_PD1=0.0_JPRB
ENDIF

!*       1.08  Semi-Lagrangian interpolators for GMV and GMVS variables.
!              - Quasi-monotonic interpolations: LQM[X], LQMH[X].

IF (LSLAG.AND.(NCONF == 1.OR.NCONF == 302)) THEN
  LQMHW = .TRUE.
  LQMHT = .TRUE.
  LQMP  = .TRUE.
ELSEIF ((.NOT.LECMWF).AND.LSLAG.AND.NCONF == 131) THEN
  LQMHW = .TRUE.
  LQMHT = .TRUE.
  LQMP  = .TRUE.
ELSE
  LQMHW = .FALSE.
  LQMHT = .FALSE.
  LQMP  = .FALSE.
ENDIF

LQMW  = .FALSE.
LQMT  = .FALSE.
LQMHP = .FALSE.
LQMPD = .FALSE.
LQMHPD= .FALSE.
LQMVD = .FALSE.
LQMHVD= .FALSE.


!*       1.09  ICI (PC) schemes.

NCURRENT_ITER=0
NSITER=0
LRHDI_LASTITERPC=.FALSE.

!*       1.10  Control the length of the SL trajectory.

IF(NFLEVG >= 91) THEN
  VMAX1=250._JPRB
  VMAX2=400._JPRB
ELSE
  VMAX1=220._JPRB
  VMAX2=280._JPRB
ENDIF

VETAON=1.0_JPRB
VETAOX=1.0_JPRB

!*       1.11  NDLNPR and NH model specific options.

RHYDR0=1._JPRB
NDLNPR=0
NRUBC=0
IF (LRUBC) THEN
  RTEMRB=280._JPRB
  SITRUB=0._JPRB
  SIPRUB=0._JPRB
  NDLNPR=1
  NRUBC=1
ENDIF
LVFE_LAPL=LVERTFE.AND.LNHDYN
LVFE_LAPL_BC=LVERTFE.AND.LNHDYN
LVFE_X_TERM=LVERTFE
LVFE_GW=LVERTFE
LVFE_Z_TERM=LVERTFE.AND.LNHDYN
LVFE_DELNHPRE=LVERTFE.AND.LNHDYN
LVFE_GWMPA=.FALSE.
LVFE_DERIB=.FALSE.
LVFE_DBCS=.FALSE.
LVFE_DBCT=.FALSE.

!*       1.12  Deep-layer equation model.

VCPR=VP00
IF (LVERCOR) THEN
  VCAK=1._JPRB
  VCTR=288.15_JPRB
  LADVFW=(LADVF.OR.LIMPF)
ELSEIF (LRWSDLW.AND.(.NOT.LRWSDLR)) THEN
  VCAK=0._JPRB
  VCTR=0._JPRB
  LADVFW=.FALSE.
ELSEIF (LRWSDLW.AND.LRWSDLR) THEN
  VCAK=0._JPRB
  VCTR=0._JPRB
  LADVFW=(LADVF.OR.LIMPF)
ELSEIF ((.NOT.LRWSDLW).AND.LRWSDLR) THEN
  VCAK=0._JPRB
  VCTR=0._JPRB
  LADVFW=.FALSE.
ELSE
  VCAK=0._JPRB
  VCTR=0._JPRB
  LADVFW=.FALSE.
ENDIF

IF (LRWSDLR) THEN
  NITPRHS=8
ELSE
  NITPRHS=0
ENDIF

!*       1.13 Physical fields for animation.

IF (LMOVPH) THEN
  ALLOCATE(FTHSOR(NGPTOT))
  WRITE(KULOUT,9990) 'FTHSOR   ',SIZE(FTHSOR   ),SHAPE(FTHSOR   )
  FTHSOR=0._JPRB
ENDIF

!*       1.14  Initial values for safe vertical separation for updates
!              (vectorization of adjoint semi-Lagrangian scheme).

NVSEPC=4
NVSEPL=2

!*       1.15  Computation of moisture convergence CVGQ.

! Initialisation of NCOMP_CVGQ : switch for computation of Moisture Convergence 
! for french deep convection scheme
!   0 ==> YQ must be spectral and derivative are used 
!   1 ==> YQ unspecified and YCVGQ spectral 
!   2 ==> YQ unspecified and YCVGQ grid point, SL computation are performed
NCOMP_CVGQ=0

!*       1.16  Miscellaneous quantities.

LMASCOR = .FALSE.
LMASDRY = .FALSE.
GMASSI  = 0.0_JPRB
IF (LECMWF) THEN
  LDRY_ECMWF=.TRUE.
  VNORM = 0.04_JPRB
ELSE
  LDRY_ECMWF=.FALSE.
  VNORM = 1._JPRB  
ENDIF

IF (LELAM) THEN
  LJBENER=.FALSE.
ENDIF

!*       1.18  Rayleigh friction (if active)

!  Defaults still same as 36r1, to be revised later.
!  Suggested values: RRFZ1=68, RRFPLM=100

RRFZ1=61._JPRB
RRFPLM=990._JPRB

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

!*       2.    Modify default values.
!              ----------------------

!        2.1   Read namelist.

CALL POSNAM(NULNAM,'NAMDYN')
READ(NULNAM,NAMDYN)

!        2.2   Overwrite namelist with command line arguments

IF (UTSTEP > 0) THEN
  IF (TSTEP /= UTSTEP) THEN
    TSTEP=UTSTEP
    WRITE(KULOUT,*) 'TSTEP   OVERWRITTEN BY COMAND LINE'
  ENDIF
ENDIF

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

!*       3.    Reset variables and test.
!              -------------------------

!*       3.01  Timestep and truncation (model, traj, background).

! This should go in suvar but it seems that
! TSTEP is not known yet when suvar is called...

IF (TSTEP_TRAJ<0) TSTEP_TRAJ=TSTEP

WRITE(KULOUT,*)'SUDYN: TSTEP_TRAJ,TSTEP=',TSTEP_TRAJ,TSTEP
IF (TSTEP /= 0._JPRB) THEN
  IF (MOD(TSTEP_TRAJ,TSTEP)/=0) &
   & CALL ABOR1('SUDYN: TSTEP_TRAJ has to be a multiple of TSTEP')  
ENDIF
WRITE(KULOUT,*)'SUDYN: NSMAX_TRAJ,NSMAX=',NSMAX_TRAJ,NSMAX
IF (NSMAX_TRAJ>NSMAX) CALL ABOR1('SUDYN: nsmax_traj>nsmax not possible')
WRITE(KULOUT,*) &
 & 'SUDYN: NSMAX_BACKGR00, NSMAX_BACKGR01, NSMAX_BACKGR02, NSMAX_BACKGR03=',&
 & NSMAX_BACKGR00, NSMAX_BACKGR01, NSMAX_BACKGR02, NSMAX_BACKGR03

! This should go in suvar but it seems that
! TSTEP is not known yet when suvar is called...
CALL SETUP_TESTVAR

TDT=TSTEP

! Timestep check for dummies (only warning, for the moment)
CALL SUTSTEP(ZTSTEP)
IF (TSTEP/ZTSTEP > 1.5_JPRB) THEN
  WRITE (KULOUT,'(A)') &
   & ' *************************************************************** '
  WRITE (KULOUT,'(A,F10.2)') &
   & '   SUDYN WARNING: Your timestep is          : ',TSTEP
  WRITE (KULOUT,'(A,F10.2)') &
   & '                  The recomended timestep is: ',ZTSTEP
  WRITE (KULOUT,'(A)') &
   & '      Are you really sure about this your choice?! '
  WRITE (KULOUT,'(A)') &
   & ' *************************************************************** '
ENDIF



!*       3.02  Stretched geometry specific features.

ZEPS=100.0_JPRB*TINY(1.0_JPRB)
LLSTRSG=(.NOT.LELAM).AND.(ABS(RSTRET-1.0_JPRB)>ZEPS)
LSTRHD=LLSTRSG.AND.(NCONF<900)
LSIDG=LLSTRSG.AND.(NCONF<900).AND.(NSTOP > 0.OR.NEINI /= 0)

!*       3.03  NH 2D model.

IF(LLN2HYD) THEN
  IF(NFLEVG == 90) THEN
    RHYDR0=0.163_JPRB
  ELSE
    RHYDR0=LOG(2.0_JPRB)
  ENDIF
ENDIF

!*       3.04  Semi-implicit scheme reference profiles.

SIRPRG=RD*SITR
SIRPRN=1.0_JPRB/SIPR

! * Use negative value or zero value for REFGEO?
IF (REFGEO <= 0.0_JPRB) THEN
  CALL ABOR1(' SUDYN : REFGEO MUST BE GREATER THAN 0.')
ENDIF

!*       3.05  Horizontal diffusion scheme.

! * Check NSREFDH, SLEVDH.. quantities, and reset SLEVDH2 and SLEVDHS2
!   when relevant:
IF (NSREFDH == NSMAX) THEN
  SLEVDH2=SLEVDH
  SLEVDHS2=SLEVDHS
ENDIF
IF ((NSREFDH /= NSMAX) .AND. LELAM) THEN
  ! * Use (NSREFDH /= NSMAX) in ALADIN (not coded)?
  WRITE(KULOUT,*) 'Case NSREFDH /= NSMAX is not coded in ALADIN.'
  CALL ABOR1('SUDYN: ABOR1 CALLED')
ENDIF
IF ( (SLEVDH2 > SLEVDH) .OR. (SLEVDHS2 > SLEVDHS) ) THEN
  ! * Use (SLEVDH2 > SLEVDH) or (SLEVDHS2 > SLEVDHS) (not coded)?
  WRITE(KULOUT,*) 'SLEVDH2 must be <= SLEVDH.'
  WRITE(KULOUT,*) 'SLEVDHS2 must be <= SLEVDHS.'
  CALL ABOR1('SUDYN: ABOR1 CALLED')
ENDIF

! * HDIR[X], HRDIR[X], HDSR[X], HRDSR[X].
IF ((LECMWF .AND. LNEWHD) .OR. (.NOT. LECMWF)) THEN
  IF((HDIRVOR /= ZNOTUSED).OR.(HDIRDIV /= ZNOTUSED) .OR. &
   & (HDIRT   /= ZNOTUSED).OR.(HDIRQ   /= ZNOTUSED) .OR. &
   & (HDIRO3  /= ZNOTUSED).OR.(HDIRSP  /= ZNOTUSED) .OR. &
   & (HDIRVD  /= ZNOTUSED).OR.(HDIRPD  /= ZNOTUSED)) THEN
    WRITE(KULOUT,*) &
     & 'SUDYN WARNING: The spectral diffusion in this case ', &
     & 'is not any more driven by namelist parameters HDIR[x] !!! ', &
     & 'Please remove them from your namelist and use new set-up.'
    CALL ABOR1('SUDYN: ABOR1 CALLED')
  ENDIF
  CALL SUHDIR
ELSE
  IF(HDIRVOR /= 0._JPRB) THEN
    HRDIRVOR = 1._JPRB/HDIRVOR
  ELSE
    HRDIRVOR = 0._JPRB
  ENDIF
  IF(HDIRDIV /= 0._JPRB) THEN
    HRDIRDIV = 1._JPRB/HDIRDIV
  ELSE
    HRDIRDIV = 0._JPRB
  ENDIF
  IF(HDIRT   /= 0._JPRB) THEN
    HRDIRT   = 1._JPRB/HDIRT  
  ELSE
    HRDIRT   = 0._JPRB
  ENDIF
  IF(HDIRQ   /= 0._JPRB) THEN
    HRDIRQ   = 1._JPRB/HDIRQ  
  ELSE
    HRDIRQ   = 0._JPRB
  ENDIF
  IF(HDIRO3  /= 0._JPRB) THEN
    HRDIRO3  = 1._JPRB/HDIRO3 
  ELSE
    HRDIRO3  = 0._JPRB
  ENDIF
  IF(HDIRSP  /= 0._JPRB) THEN
    HRDIRSP  = 1._JPRB/HDIRSP 
  ELSE
    HRDIRSP  = 0._JPRB
  ENDIF
  IF(HDIRVD  /= 0._JPRB) THEN
    HRDIRVD  = 1._JPRB/HDIRVD 
  ELSE
    HRDIRVD  = 0._JPRB
  ENDIF
  IF(HDIRPD  /= 0._JPRB) THEN
    HRDIRPD  = 1._JPRB/HDIRPD 
  ELSE
    HRDIRPD  = 0._JPRB
  ENDIF
  ! for the time being, no SLHD in this case
  HDSRDIV=0._JPRB
  HDSRVOR=0._JPRB
  HDSRVD =0._JPRB
  HRDSRDIV=0._JPRB
  HRDSRVOR=0._JPRB
  HRDSRVD =0._JPRB
ENDIF

! * Warning: with ECMWF, LNEWHD=.F., nam. param. RRDXTAU is ignored
IF (LECMWF.AND..NOT.LNEWHD) THEN
  WRITE(KULOUT,*) 'WARNING: LNEWHD=.F. => RRDXTAU IGNORED (IF SET)'
ENDIF


! * SLHD

WRITE(UNIT=KULOUT,FMT='(A)')    ' After SUDYNA and GFL attribute %LSLHD check:'
WRITE(UNIT=KULOUT,FMT='(A,L1)') '==> final value LSLHD = ',LSLHD
WRITE(UNIT=KULOUT,FMT='(A,L1)') '==> LSLHDQUAD = ',LSLHDQUAD


! * Check consistency of LSLHD key

! Use SLHD scheme with Eulerian advection?
IF (LSLHD.AND.(.NOT.LSLAG)) THEN
  WRITE(KULOUT,*) ' SUDYN: SLHD scheme acts only with SL advection!'
  CALL ABOR1(' SUDYN: ABOR1 CALLED')
ENDIF

! Use unavailable option LSLHD=T for ECMWF options for hor. diffusion?
IF (LSLHD.AND.(LECMWF.AND.(.NOT. LNEWHD))) THEN
  WRITE(KULOUT,*) ' SUDYN: SLHD can be currently used for modern HD setup only!'
  CALL ABOR1(' SUDYN: ABOR1 CALLED')
  ! ky: in this case it is still missing the modification of the
  !     spectral diffusion (mainly in SUHDF) to be brought to reduce the
  !     intensity of the spectral diffusion.
ENDIF

! Use SLHD in global model?
IF (LSLHD.AND.(.NOT.LELAM)) THEN
  WRITE(KULOUT,*) ' SUDYN: Warning!'
  WRITE(KULOUT,*) '   The setup of SLHD has not yet completely been'
  WRITE(KULOUT,*) '   updated for spherical geometry.'
ENDIF

! Use nonzero SLHDKMIN outside of SLHD scheme?
IF ((.NOT.LSLHD).AND.(SLHDKMIN /= 0)) THEN
  WRITE(KULOUT,*) ' SUDYN: Warning!'
  WRITE(KULOUT,*) '   Nonzero SLHDKMIN redefines high order SL interpolator'
  WRITE(KULOUT,*) '   even if SLHD scheme is off.'
ENDIF

! Use SLHD with SLHDKMIN > SLHDKMAX?
IF (LSLHD.AND.(SLHDKMIN > SLHDKMAX)) THEN
  WRITE(KULOUT,*) ' SUDYN: SLHDKMIN must not be greater than SLHDKMAX!'
  CALL ABOR1(' SUDYN: ABOR1 CALLED')
ENDIF

! * Check SLHD:
IF (LSLHD) THEN
  ! * Use SDRED out of interval [0;1]?
  IF ((SDRED < 0.0_JPRB ).OR.(SDRED > 1.0_JPRB )) THEN
    WRITE(KULOUT,*) &
     & 'SUDYN WARNING: SDRED should be within interval <0,1> !'  
    CALL ABOR1('SUDYN: ABOR1 CALLED')
  ENDIF
  IF (.NOT.LELAM .AND. LSLHD_SVD .AND. (RDAMPVDS /= 0._JPRB)) THEN
    WRITE(KULOUT,*) &
     & 'SUDYN WARNING!: When LNHDYN and SLHD are TRUE on sphere',&
     & 'the supporting diffusion of SVD is not coded yet!'
  ENDIF
ENDIF

! * Quasi-horizontal triggering in TL/AD model
!   (Note that the LSLHD can be still redefined in SUCTRL_GFLATTR,
!    thus some bizzare settings might pass through this security.)
IF (LSLHD.AND.(SLHDHOR /= 0._JPRB).AND.(NCONF == 131.OR.NCONF == 401 &
 &  .OR.NCONF == 501.OR.NCONF == 601.OR.NCONF == 801).AND. &
 &  (.NOT.LSLHD_STATIC)) THEN
  WRITE(KULOUT,*) ' SUDYN: TL/AD versions of SLHD are coded only for SLHDHOR=0.'
  CALL ABOR1(' SUDYN: ABOR1 CALLED')
ENDIF

!*       3.07  Advection, SL scheme, Coriolis term.
!         - Coriolis term: LADVF,LIMPF
!         - Advec scheme, SL traj: LELTRA,RW2TLFF,LSETTLST,LSETTLS,NITMP,
!           RCMSLP0,LSVTSM
!         - Discretisation of eqns in SL scheme: N[X]LAG
!         - Option LSITRIC in the SI scheme.

IF (LL2D) THEN

  ! * N[X]LAG out of bounds?
  IF ((NVLAG /= 2).AND.(NVLAG /= 3).AND.(NVLAG /= -2)) THEN
    WRITE(KULOUT,*) '2D MODEL. NVLAG MUST BE -2 OR 2 OR 3.'
    CALL ABOR1('SUDYN: ABOR1 CALLED')
  ENDIF
  IF ((NVLAG == -2).AND.LTWOTL) THEN
    WRITE(KULOUT,*) '2D MODEL. 2TLSL NOT CODED FOR NVLAG=-2.'
    CALL ABOR1('SUDYN: ABOR1 CALLED')
  ENDIF
  IF (NWLAG /= 2.AND.NWLAG /= 3) THEN
    WRITE(KULOUT,*) '2D MODEL. NWLAG MUST BE 2 OR 3.'
    CALL ABOR1('SUDYN: ABOR1 CALLED')
  ENDIF
  ! * Use LSETTLST=T when not coded?
  IF (LSETTLST.AND..NOT.LTWOTL) THEN
    WRITE(KULOUT,*) 'LSETTLST ONLY WORKS WITH LTWOTL'
    CALL ABOR1('SUDYN: ABOR1 CALLED')
  ENDIF
  ! * Use LSETTLS=T when not coded?
  IF (LSETTLS.AND..NOT.(NWLAG == 3.AND.NVLAG == 3.AND.LTWOTL)) THEN
    WRITE(KULOUT,*) 'LSETTLS ONLY WORKS WITH LTWOTL and NWLAG=NVLAG=3'
    CALL ABOR1('SUDYN: ABOR1 CALLED')
  ENDIF
  ! *  Proper use of LADVF/LIMPF?
  IF (LADVF.AND.LIMPF) THEN
    WRITE(KULOUT,*) 'LADVF and LIMPF CANNOT BOTH BE TRUE.'
    CALL ABOR1('SUDYN: ABOR1 CALLED')
  ENDIF
  ! IF ((LTWOTL.AND..NOT.LPC_FULL).AND..NOT.(LADVF.OR.LIMPF)) THEN
  !   WRITE(KULOUT,*) 'FOR 2TL, LADVF OR LIMPF MUST BE TRUE IF NO PC SCHEME.'
  !   CALL ABOR1('SUDYN: ABOR1 CALLED')
  ! ENDIF
  IF (LIMPF.AND.(NSTTYP /= 1.OR.LLSTRSG)) THEN
    WRITE(KULOUT,*) 'LIMPF CANNOT BE USED WITH TILTING OR',' STRETCHING.'
    CALL ABOR1('SUDYN: ABOR1 CALLED')
  ENDIF
  ! * Use RCMSLP0 /= 0 when not available?
  IF ((RCMSLP0 /= 0.0_JPRB).AND.(.NOT.LSLAG)) THEN
    WRITE(KULOUT,*) 'RCMSLP0 /= ZERO CAN BE USED ONLY FOR SL SCHEME.'
    CALL ABOR1('SUDYN: ABOR1 CALLED')
  ENDIF
  IF ((RCMSLP0 /= 0.0_JPRB).AND.LSLAG.AND.(NVLAG < 0)) THEN
    WRITE(KULOUT,*) 'RCMSLP0 /= ZERO CANNOT BE USED FOR LAGRANGIAN',&
     & ' FORMULATION OF CONTINUITY EQUATION.'  
    CALL ABOR1('SUDYN: ABOR1 CALLED')
  ENDIF

ELSE

  ! * N[X]LAG out of bounds?
  IF (NVLAG < 2.OR.NVLAG > 3) THEN
    WRITE(KULOUT,*) '3D MODEL. NVLAG MUST BE BETWEEN 2 AND 3.'
    CALL ABOR1('SUDYN: ABOR1 CALLED')
  ENDIF
  IF (NWLAG < 2.OR.NWLAG > 3) THEN
    WRITE(KULOUT,*) '3D MODEL. NWLAG MUST BE BETWEEN 2 AND 3.'
    CALL ABOR1('SUDYN: ABOR1 CALLED')
  ENDIF
  IF (NTLAG < 2.OR.NTLAG > 3) THEN
    WRITE(KULOUT,*) '3D MODEL. NTLAG MUST BE BETWEEN 2 AND 3.'
    CALL ABOR1('SUDYN: ABOR1 CALLED')
  ENDIF
  IF (LNHDYN.AND.(NSPDLAG < 2.OR.NSPDLAG > 3)) THEN
    WRITE(KULOUT,*) '3D MODEL. NSPDLAG MUST BE BETWEEN 2 AND 3.'
    CALL ABOR1('SUDYN: ABOR1 CALLED')
  ENDIF
  IF (LNHDYN.AND.(NSVDLAG < 2.OR.NSVDLAG > 3)) THEN
    WRITE(KULOUT,*) '3D MODEL. NSVDLAG MUST BE BETWEEN 2 AND 3.'
    CALL ABOR1('SUDYN: ABOR1 CALLED')
  ENDIF
  ! * Use LSETTLST=T when not coded?
  IF (LSETTLST.AND..NOT.LTWOTL) THEN  
    WRITE(KULOUT,*) 'LSETTLST ONLY WORKS WITH LTWOTL=T'
    CALL ABOR1('SUDYN: ABOR1 CALLED')
  ENDIF
  ! * Use LSETTLS=T when not coded?
  IF (LSETTLS.AND..NOT.(NWLAG == 3.AND.NTLAG == 3.AND.NVLAG == 3 &
     & .AND.LTWOTL)) THEN  
    WRITE(KULOUT,*) 'LSETTLS ONLY WORKS WITH NWLAG=NTLAG=NVLAG=3, LTWOTL=T'
    CALL ABOR1('SUDYN: ABOR1 CALLED')
  ENDIF
  IF (LNHDYN.AND.LSETTLS.AND..NOT.(NSPDLAG == 3.AND.NSVDLAG == 3 &
     & .AND.LTWOTL)) THEN  
    WRITE(KULOUT,*) 'LSETTLS ONLY WORKS WITH NSPDLAG=NSVDLAG=3, LTWOTL=T'
    CALL ABOR1('SUDYN: ABOR1 CALLED')
  ENDIF
  ! * Use .NOT.(LPC_NESC.OR.LSETTLS)=T when not coded?
  IF (LGWADV.AND.LSLAG.AND.LTWOTL.AND.(.NOT.(LPC_NESC.OR.LSETTLS))) THEN
    ! * Use SL2TL scheme with LPC_NESC=F and LSETTLS=F when LGWADV=true?
    WRITE(KULOUT,*) ' LGWADV=T requires LPC_NESC=T or LSETTLS=T in the SL2TL.'
    CALL ABOR1('SUDYN: ABOR1 CALLED')
    ! The not coded cases require additional interpolations for linear terms.
    ! LSETTLS=(SETTLS for total terms, NESC for linear terms).
  ENDIF
  ! *  Proper use of LADVF/LIMPF?
  IF (LADVF.AND.LIMPF) THEN
    WRITE(KULOUT,*) 'LADVF and LIMPF CANNOT BOTH BE TRUE.'
    CALL ABOR1('SUDYN: ABOR1 CALLED')
  ENDIF
  ! IF ((LTWOTL.AND..NOT.LPC_FULL).AND..NOT.(LADVF.OR.LIMPF).AND..NOT.LL2DPLANE)&
  !  & THEN
  !   WRITE(KULOUT,*) 'FOR 2TL, LADVF OR LIMPF MUST BE TRUE IF NO PC SCHEME.'
  !   CALL ABOR1('SUDYN: ABOR1 CALLED')
  ! ENDIF
  IF (LIMPF.AND.(NSTTYP /= 1.OR.LLSTRSG)) THEN
    WRITE(KULOUT,*) 'LIMPF CANNOT BE USED WITH TILTING OR',' STRETCHING.'
    CALL ABOR1('SUDYN: ABOR1 CALLED')
  ENDIF
  ! * Proper use of LSITRIC?
  IF (LSITRIC.AND.(LIMPF.OR.LSIDG)) THEN
    WRITE(KULOUT,*) 'LSITRIC MUST BE FALSE.'
    CALL ABOR1('SUDYN: ABOR1 CALLED')
  ENDIF
  ! * Use RCMSLP0 /= 0 when not available?
  IF ((RCMSLP0 /= 0.0_JPRB).AND.(.NOT.LSLAG)) THEN
    WRITE(KULOUT,*) 'RCMSLP0 /= ZERO CAN BE USED ONLY FOR SL SCHEME.'
    CALL ABOR1('SUDYN: ABOR1 CALLED')
  ENDIF

ENDIF

!*       3.08  Check settings of BETADT and XIDT.

! Reset VESL to zero when XIDT is non zero.
IF (LL2D) THEN
  XIDT=0._JPRB
  IF(N2DINI == 11) BETADT=0.0_JPRB
ELSE
  IF (LSLAG.AND.LTWOTL) THEN
    IF (XIDT > 0.0_JPRB) THEN
      WRITE(KULOUT,*) ' SUDYN: NON-ZERO XIDT IS REQUESTED,',&
       & ' SO VESL IS RESET TO ZERO.'  
      VESL=0._JPRB
    ENDIF
    IF (XIDT < 0.0_JPRB) THEN
      WRITE(KULOUT,*) ' SUDYN: XIDT<0. NOT ALLOWED,',&
       & ' SO XIDT IS RESET TO ZERO.'  
      XIDT=0._JPRB
    ENDIF
  ELSE
    XIDT=0._JPRB
  ENDIF
ENDIF

!*       3.09  Deep-layer equations.

! Check consistency of "VCAK", "VCTR" and LADVFW.
! LVERCOR = .TRUE.  ==> no additional change.
! LVERCOR = .FALSE. ==> VCAK and VCTR are reset to zero.
! LVERCOR=LRWSDLW=F ==> LADVFW is reset to .FALSE.
IF (.NOT.LVERCOR) THEN
  VCAK=0._JPRB
  VCTR=0._JPRB
ENDIF
IF (.NOT.(LVERCOR.OR.(LRWSDLW.AND.LRWSDLR))) THEN
  LADVFW=.FALSE.
ENDIF

IF (.NOT.LRWSDLR) NITPRHS=0

!*       3.10  RW2TLFF.

!      Check RW2TLFF and reset if necessary; compute L2TLFF:
!      Refined computation of 2*Omega*Vec*r can be activated only if:
!      - Semi-Lagrangian scheme.
!      - LADVF=T or LADVFW=T.
!      - NWLAG=3.

LL2TLFFX_NOVC= &
 & (RW2TLFF > 0._JPRB).AND.(.NOT.(LVERCOR.OR.LRWSDLW.OR.LRWSDLR)).AND.LADVF
LL2TLFFX_VC= &
 & (RW2TLFF > 0._JPRB).AND.(LVERCOR.OR.LRWSDLW.OR.LRWSDLR).AND.(LADVF.OR.LADVFW)
LL2TLFFX=LL2TLFFX_NOVC.OR.(LL2TLFFX_VC.AND.(NCONF == 1.OR.NCONF == 302))
IF (LSLAG.AND.(NWLAG == 3).AND.LL2TLFFX) THEN
  ! * cases where l2tlff=.true. is available and asked for.
  IF (NCONF == 1.OR.NCONF == 302) THEN
    ! - case where l2tlff=.true. and all values of rw2tlff are available.
    L2TLFF=.TRUE.
  ELSE
    ! - case where (l2tlff=.true.; rw2tlff=1.) is available, but not
    !   rw2tlff different from one if non-zero => reset RW2TLFF to one.
    L2TLFF=.TRUE.
    RW2TLFF=1.0_JPRB
  ENDIF
ELSE
  ! * cases where either l2tlff=.true. is not available or not asked for.
  L2TLFF=.FALSE.
  RW2TLFF=0.0_JPRB
ENDIF

!*       3.11  VNORM.

! * Use negative value or zero value for VNORM?
IF (VNORM <= 0.0_JPRB) THEN
  WRITE(UNIT=KULOUT,FMT=&
   & '('' WRONG CHOICE FOR THE SCALING OF VERTICAL EIGENMODES '')')  
  WRITE(KULOUT,*) 'VNORM must be > 0'
  CALL ABOR1('SUDYN : ABOR1 CALLED')
ENDIF

!*       3.12  ICI (PC) schemes.

! *  Use LPC_NESCT,LPC_NESC when not available?
IF( (LPC_NESCT.OR.LPC_NESC).AND..NOT.LPC_FULL )THEN
  WRITE(KULOUT,*) 'LPC_NESCT or LPC_NESC (nonetrapolating scheme)', &
   & ' HAS MEANING ONLY WITH PC SCHEME LPC_FULL'
  CALL ABOR1('SUDYN: ABOR1 CALLED')
ENDIF
IF( LPC_NESCT.AND.LSETTLST )THEN
  WRITE(KULOUT,*) 'LPC_NESCT cannot be used with LSETTLST'
  CALL ABOR1('SUDYN: ABOR1 CALLED')
ENDIF
IF( LPC_NESC.AND.LSETTLS )THEN
  WRITE(KULOUT,*) 'LPC_NESC cannot be used with LSETTLS'
  CALL ABOR1('SUDYN: ABOR1 CALLED')
ENDIF
! *  Use LPC_CHEAP when not available?
IF( LPC_CHEAP.AND..NOT.LPC_FULL )THEN
  WRITE(KULOUT,*) 'LPC_CHEAP (cheap PC_FULL scheme)', &
   & ' HAS MEANING ONLY WITH PC SCHEME LPC_FULL'
  CALL ABOR1('SUDYN: ABOR1 CALLED')
ENDIF
IF( LPC_CHEAP.AND..NOT.LSLAG )THEN
  WRITE(KULOUT,*) 'LPC_CHEAP IS CODED ONLY IN THE SL SCHEME'
  CALL ABOR1('SUDYN: ABOR1 CALLED')
ENDIF
IF( LPC_CHEAP.AND..NOT.LPC_NESC )THEN
  ! LPC_CHEAP is not coded for extrapolating schemes in the eqns RHS 
  !  (for LPC_NESC=F interpolated quantities are not the same ones
  !  at the predictor and corrector steps, and the LPC_CHEAP code
  !  currently assumes that they are identical; changes are to be expected
  !  at least in lattex.F90, lattex_dnt.F90, lattes.F90, lavabo.F90,
  !  lapineb.F90, larcinb.F90, suslb.F90, ptrslb1.F90 due to additional
  !  SL interpolations to code in the predictor step).
  WRITE(KULOUT,*) 'LPC_CHEAP WITH .NOT.LPC_NESC not yet coded'
  CALL ABOR1('SUDYN: ABOR1 CALLED')
ENDIF
! *  Use LPC_OLD when not available?
IF( LPC_OLD.AND..NOT.LNHDYN )THEN
  WRITE(KULOUT,*) &
   & 'Old D3 Predictor/Corrector (LPC_OLD) works for NH dynamics only'
  CALL ABOR1('SUDYN: ABOR1 CALLED')
ENDIF
! * Consistency between NSITER and (LPC_OLD or LPC_FULL or LRUBC):
IF (NSITER < 0) THEN
  WRITE(KULOUT,*) 'Negative value of NSITER is not allowed'
  CALL ABOR1('SUDYN: ABOR1 CALLED')
ENDIF
IF( NSITER==0.AND.((LPC_OLD.AND.LNHDYN).OR.LPC_FULL) )THEN
  WRITE(KULOUT,*) 'No iterations NSITER=0 but LPC_OLD or LPC_FULL is .T.'
  WRITE(KULOUT,*) 'A lot of meaningless allocations'
  CALL ABOR1('SUDYN: ABOR1 CALLED')
ENDIF
IF( NSITER>0.AND..NOT.((LPC_OLD.AND.LNHDYN).OR.LPC_FULL))THEN
  WRITE(KULOUT,*) 'dynamics with NSITER>0 needs LPC_OLD or LPC_FULL'          
  CALL ABOR1('SUDYN: ABOR1 CALLED')
ENDIF
IF(NSITER==0 .AND. LRUBC) THEN
  WRITE(KULOUT,*) 'When LRUBC=true, at least one PC scheme must be plugged on'
  CALL ABOR1('SUDYN: ABOR1 CALLED')
ENDIF
! * Check that one (and no more) PC scheme is plugged on.
IF( LPC_OLD.AND.LPC_FULL )THEN
  WRITE(KULOUT,*) 'Two versions of iterative scheme are ON'          
  CALL ABOR1('SUDYN: ABOR1 CALLED')
ENDIF
! * Use LPC_FULL for leap-frog schemes?
IF ((NSITER>0).AND.(.NOT.LTWOTL.AND.LSLAG).AND.LPC_FULL) THEN
  WRITE(KULOUT,*) 'P/C scheme not yet coded for 3TL LSLAG scheme'
  CALL ABOR1('SUDYN: ABOR1 CALLED')
ENDIF

!*       3.13  NH dynamics.

! * Use LRUBC in spherical geometry or improper options for LRUBC?
IF (LRUBC) THEN
  IF (.NOT.LELAM) THEN
    WRITE(KULOUT,*)'Radiative upper boundary not ready for ARPEGE'
    WRITE(KULOUT,*)'with LRUBC=.T. you can run Aladin only'
    CALL ABOR1('SUDYN: ABOR1 CALLED')
  ELSEIF (NDLNPR /= 1.OR. NSITER /= 1) THEN
    WRITE(KULOUT,*)'for LRUBC=.T.'
    WRITE(KULOUT,*)'is needed NDLNPR=1, NSITER=1'
    CALL ABOR1('SUDYN: ABOR1 CALLED')
  ENDIF
  NRUBC=MAX(1,MIN(2,NRUBC))
ELSE
  NRUBC=0
ENDIF

! * Reset the LVFE_... keys to F if LVERTFE=F.
LVFE_LAPL=(LVERTFE.AND.LNHDYN).AND.LVFE_LAPL
LVFE_LAPL_BC=(LVERTFE.AND.LNHDYN).AND.LVFE_LAPL_BC
LVFE_X_TERM=LVERTFE.AND.LVFE_X_TERM
LVFE_GW=LVERTFE.AND.LVFE_GW
LVFE_Z_TERM=(LVERTFE.AND.LNHDYN).AND.LVFE_Z_TERM
LVFE_DELNHPRE=(LVERTFE.AND.LNHDYN).AND.LVFE_DELNHPRE
LVFE_GWMPA=LVERTFE.AND.LVFE_GWMPA
LVFE_DERIB=LVERTFE.AND.LVFE_DERIB
LVFE_DBCS=LVERTFE.AND.LVFE_DBCS
LVFE_DBCT=LVERTFE.AND.LVFE_DBCT

! * Reset the LVFE_... keys to T if LVERTFE=T and LNH_GEOGW=T.
!   (remark: some of them are not used in this case but they are reset
!   to .T. for safety).
!   LVFE_DELNHPRE is not reset (can be set to F or T). 
IF (LNH_GEOGW.AND.LVERTFE) THEN
  LVFE_LAPL=.TRUE.
  LVFE_LAPL_BC=.TRUE.
  LVFE_X_TERM=.TRUE.
  LVFE_GW=.TRUE.
  LVFE_Z_TERM=.TRUE.
ENDIF

! * Set-up the LSLINL.. variables
! Separate linear from other terms in continuity equation
LSLINLC1=LNHDYN.AND.LNH_PDVD.AND.(LVERTFE.AND.LRNHC1)
LSLINLC2=LNHDYN.AND.LNH_PDVD.AND.(LTWOTL.AND.LGWADV.AND.LSETTLS)
! Separate linear from other terms in other equations
LSLINL=LNHDYN.AND.LNH_PDVD.AND.(LTWOTL.AND.LGWADV.AND.LSETTLS)

! * Check that we have not LVFE_LAPL=T, LVFE_LAPL_BC=T if LGWADV=T.
IF (LGWADV.AND.(LVFE_LAPL.OR.LVFE_LAPL_BC)) THEN
  WRITE(KULOUT,*) 'If LGWADV=T, LVFE_LAPL,LVFE_LAPL_BC should be F'
  CALL ABOR1('SUDYN: ABOR1 CALLED')
ENDIF

! * If LVFE_DBCS=T or LVFE_DBCT=T, LVFE_DERIB should be F.
IF ((LVFE_DBCS.OR.LVFE_DBCT).AND.LVFE_DERIB) THEN
  WRITE(KULOUT,*) 'If (LVFE_DBCS.OR.LVFE_DBCT)=T, LVFE_DERIB should be F'
  CALL ABOR1('SUDYN: ABOR1 CALLED')
ENDIF
! * If LVFE_DERIB=T, LVFE_DBCS and LVFE_DBCT should be F.
IF (LVFE_DERIB.AND.(LVFE_DBCS.OR.LVFE_DBCT)) THEN
  WRITE(KULOUT,*) 'If LVFE_DERIB=T, LVFE_DBCS and LVFE_DBCT should be F'
  CALL ABOR1('SUDYN: ABOR1 CALLED')
ENDIF

!*       3.15  Moisture convergence.

! * CVGQ for french deep convection scheme:

! ky: definition of LLCOMPUTE_CVGQ must be the same everywhere in the code.
!     (also in CPPHINP).
LLCOMPUTE_CVGQ=LMPHYS.AND.(.NOT.LMPA)

IF (LLCOMPUTE_CVGQ) THEN
  ! * Try to compute an Eulerian CVGQ with spectral YQ-GFL when YQ is
  !   available only in grid-point space?
  IF ((NCOMP_CVGQ==0) .AND. YQ%LGP .AND. (NSTOP>0.OR.NEINI>0)) THEN
    WRITE(KULOUT,*) &
     & 'SUDYN WARNING: when NCOMP_CVGQ = 0 YQ must be spectral'
    CALL ABOR1('SUDYN: NCOMP_CVGQ inconsistency ABOR1 CALLED')
  ENDIF
  ! * Try to compute an Eulerian CVGQ with spectral YCVGQ-GFL when
  !   the GFL variable YCVGQ is not available, or when this GFL variable
  !   is available in grid-point only?
  IF ((NCOMP_CVGQ == 1) .AND. ((.NOT. YCVGQ%LACTIVE).OR. (YCVGQ%LGP))) THEN
    WRITE(KULOUT,*) &
     & 'SUDYN WARNING: when NCOMP_CVGQ == 1 YCVGQ must be active and spectral'
    CALL ABOR1('SUDYN: NCOMP_CVGQ inconsistency ABOR1 CALLED')
  ENDIF
  ! * Try to compute a Semi-Lagrangian CVGQ with grid-point YCVGQ-GFL when
  !   the GFL variable YCVGQ is not available, or when this GFL variable
  !   is available in spectral space only?
  IF ((NCOMP_CVGQ == 2) .AND. ((.NOT. YCVGQ%LACTIVE).OR. (YCVGQ%LSP))) THEN
    WRITE(KULOUT,*) &
     & 'SUDYN WARNING: when NCOMP_CVGQ == 2 YCVGQ must be active and grid point'
    CALL ABOR1('SUDYN: NCOMP_CVGQ inconsistency ABOR1 CALLED')
  ENDIF
  ! * Try to use NCOMP_CVGQ>0 in an Eulerian model?
  IF ((NCOMP_CVGQ > 0) .AND. (.NOT.LSLAG) .AND. (NSTOP>0.OR.NEINI>0)) THEN
    WRITE(KULOUT,*) &
     & 'SUDYN WARNING: in an Eulerian scheme only NCOMP_CVGQ=0 can be used'
    CALL ABOR1('SUDYN: NCOMP_CVGQ inconsistency ABOR1 CALLED')
  ENDIF
  ! * Try to use NCOMP_CVGQ=2 in a 3TLSL model (not yet coded)?
  IF ((NCOMP_CVGQ == 2) .AND. (.NOT.LTWOTL)) THEN
    WRITE(KULOUT,*) &
     & 'SUDYN WARNING: NCOMP_CVGQ=2 is currently available in a SL2TL scheme only'
    CALL ABOR1('SUDYN: NCOMP_CVGQ inconsistency ABOR1 CALLED')
  ENDIF
ENDIF

!*       3.16  Disable sponge in global model.

IF ( .NOT.LELAM ) THEN
  NSPONGE = 0
ENDIF

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

!*       4.    INITIALIZE STANDARD ATMOSPHERE.
!              -------------------------------

CALL SUSTA
IF(LRWSDLR) CALL SUSTADLR

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

!*       5.    ALLOCATE SOME ARRAYS.
!              ---------------------

IF (NSTOP > 0.OR.NEINI /= 0) THEN
  IF (LELAM) THEN
    CALL SUELDYNB
  ELSE
    CALL SUALDYNB
  ENDIF
ENDIF

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

!*       6.    INITIALIZE COEFFICIENTS FOR SPECTRAL MULTIPLICATIONS
!              BY POLYNOMIAL EXPRESSIONS OF GM (GM=MAP FACTOR).
!              ----------------------------------------------------

IF (NSTOP > 0.OR.NEINI /= 0) THEN
  IF (LSIDG) THEN
    CALL SUSMAP(KULOUT,SCGMAP(1,1),SCGMAP(1,2),SCGMAP(1,3))
  ENDIF
  IF (LSTRHD) THEN
    CALL SUSPGM(KULOUT,GMR(1,1),GMR(1,2))
  ENDIF
ENDIF

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

!*       7.    INITIALIZE POINTERS TO SAVE ECMWF PHYSICAL TENDENCIES
!              -----------------------------------------------------

CALL SUSAVTEND

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

!*       8.    Print final values.
!              -------------------

WRITE(UNIT=KULOUT,FMT='('' MODULE YOMDYN '')')
WRITE(UNIT=KULOUT,FMT='('' TSTEP  = '',E14.8 &
 & ,'' TDT    = '',E14.8 )') TSTEP,TDT  
WRITE(UNIT=KULOUT,FMT='('' REPS1  = '',E14.8 &
 & ,'' REPS2  = '',E14.8)') REPS1 ,REPS2  
WRITE(UNIT=KULOUT,FMT='('' REPSM1  = '',E14.8 &
 & ,'' REPSM2  = '',E14.8 &
 & ,'' REPSP1  = '',E14.8)')&
 & REPSM1,REPSM2,REPSP1  
WRITE(UNIT=KULOUT,FMT='('' LNEWHD  = '',L2,'' RRDXTAU = '',E14.8)')&
 & LNEWHD,RRDXTAU
WRITE(UNIT=KULOUT,FMT='('' RDAMPVOR = '',E14.8 &
 & ,'' RDAMPDIV = '',E14.8)')&
 & RDAMPVOR,RDAMPDIV  
WRITE(UNIT=KULOUT,FMT='('' RDAMPT   = '',E14.8 &
 & ,'' RDAMPQ   = '',E14.8)')&
 & RDAMPT,RDAMPQ  
WRITE(UNIT=KULOUT,FMT='(A,E14.8)') ' RDAMPO3 = ', RDAMPO3
WRITE(UNIT=KULOUT,FMT='('' RDAMPPD  = '',E14.8 &
 & ,'' RDAMPVD  = '',E14.8)')&
 & RDAMPPD,RDAMPVD  
WRITE(UNIT=KULOUT,FMT='('' RDAMPSP  = '',E14.8)') RDAMPSP  
WRITE(UNIT=KULOUT,FMT='('' HDIRVOR = '',E14.8 &
 & ,'' HDIRDIV = '',E14.8)')&
 & HDIRVOR,HDIRDIV  
WRITE(UNIT=KULOUT,FMT='('' HDIRT   = '',E14.8 &
 & ,'' HDIRQ   = '',E14.8)')&
 & HDIRT,HDIRQ  
WRITE(UNIT=KULOUT,FMT='(A,E14.8)') ' HDIRO3 = ', HDIRO3
WRITE(UNIT=KULOUT,FMT='('' HDIRPD  = '',E14.8 &
 & ,'' HDIRVD  = '',E14.8)')&
 & HDIRPD,HDIRVD  
WRITE(UNIT=KULOUT,FMT='('' HDIRSP  = '',E14.8)') HDIRSP  
WRITE(UNIT=KULOUT,&
 & FMT='('' REXPDH = '',E14.8,'' FRANDH = '',E14.8)')&
 & REXPDH,FRANDH  
WRITE(UNIT=KULOUT,FMT='(&
 & '' SLEVDH = '',E14.8,'' SLEVDH2 = '',E14.8 &
 & ,'' SLEVDH3 = '',E14.8 &
 & ,'' NSREFDH = '',I3)')&
 & SLEVDH,SLEVDH2,SLEVDH3,NSREFDH  
WRITE(UNIT=KULOUT,FMT='('' LSTRHD = '',L2)') LSTRHD
WRITE(UNIT=KULOUT,FMT='('' LSIDG = '',L2)') LSIDG
WRITE(UNIT=KULOUT,FMT='('' BETADT = '',E14.8,'' XIDT = '',E14.8 &
 & ,'' SITR   = '',E14.8 &
 & ,'' SITRA  = '',E14.8 &
 & ,'' SIPR   = '',E14.8 &
 & ,'' NSITER = '',I2)')&
 & BETADT,XIDT,SITR,SITRA,SIPR,NSITER  
WRITE(UNIT=KULOUT,FMT='('' NITERHELM= '',I2)') NITERHELM
WRITE(UNIT=KULOUT,FMT='('' LRNHC1  = '',L2)') LRNHC1
WRITE(UNIT=KULOUT,FMT='('' NITMP= '',I2)') NITMP
WRITE(UNIT=KULOUT,FMT='('' REFGEO = '',E14.8 &
 & ,'' NVLAG  = '',I8,'' NWLAG  = '',I8 &
 & ,'' NTLAG = '',I8)')&
 & REFGEO,NVLAG,NWLAG,NTLAG  
WRITE(UNIT=KULOUT,FMT='('' NSVDLAG = '',I8 &
 & ,'' NSPDLAG = '',I8)') NSVDLAG,NSPDLAG  
WRITE(UNIT=KULOUT,FMT='('' LQMW = '',L2,'' LQMHW  = '',L2)') LQMW,LQMHW
WRITE(UNIT=KULOUT,FMT='('' LQMT = '',L2,'' LQMHT  = '',L2)') LQMT,LQMHT
WRITE(UNIT=KULOUT,FMT='('' LQMP = '',L2,'' LQMHP  = '',L2)') LQMP,LQMHP
WRITE(UNIT=KULOUT,FMT='('' LQMPD = '',L2,'' LQMHPD  = '',L2)') LQMPD,LQMHPD
WRITE(UNIT=KULOUT,FMT='('' LQMVD = '',L2,'' LQMHVD  = '',L2)') LQMVD,LQMHVD
WRITE(UNIT=KULOUT,FMT='('' VNORM  = '',F6.3)') VNORM
WRITE(UNIT=KULOUT &
 & ,FMT='('' VMAX1 = '',E10.4,'' VMAX2  = '',E10.4)')&
 & VMAX1,VMAX2  
WRITE(UNIT=KULOUT &
 & ,FMT='('' VETAON = '',F16.12,'' VETAOX  = '',F16.12)')&
 & VETAON,VETAOX  
WRITE(UNIT=KULOUT,FMT=&
 & '('' N.B.: VMAX1, VMAX2 WILL BE RECOMPUTED IN SUSC2'')')  
WRITE(UNIT=KULOUT,FMT='('' VESL  = '',E10.4)') VESL
WRITE(UNIT=KULOUT,FMT='('' LIMPF = '',L2)') LIMPF
WRITE(UNIT=KULOUT,FMT='('' LADVF = '',L2)') LADVF
WRITE(UNIT=KULOUT,FMT='('' RW2TLFF = '',E14.8)') RW2TLFF
WRITE(UNIT=KULOUT,FMT='('' L2TLFF = '',L2)') L2TLFF
WRITE(UNIT=KULOUT,FMT='('' LSETTLST = '',L2)') LSETTLST
WRITE(UNIT=KULOUT,FMT='('' LSETTLS = '',L2)') LSETTLS
WRITE(UNIT=KULOUT,FMT='('' LELTRA = '',L2)') LELTRA
WRITE(UNIT=KULOUT,FMT='('' RCMSLP0 ='',E14.8)') RCMSLP0
WRITE(UNIT=KULOUT,FMT='('' RHYDR0= '',E10.4)') RHYDR0
WRITE(UNIT=KULOUT,FMT='('' NDLNPR= '',I1)') NDLNPR
IF (LRUBC) THEN
  WRITE(UNIT=KULOUT,FMT='('' RTEMRB= '',E10.4)') RTEMRB
  WRITE(UNIT=KULOUT,FMT='('' SITRUB= '',E10.4)') SITRUB
  WRITE(UNIT=KULOUT,FMT='('' SIPRUB= '',E10.4)') SIPRUB
ENDIF
WRITE(UNIT=KULOUT,FMT='('' NRUBC = '',I1)') NRUBC
WRITE(UNIT=KULOUT,FMT='('' VCPR ='',E14.8)') VCPR
WRITE(UNIT=KULOUT,FMT='('' VCAK ='',E14.8)') VCAK
WRITE(UNIT=KULOUT,FMT='('' VCTR ='',E14.8)') VCTR
WRITE(UNIT=KULOUT,FMT='('' LADVFW = '',L2)') LADVFW
WRITE(UNIT=KULOUT,FMT='('' NITPRHS = '',I8)') NITPRHS
WRITE(UNIT=KULOUT,FMT='('' NVSEPC = '',I8,'' NVSEPL = '',I8)') NVSEPC, NVSEPL
WRITE(UNIT=KULOUT,FMT='('' LSVTSM = '',L2)') LSVTSM
IF (LSLHD) THEN
  WRITE(KULOUT,*) 'SUDYN: variables controlling SLHD scheme.'
  WRITE(UNIT=KULOUT,FMT='('' SLHDA0  = '',E10.4)') SLHDA0
  WRITE(UNIT=KULOUT,FMT='('' SLHDB   = '',E10.4)') SLHDB
  WRITE(UNIT=KULOUT,FMT='('' SLHDD00 = '',E14.8)') SLHDD00
  WRITE(UNIT=KULOUT,FMT='('' SLHDDIV = '',E14.8)') SLHDDIV
  WRITE(UNIT=KULOUT,FMT='('' SLHDRATDDIV = '',E14.8)') SLHDRATDDIV
  WRITE(UNIT=KULOUT,FMT='('' SLHDHOR = '',E14.8)') SLHDHOR
  WRITE(UNIT=KULOUT,FMT='(&
   & '' ZSLHDP1 = '',E14.8,'' ZSLHDP3 = '',E14.8)')&
   & ZSLHDP1,ZSLHDP3
  WRITE(UNIT=KULOUT,FMT='('' LPSLHDN= '',L2)') LPSLHDN
  WRITE(UNIT=KULOUT,FMT='('' REXPDHS = '',E14.8)') REXPDHS
  WRITE(UNIT=KULOUT,FMT='(&
   & '' SLEVDHS = '',E14.8,'' SLEVDHS2 = '',E14.8)')&
   & SLEVDHS,SLEVDHS2
  WRITE(UNIT=KULOUT,FMT='('' SDRED   = '',E14.8)') SDRED
  WRITE(UNIT=KULOUT,FMT='('' RDAMPDIVS= '',E14.8)') RDAMPDIVS
  WRITE(UNIT=KULOUT,FMT='('' RDAMPVORS= '',E14.8)') RDAMPVORS
  WRITE(UNIT=KULOUT,FMT='('' RDAMPVDS= '',E14.8)') RDAMPVDS
  WRITE(UNIT=KULOUT,FMT='('' RDAMPHDS = '',E14.8)') RDAMPHDS
ENDIF
WRITE(UNIT=KULOUT,FMT='('' LDRY_ECMWF= '',L2)') LDRY_ECMWF
WRITE(UNIT=KULOUT,FMT='('' LRHDI_LASTITERPC = '',L2)') LRHDI_LASTITERPC
WRITE(UNIT=KULOUT,FMT='('' NCOMP_CVGQ = '',I1)') NCOMP_CVGQ
IF (NSTOP > 0.OR.NEINI /= 0) THEN
  WRITE(UNIT=KULOUT,FMT='('' NEPHYS_PCFULL = '',I3)') NEPHYS_PCFULL
ENDIF
WRITE(UNIT=KULOUT,FMT='('' LVFE_LAPL = '',L2)') LVFE_LAPL
WRITE(UNIT=KULOUT,FMT='('' LVFE_LAPL_BC = '',L2)') LVFE_LAPL_BC
WRITE(UNIT=KULOUT,FMT='('' LVFE_X_TERM = '',L2)') LVFE_X_TERM
WRITE(UNIT=KULOUT,FMT='('' LVFE_GW = '',L2)') LVFE_GW
WRITE(UNIT=KULOUT,FMT='('' LVFE_Z_TERM = '',L2)') LVFE_Z_TERM
WRITE(UNIT=KULOUT,FMT='('' LVFE_DELNHPRE = '',L2)') LVFE_DELNHPRE
WRITE(UNIT=KULOUT,FMT='('' LVFE_GWMPA = '',L2)') LVFE_GWMPA
WRITE(UNIT=KULOUT,FMT='('' LVFE_DERIB = '',L2)') LVFE_DERIB
WRITE(UNIT=KULOUT,FMT='('' LVFE_DBCS = '',L2)') LVFE_DBCS
WRITE(UNIT=KULOUT,FMT='('' LVFE_DBCT = '',L2)') LVFE_DBCT
WRITE(UNIT=KULOUT,FMT='('' LSLINLC1 = '',L2)') LSLINLC1
WRITE(UNIT=KULOUT,FMT='('' LSLINLC2 = '',L2)') LSLINLC2
WRITE(UNIT=KULOUT,FMT='('' LSLINL = '',L2)') LSLINL
WRITE(UNIT=KULOUT,FMT='('' RC_PD1 = '',E14.8)') RC_PD1

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

!*       9.    INITIALIZE SEMI-IMPLICIT AND VERTICAL NORMAL MODES.
!              ---------------------------------------------------

! ky: In the 3D model, when NSTOP=0, the setup of the SI scheme should be
!     called each time we need to call CPG at instant 0 (for example to do
!     diagnostics). This is the case for example if LSDDH=T.
!     The test should be consistent with CNT4 code.

IF ( ((NSTOP > 0).OR.(NEINI /= 0).OR.(NSTOP==0.AND.LSDDH).OR. &
 & (NSTOP==0.AND.LWCOU)).AND.(NFLEVG > 1) ) THEN

  ! Setup of the SI scheme for 3D models.
  IF (LNHDYN) THEN
    SITIME=-1.0_JPRB
    CALL SUNHSI(KULOUT,.TRUE.)
  ELSE
    CALL SUSI(KULOUT)
  ENDIF

ELSEIF(NSTOP > 0.OR.NEINI /= 0) THEN

  ! Setup of the SI scheme for 2D models.
  SIVP(1)=REFGEO
  IF (LSIDG) THEN
    SITIME=-1.0_JPRB
    CALL SUHEG
  ENDIF
  SIBI(1,1)=1.0_JPRB/SIVP(1)

ENDIF

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

!*       10.   INITIALIZE HORIZONTAL DIFFUSION.
!              --------------------------------

IF (NSTOP > 0.OR.NEINI /= 0) THEN

  !*     10.1. resolution correction for SLHD

  IF (LSLHD.AND.(.NOT.LSLHD_STATIC)) THEN

    ! rescaling of SLHDA with respect to the generalised (horizontal)
    !  smallest wavenumber times sqrt(2.)
    ! and computing of SLHDD0 with respect of mesh-size (after Leith(1969))

    ZLXY=52349.828_JPRB  ! reference mesh-size at a location where M=1

    ! * NOTE: The proposed setting is valid only for resolutions finer
    !   than 40-50 km of horizontal mesh. When a coarser resolution
    !   is used, the linear formula for SLHDD0 (and SLHDA) has to be
    !   generalized by a saturation above the mentioned limit.
    !   Since it is quite easy to meet this limit when LLSTRSG=.T., 
    !   a temporal fix has been implemented for this option. It has
    !   been experimantally proven as fine for the operational ARPEGE
    !   model configuration at MF (June, 2006). For the other geometries
    !   with LLSTRSG=.T. the SLHD performance is not garranted.
    IF (LLSTRSG) THEN
      SLHDA(1:NGPTOT) =SLHDA0 * ( ZLXY * GM(1:NGPTOT) / SLHDP )**(ZSLHDP1)
      SLHDD0(1:NGPTOT)=SLHDD00 *( ZLXY * GM(1:NGPTOT) / SLHDP )**(ZSLHDP3) &
       & * SQRT(RSTRET/GM(1:NGPTOT))
    ELSE
      IF (LPSLHDN) THEN
        ! preserves SLHD norms for non-stretched grid
        SLHDA(1:NGPTOT) =SLHDA0 * ( ZLXY / SLHDP )**(ZSLHDP1)
        SLHDD0(1:NGPTOT)=SLHDD00 *( ZLXY / SLHDP )**(ZSLHDP3)
      ELSE
        ! this more general fashion is preferable for the future
        SLHDA(1:NGPTOT) =SLHDA0 * ( ZLXY * GM(1:NGPTOT) / SLHDP )**(ZSLHDP1)
        SLHDD0(1:NGPTOT)=SLHDD00 *( ZLXY * GM(1:NGPTOT) / SLHDP )**(ZSLHDP3)
      ENDIF
    ENDIF

  ENDIF

  !*     10.2. spectral HD

  IF (LELAM) THEN
    CALL SUEHDF
  ELSE
    CALL SUHDF
  ENDIF

  IF (LSTRHD) THEN
    HDTIME_STRHD=-1.0_JPRB
    CALL SUHDU
  ENDIF

ENDIF

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

!*       11.   INITIALIZE RCORDI... ARRAYS.
!              ----------------------------

CALL SURCORDI

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

!*       12.   INITIALIZE RKRF (RAYLEIGH FRICTION).
!              ------------------------------------

CALL SURAYFRIC

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

!*       13.   SET GFL ATTRIBUTES
!              ------------------

CALL SUDYN_SETGFLATTR

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

9990 FORMAT(1X,'ARRAY ',A10,' ALLOCATED ',8I8)

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

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