!OCL  NOEVAL
SUBROUTINE GNH_TNDLAGADIAB_SPD( &
 ! --- INPUT -----------------------------------------------------------------
 & KFLEV,KPROMA,KSTART,KPROF, &
 & PKAP,P3DIVG,PVVEL,PGWF, &
 & PEVEL,PRDELP,PU,PV,POROG,POROGL,POROGM, &
 ! --- OUTPUT ----------------------------------------------------------------
 & PTNDPD &
 & )  

!**** *GNH_TNDLAGADIAB_SPD* - Computation of the adiabatic contribution of
!                             [D (spd) / Dt] in the NH model.
!                             "spd" is the pressure departure variable.

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

!     Computation of the adiabatic contribution of [D (spd) / Dt] in the NH model
!     at full levels.

!     For spd=Qcha, expression of this tendency is:
!      [D (Qcha) / Dt]_adiab = - (cp/cv) D3 - omega/prehyd
!     For spd=Phi, expression of this tendency is:
!      [D (Phi) / Dt]_adiab = gw
!     For spd=Phi-B*Phis, expression of this tendency is:
!      [D (Phi-B*Phis) / Dt]_adiab = gw - B V*grad(phis) - etadot (dB/d eta) Phis

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

!        Explicit arguments :
!        --------------------
!         * INPUT:
!           KFLEV     : number of levels.
!           KPROMA    : horizontal dimension.
!           KSTART    : start of work.
!           KPROF     : working length.
!           PKAP      : Kappa=R/cp at full levels.
!           P3DIVG    : total divergence D3 at full levels.
!           PVVEL     : omega/prehyd at full levels.
!           PGWF      : "gw" at full levels.
!           PEVEL     : "etadot d prehyd/d eta" at half (FD) or full (VFE) lev.
!           PRDELP    : 1/[Delta prehyd] at full levels.
!           PU        : U-wind at full levels.
!           PV        : V-wind at full levels.
!           POROG     : Surface orography.
!           POROGL    : zonal component of grad(surface orography).
!           POROGM    : meridian component of grad(surface orography).

!         * OUTPUT:
!           PTNDPD    : tendency [D (spd) / Dt]_adiab at full levels.

!         Remark: input data PKAP,P3DIVG,PVVEL,PGWF are at time t.

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

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

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

!     Reference.
!     ----------
!        See documentations Arpege about the NH model.

!     Author.
!     -------
!        K. YESSAD (after routine GNHPDVD).

!     Modifications.
!     --------------
!   Original : 08-Dec-2004
!   N. Wedi and K. Yessad (Jan 2008): different dev for NH model and PC scheme
!     ------------------------------------------------------------------

USE YOMCT0   , ONLY : LSLAG
USE YOMCVER  , ONLY : LVERTFE 
USE YOMDYNA  , ONLY : NPDVAR   ,LRWSDLR
USE YOMDYN   , ONLY : RC_PD1   ,RCORPDH
USE YOMGEM   , ONLY : VBF      ,VBH      ,VDELB
USE PARKIND1 , ONLY : JPIM     ,JPRB
USE YOMHOOK  , ONLY : LHOOK    ,DR_HOOK

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

IMPLICIT NONE

INTEGER(KIND=JPIM),INTENT(IN)    :: KFLEV
INTEGER(KIND=JPIM),INTENT(IN)    :: KPROMA 
INTEGER(KIND=JPIM),INTENT(IN)    :: KSTART 
INTEGER(KIND=JPIM),INTENT(IN)    :: KPROF 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PKAP(KPROMA,KFLEV)
REAL(KIND=JPRB)   ,INTENT(IN)    :: P3DIVG(KPROMA,KFLEV)
REAL(KIND=JPRB)   ,INTENT(IN)    :: PVVEL(KPROMA,KFLEV)
REAL(KIND=JPRB)   ,INTENT(IN)    :: PGWF(KPROMA,KFLEV)
REAL(KIND=JPRB)   ,INTENT(IN)    :: PEVEL(KPROMA,0:KFLEV)
REAL(KIND=JPRB)   ,INTENT(IN)    :: PRDELP(KPROMA,KFLEV)
REAL(KIND=JPRB)   ,INTENT(IN)    :: PU(KPROMA,KFLEV)
REAL(KIND=JPRB)   ,INTENT(IN)    :: PV(KPROMA,KFLEV)
REAL(KIND=JPRB)   ,INTENT(IN)    :: POROG(KPROMA)
REAL(KIND=JPRB)   ,INTENT(IN)    :: POROGL(KPROMA)
REAL(KIND=JPRB)   ,INTENT(IN)    :: POROGM(KPROMA)
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PTNDPD(KPROMA,KFLEV)

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

INTEGER(KIND=JPIM) :: JROF,JLEV
REAL(KIND=JPRB) :: ZCPCV
REAL(KIND=JPRB) :: ZWT0(KPROMA)
REAL(KIND=JPRB) :: ZVBF(KFLEV)

REAL(KIND=JPRB) :: ZHOOK_HANDLE

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

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

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

!*       1.    COMPUTATION OF [D (spd) / Dt]_adiab
!              -----------------------------------

IF (NPDVAR==2) THEN
  DO JLEV=1,KFLEV
    DO JROF=KSTART,KPROF
      ZCPCV=1.0_JPRB/(1.0_JPRB-PKAP(JROF,JLEV))
      PTNDPD(JROF,JLEV)=-(ZCPCV*P3DIVG(JROF,JLEV)+PVVEL(JROF,JLEV))
    ENDDO
  ENDDO
  IF (LSLAG.AND.LRWSDLR) THEN
    ! One takes account of the variable change ("rc_pd1*rcorpd" increment):
    !  there is an additional contribution equal to
    !  "etadot (d(rc_pd1*rcorpd)/deta)" to take account in the RHS of
    !  [D (spd) / Dt]_adiab.
    ! For the Eulerian scheme nothing is done here, because there are
    !  simply vertical advection terms which cancel between the RHS and
    !  the vertical advection terms, so they have been omitted here and
    !  in CPEULDYN.
    DO JLEV=1,KFLEV
      IF(LVERTFE) THEN
        DO JROF=KSTART,KPROF
          ZWT0(JROF)=PEVEL(JROF,JLEV)*PRDELP(JROF,JLEV)
        ENDDO
      ELSE
        DO JROF=KSTART,KPROF
          ZWT0(JROF)=0.5_JPRB*(PEVEL(JROF,JLEV)&
           & +PEVEL(JROF,JLEV-1))*PRDELP(JROF,JLEV)
        ENDDO
      ENDIF
      DO JROF=KSTART,KPROF
        PTNDPD(JROF,JLEV)=PTNDPD(JROF,JLEV) &
         & +RC_PD1*ZWT0(JROF)*(RCORPDH(JLEV)-RCORPDH(JLEV-1))
      ENDDO
    ENDDO
  ENDIF
ELSEIF (NPDVAR==3) THEN
  DO JLEV=1,KFLEV
    IF(LVERTFE) THEN
      DO JROF=KSTART,KPROF
        ZWT0(JROF)=PEVEL(JROF,JLEV)*PRDELP(JROF,JLEV)
      ENDDO
      ZVBF(JLEV)=VBF(JLEV)
    ELSE
      DO JROF=KSTART,KPROF
        ZWT0(JROF)=0.5_JPRB*(PEVEL(JROF,JLEV)&
         & +PEVEL(JROF,JLEV-1))*PRDELP(JROF,JLEV)
      ENDDO
      ZVBF(JLEV)=0.5_JPRB*(VBH(JLEV)+VBH(JLEV-1))
    ENDIF
    ! Probably something to add later here for deep-layer equations.
    DO JROF=KSTART,KPROF
      PTNDPD(JROF,JLEV)=PGWF(JROF,JLEV) &
       & -ZVBF(JLEV)*PU(JROF,JLEV)*POROGL(JROF) &
       & -ZVBF(JLEV)*PV(JROF,JLEV)*POROGM(JROF) &
       & -VDELB(JLEV)*ZWT0(JROF)*POROG(JROF)
    ENDDO
  ENDDO
ELSEIF (NPDVAR==4) THEN
  PTNDPD(KSTART:KPROF,1:KFLEV)=PGWF(KSTART:KPROF,1:KFLEV)
ENDIF

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

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