!OPTION! -pvctl noouterunroll -pvctl noouterstrip
SUBROUTINE LARCINBAD(KSTGLO,KST,KPROF,LD2TLFF1,KDIM,KDEP,KLOCK,KL0,KLH0,&
 & PDLO,PCLO,PCLOSLD,PDLAT,PCLA,PCLASLD,PDVER,PVINTW,PVINTWSLD,PB1,PB15,&
 & PINC,KINC,KDIM1,KDIM2,&
 & PDP,PUF,PVF,PTF,PGFLF,PCF,PUFZ,PVFZ,&
 & PDLO5,PCLO5,PCLOSLD5,PDLAT5,PCLA5,PCLASLD5,PDVER5,PVINTW5,PVINTWSLD5)

!**** *LARCINBAD - semi-LAgrangian scheme:   (adjoint version - Part B)

!     Purpose.
!     --------
!       - adjoints of interpolations at origin point.

!       Second part of from 'old' LAPINEAD

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

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

!          KSTGLO  - global offset into nproma buffer.
!          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.
!          KDIM    - Number of independent updates
!          KDEP    - indication of the interpolation stencil latitudial
!                    dependences (used for LVECADIN=.T. option in ALADIN)
!          KLOCK   - ??? (used for OpenMP purposes).
!          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).
!          PDP     - Interpolated 2D term at O for continuity equation.
!          PUF     - Interpolated quantity at O in the U-wind equation.
!          PVF     - Interpolated quantity at O in the V-wind equation.
!          PTF     - Interpolated quantity at O in the temperature equation.
!          PGFLF   - Interpolated quantity at O - GFL
!          PCF     - Interpolated 3D quantity at O in the continuity equation.
!          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.
!          KDIM1,KDIM2 - dimensions of KINC, PINC
!          KINC    - addresses of interpolation increments in global buffer
!          PINC    - interpolation increments to global buffer (vector only)

!        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 LAPINEBAD
!        Calls: see below.

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

!     Author.
!     -------
!        D. Salmond (ECMWF)

!     Modifications.
!     --------------
!      Original: 05/02/05
!      D.Salmond   08-Feb-2005 New LARCINBAD
!      C.Temperton 05/03/03: Re-use previous results of LARCHE
!      C.Temperton 05/03/07: Re-use previous results of LASCAW
!      F. Vana 06/12/12: - LRPLANE=.T. (special treatment for LVECADIN=.T.)
!                        - NEC-SX optimization
!      Modified 19-Mar-2007 K. Yessad: reorder according to LARCINB.
!      F. Vana 17-Jul-2007 - cleaning
!      E.Holm      07/06/27: Option to advect without wind increments (LADV5)
!      NEC      11-Dec-2007 Optimizations
!      G.Mozdzynski 21-Feb-2008: Use of locks made dynamic for performance
!      F. Vana 13-Aug-2008 - weights driven interpolation, unification
!                            of LAM and spherical interpolation for vect.
!      K. Yessad Nov 2008: rationalisation of dummy argument interfaces
!      F. Vana : 11-Dec-2008 OpenMP for vector platforms
!      E. Sevault, R. El Khatib & NEC  06-May-2009 : SX9 portability fix : add
!            ",VOB" to VOVERTAKE directives (gather operations handled 
!            differently on SX8 and SX9)
!      E. Sevault 18-May-2009 : SX9 compiler workaround : optimisations 
!            "outerunroll" and "outerstrip" manually switched off to prevent
!            unexpected numerical variations. Note that this workaround may
!            be irrelevent when the source code of this subroutine is deeply
!            re-written.
!     ------------------------------------------------------------------

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 ,MSLB1C0  ,MSLB1U9  ,MSLB1V9  ,&
 & MSLB1T9  ,MSLB1GFL9,MSLB1C9  ,MSLB1U0  ,MSLB1V0  ,MSLB1T0  ,RPARSL1
USE PTRSLB15 , ONLY : MSLB1UR95,MSLB1VR95,MSLB1C05 ,MSLB1U95 ,MSLB1V95 ,&
 & MSLB1T95 ,MSLB1GFL95,MSLB1C95 ,MSLB1U05 ,MSLB1V05 ,MSLB1T05
USE YOMSLREP , ONLY : LSLADREP, MASK_SLTOT, NADCORE, LSLCORE, LVECADIN
USE YOMVAR   , ONLY : NSIM4D
USE YOMLUN   , ONLY : NULERR   ,NULOUT
USE YOMCT0   , ONLY : LRPLANE  ,NPROC
USE YOMMASK  , ONLY : MASK_SL1 ,LSLONDEM
USE YOMSEP   , ONLY : NVSEPC
USE OML_MOD, ONLY : OML_INCR_EVENT, OML_OMP, OML_WAIT_EVENT

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

IMPLICIT NONE

INTEGER(KIND=JPIM),INTENT(IN)    :: KSTGLO 
INTEGER(KIND=JPIM),INTENT(IN)    :: KST 
INTEGER(KIND=JPIM),INTENT(IN)    :: KPROF 
LOGICAL           ,INTENT(IN)    :: LD2TLFF1 
INTEGER(KIND=JPIM),INTENT(IN)    :: KDIM 
INTEGER(KIND=JPIM),INTENT(IN)    :: KDEP(NPROMA,NFLEVG)
INTEGER(KIND=JPIM),INTENT(INOUT) :: KLOCK(:)
INTEGER(KIND=JPIM),INTENT(IN)    :: KL0(NPROMA,NFLEVG,0:3)
INTEGER(KIND=JPIM),INTENT(IN)    :: KLH0(NPROMA,NFLEVG,0:3)
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PDLO(NPROMA,NFLEVG,0:3) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PCLO(NPROMA,NFLEVG,3,2) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PCLOSLD(NPROMA,NFLEVG,3,2) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PDLAT(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PCLA(NPROMA,NFLEVG,3) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PCLASLD(NPROMA,NFLEVG,3) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PDVER(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PVINTW(NPROMA,NFLEVG,3) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PVINTWSLD(NPROMA,NFLEVG,3)
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PB1(NASLB1,NFLDSLB1)
REAL(KIND=JPRB)   ,INTENT(IN)    :: PB15(NASLB1,NFLDSLB15)
INTEGER(KIND=JPIM),INTENT(OUT)   :: KINC(KDIM1,KDIM2)
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PINC(KDIM1,KDIM2)
INTEGER(KIND=JPIM),INTENT(IN)    :: KDIM1 
INTEGER(KIND=JPIM),INTENT(IN)    :: KDIM2 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: 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(INOUT) :: PGFLF(NPROMA,NFLEVG,YGFL%NUMFLDS) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PCF(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PUFZ(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PVFZ(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)

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

INTEGER(KIND=JPIM) :: ISIGN(NFLDSLB1)

INTEGER(KIND=JPIM) :: IENOUGH, ISEP, &
 & JLEV, JROF, INCA, JFLD, JGFL, IOFF, JSTAR, IPOI, ILOCK

LOGICAL         :: LLADV5, LLSLHD_P, LLSLHD_GFL

REAL(KIND=JPRB),ALLOCATABLE :: ZSIGN8 (:,:,:,:)
REAL(KIND=JPRB),ALLOCATABLE :: ZSIGN12(:,:,:,:)
REAL(KIND=JPRB),ALLOCATABLE :: ZSIGN32(:,:,:,:)

INTEGER(KIND=JPIM),ALLOCATABLE :: IMAP8 (:,:,:)
INTEGER(KIND=JPIM),ALLOCATABLE :: IMAP12(:,:,:)
INTEGER(KIND=JPIM),ALLOCATABLE :: IMAP32(:,:,:)
REAL(KIND=JPRB) :: ZHOOK_HANDLE
INTEGER(KIND=JPIM) :: IERR

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

#include "abor1.intfb.h"
#include "laiddi_init.intfb.h"
#include "laidditlad.intfb.h"
#include "laitli_init.intfb.h"
#include "laitlitlad.intfb.h"
#include "laitri_init.intfb.h"
#include "laitre_gmv_ad.intfb.h"

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

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

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

!*       1.    PRELIMINARY INITIALISATIONS.
!              ----------------------------

IERR=0
DO JFLD=1,NFLDSLB1
  IF( ABS(RPARSL1(JFLD)) ==  1.0_JPRB )THEN
    ISIGN(JFLD)=INT(1.5_JPRB - 0.5_JPRB * RPARSL1(JFLD))
  ELSE
    IERR=IERR+1
  ENDIF
ENDDO
IF (IERR > 0) CALL ABOR1('LARCINBAD: RPARSL1 INVALID SIGN')

! * Computation of ISEP
ISEP=NVSEPC               ! cubic interpolations
IENOUGH=4

IF( LSLADREP )THEN
  ALLOCATE(ZSIGN8 (NPROMA,8 ,NFLEVG,2))
  ALLOCATE(IMAP8  (NPROMA,8 ,NFLEVG))
  ALLOCATE(ZSIGN12(NPROMA,12,NFLEVG,2))
  ALLOCATE(IMAP12 (NPROMA,12,NFLEVG))
  ALLOCATE(ZSIGN32(NPROMA,32,NFLEVG,2))
  ALLOCATE(IMAP32 (NPROMA,32,NFLEVG))
  CALL LAIDDI_INIT(NASLB1,NPROMA,KST,KPROF,NFLEVG,KLH0(1,1,0),IMAP12,ZSIGN12)
  CALL LAITLI_INIT(NASLB1,NPROMA,KST,KPROF,NFLEVG,KL0(1,1,0),IMAP8,ZSIGN8)
  CALL LAITRI_INIT(NASLB1,NPROMA,KST,KPROF,NFLEVG,KL0(1,1,0),IMAP32,ZSIGN32)
ELSE
  ALLOCATE(ZSIGN8 (1,1,1,2))
  ALLOCATE(IMAP8  (1,1,1))
  ALLOCATE(ZSIGN12(1,1,1,2))
  ALLOCATE(IMAP12 (1,1,1))
  ALLOCATE(ZSIGN32(1,1,1,2))
  ALLOCATE(IMAP32 (1,1,1))
ENDIF

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

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

INCA=1
ILOCK=0

! * U-Momentum equation:

IF(NWLAG == 3) THEN

  ! --- part of the RHS requiring a trilinear interpolation:
  ILOCK=ILOCK+1
  IF (OML_OMP().AND..NOT.LVECADIN ) CALL OML_WAIT_EVENT(KSTGLO,KLOCK(ILOCK))
  CALL LAITLITLAD(NASLB1,NPROMA,KST,KPROF,NFLEVG,NFLSA,NFLEN,&
   & MSLB1U0,ISEP,IMAP8,ZSIGN8(1,1,1,ISIGN(MSLB1U0)),&
   & LVECADIN,PDLAT,PDLO(1,1,1),KL0(1,1,1),PDVER,&
   & PDLAT5,PDLO5(1,1,1),PDVER5,&
   & KINC(INCA,1),PINC(INCA,1),KDIM,PB1(1,MSLB1U0),PB15(1,MSLB1U05),PUF)  
  INCA=INCA+8
  IF (OML_OMP().AND..NOT.LVECADIN ) CALL OML_INCR_EVENT(KPROF,KLOCK(ILOCK))

  ! --- save U in some cases:
  IF (LD2TLFF1) THEN
    ! Interpolate U at the origin point and use PUFZ
    ! to store the interpolated quantities.
    ILOCK=ILOCK+1
    IF (OML_OMP().AND..NOT.LVECADIN ) CALL OML_WAIT_EVENT(KSTGLO,KLOCK(ILOCK))
    LLADV5=.FALSE.
    CALL LAITRE_GMV_AD(NASLB1,NPROMA,KST,KPROF,NFLEVG,NFLSA,&
     & NFLEN,MSLB1UR9,ISEP,IMAP32,ZSIGN32(1,1,1,ISIGN(MSLB1UR9)),&
     & KDEP,LVECADIN,LRPLANE,LSLHD_W,LLADV5,&
     & PDLAT,PCLA,PCLASLD,PDLO,PCLO,PCLOSLD,&
     & PDLAT5,PCLA5,PCLASLD5,PDLO5,PCLO5,PCLOSLD5,&
     & KL0(1,1,0),PVINTW,PVINTWSLD,PVINTW5,PVINTWSLD5,&
     & KINC(INCA,1),PINC(INCA,1),KDIM,PB1(1,MSLB1UR9),PB15(1,MSLB1UR95),PUFZ)  
    INCA=INCA+32
    IF (OML_OMP().AND..NOT.LVECADIN ) CALL OML_INCR_EVENT(KPROF,KLOCK(ILOCK))
  ELSE
    ! Save PUF in case of refined treatment of
    ! Coriolis term and lagged physics in 2TL scheme:
    PUF(KST:KPROF,1:NFLEVG)=&
     & PUF(KST:KPROF,1:NFLEVG)+PUFZ(KST:KPROF,1:NFLEVG)  
  ENDIF

ENDIF

! --- part of the RHS requiring a "high order" interpolation:
ILOCK=ILOCK+1
IF (OML_OMP().AND..NOT.LVECADIN ) CALL OML_WAIT_EVENT(KSTGLO,KLOCK(ILOCK))
LLADV5=.FALSE.
CALL LAITRE_GMV_AD(NASLB1,NPROMA,KST,KPROF,NFLEVG,NFLSA,&
 & NFLEN,MSLB1U9,ISEP,IMAP32,ZSIGN32(1,1,1,ISIGN(MSLB1U9)),&
 & KDEP,LVECADIN,LRPLANE,LSLHD_W,LLADV5,&
 & PDLAT,PCLA,PCLASLD,PDLO,PCLO,PCLOSLD,&
 & PDLAT5,PCLA5,PCLASLD5,PDLO5,PCLO5,PCLOSLD5,&
 & KL0(1,1,0),PVINTW,PVINTWSLD,PVINTW5,PVINTWSLD5,&
 & KINC(INCA,1),PINC(INCA,1),KDIM,PB1(1,MSLB1U9),PB15(1,MSLB1U95),PUF)  
INCA=INCA+32
IF (OML_OMP().AND..NOT.LVECADIN ) CALL OML_INCR_EVENT(KPROF,KLOCK(ILOCK))

! * V-Momentum equation:

IF(NWLAG == 3) THEN

  ! --- part of the RHS requiring a trilinear interpolation:
  ILOCK=ILOCK+1
  IF (OML_OMP().AND..NOT.LVECADIN ) CALL OML_WAIT_EVENT(KSTGLO,KLOCK(ILOCK))
  CALL LAITLITLAD(NASLB1,NPROMA,KST,KPROF,NFLEVG,NFLSA,NFLEN,&
   & MSLB1V0,ISEP,IMAP8,ZSIGN8(1,1,1,ISIGN(MSLB1V0)),&
   & LVECADIN,PDLAT,PDLO(1,1,1),KL0(1,1,1),PDVER,&
   & PDLAT5,PDLO5(1,1,1),PDVER5,&
   & KINC(INCA,1),PINC(INCA,1),KDIM,PB1(1,MSLB1V0),PB15(1,MSLB1V05),PVF)  
  INCA=INCA+8
  IF (OML_OMP().AND..NOT.LVECADIN ) CALL OML_INCR_EVENT(KPROF,KLOCK(ILOCK))

  ! --- save V in some cases:
  IF (LD2TLFF1) THEN
    ! Interpolate V at the origin point and use PVFZ
    ! to store the interpolated quantities.
    ILOCK=ILOCK+1
    IF (OML_OMP().AND..NOT.LVECADIN ) CALL OML_WAIT_EVENT(KSTGLO,KLOCK(ILOCK))
    LLADV5=.FALSE.
    CALL LAITRE_GMV_AD(NASLB1,NPROMA,KST,KPROF,NFLEVG,NFLSA,&
     & NFLEN,MSLB1VR9,ISEP,IMAP32,ZSIGN32(1,1,1,ISIGN(MSLB1VR9)),&
     & KDEP,LVECADIN,LRPLANE,LSLHD_W,LLADV5,&
     & PDLAT,PCLA,PCLASLD,PDLO,PCLO,PCLOSLD,&
     & PDLAT5,PCLA5,PCLASLD5,PDLO5,PCLO5,PCLOSLD5,&
     & KL0(1,1,0),PVINTW,PVINTWSLD,PVINTW5,PVINTWSLD5,&
     & KINC(INCA,1),PINC(INCA,1),KDIM,PB1(1,MSLB1VR9),PB15(1,MSLB1VR95),PVFZ)  
    INCA=INCA+32
    IF (OML_OMP().AND..NOT.LVECADIN ) CALL OML_INCR_EVENT(KPROF,KLOCK(ILOCK))
  ELSE
    ! Save PVF in case of refined treatment of
    ! Coriolis term and lagged physics in 2TL scheme:
    PVF(KST:KPROF,1:NFLEVG)=&
     & PVF(KST:KPROF,1:NFLEVG)+PVFZ(KST:KPROF,1:NFLEVG)  
  ENDIF

ENDIF

! --- part of the RHS requiring a "high order" interpolation:
ILOCK=ILOCK+1
IF (OML_OMP().AND..NOT.LVECADIN ) CALL OML_WAIT_EVENT(KSTGLO,KLOCK(ILOCK))
LLADV5=.FALSE.
CALL LAITRE_GMV_AD(NASLB1,NPROMA,KST,KPROF,NFLEVG,NFLSA,&
 & NFLEN,MSLB1V9,ISEP,IMAP32,ZSIGN32(1,1,1,ISIGN(MSLB1V9)),&
 & KDEP,LVECADIN,LRPLANE,LSLHD_W,LLADV5,&
 & PDLAT,PCLA,PCLASLD,PDLO,PCLO,PCLOSLD,&
 & PDLAT5,PCLA5,PCLASLD5,PDLO5,PCLO5,PCLOSLD5,&
 & KL0(1,1,0),PVINTW,PVINTWSLD,PVINTW5,PVINTWSLD5,&
 & KINC(INCA,1),PINC(INCA,1),KDIM,PB1(1,MSLB1V9),PB15(1,MSLB1V95),PVF)  
INCA=INCA+32
IF (OML_OMP().AND..NOT.LVECADIN ) CALL OML_INCR_EVENT(KPROF,KLOCK(ILOCK))

! * Temperature equation:

IF(NTLAG == 3) THEN
  ! --- part of the RHS requiring a trilinear interpolation:
  ILOCK=ILOCK+1
  IF (OML_OMP().AND..NOT.LVECADIN ) CALL OML_WAIT_EVENT(KSTGLO,KLOCK(ILOCK))
  CALL LAITLITLAD(NASLB1,NPROMA,KST,KPROF,NFLEVG,NFLSA,NFLEN,&
   & MSLB1T0,ISEP,IMAP8,ZSIGN8(1,1,1,ISIGN(MSLB1T0)),&
   & LVECADIN,PDLAT,PDLO(1,1,1),KL0(1,1,1),PDVER,&
   & PDLAT5,PDLO5(1,1,1),PDVER5,&
   & KINC(INCA,1),PINC(INCA,1),KDIM,PB1(1,MSLB1T0),PB15(1,MSLB1T05),PTF)  
  INCA=INCA+8
  IF (OML_OMP().AND..NOT.LVECADIN ) CALL OML_INCR_EVENT(KPROF,KLOCK(ILOCK))
ENDIF

! --- part of the RHS requiring a "high order" interpolation:
ILOCK=ILOCK+1
IF (OML_OMP().AND..NOT.LVECADIN ) CALL OML_WAIT_EVENT(KSTGLO,KLOCK(ILOCK))
LLADV5=.FALSE.
CALL LAITRE_GMV_AD(NASLB1,NPROMA,KST,KPROF,NFLEVG,NFLSA,&
 & NFLEN,MSLB1T9,ISEP,IMAP32,ZSIGN32(1,1,1,ISIGN(MSLB1T9)),&
 & KDEP,LVECADIN,LRPLANE,LSLHD_T,LLADV5,&
 & PDLAT,PCLA,PCLASLD,PDLO,PCLO,PCLOSLD,&
 & PDLAT5,PCLA5,PCLASLD5,PDLO5,PCLO5,PCLOSLD5,&
 & KL0(1,1,0),PVINTW,PVINTWSLD,PVINTW5,PVINTWSLD5,&
 & KINC(INCA,1),PINC(INCA,1),KDIM,PB1(1,MSLB1T9),PB15(1,MSLB1T95),PTF) 
INCA=INCA+32
IF (OML_OMP().AND..NOT.LVECADIN ) CALL OML_INCR_EVENT(KPROF,KLOCK(ILOCK))

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

!*       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_AD = LAITRE_GMV_AD for the time being)
    IPOI=(YGFLC(JGFL)%MP_SL1-1)*(NFLEVG+2)
    LLADV5=YGFLC(JGFL)%LADV5
    LLSLHD_GFL=( YGFLC(JGFL)%CSLINT == 'LAITRI(SLD) ' )
    ILOCK=ILOCK+1
    IF (OML_OMP().AND..NOT.LVECADIN ) CALL OML_WAIT_EVENT(KSTGLO,KLOCK(ILOCK))
    CALL LAITRE_GMV_AD(NASLB1,NPROMA,KST,KPROF,NFLEVG,NFLSA,&
     & NFLEN,MSLB1GFL9+IPOI,ISEP,IMAP32,&
     & ZSIGN32(1,1,1,ISIGN(MSLB1GFL9+IPOI)),&
     & KDEP,LVECADIN,LRPLANE,LLSLHD_GFL,LLADV5,&
     & PDLAT,PCLA,PCLASLD,PDLO,PCLO,PCLOSLD,&
     & PDLAT5,PCLA5,PCLASLD5,PDLO5,PCLO5,PCLOSLD5,&
     & KL0(1,1,0),PVINTW,PVINTWSLD,PVINTW5,PVINTWSLD5,&
     & KINC(INCA,1),PINC(INCA,1),KDIM,&
     & 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))  
    INCA=INCA+32
    IF (OML_OMP().AND..NOT.LVECADIN ) CALL OML_INCR_EVENT(KPROF,KLOCK(ILOCK))
  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:

ILOCK=ILOCK+1
IF (OML_OMP().AND..NOT.LVECADIN ) CALL OML_WAIT_EVENT(KSTGLO,KLOCK(ILOCK))

IF(NVLAG == 2) THEN
  LLADV5=.FALSE.
  LLSLHD_P=.FALSE. ! SLHD should not be applied to cont. equation
  CALL LAITRE_GMV_AD(NASLB1,NPROMA,KST,KPROF,NFLEVG,NFLSA,&
   & NFLEN,MSLB1C9,ISEP,IMAP32,ZSIGN32(1,1,1,ISIGN(MSLB1C9)),&
   & KDEP,LVECADIN,LRPLANE,LLSLHD_P,LLADV5,&
   & PDLAT,PCLA,PCLASLD,PDLO,PCLO,PCLOSLD,&
   & PDLAT5,PCLA5,PCLASLD5,PDLO5,PCLO5,PCLOSLD5,&
   & KL0(1,1,0),PVINTW,PVINTWSLD,PVINTW5,PVINTWSLD5,&
   & KINC(INCA,1),PINC(INCA,1),KDIM,PB1(1,MSLB1C9),PB15(1,MSLB1C95),PCF)  
  INCA=INCA+32
ENDIF

! --- 3D part of the RHS requiring a trilinear interpolation:
IF(NVLAG == 3) THEN
  CALL LAITLITLAD(NASLB1,NPROMA,KST,KPROF,NFLEVG,NFLSA,NFLEN,&
   & MSLB1C9,ISEP,IMAP8,ZSIGN8(1,1,1,ISIGN(MSLB1C9)),&
   & LVECADIN,PDLAT,PDLO(1,1,1),KL0(1,1,1),PDVER,&
   & PDLAT5,PDLO5(1,1,1),PDVER5,&
   & KINC(INCA,1),PINC(INCA,1),KDIM,PB1(1,MSLB1C9),PB15(1,MSLB1C95),PCF)  
  INCA=INCA+8
ENDIF

IF (OML_OMP().AND..NOT.LVECADIN ) CALL OML_INCR_EVENT(KPROF,KLOCK(ILOCK))

! --- 2D part of the RHS requiring a "high order" interpolation:
! ky: MSLB1SP9 and MSLB1SP95 used in the TL code, but MSLB1C0 and MSLB1C05
!     used in the AD code => to be checked.
ILOCK=ILOCK+1
IF (OML_OMP().AND..NOT.LVECADIN ) CALL OML_WAIT_EVENT(KSTGLO,KLOCK(ILOCK))
CALL LAIDDITLAD(NASLB1,NPROMA,KST,KPROF,NFLEVG,NFLSA,NFLEN,&
 & MSLB1C0,ISEP,IMAP12,ZSIGN12(1,1,1,ISIGN(MSLB1C0)),&
 & KDEP,LVECADIN,LRPLANE,PCLA,PDLO,PCLO,PCLA5,PDLO5,PCLO5,&
 & KLH0(1,1,0),KINC(INCA,1),PINC(INCA,1),KDIM,PB1(1,MSLB1C0),PB15(1,MSLB1C05),PDP)  
INCA=INCA+12
IF (OML_OMP().AND..NOT.LVECADIN ) CALL OML_INCR_EVENT(KPROF,KLOCK(ILOCK))

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

!*       5.    ADDITIONAL TASKS.
!              -----------------

IF (.NOT.LVECADIN) THEN

  IF( ILOCK > SIZE(KLOCK) )THEN
    WRITE(NULOUT,'("LARCINBAD: ILOCK > SIZE(KLOCK), ILOCK=",I2," SIZE(KLOCK)=",I2)')&
     & ILOCK,SIZE(KLOCK)
    CALL ABOR1('LARCINBAD: PLEASE INCREASE JP_LOCKS IN CALL_SL_AD')
  ENDIF

ELSE 

  INCA=INCA-1

  IF(KDIM  /=  INCA) THEN
    WRITE(NULERR,*) "KDIM,INCA=",KDIM,INCA
    DO JGFL=1,YGFL%NUMFLDS
      WRITE(NULERR,*) "JGFL,YGFLC=",JGFL,YGFLC(JGFL)%LADV
    ENDDO
    CALL ABOR1('LARCINBAD: KDIM /= INCA')
  ENDIF
  
ENDIF

IF( .NOT.LSLADREP .AND. NSIM4D == 0 .AND. LSLONDEM .AND. NPROC > 1)THEN
  
  DO JLEV=1,NFLEVG
!OCL NOVREC
    DO JROF=KST,KPROF
      IOFF=MOD(KL0(JROF,JLEV,0),NASLB1)+1
      MASK_SL1(IOFF)=1
      IOFF=MOD(KL0(JROF,JLEV,0)+1,NASLB1)+1
      MASK_SL1(IOFF)=1
      IOFF=MOD(KL0(JROF,JLEV,1)-1,NASLB1)+1
      MASK_SL1(IOFF)=1
      IOFF=MOD(KL0(JROF,JLEV,1),NASLB1)+1
      MASK_SL1(IOFF)=1
      IOFF=MOD(KL0(JROF,JLEV,1)+1,NASLB1)+1
      MASK_SL1(IOFF)=1
      IOFF=MOD(KL0(JROF,JLEV,1)+2,NASLB1)+1
      MASK_SL1(IOFF)=1
      IOFF=MOD(KL0(JROF,JLEV,2)-1,NASLB1)+1
      MASK_SL1(IOFF)=1
      IOFF=MOD(KL0(JROF,JLEV,2),NASLB1)+1
      MASK_SL1(IOFF)=1
      IOFF=MOD(KL0(JROF,JLEV,2)+1,NASLB1)+1
      MASK_SL1(IOFF)=1
      IOFF=MOD(KL0(JROF,JLEV,2)+2,NASLB1)+1
      MASK_SL1(IOFF)=1
      IOFF=MOD(KL0(JROF,JLEV,3),NASLB1)+1
      MASK_SL1(IOFF)=1
      IOFF=MOD(KL0(JROF,JLEV,3)+1,NASLB1)+1
      MASK_SL1(IOFF)=1
    ENDDO
  ENDDO

ENDIF

IF( LSLADREP .AND. NSIM4D == 0 .AND. NPROC > 1  )THEN
  DO JLEV=1,NFLEVG
    DO JSTAR=1,32
!OCL NOVREC
      DO JROF=KST,KPROF
        IOFF=MOD(IMAP32(JROF,JSTAR,JLEV)-1,NASLB1)+1
        IF( LSLCORE(IOFF) )THEN
          ! NSLCORE POINT HAS BEEN UPDATED
          MASK_SLTOT(NADCORE(KSTGLO+JROF-1))=1
        ENDIF
      ENDDO
    ENDDO
  ENDDO
ENDIF

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

!*       6.    DESALLOCATIONS.
!              ---------------

IF(ALLOCATED(ZSIGN8 )) DEALLOCATE(ZSIGN8 )
IF(ALLOCATED(ZSIGN12)) DEALLOCATE(ZSIGN12)
IF(ALLOCATED(ZSIGN32)) DEALLOCATE(ZSIGN32)
IF(ALLOCATED(IMAP8  )) DEALLOCATE(IMAP8  )
IF(ALLOCATED(IMAP12 )) DEALLOCATE(IMAP12 )
IF(ALLOCATED(IMAP32 )) DEALLOCATE(IMAP32 )

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

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