SUBROUTINE PPINTZAD(KPROMA,KSTART,KPROF,KFLEV,KLEVP,KLOLEV,KLEVB,&
 & KSLCT,KSTL,LDBE,LDBL,PZO,&
 & PRXZ,PRXZD,PFLDI,&
 & PFLDO,&
 & PRXZ5,PRXZD5,PFLDI5)  

!**** *PPINTZAD* - LINEARLY INTERPOLATE FIELDS TO GIVEN LEVEL - ADJOINT

!     PURPOSE.
!     --------
!        PERFORMS THE VERTICAL INTERPOLATION OF A FIELD TO A GIVEN
!     LEVEL.

!**   INTERFACE.
!     ----------
!        *CALL* *PPINTZAD(KPROMA,KSTART,KPROF,KFLEV,KLEVP,KLOLEV,KLEVB,
!                         KSLCT,LDBE,LDBL,PZO,
!                         PRXZ,PRXZD,PFLDI,
!                         PFLDO,
!                         PRXZ5,PRXZD5,PFLDI5)

!        EXPLICIT ARGUMENTS :
!        --------------------
!        KPROMA                     - HORIZONTAL DIMENSION.
!        KSTART                     - START OF WORK.
!        KPROF                      - DEPTH OF WORK.
!        KFLEV                      - NUMBER OF INPUT PRESSURE LEVELS
!        KLEVP                      - NUMBER OF OUTPUT PRESSURE LEVELS
!        KLOLEV                     - BEGINING FOR THE INTERPOLATION
!        KLEVB                      - INPUT LEVEL BELOW PZO
!        KSLCT                      - INTERPOLATION CHOICE:
!                                     1= FIELD GIVEN ON HALF LEVELS,
!                                        INTERPOLATION IN Z
!                                     2= FIELD GIVEN ON FULL LEVELS,
!                                        INTERPOLATION IN Z
!                                     3= FIELD GIVEN ON HALF LEVELS,
!                                        INTERPOLATION IN LN(Z)
!                                     4= FIELD GIVEN ON FULL LEVELS,
!                                        INTERPOLATION IN LN(Z)
!        KSTL                       - START LEVEL FOR INPUT FIELD
!        LDBE                       - .TRUE. IF HEIGHT IS UNDER
!                                     LOWEST  MODEL LEVEL
!        LDBL                       - .TRUE. IF LDBELO IS CONTAINING
!                                     AT LEAST ONE .TRUE.
!        PZO    (KPROMA,KLEVP)      - POST-PROCESSING LEVELS
!        PRXZ(KPROMA,0:KFLEV,NPPM ) - HALF,FULL AND LN HALF,FULL LEVEL
!                                     HEIGHTS (SEE PPINITZ)
!        PRXZD(KPROMA,0:KFLEV,NPPM) - 1./D(Z) AND 1./D(LN(Z))
!        PFLDI(KPROMA,KLB:KFLEV)    - MODEL LEVEL FIELD VALUES
!        PFLDO(KPROMA,KLEVP)        - INTERPOLATED FIELD VALUES
!        PRXZ5(KPROMA,0:KFLEV,NPPM) - HALF,FULL AND LN HALF,FULL LEVEL Z
!        PRXZD5(KPROMA,0:KFLEV,NPPM)- 1./D(Z) AND 1./D(LN(Z))
!        PFLDI5(KPROMA,KLB:KFLEV)   - MODEL LEVEL FIELD VALUES

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

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

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

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

!     AUTHOR.
!     -------
!        D. VASILJEVIC  *ECMWF*

!     MODIFICATIONS.
!     --------------
!        ORIGINAL : 90-02-01
!        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)    :: KSTL 
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)    :: LDBE(KPROMA,KLEVP) 
LOGICAL           ,INTENT(IN)    :: LDBL(KLEVP) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PZO(KPROMA,KLEVP) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PRXZ(KPROMA,0:KFLEV,NPPM) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PRXZD(KPROMA,0:KFLEV,NPPM) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PFLDI(KPROMA,KSTL:KFLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PFLDO(KPROMA,KLEVP) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PRXZ5(KPROMA,0:KFLEV,NPPM) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PRXZD5(KPROMA,0:KFLEV,NPPM) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PFLDI5(KPROMA,KSTL:KFLEV) 
INTEGER(KIND=JPIM) :: IAB, IBL, JL, JLEVP
REAL(KIND=JPRB) :: ZHOOK_HANDLE

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

!*       1.    Linear interpolation and constant value extrapolation.
!              ------------------------------------------------------

!*       1.1   INTERPOLATE .

IF (LHOOK) CALL DR_HOOK('PPINTZAD',0,ZHOOK_HANDLE)
DO JLEVP=KLOLEV,KLEVP
  IF(.NOT. LDBL  (JLEVP)) THEN
    DO JL=KSTART,KPROF
      IBL=KLEVB(JL,JLEVP,KSLCT)
      IAB=IBL-1
      PFLDI(JL,IBL)=PFLDI(JL,IBL) +&
       & PFLDO(JL,JLEVP)*&
       & (1.0_JPRB-&
       & PZO(JL,JLEVP)*PRXZD5(JL,IAB,KSLCT)+&
       & PRXZ5(JL,IBL,KSLCT)*PRXZD5(JL,IAB,KSLCT))  

      PFLDI(JL,IAB)=PFLDI(JL,IAB) +&
       & PFLDO(JL,JLEVP)*&
       & (PZO(JL,JLEVP)*PRXZD5(JL,IAB,KSLCT)-&
       & PRXZ5(JL,IBL,KSLCT)*PRXZD5(JL,IAB,KSLCT))  

      PRXZ(JL,IBL,KSLCT)=PRXZ(JL,IBL,KSLCT) +&
       & PFLDO(JL,JLEVP)*&
       & (PFLDI5(JL,IBL)*PRXZD5(JL,IAB,KSLCT)-&
       & PFLDI5(JL,IAB)*PRXZD5(JL,IAB,KSLCT) )  

      PRXZD(JL,IAB,KSLCT)=PRXZD(JL,IAB,KSLCT) +&
       & PFLDO(JL,JLEVP)*&
       & (PZO(JL,JLEVP)*PFLDI5(JL,IAB)-&
       & PFLDI5(JL,IAB)*PRXZ5(JL,IBL,KSLCT)-&
       & PZO(JL,JLEVP)*PFLDI5(JL,IBL)+&
       & PFLDI5(JL,IBL)*PRXZ5(JL,IBL,KSLCT))  
    ENDDO
  ELSE
    DO JL=KSTART,KPROF
      IF(.NOT.LDBE  (JL,JLEVP)) THEN
        IBL=KLEVB(JL,JLEVP,KSLCT)
        IAB=IBL-1
        PFLDI(JL,IBL)=PFLDI(JL,IBL) +&
         & PFLDO(JL,JLEVP)*&
         & (1.0_JPRB-&
         & PZO(JL,JLEVP)*PRXZD5(JL,IAB,KSLCT)+&
         & PRXZ5(JL,IBL,KSLCT)*PRXZD5(JL,IAB,KSLCT))  

        PFLDI(JL,IAB)=PFLDI(JL,IAB) +&
         & PFLDO(JL,JLEVP)*&
         & (PZO(JL,JLEVP)*PRXZD5(JL,IAB,KSLCT)-&
         & PRXZ5(JL,IBL,KSLCT)*PRXZD5(JL,IAB,KSLCT))  

        PRXZ(JL,IBL,KSLCT)=PRXZ(JL,IBL,KSLCT) +&
         & PFLDO(JL,JLEVP)*&
         & (PFLDI5(JL,IBL)*PRXZD5(JL,IAB,KSLCT)-&
         & PFLDI5(JL,IAB)*PRXZD5(JL,IAB,KSLCT) )  

        PRXZD(JL,IAB,KSLCT)=PRXZD(JL,IAB,KSLCT) +&
         & PFLDO(JL,JLEVP)*&
         & (PZO(JL,JLEVP)*PFLDI5(JL,IAB)-&
         & PFLDI5(JL,IAB)*PRXZ5(JL,IBL,KSLCT)-&
         & PZO(JL,JLEVP)*PFLDI5(JL,IBL)+&
         & PFLDI5(JL,IBL)*PRXZ5(JL,IBL,KSLCT))  
      ENDIF
    ENDDO
  ENDIF
ENDDO

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

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

