#ifdef RS6K
@PROCESS NOCHECK
#endif
SUBROUTINE CPG_GP( &
 !---------------------------------------------------------------------
 ! - INPUT .
 & KST,KEND,KSTC,KENDC,KBL,KSTGLO, &
 & LDLFSTEP,LDLDIAB,LDLADNMI, &
 & PTE, &
 & PGM,PGNORDL,PGNORDM,PRCORI,PRCORIC, &
 & PGNORDLCL,PGNORDMCL,PGNORDMCM, &
 & PRATATX,PRATATH,POROG, &
 & POROGL_RE,POROGM_RE,POROGLL_RE,POROGMM_RE,POROGLM_RE, &
 !---------------------------------------------------------------------
 ! - INPUT/OUTPUT .
 & PGFL, &
 & PGMV,PGMVS, &
 !---------------------------------------------------------------------
 ! - OUTPUT .
 & POROGL,POROGM, &
 & PRE0,PRE0L,PRE0M,PRE0F,PNHPRE0F,PNHPRE0H, &
 & PDELP0,PRDELP0,PLNPR0,PALPH0, &
 & PLHU0,PLHV0, &
 & PHI0,PHIF0,PHI0FL,PHI0FM, &
 & PCP0,PR0,PRTGR0, &
 & PKAP0,PRRED0, &
 & PEVEL0,PVVEL0,PGWFT0,PSDVBC0,PKENE0, &
 & PSGRTL,PSGRTM,PGPHL,PGPHM,&
 & PSDIV0,PDIVP0,PSDFI0,&
 & PRT0L,PRT0M,PWW0, &
 & PVCRSSA0F,PVCRSSA0FL,PVCRSSA0FM, &
 & PVCRSSA0H,PVCASRS0F,PVCASRS0H, &
 & PVCTS0F,PVCMUS0F,PVCW0F,PWDLW0F,PRDLR0,PRDLR9, &
 & PRE9,PRE9F,PNHPRE9F,PNHPRE9H,&
 & PDELP9,PRDELP9,PLNPR9,PALPH9, &
 & PHI9,PHIF9,PCP9,PR9,PGWFT9, &
 & PVCRSSA9F, &
 & PGPAR,PGPPC,&
 & PB2, &
 & PGMVT1,PGMVT1S,PGFLT1, &
 & PKOZO,&
 & PQS,PQICE,PQLI, &
 & PTNDPD,PTNDVD,PTNDGW,P3DIVG,PD3Y0,PD3Y9,PDBBC,PRDPHI,PGWT0,PGWT9,PGWS,&
 & PNHXT0,PNHXT9,PQCHA0L,PQCHA0M)

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

USE YOMDIM   , ONLY : NFLEVG   ,NPROMA   ,NPROMNH  ,NPROMVC  ,NPROMDLW ,&
 & NPROMDLR ,NFGPPC
USE YOMCT0   , ONLY : LSLAG    ,LTWOTL   ,LSPRT    ,LNHDYN   ,LVERCOR  ,&
 & LRUBC , LPC_OLD, LPC_FULL ,LTENC    ,LRPLANE, LSFORC
USE YOMCT3   , ONLY : NSTEP
USE YOMCST   , ONLY : RD       ,RV       ,RG
USE YOMDYN   , ONLY : NCURRENT_ITER
USE YOMDYNA  , ONLY : NPDVAR   ,NVDVAR   ,LGWADV   ,LRDBBC   ,ND4SYS   ,&
 & LNH_PDVD ,LNH_GEOGW,LRWSDLW  ,LRWSDLR  ,LRWSDLR2
USE YOMGEM   , ONLY : VBF      ,VBH      ,VAH      ,VC       ,VDELB    ,RSTRET  
USE YOMSC2   , ONLY : NFLDSLB2
USE YOMGPPB  , ONLY : GPARBUF
USE YOM_YGFL , ONLY : YGFL, YQ, YL, YI,YR, YS, YG, YO3,YA, YFORC
USE YOMGPPCB , ONLY : GPPCBUF
USE YOMNUD   , ONLY : NFNUDG   ,LNUDG
USE YOMSNU   , ONLY : XPNUDG
USE YOMIOPNH , ONLY : LTRAJNH  ,NG3NH95
USE YOMSIMPHL, ONLY : LSIMPH
USE YOEPHY   , ONLY : LEO3CH
USE YOPHLC   , ONLY : LSPHLC
USE YOMDPHY  , ONLY : NVCLIS   ,NTOZ1D   ,NTOZ2D   ,NTOZ3D  
USE YOMCVER  , ONLY : LVERTFE  ,LVFE_X_TERM,LVFE_Z_TERM,LVFE_GW
USE YOMPONG  , ONLY : NSPONGE
USE PTRSLB2  , ONLY : MSLB2VCVWEI
USE PTRGPPC  , ONLY : MGPPCO_Y ,MGPPCO_GL,MGPPCO_GM,MGPPCO_RR,MGPPCO_WW
USE YOMGMV   , ONLY : YT0,YT9,YT1,NDIMGMV,NDIMGMVS
USE SURFACE_FIELDS_MIX  , ONLY :  GPPOPER,&
 & SP_SB, YSP_SB, YSP_SBD, SP_RR, YSP_RR, SP_SG, YSP_SG, &
 & SD_VF, YSD_VF, SD_VV, YSD_VV
USE YOMARPHY , ONLY : LMPA, LMSE
USE YOMARAR  , ONLY : NGPAR
USE YOMLSFORC, ONLY : LSW_FRC
USE PAR_RDLR , ONLY : JP_ASRF  ,JP_ASRH  ,JP_DIMR0 ,JP_DIMR9

!**** *CPG_GP* - Grid point calculations:
!                initial part of not lagged grid-point calculations.

!     Purpose.
!     --------
!           Grid point calculations:
!           initial part of not lagged grid-point calculations.
!           - get data in buffers.
!           - multiply p-order horizontal derivatives by M**p.
!           - second part of the temporal filter.
!           - grid-point calculations for nudging.
!           - grid-point calculations for NSPONGE > 0
!           - calls some GP... routines to initialise some auxiliary variables.
!           - sets-up and PB2.

!           Abbreviation "vwv" stands for "vertical wind variable".

!           Most comments stand for thin layer equations.
!           For deep-layer equations:
!           * "grad" is the semi-reduced gradient (grad=(r/a)geograd).
!           * if LRWSDLR=T, hydrostatic pressure quantities are now based on
!             "presim" instead of "prehyd", where d(presim)/d(prehyd)=(r**2/a**2)*(G/g)

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

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

!     INPUT:
!     ------
!        KST       : first element of work.
!        KEND      : last element of work.
!        KSTC,KENDC: the same as KST,KEND but including zone C for ALADIN.
!        KBL       : block number.
!        KSTGLO    : global offset.
!        LDLFSTEP  : .T.: first time-step?
!        LDLDIAB   : .T. if complete physics is activated and predictor step.
!        LDLADNMI  : .T. if adiabatic NNMI iteration.
!        PTE       : 1. or 0. according to different configurations.
!        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    : f = 2 Omega sin(theta).
!        PRCORIC   : 2 Omega cos(theta).
!        PGNORDLCL : zonal component of "rssavnabla (Gnordl cos(theta))".
!        PGNORDMCL : zonal component of "rssavnabla (Gnordm cos(theta))".
!        PGNORDMCM : meridian component of "rssavnabla (Gnordm cos(theta))".
!        PRATATX   : spherical geometry: zero
!                    plane geometry: 2 S (sin(theta) - K_L)/(a cos(theta))
!                    Used for curvature terms.
!        PRATATH   : spherical geometry: 2 tan(theta_bne)/a
!                    (theta_bne = tilted but not stretched sphere latitude)
!                    plane geometry: 2 C (sin(theta) - K_L)/(a cos(theta))
!                    Used for curvature terms.
!        POROG     : surface orography.
!        POROGL_RE : zonal component of "vnabla'(surf orography)"
!        POROGM_RE : meridian component of "vnabla'(surf orography)"
!        POROGLL_RE: second order zonal reduced der. of the orography.
!        POROGMM_RE: second order merid reduced der. of the orography.
!        POROGLM_RE: second order crossed reduced der. of the orography.

!     INPUT/OUTPUT:
!     -------------
!        PGFL      : unified_treatment grid-point fields at t
!        PGMV      : upper air GMV variables at time t and t-dt.
!        PGMVS     : surface GMV variables at time t and t-dt.

!     OUTPUT:
!     -------
!        POROGL    : zonal component of "rssavnabla(surf orography)"
!        POROGM    : meridian component of "rssavnabla(surf orography)"
!        PRE0      : hydrostatic pressure "prehyd" on interlayers at time t.
!        PRE0L     : zonal component of "rssavnabla prehyds" at t.
!        PRE0M     : meridian component of "rssavnabla prehyds" at t.
!        PRE0F     : hydrostatic pressure "prehyd" on layers at time t.
!        PNHPRE0F  : "pre" at full levels (time t).
!        PNHPRE0H  : "pre" at half levels (time t).
!        PDELP0    : hydrostatic pressure depth of layers at t.
!        PRDELP0   : 1/(hydrostatic pressure depth of layers) at t.
!        PLNPR0    : "delta" on layers at time t.
!        PALPH0    : "alpha" on layers at time t.
!        PLHU0     : zonal wind time t on interlayers.
!        PLHV0     : meridian wind time t on interlayers.
!        PHI0      : geopotential height "gz" at t on interlayers.
!        PHIF0     : geopotential height "gz" at t on layers.
!        PHI0FL    : zonal component of "rssavnabla (gz)" at t on layers.
!        PHI0FM    : meridian component of "rssavnabla (gz)" at t on layers.
!        PCP0      : "cp" at t.
!        PR0       : air constant "R" at t.
!        PRTGR0    : scalar ratio of vectors "(rssavnabla prehyd)/prehyd" at t.
!        PKAP0     : "kappa = R/cp" at t.
!        PRRED0    : reduced gas constant by (1.+Prond) in NH at t.
!        PEVEL0    : "etadot d prehyd / d eta" at t.
!                    On interlayers (resp. layers) if LVERTFE=F (resp. T).
!        PVVEL0    : "omega/prehyd" on layers at t.
!        PGWFT0    : [gw] at full layers at t.
!        PSDVBC0   : vertical integral of divergence computed in "gpcty",
!                    including the "lrubc" and "delta m=1" contributions
!                    of "etadot d prehyd / d eta".
!        PKENE0    : kinetic energy at t.
!        PSGRTL    : semi-reduced zonal component of the pressure force grad.
!        PSGRTM    : semi-reduced merid. component of the pressure force grad.
!        PGPHL     : semi-reduced zonal component of "gz" gradient
!                    on interlayers (cf. PHIHL in GPGRGEO (time t)).
!        PGPHM     : semi-reduced meridian component of "gz" gradient
!                    on interlayers (cf. PHIHM in GPGRGEO (time t)).
!        PSDIV0    : vertical integral of divergence without
!                   "lrubc" and "delta m=1" contributions.
!        PDIVP0    : "rssavnabla( (rs/a) * vec(V) * (Delta prehyd) )" on layers
!        PSDFI0    : vertical integral of divergence with
!                    "lrubc" and with "delta m=1" contributions
!                    for "etadot d prehyd / d eta", and with the
!                    physics of "delta m=1".
!        PRT0L     : zonal component of "rssavnabla RT" on layers.
!        PRT0M     : meridian component of "rssavnabla RT" on layers.
!        PWW0      : weights to compute (U,V) on interlayers.
!        PVCRSSA0F : "rs/a" on layers at t.
!        PVCRSSA0FL: zonal component of "rssavnabla (rs/a)" on layers at t.
!        PVCRSSA0FM: meridian component of "rssavnabla (rs/a)" on layers at t.
!        PVCRSSA0H : "rs/a" on interlayers at t.
!        PVCASRS0F : "a/rs" on layers at t.
!        PVCASRS0H : "a/rs" on interlayers at t.
!        PVCTS0F   : reference temperature "Ts" at t on layers.
!        PVCMUS0F  : "mu_s" on layers.
!        PVCW0F    : pseudo-vertical velocity " W = Drs/Dt " on layers 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.
!        PRE9      : hydrostatic pressure "prehyd" on interlayers at t-dt.
!        PRE9F     : hydrostatic pressure "prehyd" on layers at time t-dt.
!        PNHPRE9F  : "pre" at full levels (time t-dt).
!        PNHPRE9H  : "pre" at half levels (time t-dt).
!        PDELP9    : hydrostatic pressure depth of layers at t-dt.
!        PRDELP9   : 1/(hydrostatic pressure depth of layers) at t-dt.
!        PLNPR9    : "delta" on layers at time t-dt.
!        PALPH9    : "alpha" on layers at time t-dt.
!        PHI9      : geopotential height "gz" at t-dt on interlayers.
!        PHIF9     : geopotential height "gz" at t-dt on layers.
!        PCP9      : "cp" at t-dt.
!        PR9       : air constant "R" at t-dt.
!        PGWFT9    : [gw] at full layers at t-dt.
!        PVCRSSA9F : "rs/a" on layers at t-dt.
!        PGPAR     : surface fields for AROME.
!        PGPPC     : buffer containing some fields used in the PC schemes.
!        PB2       : "SLB2" buffer.
!        PGMVT1    : upper air GMV variables at t+dt.
!        PGMVT1S   : surface GMV variables at t+dt.
!        PGFLT1    : GFL variables at t+dt.
!        PKOZO     : fields for photochemistery of ozon.
!        PQS       : specific humidity at surface level.
!        PQICE     : specific humidity of solid water for radiation.
!        PQLI      : specific humidity of liquid water for radiation.
!        PTNDPD    : [D(pressure departure variable)/Dt]_adiab
!        PTNDVD    : [D(vertical divergence variable)/Dt]_adiab
!        PTNDGW    : [D(gw)/Dt]_adiab (case LGWADV=T only).
!                    half level values 0 to nflevg-1 if LVFE_GW=F.
!                    full level values 1 to nflevg if LVFE_GW=T.
!        P3DIVG    : D3 at t (full levels).
!        PD3Y0     : term 'Y' at t.
!        PD3Y9     : term 'Y' 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).
!        PGWT9     : [gw] at t-dt (LGWADV=T only).
!                    for PGWT0 and PGWT9:
!                    * half level 0 to nflevg-1 values if LVFE_GW=F.
!                    * full level 1 to nflevg values if LVFE_GW=T.
!        PGWS      : [gw]_surf at t (LRDBBC only).
!        PNHXT0    : term 'NHX' at t.
!        PNHXT9    : term 'NHX' at t-dt.
!        PQCHA0L   : zonal comp grad(log(pre/prehyd)).
!        PQCHA0M   : merid comp grad(log(pre/prehyd)).

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

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

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

!     Reference.
!     ----------
!        ARPEGE documentation vol 2 ch 1 and vol 3 ch 6

!     Author.
!     -------
!        K. YESSAD, after parts 1, 2 and 3 of old CPG. 

! Modifications
! -------------
!   Original : 01-08-16
!   01-11-15 : C. Fischer - NPDVAR becomes IPDVAR before merge to CY24R4
!   01-12-11 : C. Fischer - NPDVAR reappears
!   04 JAN 2002: K.YESSAD - pruning; thin layer hyp relaxation for SL.
!   03-2002      J.Vivoda : - nonlinear model calculation organized according 
!                             time
!                           - PC schemes for NH dynamics (LPC_XXXX keys)
!   02-04-22 : C. Fischer - add call to wrnhtrajm (moved from mf_phys)
!   02-09-18 : C. Moussy  - add call gptenc (1.1) 
!   02-07-09 : C. Fischer - add cdlock values to calls (gphluv,gphlwi,gnhgrp)
!   02-09-30 : P. Smolikova - variable d4 in NH
!   12-10-2002, J. Masek  - phasing of PC bugfix
!                         - introducing new sponge (modified interface
!                           to GPSPNG, LEPONGE replaced by NSPONGE)
!   Modified 08-2002 C. Smith : use "w" as prognostic variable in the
!    semi-lag advection of vertical divergence in the NH model.
!   03-01-31 : P. Smolikova - variable d4 in 2tl PC NH
!   Modified 2003-07-17 C. Fischer - psvdauxt0* come from pgmv
!   03-05-01 : P. Termonia - change argument in call gptenc KEND -> KENDC
!   01-Oct-2003 M. Hamrud  CY28 Cleaning
!   10-Jan-2004 M. Hamrud  CY28R1 Cleaning
!   Jan-2004 K. YESSAD  split GP_SPV into GP_SPV + GPMPFC_GMVS;
!               remove PZSPT.. array and use PGMVS instead.
!   03-Jun-2004 J. Masek  NH cleaning (NPDVAR, LFULLIMP, LPC_NOTR)
!   01-Jul-2004 K. Yessad  Make clearer the tests for PC scheme.
!   20-Feb-2005 J. Vivoda  3TL PC Eulerian scheme, GWADV scheme for PC_FULL 
!   14-Nov-2004 Y. Seity : new arguments to GPRCP and GPSPNG 
!       (rain, snow and graupel),read surface fields for AROME
!       (via PGPAR and GPARBUF)
!   06-Jan-2005 K. Yessad: clearer rewriting of the NH model.
!   15-Jan-2006 M.Hamrud  Revised GPRCP
!   25-Jan-2006 F. Bouyssel: add security on YS if LPROCLD
!   01-Jul-2006 M.Hamrud : Revised surface fields
!   06-Mar-2006 R. Zaaboul Add LMSE when reading PGPAR for Arome
!   06-Jun-2006 S. Malardel: add vertical velocity forcing (CALL GPCTY_FORC)
!   26-Oct-2006 A. Alias : Change in UPDSST arguments list
!   17-Apr-2007 S.Ivatek-S: Over dimensioning of PGPAR to NGPAR+1 and PGPNH to
!                NFGPNH+1, boundary checking problem if NGPAR=0 or NFGPNH=0 bf
!   J. Vivoda and K. Yessad (Oct 2007): VFE for NH model. 
!   N. Wedi and K. Yessad (Nov 2007): ND4SYS=2 to stabilize NH model.
!   N. Wedi and K. Yessad (Jan 2008): different dev for NH model and PC scheme
!   K. Yessad (Sep 2008): prune enhanced diffusion (lfrein).
!   F. Bouyssel (Nov 2008): Removal of LPROCLD protection
!   K. Yessad Nov 2008: rationalisation of dummy argument interfaces
!   K. Yessad (Dec 2008): remove dummy CDLOCK
!   K. Yessad (March 2009): correct false comments for LRWSDLG=T
! End Modifications
!------------------------------------------------------------------

IMPLICIT NONE

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

INTEGER(KIND=JPIM),INTENT(IN)    :: KST 
INTEGER(KIND=JPIM),INTENT(IN)    :: KEND 
INTEGER(KIND=JPIM),INTENT(IN)    :: KSTC 
INTEGER(KIND=JPIM),INTENT(IN)    :: KENDC 
INTEGER(KIND=JPIM),INTENT(IN)    :: KBL 
INTEGER(KIND=JPIM),INTENT(IN)    :: KSTGLO 
LOGICAL           ,INTENT(IN)    :: LDLFSTEP 
LOGICAL           ,INTENT(IN)    :: LDLDIAB 
LOGICAL           ,INTENT(IN)    :: LDLADNMI 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PTE 
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)    :: PGNORDLCL(NPROMA) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PGNORDMCL(NPROMA) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PGNORDMCM(NPROMA) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PRATATX(NPROMA) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PRATATH(NPROMA) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: POROG(NPROMA) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: POROGL_RE(NPROMA) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: POROGM_RE(NPROMA) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: POROGLL_RE(NPROMNH) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: POROGMM_RE(NPROMNH) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: POROGLM_RE(NPROMNH) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: 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(OUT)   :: POROGL(NPROMA) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: POROGM(NPROMA) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PRE0(NPROMA,0:NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PRE0L(NPROMA) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PRE0M(NPROMA) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PRE0F(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PNHPRE0F(NPROMNH,NFLEVG)
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PNHPRE0H(NPROMNH,0:NFLEVG)
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PDELP0(NPROMA,0:NFLEVG+1) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PRDELP0(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PLNPR0(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PALPH0(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PLHU0(NPROMA,0:NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PLHV0(NPROMA,0:NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PHI0(NPROMA,0:NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PHIF0(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PHI0FL(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PHI0FM(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PCP0(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PR0(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PRTGR0(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PKAP0(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PRRED0(NPROMNH,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PEVEL0(NPROMA,0:NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PVVEL0(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PGWFT0(NPROMA,NFLEVG)
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PSDVBC0(NPROMA,0:NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PKENE0(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PSGRTL(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PSGRTM(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PGPHL(NPROMA,0:NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PGPHM(NPROMA,0:NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PSDIV0(NPROMA,0:NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PDIVP0(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PSDFI0(NPROMA,0:NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PRT0L(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PRT0M(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PWW0(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PVCRSSA0F(NPROMVC,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PVCRSSA0FL(NPROMVC,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PVCRSSA0FM(NPROMVC,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PVCRSSA0H(NPROMVC,0:NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PVCASRS0F(NPROMVC,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PVCASRS0H(NPROMVC,0:NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PVCTS0F(NPROMVC,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PVCMUS0F(NPROMVC,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PVCW0F(NPROMVC,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PWDLW0F(NPROMDLW,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PRDLR0(NPROMDLR,0:NFLEVG,JP_DIMR0) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PRDLR9(NPROMDLR,0:NFLEVG,JP_DIMR9) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PRE9(NPROMA,0:NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PRE9F(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PNHPRE9F(NPROMNH,NFLEVG)
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PNHPRE9H(NPROMNH,0:NFLEVG)
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PDELP9(NPROMA,0:NFLEVG+1) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PRDELP9(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PLNPR9(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PALPH9(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PHI9(NPROMA,0:NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PHIF9(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PCP9(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PR9(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PGWFT9(NPROMA,NFLEVG)
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PVCRSSA9F(NPROMVC,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PGPAR(NPROMA,NGPAR+1)
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PGPPC(NPROMA,NFGPPC+1) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PB2(NPROMA,NFLDSLB2) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PGMVT1(NPROMA,NFLEVG,YT1%NDIM) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PGMVT1S(NPROMA,YT1%NDIMS) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PGFLT1(NPROMA,NFLEVG,YGFL%NDIM1) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PKOZO(NPROMA,NFLEVG*NVCLIS+1) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PQS(NPROMA) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PQICE(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PQLI(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PTNDPD(NPROMNH,NFLEVG)
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PTNDVD(NPROMNH,NFLEVG)
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PTNDGW(NPROMNH,NFLEVG)
REAL(KIND=JPRB)   ,INTENT(OUT)   :: P3DIVG(NPROMNH,NFLEVG)
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PD3Y0(NPROMNH,NFLEVG)
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PD3Y9(NPROMNH,NFLEVG)
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PDBBC(NPROMNH)
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PRDPHI(NPROMNH,NFLEVG)
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PGWT0(NPROMNH,NFLEVG)
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PGWT9(NPROMNH,NFLEVG)
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PGWS(NPROMNH)
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PNHXT0(NPROMA,NFLEVG)
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PNHXT9(NPROMA,NFLEVG)
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PQCHA0L(NPROMNH,NFLEVG)
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PQCHA0M(NPROMNH,NFLEVG)

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

INTEGER(KIND=JPIM) :: IFLAG, IITFIELDS, INHFIELDS
INTEGER(KIND=JPIM) :: JLEV, JROF
LOGICAL :: LLSTR
LOGICAL :: LLDER
LOGICAL :: LLGWF0,LLGWF9,LLGDWI
LOGICAL :: LLGPXX

!     ==== SPECIFIC "LVERCOR=T" QUANTITIES ===
!     ==== COMPUTED IN GPVC... ROUTINES ======
REAL(KIND=JPRB) :: ZVCMUS0FL(NPROMVC,NFLEVG) ! zonal comp of "rssavnabla mu_s"
!                                              on layers.
REAL(KIND=JPRB) :: ZVCMUS0FM(NPROMVC,NFLEVG) ! merid comp of "rssavnabla mu_s"
!                                              on layers.
REAL(KIND=JPRB) :: ZVCTS0FL(NPROMVC,NFLEVG)  ! zonal comp of "rssavnabla Ts"
!                                              on layers.
REAL(KIND=JPRB) :: ZVCTS0FM(NPROMVC,NFLEVG)  ! merid comp of "rssavnabla Ts"
!                                              on layers.
REAL(KIND=JPRB) :: ZVCRSSA9H(NPROMVC,0:NFLEVG)!"rs/a" on interlayers at t-dt.
REAL(KIND=JPRB) :: ZVCASRS9H(NPROMVC,0:NFLEVG)!"a/rs" on interlayers at t-dt.

!    ==== MISCELLANEOUS ======================
REAL(KIND=JPRB) :: ZALPH0L(NPROMA,NFLEVG)    ! cf. PALPHL in GPGRXYB (time t).
REAL(KIND=JPRB) :: ZALPH0M(NPROMA,NFLEVG)    ! cf. PALPHM in GPGRXYB (time t).
REAL(KIND=JPRB) :: ZALPHPL0L(NPROMA,NFLEVG)  ! cf. PALPHPLL in GPGRXYB (time t)
REAL(KIND=JPRB) :: ZALPHPL0M(NPROMA,NFLEVG)  ! cf. PALPHPLM in GPGRXYB (time t)
REAL(KIND=JPRB) :: ZLNPR0L(NPROMA,NFLEVG)    ! cf. PLNPRL in GPGRXYB (time t).
REAL(KIND=JPRB) :: ZLNPR0M(NPROMA,NFLEVG)    ! cf. PLNPRM in GPGRXYB (time t).
REAL(KIND=JPRB) :: ZNHPRE0L(NPROMNH,NFLEVG)  ! zon comp of "rssavnabla pre"
!                                              on layer (t).
REAL(KIND=JPRB) :: ZNHPRE0M(NPROMNH,NFLEVG)  ! mer comp of "rssavnabla pre"
!                                              on layer (t).
REAL(KIND=JPRB) :: ZRNHPPI0(NPROMA,NFLEVG)   ! "prehyd/pre" on layers (time t).
REAL(KIND=JPRB) :: ZRNHPPI9(NPROMA,NFLEVG)   ! "prehyd/pre" on layers (t-dt).
REAL(KIND=JPRB) :: ZPRE9L(NPROMA)            ! zonal comp of
!                                              "rssavnabla prehyds" at t-dt
REAL(KIND=JPRB) :: ZPRE9M(NPROMA)            ! merid comp of
!                                              "rssavnabla prehyds" at t-dt
REAL(KIND=JPRB) :: ZRPRE0(NPROMA,NFLEVG)     ! cf. PRPRES in GPXYB (time t).
REAL(KIND=JPRB) :: ZRPRE0F(NPROMA,NFLEVG)    ! cf. PRPREF in GPCTY (time t).
REAL(KIND=JPRB) :: ZRPRE9(NPROMA,NFLEVG)     ! cf. PRPRES in GPXYB (time t-dt).
REAL(KIND=JPRB) :: ZRPP0(NPROMA,NFLEVG)      ! cf. PRPP in GPCTY (time t).
REAL(KIND=JPRB) :: ZRPP9(NPROMA,NFLEVG)      ! cf. PRPP in GPCTY (time t-dt).
REAL(KIND=JPRB) :: ZRRED9(NPROMNH,NFLEVG)    ! "R/(1.+Prond)" in NH at t-dt.
REAL(KIND=JPRB) :: ZRTGR9(NPROMA,NFLEVG)     ! cf. PRTGR in GPXYB (time t-dt).
REAL(KIND=JPRB) :: ZRT0(NPROMA,NFLEVG)       ! "RT" on layers (time t).
REAL(KIND=JPRB) :: ZRT9(NPROMA,NFLEVG)       ! "RT" on layers (time t-dt).
REAL(KIND=JPRB) :: ZNHPPI0(NPROMA,NFLEVG)    ! "pre/prehyd" on layers (time t).
REAL(KIND=JPRB) :: ZNHPPI9(NPROMNH,NFLEVG)   ! "pre/prehyd" on layers (t-dt).
REAL(KIND=JPRB) :: ZRTR0(NPROMNH,NFLEVG)     ! PRRED0*"T" at t.
REAL(KIND=JPRB) :: ZLHU9(NPROMA,0:NFLEVG)    ! zonal wind time t-dt at half lay
REAL(KIND=JPRB) :: ZLHV9(NPROMA,0:NFLEVG)    ! merid wind time t-dt at half lay

REAL(KIND=JPRB) :: ZPDEP0(NPROMNH,NFLEVG)    ! "pre-prehyd" on layers (time t).
REAL(KIND=JPRB) :: ZPDEP9(NPROMNH,NFLEVG)    ! "pre-prehyd" on layers (t-dt).
REAL(KIND=JPRB) :: ZDELNHPRE0(NPROMNH,NFLEVG)! "Delta pre" on layers (time t).
REAL(KIND=JPRB) :: ZDELNHPRE9(NPROMNH,NFLEVG)! "Delta pre" on layers (t-dt).
REAL(KIND=JPRB) :: ZLNNHPREF0L(NPROMNH,NFLEVG)! zon cmp grad(PNHPRE0F)/PNHPRE0F
REAL(KIND=JPRB) :: ZLNNHPREF0M(NPROMNH,NFLEVG)! mer cmp grad(PNHPRE0F)/PNHPRE0F
REAL(KIND=JPRB) :: ZDVER0(NPROMA,NFLEVG)     ! dver (time t)
REAL(KIND=JPRB) :: ZDVER0L(NPROMNH,NFLEVG)   ! zonal comp grad(dver) (time t)
REAL(KIND=JPRB) :: ZDVER0M(NPROMNH,NFLEVG)   ! merid comp grad(dver) (time t)
REAL(KIND=JPRB) :: ZDVER9(NPROMA,NFLEVG)     ! dver (time t-dt)

REAL(KIND=JPRB) :: ZUS0(NPROMA)              ! U_surf (time t).
REAL(KIND=JPRB) :: ZVS0(NPROMA)              ! V_surf (time t).
REAL(KIND=JPRB) :: ZUS0_L(NPROMNH)           ! zonal comp grad(U_surf) (time t)
REAL(KIND=JPRB) :: ZVS0_L(NPROMNH)           ! zonal comp grad(V_surf) (time t)
REAL(KIND=JPRB) :: ZUS0_M(NPROMNH)           ! merid comp grad(U_surf) (time t)
REAL(KIND=JPRB) :: ZVS0_M(NPROMNH)           ! merid comp grad(V_surf) (time t)
REAL(KIND=JPRB) :: ZUS9(NPROMA)              ! U_surf (time t-dt).
REAL(KIND=JPRB) :: ZVS9(NPROMA)              ! V_surf (time t-dt).
REAL(KIND=JPRB) :: ZSGRTSL(NPROMNH)          ! cf. PSGRTL but at the surface
REAL(KIND=JPRB) :: ZSGRTSM(NPROMNH)          ! cf. PSGRTM but at the surface

REAL(KIND=JPRB) :: ZGWFL(NPROMNH,NFLEVG)     ! zonal comp grad(gw) at full lay
REAL(KIND=JPRB) :: ZGWFM(NPROMNH,NFLEVG)     ! merid comp grad(gw) at full lay
REAL(KIND=JPRB) :: ZGWHL(NPROMNH,0:NFLEVG)   ! zonal comp grad(gw) at half lay
REAL(KIND=JPRB) :: ZGWHM(NPROMNH,0:NFLEVG)   ! merid comp grad(gw) at half lay
REAL(KIND=JPRB) :: ZGDW0(NPROMNH,NFLEVG)     ! 'g dw' at full lay at t
REAL(KIND=JPRB) :: ZGDW9(NPROMNH,NFLEVG)     ! 'g dw' at full lay at t-dt
REAL(KIND=JPRB) :: ZGWHT0(NPROMA,0:NFLEVG)   ! 'gw' at half lay at t
REAL(KIND=JPRB) :: ZGWHT9(NPROMA,0:NFLEVG)   ! 'gw' at half lay at t-dt

REAL(KIND=JPRB) :: ZOROGLL(NPROMNH)          ! M**2 * POROGLL_RE
REAL(KIND=JPRB) :: ZOROGMM(NPROMNH)          ! M**2 * POROGMM_RE
REAL(KIND=JPRB) :: ZOROGLM(NPROMNH)          ! M**2 * POROGLM_RE

REAL(KIND=JPRB) :: ZTNDUS(NPROMNH)           ! U comp of [DV/Dt]_surf 
REAL(KIND=JPRB) :: ZTNDVS(NPROMNH)           ! V comp of [DV/Dt]_surf 

REAL(KIND=JPRB) :: ZVAL(NPROMNH),ZMN

REAL(KIND=JPRB) :: ZTNDGWH_LAP(NPROMNH,0:NFLEVG)
REAL(KIND=JPRB) :: ZTNDGWH_OTH(NPROMNH,0:NFLEVG)
REAL(KIND=JPRB) :: ZTNDGWF_LAP(NPROMNH,NFLEVG)
REAL(KIND=JPRB) :: ZTNDGWF_OTH(NPROMNH,NFLEVG)

REAL(KIND=JPRB) :: ZWDLMUS0F(NPROMDLW,NFLEVG) 
REAL(KIND=JPRB) :: ZWDLMUS0H(NPROMDLW,0:NFLEVG) 

REAL(KIND=JPRB) :: ZONE(NPROMA,0:NFLEVG)      ! contains 1 

REAL(KIND=JPRB) :: ZEPS
REAL(KIND=JPRB) :: ZEPS2
REAL(KIND=JPRB) :: ZHOOK_HANDLE

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

#include "abor1.intfb.h"
#include "cpg_gpb_nhgeogw.intfb.h"
#include "gnhd3.intfb.h"
#include "gnhdlr.intfb.h"
#include "gnhgrdlr.intfb.h"
#include "gnhgrgw.intfb.h"
#include "gnhgrpre.intfb.h"
#include "gnhpre.intfb.h"
#include "gnhpreh.intfb.h"
#include "gnhy.intfb.h"
#include "gnh_tndlagadiab_gw.intfb.h"
#include "gnh_tndlagadiab_spd.intfb.h"
#include "gnh_tndlagadiab_svd.intfb.h"
#include "gnh_tndlagadiab_uvs.intfb.h"
#include "gpcty.intfb.h"
#include "gpcty_forc.intfb.h"
#include "gpgeo.intfb.h"
#include "gpgrgeo.intfb.h"
#include "gpgrp.intfb.h"
#include "gpgrvcmus.intfb.h"
#include "gpgrvcrs.intfb.h"
#include "gpgrxyb.intfb.h"
#include "gpgw.intfb.h"
#include "gphluv.intfb.h"
#include "gphlwi.intfb.h"
#include "gpinislb.intfb.h"
#include "gpinozst.intfb.h"
#include "gpmpfc.intfb.h"
#include "gpmpfc_gmvs.intfb.h"
#include "gppref.intfb.h"
#include "gppreh.intfb.h"
#include "gprcp.intfb.h"
#include "gprt.intfb.h"
#include "gpspng.intfb.h"
#include "gp_spv.intfb.h"
#include "gptenc.intfb.h"
#include "gptf2.intfb.h"
#include "gpuvs.intfb.h"
#include "gpvcmus.intfb.h"
#include "gpvcrs.intfb.h"
#include "gpvcts.intfb.h"
#include "gpvcw.intfb.h"
#include "gpxx.intfb.h"
#include "gpxyb.intfb.h"
#include "sc2rdg.intfb.h"
#include "updsst.intfb.h"
#include "writtrajm.intfb.h"
#include "wrnhtrajm.intfb.h"

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

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

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

!*       0.    PRELIMINARY INITIALISATIONS.
!              ----------------------------

ZEPS=100.0_JPRB*TINY(1.0_JPRB)
ZEPS2=1.E-12_JPRB
LLSTR=(ABS(RSTRET-1.0_JPRB)>ZEPS)
LLGPXX=.NOT.(LSLAG.AND.LNHDYN.AND.(NVDVAR == 4).AND.(ND4SYS==2))

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

!*       1.    INTERFACE TO GLOBAL ARRAYS/WORK FILES.
!              --------------------------------------

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

!*     1.1  TENDENCY COUPLING FOR SURFACE PRESSURE.

  IF (LTENC.AND..NOT.LTWOTL) THEN
    CALL ABOR1('CPG_GP: ABOR1 CALLED: LTENC.AND..NOT.LTWOTL')
  ENDIF
  IF (LTENC.AND.LRWSDLR) THEN
    CALL ABOR1('CPG_GP: LRWSDLR not yet coded for LTENC')
  ENDIF
  IF (NSTEP > 0.AND.LTENC) THEN
    CALL GPTENC(KENDC,KSTGLO,PGMVS(1,YT0%MSP),&
     & PGMVS(1,YT0%MSPL),PGMVS(1,YT0%MSPM),&
     & PGMVS(1,YT9%MSP),PGMVS(1,YT9%MSPL),PGMVS(1,YT9%MSPM))  
  ENDIF                 

ENDIF

!*     1.3   SPONGE AT THE TOP OF THE MODEL (ACADEMIC SIMULATIONS).

IF ( NSPONGE > 0 ) THEN
  CALL GPSPNG(KST,KEND,&
   & POROG,POROGL_RE,POROGM_RE,&
   & PGMVS(1,YT0%MSP),PGMVS(1,YT0%MSPL),PGMVS(1,YT0%MSPM),&
   & PGMV(1,1,YT0%MU),PGMV(1,1,YT0%MUL),PGMV(1,1,YT0%MV),PGMV(1,1,YT0%MVL),&
   & PGMV(1,1,YT0%MDIV),PGMV(1,1,YT0%MVOR),&
   & PGMV(1,1,YT0%MT),PGMV(1,1,YT0%MTL),PGMV(1,1,YT0%MTM),&
   & PGFL(1,1,YQ%MP),PGFL(1,1,YQ%MPL),PGFL(1,1,YQ%MPM),&
   & PGFL(1,1,YO3%MP),PGFL(1,1,YO3%MPL),PGFL(1,1,YO3%MPM),&
   & PGFL(1,1,YL%MP),PGFL(1,1,YL%MPL),PGFL(1,1,YL%MPM),&
   & PGFL(1,1,YI%MP),PGFL(1,1,YI%MPL),PGFL(1,1,YI%MPM),&
   & PGFL(1,1,YR%MP),PGFL(1,1,YS%MP),PGFL(1,1,YG%MP),&
   & PGFL(1,1,YA%MP),&
   & PGMV(1,1,YT0%MSPD),PGMV(1,1,YT0%MSPDL),PGMV(1,1,YT0%MSPDM),&
   & PGMV(1,1,YT0%MSVD),PGMV(1,1,YT0%MSVDL),PGMV(1,1,YT0%MSVDM),&
   & PGMV(1,1,YT0%MNHX),PGMV(1,1,YT0%MNHXL),PGMV(1,1,YT0%MNHXM))
ENDIF

!*     1.4   PART 2 OF TIME FILTER.

IF(NCURRENT_ITER == 0) THEN
  CALL GPTF2(&
   ! --- INPUT ---------------------------------------------------------
   & KST,KEND,LDLFSTEP,&
   ! --- INPUT for P.T0.; INPUT/OUTPUT for P.T9. -----------------------
   & PGMV,PGMVS,PGFL)
ENDIF

!*     1.5   MAP FACTOR AND SURFACE PRESSURE VARIABLES.

POROGL(KST:KEND)=POROGL_RE(KST:KEND)*PGM(KST:KEND)
POROGM(KST:KEND)=POROGM_RE(KST:KEND)*PGM(KST:KEND)
IF(LNHDYN) THEN
  ZOROGLL(KST:KEND)=POROGLL_RE(KST:KEND)*PGM(KST:KEND)**2
  ZOROGMM(KST:KEND)=POROGMM_RE(KST:KEND)*PGM(KST:KEND)**2
  ZOROGLM(KST:KEND)=POROGLM_RE(KST:KEND)*PGM(KST:KEND)**2
ENDIF

IF(LLSTR) THEN

  IFLAG=0

  CALL GPMPFC(&
   ! --- INPUT ---------------------------------------------------------
   & KST,KEND,IFLAG,PGM,&
   ! --- INPUT/OUTPUT --------------------------------------------------
   & PGMV(1,1,YT0%MU),PGMV(1,1,YT0%MV),PGMV(1,1,YT0%MDIV),&
   & PGMV(1,1,YT0%MTL),PGMV(1,1,YT0%MTM),&
   & PGMV(1,1,YT0%MSPDL),PGMV(1,1,YT0%MSPDM),&
   & PGMV(1,1,YT0%MSVDL),PGMV(1,1,YT0%MSVDM),PGMV(1,1,YT0%MNHXL),&
   & PGMV(1,1,YT0%MNHXM),&
   & PGMV(1,1,YT9%MU)   ,PGMV(1,1,YT9%MV)   ,PGMV(1,1,YT9%MDIV),&
   & PGMV(1,1,YT9%MTL)  ,PGMV(1,1,YT9%MTM)  ,PGMV(1,1,YT9%MSPDL),&
   & PGMV(1,1,YT9%MSPDM),PGMV(1,1,YT9%MSVDL),PGMV(1,1,YT9%MSVDM),&
   & PGMV(1,1,YT0%MUL),PGMV(1,1,YT0%MVL),PGMV(1,1,YT0%MVOR),&
   & PGMV(1,1,YT9%MUL),PGMV(1,1,YT9%MVL),PGMV(1,1,YT9%MVOR),&
   & PGFL)

  CALL GPMPFC_GMVS(&
   ! --- INPUT ---------------------------------------------------------
   & KST,KEND,IFLAG,PGM,&
   ! --- INPUT/OUTPUT --------------------------------------------------
   & PGMVS(1,YT0%MSPL),PGMVS(1,YT0%MSPM),&
   & PGMVS(1,YT9%MSPL),PGMVS(1,YT9%MSPM))

ENDIF

CALL GP_SPV(LDLADNMI,.FALSE.,KST,KEND,&
 & PGMVS(1,YT0%MSP),PGMVS(1,YT0%MSPL),PGMVS(1,YT0%MSPM),&
 & PGMVS(1,YT9%MSP),PGMVS(1,YT9%MSPL),PGMVS(1,YT9%MSPM),&
 & PRE0,PRE0L,PRE0M,&
 & PRE9,ZPRE9L,ZPRE9M)

IF (NCURRENT_ITER == 0) THEN 

!*     1.6   SURFACE VARIABLES.

  IF ((LDLDIAB.OR.LSPHLC.OR.LSIMPH).AND.(.NOT.LDLADNMI)) THEN
    PQS(KST:KEND)=0.0_JPRB
    IF(LDLFSTEP .AND. .NOT. LTWOTL) THEN
      CALL GPPOPER('SET9TO0',KBL=KBL)
    ENDIF
  ENDIF

  ! for AROME   
  IF (LMSE.AND.NGPAR/=0) THEN
    CALL SC2RDG(GPARBUF,KSTGLO,KSTC,KENDC,PGPAR(1:NPROMA,1:NGPAR))
  ENDIF

!*     1.8   OZON PHYSICO-CHEMICAL PROPERTIES AND SUBGRID SURFACE TEMPERATURE.

  IF (LDLDIAB.AND.(.NOT.LDLADNMI)) THEN
    IF(NTOZ3D > 0.OR.NTOZ2D > 0.OR.NTOZ1D > 0.AND.(.NOT.LEO3CH)) THEN
      CALL GPINOZST(KST,KEND,KSTGLO,PKOZO)
    ENDIF
  ENDIF

!*     1.9  NUDGING.

 IF(LNUDG)THEN
    CALL UPDSST(NPROMA,KST,KEND,NFNUDG,YSP_SBD%NLEVS,KBL,&
     & XPNUDG,&
     & SP_RR(1,YSP_RR%YT%MP0,KBL),&
     & SP_SB(1,1,YSP_SB%YT%MP0,KBL),SP_RR(1,YSP_RR%YW%MP0,KBL),&
     & SP_SB(1,1,YSP_SB%YQ%MP0,KBL),SP_SG(1,YSP_SG%YF%MP0,KBL),&
     & SD_VF(1,YSD_VF%YLSM%MP,KBL),SD_VF(1,YSD_VF%YALBF%MP,KBL),&
     & SD_VF(1,YSD_VF%YEMISF%MP,KBL),SD_VF(1,YSD_VF%YZ0F%MP,KBL),&
     & SD_VV(1,YSD_VV%YZ0H%MP,KBL),SD_VV(1,YSD_VV%YD2%MP,KBL),&
     & SD_VV(1,YSD_VV%YIVEG%MP,KBL))
  ENDIF

ENDIF

!*     1.10  TEST Phi(jlev-1) > Phi(jlev) in the Phi-gw NH model.

IF ((NCURRENT_ITER == 0).OR.(NCURRENT_ITER > 0 .AND. LPC_FULL)) THEN
  IF (LNH_GEOGW .AND. NPDVAR==3 .AND. LVERTFE) THEN
    ! Phi should increase when "eta" decreases.
    DO JLEV=2,NFLEVG
      ZVAL(KST:KEND)=PGMV(KST:KEND,JLEV-1,YT0%MSPD) &
       & -PGMV(KST:KEND,JLEV,YT0%MSPD)+(VBF(JLEV-1)-VBF(JLEV))*POROG(KST:KEND)
      ZMN=MINVAL(ZVAL(KST:KEND))
      IF (ZMN <= 0.0_JPRB) THEN
        CALL ABOR1('CPG_GP: Phi(jlev-1) <= Phi(jlev) in the Phi-gw NH model')
      ENDIF
    ENDDO
    ! Phi(full level = nflevg) should be > surface orography.
    ZVAL(KST:KEND)=PGMV(KST:KEND,NFLEVG,YT0%MSPD) &
     & +(VBF(NFLEVG)-1.0_JPRB)*POROG(KST:KEND)
    ZMN=MINVAL(ZVAL(KST:KEND))
    IF (ZMN <= 0.0_JPRB) THEN
      CALL ABOR1('CPG_GP: Phi(nflevg) <= Phi(surf) in the Phi-gw NH model')
    ENDIF
  ENDIF
  IF (LNH_GEOGW .AND. NPDVAR==4 .AND. LVERTFE) THEN
    ! Phi should increase when "eta" decreases.
    DO JLEV=2,NFLEVG
      ZMN=MINVAL(PGMV(KST:KEND,JLEV-1,YT0%MSPD)-PGMV(KST:KEND,JLEV,YT0%MSPD))
      IF (ZMN <= 0.0_JPRB) THEN
        CALL ABOR1('CPG_GP: Phi(jlev-1) <= Phi(jlev) in the Phi-gw NH model')
      ENDIF
    ENDDO
    ! Phi(full level = nflevg) should be > surface orography.
    ZMN=MINVAL(PGMV(KST:KEND,NFLEVG,YT0%MSPD)-POROG(KST:KEND))
    IF (ZMN <= 0.0_JPRB) THEN
      CALL ABOR1('CPG_GP: Phi(nflevg) <= Phi(surf) in the Phi-gw NH model')
    ENDIF
  ENDIF
ENDIF

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

!*       2.    INTERFACE TO GLOBAL ARRAYS/WORK FILES.
!              --------------------------------------

!*     2.1   NHS ITERATION: BUFFER + TRAJECTORY.

IF (NCURRENT_ITER > 0 .AND. LPC_OLD) THEN

  ! * get PGPPC:
  CALL SC2RDG(GPPCBUF,KSTGLO,KSTC,KENDC,PGPPC(1:NPROMA,1:NFGPPC))

  IF (LTRAJNH) THEN
    ! * write trajectory:
    IITFIELDS=13*NFLEVG+1
    CALL WRITTRAJM(NSTEP,KST,KEND,KSTGLO,IITFIELDS,&
     & PGMV(1,1,YT0%MU),PGMV(1,1,YT0%MV),PGMV(1,1,YT0%MT),PGMV(1,1,YT0%MSVD),&
     & PGPPC(1,MGPPCO_Y),PGPPC(1,MGPPCO_RR),&
     & PGPPC(1,MGPPCO_GL),PGPPC(1,MGPPCO_GM),PGPPC(1,MGPPCO_WW),&
     & PGMV(1,1,YT0%MVOR),PGMV(1,1,YT0%MDIV),&
     & PGMV(1,1,YT0%MUL),PGMV(1,1,YT0%MVL),&
     & PGMVS(1,YT0%MSP))  
  ENDIF
ENDIF

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

!*       3.    INITIALISE AUXILIARY VARIABLES.
!              -------------------------------

!---------------------------------------------------------------
!      3.1         TIME t0 CALCULATIONS for HYD or NH-PDVD model
!---------------------------------------------------------------

IF (.NOT.LNHDYN.OR.LNH_PDVD) THEN

!*     3.1.1 COMPUTE HALF-LAYER HYDROSTATIC PRESSURE.

  CALL GPPREH(NPROMA,KST,KEND,NFLEVG,VAH,VBH,PRE0)

!*     3.1.2 COMPUTE AUXILIARY ARRAYS RELATED TO THE VERTICAL
!            AND FULL-LAYER HYDROSTATIC PRESSURE.

  CALL GPXYB(NPROMA,KST,KEND,NFLEVG,VDELB,VC,&
   & PRE0,PDELP0(1,1),PRDELP0,PLNPR0,PALPH0,PRTGR0,&
   & ZRPRE0,ZRPP0)  
  CALL GPPREF(NPROMA,KST,KEND,NFLEVG,PALPH0,PRE0,PRE0F)

ENDIF

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

  IF(LVERTFE) THEN
    DO JLEV=1,NFLEVG
      DO JROF=KST,KEND
        ZRPRE0F(JROF,JLEV)=1.0_JPRB/PRE0F(JROF,JLEV)
      ENDDO
    ENDDO
  ENDIF
  CALL GPGRXYB(NPROMA,KST,KEND,NFLEVG,VC,VBH,&
   & PRE0L,PRE0M,PRDELP0,ZRPRE0,ZRPP0,PLNPR0,PALPH0,PRTGR0,&
   & ZLNPR0L,ZLNPR0M,ZALPH0L,ZALPH0M,ZALPHPL0L,ZALPHPL0M)

!*     3.1.3 COMPUTE "R", "cp" AND "kappa".

  CALL GPRCP(NPROMA,KST,KEND,NFLEVG,PGFL=PGFL,PCP=PCP0,PR=PR0,PKAP=PKAP0)  

!*     3.1.4 COMPUTES "RT" AND ITS GRADIENT.

  CALL GPRT(LSPRT,NPROMA,KST,KEND,NFLEVG,RD,RV,&
   & PR0,PGMV(1,1,YT0%MT),PGMV(1,1,YT0%MTL),PGMV(1,1,YT0%MTM),&
   & PGFL(1,1,YQ%MPL),PGFL(1,1,YQ%MPM),&
   & ZRT0,PRT0L,PRT0M)  

!*     3.1.5 COMPUTE QUANTITIES NECESSARY FOR OPTION LVERCOR=.T..

  IF (LVERCOR) THEN
    CALL GPVCTS(NPROMVC,KST,KEND,NFLEVG,&
     & PRTGR0,PRE0F,PRE0L,PRE0M,&
     & PVCTS0F,ZVCTS0FL,ZVCTS0FM)
    CALL GPVCRS(NPROMVC,KST,KEND,NFLEVG,&
     & PRE0F,PRE0,PVCRSSA0F,PVCRSSA0H,PVCASRS0F,PVCASRS0H)
    CALL GPGRVCRS(NPROMVC,KST,KEND,NFLEVG,&
     & PRTGR0,PRE0F,PRE0L,PRE0M,&
     & PVCRSSA0FL,PVCRSSA0FM)
    CALL GPVCMUS(NPROMVC,KST,KEND,NFLEVG,&
     & PRCORIC,PGNORDL,PGNORDM,PVCASRS0F,PGMV(1,1,YT0%MU),PGMV(1,1,YT0%MV),&
     & PVCMUS0F)
    CALL GPGRVCMUS(NPROMVC,KST,KEND,NFLEVG,&
     & PRCORIC,PGNORDL,PGNORDM,PGNORDLCL,PGNORDMCL,PGNORDMCM,PRATATH,PRATATX,&
     & PGMV(1,1,YT0%MU),PGMV(1,1,YT0%MV),PGMV(1,1,YT0%MUL),PGMV(1,1,YT0%MVL),&
     & PGMV(1,1,YT0%MDIV),PGMV(1,1,YT0%MVOR),&
     & PVCASRS0F,PVCRSSA0FL,PVCRSSA0FM,&
     & ZVCMUS0FL,ZVCMUS0FM)
  ENDIF
  IF (.NOT.LVERCOR) THEN
    PVCTS0F(1:NPROMVC,1:NFLEVG)=0.0_JPRB
    ZVCTS0FL(1:NPROMVC,1:NFLEVG)=0.0_JPRB
    ZVCTS0FM(1:NPROMVC,1:NFLEVG)=0.0_JPRB
    PVCRSSA0F(1:NPROMVC,1:NFLEVG)=1.0_JPRB
    PVCRSSA0FL(1:NPROMVC,1:NFLEVG)=0.0_JPRB
    PVCRSSA0FM(1:NPROMVC,1:NFLEVG)=0.0_JPRB
    PVCRSSA0H(1:NPROMVC,0:NFLEVG)=1.0_JPRB
    PVCASRS0F(1:NPROMVC,1:NFLEVG)=1.0_JPRB
    PVCASRS0H(1:NPROMVC,0:NFLEVG)=1.0_JPRB
    PVCMUS0F(1:NPROMVC,1:NFLEVG)=0.0_JPRB
    ZVCMUS0FL(1:NPROMVC,1:NFLEVG)=0.0_JPRB
    ZVCMUS0FM(1:NPROMVC,1:NFLEVG)=0.0_JPRB
  ENDIF

!*     3.1.6 COMPUTE QUANTITIES FOR NH MODEL.

  IF (LNHDYN) THEN
    CALL GNHPRE(NPROMA,NFLEVG,KST,KEND,PGMV(1,1,YT0%MSPD),PRE0F, &
     & PNHPRE0F,ZNHPPI0,ZRNHPPI0,ZPDEP0)
    DO JLEV=1,NFLEVG
      PRRED0(KST:KEND,JLEV)=PR0(KST:KEND,JLEV)/ZNHPPI0(KST:KEND,JLEV)
      ZRTR0(KST:KEND,JLEV)=PRRED0(KST:KEND,JLEV)*PGMV(KST:KEND,JLEV,YT0%MT)
    ENDDO
    CALL GNHPREH(NPROMA,NFLEVG,KST,KEND,PGMV(1,1,YT0%MSPD),PRE0, &
     & PDELP0(1,1),PLNPR0,ZNHPPI0,PNHPRE0H,ZDELNHPRE0)
    CALL GNHGRPRE(NPROMA,NFLEVG,KST,KEND,PRTGR0,PRE0L,PRE0M, &
     & PNHPRE0F,PGMV(1,1,YT0%MSPDL),PGMV(1,1,YT0%MSPDM), &
     & ZNHPRE0L,ZNHPRE0M,ZLNNHPREF0L,ZLNNHPREF0M,PQCHA0L,PQCHA0M)
  ELSE
    ZNHPPI0(1:NPROMA,1:NFLEVG)=1.0_JPRB
    ZRNHPPI0(1:NPROMA,1:NFLEVG)=1.0_JPRB
    ZNHPRE0L(1:NPROMNH,1:NFLEVG)=0.0_JPRB
    ZNHPRE0M(1:NPROMNH,1:NFLEVG)=0.0_JPRB
  ENDIF

!*     3.1.7a COMPUTES THE RADIUS "r" , THE GEOPOTENTIAL HEIGHT "gz"
!             AND THEIR GRADIENTS IF LRWSDLR=T.

  ! In this case we must compute these quantities before the call to GPCTY
  ! because we use PRDLR0 in GPCTY, and nothing is done in 3.1.8.
  IF (LNHDYN.AND.LRWSDLR) THEN
    ! "r/a", "a/r" and geopotential height.
    CALL GNHDLR(NPROMA,NFLEVG,KST,KEND,PGMV(1,1,YT0%MT),PR0,ZRNHPPI0, &
     & PLNPR0,PALPH0,POROG,PRDLR0,PHIH=PHI0,PHIF=PHIF0)
    ! "grad(r/a)" and gradient of geopotential height.
    CALL GNHGRDLR(NPROMA,NFLEVG,KST,KEND,&
     & PGMV(1,1,YT0%MT),PR0,ZRNHPPI0,PRT0L,PRT0M,&
     & PLNPR0,ZLNPR0L,ZLNPR0M,PALPH0,ZALPH0L,ZALPH0M,&
     & PQCHA0L,PQCHA0M,POROGL,POROGM,PRDLR0,&
     & PHI0FL,PHI0FM,PGPHL,PGPHM)
  ENDIF

!*     3.1.7b COMPUTES "mus" AT FULL LEVELS 

  ! 'mus' terms in the RHS of 'gw' equation.
  IF (LRWSDLW.AND.(.NOT.LRWSDLR)) THEN
    ZONE(KST:KEND,1:NFLEVG)=1.0_JPRB
    CALL GPVCMUS(NPROMA,KST,KEND,NFLEVG,&
     & PRCORIC,PGNORDL,PGNORDM,ZONE(1,1),PGMV(1,1,YT0%MU),PGMV(1,1,YT0%MV),&
     & ZWDLMUS0F)  
  ELSEIF (LRWSDLW.AND.LRWSDLR) THEN
    CALL GPVCMUS(NPROMA,KST,KEND,NFLEVG,&
     & PRCORIC,PGNORDL,PGNORDM,PRDLR0(1,1,JP_ASRF),&
     & PGMV(1,1,YT0%MU),PGMV(1,1,YT0%MV),&
     & ZWDLMUS0F)  
  ENDIF

!*     3.1.7c COMPUTATION OF SOME VERTICAL VELOCITIES.
!*           Solve continuity equation
!            Computation of the vertical velocities "etapt (d prehyd / d eta)"
!            "omega/prehyd" and "W".

  CALL GPCTY(LVERCOR,NPROMA,NPROMVC,KST,KEND,NFLEVG,VDELB,VBH,&
   & PGMV(1,1,YT0%MU),PGMV(1,1,YT0%MV),&
   & PGMV(1,1,YT0%MDIV),PGMV(1,1,YT0%MEDOT),LRUBC,&
   & PDELP0(1,1),PRDELP0,PLNPR0,PALPH0,PRTGR0,PRE0L,PRE0M,&
   & PVCRSSA0F,PVCRSSA0H,PVCASRS0F,PVCASRS0H,PVCRSSA0FL,PVCRSSA0FM,&
   & PEVEL0,PVVEL0,PSDIV0,PSDVBC0,PDIVP0,ZRPRE0F,&
   & LDRWSDLR=LRWSDLR,PRDLR=PRDLR0)  
  IF(LVERTFE)THEN
    PSDFI0(KST:KEND,NFLEVG)=PSDVBC0(KST:KEND,NFLEVG)
  ELSE
    PSDFI0(KST:KEND,0:NFLEVG)=PSDVBC0(KST:KEND,0:NFLEVG)
  ENDIF 

  ! Overwrite PEVEL0 and PVVEL0 with large scale forced values in case
  ! of 1D model (SCUM)
  ! (in SCUM,  PEVEL0 and PVVEL0 = 0 in GPCTY)
  IF ( LSFORC .AND. LSW_FRC ) THEN 
    CALL GPCTY_FORC(KST, KEND, PGFL(1,1,YFORC(1)%MP), &
     & PRE0F, PGMV(1,1,YT0%MT), PR0, &
     & PEVEL0, PVVEL0)
  ENDIF

  IF (LVERCOR) THEN
    CALL GPVCW(NPROMVC,KST,KEND,NFLEVG,PVCTS0F,PVVEL0,PVCW0F)
  ELSE
    PVCW0F(1:NPROMVC,1:NFLEVG)=0.0_JPRB
  ENDIF

!*     3.1.8 COMPUTES THE GEOPOTENTIAL HEIGHT "gz" AND ITS GRADIENT.

  ! * "gz" on layers and interlayers.

  IF(LNHDYN.AND.(.NOT.LRWSDLR)) THEN
    PHI0(KST:KEND,NFLEVG)=POROG(KST:KEND)
    CALL GPGEO(NPROMA,KST,KEND,NFLEVG,PHI0,PHIF0,PGMV(1,1,YT0%MT),&
     & PRRED0,PLNPR0,PALPH0)  
  ELSEIF(.NOT.LNHDYN) THEN
    PHI0(KST:KEND,NFLEVG)=POROG(KST:KEND)
    CALL GPGEO(NPROMA,KST,KEND,NFLEVG,PHI0,PHIF0,PGMV(1,1,YT0%MT),&
     & PR0,PLNPR0,PALPH0)  
  ENDIF

  ! * "rssavnabla gz" on layers and interlayers.

  IF((LNHDYN.AND.(.NOT.LRWSDLR)).OR.(.NOT.LNHDYN)) THEN
    CALL GPGRGEO(LNHDYN,&
     & NPROMA,KST,KEND,NFLEVG,&
     & ZRNHPPI0,PGMV(1,1,YT0%MT),PR0,PRT0L,PRT0M,&
     & PLNPR0,ZLNPR0L,ZLNPR0M,PALPH0,ZALPH0L,ZALPH0M,&
     & PQCHA0L,PQCHA0M,&
     & POROGL,POROGM,&
     & PHI0FL,PHI0FM,PGPHL,PGPHM)
  ENDIF

!*     3.1.9 COMPUTES KINETIC ENERGY.

  DO JLEV=1,NFLEVG
    DO JROF=KST,KEND
      PKENE0(JROF,JLEV)=0.5_JPRB* &
       & (PGMV(JROF,JLEV,YT0%MU)**2+PGMV(JROF,JLEV,YT0%MV)**2)  
    ENDDO
  ENDDO

!*     3.1.10 COMPUTES HALF-LEVEL WINDS.

  ! Testing the cases where we actually need them becomes very tricky,
  ! so for simplicity they are always computed, even when not used.
  CALL GPHLWI(NPROMA,KST,KEND,PLNPR0,PALPH0,PWW0)
  CALL GPHLUV(NPROMA,KST,KEND,PWW0,PGMV(1,1,YT0%MU),PGMV(1,1,YT0%MV),&
   & PLHU0,PLHV0)  

  ! 'mus' terms in the RHS of 'gw' equation.
  IF (LRWSDLW.AND.(.NOT.LRWSDLR)) THEN
    ZONE(KST:KEND,0:NFLEVG)=1.0_JPRB
    CALL GPVCMUS(NPROMA,KST,KEND,NFLEVG+1,&
     & PRCORIC,PGNORDL,PGNORDM,ZONE(1,0),PLHU0,PLHV0,&
     & ZWDLMUS0H)  
  ELSEIF (LRWSDLW.AND.LRWSDLR) THEN
    CALL GPVCMUS(NPROMA,KST,KEND,NFLEVG+1,&
     & PRCORIC,PGNORDL,PGNORDM,PRDLR0(1,0,JP_ASRH),PLHU0,PLHV0,&
     & ZWDLMUS0H)  
  ENDIF

  LLDER=LNHDYN
  CALL GPUVS(NFLEVG,NPROMA,KST,KEND,LLDER, &
   & PGMV(1,1,YT0%MU),PGMV(1,1,YT0%MV),ZUS0,ZVS0, &
   & PDIVF=PGMV(1,1,YT0%MDIV),PVORF=PGMV(1,1,YT0%MVOR), &
   & PUFL=PGMV(1,1,YT0%MUL),PVFL=PGMV(1,1,YT0%MVL), &
   & PUS_L=ZUS0_L,PVS_L=ZVS0_L,PUS_M=ZUS0_M,PVS_M=ZVS0_M)

!*     3.1.12 COMPUTES THE PRESSURE FORCE FOR THE RHS OF MOMENTUM EQN.

  CALL GPGRP( &
   ! --- INPUT ----------------------------------------------------------------
   & LVERCOR, &
   & NPROMA,NPROMVC,NPROMNH,KST,KEND,NFLEVG, &
   & ZRT0,PRT0L,PRT0M,PRDELP0,PRE0L,PRE0M,PRTGR0, &
   & PLNPR0,ZLNPR0L,ZLNPR0M,PALPH0,ZALPHPL0L,ZALPHPL0M, &
   & ZDELNHPRE0,ZLNNHPREF0L,ZLNNHPREF0M, &
   & ZRNHPPI0,PQCHA0L,PQCHA0M, &
   & PGPHL,PGPHM,PHI0FL,PHI0FM, &
   & PVCTS0F,ZVCTS0FL,ZVCTS0FM,PVCMUS0F,ZVCMUS0FL,ZVCMUS0FM,&
   ! --- OUTPUT ---------------------------------------------------------------
   & PSGRTL,PSGRTM,ZSGRTSL,ZSGRTSM, &
   ! --- OPTIONAL -------------------------------------------------------------
   & LDRWSDLR=LRWSDLR,PRDLR=PRDLR0)  

!*     3.1.13 COMPUTES TERM "NHX".

  ! * Currently we need it:
  !   - in the hydrostatic model if LMPA=T
  !   - in the NH model.
  IF (LLGPXX) THEN
    CALL GPXX( &
     ! --- INPUT -------------------------------------------------------------
     & NFLEVG,NPROMA,KST,KEND,PGPHL,PGPHM,PHI0FL,PHI0FM, &
     & PLNPR0,ZNHPPI0,PGMV(1,1,YT0%MT),PR0, &
     & PGMV(1,1,YT0%MU),PGMV(1,1,YT0%MV),PLHU0,PLHV0, &
     ! --- OUTPUT ------------------------------------------------------------
     & PNHXT0,LDRWSDLR=LRWSDLR,PRDLR=PRDLR0)
  ELSE
    PNHXT0(KST:KEND,1:NFLEVG)=PGMV(KST:KEND,1:NFLEVG,YT0%MNHX)
  ENDIF

!*     3.1.14 COMPUTES dver AND grad(dver).

  ! * Currently we need it:
  !   - in the hydrostatic model if LMPA=T
  !   - in the NH model.

  IF (LNHDYN) THEN
    IF (NVDVAR == 3) THEN
      ZDVER0(KST:KEND,1:NFLEVG)=PGMV(KST:KEND,1:NFLEVG,YT0%MSVD)
      IF (.NOT.LGWADV) THEN
        ZDVER0L(KST:KEND,1:NFLEVG)=PGMV(KST:KEND,1:NFLEVG,YT0%MSVDL)
        ZDVER0M(KST:KEND,1:NFLEVG)=PGMV(KST:KEND,1:NFLEVG,YT0%MSVDM)
      ENDIF
    ELSEIF (NVDVAR == 4) THEN
      ZDVER0(KST:KEND,1:NFLEVG)= &
       & PGMV(KST:KEND,1:NFLEVG,YT0%MSVD)-PNHXT0(KST:KEND,1:NFLEVG)
      IF (.NOT.LGWADV) THEN
        ZDVER0L(KST:KEND,1:NFLEVG)=PGMV(KST:KEND,1:NFLEVG,YT0%MSVDL)- &
         & PGMV(KST:KEND,1:NFLEVG,YT0%MNHXL)
        ZDVER0M(KST:KEND,1:NFLEVG)=PGMV(KST:KEND,1:NFLEVG,YT0%MSVDM)- &
         & PGMV(KST:KEND,1:NFLEVG,YT0%MNHXM)
      ENDIF
    ENDIF
  ELSE
    ! dver_hyd=-(R/Rd)*(D+X+(cv/cp)(omega/prehyd))
    DO JLEV=1,NFLEVG
      DO JROF=KST,KEND
        ZDVER0(JROF,JLEV)=-(PR0(JROF,JLEV)/RD)*(PGMV(JROF,JLEV,YT0%MDIV) &
         & +PNHXT0(JROF,JLEV)+(1.0_JPRB-PKAP0(JROF,JLEV))*PVVEL0(JROF,JLEV))
      ENDDO
    ENDDO
  ENDIF

!*     3.1.16 COMPUTES term [gw].

  ! * Currently we need it:
  !   - in the hydrostatic model in some cases (full level only).
  !   - in the NH model (full lev or half lev or both according to the option).
  !   At least, full level values and surface value are always computed.
  LLGWF0=.TRUE.
  LLGDWI=.FALSE.
  IF (LNHDYN.AND.LGWADV.AND.LVERTFE.AND.LVFE_GW) THEN
    ! PGDW is required (at least for SL2TL)
    CALL GPGW(NFLEVG,NPROMA,KST,KEND,LLGWF0,LLGDWI, &
     & POROGL,POROGM,PLNPR0,PALPH0,ZUS0,ZVS0, &
     & PGMV(1,1,YT0%MT),ZDVER0,ZRNHPPI0,ZGWHT0,PGWFT0, &
     & LDRWSDLR=LRWSDLR,LDRWSDLR2=LRWSDLR2,PRDLR=PRDLR0,PGDW=ZGDW0)
  ELSE
    CALL GPGW(NFLEVG,NPROMA,KST,KEND,LLGWF0,LLGDWI, &
     & POROGL,POROGM,PLNPR0,PALPH0,ZUS0,ZVS0, &
     & PGMV(1,1,YT0%MT),ZDVER0,ZRNHPPI0,ZGWHT0,PGWFT0, &
     & LDRWSDLR=LRWSDLR,LDRWSDLR2=LRWSDLR2,PRDLR=PRDLR0)
  ENDIF
  IF (LNHDYN.AND.LGWADV) THEN
    IF (LVERTFE.AND.LVFE_GW) THEN
      PGWT0(KST:KEND,1:NFLEVG)=PGWFT0(KST:KEND,1:NFLEVG)
    ELSE
      PGWT0(KST:KEND,1:NFLEVG)=ZGWHT0(KST:KEND,0:NFLEVG-1)
    ENDIF
  ENDIF
  IF (LTWOTL.AND.LNHDYN.AND.LRDBBC) THEN
    PGWS(KST:KEND)=ZGWHT0(KST:KEND,NFLEVG)
  ENDIF

  ! "w" for inertia terms in Wood and Staniforth deep-layer eqns.
  IF (LRWSDLW) THEN
    PWDLW0F(KST:KEND,1:NFLEVG)=PGWFT0(KST:KEND,1:NFLEVG)/RG
  ENDIF

!*     3.1.17 COMPUTES grad(gw) (NH model).

  IF (LNHDYN.AND.(.NOT.LGWADV)) THEN
    CALL GNHGRGW( &
     ! --- INPUT --------------------------------------------------------------
     & NPROMA,NFLEVG,KST,KEND, &
     & PGMV(1,1,YT0%MT),PGMV(1,1,YT0%MTL),PGMV(1,1,YT0%MTM), &
     & ZDVER0,ZDVER0L,ZDVER0M,ZRNHPPI0,PQCHA0L,PQCHA0M, &
     & PLNPR0,ZLNPR0L,ZLNPR0M,PALPH0,ZALPH0L,ZALPH0M, &
     & ZUS0,ZVS0,ZUS0_L,ZVS0_L,ZUS0_M,ZVS0_M, &
     & POROGL,POROGM,ZOROGLM,ZOROGLL,ZOROGMM, &
     ! --- OUTPUT -------------------------------------------------------------
     & ZGWFL,ZGWFM,ZGWHL,ZGWHM &
     & )
  ENDIF

!*     3.1.18 COMPUTES D3 (NH model).

  IF (LNHDYN) THEN
    CALL GNHD3(NFLEVG,NPROMA,KST,KEND, &
     & PGMV(1,1,YT0%MDIV),PNHXT0,ZDVER0,PR0,P3DIVG,PRDLR=PRDLR0)
  ENDIF

!*     3.1.19 COMPUTES (RT prehyd [Delta log(prehyd)])/pre at t. (NH model).

  IF (LNHDYN.AND.(.NOT.LGWADV)) THEN
    DO JLEV=1,NFLEVG
      DO JROF=KST,KEND
        PRDPHI(JROF,JLEV)=1.0_JPRB/(PLNPR0(JROF,JLEV)*ZRTR0(JROF,JLEV))
      ENDDO
    ENDDO
  ENDIF

!*     3.1.20 COMPUTES [D V_surf/Dt] (NH model).

  IF (LNHDYN.AND.(.NOT.LGWADV)) THEN
    CALL GNH_TNDLAGADIAB_UVS( &
     ! --- INPUT -------------------------------------------------------------
     & NPROMA,KST,KEND, &
     & LRPLANE, &
     & PRCORI,PRATATX,PRATATH,ZUS0,ZVS0,ZSGRTSL,ZSGRTSM, &
     ! --- OUTPUT ------------------------------------------------------------
     & ZTNDUS,ZTNDVS &
     & )
  ENDIF

!*     3.1.21 COMPUTES [D(gw)/Dt] (NH model).

  IF (LNHDYN) THEN
    IF (LGWADV) THEN
      IF (LVFE_GW) THEN
        CALL GNH_TNDLAGADIAB_GW(NFLEVG,NPROMA,KST,KEND, &
         & PDELP=PDELP0(1,1),PDELNHPRE=ZDELNHPRE0,PMUSF=ZWDLMUS0F,PRDLR=PRDLR0,&
         & PTNDGWF_LAP=ZTNDGWF_LAP,PTNDGWF_OTH=ZTNDGWF_OTH,PDBBC=PDBBC)
        DO JLEV=1,NFLEVG
          DO JROF=KST,KEND
            PTNDGW(JROF,JLEV)=ZTNDGWF_LAP(JROF,JLEV)+ZTNDGWF_OTH(JROF,JLEV)
          ENDDO
        ENDDO
      ELSE
        CALL GNH_TNDLAGADIAB_GW(NFLEVG,NPROMA,KST,KEND, &
         & PDEP=ZPDEP0,PREF=PRE0F,PREH=PRE0,PMUSH=ZWDLMUS0H,PRDLR=PRDLR0,&
         & PTNDGWH_LAP=ZTNDGWH_LAP,PTNDGWH_OTH=ZTNDGWH_OTH)
        DO JLEV=1,NFLEVG
          DO JROF=KST,KEND
            PTNDGW(JROF,JLEV)=ZTNDGWH_LAP(JROF,JLEV-1)+ZTNDGWH_OTH(JROF,JLEV-1)
          ENDDO
        ENDDO
      ENDIF
    ELSE
      CALL GNH_TNDLAGADIAB_GW(NFLEVG,NPROMA,KST,KEND, &
       & POROGL=POROGL,POROGM=POROGM, &
       & POROGLM=ZOROGLM,POROGLL=ZOROGLL,POROGMM=ZOROGMM, &
       & PUS=ZUS0,PVS=ZVS0,PTNDUS=ZTNDUS,PTNDVS=ZTNDVS, &
       & PDEP=ZPDEP0,PREF=PRE0F,PREH=PRE0, &
       & PTNDGWH_LAP=ZTNDGWH_LAP,PTNDGWH_OTH=ZTNDGWH_OTH, &
       & PTNDGWF_OTH=ZTNDGWF_OTH,PDBBC=PDBBC)
    ENDIF
  ENDIF

!*     3.1.22 COMPUTES [D(pressure departure variable)/Dt] (NH model).

  IF (LNHDYN) THEN
    CALL GNH_TNDLAGADIAB_SPD( &
     ! --- INPUT -------------------------------------------------------------
     & NFLEVG,NPROMA,KST,KEND, &
     & PKAP0,P3DIVG,PVVEL0,PGWFT0, &
     & PEVEL0,PRDELP0,PGMV(1,1,YT0%MU),PGMV(1,1,YT0%MV),POROG,POROGL,POROGM, &
     ! --- OUTPUT ------------------------------------------------------------
     & PTNDPD &
     & )
  ENDIF

!*     3.1.23 COMPUTES [D(vertical divergence variable)/Dt] (NH model).

  IF (LNHDYN.AND.(.NOT.LGWADV)) THEN
    ! Remark: PTNDVD is useless (and not computed) if LGWADV.
    CALL GNH_TNDLAGADIAB_SVD( &
     ! --- INPUT -------------------------------------------------------------
     & NFLEVG,NPROMA,KST,KEND, &
     & PGMV(1,1,YT0%MU),PGMV(1,1,YT0%MV),PLHU0,PLHV0, &
     & PRDPHI,ZGWHL,ZGWHM,ZGWFL,ZGWFM,ZDVER0,PGMV(1,1,YT0%MDIV),P3DIVG, &
     & ZTNDGWH_LAP,ZTNDGWH_OTH,ZTNDGWF_OTH, &
     & PDBBC,ZPDEP0,PRE0,PRE0F,PDELP0(1,1),PLNPR0, &
     ! --- OUTPUT ------------------------------------------------------------
     & PTNDVD &
     & )
  ENDIF

ENDIF

!---------------------------------------------------------------
!      3.2         TIME t9 CALCULATIONS for HYD or NH-PDVD model
!---------------------------------------------------------------

IF ((.NOT.LNHDYN.OR.LNH_PDVD).AND. &
 & (.NOT.LTWOTL .AND. NCURRENT_ITER == 0)) THEN

!*     3.2.1 COMPUTE HALF-LAYER HYDROSTATIC PRESSURE.

  CALL GPPREH(NPROMA,KST,KEND,NFLEVG,VAH,VBH,PRE9)

!*     3.2.2 COMPUTE AUXILIARY ARRAYS RELATED TO THE VERTICAL
!            AND FULL-LAYER HYDROSTATIC PRESSURE.

  CALL GPXYB(NPROMA,KST,KEND,NFLEVG,VDELB,VC,&
   & PRE9,PDELP9(1,1),PRDELP9,PLNPR9,PALPH9,ZRTGR9,&
   & ZRPRE9,ZRPP9 &
   & )  
  CALL GPPREF(NPROMA,KST,KEND,NFLEVG,PALPH9,PRE9,PRE9F)

!*     3.2.3 COMPUTE "R", "cp" AND "kappa".

  CALL GPRCP(NPROMA,KST,KEND,NFLEVG,PGFL=PGFL,KGFLTYP=9,PCP=PCP9,PR=PR9)

!*     3.2.4 COMPUTE "RT".

  ZRT9(KST:KEND,1:NFLEVG)=PGMV(KST:KEND,1:NFLEVG,YT9%MT)*PR9(KST:KEND,1:NFLEVG)

!*     3.2.5 COMPUTE QUANTITIES NECESSARY FOR OPTION LVERCOR=.T..

  IF(LVERCOR)THEN
    IF (LSLAG) THEN
      CALL GPVCRS(NPROMVC,KST,KEND,NFLEVG,&
       & PRE9F,PRE9,PVCRSSA9F,ZVCRSSA9H,PGMV(1,1,YT9%MVCASRS),ZVCASRS9H)
    ENDIF
  ELSE
    IF (LSLAG) THEN
      PVCRSSA9F(1:NPROMVC,1:NFLEVG)=1.0_JPRB
      ZVCRSSA9H(1:NPROMVC,0:NFLEVG)=1.0_JPRB
      ZVCASRS9H(1:NPROMVC,0:NFLEVG)=1.0_JPRB
    ENDIF
  ENDIF

!*     3.2.6 COMPUTE QUANTITIES FOR NH MODEL.

  IF (LNHDYN) THEN
    CALL GNHPRE(NPROMA,NFLEVG,KST,KEND,PGMV(1,1,YT9%MSPD),PRE9F, &
     & PNHPRE9F,ZNHPPI9,ZRNHPPI9,ZPDEP9)
    DO JLEV=1,NFLEVG
      ZRRED9(KST:KEND,JLEV)=PR9(KST:KEND,JLEV)/ZNHPPI9(KST:KEND,JLEV)
    ENDDO
    CALL GNHPREH(NPROMA,NFLEVG,KST,KEND,PGMV(1,1,YT9%MSPD),PRE9, &
     & PDELP9(1,1),PLNPR9,ZNHPPI9,PNHPRE9H,ZDELNHPRE9)
  ELSE
    ZRNHPPI9(1:NPROMA,1:NFLEVG)=1.0_JPRB
  ENDIF

!*     3.2.7a COMPUTES THE RADIUS "r" , THE GEOPOTENTIAL HEIGHT "gz"
!             AND THEIR GRADIENTS IF LRWSDLR=T.

  ! In this case, nothing is done in 3.2.8. 
  IF (LNHDYN.AND.LRWSDLR) THEN
    ! "r/a", "a/r" and geopotential height.
    CALL GNHDLR(NPROMA,NFLEVG,KST,KEND,PGMV(1,1,YT9%MT),PR9,ZRNHPPI9, &
     & PLNPR9,PALPH9,POROG,PRDLR9,PHIH=PHI9,PHIF=PHIF9)
    PGMV(KST:KEND,1:NFLEVG,YT9%MRDLASR)=PRDLR9(KST:KEND,1:NFLEVG,JP_ASRF)
  ENDIF

!*     3.2.8 COMPUTES THE GEOPOTENTIAL HEIGHT "gz" AND ITS GRADIENT.

! * "gz" on layers and interlayers.

  IF((LDLDIAB.OR.LSIMPH)) THEN
    IF(LNHDYN.AND.(.NOT.LRWSDLR)) THEN
      PHI9(KST:KEND,NFLEVG)=POROG(KST:KEND)
      CALL GPGEO(NPROMA,KST,KEND,NFLEVG,PHI9,PHIF9,PGMV(1,1,YT9%MT),&
       & ZRRED9,PLNPR9,PALPH9)  
    ELSEIF(.NOT.LNHDYN) THEN
      PHI9(KST:KEND,NFLEVG)=POROG(KST:KEND)
      CALL GPGEO(NPROMA,KST,KEND,NFLEVG,PHI9,PHIF9,PGMV(1,1,YT9%MT),&
       & PR9,PLNPR9,PALPH9)  
    ENDIF
  ENDIF

!*     3.2.10 COMPUTES HALF-LEVEL WINDS.

  IF (.NOT.(LVERTFE.AND.LVFE_X_TERM.AND.LVFE_Z_TERM)) THEN
    ! * same remark as for time t half-level winds.
    CALL GPHLUV(NPROMA,KST,KEND,PWW0,PGMV(1,1,YT9%MU),PGMV(1,1,YT9%MV),&
     & ZLHU9,ZLHV9)
  ENDIF

  LLDER=.FALSE.
  CALL GPUVS(NFLEVG,NPROMA,KST,KEND,LLDER, &
   & PGMV(1,1,YT9%MU),PGMV(1,1,YT9%MV),ZUS9,ZVS9)

!*     3.2.13 COMPUTES TERM "NHX".

  ! * Currently we need it:
  !   - in the hydrostatic model if LMPA=T
  !   - in the NH model.

  ! caution: must use "R" and "pre/prehyd" at time t.
  IF (LLGPXX) THEN
    CALL GPXX( &
     ! --- INPUT -------------------------------------------------------------
     & NFLEVG,NPROMA,KST,KEND,PGPHL,PGPHM,PHI0FL,PHI0FM, &
     & PLNPR9,ZNHPPI0,PGMV(1,1,YT9%MT),PR0, &
     & PGMV(1,1,YT9%MU),PGMV(1,1,YT9%MV),ZLHU9,ZLHV9, &
     ! --- OUTPUT ------------------------------------------------------------
     & PNHXT9,LDRWSDLR=LRWSDLR,PRDLR=PRDLR9)
  ELSE
    PNHXT9(KST:KEND,1:NFLEVG)=PGMV(KST:KEND,1:NFLEVG,YT9%MNHX)
  ENDIF

!*     3.2.14 COMPUTES dver.

  ! * Currently we need it:
  !   - in the hydrostatic model if LMPA=T
  !   - in the NH model.

  IF (LNHDYN) THEN
    IF (NVDVAR == 3) THEN
      ZDVER9(KST:KEND,1:NFLEVG)=PGMV(KST:KEND,1:NFLEVG,YT9%MSVD)
    ELSEIF (NVDVAR == 4) THEN
      ZDVER9(KST:KEND,1:NFLEVG)= &
       & PGMV(KST:KEND,1:NFLEVG,YT9%MSVD)-PNHXT9(KST:KEND,1:NFLEVG)
    ENDIF
  ELSE
    ! dver_hyd=-(R/Rd)*(D+X+(cv/cp)(omega/prehyd))
    !  Caution: must use R, Kappa and (omega/prehyd) at time t.
    DO JLEV=1,NFLEVG
      DO JROF=KST,KEND
        ZDVER9(JROF,JLEV)=-(PR0(JROF,JLEV)/RD)*(PGMV(JROF,JLEV,YT9%MDIV) &
         & +PNHXT9(JROF,JLEV)+(1.0_JPRB-PKAP0(JROF,JLEV))*PVVEL0(JROF,JLEV))
      ENDDO
    ENDDO
  ENDIF

!*     3.2.16 COMPUTES term [gw].

  ! * Currently we need it:
  !   - in the hydrostatic model in some cases (full level only).
  !   - in the NH model (full lev or half lev or both according to the option).
  !   At least, full level values are always computed.
  LLGWF9=(.NOT.LTWOTL).AND.LMPA
  LLGDWI=.FALSE.
  IF (LNHDYN.AND.LGWADV.AND.LVERTFE.AND.LVFE_GW) THEN
    ! PGDW is required (at least for SL3TL)
    CALL GPGW(NFLEVG,NPROMA,KST,KEND,LLGWF9,LLGDWI, &
     & POROGL,POROGM,PLNPR9,PALPH9,ZUS9,ZVS9, &
     & PGMV(1,1,YT9%MT),ZDVER9,ZRNHPPI9,ZGWHT9,PGWFT9, &
     & LDRWSDLR=LRWSDLR,LDRWSDLR2=LRWSDLR2,PRDLR=PRDLR9,PGDW=ZGDW9)
  ELSE
    CALL GPGW(NFLEVG,NPROMA,KST,KEND,LLGWF9,LLGDWI, &
     & POROGL,POROGM,PLNPR9,PALPH9,ZUS9,ZVS9, &
     & PGMV(1,1,YT9%MT),ZDVER9,ZRNHPPI9,ZGWHT9,PGWFT9, &
     & LDRWSDLR=LRWSDLR,LDRWSDLR2=LRWSDLR2,PRDLR=PRDLR9)
  ENDIF
  IF (LNHDYN.AND.LGWADV) THEN
    IF (LVERTFE.AND.LVFE_GW) THEN
      PGWT9(KST:KEND,1:NFLEVG)=PGWFT9(KST:KEND,1:NFLEVG)
    ELSE
      PGWT9(KST:KEND,1:NFLEVG)=ZGWHT9(KST:KEND,0:NFLEVG-1)
    ENDIF
  ENDIF
  IF (LNHDYN.AND.LRDBBC) THEN
    PGWS(KST:KEND)=ZGWHT9(KST:KEND,NFLEVG)
  ENDIF

ENDIF

!------------------------------------------------------------------
!      3.3         TIME t0 AND t9 CALCULATIONS FOR Phi-gw NH MODEL
!------------------------------------------------------------------

IF (LNH_GEOGW) THEN
  CALL CPG_GPB_NHGEOGW( &
   !---------------------------------------------------------------------
   ! - INPUT .
   & KST,KEND,LDLDIAB,PRCORI, &
   & PRATATX,PRATATH,POROG,POROGL,POROGM,ZOROGLL,ZOROGMM,ZOROGLM, &
   !---------------------------------------------------------------------
   ! - INPUT/OUTPUT .
   & PGFL,PGMV, &
   !---------------------------------------------------------------------
   ! - OUTPUT .
   & PRE0,PRE0L,PRE0M,PRE0F,PNHPRE0F,PNHPRE0H,PDELP0,PRDELP0,PLNPR0,PALPH0, &
   & PHI0,PHIF0,PHI0FL,PHI0FM,PCP0,PR0,PRTGR0,PKAP0,PRRED0, &
   & PEVEL0,PVVEL0,PGWFT0,PSDVBC0,PKENE0, &
   & PSGRTL,PSGRTM,PGPHL,PGPHM,PSDIV0,PDIVP0,PSDFI0,PRT0L,PRT0M, &
   & PRE9,PRE9F,PNHPRE9F,PNHPRE9H,PDELP9,PRDELP9,PLNPR9,PALPH9, &
   & PHI9,PHIF9,PCP9,PR9,PGWFT9, &
   & PTNDPD,PTNDVD,P3DIVG,PDBBC,&
   & PNHXT0,PNHXT9,PQCHA0L,PQCHA0M)
ENDIF

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

!*       4.    INITIALISE AUXILIARY VARIABLES.
!              -------------------------------

!*     LPC_OLD option.

IF (LNHDYN.AND.LNH_PDVD.AND.LPC_OLD.AND.(NCURRENT_ITER == 0)) THEN
  ! Compute PD3Y0 and PD3Y9.
  CALL GNHY(NFLEVG,NPROMA,KST,KEND,PNHXT0,ZDVER0,PR0,PD3Y0)
  IF (.NOT.LTWOTL) THEN
    ! caution: must use "R" at time t.
    CALL GNHY(NFLEVG,NPROMA,KST,KEND,PNHXT9,ZDVER9,PR0,PD3Y9)
  ENDIF
ENDIF

IF (LNHDYN.AND.LNH_PDVD.AND.LPC_OLD.AND.(NCURRENT_ITER > 0)) THEN
  ! Compute PLHU0 and PLHV0.
  CALL GPHLUV(NPROMA,KST,KEND, &
   & PGPPC(1,MGPPCO_WW),PGMV(1,1,YT0%MU),PGMV(1,1,YT0%MV),&
   & PLHU0,PLHV0)
ENDIF

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

!*       5.    TIME DIMENSION.
!              ---------------

IF ((NCURRENT_ITER == 0).OR.(NCURRENT_ITER > 0 .AND. LPC_FULL)) THEN
  CALL GPINISLB(&
   & KST,KEND,PTE,.FALSE., &
   & PGFL, &
   & PGMV(1,1,YT9%MU),PGMV(1,1,YT9%MV),PGMV(1,1,YT9%MT), &
   & PGMV(1,1,YT9%MSPD),PGMV(1,1,YT9%MSVD),PNHXT9, &
   & PGMVS(1,YT9%MSP), &
   & PVVEL0,PRE0F, &
   & PGMVT1(1,1,YT1%MU),PGMVT1(1,1,YT1%MV),PGMVT1(1,1,YT1%MT),PGFLT1, &
   & PGMVT1(1,1,YT1%MSPD),PGMVT1(1,1,YT1%MSVD),PGMVT1(1,1,YT1%MNHX), &
   & PGMVT1S(1,YT1%MSP), &
   & PB2,PQICE,PQLI, &
   & PGWFT0=PGWFT0,PGDW0=ZGDW0,PGWS0=ZGWHT0(1,NFLEVG), &
   & PGWFT9=PGWFT0,PGDW9=ZGDW9,PGWS9=ZGWHT9(1,NFLEVG))

  IF (LSLAG.AND.LVERCOR) THEN
    PB2(KST:KEND,MSLB2VCVWEI:MSLB2VCVWEI+NFLEVG-1)=0.0_JPRB
  ENDIF

ENDIF

IF (NCURRENT_ITER == 0) THEN

  IF ((LDLDIAB.OR.LSIMPH).AND.(.NOT.LDLADNMI)) THEN
    CALL GPPOPER('SET1TO9',KBL=KBL)
  ENDIF

ENDIF

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

!*       6.    STORE T9 ARRAYS FOR NH TRAJECTORY.
!              ----------------------------------

IF (LNHDYN.AND.LTRAJNH.AND. &
 & ((NCURRENT_ITER == 0).OR.(NCURRENT_ITER > 0 .AND. LPC_FULL))) THEN
  INHFIELDS=NG3NH95*NFLEVG+1
  CALL WRNHTRAJM(NSTEP,KST,KEND,KSTGLO,INHFIELDS,&
   & PGMV(1,1,YT0%MSPD),PGMV(1,1,YT9%MSVD),&
   & PGMV(1,1,YT9%MDIV),PGMV(1,1,YT9%MU),PGMV(1,1,YT9%MV),PGMV(1,1,YT9%MT),&
   & PGMVS(1,YT9%MSP))  
ENDIF

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

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