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

!**** *LAIDLIC  -  Observation interpolator:
!                 Bilinear horizontal interpolations for one variable.

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


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

!        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 SLINT.

!     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.
!        Drasco Vasiljevic, Ad Stoffelen  ECMWF    16/08/93   :
!                            -   After LAIDLI, but closest point
!     E.Andersson 96-07-08 : Fujitsu vectorisation
!     E.Andersson 98-08-18 : Correction of bug, which caused interpolated
!                            SSMI CLW to be zero everywhere.
!        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) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PDLO(KPROMB,1:2) 
INTEGER(KIND=JPIM),INTENT(IN)    :: KL0(KPROMB,2,2) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PXSL(KPROMA*(KFLDX-KFLDN+1)) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PXF(KPROMB,KFLEV) 

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

INTEGER(KIND=JPIM) :: IPOINT(KPROMB)

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

REAL(KIND=JPRB) :: ZDLAT, ZDLO1, ZDLO2, ZW11, ZW12, ZW21, ZW22, ZWMAX
REAL(KIND=JPRB) :: ZHOOK_HANDLE

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

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

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

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

!        1.1   Computation of coordinates and distances.

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

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

  ZW11 = (1.0_JPRB-ZDLO1)*(1.0_JPRB-ZDLAT)
  ZW12 =     ZDLO1 *(1.0_JPRB-ZDLAT)
  ZW21 = (1.0_JPRB-ZDLO2)*    ZDLAT
  ZW22 =     ZDLO2 *    ZDLAT
  ZWMAX = MAX(ZW11,ZW12,ZW21,ZW22)

!        1.2   Pick nearest point

  IF(ZWMAX == ZW11)THEN
    IPNT1 = 1
    IPNT2 = 1
  ELSEIF(ZWMAX == ZW12)THEN
    IPNT1 = 1
    IPNT2 = 2
  ELSEIF(ZWMAX == ZW21)THEN
    IPNT1 = 2
    IPNT2 = 1
  ELSE
    IPNT1 = 2
    IPNT2 = 2
  ENDIF
  IPOINT(JROF)=KL0(JROF,IPNT1,IPNT2)
ENDDO

CALL GSTATS(1021,0)
!$OMP PARALLEL DO SCHEDULE(DYNAMIC,1) PRIVATE(JLEV,IOFF,JROF)
DO JLEV=1,KFLEV
  IOFF=(JLEV-1)*KPROMA
  DO JROF=KSTART,KPROF
    PXF(JROF,JLEV) = PXSL(IPOINT(JROF)+IOFF)
  ENDDO
ENDDO
!$OMP END PARALLEL DO
CALL GSTATS(1021,1)

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

