!OCL  NOEVAL
SUBROUTINE GPGRGEOTL(&
 ! --- INPUT ------------------------------------------
 & LDNHDYN,KPROMA,KD,KF,KFLEV,&
 !NYC-NH & PREHYDSPRE,&
 & PT,PR,PRTL,PRTM,&
 & PLNPR,PLNPRL,PLNPRM,PALPH,PALPHL,PALPHM,&
 !NYC-NH & PQCHAL,PQCHAM,&
 ! --- OUTPUT -----------------------------------------
 & PHIFL,PHIFM,PHIHL,PHIHM,&
 ! --- INPUT-TRAJECTORY -------------------------------
 & PREHYDSPRE5,PT5,PR5,PRT5L,PRT5M,&
 & PLNPR5,PLNPR5L,PLNPR5M,PALPH5,PALPH5L,PALPH5M &
 !NYC-NH & PQCHA5L,PQCHA5M,PNH15L,PNH15M &
 & )  

!**** *GPGRGEOTL* - Computes half and full level gradient of geopotential
!                 height "gz". TL code.

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

!      See GPGRGEO.

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

!        Explicit arguments :
!        --------------------
!         * INPUT:
!           LDNHDYN      : .F./.T.: hydrostatic/non hydrostatic model.
!           KPROMA       : horizontal dimension
!           KD           : start of work
!           KF           : working length
!           KFLEV        : number of levels
!           PREHYDSPRE   : "prehyd/pre" on layers. Contains "0" if hydrostatic (NYC-NH)
!           PR           : "R(air)" on layers
!           PT           : temperature "T" on layers
!           PRTL         : zonal component of "rssavnabla (RT)" on layers
!           PRTM         : meridian component of "rssavnabla (RT)" on layers
!           PLNPR        : "delta" on layers (is equal to
!                          "log(prehyd[lbar]/prehyd[lbar-1])" if "ndlnpr=0")
!           PLNPRL       : zonal component of "rssavnabla delta" on layers
!           PLNPRM       : meridian component of "rssavnabla delta" on layers
!           PALPH        : "alpha" on layers
!           PALPHL       : zonal component of "rssavnabla alpha" on layers
!           PALPHM       : meridian component "rssavnabla alpha" on layers
!           PQCHAL       : zonal component of
!                          "rssavnabla(log(pre/prehyd))=
!                          (rssavnabla pre)/pre - (rssavnabla(prehyd))/prehyd"
!                          on layers (NYC-NH)
!           PQCHAM       : merid component of
!                          "rssavnabla(log(pre/prehyd))=
!                          (rssavnabla pre)/pre - (rssavnabla(prehyd))/prehyd"
!                          on layers (NYC-NH)

!         * OUTPUT:
!           PHIFL        : zonal component of "rssavnabla (gz)" on layers
!           PHIFM        : merid component of "rssavnabla (gz)" on layers
!           PHIHL        : zonal component of "rssavnabla (gz)" on interlayers
!           PHIHM        : merid component of "rssavnabla (gz)" on interlayers

!         * INPUT-TRAJECTORY:
!           PREHYDSPRE5,PT5,PR5,PRT5L,PRT5M,
!           PLNPR5,PLNPR5L,PLNPR5M,PALPH5,PALPH5L,PALPH5M,
!           PQCHA5L,PQCHA5M,&
!           PNH15L,PNH15M:
!           trajectory version of PREHYDSPRE,PT,PR,PRTL,PRTM,
!           PLNPR,PLNPRL,PLNPRM,PALPH,PALPHL,PALPHM,
!           PQCHAL,PQCHAM,&
!           ZNH1L,ZNH1M in GPGRGEO.

!        Implicit arguments :   None.
!        --------------------

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

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

!     Reference.
!     ----------
!        See  documentation Arpege ALGORITHME CHAPITRE 6 paragraphe 6

!     Author.
!     -------
!        K. YESSAD

!     Modifications.
!     --------------
!        Original : Dec 2005
!     K. Yessad (Dec 2008): remove dummy CDLOCK
!     ------------------------------------------------------------------

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

USE YOMCVER  , ONLY : LVERTFE
USE YOMGEM   , ONLY : VFE_RDETAH

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

IMPLICIT NONE

INTEGER(KIND=JPIM),INTENT(IN)    :: KPROMA 
INTEGER(KIND=JPIM),INTENT(IN)    :: KFLEV 
LOGICAL           ,INTENT(IN)    :: LDNHDYN 
INTEGER(KIND=JPIM),INTENT(IN)    :: KD 
INTEGER(KIND=JPIM),INTENT(IN)    :: KF 
!NYC-NH REAL(KIND=JPRB)   ,INTENT(IN)    :: PREHYDSPRE(KPROMA,KFLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PT(KPROMA,KFLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PR(KPROMA,KFLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PRTL(KPROMA,KFLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PRTM(KPROMA,KFLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PLNPR(KPROMA,KFLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PLNPRL(KPROMA,KFLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PLNPRM(KPROMA,KFLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PALPH(KPROMA,KFLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PALPHL(KPROMA,KFLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PALPHM(KPROMA,KFLEV) 
!NYC-NH REAL(KIND=JPRB)   ,INTENT(IN)    :: PQCHAL(KPROMA,KFLEV) 
!NYC-NH REAL(KIND=JPRB)   ,INTENT(IN)    :: PQCHAM(KPROMA,KFLEV) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PHIFL(KPROMA,KFLEV) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PHIFM(KPROMA,KFLEV) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PHIHL(KPROMA,0:KFLEV) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PHIHM(KPROMA,0:KFLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PREHYDSPRE5(KPROMA,KFLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PT5(KPROMA,KFLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PR5(KPROMA,KFLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PRT5L(KPROMA,KFLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PRT5M(KPROMA,KFLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PLNPR5(KPROMA,KFLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PLNPR5L(KPROMA,KFLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PLNPR5M(KPROMA,KFLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PALPH5(KPROMA,KFLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PALPH5L(KPROMA,KFLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PALPH5M(KPROMA,KFLEV) 
!NYC-NH REAL(KIND=JPRB)   ,INTENT(IN)    :: PQCHA5L(KPROMA,KFLEV) 
!NYC-NH REAL(KIND=JPRB)   ,INTENT(IN)    :: PQCHA5M(KPROMA,KFLEV) 
!NYC-NH REAL(KIND=JPRB)   ,INTENT(IN)    :: PNH15L(KPROMA,KFLEV) 
!NYC-NH REAL(KIND=JPRB)   ,INTENT(IN)    :: PNH15M(KPROMA,KFLEV) 

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

!NYC-NH REAL(KIND=JPRB) :: ZNH1L(KPROMA,KFLEV), ZNH1M(KPROMA,KFLEV)
REAL(KIND=JPRB) :: ZGPHL(KPROMA,0:KFLEV), ZGPHM(KPROMA,0:KFLEV)
REAL(KIND=JPRB) :: ZINL(KPROMA,KFLEV) , ZINM(KPROMA,KFLEV)

INTEGER(KIND=JPIM) :: JLEV, JROF
REAL(KIND=JPRB) :: ZHOOK_HANDLE

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

#include "verint.intfb.h"

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

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

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

!*    1. Computation of term:
!        R[l] T[l] {(rssavnabla(prehyd)/prehyd)[l] - (rssavnabla(pre)/pre)[l]}
!        according to "lnhdyn".

IF (LDNHDYN) THEN

  ! Not yet coded (following code to be activated later)
  !NYC-NH DO JLEV=1,KFLEV
  !NYC-NH   ZNH1L(KD:KF,JLEV)=-PR(KD:KF,JLEV)*PT5(KD:KF,JLEV)*PQCHA5L(KD:KF,JLEV) &
  !NYC-NH    & -PR5(KD:KF,JLEV)*PT(KD:KF,JLEV)*PQCHA5L(KD:KF,JLEV) &
  !NYC-NH    & -PR5(KD:KF,JLEV)*PT5(KD:KF,JLEV)*PQCHAL(KD:KF,JLEV)
  !NYC-NH   ZNH1M(KD:KF,JLEV)=-PR(KD:KF,JLEV)*PT5(KD:KF,JLEV)*PQCHA5M(KD:KF,JLEV) &
  !NYC-NH    & -PR5(KD:KF,JLEV)*PT(KD:KF,JLEV)*PQCHA5M(KD:KF,JLEV) &
  !NYC-NH    & -PR5(KD:KF,JLEV)*PT5(KD:KF,JLEV)*PQCHAM(KD:KF,JLEV)
  !NYC-NH ENDDO

ENDIF

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

!*    2.1 Calculation of "rssavnabla (gz)" on interlayers.
!         ("delta" and "rssavnabla delta" terms contributions.

DO JROF=KD,KF
  PHIHL(JROF,KFLEV)=0._JPRB
  PHIHM(JROF,KFLEV)=0._JPRB
ENDDO

DO JLEV=KFLEV,1,-1
  ! In the hydrostatic model, ZNH1L, ZNH1M, PNH15L, PNH15M and PREHYDSPRE are 0,
  ! so the corresponding contributions are added only in the NH model.
  DO JROF=KD,KF
    PHIHL(JROF,JLEV-1)= PHIHL(JROF,JLEV)&
     & +PLNPR(JROF,JLEV)*PREHYDSPRE5(JROF,JLEV)*PRT5L(JROF,JLEV)&
     & +PLNPR5(JROF,JLEV)*PREHYDSPRE5(JROF,JLEV)*PRTL(JROF,JLEV)&
     & +PLNPRL(JROF,JLEV)*PREHYDSPRE5(JROF,JLEV)*PR5(JROF,JLEV)*PT5(JROF,JLEV)&
     & +PLNPR5L(JROF,JLEV)*PREHYDSPRE5(JROF,JLEV)*PR(JROF,JLEV)*PT5(JROF,JLEV)&
     & +PLNPR5L(JROF,JLEV)*PREHYDSPRE5(JROF,JLEV)*PR5(JROF,JLEV)*PT(JROF,JLEV)  
    PHIHM(JROF,JLEV-1)= PHIHM(JROF,JLEV)&
     & +PLNPR(JROF,JLEV)*PREHYDSPRE5(JROF,JLEV)*PRT5M(JROF,JLEV)&
     & +PLNPR5(JROF,JLEV)*PREHYDSPRE5(JROF,JLEV)*PRTM(JROF,JLEV)&
     & +PLNPRM(JROF,JLEV)*PREHYDSPRE5(JROF,JLEV)*PR5(JROF,JLEV)*PT5(JROF,JLEV)&
     & +PLNPR5M(JROF,JLEV)*PREHYDSPRE5(JROF,JLEV)*PR(JROF,JLEV)*PT5(JROF,JLEV)&
     & +PLNPR5M(JROF,JLEV)*PREHYDSPRE5(JROF,JLEV)*PR5(JROF,JLEV)*PT(JROF,JLEV)  
  ENDDO
  IF (LDNHDYN) THEN
    ! Not yet coded (following code to be activated later)
    !NYC-NH DO JROF=KD,KF
    !NYC-NH   PHIHL(JROF,JLEV-1)=PHIHL(JROF,JLEV-1)&
    !NYC-NH    & +PLNPR5(JROF,JLEV)*PREHYDSPRE5(JROF,JLEV)*ZNH1L(JROF,JLEV)&
    !NYC-NH    & +PLNPR(JROF,JLEV)*PREHYDSPRE5(JROF,JLEV)*PNH15L(JROF,JLEV)&
    !NYC-NH    & +(PLNPR5(JROF,JLEV)*(PRT5L(JROF,JLEV)+PNH15L(JROF,JLEV))&
    !NYC-NH    & +PLNPR5L(JROF,JLEV)*PR5(JROF,JLEV)*PT5(JROF,JLEV))&
    !NYC-NH    & *PREHYDSPRE(JROF,JLEV)
    !NYC-NH   PHIHM(JROF,JLEV-1)=PHIHM(JROF,JLEV-1)&
    !NYC-NH    & +PLNPR5(JROF,JLEV)*PREHYDSPRE5(JROF,JLEV)*ZNH1M(JROF,JLEV)&
    !NYC-NH    & +PLNPR(JROF,JLEV)*PREHYDSPRE5(JROF,JLEV)*PNH15M(JROF,JLEV)&
    !NYC-NH    & +(PLNPR5(JROF,JLEV)*(PRT5M(JROF,JLEV)+PNH15M(JROF,JLEV))&
    !NYC-NH    & +PLNPR5M(JROF,JLEV)*PR5(JROF,JLEV)*PT5(JROF,JLEV))&
    !NYC-NH    & *PREHYDSPRE(JROF,JLEV)
    !NYC-NH ENDDO
  ENDIF
ENDDO

!*    2.2 Calculation of "rssavnabla (gz)" on interlayers.
!         "alpha" and "rssavnabla alpha" terms contributions.

IF(LVERTFE) THEN
  DO JLEV=1,KFLEV
    ! In the hydrostatic model, ZNH1L, ZNH1M, PNH15L, PNH15M and PREHYDSPRE are 0,
    ! so the corresponding contributions are added only in the NH model.
    DO JROF=KD,KF
      ZINL(JROF,JLEV)=(&
       & -PLNPR(JROF,JLEV)*PREHYDSPRE5(JROF,JLEV)*PRT5L(JROF,JLEV)&
       & -PLNPR5(JROF,JLEV)*PREHYDSPRE5(JROF,JLEV)*PRTL(JROF,JLEV)&
       & -PLNPRL(JROF,JLEV)*PREHYDSPRE5(JROF,JLEV)*PR5(JROF,JLEV)*PT5(JROF,JLEV)&
       & -PLNPR5L(JROF,JLEV)*PREHYDSPRE5(JROF,JLEV)*PR(JROF,JLEV)*PT5(JROF,JLEV)&
       & -PLNPR5L(JROF,JLEV)*PREHYDSPRE5(JROF,JLEV)*PR5(JROF,JLEV)*PT(JROF,JLEV)&
       & )*VFE_RDETAH(JLEV)  
      ZINM(JROF,JLEV)=(&
       & -PLNPR(JROF,JLEV)*PREHYDSPRE5(JROF,JLEV)*PRT5M(JROF,JLEV)&
       & -PLNPR5(JROF,JLEV)*PREHYDSPRE5(JROF,JLEV)*PRTM(JROF,JLEV)&
       & -PLNPRM(JROF,JLEV)*PREHYDSPRE5(JROF,JLEV)*PR5(JROF,JLEV)*PT5(JROF,JLEV)&
       & -PLNPR5M(JROF,JLEV)*PREHYDSPRE5(JROF,JLEV)*PR(JROF,JLEV)*PT5(JROF,JLEV)&
       & -PLNPR5M(JROF,JLEV)*PREHYDSPRE5(JROF,JLEV)*PR5(JROF,JLEV)*PT(JROF,JLEV)&
       & )*VFE_RDETAH(JLEV)  
    ENDDO
    IF (LDNHDYN) THEN
      ! Not yet coded (following code to be activated later)
      !NYC-NH DO JROF=KD,KF
      !NYC-NH   ZINL(JROF,JLEV)=ZINL(JROF,JLEV)-VFE_RDETAH(JLEV)*&
      !NYC-NH    & PLNPR5(JROF,JLEV)*PREHYDSPRE5(JROF,JLEV)*ZNH1L(JROF,JLEV)&
      !NYC-NH    & -PLNPR(JROF,JLEV)*PREHYDSPRE5(JROF,JLEV)*PNH15L(JROF,JLEV)&
      !NYC-NH    & -(PLNPR5(JROF,JLEV)*(PRT5L(JROF,JLEV)+PNH15L(JROF,JLEV))&
      !NYC-NH    & +PLNPR5L(JROF,JLEV)*PR5(JROF,JLEV)*PT5(JROF,JLEV))&
      !NYC-NH    & *PREHYDSPRE(JROF,JLEV)
      !NYC-NH   ZINM(JROF,JLEV)=ZINM(JROF,JLEV)-VFE_RDETAH(JLEV)*&
      !NYC-NH    & PLNPR5(JROF,JLEV)*PREHYDSPRE5(JROF,JLEV)*ZNH1M(JROF,JLEV)&
      !NYC-NH    & -PLNPR(JROF,JLEV)*PREHYDSPRE5(JROF,JLEV)*PNH15M(JROF,JLEV)&
      !NYC-NH    & -(PLNPR5(JROF,JLEV)*(PRT5M(JROF,JLEV)+PNH15M(JROF,JLEV))&
      !NYC-NH    & +PLNPR5M(JROF,JLEV)*PR5(JROF,JLEV)*PT5(JROF,JLEV))&
      !NYC-NH    & *PREHYDSPRE(JROF,JLEV)
      !NYC-NH ENDDO
    ENDIF
  ENDDO
  CALL VERINT(KPROMA,KD,KF,KFLEV,ZINL,ZGPHL,1)
  CALL VERINT(KPROMA,KD,KF,KFLEV,ZINM,ZGPHM,1)
  DO JLEV=1,KFLEV
    DO JROF=KD,KF
      PHIFL(JROF,JLEV)=ZGPHL(JROF,JLEV-1)
      PHIFM(JROF,JLEV)=ZGPHM(JROF,JLEV-1)
    ENDDO
  ENDDO  
ELSE
  DO JLEV=1,KFLEV
    ! In the hydrostatic model, ZNH1L, ZNH1M, PNH15L, PNH15M and PREHYDSPRE are 0,
    ! so the corresponding contributions are added only in the NH model.
    DO JROF=KD,KF
      PHIFL(JROF,JLEV)= PHIHL(JROF,JLEV)&
       & +PALPH(JROF,JLEV)*PREHYDSPRE5(JROF,JLEV)*PRT5L(JROF,JLEV)&
       & +PALPH5(JROF,JLEV)*PREHYDSPRE5(JROF,JLEV)*PRTL(JROF,JLEV)&
       & +PALPHL(JROF,JLEV)*PREHYDSPRE5(JROF,JLEV)*PR5(JROF,JLEV)*PT5(JROF,JLEV)&
       & +PALPH5L(JROF,JLEV)*PREHYDSPRE5(JROF,JLEV)*PR(JROF,JLEV)*PT5(JROF,JLEV)&
       & +PALPH5L(JROF,JLEV)*PREHYDSPRE5(JROF,JLEV)*PR5(JROF,JLEV)*PT(JROF,JLEV)  
      PHIFM(JROF,JLEV)= PHIHM(JROF,JLEV)&
       & +PALPH(JROF,JLEV)*PREHYDSPRE5(JROF,JLEV)*PRT5M(JROF,JLEV)&
       & +PALPH5(JROF,JLEV)*PREHYDSPRE5(JROF,JLEV)*PRTM(JROF,JLEV)&
       & +PALPHM(JROF,JLEV)*PREHYDSPRE5(JROF,JLEV)*PR5(JROF,JLEV)*PT5(JROF,JLEV)&
       & +PALPH5M(JROF,JLEV)*PREHYDSPRE5(JROF,JLEV)*PR(JROF,JLEV)*PT5(JROF,JLEV)&
       & +PALPH5M(JROF,JLEV)*PREHYDSPRE5(JROF,JLEV)*PR5(JROF,JLEV)*PT(JROF,JLEV)  
    ENDDO
    IF (LDNHDYN) THEN
      ! Not yet coded (following code to be activated later)
      !NYC-NH DO JROF=KD,KF
      !NYC-NH   PHIFL(JROF,JLEV)=PHIHL(JROF,JLEV)&
      !NYC-NH    & +PALPH5(JROF,JLEV)*PREHYDSPRE5(JROF,JLEV)*ZNH1L(JROF,JLEV)&
      !NYC-NH    & +PALPH(JROF,JLEV)*PREHYDSPRE5(JROF,JLEV)*PNH15L(JROF,JLEV)&
      !NYC-NH    & +(PALPH5(JROF,JLEV)*(PRT5L(JROF,JLEV)+PNH15L(JROF,JLEV))&
      !NYC-NH    & +PALPH5L(JROF,JLEV)*PR5(JROF,JLEV)*PT5(JROF,JLEV))&
      !NYC-NH    & *PREHYDSPRE(JROF,JLEV)
      !NYC-NH   PHIFM(JROF,JLEV)=PHIHM(JROF,JLEV)&
      !NYC-NH    & +PALPH5(JROF,JLEV)*PREHYDSPRE5(JROF,JLEV)*ZNH1M(JROF,JLEV)&
      !NYC-NH    & +PALPH(JROF,JLEV)*PREHYDSPRE5(JROF,JLEV)*PNH15M(JROF,JLEV)&
      !NYC-NH    & +(PALPH5(JROF,JLEV)*(PRT5M(JROF,JLEV)+PNH15M(JROF,JLEV))&
      !NYC-NH    & +PALPH5M(JROF,JLEV)*PR5(JROF,JLEV)*PT5(JROF,JLEV))&
      !NYC-NH    & *PREHYDSPRE(JROF,JLEV)
      !NYC-NH ENDDO
    ENDIF
  ENDDO
ENDIF

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

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