#ifdef RS6K
@PROCESS NOCHECK
#endif
SUBROUTINE CPGAD(&
 !---------------------------------------------------------------------
 ! - INPUT .
 & CDCONF,KGPCOMP,&
 !---------------------------------------------------------------------
 ! - INPUT/OUTPUT IN TL.
 & PGMV,PGMVS,&
 !---------------------------------------------------------------------
 ! - OUTPUT IN TL.
 & PB1,PB2,PGMVT1,PGMVT1S,PGFLT1, &
 !---------------------------------------------------------------------
 ! - TRAJECTORY .
 & PGMV5,PGMV5S)


USE PARKIND1  ,ONLY : JPIM     ,JPRB
USE YOMHOOK   ,ONLY : LHOOK    ,DR_HOOK
USE YOMDIM   , ONLY : NFLEVG   ,NPROMA   ,NPROMM   ,NPROMNH  , &
 &                    NFGPPC   ,NGPBLKS
USE YOMDIMT  , ONLY : NPROMT
USE YOMCT0   , ONLY : LSLAG    ,LTWOTL   ,LNHDYN   ,LALLOPR  , &
 &                    LRETCFOU ,LPC_FULL ,LPC_OLD
USE YOMIOPNH , ONLY : LTRAJNH
USE YOMCT3   , ONLY : NSTEP
USE YOMDYN   , ONLY : TDT      ,NCURRENT_ITER      ,SLHDA    ,SLHDD0
USE YOMGC    , ONLY : RCORI    ,GEMU     ,GELAM    ,&
 & GM       ,GOMVRL   ,GOMVRM   ,&
 & OROG     ,OROGL    ,OROGM    ,OROGLL   ,OROGMM   ,OROGLM   ,&
 & NGPLAT
USE YOMGEM   , ONLY : NGPTOT   ,RATATH   ,RATATX   ,RSTRET
USE YOMLUN   , ONLY : NULOUT
USE YOMMP    , ONLY : NASLB1   ,NSLCORE  ,NFRSTLOFF
USE YOMSC2   , ONLY : NFLDSLB2 ,NFLDSLB1
USE YOM_YGFL , ONLY : YGFL, YQ
USE YOMGFL   , ONLY : GFL      ,GFL5
USE YOMSIMPHL, ONLY : LSIMPH   
USE YOMGMV   , ONLY : NDIMGMV  ,NDIMGMVS ,YT0,YT9,YT5,YT1
USE SURFACE_FIELDS_MIX, ONLY : YSD_VFD   

!**** *CPGAD* - Adjoint grid point calculations.

!     Purpose.
!     --------
!           Adjoint grid point calculations.

!**   Interface.
!     ----------
!        *CALL* *CPGAD*

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

!      INPUT:
!      ------
!       CDCONF         : configuration of work
!       KGPCOMP        : total number of grid points:
!                        ndglg*ndlon in global / ndguxg*ndlon in LAM
!                        used for model computations.

!      INPUT/OUTPUT IN TL:
!      -------------------
!       PGMV           : upper air GMV variables at t and t-dt.
!       PGMVS          : surface GMV variables at t and t-dt.

!      OUTPUT IN TL:
!      -------------
!       PB1            : "SLBUF1" buffer for interpolations in SL scheme.
!       PB2            : "SLBUF2" buffer.
!       PGMVT1         : upper air GMV variables buffer.
!       PGMVT1S        : surface GMV variables buffer.
!       PGFLT1         : GFL variables buffer.

!      TRAJECTORY:
!      -----------
!       PGMV5          : upper air GMV variables at t and t-dt.
!       PGMV5S         : surface GMV variables at t and t-dt.

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

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

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

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

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

!     Modifications.
!     --------------
!        Original : 88-02-04
!        Modified : 91-11-01 F.Rabier - UV formulation
!        Modified : 92-04-10 J.N. Thepaut - IO scheme.
!        Modified : 92-06-25 D.Dent - Remove event logic
!        Modified : 92-07-08 V.Ducrocq (introduction of a new curvature
!         term and modify the call to CPDYNAD)
!        Modified : 94-05-13 E.Bazile ( Modif CALL GPRCP,AD liquid water )
!      Modified 93-11-10 by R. EL Khatib (Non hydrostatic variables pointers)
!      Modified 95-03-01 by M.Hamrud (F90 re-write)
!      Modified (OCT 1995) by K. YESSAD: redimensioning of Z(X)NLT9 for
!                          2TL SL scheme.
!      Modified 96-01-18 by M. Janiskova: call for simplified phys.param
!      Modified 96-02-20 by L.Isaksen (Message Passing option added)
!      Modified 97-02-25 by J.F. Mahfouf (initialisation SL buffers t-dt)
!      Modified 97-08-21 by J.M. Piriou (APLPARSAD*'s arguments locks).
!      Modified 98-01-14 by E. Holm (Included ozone)
!        R. El Khatib : 97-12-23 PEVT0 ,LRUBC in GPCTY
!      Modified 99-02-22 by M. Janiskova (Reading radiation coefficients)
!      Modified 98-07-31 by K. YESSAD: cleanings.
!        - No longer third dimension to 'NLT9' arrays (removal of VESLA).
!      Modified 98-08-10 by K. YESSAD: removal of LRPOLE option.
!      Modified 99-07-27 by M.Janiskova (computation of vert.velocity perturb.)
!      Modified 99-09-17 by C. Temperton: change CPDYNAD call to enable
!                           the combination Eulerian + LIMPF
!      Modified 99-10-13 by C. Temperton: adjoint of semi-Lagrangian
!      Modified 98-11-24 by M.Charron (Nonhydrostatics)
!      Modified 99-02-17 by K. YESSAD: options LRETCFOU, LWRTCFOU.
!      Modified 99-03-31 by P. SMOLIKOVA: option LRDAORG (double averaging).
!      Modified 00-02-08 by C. Temperton: MSLB1C0 included for SL TL/AD
!         (for improved vectorization in the "update loop" in LARCINAD)
!      Modified 99-11-15 by K. YESSAD:
!       - new "zsdvbc5" in "gpcty", use "zsdvbc5" in "cpdynad", "gnhdynad"
!         and the future "lacdynad".
!       - cleaning of "cpdynad".
!      Modified 00-02-04 by C. Fischer: add dummy KNUMBE
!      Modified 00-08-15 Y.Tremolet : use module TRAJECTORY
!      Modified 2000-12  A. Untch: vertical finite element scheme
!      Modified 00-10-02 C. Fischer : call gnhsimad (moved from scan2mad)
!      Modified 01-02-07 K. Yessad and F. Bouyssel:
!       - adapt MF_PHYSTL to SL2TL + cleaning of MF_PHYSTL.
!      Modified 01-07-11 by K. YESSAD: relaxation of thin layer hyp for SL2TL.
!      Modified 01-08-30 by K. YESSAD: pruning and some other cleanings.
!        R. El Khatib : 01-08-07 Pruning options
!        Modified 03-2002  J.Vivoda  interface to SC2...9 routines
!      Modified 03-2002  J.Vivoda : PC schemes for NH dynamics (LPC_XXXX keys)
!      Modified 02-07-09 by C. Fischer and K. Yessad (as supervisor):
!              make code more modular and reorder operations (before splitting)
!         1. scalar and local initializations
!         2. allocations
!         3. gridpoint computations for the trajectory (later cpg_gp5)
!         7. final gridpoint computations - adjoint
!         6. dynamics (+ Buizza's physics) - adjoint
!         5. physics - adjoint
!         4. perturbation computations prior to MF physics - adjoint
!         8. final operations on trajectory arrays: map factor ...
!         9. deallocations
!      Modified 02-09-30 P.Smolikova : interface to SC2...9 for d4 in NH
!      Modified 03-05-21 by C. Temperton: Case LSPRT=.TRUE.
!   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 ZSPT.. arrays and use PGMVS instead.
!      Jan-2004 K. YESSAD  make the code valid for any value of NFLSA.
!   09-Jun-2004 J. Masek   NH cleaning (LPC_NOTR, LLFULLIMP)
!   01-Jul-2004 K. Yessad  Make clearer the tests for PC scheme.
!   06-Jul-2004 K. Yessad  Pointers of PTRGPPC are now computed in SUDIM2.
!      Jul-2004 K. Yessad  Modularization of CPGTL according to CPG.
!   17-Apr-2007 S. Ivatek-S Over dimensioning of ZGPNH and ZGPNH5 to NFGPNH+1,
!                          boundary checking problem if NFGPNH=0 bf
!   N. Wedi and K. Yessad (Jan 2008): different dev for NH model and PC scheme
!   K. Yessad (Dec 2008): remove dummy CDLOCK + cleanings
!   F. Vana  13-Jan-2009: add SLHDA and SLHDD0 for SLHD KAPPA
! End Modifications
!------------------------------------------------------------------------------

IMPLICIT NONE

CHARACTER(LEN=1)  ,INTENT(IN)    :: CDCONF
INTEGER(KIND=JPIM),INTENT(IN)    :: KGPCOMP
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PGMV(NPROMA,NFLEVG,NDIMGMV,NGPBLKS)
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PGMVS(NPROMA,NDIMGMVS,NGPBLKS)
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PB1(NASLB1,NFLDSLB1)
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PB2(NPROMA,NFLDSLB2,NGPBLKS)
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PGMVT1(NPROMA,NFLEVG,YT1%NDIM,NGPBLKS)
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PGMVT1S(NPROMA,YT1%NDIMS,NGPBLKS)
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PGFLT1(NPROMA,NFLEVG,YGFL%NDIM1,NGPBLKS)
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PGMV5(NPROMA,NFLEVG,YT5%NDIM,NGPBLKS)
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PGMV5S(NPROMA,YT5%NDIMS,NGPBLKS)

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

! - semi-reduced derivatives of orography.
REAL(KIND=JPRB) :: ZOROGL(NPROMA)                   ! cf. POROGL in CPG5_GP.
REAL(KIND=JPRB) :: ZOROGM(NPROMA)                   ! cf. POROGM in CPG5_GP.
REAL(KIND=JPRB) :: ZOROGLL(NPROMNH)                 ! cf. POROGLL in CPG5_GP.
REAL(KIND=JPRB) :: ZOROGMM(NPROMNH)                 ! cf. POROGMM in CPG5_GP.
REAL(KIND=JPRB) :: ZOROGLM(NPROMNH)                 ! cf. POROGLM in CPG5_GP.
! - other auxiliary quantities at time 5.
REAL(KIND=JPRB) :: ZPRE5(NPROMA,0:NFLEVG)           ! cf. PRE5 in CPG5_GP.
REAL(KIND=JPRB) :: ZPRE5F(NPROMA,NFLEVG)            ! cf. PRE5F in CPG5_GP.
REAL(KIND=JPRB) :: ZPRE5L(NPROMA)                   ! cf. PRE5L in CPG5_GP.
REAL(KIND=JPRB) :: ZPRE5M(NPROMA)                   ! cf. PRE5M in CPG5_GP.
REAL(KIND=JPRB) :: ZRPRE5(NPROMA,NFLEVG)            ! cf. PRPRE5 in CPG5_GP.
REAL(KIND=JPRB) :: ZRPREF5(NPROMA,NFLEVG)           ! cf. PRPREF5 in CPG5_GP.
REAL(KIND=JPRB) :: ZRPP5(NPROMA,NFLEVG)             ! cf. PRPP5 in CPG5_GP.
REAL(KIND=JPRB) :: ZRT5(NPROMA,NFLEVG)              ! cf. PRT5 in CPG5_GP.
REAL(KIND=JPRB) :: ZRT5L(NPROMA,NFLEVG)             ! cf. PRT5L in CPG5_GP.
REAL(KIND=JPRB) :: ZRT5M(NPROMA,NFLEVG)             ! cf. PRT5M in CPG5_GP.
REAL(KIND=JPRB) :: ZDELP5(NPROMA,0:NFLEVG+1)        ! cf. PDELP5 in CPG5_GP.
REAL(KIND=JPRB) :: ZRDELP5(NPROMA,NFLEVG)           ! cf. PRDELP5 in CPG5_GP.
REAL(KIND=JPRB) :: ZLNPR5(NPROMA,NFLEVG)            ! cf. PLNPR5 in CPG5_GP.
REAL(KIND=JPRB) :: ZALPH5(NPROMA,NFLEVG)            ! cf. PALPH5 in CPG5_GP.
REAL(KIND=JPRB) :: ZRTGR5(NPROMA,NFLEVG)            ! cf. PRTGR5 in CPG5_GP.
REAL(KIND=JPRB) :: ZWW5(NPROMNH,NFLEVG)             ! cf. PWW5 in CPG5_GP.
REAL(KIND=JPRB) :: ZRRED5(NPROMNH,NFLEVG)           ! cf. PRRED5 in CPG5_GP.
REAL(KIND=JPRB) :: ZSGRT5L(NPROMA,NFLEVG)           ! cf. PSGRT5L in CPG5_GP.
REAL(KIND=JPRB) :: ZSGRT5M(NPROMA,NFLEVG)           ! cf. PSGRT5M in CPG5_GP.
REAL(KIND=JPRB) :: ZGPH5L(NPROMA,0:NFLEVG)          ! cf. PGPH5L in CPG5_GP.
REAL(KIND=JPRB) :: ZGPH5M(NPROMA,0:NFLEVG)          ! cf. PGPH5M in CPG5_GP.
REAL(KIND=JPRB) :: ZLHU5(NPROMNH,0:NFLEVG)          ! cf. PLHU5 in CPG5_GP.
REAL(KIND=JPRB) :: ZLHV5(NPROMNH,0:NFLEVG)          ! cf. PLHV5 in CPG5_GP.
REAL(KIND=JPRB) :: ZR5(NPROMA,NFLEVG)               ! cf. PR5 in CPG5_GP.
REAL(KIND=JPRB) :: ZCP5(NPROMA,NFLEVG)              ! cf. PCP5 in CPG5_GP.
REAL(KIND=JPRB) :: ZKAP5(NPROMA,NFLEVG)             ! cf. PKAP5 in CPG5_GP.
REAL(KIND=JPRB) :: ZPHI5(NPROMA,0:NFLEVG)           ! cf. PHI5 in CPG5_GP.
REAL(KIND=JPRB) :: ZPHIF5(NPROMA,NFLEVG)            ! cf. PHIF5 in CPG5_GP.
REAL(KIND=JPRB) :: ZEVEL5(NPROMA,0:NFLEVG)          ! cf. PEVEL5 in CPG5_GP.
REAL(KIND=JPRB) :: ZSDIV5(NPROMA,0:NFLEVG)          ! cf. PSDIV5 in CPG5_GP.
REAL(KIND=JPRB) :: ZSDVBC5(NPROMA,0:NFLEVG)         ! cf. PSDVBC5 in CPG5_GP.
REAL(KIND=JPRB) :: ZVVEL5(NPROMA,NFLEVG)            ! cf. PVVEL5 in CPG5_GP.
REAL(KIND=JPRB) :: ZSD_VF5(NPROMA,YSD_VFD%NDIM5)    ! Surface traj (VARSF)
REAL(KIND=JPRB) :: ZQCHA5L(NPROMNH,NFLEVG)          ! cf. PQCHA5L in CPG5_GP.
REAL(KIND=JPRB) :: ZQCHA5M(NPROMNH,NFLEVG)          ! cf. PQCHA5M in CPG5_GP.
REAL(KIND=JPRB) :: ZALPH5L(NPROMA,NFLEVG)           ! cf. PALPH5L in CPG5_GP.
REAL(KIND=JPRB) :: ZALPH5M(NPROMA,NFLEVG)           ! cf. PALPH5M in CPG5_GP.
REAL(KIND=JPRB) :: ZALPHPL5L(NPROMA,NFLEVG)         ! cf. PALPHPL5L in CPG5_GP.
REAL(KIND=JPRB) :: ZALPHPL5M(NPROMA,NFLEVG)         ! cf. PALPHPL5M in CPG5_GP.
REAL(KIND=JPRB) :: ZLNPR5L(NPROMA,NFLEVG)           ! cf. PLNPR5L in CPG5_GP.
REAL(KIND=JPRB) :: ZLNPR5M(NPROMA,NFLEVG)           ! cf. PLNPR5M in CPG5_GP.
REAL(KIND=JPRB) :: ZRNHPPI5(NPROMA,NFLEVG)          ! cf. PRNHPPI5 in CPG5_GP.
REAL(KIND=JPRB) :: ZPHI5FL(NPROMA,NFLEVG)           ! cf. PHI5FL in CPG5_GP.
REAL(KIND=JPRB) :: ZPHI5FM(NPROMA,NFLEVG)           ! cf. PHI5FM in CPG5_GP.
REAL(KIND=JPRB) :: ZCOEFD5(NPROMA,NFLEVG)           ! cf. PCOEFD5 in CPG5_GP.
REAL(KIND=JPRB) :: ZCOEFA5(NPROMA,NFLEVG)           ! cf. PCOEFA5 in CPG5_GP.
REAL(KIND=JPRB) :: ZCOEFAPL5(NPROMA,NFLEVG)         ! cf. PCOEFAPL5 in CPG5_GP.
REAL(KIND=JPRB) :: ZNH15L(NPROMA,NFLEVG)            ! cf. PNH15L in CPG5_GP.
REAL(KIND=JPRB) :: ZNH15M(NPROMA,NFLEVG)            ! cf. PNH15M in CPG5_GP.
! - other auxiliary quantities at time 95 dimensioned with NPROMT.
REAL(KIND=JPRB) :: ZPRE95(NPROMT,0:NFLEVG)          ! cf. PRE95 in CPG5_GP.
REAL(KIND=JPRB) :: ZPRE95F(NPROMT,NFLEVG)           ! cf. PRE95F in CPG5_GP.
REAL(KIND=JPRB) :: ZRPRE95(NPROMT,NFLEVG)           ! cf. PRPRE95 in CPG5_GP.
REAL(KIND=JPRB) :: ZRPP95(NPROMT,NFLEVG)            ! cf. PRPP95 in CPG5_GP.
REAL(KIND=JPRB) :: ZDELP95(NPROMT,0:NFLEVG+1)       ! cf. PDELP95 in CPG5_GP.
REAL(KIND=JPRB) :: ZRDELP95(NPROMT,NFLEVG)          ! cf. PRDELP95 in CPG5_GP.
REAL(KIND=JPRB) :: ZLNPR95(NPROMT,NFLEVG)           ! cf. PLNPR95 in CPG5_GP.
REAL(KIND=JPRB) :: ZALPH95(NPROMT,NFLEVG)           ! cf. PALPH95 in CPG5_GP.
REAL(KIND=JPRB) :: ZUT95(NPROMT,NFLEVG)             ! cf. PUT95 in CPG5_GP.
REAL(KIND=JPRB) :: ZVT95(NPROMT,NFLEVG)             ! cf. PVT95 in CPG5_GP.
REAL(KIND=JPRB) :: ZTT95(NPROMT,NFLEVG)             ! cf. PTT95 in CPG5_GP.
REAL(KIND=JPRB) :: ZQT95(NPROMT,NFLEVG)             ! cf. PQT95 in CPG5_GP.
! - other auxiliary quantities at time 0.
REAL(KIND=JPRB) :: ZPRE0(NPROMA,0:NFLEVG)           ! cf. PRE0 in CPG_GP_AD.
REAL(KIND=JPRB) :: ZPRE0F(NPROMA,NFLEVG)            ! cf. PRE0F in CPG_GP_AD.
REAL(KIND=JPRB) :: ZPRE0L(NPROMA)                   ! cf. PRE0L in CPG_GP_AD.
REAL(KIND=JPRB) :: ZPRE0M(NPROMA)                   ! cf. PRE0M in CPG_GP_AD.
REAL(KIND=JPRB) :: ZRT0L(NPROMA,NFLEVG)             ! cf. PRT0L in CPG_GP_AD.
REAL(KIND=JPRB) :: ZRT0M(NPROMA,NFLEVG)             ! cf. PRT0M in CPG_GP_AD.
REAL(KIND=JPRB) :: ZDELP0(NPROMA,0:NFLEVG+1)        ! cf. PDELP0 in CPG_GP_AD.
REAL(KIND=JPRB) :: ZRDELP0(NPROMA,NFLEVG)           ! cf. PRDELP0 in CPG_GP_AD.
REAL(KIND=JPRB) :: ZLNPR0(NPROMA,NFLEVG)            ! cf. PLNPR0 in CPG_GP_AD.
REAL(KIND=JPRB) :: ZALPH0(NPROMA,NFLEVG)            ! cf. PALPH0 in CPG_GP_AD.
REAL(KIND=JPRB) :: ZRTGR0(NPROMA,NFLEVG)            ! cf. PRTGR0 in CPG_GP_AD.
REAL(KIND=JPRB) :: ZWW0(NPROMNH,NFLEVG)             ! cf. PWW0 in CPG_GP_AD.
REAL(KIND=JPRB) :: ZRRED0(NPROMNH,NFLEVG)           ! cf. PRRED0 in CPG_GP_AD.
REAL(KIND=JPRB) :: ZRTR0(NPROMNH,NFLEVG)            ! cf. PRTR0 in CPG_GP_AD.
REAL(KIND=JPRB) :: ZSGRTL(NPROMA,NFLEVG)            ! cf. PSGRTL in CPG_GP_AD.
REAL(KIND=JPRB) :: ZSGRTM(NPROMA,NFLEVG)            ! cf. PSGRTM in CPG_GP_AD.
REAL(KIND=JPRB) :: ZGPHL(NPROMA,0:NFLEVG)           ! cf. PGPHL in CPG_GP_AD.
REAL(KIND=JPRB) :: ZGPHM(NPROMA,0:NFLEVG)           ! cf. PGPHM in CPG_GP_AD.
REAL(KIND=JPRB) :: ZGRAWL(NPROMNH,0:NFLEVG)         ! cf. PGRAWL in CPG_GP_AD.
REAL(KIND=JPRB) :: ZGRAWM(NPROMNH,0:NFLEVG)         ! cf. PGRAWM in CPG_GP_AD.
REAL(KIND=JPRB) :: ZLHU0(NPROMNH,0:NFLEVG)          ! cf. PLHU0 in CPG_GP_AD.
REAL(KIND=JPRB) :: ZLHV0(NPROMNH,0:NFLEVG)          ! cf. PLHV0 in CPG_GP_AD.
REAL(KIND=JPRB) :: ZR0(NPROMA,NFLEVG)               ! cf. PR0 in CPG_GP_AD.
REAL(KIND=JPRB) :: ZCP0(NPROMA,NFLEVG)              ! cf. PCP0 in CPG_GP_AD.
REAL(KIND=JPRB) :: ZKAP0(NPROMA,NFLEVG)             ! cf. PKAP0 in CPG_GP_AD.
REAL(KIND=JPRB) :: ZPHI0(NPROMA,0:NFLEVG)           ! cf. PHI0 in CPG_GP_AD.
REAL(KIND=JPRB) :: ZPHIF0(NPROMA,NFLEVG)            ! cf. PHIF0 in CPG_GP_AD.
REAL(KIND=JPRB) :: ZEVEL0(NPROMA,0:NFLEVG)          ! cf. PEVEL0 in CPG_GP_AD.
REAL(KIND=JPRB) :: ZSDIV0(NPROMA,0:NFLEVG)          ! cf. PSDIV0 in CPG_GP_AD.
REAL(KIND=JPRB) :: ZSDVBC0(NPROMA,0:NFLEVG)         ! cf. PSDVBC0 in CPG_GP_AD.
REAL(KIND=JPRB) :: ZVVEL0(NPROMA,NFLEVG)            ! cf. PVVEL0 in CPG_GP_AD.
REAL(KIND=JPRB) :: ZDIVP0(NPROMA,NFLEVG)            ! cf. PDIVP0 in CPG_GP_AD.
REAL(KIND=JPRB) :: ZKENE0(NPROMA,NFLEVG)            ! cf. PKENE0 in CPG_GP_AD.
REAL(KIND=JPRB) :: ZD3Y(NPROMNH,NFLEVG)             ! cf. PD3Y in CPG_DYN_AD.
! - quantities for physics.
REAL(KIND=JPRB) :: ZQS(NPROMM)                      ! cf. PQS in MF_PHYS_AD.
REAL(KIND=JPRB) :: ZQS1(NPROMM)                     ! cf. PQS1 in MF_PHYS_AD.
REAL(KIND=JPRB) :: ZTS(NPROMM)                      ! cf. PTS in MF_PHYS_AD.
REAL(KIND=JPRB) :: ZTS1(NPROMM)                     ! cf. PTS1 in MF_PHYS_AD.
REAL(KIND=JPRB) :: ZSNS(NPROMM)                     ! cf. PSNS in MF_PHYS_AD.
! - other auxiliary quantities at time 95.
REAL(KIND=JPRB),ALLOCATABLE :: ZLHU95(:,:)          ! cf. PLHU95 in CPG5_GP.
REAL(KIND=JPRB),ALLOCATABLE :: ZLHV95(:,:)          ! cf. PLHV95 in CPG5_GP.
REAL(KIND=JPRB),ALLOCATABLE :: ZR95(:,:)            ! cf. PR95 in CPG5_GP.
REAL(KIND=JPRB),ALLOCATABLE :: ZCP95(:,:)           ! cf. PCP95 in CPG5_GP.
REAL(KIND=JPRB),ALLOCATABLE :: ZPHI95(:,:)          ! cf. PHI95 in CPG5_GP.
REAL(KIND=JPRB),ALLOCATABLE :: ZPHIF95(:,:)         ! cf. PHIF95 in CPG5_GP.
REAL(KIND=JPRB),ALLOCATABLE :: ZRRED95(:,:)         ! cf. PRRED95 in CPG5_GP.
REAL(KIND=JPRB),ALLOCATABLE :: ZDIVT95(:,:)         ! cf. PDIVT95 in CPG5_GP.
REAL(KIND=JPRB),ALLOCATABLE :: ZVORT95(:,:)         ! cf. PVORT95 in CPG5_GP.
REAL(KIND=JPRB),ALLOCATABLE :: ZUT95L(:,:)          ! cf. PUT95L in CPG5_GP.
REAL(KIND=JPRB),ALLOCATABLE :: ZVT95L(:,:)          ! cf. PVT95L in CPG5_GP.
REAL(KIND=JPRB),ALLOCATABLE :: ZSPDT95(:,:)         ! cf. PSPDT95 in CPG5_GP.
REAL(KIND=JPRB),ALLOCATABLE :: ZSVDT95(:,:)         ! cf. PSVDT95 in CPG5_GP.
! - other auxiliary quantities at time 9.
REAL(KIND=JPRB),ALLOCATABLE :: ZPRE9(:,:)           ! cf. PRE9 in CPG_GP_AD.
REAL(KIND=JPRB),ALLOCATABLE :: ZPRE9F(:,:)          ! cf. PRE9F in CPG_GP_AD.
REAL(KIND=JPRB),ALLOCATABLE :: ZDELP9(:,:)          ! cf. PDELP9 in CPG_GP_AD.
REAL(KIND=JPRB),ALLOCATABLE :: ZRDELP9(:,:)         ! cf. PRDELP9 in CPG_GP_AD.
REAL(KIND=JPRB),ALLOCATABLE :: ZLNPR9(:,:)          ! cf. PLNPR9 in CPG_GP_AD.
REAL(KIND=JPRB),ALLOCATABLE :: ZALPH9(:,:)          ! cf. PALPH9 in CPG_GP_AD.
REAL(KIND=JPRB),ALLOCATABLE :: ZLHU9(:,:)           ! cf. PLHU9 in CPG_GP_AD.
REAL(KIND=JPRB),ALLOCATABLE :: ZLHV9(:,:)           ! cf. PLHV9 in CPG_GP_AD.
REAL(KIND=JPRB),ALLOCATABLE :: ZR9(:,:)             ! cf. PR9 in CPG_GP_AD.
REAL(KIND=JPRB),ALLOCATABLE :: ZCP9(:,:)            ! cf. PCP9 in CPG_GP_AD.
REAL(KIND=JPRB),ALLOCATABLE :: ZPHI9(:,:)           ! cf. PHI9 in CPG_GP_AD.
REAL(KIND=JPRB),ALLOCATABLE :: ZPHIF9(:,:)          ! cf. PHIF9 in CPG_GP_AD.
! - other quantities.
REAL(KIND=JPRB),ALLOCATABLE :: ZGPPC(:,:)           ! cf. PGPPC in CPG_GP.
REAL(KIND=JPRB),ALLOCATABLE :: ZGPPC5(:,:)          ! cf. PGPPC5 in CPG5_GP.
REAL(KIND=JPRB),ALLOCATABLE :: ZSLBUF1AU(:,:)       ! local version of SLBUF1 
! - NH intermediate storage for the corrector step of LPC_OLD.
REAL(KIND=JPRB),ALLOCATABLE :: ZGPUT5(:,:)
REAL(KIND=JPRB),ALLOCATABLE :: ZGPVT5(:,:)
REAL(KIND=JPRB),ALLOCATABLE :: ZGPTT5(:,:)
REAL(KIND=JPRB),ALLOCATABLE :: ZGPSVDT5(:,:)
REAL(KIND=JPRB),ALLOCATABLE :: ZGPVORT5(:,:)
REAL(KIND=JPRB),ALLOCATABLE :: ZGPDIVT5(:,:)
REAL(KIND=JPRB),ALLOCATABLE :: ZGPUT5L(:,:)
REAL(KIND=JPRB),ALLOCATABLE :: ZGPVT5L(:,:)
REAL(KIND=JPRB),ALLOCATABLE :: ZGPSPT5(:)

! Remark: for the time being, ZUT95L, ZVT95L, ZSPDT95, ZSVDT95, ZVORT95,
! ZDIVT95, ZGPH5L, ZGPH5M, ZLHU95, ZLHV95 are not used out of CPG5_GP.

REAL(KIND=JPRB) :: ZEPS
REAL(KIND=JPRB) :: ZDT, ZDTPHY, ZTE
REAL(KIND=JPRB) :: ZDUM(NPROMA,NFLEVG)
REAL(KIND=JPRB) :: ZDUMSPT(NPROMA)

INTEGER(KIND=JPIM) :: JROF,JKGLO,JFLD
INTEGER(KIND=JPIM) :: IEND, IENDC, IST, ISTC
INTEGER(KIND=JPIM) :: IBL
INTEGER(KIND=JPIM) :: ICEND, ICENDE
INTEGER(KIND=JPIM) :: IFIELDS, IFLAG
INTEGER(KIND=JPIM) :: IGL3, IGL4
INTEGER(KIND=JPIM) :: IGPCOMP
INTEGER(KIND=JPIM) :: IOFF
INTEGER(KIND=JPIM) :: ISTGLO

LOGICAL :: LLADNMI, LLRSTEP
LOGICAL :: LLSTR
LOGICAL :: LLUSEPB1

REAL(KIND=JPRB) :: ZHOOK_HANDLE

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

#include "cpg5_gp.intfb.h"
#include "cpg_dyn_ad.intfb.h"
#include "cpg_end_ad.intfb.h"
#include "cpg_gp_ad.intfb.h"
#include "cpg_zero_ad.intfb.h"
#include "gpmpfc.intfb.h"
#include "gpmpfc_gmvs.intfb.h"
#include "mf_physad.intfb.h"

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

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

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

!*       1.    Local scalar initializations.
!              -----------------------------

IF(NSTEP > 0) THEN
  LLRSTEP=.FALSE.
ELSE
  LLRSTEP=.TRUE.
ENDIF

! Adiabatic NNMI iteration
LLADNMI= CDCONF == 'E' .OR. CDCONF == 'F'

IF (LSLAG .AND. ((NCURRENT_ITER == 0).OR.(NCURRENT_ITER > 0 .AND. LPC_FULL)))&
 & THEN
  LLUSEPB1=.TRUE.
ELSE
  LLUSEPB1=.FALSE.
ENDIF

ZEPS=100.0_JPRB*TINY(1.0_JPRB)
LLSTR=(ABS(RSTRET-1.0_JPRB)>ZEPS)


! * Time dimension.
ZDT=0.0_JPRB
ZDTPHY=0.0_JPRB
ZTE=0.0_JPRB
IF (CDCONF == 'A'.OR.CDCONF == 'S') THEN
  ZDT=TDT
  ZDTPHY=TDT
  ZTE=1.0_JPRB
ELSEIF (LLADNMI) THEN
  ZDT=1.0_JPRB
  ZDTPHY=0.0_JPRB
  ZTE=0.0_JPRB
ENDIF

IGPCOMP=KGPCOMP
IST=1
ISTC=1

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

!*       2.    Allocations.
!              ------------

!$OMP PARALLEL &
!$OMP& PRIVATE (JKGLO,IOFF,ISTGLO,IBL,ICEND,ICENDE,IEND,IENDC) &
!$OMP& PRIVATE (JROF,JFLD) &
!$OMP& PRIVATE (IGL3,IGL4,IFLAG)&
!$OMP& PRIVATE ( ZOROGL, ZOROGM, ZOROGLL, ZOROGMM, ZOROGLM)&
!$OMP& PRIVATE ( ZPRE5, ZPRE5F, ZPRE5L, ZPRE5M, ZRPRE5, ZRPREF5)&
!$OMP& PRIVATE ( ZRPP5, ZRT5, ZRT5L, ZRT5M, ZDELP5, ZRDELP5)&
!$OMP& PRIVATE ( ZLNPR5, ZALPH5, ZRTGR5, ZWW5, ZRRED5, ZSGRT5L, ZSGRT5M)&
!$OMP& PRIVATE ( ZGPH5L, ZGPH5M, ZLHU5, ZLHV5, ZR5)&
!$OMP& PRIVATE ( ZCP5, ZKAP5, ZPHI5, ZPHIF5, ZEVEL5, ZSDIV5, ZSDVBC5, ZVVEL5)&
!$OMP& PRIVATE ( ZSD_VF5, ZPRE95, ZPRE95F, ZRPRE95, ZRPP95)&
!$OMP& PRIVATE ( ZDELP95, ZRDELP95, ZLNPR95, ZALPH95, ZUT95, ZVT95)&
!$OMP& PRIVATE ( ZTT95, ZQT95)&
!$OMP& PRIVATE ( ZPRE0, ZPRE0F, ZPRE0L, ZPRE0M, ZRT0L, ZRT0M, ZDELP0, ZRDELP0)&
!$OMP& PRIVATE ( ZLNPR0, ZALPH0, ZRTGR0, ZWW0, ZRRED0, ZRTR0, ZSGRTL, ZSGRTM)&
!$OMP& PRIVATE ( ZGPHL, ZGPHM, ZGRAWL, ZGRAWM, ZLHU0, ZLHV0, ZR0, ZCP0)&
!$OMP& PRIVATE ( ZKAP0, ZPHI0, ZPHIF0, ZEVEL0, ZSDIV0, ZSDVBC0, ZVVEL0, ZDIVP0)&
!$OMP& PRIVATE ( ZKENE0, ZD3Y, ZQS, ZQS1, ZTS, ZTS1, ZSNS)&
!$OMP& PRIVATE ( ZLHU95, ZLHV95, ZR95, ZCP95, ZPHI95, ZPHIF95)&
!$OMP& PRIVATE ( ZRRED95, ZDIVT95, ZVORT95, ZUT95L, ZVT95L, ZSPDT95, ZSVDT95)&
!$OMP& PRIVATE ( ZPRE9, ZPRE9F, ZDELP9, ZRDELP9, ZLNPR9, ZALPH9, ZLHU9)&
!$OMP& PRIVATE ( ZLHV9, ZR9, ZCP9, ZPHI9, ZPHIF9)&
!$OMP& PRIVATE ( ZGPPC, ZGPPC5, ZSLBUF1AU, ZGPUT5, ZGPVT5, ZGPTT5, ZGPSVDT5)&
!$OMP& PRIVATE ( ZGPVORT5, ZGPDIVT5, ZGPUT5L, ZGPVT5L, ZGPSPT5, ZDUM, ZDUMSPT)&
!$OMP& PRIVATE ( ZQCHA5L, ZQCHA5M, ZALPH5L, ZALPH5M, ZALPHPL5L, ZALPHPL5M)&
!$OMP& PRIVATE ( ZLNPR5L, ZLNPR5M, ZRNHPPI5, ZPHI5FL, ZPHI5FM, ZCOEFD5)&
!$OMP& PRIVATE ( ZCOEFA5, ZCOEFAPL5, ZNH15L, ZNH15M )

! * Allocate some "95" variables (leap-frog scheme only).

IF ((.NOT.LTWOTL).AND.LNHDYN) THEN
  IF (.NOT.ALLOCATED(ZLHU95)) ALLOCATE(ZLHU95(NPROMNH,0:NFLEVG))
  IF (LALLOPR) WRITE(NULOUT,9990) 'ZLHU95   ',SIZE(ZLHU95),SHAPE(ZLHU95)
  IF (.NOT.ALLOCATED(ZLHV95)) ALLOCATE(ZLHV95(NPROMNH,0:NFLEVG))
  IF (LALLOPR) WRITE(NULOUT,9990) 'ZLHV95   ',SIZE(ZLHV95),SHAPE(ZLHV95)
ENDIF

IF ((.NOT.LTWOTL).AND.LSIMPH) THEN
  IF (.NOT.ALLOCATED(ZR95)) ALLOCATE(ZR95(NPROMA,NFLEVG))
  IF (LALLOPR) WRITE(NULOUT,9990) 'ZR95     ',SIZE(ZR95),SHAPE(ZR95)
  IF (.NOT.ALLOCATED(ZCP95)) ALLOCATE(ZCP95(NPROMA,NFLEVG))
  IF (LALLOPR) WRITE(NULOUT,9990) 'ZCP95    ',SIZE(ZCP95),SHAPE(ZCP95)
  IF (.NOT.ALLOCATED(ZPHI95)) ALLOCATE(ZPHI95(NPROMA,0:NFLEVG))
  IF (LALLOPR) WRITE(NULOUT,9990) 'ZPHI95   ',SIZE(ZPHI95),SHAPE(ZPHI95)
  IF (.NOT.ALLOCATED(ZPHIF95)) ALLOCATE(ZPHIF95(NPROMA,NFLEVG))
  IF (LALLOPR) WRITE(NULOUT,9990) 'ZPHIF95  ',SIZE(ZPHIF95),SHAPE(ZPHIF95)
  IF (.NOT.ALLOCATED(ZRRED95)) ALLOCATE(ZRRED95(NPROMA,NFLEVG))
  IF (LALLOPR) WRITE(NULOUT,9990) 'ZRRED95  ',SIZE(ZRRED95),SHAPE(ZRRED95)
ENDIF

IF ( ((NCURRENT_ITER == 0).OR.(NCURRENT_ITER > 0 .AND. LPC_FULL))&
 & .AND. LNHDYN .AND. (LTRAJNH.OR.(.NOT.LTWOTL)) ) THEN
  IF (.NOT.ALLOCATED(ZDIVT95)) ALLOCATE(ZDIVT95(NPROMNH,NFLEVG))
  IF (LALLOPR) WRITE(NULOUT,9990) 'ZDIVT95  ',SIZE(ZDIVT95),SHAPE(ZDIVT95)
  IF (.NOT.ALLOCATED(ZVORT95)) ALLOCATE(ZVORT95(NPROMNH,NFLEVG))
  IF (LALLOPR) WRITE(NULOUT,9990) 'ZVORT95  ',SIZE(ZVORT95),SHAPE(ZVORT95)
  IF (.NOT.ALLOCATED(ZUT95L)) ALLOCATE(ZUT95L(NPROMNH,NFLEVG))
  IF (LALLOPR) WRITE(NULOUT,9990) 'ZUT95L   ',SIZE(ZUT95L),SHAPE(ZUT95L)
  IF (.NOT.ALLOCATED(ZVT95L)) ALLOCATE(ZVT95L(NPROMNH,NFLEVG))
  IF (LALLOPR) WRITE(NULOUT,9990) 'ZVT95L   ',SIZE(ZVT95L),SHAPE(ZVT95L)
ENDIF

IF ((.NOT.LTWOTL).AND.LNHDYN) THEN
  IF (.NOT.ALLOCATED(ZSPDT95)) ALLOCATE(ZSPDT95(NPROMNH,NFLEVG))
  IF (LALLOPR) WRITE(NULOUT,9990) 'ZSPDT95  ',SIZE(ZSPDT95),SHAPE(ZSPDT95)
  IF (.NOT.ALLOCATED(ZSVDT95)) ALLOCATE(ZSVDT95(NPROMNH,NFLEVG))
  IF (LALLOPR) WRITE(NULOUT,9990) 'ZSVDT95  ',SIZE(ZSVDT95),SHAPE(ZSVDT95)
ENDIF

! * Allocate some "9" variables (leap-frog scheme only).

IF ((LTWOTL.AND.LPC_FULL).OR.(.NOT.LTWOTL)) THEN
  IF (.NOT.ALLOCATED(ZPRE9)) ALLOCATE(ZPRE9(NPROMA,0:NFLEVG))
  IF (LALLOPR) WRITE(NULOUT,9990) 'ZPRE9    ',SIZE(ZPRE9),SHAPE(ZPRE9)
ENDIF

IF ((.NOT.LTWOTL) .AND. (NCURRENT_ITER == 0) .AND. &
 & ((LSIMPH.AND.(.NOT.LLADNMI)).OR.LNHDYN) ) THEN
  IF (.NOT.ALLOCATED(ZPRE9F)) ALLOCATE(ZPRE9F(NPROMA,NFLEVG))
  IF (LALLOPR) WRITE(NULOUT,9990) 'ZPRE9F   ',SIZE(ZPRE9F),SHAPE(ZPRE9F)
  IF (.NOT.ALLOCATED(ZDELP9)) ALLOCATE(ZDELP9(NPROMA,0:NFLEVG+1))
  IF (LALLOPR) WRITE(NULOUT,9990) 'ZDELP9   ',SIZE(ZDELP9),SHAPE(ZDELP9)
  IF (.NOT.ALLOCATED(ZRDELP9)) ALLOCATE(ZRDELP9(NPROMA,NFLEVG))
  IF (LALLOPR) WRITE(NULOUT,9990) 'ZRDELP9  ',SIZE(ZRDELP9),SHAPE(ZRDELP9)
  IF (.NOT.ALLOCATED(ZLNPR9)) ALLOCATE(ZLNPR9(NPROMA,NFLEVG))
  IF (LALLOPR) WRITE(NULOUT,9990) 'ZLNPR9   ',SIZE(ZLNPR9),SHAPE(ZLNPR9)
  IF (.NOT.ALLOCATED(ZALPH9)) ALLOCATE(ZALPH9(NPROMA,NFLEVG))
  IF (LALLOPR) WRITE(NULOUT,9990) 'ZALPH9   ',SIZE(ZALPH9),SHAPE(ZALPH9)
ENDIF

IF ((.NOT.LTWOTL).AND.LNHDYN) THEN
  IF (.NOT.ALLOCATED(ZLHU9)) ALLOCATE(ZLHU9(NPROMNH,0:NFLEVG))
  IF (LALLOPR) WRITE(NULOUT,9990) 'ZLHU9    ',SIZE(ZLHU9),SHAPE(ZLHU9)
  IF (.NOT.ALLOCATED(ZLHV9)) ALLOCATE(ZLHV9(NPROMNH,0:NFLEVG))
  IF (LALLOPR) WRITE(NULOUT,9990) 'ZLHV9    ',SIZE(ZLHV9),SHAPE(ZLHV9)
ENDIF

IF ((.NOT.LTWOTL).AND.LSIMPH) THEN
  IF (.NOT.ALLOCATED(ZR9)) ALLOCATE(ZR9(NPROMA,NFLEVG))
  IF (LALLOPR) WRITE(NULOUT,9990) 'ZR9      ',SIZE(ZR9),SHAPE(ZR9)
  IF (.NOT.ALLOCATED(ZCP9)) ALLOCATE(ZCP9(NPROMA,NFLEVG))
  IF (LALLOPR) WRITE(NULOUT,9990) 'ZCP9     ',SIZE(ZCP9),SHAPE(ZCP9)
  IF (.NOT.ALLOCATED(ZPHI9)) ALLOCATE(ZPHI9(NPROMA,0:NFLEVG))
  IF (LALLOPR) WRITE(NULOUT,9990) 'ZPHI9    ',SIZE(ZPHI9),SHAPE(ZPHI9)
  IF (.NOT.ALLOCATED(ZPHIF9)) ALLOCATE(ZPHIF9(NPROMA,NFLEVG))
  IF (LALLOPR) WRITE(NULOUT,9990) 'ZPHIF9   ',SIZE(ZPHIF9),SHAPE(ZPHIF9)
ENDIF

! * Allocate some other arrays.

IF (.NOT.ALLOCATED(ZGPPC)) ALLOCATE(ZGPPC(NPROMA,NFGPPC+1))
IF (LALLOPR) WRITE(NULOUT,9990) 'ZGPPC    ',SIZE(ZGPPC),SHAPE(ZGPPC)
IF (.NOT.ALLOCATED(ZGPPC5)) ALLOCATE(ZGPPC5(NPROMA,NFGPPC+1))
IF (LALLOPR) WRITE(NULOUT,9990) 'ZGPPC5   ',SIZE(ZGPPC5),SHAPE(ZGPPC5)

IF (.NOT.ALLOCATED(ZSLBUF1AU)) ALLOCATE(ZSLBUF1AU(NPROMA,NFLDSLB1))
IF (LALLOPR) WRITE(NULOUT,9990) 'ZSLBUF1AU',SIZE(ZSLBUF1AU),SHAPE(ZSLBUF1AU)

! * Allocate the NH intermediate storage arrays for the corrector step of
!   LPC_OLD.

IF ((NCURRENT_ITER > 0 .AND. LPC_OLD).AND.LTRAJNH) THEN

  IF (.NOT.ALLOCATED(ZGPUT5)) ALLOCATE(ZGPUT5(NPROMA,NFLEVG))
  IF (LALLOPR) WRITE(NULOUT,9990) 'ZGPUT5   ',SIZE(ZGPUT5),SHAPE(ZGPUT5)
  IF (.NOT.ALLOCATED(ZGPVT5)) ALLOCATE(ZGPVT5(NPROMA,NFLEVG))
  IF (LALLOPR) WRITE(NULOUT,9990) 'ZGPVT5   ',SIZE(ZGPVT5),SHAPE(ZGPVT5)
  IF (.NOT.ALLOCATED(ZGPTT5)) ALLOCATE(ZGPTT5(NPROMA,NFLEVG))
  IF (LALLOPR) WRITE(NULOUT,9990) 'ZGPTT5   ',SIZE(ZGPTT5),SHAPE(ZGPTT5)
  IF (.NOT.ALLOCATED(ZGPSVDT5)) ALLOCATE(ZGPSVDT5(NPROMA,NFLEVG))
  IF (LALLOPR) WRITE(NULOUT,9990) 'ZGPSVDT5 ',SIZE(ZGPSVDT5),SHAPE(ZGPSVDT5)
  IF (.NOT.ALLOCATED(ZGPVORT5)) ALLOCATE(ZGPVORT5(NPROMA,NFLEVG))
  IF (LALLOPR) WRITE(NULOUT,9990) 'ZGPVORT5 ',SIZE(ZGPVORT5),SHAPE(ZGPVORT5)
  IF (.NOT.ALLOCATED(ZGPDIVT5)) ALLOCATE(ZGPDIVT5(NPROMA,NFLEVG))
  IF (LALLOPR) WRITE(NULOUT,9990) 'ZGPDIVT5 ',SIZE(ZGPDIVT5),SHAPE(ZGPDIVT5)
  IF (.NOT.ALLOCATED(ZGPUT5L)) ALLOCATE(ZGPUT5L(NPROMA,NFLEVG))
  IF (LALLOPR) WRITE(NULOUT,9990) 'ZGPUT5L  ',SIZE(ZGPUT5L),SHAPE(ZGPUT5L)
  IF (.NOT.ALLOCATED(ZGPVT5L)) ALLOCATE(ZGPVT5L(NPROMA,NFLEVG))
  IF (LALLOPR) WRITE(NULOUT,9990) 'ZGPVT5L  ',SIZE(ZGPVT5L),SHAPE(ZGPVT5L)
  IF (.NOT.ALLOCATED(ZGPSPT5)) ALLOCATE(ZGPSPT5(NPROMA))
  IF (LALLOPR) WRITE(NULOUT,9990) 'ZGPSPT5  ',SIZE(ZGPSPT5),SHAPE(ZGPSPT5)

ENDIF

ZDUM(:,:)=0.0_JPRB
ZDUMSPT(:)=0.0_JPRB
ZGPPC(:,:)=0.0_JPRB
ZGPPC5(:,:)=0.0_JPRB

!     ------------------------------------------------------------------
!     BEGIN LOOP ON JKGLO
!     ------------------------------------------------------------------

!$OMP DO SCHEDULE(DYNAMIC,1) 
DO JKGLO=1,IGPCOMP,NPROMA

  IOFF=JKGLO
  ISTGLO=JKGLO
  IBL=(JKGLO-1)/NPROMA+1
  ICEND=MIN(NPROMA,IGPCOMP-JKGLO+1)
  ICENDE=MIN(NPROMA,NGPTOT-JKGLO+1)
  IEND=ICEND
  IENDC=ICENDE

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

!*       3.    Gridpoint computations for the trajectory
!              -----------------------------------------

  IF ((NCURRENT_ITER > 0 .AND. LPC_OLD).AND.LTRAJNH) THEN

    ! this preliminary copy is done to avoid overwriting of the input P.T5 .
    ! the P.T5 should be kept when exiting cpgad at corrector step
    ! (needed since P.T5 are given through a global module array by scan2mad) .

    ZGPUT5(:,:)=PGMV5(:,:,YT5%MU,IBL)
    ZGPVT5(:,:)=PGMV5(:,:,YT5%MV,IBL)
    ZGPTT5(:,:)=PGMV5(:,:,YT5%MT,IBL)
    ZGPSVDT5(:,:)=PGMV5(:,:,YT5%MSVD,IBL)
    ZGPVORT5(:,:)=PGMV5(:,:,YT5%MVOR,IBL)
    ZGPDIVT5(:,:)=PGMV5(:,:,YT5%MDIV,IBL)
    ZGPUT5L(:,:)=PGMV5(:,:,YT5%MUL,IBL)
    ZGPVT5L(:,:)=PGMV5(:,:,YT5%MVL,IBL)
    ZGPSPT5(:)=PGMV5S(:,YT5%MSP,IBL)

  ENDIF

  CALL CPG5_GP( &
   !---------------------------------------------------------------------
   ! - INPUT .
   & IST,IEND,ISTGLO, &
   & LLADNMI, &
   & GM(IOFF), &
   & OROG(IOFF), &
   & OROGL(IOFF),OROGM(IOFF),OROGLL(IOFF),OROGMM(IOFF),OROGLM(IOFF), &
   !---------------------------------------------------------------------
   ! - INPUT/OUTPUT .
   & GFL5(1,1,1,IBL),PGMV5(1,1,1,IBL),PGMV5S(1,1,IBL), &
   !---------------------------------------------------------------------
   ! - OUTPUT .
   & ZOROGL,ZOROGM,ZOROGLL,ZOROGMM,ZOROGLM, &
   & ZUT95,ZUT95L,ZVT95,ZVT95L,ZTT95,ZQT95, &
   & ZSPDT95,ZSVDT95,ZVORT95,ZDIVT95, &
   & ZPRE5,ZPRE5L,ZPRE5M,ZPRE5F, &
   & ZDELP5,ZRDELP5,ZLNPR5,ZALPH5, &
   & ZRPRE5,ZRPREF5,ZRPP5, &
   & ZLHU5,ZLHV5, &
   & ZPHI5,ZPHIF5, &
   & ZCP5,ZR5,ZRTGR5, &
   & ZKAP5,ZRRED5, &
   & ZEVEL5,ZVVEL5,ZSDVBC5, &
   & ZSGRT5L,ZSGRT5M,ZGPH5L,ZGPH5M,&
   & ZSDIV5,&
   & ZRT5,ZRT5L,ZRT5M,ZWW5, &
   & ZPRE95,ZPRE95F,&
   & ZDELP95,ZRDELP95,ZLNPR95,ZALPH95, &
   & ZRPRE95,ZRPP95,ZRRED95, &
   & ZLHU95,ZLHV95, &
   & ZPHI95,ZPHIF95,ZCP95,ZR95, &
   & ZGPPC5,&
   & ZQS,ZQS1,ZTS,ZTS1,ZSNS, &
   & ZSD_VF5, &
   & ZQCHA5L,ZQCHA5M, &
   & ZALPH5L,ZALPH5M,ZALPHPL5L,ZALPHPL5M,ZLNPR5L,ZLNPR5M, &
   & ZRNHPPI5,ZPHI5FL,ZPHI5FM, &
   & ZCOEFD5,ZCOEFA5,ZCOEFAPL5, &
   & ZNH15L,ZNH15M)

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

!*       7.    Final part of vector gridpoint operations.
!              ------------------------------------------

  CALL CPG_ZERO_AD( &
   ! --------------------------------------------------------------------------
   ! - INPUT:
   & CDCONF,IST,IEND,&
   ! --------------------------------------------------------------------------
   ! - OUTPUT:
   & ZRT0L,ZRT0M,&
   & ZPRE0F,ZRDELP0,ZLNPR0,ZALPH0,ZRTGR0,&
   & ZR0,ZCP0,ZKAP0,ZPHIF0,ZVVEL0,ZDIVP0,ZKENE0,ZSGRTL,ZSGRTM,&
   & ZPRE9F,ZRDELP9,ZLNPR9,ZALPH9,ZR9,ZCP9,ZPHIF9,&
   & ZPRE0,ZDELP0,ZPHI0,ZEVEL0,ZSDIV0,ZSDVBC0,&
   & ZPRE9,ZDELP9,ZPHI9,&
   & ZRTR0,ZGRAWL,ZGRAWM,ZLHU0,ZLHV0,ZLHU9,ZLHV9,&
   & ZPRE0L,ZPRE0M,&
   & ZD3Y,ZRRED0,ZGPHL,ZGPHM,ZWW0,ZGPPC)

  CALL CPG_END_AD( &
   !---------------------------------------------------------------------
   ! - INPUT in TL code.
   & IST,IEND,ISTC,IENDC,ISTGLO, &
   & GM(IOFF), &
   & ZD3Y,ZRRED0,ZGPHL,ZGPHM,ZWW0, &
   !---------------------------------------------------------------------
   ! - INPUT/OUTPUT in TL code.
   & GFL(1,1,1,IBL),ZGPPC,PGMV(1,1,1,IBL),PGMVS(1,1,IBL))

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

!*       6.    Dynamics.
!              ---------

  ! * Set ZSLBUF1AU to zero.
  IF (LLUSEPB1) THEN
    DO JFLD=1,NFLDSLB1
      DO JROF=ISTGLO,MIN(ISTGLO-1+NPROMA,IGPCOMP)
        ZSLBUF1AU(JROF-ISTGLO+1,JFLD)=0.0_JPRB
      ENDDO
    ENDDO
  ENDIF

  IF (LLUSEPB1) THEN
    DO JFLD=1,NFLDSLB1
      DO JROF=ISTGLO,MIN(ISTGLO-1+NPROMA,IGPCOMP)
        ZSLBUF1AU(JROF-ISTGLO+1,JFLD)= &
         & ZSLBUF1AU(JROF-ISTGLO+1,JFLD)+PB1(NSLCORE(JROF),JFLD)
      ENDDO
    ENDDO
  ENDIF

  CALL CPG_DYN_AD( &
   ! --- INPUT IN TL ----------------------------------------------------
   & CDCONF, &
   & IST,IEND, &
   & LLADNMI, &
   & ZDT, &
   & SLHDA(IOFF),SLHDD0(IOFF), &
   & GM(IOFF),RCORI(IOFF),GOMVRL(IOFF),GOMVRM(IOFF),RATATX(IOFF),RATATH(IOFF),&
   & OROG(IOFF),ZOROGL,ZOROGM, &
   & ZPRE0,ZDELP0,ZRDELP0, &
   & ZPHI0,ZPHIF0,ZCP0,ZR0, &
   & ZKAP0,ZEVEL0,ZVVEL0,ZSDVBC0,ZKENE0, &
   & ZSGRTL,ZSGRTM, &
   & GFL(1,1,1,IBL),&
   ! --- INPUT/OUTPUT IN TL ---------------------------------------------
   & PGMV(1,1,1,IBL),PGMVS(1,1,IBL),&
   & ZSLBUF1AU,PB2(1,1,IBL),PGMVT1(1,1,1,IBL),PGMVT1S(1,1,IBL), &
   & PGFLT1(1,1,1,IBL), &
   ! --- TRAJECTORY-INPUT -----------------------------------------------
   & ZPRE5,ZDELP5,ZRDELP5, &
   & ZPHI5,ZPHIF5, &
   & ZCP5,ZR5,ZKAP5, &
   & ZEVEL5,ZVVEL5,ZSDVBC5, &
   & ZSD_VF5,&
   ! --- TRAJECTORY-INOUT -----------------------------------------------
   & PGMV5(1,1,1,IBL),PGMV5S(1,1,IBL),GFL5(1,1,1,IBL))

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

!*       5.    Call physics.
!              -------------

  ! * IGL3: first DM-local lat index of the current NPROMA-packet.
  IGL3=NGPLAT(IOFF)-NFRSTLOFF

  ! * IGL4: last DM-local lat index of the current NPROMA-packet.
  IGL4=NGPLAT(ICEND+JKGLO-1)-NFRSTLOFF

  ! * Unlagged ECMWF physics (CALL EC_PHYS_AD) or
  !   split ECMWF physics (CALL EC_PHYS_LSLPHY_AD) not yet coded.

  ! * Unlagged MF physics.
  !   Remark! the management of physics for LPC_FULL PC scheme
  !   (CALL CPG_PT_AD before CALL MF_PHYSAD) is not yet coded.
  IF (LSIMPH.AND.(.NOT.LLADNMI).AND.(NCURRENT_ITER == 0)) THEN

    CALL MF_PHYSAD &
     & (IST,IEND,IGL3,IGL4,IOFF,ISTGLO,LRETCFOU,ZDTPHY, &
     & GELAM(IOFF),GEMU(IOFF),GM(IOFF),OROG(IOFF), &
     & PGMV(1,1,YT0%MU,IBL),PGMV(1,1,YT0%MV,IBL),PGMV(1,1,YT0%MT,IBL),&
     & GFL(1,1,YQ%MP,IBL),GFL(1,1,YQ%MPL,IBL),GFL(1,1,YQ%MPM,IBL), &
     & ZCP0,ZDELP0,ZRDELP0,ZPHI0,ZPHIF0,ZPRE0,ZPRE0F,ZEVEL0, &
     & PGMV(1,1,YT9%MU,IBL),PGMV(1,1,YT9%MV,IBL),PGMV(1,1,YT9%MT,IBL),&
     & GFL(1,1,YQ%MP9,IBL), &
     & ZCP9,ZDELP9,ZRDELP9,ZPHI9,ZPHIF9,ZPRE9,ZPRE9F, &
     & ZQS,ZQS1,ZSNS,ZTS,ZTS1, &
     & ZSLBUF1AU,PGMVT1(1,1,1,IBL),PGFLT1(1,1,1,IBL), &
     & IFIELDS, &
     & PGMV5(1,1,YT5%MU,IBL),PGMV5(1,1,YT5%MV,IBL),PGMV5(1,1,YT5%MT,IBL),&
     & GFL5(1,1,YQ%MP5,IBL),GFL5(1,1,YQ%MP5L,IBL),GFL5(1,1,YQ%MP5M,IBL), &
     & ZCP5,ZDELP5,ZRDELP5,ZPHI5,ZPHIF5,ZPRE5,ZPRE5F,ZEVEL5, &
     & ZUT95,ZVT95,ZTT95,ZQT95, &
     & ZCP95,ZDELP95,ZRDELP95,ZPHI95,ZPHIF95,ZPRE95,ZPRE95F,ZSD_VF5)  

  ENDIF

  ! * At this level ZSLBUF1AU and PB1 are not used any longer.
  !   They are reset to zero (for security).
  IF (LLUSEPB1) THEN
    DO JFLD=1,NFLDSLB1
      DO JROF=ISTGLO,MIN(ISTGLO-1+NPROMA,IGPCOMP)
        ZSLBUF1AU(JROF-ISTGLO+1,JFLD)=0.0_JPRB
        PB1(NSLCORE(JROF),JFLD)=0.0_JPRB
      ENDDO
    ENDDO
  ENDIF

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

!*       4.    Gridpoint computations before physics for perturbations
!              at t-dt and t
!              -------------------------------------------------------

  CALL CPG_GP_AD( &
   !---------------------------------------------------------------------
   ! - INPUT .
   & IST,IEND,ISTC,IENDC,ISTGLO,LLRSTEP,LLADNMI,ZTE,GM(IOFF), &
   !---------------------------------------------------------------------
   ! - INPUT IN TL.
   & GFL(1,1,1,IBL), &
   !---------------------------------------------------------------------
   ! - INPUT/OUTPUT IN TL.
   & PGMV(1,1,1,IBL),PGMVS(1,1,IBL), &
   !---------------------------------------------------------------------
   ! - OUTPUT IN TL.
   & ZPRE0,ZPRE0L,ZPRE0M,ZPRE0F,ZDELP0,ZRDELP0,ZLNPR0,ZALPH0, &
   !NYC-NH & ZLHU0,ZLHV0, &
   & ZPHI0,ZPHIF0,ZCP0,ZR0,ZRTGR0,ZKAP0, &
   !NYC-NH & ZRRED0, &
   & ZEVEL0,ZVVEL0,ZSDVBC0,ZKENE0, &
   & ZSGRTL,ZSGRTM,ZGPHL,ZGPHM, &
   & ZSDIV0,ZDIVP0,ZRT0L,ZRT0M, &
   !NYC-NH & ZWW0, &
   & ZPRE9,ZPRE9F,ZDELP9,ZRDELP9,ZLNPR9,ZALPH9,ZPHI9,ZPHIF9,ZCP9,ZR9, &
   & ZGPPC,PB2(1,1,IBL), &
   & PGMVT1(1,1,1,IBL),PGMVT1S(1,1,IBL),PGFLT1(1,1,1,IBL), &
   !---------------------------------------------------------------------
   ! - TRAJECTORY (INPUT) .
   & GFL5(1,1,1,IBL),PGMV5(1,1,1,IBL),PGMV5S(1,1,IBL), &
   & ZPRE5,ZPRE5L,ZPRE5M,ZPRE5F,ZDELP5,ZRDELP5,ZLNPR5,ZALPH5,ZCP5,ZR5,ZRTGR5, &
   !NYC-NH & ZRRED5, &
   & ZVVEL5,ZSDIV5,ZRT5,ZRT5L,ZRT5M, &
   !NYC-NH & ZWW5, &
   & ZRPRE5,ZRPREF5,ZRPP5, &
   !NYC-NH & ZGPPC5,&
   !NYC-NH & ZQCHA5L,ZQCHA5M, &
   & ZALPH5L,ZALPH5M,ZALPHPL5L,ZALPHPL5M,ZLNPR5L,ZLNPR5M, &
   & ZRNHPPI5,ZPHI5FL,ZPHI5FM, &
   & ZCOEFD5,ZCOEFA5,ZCOEFAPL5, &
   !NYC-NH & ZNH15L,ZNH15M, &
   !NYC-NH & ZUT95,ZVT95, &
   & ZTT95,ZPRE95,ZPRE95F,ZDELP95,ZRDELP95,ZLNPR95,ZALPH95,ZR95, &
   & ZRPRE95,ZRPP95 &
   !NYC-NH & ZRRED95 &
   & )

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

!*       8.    Final part of vector gridpoint operations: trajectory.
!              ------------------------------------------------------

  ! * Apply the mapping factor:

  IF(LLSTR) THEN

    IFLAG=1

    CALL GPMPFC(&
     ! --- INPUT ---------------------------------------------------------
     & IST,IEND,IFLAG,GM(IOFF),&
     ! --- INPUT/OUTPUT --------------------------------------------------
     & PGMV5(1,1,YT5%MU,IBL),PGMV5(1,1,YT5%MV,IBL),PGMV5(1,1,YT5%MDIV,IBL),&
     & PGMV5(1,1,YT5%MTL,IBL),PGMV5(1,1,YT5%MTM,IBL),&
     & PGMV5(1,1,YT5%MSPDL,IBL),PGMV5(1,1,YT5%MSPDM,IBL),&
     & PGMV5(1,1,YT5%MSVDL,IBL),PGMV5(1,1,YT5%MSVDM,IBL),&
     & ZDUM,ZDUM,&
     & ZDUM,ZDUM,ZDUM,ZDUM,ZDUM,ZDUM,ZDUM,ZDUM,ZDUM,&
     & PGMV5(1,1,YT5%MUL,IBL),PGMV5(1,1,YT5%MVL,IBL),PGMV5(1,1,YT5%MVOR,IBL),&
     & ZDUM,ZDUM,ZDUM,&
     & GFL5(1,1,1,IBL))

    CALL GPMPFC_GMVS(&
     ! --- INPUT ---------------------------------------------------------
     & IST,IEND,IFLAG,GM(IOFF),&
     ! --- INPUT/OUTPUT --------------------------------------------------
     & PGMV5S(1,YT5%MSPL,IBL),PGMV5S(1,YT5%MSPM,IBL),&
     & ZDUMSPT,ZDUMSPT)

  ENDIF

  ! * Copy back the true T0 trajectory arrays previously overwritten
  !   by the T1* arrays (end of the predictor step - traj)

  IF ((NCURRENT_ITER > 0 .AND. LPC_OLD).AND.LTRAJNH) THEN

    PGMV5(:,:,YT5%MU,IBL)=ZGPUT5(:,:)
    PGMV5(:,:,YT5%MV,IBL)=ZGPVT5(:,:)
    PGMV5(:,:,YT5%MT,IBL)=ZGPTT5(:,:)
    PGMV5(:,:,YT5%MSVD,IBL)=ZGPSVDT5(:,:)
    PGMV5(:,:,YT5%MVOR,IBL)=ZGPVORT5(:,:)
    PGMV5(:,:,YT5%MDIV,IBL)=ZGPDIVT5(:,:)
    PGMV5(:,:,YT5%MUL,IBL)=ZGPUT5L(:,:)
    PGMV5(:,:,YT5%MVL,IBL)=ZGPVT5L(:,:)
    PGMV5S(:,YT5%MSP,IBL)=ZGPSPT5(:)

  ENDIF

ENDDO

!$OMP END DO

!     ------------------------------------------------------------------
!     END LOOP ON JKGLO
!     ------------------------------------------------------------------

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

!*       9.    Deallocations
!              -------------

! * Deallocate some "95" variables.

IF (ALLOCATED(ZLHU95)) THEN
  DEALLOCATE(ZLHU95)
  IF (LALLOPR) WRITE(NULOUT,9991) 'ZLHU95   '
ENDIF
IF (ALLOCATED(ZLHV95)) THEN
  DEALLOCATE(ZLHV95)
  IF (LALLOPR) WRITE(NULOUT,9991) 'ZLHV95   '
ENDIF
IF (ALLOCATED(ZR95)) THEN
  DEALLOCATE(ZR95)
  IF (LALLOPR) WRITE(NULOUT,9991) 'ZR95     '
ENDIF
IF (ALLOCATED(ZCP95)) THEN
  DEALLOCATE(ZCP95)
  IF (LALLOPR) WRITE(NULOUT,9991) 'ZCP95    '
ENDIF
IF (ALLOCATED(ZPHI95)) THEN
  DEALLOCATE(ZPHI95)
  IF (LALLOPR) WRITE(NULOUT,9991) 'ZPHI95   '
ENDIF
IF (ALLOCATED(ZPHIF95)) THEN
  DEALLOCATE(ZPHIF95)
  IF (LALLOPR) WRITE(NULOUT,9991) 'ZPHIF95  '
ENDIF
IF (ALLOCATED(ZRRED95)) THEN
  DEALLOCATE(ZRRED95)
  IF (LALLOPR) WRITE(NULOUT,9991) 'ZRRED95  '
ENDIF
IF (ALLOCATED(ZDIVT95)) THEN
  DEALLOCATE(ZDIVT95)
  IF (LALLOPR) WRITE(NULOUT,9991) 'ZDIVT95  '
ENDIF
IF (ALLOCATED(ZVORT95)) THEN
  DEALLOCATE(ZVORT95)
  IF (LALLOPR) WRITE(NULOUT,9991) 'ZVORT95  '
ENDIF
IF (ALLOCATED(ZUT95L)) THEN
  DEALLOCATE(ZUT95L)
  IF (LALLOPR) WRITE(NULOUT,9991) 'ZUT95L   '
ENDIF
IF (ALLOCATED(ZVT95L)) THEN
  DEALLOCATE(ZVT95L)
  IF (LALLOPR) WRITE(NULOUT,9991) 'ZVT95L   '
ENDIF
IF (ALLOCATED(ZSPDT95)) THEN
  DEALLOCATE(ZSPDT95)
  IF (LALLOPR) WRITE(NULOUT,9991) 'ZSPDT95  '
ENDIF
IF (ALLOCATED(ZSVDT95)) THEN
  DEALLOCATE(ZSVDT95)
  IF (LALLOPR) WRITE(NULOUT,9991) 'ZSVDT95  '
ENDIF

! * Deallocate some "9" variables.

IF (ALLOCATED(ZPRE9)) THEN
  DEALLOCATE(ZPRE9)
  IF (LALLOPR) WRITE(NULOUT,9991) 'ZPRE9    '
ENDIF
IF (ALLOCATED(ZPRE9F)) THEN
  DEALLOCATE(ZPRE9F)
  IF (LALLOPR) WRITE(NULOUT,9991) 'ZPRE9F   '
ENDIF
IF (ALLOCATED(ZDELP9)) THEN
  DEALLOCATE(ZDELP9)
  IF (LALLOPR) WRITE(NULOUT,9991) 'ZDELP9   '
ENDIF
IF (ALLOCATED(ZRDELP9)) THEN
  DEALLOCATE(ZRDELP9)
  IF (LALLOPR) WRITE(NULOUT,9991) 'ZRDELP9  '
ENDIF
IF (ALLOCATED(ZLNPR9)) THEN
  DEALLOCATE(ZLNPR9)
  IF (LALLOPR) WRITE(NULOUT,9991) 'ZLNPR9   '
ENDIF
IF (ALLOCATED(ZALPH9)) THEN
  DEALLOCATE(ZALPH9)
  IF (LALLOPR) WRITE(NULOUT,9991) 'ZALPH9   '
ENDIF
IF (ALLOCATED(ZLHU9)) THEN
  DEALLOCATE(ZLHU9)
  IF (LALLOPR) WRITE(NULOUT,9991) 'ZLHU9    '
ENDIF
IF (ALLOCATED(ZLHV9)) THEN
  DEALLOCATE(ZLHV9)
  IF (LALLOPR) WRITE(NULOUT,9991) 'ZLHV9    '
ENDIF
IF (ALLOCATED(ZR9)) THEN
  DEALLOCATE(ZR9)
  IF (LALLOPR) WRITE(NULOUT,9991) 'ZR9      '
ENDIF
IF (ALLOCATED(ZCP9)) THEN
  DEALLOCATE(ZCP9)
  IF (LALLOPR) WRITE(NULOUT,9991) 'ZCP9     '
ENDIF
IF (ALLOCATED(ZPHI9)) THEN
  DEALLOCATE(ZPHI9)
  IF (LALLOPR) WRITE(NULOUT,9991) 'ZPHI9    '
ENDIF
IF (ALLOCATED(ZPHIF9)) THEN
  DEALLOCATE(ZPHIF9)
  IF (LALLOPR) WRITE(NULOUT,9991) 'ZPHIF9   '
ENDIF

! * Deallocate some other arrays.

IF (ALLOCATED(ZGPPC)) THEN
  DEALLOCATE(ZGPPC)
  IF (LALLOPR) WRITE(NULOUT,9991) 'ZGPPC    '
ENDIF
IF (ALLOCATED(ZGPPC5)) THEN
  DEALLOCATE(ZGPPC5)
  IF (LALLOPR) WRITE(NULOUT,9991) 'ZGPPC5   '
ENDIF
IF (ALLOCATED(ZSLBUF1AU)) THEN
  DEALLOCATE(ZSLBUF1AU)
  IF (LALLOPR) WRITE(NULOUT,9991) 'ZSLBUF1AU'
ENDIF

! * Deallocate the NH intermediate storage arrays for the corrector step of
!   LPC_OLD.

IF ((NCURRENT_ITER > 0 .AND. LPC_OLD).AND.LTRAJNH) THEN

  IF (ALLOCATED(ZGPUT5)) THEN
    DEALLOCATE(ZGPUT5)
    IF (LALLOPR) WRITE(NULOUT,9991) 'ZGPUT5'
  ENDIF

  IF (ALLOCATED(ZGPVT5)) THEN
    DEALLOCATE(ZGPVT5)
    IF (LALLOPR) WRITE(NULOUT,9991) 'ZGPVT5'
  ENDIF

  IF (ALLOCATED(ZGPTT5)) THEN
    DEALLOCATE(ZGPTT5)
    IF (LALLOPR) WRITE(NULOUT,9991) 'ZGPTT5'
  ENDIF

  IF (ALLOCATED(ZGPSVDT5)) THEN
    DEALLOCATE(ZGPSVDT5)
    IF (LALLOPR) WRITE(NULOUT,9991) 'ZGPSVDT5'
  ENDIF

  IF (ALLOCATED(ZGPVORT5)) THEN
    DEALLOCATE(ZGPVORT5)
    IF (LALLOPR) WRITE(NULOUT,9991) 'ZGPVORT5'
  ENDIF

  IF (ALLOCATED(ZGPDIVT5)) THEN
    DEALLOCATE(ZGPDIVT5)
    IF (LALLOPR) WRITE(NULOUT,9991) 'ZGPDIVT5'
  ENDIF

  IF (ALLOCATED(ZGPUT5L)) THEN
    DEALLOCATE(ZGPUT5L)
    IF (LALLOPR) WRITE(NULOUT,9991) 'ZGPUT5L'
  ENDIF

  IF (ALLOCATED(ZGPVT5L)) THEN
    DEALLOCATE(ZGPVT5L)
    IF (LALLOPR) WRITE(NULOUT,9991) 'ZGPVT5L'
  ENDIF

  IF (ALLOCATED(ZGPSPT5)) THEN
    DEALLOCATE(ZGPSPT5)
    IF (LALLOPR) WRITE(NULOUT,9991) 'ZGPSPT5'
  ENDIF

ENDIF

!$OMP END PARALLEL

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

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

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

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