SUBROUTINE PPPMER(KPROMA,KSTART,KPROF,PRPRESS,POROG,PTSTAR,PT0,PMSLPPP)

!**** *PPPMER* - POST-PROCESS MSL PRESSURE.

!     PURPOSE.
!     --------
!           COMPUTES MSL PRESSURE.

!**   INTERFACE.
!     ----------
!        *CALL* *PPPMER(KPROMA,KSTART,KPROF,PRPRESS,POROG,PTSTAR,PT0,
!    S                  PMSLPPP)

!        EXPLICIT ARGUMENTS
!        --------------------

!        KPROMA                    - HORIZONTAL DIMENSION.             (INPUT)
!        KSTART                    - START OF WORK.                    (INPUT)
!        KPROF                     - DEPTH OF WORK.                    (INPUT)
!        PRPRESS(KPROMA)           - SURFACE PRESSURE                  (INPUT)
!        POROG(KPROMA)             - MODEL OROGRAPHY.                  (INPUT)
!        PTSTAR(KPROMA)            - SURFACE TEMPERATURE               (INPUT)
!        PT0(KPROMA)               - STANDARD SURFACE TEMPERATURE      (INPUT)

!        PMSLPPP(KPROMA)           - POST-PROCESSED MSL PRESSURE       (OUTPUT)

!        IMPLICIT ARGUMENTS :  CONSTANTS FROM YOMCST,YOMGEM,YOMSTA.
!        --------------------

!     METHOD.
!     -------
!        SEE DOCUMENTATION

!     EXTERNALS.  NONE
!     ----------

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

!     AUTHOR.
!     -------
!        MATS HAMRUD AND PHILIPPE COURTIER  *ECMWF*

!     MODIFICATIONS.
!     --------------
!        ORIGINAL : 89-01-26
!     E. A-son, J-F Geleyn 920409 Mod. T*, T0 and alpha below surface.
!        M.Hamrud      01-Oct-2003 CY28 Cleaning
!     ------------------------------------------------------------------

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

USE YOMCST   , ONLY : RG       ,RD
USE YOMSTA   , ONLY : RDTDZ1

IMPLICIT NONE

INTEGER(KIND=JPIM),INTENT(IN)    :: KPROMA 
INTEGER(KIND=JPIM),INTENT(IN)    :: KSTART 
INTEGER(KIND=JPIM),INTENT(IN)    :: KPROF 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PRPRESS(KPROMA) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: POROG(KPROMA) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PTSTAR(KPROMA) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PT0(KPROMA) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PMSLPPP(KPROMA) 
REAL(KIND=JPRB) :: ZTSTAR(KPROMA)
REAL(KIND=JPRB) :: ZALPHA(KPROMA)

INTEGER(KIND=JPIM) :: JL

REAL(KIND=JPRB) :: ZDTDZSG, ZOROG, ZT0, ZTX, ZTY, ZX, ZY, ZY2
REAL(KIND=JPRB) :: ZHOOK_HANDLE

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

!*       1.    POST-PROCESS MSL PRESSURE.
!              --------------------------

!*       1.1   COMPUTATION OF MODIFIED ALPHA AND TSTAR.

IF (LHOOK) CALL DR_HOOK('PPPMER',0,ZHOOK_HANDLE)
ZTX=290.5_JPRB
ZTY=255.0_JPRB
ZDTDZSG=-RDTDZ1/RG
DO JL=KSTART,KPROF

  IF(PTSTAR(JL) < ZTY) THEN
    ZTSTAR(JL)=0.5_JPRB*(ZTY+PTSTAR(JL))
  ELSEIF(PTSTAR(JL) < ZTX) THEN
    ZTSTAR(JL)=PTSTAR(JL)
  ELSE
    ZTSTAR(JL)=0.5_JPRB*(ZTX+PTSTAR(JL))
  ENDIF

  ZT0=ZTSTAR(JL)+ZDTDZSG*POROG(JL)
  IF(ZTX > ZTSTAR(JL) .AND. ZT0 > ZTX) THEN
    ZT0=ZTX
  ELSEIF(ZTX <= ZTSTAR(JL) .AND. ZT0 > ZTSTAR(JL)) THEN
    ZT0=ZTSTAR(JL)
  ELSE
    ZT0=PT0(JL)
  ENDIF

  ZOROG=SIGN(MAX(1.0_JPRB,ABS(POROG(JL))),POROG(JL))
  ZALPHA(JL)=RD*(ZT0-ZTSTAR(JL))/ZOROG
ENDDO

!*       1.2   COMPUTATION OF MSL PRESSURE.

DO JL=KSTART,KPROF
  IF (ABS(POROG(JL)) >= 0.001_JPRB) THEN
    ZX=POROG(JL)/(RD*ZTSTAR(JL))
    ZY=ZALPHA(JL)*ZX
    ZY2=ZY*ZY
    PMSLPPP(JL)=PRPRESS(JL)*EXP(ZX*(1.0_JPRB-0.5_JPRB*ZY+1.0_JPRB/3._JPRB*ZY2))
  ELSE
    PMSLPPP(JL)=PRPRESS(JL)
  ENDIF
ENDDO

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

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