SUBROUTINE PPINTP(KPROMA,KSTART,KPROF,KFLEV,KLEVP,KLOLEV,&
 & KLEVB,KSLCT,&
 & LDBELO,LDBLOW,PRPRESC,PRXP,PRXPD,&
 & PFLDI,PFLDO)  

!**** *PPINTP* - LINEARLY INTERPOLATE FIELDS TO GIVEN LEVEL

!     PURPOSE.
!     --------
!           PERFORMS THE VERTICAL LINEAR INTERPOLATION OF A FIELD
!           TO A GIVEN LEVEL.
!           IMPLICITLY ALSO EXTRAPOLATES ABOVE THE TOP MODEL LEVEL.

!**   INTERFACE.
!     ----------
!        *CALL* *PPINTP(KPROMA,KSTART,KPROF,KFLEV,KLEVP,KLOLEV,
!                       KLEVB,KSLCT,
!                       LDBELO,LDBLOW,PRPRESC,PRXP,PRXPD,
!                       PFLDI,PFLDO)

!        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)
!        KLEVB(KPROMA,KLEVP,NPPM)  - INPUT LEVEL BELOW PRPRES          (INPUT-C)
!        KLOLEV                    - BEGINING FOR THE INTERPOLATION    (INPUT-C)
!        KLEVB(KPROMA,KLEVP,3)     - INPUT LEVEL BELOW PRPRES           (INPUT-C)
!                                    (SEE PPFLEV)
!        KSLCT                     - 1:  FIELD GIVEN ON HALF LEVELS.
!                                        INTERPOLATE IN P
!                                  - 2:  FIELD GIVEN ON FULL LEVELS.
!                                        INTERPOLATE IN P
!                                  - 3:  FIELD GIVEN ON HALF LEVELS.
!                                        INTERPOLATE IN LN(P)          (INPUT-C)
!                                  - 4:  FIELD GIVEN ON FULL LEVELS.
!                                        INTERPOLATE IN LN(P)
!        LDBELO(KPROMA,KLEVP)      - .TRUE. IF PRESSURE IS UNDER
!                                     LOWEST  MODEL LEVEL              (INPUT-C)
!        LDBLOW(KLEVP)             - .TRUE. IF LDBELO IS   CONTAINING
!                                    AT LEAST ONE .TRUE.               (INPUT-C)
!        PRPRESC(KPROMA,KLEVP)      - POST-PROCESSING LEVEL
!                                    PRESSURES:
!                                    IF KVINT=1 OR KVINT = 2:
!                                     PRESSURE
!                                    IF KVINT=3:
!                                     LN PRESSURE                      (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)
!        PFLDI(KPROMA,KLB:KFLEV)   - MODEL LEVEL FIELD VALUES          (INPUT)

!        PFLDO(KPROMA,KLEVP)       - INTERPOLATED FIELD VALUES         (OUTPUT)

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

!     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
!        M.Hamrud      01-Oct-2003 CY28 Cleaning
!        R. El Khatib  27-Apr-2007 Optimization
!     ------------------------------------------------------------------

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) 
INTEGER(KIND=JPIM),INTENT(IN)    :: KSLCT 
LOGICAL           ,INTENT(IN)    :: LDBELO(KPROMA,KLEVP) 
LOGICAL           ,INTENT(IN)    :: LDBLOW(KLEVP) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PRPRESC(KPROMA,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(IN)    :: PFLDI(KPROMA,0:KFLEV) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PFLDO(KPROMA,KLEVP) 
INTEGER(KIND=JPIM) :: IAB, JL, JLEVP
REAL(KIND=JPRB) :: ZHOOK_HANDLE

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

!*       1.    LINEAR INTERPOLATION AND UPWARD EXTRAPOLATION.
!              ----------------------------------------------

!*       1.1   INTERPOLATE .
IF (LHOOK) CALL DR_HOOK('PPINTP',0,ZHOOK_HANDLE)
DO JLEVP=KLOLEV,KLEVP
  IF (.NOT.LDBLOW(JLEVP)) THEN
    DO JL=KSTART,KPROF
      IAB=KLEVB(JL,JLEVP,KSLCT)-1
      PFLDO(JL,JLEVP)=PFLDI(JL,IAB)+ &
       & (PFLDI(JL,KLEVB(JL,JLEVP,KSLCT))-PFLDI(JL,IAB))* &
       & (PRPRESC(JL,JLEVP)-PRXP(JL,IAB,KSLCT))*PRXPD(JL,IAB,KSLCT)
    ENDDO
  ELSE
    DO JL=KSTART,KPROF
      IF (.NOT.LDBELO(JL,JLEVP)) THEN
        IAB=KLEVB(JL,JLEVP,KSLCT)-1
        PFLDO(JL,JLEVP)=PFLDI(JL,IAB)+ &
         & (PFLDI(JL,KLEVB(JL,JLEVP,KSLCT))-PFLDI(JL,IAB))* &
         & (PRPRESC(JL,JLEVP)-PRXP(JL,IAB,KSLCT))*PRXPD(JL,IAB,KSLCT)
      ENDIF
    ENDDO
  ENDIF
ENDDO

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

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