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

!**** *LAIDLIOBSAD-  Observation interpolator:
!                    AD of Bilinear horizontal interpolations for one variable.

!     Purpose.
!     --------
!       Performs AD of bilinear horizontal interpolations for one variable.
!       The position of the interpolation point and the weights
!        are considered as constants (they are not differentiated).

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

!        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.
!          PXSL    - quantity to be interpolated.

!        OUTPUT:
!          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.
!        M.Hamrud      01-Oct-2003 CY28 Cleaning
!        K.Yessad (Sept 2008): correct false comments + cleanings.
!     ------------------------------------------------------------------

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

USE YOMPLDSW , ONLY : LOPT_SCALAR

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

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) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PDLO(KPROMB,1:2) 
INTEGER(KIND=JPIM),INTENT(IN)    :: KL0(KPROMB,2,2) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PXSL(KPROMA*(KFLDX-KFLDN+1)) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PXF(:,:) 

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

INTEGER(KIND=JPIM) :: IP11, IP12, IP21, IP22, JLEV, JROF

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

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

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

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

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

IF(LOPT_SCALAR)THEN
  CALL GSTATS(1085,0)
!$OMP PARALLEL DO SCHEDULE(STATIC)&
!$OMP&PRIVATE(JLEV,JROF,ZDLAT,ZDLO1,ZDLO2,ZVALL01,ZVALL02) &
!$OMP&            PRIVATE(IP11,IP12,IP21,IP22)
  DO JLEV=1,KFLEV
    DO JROF=KSTART,KPROF

!     Computation of coordinates and distances.

      ZDLAT = PDLAT(JROF)
  
      ZDLO1 = PDLO(JROF,1)
      ZDLO2 = PDLO(JROF,2)

!     Interpolation.

      ZVALL01 = (1.0_JPRB-ZDLAT)*PXF(JLEV,JROF)
      ZVALL02 = ZDLAT*PXF(JLEV,JROF)

      IP11 = KL0(JROF,1,1)+(JLEV-1)*KPROMA
      IP12 = KL0(JROF,1,2)+(JLEV-1)*KPROMA
      IP21 = KL0(JROF,2,1)+(JLEV-1)*KPROMA
      IP22 = KL0(JROF,2,2)+(JLEV-1)*KPROMA

      PXSL(IP11) = PXSL(IP11)+(1.0_JPRB-ZDLO1)*ZVALL01
      PXSL(IP12) = PXSL(IP12)+ZDLO1     *ZVALL01
      PXSL(IP21) = PXSL(IP21)+(1.0_JPRB-ZDLO2)*ZVALL02
      PXSL(IP22) = PXSL(IP22)+ZDLO2     *ZVALL02

    ENDDO
  ENDDO
!$OMP END PARALLEL DO
  CALL GSTATS(1085,1)

ELSE

  DO JROF=KSTART,KPROF
!DIR$ IVDEP
!OCL NOVREC
    DO JLEV=1,KFLEV

!     Computation of coordinates and distances.

      ZDLAT = PDLAT(JROF)

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

!     Interpolation.

      ZVALL01 = (1.0_JPRB-ZDLAT)*PXF(JLEV,JROF)
      ZVALL02 = ZDLAT*PXF(JLEV,JROF)

      IP11 = KL0(JROF,1,1)+(JLEV-1)*KPROMA
      IP12 = KL0(JROF,1,2)+(JLEV-1)*KPROMA
      IP21 = KL0(JROF,2,1)+(JLEV-1)*KPROMA
      IP22 = KL0(JROF,2,2)+(JLEV-1)*KPROMA

      PXSL(IP11) = PXSL(IP11)+(1.0_JPRB-ZDLO1)*ZVALL01
      PXSL(IP12) = PXSL(IP12)+ZDLO1     *ZVALL01
      PXSL(IP21) = PXSL(IP21)+(1.0_JPRB-ZDLO2)*ZVALL02
      PXSL(IP22) = PXSL(IP22)+ZDLO2     *ZVALL02

    ENDDO
  ENDDO
ENDIF

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