SUBROUTINE PPRH(LDWMORH,KPROMA,KSTART,KPROF,KFLEV,KLEVP,KLOLEV,&
 & KLEVB,PRPRES,LDBELO,LDBLOW,PRHMAX,PRHMIN,&
 & PRXP,PRXPD,PQF,PTF,PRHPP)  

!**** *PPRH* - POST-PROCESS RELATIVE HUMIDITY.

!     PURPOSE.
!     --------
!           COMPUTES AND PERFORMS THE VERTICAL INTERPOLATION OF
!           RELATIVE HUMIDITY GIVEN MODEL CO-ORDINATE LEVEL.

!**   INTERFACE.
!     ----------
!        *CALL* *PPRH(LDWMORH,KPROMA,KSTART,KPROF,KFLEV,KLEVP,KLOLEV
!    1               ,KLEVB,PRPRES,LDBELO,LDBLOW
!    2               ,PRXP,PRXPD,PQF,PTF,PRHPP)

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

!        LDWMORH                   - WMO CONSIDER WATER PHASE ONLY     (INPUT-C)
!        KPROMA                    - HORIZONTAL DIMENSION.             (INPUT-C)
!        KSTART                    - START OF WORK.                    (INPUT-C)
!        KPROF                     - DEPTH OF WORK.                    (INPUT-C)
!        KFLEV                     - NUMBER OF INPUT PRESSURE LEVELS   (INPUT-C)
!        KLEVP                     - NUMBER OF OUTPUT PRESSURE LEVELS  (INPUT-C)
!        KLOLEV                    - BEGINING FOR THE INTERPOLATION    (INPUT-C)
!        KLEVB(KPROMA,KLEVP,NPPM)  - INPUT LEVEL BELOW PRPRES          (INPUT-C)
!                                    (SEE PPFLEV)
!        PRPRES(KPROMA,KLEVP)      -  POST-PROCESSING LEVEL PRESSURES  (INPUT-C)
!        LDBELO(KPROMA,KLEVP)      - .TRUE. IF PRESSURE IS UNDER
!                                     LOWEST  MODEL LEVEL              (INPUT-C)
!        LDBLOW(KLEVP)             - .TRUE. IF LDBELO(J) IS CONTAINING
!                                    AT LEAST ONE .TRUE.               (INPUT-C)
!        PRHMAX               - MAXIMUM RELATIVE HUMIDITY              (INPUT-C)
!        PRHMIN               - MINIMUM RELATIVE HUMIDITY              (INPUT-C)
!        PRXP(KPROMA,0:KFLEV,NPPM) - HALF,FULL AND LN HALF,FULL LEVEL
!                                    PRESSURES (SEE PPINIT)            (INPUT)
!        PRXPD(KPROMA,0:KFLEV,NPPM)- 1./D(P) AND 1./D(LN(P))           (INPUT)
!        PQF(KPROMA,0:KFLEV)       - SPECIFIC HUMIDITY ON FULL INPUT
!                                    LEVELS.                           (INPUT)
!        PTF(KPROMA,0:KFLEV)       - TEMPERATURE ON FULL INPUT LEVELS  (INPUT)

!        PRHPP(KPROMA,KLEVP)       - POST-PROCESSED RELATIVE HUMIDITY  (OUTPUT)

!        IMPLICIT ARGUMENTS :  NONE.
!        --------------------

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

!     EXTERNALS.  GPRH - COMPUTE RELATIVE HUMIDITY ON MODEL LEVELS
!     ----------  PPINTP - LINEAR INTERPOLATION

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

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

!     MODIFICATIONS.
!     --------------
!        ORIGINAL : 89-01-26
!     E. Andersson  99-08-17  and Pedro: WMO consider water phase only.
!        M.Hamrud      01-Oct-2003 CY28 Cleaning
!     ------------------------------------------------------------------

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

USE YOMDIM   , ONLY : NPPM

IMPLICIT NONE

INTEGER(KIND=JPIM),INTENT(IN)    :: KPROMA 
INTEGER(KIND=JPIM),INTENT(IN)    :: KFLEV 
INTEGER(KIND=JPIM),INTENT(IN)    :: KLEVP 
LOGICAL           ,INTENT(IN)    :: LDWMORH 
INTEGER(KIND=JPIM),INTENT(IN)    :: KSTART 
INTEGER(KIND=JPIM),INTENT(IN)    :: KPROF 
INTEGER(KIND=JPIM),INTENT(IN)    :: KLOLEV 
INTEGER(KIND=JPIM),INTENT(IN)    :: KLEVB(KPROMA,KLEVP,NPPM) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PRPRES(KPROMA,KLEVP) 
LOGICAL           ,INTENT(IN)    :: LDBELO(KPROMA,KLEVP) 
LOGICAL           ,INTENT(IN)    :: LDBLOW(KLEVP) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PRHMAX 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PRHMIN 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PRXP(KPROMA,0:KFLEV,NPPM) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PRXPD(KPROMA,0:KFLEV,NPPM) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PQF(KPROMA,0:KFLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PTF(KPROMA,0:KFLEV) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PRHPP(KPROMA,KLEVP) 
REAL(KIND=JPRB) :: ZES(KPROMA,0:KFLEV)
REAL(KIND=JPRB) :: ZRHF(KPROMA,0:KFLEV)

INTEGER(KIND=JPIM) :: ISLCT, JL, JLEVP
REAL(KIND=JPRB) :: ZHOOK_HANDLE

#include "gprh.intfb.h"
#include "ppintp.intfb.h"

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

!*       1.    POST-PROCESS RELATIVE HUMIDITY.
!              -------------------------------

!*       1.1   COMPUTE RELATIVE HUMIDITY ON MODEL LEVELS.

IF (LHOOK) CALL DR_HOOK('PPRH',0,ZHOOK_HANDLE)
CALL GPRH(LDWMORH,KPROMA,KSTART,KPROF,KFLEV,PRHMAX,PRHMIN,&
 & PQF(1,1),PTF(1,1),PRXP(1,1,2),&
 & ZES(1,1),ZRHF(1,1))  

!*       1.2   PREPARE FOR EXTRAPOLATION ABOVE TOP

DO JL=KSTART,KPROF
  ZRHF(JL,0)=ZRHF(JL,1)
ENDDO

!*       1.3   INTERPOLATE RELATIVE HUMIDITY.

ISLCT=2
CALL PPINTP(KPROMA,KSTART,KPROF,KFLEV,KLEVP,KLOLEV,&
 & KLEVB,ISLCT,&
 & LDBELO,LDBLOW,PRPRES,PRXP,PRXPD,&
 & ZRHF,PRHPP)  

!*       1.4   CONSTANT EXTRAPOLATION BELOW LOWEST MODEL LEVEL.

DO JLEVP=KLOLEV,KLEVP
  IF (LDBLOW(JLEVP)) THEN
    DO JL=KSTART,KPROF
      IF (LDBELO(JL,JLEVP)) THEN
        PRHPP(JL,JLEVP)=ZRHF(JL,KFLEV)
      ENDIF
    ENDDO
  ENDIF
ENDDO

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

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