SUBROUTINE PPCH4(KPROMA,KSTART,KPROF,KFLEV,KLEVP,KLOLEV,&
 & KLEVB,PRPRES,LDBELO,LDBLOW,&
 & PRXP,PRXPD,PCH4F,PCH4PP)  

!**** *PPCH4* - POST-PROCESS METHANE.

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

!**   INTERFACE.
!     ----------
!        *CALL* *PPCH4(KPROMA,KSTART,KPROF,KFLEV,KLEVP,KLOLEV
!    1              ,KLEVB,PRPRES,LDBELO,LDBLOW
!    2              ,PRXP,PRXPD,PCH4F,PCH4PP)

!        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)
!        KLOLEV                    - BEGINING FOR THE INTERPOLATION    (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)             - .TRUE. IF LDBELO(J) IS 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)
!        PCH4F(KPROMA,0:KFLEV)       - SPECIFIC HUMIDITY ON FULL INPUT
!                                    LEVELS.                           (INPUT)

!        PCH4PP(KPROMA,KLEVP)        - POST-PROCESSED SPECIFIC HUMIDITY  (OUTPUT)

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

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

!     EXTERNALS.  PPINTP - LINEAR INTERPOLATION
!     ----------

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

!     AUTHOR.
!     -------
!        Based on PPQ from MATS HAMRUD AND PHILIPPE COURTIER  *ECMWF*

!     MODIFICATIONS.
!     --------------
!        ORIGINAL : 89-01-26
!        M.Hamrud      01-Oct-2003 CY28 Cleaning
!        R. Engelen  19-Dec-2008 Change Q to CH4
!     ------------------------------------------------------------------

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(IN)    :: PRXP(KPROMA,0:KFLEV,NPPM) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PRXPD(KPROMA,0:KFLEV,NPPM) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PCH4F(KPROMA,0:KFLEV) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PCH4PP(KPROMA,KLEVP) 
INTEGER(KIND=JPIM) :: ISLCT, JL, JLEVP
REAL(KIND=JPRB) :: ZHOOK_HANDLE

#include "ppintp.intfb.h"

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

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

!*       1.1   PREPARE FOR EXTRAPOLATION ABOVE TOP

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

!*       1.2   INTERPOLATE SPECIFIC HUMIDITY.
ISLCT=2
CALL PPINTP(KPROMA,KSTART,KPROF,KFLEV,KLEVP,KLOLEV,&
 & KLEVB,ISLCT,&
 & LDBELO,LDBLOW,PRPRES,PRXP,PRXPD,&
 & PCH4F,PCH4PP)  

!*       1.3   EXTRAPOLATE  BELOW SURFACE.

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

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

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