SUBROUTINE SITNUAD(KLEV,KLON,PD,PT,PSP,KNLON)

!**** *SITNUAD*   - Continuity equation for semi-implicit.ADJOINT

!     Purpose.
!     --------
!           Evaluate operators Tau and Nu in semi-implicit.

!**   Interface.
!     ----------
!        *CALL* *SITNUAD(KLEV,KLON,PD,PT,PSP,KNLON)

!        Explicit arguments :
!        --------------------
!        KLEV   : DISTANCE IN MEMORY BETWEEN VALUES OF THE DIVERGENCE
!                OR TEMPERATURE AT THE SAME LEVEL
!        KLON   : DISTANCE IN MEMORY BETWEEN VALUES OF THE DIVERGENCE
!                OR TEMPERATURE AT THE VERTICAL

!           TYPICAL VALUES ARE  NDLSUR,1  FOR GRID POINT ARRAY
!                               1,NFLSUR  FOR SPECTRAL ARRAY

!        PD    : DIVERGENCE
!        PT    : TEMPERATURE
!        PSP   : LOG(SURFACE PRESSURE)
!        KNLON : NUMBER OF VERTICAL COLUMNS TREATED

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

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

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

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

!     Author.
!     -------
!        Jean-Noel THEPAUT METEO FRANCE/EERM/CRMD

!     Modifications.
!     --------------
!        Original :  89-12-12
!        P. Courtier 92-07-15 Optimisation
!        L. Isaksen  96-02-20 Adapted for Message Passing
!        E.Andersson 96-07-25 Fujitsu vectorisation
!        A. Untch    2000-12  Vertical finite element scheme
!        M.Hamrud      01-Oct-2003 CY28 Cleaning
!        K. Yessad (Sep 2008): update comments + cleanings.
!     ------------------------------------------------------------------

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

USE YOMDIM   , ONLY : NFLEVG
USE YOMCST   , ONLY : RKAPPA
USE YOMDYN   , ONLY : SIALPH   ,SILNPR   ,SIDELP   ,SIRDEL   ,&
 & SITR     ,SIRPRN   ,SITLAF  
USE YOMGEM   , ONLY : VFE_RDETAH
USE YOMCVER  , ONLY : LVERTFE

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

IMPLICIT NONE

INTEGER(KIND=JPIM),INTENT(IN)    :: KLEV 
INTEGER(KIND=JPIM),INTENT(IN)    :: KLON 
INTEGER(KIND=JPIM),INTENT(IN)    :: KNLON 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PD(1+(NFLEVG-1)*KLEV+(KNLON-1)*KLON) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PT(1+(NFLEVG-1)*KLEV+(KNLON-1)*KLON) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PSP(KNLON) 

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

REAL(KIND=JPRB) :: ZSDIV(KNLON,0:NFLEVG), ZOUT(KNLON,0:NFLEVG)

INTEGER(KIND=JPIM) :: IDT, JLEV, JLON
REAL(KIND=JPRB) :: ZREC
REAL(KIND=JPRB) :: ZHOOK_HANDLE

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

#include "verintad.intfb.h"

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

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

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

!*       2.    COMPUTES SURFACE PRESSURE.
!              --------------------------

DO JLON=1,KNLON
  IF(LVERTFE) THEN
    ZOUT(JLON,NFLEVG)=SIRPRN*PSP(JLON)
  ELSE
    ZSDIV(JLON,NFLEVG)=SIRPRN*PSP(JLON)
  ENDIF
  PSP(JLON)=0.0_JPRB
ENDDO
!     ------------------------------------------------------------------

!*       1.    SUM DIVERGENCE.
!              ---------------

IF(LVERTFE) THEN

  DO JLEV=1,NFLEVG
    ZREC=1.0_JPRB/SITLAF(JLEV)
    DO JLON=1,KNLON
      IDT=1+(JLEV-1)*KLEV+(JLON-1)*KLON
      ZOUT(JLON,JLEV-1)=RKAPPA*SITR*PT(IDT)*ZREC
    ENDDO
  ENDDO
  CALL VERINTAD(KNLON,1,KNLON,NFLEVG,ZSDIV(1,1),ZOUT,0)
  DO JLEV=1,NFLEVG
    DO JLON=1,KNLON
      IDT=1+(JLEV-1)*KLEV+(JLON-1)*KLON
      PD(IDT)=PD(IDT)+ZSDIV(JLON,JLEV)*SIDELP(JLEV)*VFE_RDETAH(JLEV)
      PT(IDT)=0.0_JPRB
    ENDDO
  ENDDO

ELSE

  DO JLEV=NFLEVG,1,-1
!OCL NOVREC
    DO JLON=1,KNLON
      IDT=1+(JLEV-1)*KLEV+(JLON-1)*KLON
      PD(IDT)=PD(IDT)+RKAPPA*SITR*SIALPH(JLEV)*PT(IDT)&
       & +SIDELP(JLEV)*ZSDIV(JLON,JLEV)  
      ZSDIV(JLON,JLEV-1)=RKAPPA*SITR*&
       & SIRDEL(JLEV)*SILNPR(JLEV)*PT(IDT)&
       & +ZSDIV(JLON,JLEV)  
      PT(IDT)=0.0_JPRB
    ENDDO
  ENDDO
ENDIF

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

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

