SUBROUTINE SIPTP(KLEV,KLON,PDH,PDV,PRNH,PT,PSP,KNLON)

!**** *SIPTP* - Counterpart of SITNU in nonhydrostatic

!     Purpose.
!     --------
!           Provide corrections of temperature, surface
!           pressure and nonhydrostatic perturbation from
!           3D divergence in semiimplicit

!**   Interface.
!     ----------
!        *CALL* *SIPTP(KLEV,KLON,PDH,PDV,PRNH,PT,PSP,KNLON)

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

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

!        PDH   : HORIZONTAL DIVERGENCE                       - input
!        PDV   : VERTICAL DIVERGENCE VARIABLE                - input
!        PRNH  : NONHYDROSTATIC PRESSURE DEPARTURE VARIABLE  - output
!        PT    : TEMPERATURE                                 - output
!        PSP   : LOG(SURFACE PRESSURE)                       - output
!        KNLON : NUMBER OF VERTICAL COLUMNS TREATED

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

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

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

!     Reference.
!     ----------
!        Arpege/Aladin Documentation

!     Author.
!     -------
!        Radmila Bubnova  *GMAP/COMPAS - stage MRE*

!     Modifications.
!     --------------
!        Original : 93-03-24
!        L. Isaksen 96-05-05  Adapted for Message Passing
!        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 : RD       ,RCPD     ,RCVD
USE YOMDYN   , ONLY : SITR

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

IMPLICIT NONE

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

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

INTEGER(KIND=JPIM) :: ILEV, ILON, INLON, JAD, JLEV

REAL(KIND=JPRB) :: Z3DIVC
REAL(KIND=JPRB) :: ZHOOK_HANDLE

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

#include "sitnu.intfb.h"

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

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

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

!*       1.    SITNU ON PDH TO GET PSP AND PART OF PRNH
!              ----------------------------------------

ILEV = KLEV
ILON = KLON
INLON= KNLON

CALL SITNU(ILEV,ILON,PDH,PRNH,PSP,INLON)

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

!*       2.    FINISH PT AND PRNH CALCULATION.
!              -------------------------------

DO JLEV = 1, NFLEVG
  DO JAD=1+(JLEV-1)*ILEV,1+(JLEV-1)*ILEV+(INLON-1)*ILON,ILON
    Z3DIVC = (PDH(JAD) + PDV(JAD))/RCVD
    PT(JAD) = RD*SITR*Z3DIVC
    PRNH(JAD) = RCPD*Z3DIVC - RCPD*PRNH(JAD)/(RD*SITR)
  ENDDO
ENDDO

!     ------------------------------------------------------------------
IF (LHOOK) CALL DR_HOOK('SIPTP',1,ZHOOK_HANDLE)
END SUBROUTINE SIPTP
