SUBROUTINE LAIDLICAD(KPROMA,KPROMB,KSTART,KPROF,KFLEV,&
 & KFLDN,KFLDX,&
 & PDLAT,PDLO,KL0,&
 & PXSL,PXF)  

!**** *LAIDLICAD  -  Observation interpolator:
!                 Bilinear horizontal interpolations for one variable.
!                 Adjoint code of LAIDLIC.

!     Purpose.
!     --------
!       Performs bilinear horizontal interpolations for one variable:
!        simply takes the value of the nearest grid point.

!**   Interface.
!     ----------
!        *CALL* *LAIDLICAD(...)

!        Explicit arguments :
!        --------------------

!        INPUT:
!          KPROMA  - horizontal dimension for grid-point quantities.
!          KPROMB  - horizontal dimension for interpolation point
!                    quantities.
!          KSTART  - first element of arrays where
!                    computations are performed.
!          KPROF   - depth of work.
!          KFLEV   - vertical dimension.
!          KFLDN   - number of the first field.
!          KFLDX   - number of the last field.
!          PDLAT   - weight (distance) for horizontal linear interpolation
!                    on a same latitude.
!          PDLO    - weights (distances) for horizontal linear interpolation
!                    on a same longitude.
!          KL0     - indices of the four western points
!                    of the 16 points interpolation grid.

!        INPUT/OUTPUT:
!          PXSL    - quantity to be interpolated.

!        INPUT:
!          PXF     - interpolated variable.

!        Implicit arguments :
!        --------------------

!     Method.
!     -------
!        See documentation

!     Externals.
!     ----------

!        No external.
!        Called by SLINTAD.

!     Reference.
!     ----------

!     Author.
!     -------
!        K. YESSAD, after the subroutines LAGINL3
!        written by Maurice IMBARD, Alain CRAPLET and Michel ROCHAS
!        METEO-FRANCE, CNRM/GMAP.

!     Modifications.
!     --------------
!        Original : FEBRUARY 1992.
!     E.Andersson 96-07-08 : Fujitsu vectorisation
!      M.Hamrud      01-Oct-2003 CY28 Cleaning
!      K. Yessad (Sep 2008): update comments + cleanings.
!     ------------------------------------------------------------------

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

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

IMPLICIT NONE

INTEGER(KIND=JPIM),INTENT(IN)    :: KPROMA 
INTEGER(KIND=JPIM),INTENT(IN)    :: KPROMB 
INTEGER(KIND=JPIM),INTENT(IN)    :: KFLEV 
INTEGER(KIND=JPIM),INTENT(IN)    :: KFLDN 
INTEGER(KIND=JPIM),INTENT(IN)    :: KFLDX 
INTEGER(KIND=JPIM),INTENT(IN)    :: KSTART 
INTEGER(KIND=JPIM),INTENT(IN)    :: KPROF 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PDLAT(KPROMB,KFLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PDLO(KPROMB,KFLEV,1:2) 
INTEGER(KIND=JPIM),INTENT(IN)    :: KL0(KPROMB,KFLEV,1:2) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PXSL(KPROMA*(KFLDX-KFLDN+1)) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PXF(KPROMB,KFLEV) 

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

REAL(KIND=JPRB) :: ZW   (KPROMB,2,2)
REAL(KIND=JPRB) :: ZWMAX(KPROMB)

INTEGER(KIND=JPIM) :: ILEV, IPNT1, IPNT2, JLEV, JROF

REAL(KIND=JPRB) :: ZDLAT, ZDLO1, ZDLO2
REAL(KIND=JPRB) :: ZHOOK_HANDLE

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

IF (LHOOK) CALL DR_HOOK('LAIDLICAD',0,ZHOOK_HANDLE)

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

!*       1.    INTERPOLATIONS.
!              ---------------

!        1.1   Computation of coordinates and distances.
!              Lat and Lon are not allowed to vary with jlev!

ILEV=1
DO JROF=KSTART,KPROF
  ZDLAT =PDLAT(JROF,ILEV)

  ZDLO1 =PDLO(JROF,ILEV,1)
  ZDLO2 =PDLO(JROF,ILEV,2)

  ZW(JROF,1,1) = (1.0_JPRB-ZDLO1)*(1.0_JPRB-ZDLAT)
  ZW(JROF,1,2) =     ZDLO1 *(1.0_JPRB-ZDLAT)
  ZW(JROF,2,1) = (1.0_JPRB-ZDLO2)*    ZDLAT
  ZW(JROF,2,2) =     ZDLO2 *    ZDLAT
  ZWMAX(JROF) = MAX(ZW(JROF,1,1),ZW(JROF,1,2),ZW(JROF,2,1),ZW(JROF,2,2))
ENDDO

!        1.2   Pick nearest point

DO JROF=KSTART,KPROF
  IF(ZWMAX(JROF) == ZW(JROF,1,1) )THEN
    IPNT1 = 1
    IPNT2 = 1
  ELSEIF(ZWMAX(JROF) == ZW(JROF,1,2) )THEN
    IPNT1 = 1
    IPNT2 = 2
  ELSEIF(ZWMAX(JROF) == ZW(JROF,2,1) )THEN
    IPNT1 = 2
    IPNT2 = 1
  ELSEIF(ZWMAX(JROF) == ZW(JROF,2,2) )THEN
    IPNT1 = 2
    IPNT2 = 2
  ENDIF

!OCL NOVREC
  DO JLEV=1,KFLEV
    PXSL(KL0(JROF,JLEV,IPNT1)+IPNT2)=&
     & PXSL(KL0(JROF,JLEV,IPNT1)+IPNT2)+PXF(JROF,JLEV)  
  ENDDO
ENDDO

!     ------------------------------------------------------------------
IF (LHOOK) CALL DR_HOOK('LAIDLICAD',1,ZHOOK_HANDLE)
END SUBROUTINE LAIDLICAD

