SUBROUTINE PPQAD(KPROMA,KSTART,KPROF,KFLEV,KLEVP,KLOLEV,&
 & KLEVB,PRPRES,LDBELO,LDBLOW,&
 & PRXP,PRXPD,PQF,&
 & PQPP,&
 & PRXP5,PRXPD5,PQF5)  

!**** *PPQAD* - POST-PROCESS SPECIFIC HUMIDITY - ADJOINT

!     PURPOSE.
!     --------
!           PERFORMS THE VERTICAL INTERPOLATION OF SPECIFIC HUMIDITY GIVEN
!       MODEL CO-ORDINATE LEVEL.

!**   INTERFACE.
!     ----------
!        *CALL* *PPQAD(KPROMA,KSTART,KPROF,KFLEV,KLEVP,KLOLEV,KLEVB,
!                    PRPRES,LDBELO,LDBLOW,PRXP,PRXPD,
!                    PQF,PQPP,PRXP5,PRXPD5,PQF5)

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

!        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)
!        KLEVB(KPROMA,KLEVP,NPPM)  - INPUT LEVEL BELOW PRPRES          (INPUT-C)
!                                    (SEE PPFLEV)
!        PRPRES(KPROMA,KLEVP)      - POST PROCESS LEVEL PRESSURES      (INPUT_C)
!        LDBELO(KPROMA,KLEVP)      - .TRUE. IF PRESSURE IS UNDER
!                                     LOWEST (FULL) MODEL LEVEL        (INPUT-C)
!        LDBLOW(KLEVP)             - FIRST LEVEL OF LDBELO CONTAINING
!                                    AT LEAST ONE .TRUE.               (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)

!        PQPP(KPROMA,KLEVP)        - POST-PROCESSED SPECIFIC HUMIDITY  (OUTPUT)
!        PRXP5(KPROMA,0:KFLEV,NPPM)- HALF,FULL AND LN HALF,FULL LEVEL
!                                    PRESSURES (SEE PPINIT)            (INPUT-T)
!        PRXPD5(KPROMA,0:KFLEV,NPPM)- 1./D(P) AND 1./D(LN(P))          (INPUT-T)
!        PQF5(KPROMA,0:KFLEV)      - SPECIFIC HUMIDITY ON FULL INPUT
!                                    LEVELS.                           (INPUT-T)

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

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

!     EXTERNALS.  PPINTPAD - LINEAR INTERPOLATION
!     ----------

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

!     AUTHOR.
!     -------
!        MATS HAMRUD *ECMWF*

!     MODIFICATIONS.
!     --------------
!        ORIGINAL : 91-01-16
!        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 
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(INOUT) :: PRXP(KPROMA,0:KFLEV,NPPM) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PRXPD(KPROMA,0:KFLEV,NPPM) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PQF(KPROMA,0:KFLEV) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PQPP(KPROMA,KLEVP) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PRXP5(KPROMA,0:KFLEV,NPPM) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PRXPD5(KPROMA,0:KFLEV,NPPM) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PQF5(KPROMA,0:KFLEV) 
INTEGER(KIND=JPIM) :: ISLCT, JL, JLEVP
REAL(KIND=JPRB) :: ZHOOK_HANDLE

#include "ppintpad.intfb.h"

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

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

IF (LHOOK) CALL DR_HOOK('PPQAD',0,ZHOOK_HANDLE)
DO JL=KSTART,KPROF
  PQF5(JL,0)=PQF5(JL,1)
ENDDO

!*       1.3   EXTRAPOLATE  BELOW SURFACE.

DO JLEVP=KLOLEV,KLEVP
  IF(LDBLOW(JLEVP)) THEN
    DO JL=KSTART,KPROF
      IF(LDBELO(JL,JLEVP)) THEN
        PQF(JL,KFLEV)=PQF(JL,KFLEV)+PQPP(JL,JLEVP)
        PQPP(JL,JLEVP)=0.0_JPRB
      ENDIF
    ENDDO
  ENDIF
ENDDO

!*       1.2   INTERPOLATE SPECIFIC HUMIDITY.
ISLCT=2
CALL PPINTPAD(KPROMA,KSTART,KPROF,KFLEV,KLEVP,KLOLEV,KLEVB,&
 & ISLCT,LDBELO,LDBLOW,PRPRES,PRXP,PRXPD,&
 & PQF,PQPP,PRXP5,PRXPD5,PQF5)  

!*       1.1   PREPARE FOR EXTRAPOLATION ABOVE TOP
DO JL=KSTART,KPROF
  PQF(JL,1)=PQF(JL,1)+PQF(JL,0)
ENDDO

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

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