SUBROUTINE LARCINBTL(KST,KPROF,LD2TLFF1,KL0,KLH0,&
 & PDLO,PCLO,PCLOSLD,PDLAT,PCLA,PCLASLD,PDVER,PVINTW,PVINTWSLD,PB1,PB15,&
 & PDP,PUF,PVF,PTF,PGFLF,PCF,PUFZ,PVFZ,&
 & PUF5,PVF5,PUFZ5,PVFZ5,&
 & PDLO5,PCLO5,PCLOSLD5,PDLAT5,PCLA5,PCLASLD5,PDVER5,PVINTW5,PVINTWSLD5)  

!**** *LARCINBTL - semi-LAgrangian scheme:(Interpolation)
!                                            (tangent-linear version)

!     Purpose.
!     --------
!       Does the interpolations necessary in the semi-Lagrangian scheme.

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

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

!        INPUT:
!          KST     - first element of arrays where computations are performed.
!          KPROF   - depth of work.
!          LD2TLFF1- .T./.F.: Refined treatement of (2*Omega Vec r) at
!                    the origin point when there is t-dt (or t in SL2TL)
!                    physics / Other cases.
!          KL0     - index of the four western points
!                    of the 16 points interpolation grid.
!          KLH0    - second value of index of the four western points
!                    of the 16 points interpolation grid if needed.
!          PDLO    - distances for horizontal linear interpolations
!                    in longitude (latitude rows 0, 1, 2, 3)
!          PCLO    - weights for horizontal cubic interpolations in
!                    longitude (latitude rows 1, 2)
!          PCLOSLD - weights for horizontal cubic interpolations in
!                    longitude, SLHD case (latitude rows 1, 2)
!          PDLAT   - distance for horizontal linear interpolations
!                    in latitude
!          PCLA    - weights for horizontal cubic interpolations
!                    in latitude
!          PCLASLD - weights for horizontal cubic interpolations
!                    in latitude, SLHD case
!          PDVER   - distance for vertical linear interpolation
!          PVINTW  - vertical cubic interpolation weights
!          PVINTWSLD-vertical cubic interpolation weights, SLHD case
!          PB1     - "SLBUF1" buffer for interpolations.
!          PB15    - "SLBUF1" buffer for interpolations (trajectory).

!        OUTPUT:
!          PDP     - Interpolated 2D term at O for continuity equation.
!          PUF     - Interpolated quantity at O in the U-wind eqn.
!          PVF     - Interpolated quantity at O in the V-wind eqn.
!          PTF     - Interpolated quantity at O in the temperature eqn.
!          PGFLF   - Interpolated quantity at O 
!          PCF     - Interpolated 3D quantity at O in the cont. eqn.
!          PUFZ and PVFZ for SL2TL scheme:
!          PUFZ    - Interpolated U-wind at O for L2TLFF=.T. option.
!          PVFZ    - Interpolated V-wind at O for L2TLFF=.T. option.
! ---------------------------- trajectory variables --------------------------
!          PUF5    - Trajectory for PUF.
!          PVF5    - Trajectory for PVF.
!          PUFZ5   - Trajectory for PUFZ.
!          PVFZ5   - Trajectory for PVFZ.
! ----------------------------------------------------------------------------

!        TRAJECTORY INPUT:
!          PDLO5   - Trajectory for PDLO.
!          PCLO5   - Trajectory for PCLO.
!          PCLOSLD5- Trajectory for PCLOSLD.
!          PDLAT5  - Trajectory for PDLAT.
!          PCLA5   - Trajectory for PCLA.
!          PCLASLD5- Trajectory for PCLASLD.
!          PDVER5  - Trajectory for PDVER.
!          PVINTW5 - Trajectory for PVINTW.
!          PVINTWSLD5- Trajectory for PVINTWSLD.

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

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

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

!        Called by LAPINEBTL.
!        Calls LAITRE_GMV_TL,LAITLITL,LAIDDITL

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

!     Author.
!     -------
!        C. Temperton (ECMWF)

!     Modifications.
!     --------------
!        Original: 99/07/12
!        Modified 00-02-07 by C. Temperton: removed redundant use of PX0
!                                           when NVLAG=3.
!        Modified 00-03-01 by C. Temperton: precompute functions for    
!                                           cubic interpolation.
!        Modified August 2000 by Deborah Salmond to split into _traj and _int
!        Modified 00-11-23 by C. Temperton: renamed _TRAJ and _INT routines.
!        Modified 01-08-30 by K. YESSAD: pruning and some other cleanings.
!        M.Hamrud      01-Oct-2003 CY28 Cleaning
!        D.Salmond     22-Dec-2003 Karim's Larcin cleaning
!        Modified 05-01-19 by C. Temperton: cleaning.
!        Modified 19-Mar-2007 K. Yessad: reorder according to LARCINB.
!        E.Holm      07/06/27: Option to advect without wind increments (LADV5)
!        F.Vana   30-Jun-2008: Weights driven interpolation
!        K. Yessad Nov 2008: rationalisation of dummy argument interfaces
!     ------------------------------------------------------------------

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

USE YOMDIM   , ONLY : NFLEVG   ,NPROMA   ,NFLSA    ,NFLEN
USE YOM_YGFL  ,ONLY : YGFL     ,YGFLC
USE YOMDYNA   ,ONLY : LSLHD_W  ,LSLHD_T
USE YOMDYN   , ONLY : NVLAG    ,NWLAG    ,NTLAG
USE YOMMP    , ONLY : NASLB1
USE YOMSC2   , ONLY : NFLDSLB1 ,NFLDSLB15
USE PTRSLB1  , ONLY : MSLB1UR9 ,MSLB1VR9 ,MSLB1SP9 ,MSLB1U9  ,MSLB1V9  ,&
 & MSLB1T9  ,MSLB1GFL9,MSLB1C9  ,MSLB1U0  ,MSLB1V0  ,MSLB1T0
USE PTRSLB15 , ONLY : MSLB1UR95,MSLB1VR95,MSLB1SP95,MSLB1U95 ,MSLB1V95 ,&
 & MSLB1T95 ,MSLB1GFL95,MSLB1C95 ,MSLB1U05 ,MSLB1V05 ,MSLB1T05

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

IMPLICIT NONE

INTEGER(KIND=JPIM),INTENT(IN)    :: KST 
INTEGER(KIND=JPIM),INTENT(IN)    :: KPROF 
LOGICAL           ,INTENT(IN)    :: LD2TLFF1 
INTEGER(KIND=JPIM),INTENT(IN)    :: KL0(NPROMA,NFLEVG,0:3) 
INTEGER(KIND=JPIM),INTENT(IN)    :: KLH0(NPROMA,NFLEVG,0:3)
REAL(KIND=JPRB)   ,INTENT(IN)    :: PDLO(NPROMA,NFLEVG,0:3)
REAL(KIND=JPRB)   ,INTENT(IN)    :: PCLO(NPROMA,NFLEVG,3,2)
REAL(KIND=JPRB)   ,INTENT(IN)    :: PCLOSLD(NPROMA,NFLEVG,3,2)
REAL(KIND=JPRB)   ,INTENT(IN)    :: PDLAT(NPROMA,NFLEVG)
REAL(KIND=JPRB)   ,INTENT(IN)    :: PCLA(NPROMA,NFLEVG,3)
REAL(KIND=JPRB)   ,INTENT(IN)    :: PCLASLD(NPROMA,NFLEVG,3)
REAL(KIND=JPRB)   ,INTENT(IN)    :: PDVER(NPROMA,NFLEVG)
REAL(KIND=JPRB)   ,INTENT(IN)    :: PVINTW(NPROMA,NFLEVG,3)
REAL(KIND=JPRB)   ,INTENT(IN)    :: PVINTWSLD(NPROMA,NFLEVG,3)
REAL(KIND=JPRB)   ,INTENT(IN)    :: PB1(NASLB1,NFLDSLB1)
REAL(KIND=JPRB)   ,INTENT(IN)    :: PB15(NASLB1,NFLDSLB15)
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PDP(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PUF(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PVF(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PTF(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PGFLF(NPROMA,NFLEVG,YGFL%NUMFLDS) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PCF(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PUFZ(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PVFZ(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PUF5(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PVF5(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PUFZ5(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PVFZ5(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PDLO5(NPROMA,NFLEVG,0:3) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PCLO5(NPROMA,NFLEVG,3,2) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PCLOSLD5(NPROMA,NFLEVG,3,2) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PDLAT5(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PCLA5(NPROMA,NFLEVG,3) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PCLASLD5(NPROMA,NFLEVG,3) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PDVER5(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PVINTW5(NPROMA,NFLEVG,3) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PVINTWSLD5(NPROMA,NFLEVG,3) 

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

REAL(KIND=JPRB) :: ZUF     (NPROMA,NFLEVG)
REAL(KIND=JPRB) :: ZVF     (NPROMA,NFLEVG)
REAL(KIND=JPRB) :: ZTF     (NPROMA,NFLEVG)
REAL(KIND=JPRB) :: ZUF5    (NPROMA,NFLEVG)
REAL(KIND=JPRB) :: ZVF5    (NPROMA,NFLEVG)
REAL(KIND=JPRB) :: ZDUM5   (NPROMA,NFLEVG)

! The array ZDUM5 receives interpolated values of '5' fields
! in those cases when they are never in fact going to be used.

INTEGER(KIND=JPIM) :: JLEV, JROF,JGFL

LOGICAL         :: LLADV5, LLSLHD_P, LLSLHD_GFL

REAL(KIND=JPRB) :: ZHOOK_HANDLE

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

#include "laidditl.intfb.h"
#include "laitlitl.intfb.h"
#include "laitre_gmv_tl.intfb.h"

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

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

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

!*       2.    ORIGIN POINT INTERPOLATIONS FOR GMV VARIABLES.
!              ----------------------------------------------

! * U-Momentum equation:

! --- part of the RHS requiring a "high order" interpolation:
LLADV5=.FALSE.
CALL LAITRE_GMV_TL(NASLB1,NPROMA,KST,KPROF,NFLEVG,NFLSA,NFLEN, &
 & LSLHD_W,LLADV5, &
 & KL0(1,1,0),PDLO,PCLO,PCLOSLD, &
 & PDLAT,PCLA,PCLASLD,PVINTW,PVINTWSLD, &
 & PDLO5,PCLO5,PCLOSLD5, &
 & PDLAT5,PCLA5,PCLASLD5,PVINTW5,PVINTWSLD5, &
 & PB1(1,MSLB1U9),PB15(1,MSLB1U95),PUF,PUF5)  

IF(NWLAG == 3) THEN
  ! --- save U in some cases:
  IF (LD2TLFF1) THEN
    ! Interpolate U at the origin point and use PUFZ
    ! to store the interpolated quantities.
    LLADV5=.FALSE.
    CALL LAITRE_GMV_TL(NASLB1,NPROMA,KST,KPROF,NFLEVG,NFLSA,NFLEN, &
     & LSLHD_W,LLADV5, &
     & KL0(1,1,0),PDLO,PCLO,PCLOSLD, &
     & PDLAT,PCLA,PCLASLD,PVINTW,PVINTWSLD, &
     & PDLO5,PCLO5,PCLOSLD5, &
     & PDLAT5,PCLA5,PCLASLD5,PVINTW5,PVINTWSLD5, &
     & PB1(1,MSLB1UR9),PB15(1,MSLB1UR95),PUFZ,PUFZ5)  
  ELSE
    ! Save PUF in case of refined treatment of
    ! Coriolis term and lagged physics in 2TL scheme:
    PUFZ(KST:KPROF,1:NFLEVG)=PUF(KST:KPROF,1:NFLEVG)
    PUFZ5(KST:KPROF,1:NFLEVG)=PUF5(KST:KPROF,1:NFLEVG)
  ENDIF

  ! --- part of the RHS requiring a trilinear interpolation:
  CALL LAITLITL(NASLB1,NPROMA,KST,KPROF,NFLEVG,NFLSA,NFLEN,&
   & PDLAT,PDLO(1,1,1),KL0(1,1,1),PDVER,&
   & PDLAT5,PDLO5(1,1,1),PDVER5,&
   & PB1(1,MSLB1U0),PB15(1,MSLB1U05),ZUF,ZUF5)  
  DO JLEV=1,NFLEVG
    DO JROF=KST,KPROF
      PUF(JROF,JLEV)=PUF(JROF,JLEV) +ZUF(JROF,JLEV)
      PUF5(JROF,JLEV)=PUF5(JROF,JLEV) +ZUF5(JROF,JLEV)
    ENDDO
  ENDDO
ENDIF

! * V-Momentum equation:

! --- part of the RHS requiring a "high order" interpolation:
LLADV5=.FALSE.
CALL LAITRE_GMV_TL(NASLB1,NPROMA,KST,KPROF,NFLEVG,NFLSA,NFLEN, &
 & LSLHD_W,LLADV5, &
 & KL0(1,1,0),PDLO,PCLO,PCLOSLD, &
 & PDLAT,PCLA,PCLASLD,PVINTW,PVINTWSLD, &
 & PDLO5,PCLO5,PCLOSLD5, &
 & PDLAT5,PCLA5,PCLASLD5,PVINTW5,PVINTWSLD5, &
 & PB1(1,MSLB1V9),PB15(1,MSLB1V95),PVF,PVF5)  

IF(NWLAG == 3) THEN
  ! --- save V in some cases:
  IF (LD2TLFF1) THEN
    ! Interpolate V at the origin point and use PVFZ
    ! to store the interpolated quantities.
    LLADV5=.FALSE.
    CALL LAITRE_GMV_TL(NASLB1,NPROMA,KST,KPROF,NFLEVG,NFLSA,NFLEN, &
     & LSLHD_W,LLADV5, &
     & KL0(1,1,0),PDLO,PCLO,PCLOSLD, &
     & PDLAT,PCLA,PCLASLD,PVINTW,PVINTWSLD, &
     & PDLO5,PCLO5,PCLOSLD5, &
     & PDLAT5,PCLA5,PCLASLD5,PVINTW5,PVINTWSLD5, &
     & PB1(1,MSLB1VR9),PB15(1,MSLB1VR95),PVFZ,PVFZ5)  
  ELSE
    ! Save PVF in case of refined treatment of
    ! Coriolis term and lagged physics in 2TL scheme:
    PVFZ(KST:KPROF,1:NFLEVG)=PVF(KST:KPROF,1:NFLEVG)
    PVFZ5(KST:KPROF,1:NFLEVG)=PVF5(KST:KPROF,1:NFLEVG)
  ENDIF

  ! --- part of the RHS requiring a trilinear interpolation:
  CALL LAITLITL(NASLB1,NPROMA,KST,KPROF,NFLEVG,NFLSA,NFLEN,&
   & PDLAT,PDLO(1,1,1),KL0(1,1,1),PDVER,&
   & PDLAT5,PDLO5(1,1,1),PDVER5,&
   & PB1(1,MSLB1V0),PB15(1,MSLB1V05),ZVF,ZVF5)  
  DO JLEV=1,NFLEVG
    DO JROF=KST,KPROF
      PVF(JROF,JLEV)=PVF(JROF,JLEV) +ZVF(JROF,JLEV)
      PVF5(JROF,JLEV)=PVF5(JROF,JLEV) +ZVF5(JROF,JLEV)
    ENDDO
  ENDDO
ENDIF

! * Temperature equation:

! --- part of the RHS requiring a "high order" interpolation:
LLADV5=.FALSE.
CALL LAITRE_GMV_TL(NASLB1,NPROMA,KST,KPROF,NFLEVG,NFLSA,NFLEN, &
 & LSLHD_T,LLADV5, &
 & KL0(1,1,0),PDLO,PCLO,PCLOSLD, &
 & PDLAT,PCLA,PCLASLD,PVINTW,PVINTWSLD, &
 & PDLO5,PCLO5,PCLOSLD5, &
 & PDLAT5,PCLA5,PCLASLD5,PVINTW5,PVINTWSLD5, &
 & PB1(1,MSLB1T9),PB15(1,MSLB1T95),PTF,ZDUM5)  

IF(NTLAG == 3) THEN
  ! --- part of the RHS requiring a trilinear interpolation:
  CALL LAITLITL(NASLB1,NPROMA,KST,KPROF,NFLEVG,NFLSA,NFLEN,&
   & PDLAT,PDLO(1,1,1),KL0(1,1,1),PDVER,&
   & PDLAT5,PDLO5(1,1,1),PDVER5,&
   & PB1(1,MSLB1T0),PB15(1,MSLB1T05),ZTF,ZDUM5)  
  DO JLEV=1,NFLEVG
    DO JROF=KST,KPROF
      PTF(JROF,JLEV)=PTF(JROF,JLEV) + ZTF(JROF,JLEV)
    ENDDO
  ENDDO
ENDIF

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

!*       3.    ORIGIN POINT INTERPOLATIONS FOR GFL VARIABLES.
!              ----------------------------------------------

! * The interpolations are tri-dimensional ones.

DO JGFL=1,YGFL%NUMFLDS
  IF(YGFLC(JGFL)%LADV) THEN
    ! --- part of the RHS requiring a "high order" interpolation:
    !     (LAITRE_GFL_TL = LAITRE_GMV_TL for the time being)
    LLADV5=YGFLC(JGFL)%LADV5
    LLSLHD_GFL=( YGFLC(JGFL)%CSLINT == 'LAITRI(SLD) ' )
    CALL LAITRE_GMV_TL(NASLB1,NPROMA,KST,KPROF,NFLEVG,NFLSA,NFLEN, &
     & LLSLHD_GFL,LLADV5, &
     & KL0(1,1,0),PDLO,PCLO,PCLOSLD, &
     & PDLAT,PCLA,PCLASLD,PVINTW,PVINTWSLD, &
     & PDLO5,PCLO5,PCLOSLD5, &
     & PDLAT5,PCLA5,PCLASLD5,PVINTW5,PVINTWSLD5, &
     & PB1(1,MSLB1GFL9+(YGFLC(JGFL)%MP_SL1-1)*(NFLEN-NFLSA+1)), &
     & PB15(1,MSLB1GFL95+(YGFLC(JGFL)%MP_SL1-1)*(NFLEN-NFLSA+1)),&
     & PGFLF(1,1,JGFL),ZDUM5)  
  ENDIF
ENDDO

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

!*       4.    ORIGIN POINT INTERPOLATIONS FOR GMVS VARIABLES.
!              -----------------------------------------------

! The interpolations are tri-dimensional and 2D ones.

! * Continuity equation:

! --- 3D part of the RHS requiring a "high order" interpolation:
IF(NVLAG == 2) THEN
  LLADV5=.FALSE.
  LLSLHD_P=.FALSE.
  CALL LAITRE_GMV_TL(NASLB1,NPROMA,KST,KPROF,NFLEVG,NFLSA,NFLEN, &
   & LLSLHD_P,LLADV5, &
   & KL0(1,1,0),PDLO,PCLO,PCLOSLD, &
   & PDLAT,PCLA,PCLASLD,PVINTW,PVINTWSLD, &
   & PDLO5,PCLO5,PCLOSLD5, &
   & PDLAT5,PCLA5,PCLASLD5,PVINTW5,PVINTWSLD5, &
   & PB1(1,MSLB1C9),PB15(1,MSLB1C95),PCF,ZDUM5)  
ENDIF

! --- 3D part of the RHS requiring a trilinear interpolation:
IF(NVLAG == 3) THEN
  CALL LAITLITL(NASLB1,NPROMA,KST,KPROF,NFLEVG,NFLSA,NFLEN,&
   & PDLAT,PDLO(1,1,1),KL0(1,1,1),PDVER,&
   & PDLAT5,PDLO5(1,1,1),PDVER5,&
   & PB1(1,MSLB1C9),PB15(1,MSLB1C95),PCF,ZDUM5)  
ENDIF

! --- 2D part of the RHS requiring a "high order" interpolation:
CALL LAIDDITL(NASLB1,NPROMA,KST,KPROF,NFLEVG,NFLSA,NFLEN,&
 & PCLA,PDLO,PCLO,PCLA5,PDLO5,PCLO5,KLH0(1,1,0),&
 & PB1(1,MSLB1SP9),PB15(1,MSLB1SP95),PDP,ZDUM5)  

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

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

