#ifdef RS6K
@PROCESS NOCHECK
#endif
SUBROUTINE LARCINAAD(KDIM,KSTGLO,KST,KPROF, &
 & KSTABUF,LDSLHD,LDSLHDQUAD,KTIP,KROT,LDPLANE,LDOCK_UP,PLSDEPI,&
 & PCOLON,PSILON,PGEMU,PGSQM2,PGECLO,PGESLO,&
 & PCOSCO,PSINCO,PSINLA,PCOPHI,PLEV,&
 & PCOSCO5,PSINCO5,PSINLA5,PCOPHI5,PLEV5,&
 & PKAPPA,PKAPPA5,PURL0,PVRL0,PWRL0,PURL05,PVRL05,PWRL05,&
 & KVSEPC,KVSEPL,KLOCK, &
 & PINC,KINC,KDIM1,KDIM2,&
 & PLON,PLAT,PO,PQ,&
 & PUF0,PVF0,PWF0,&
 & PLON5,PLAT5,&
 & KL0,PDLO,PCLO,PCLOSLD,PDLAT,PCLA,PCLASLD,PDVER,PVINTW,PVINTWSLD,&
 & PDLO5,PDLAT5,PDVER5)  

!**** *LARCINAAD - semi-LAgrangian scheme:   (adjoint version - Part A)
!                 Research of the Coordinates (of the medium or origin
!                 point) and INterpolations.

!     Purpose.
!     --------
!       Computes the longitude and latitude of the interpolation
!       point from its cartesian coordinates.
!       Then computes the vector displacement matrix
!                        I po pq I
!                        I       I
!                        I-pq po I
!       from the interpolation point to the grid point.
!       At last determines the interpolation grid:
!       - computation of the latitude and the longitude of the
!         point situated at the upper left corner of the 16 points
!         square, and of the interpolation point.
!       - interpolations.

!       First part of from 'old' LARCINAD


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

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

!          KDIM    - Number of independent updates.
!          KSTGLO  - global offset into nproma buffer.
!          KST     - first element of arrays where computations are performed.
!          KPROF   - depth of work.
!          KSTABUF - for a latitude IGL, KSTABUF(IGL) is the
!                    address of the element corresponding to
!                    (ILON=1,IGL) in the NPROMA arrays.
!          LDSLHD  - key activating SLHD weights precomputation
!          LDSLHDQUAD - key activating quadratic weights precomputation
!          KTIP    - switch :
!                    KTIP=1: interpolations for wind to find trajectory.
!                    KTIP=3: origin point interp. (In this case we only
!                    do the adjoints of LASCAW and LARCHE, not of the
!                    interpolations themselves, which are done in LARCINBAD.)
!          KROT    - KROT=1: computation of the elements po and pq
!                    of the wind displacement matrix.
!                    KROT=0: no computation.
!          LDPLANE - switch: .T. = plane geometry; .F. = spherical geometry.
!          LDOCK_UP- ???
!          PLSDEPI - (Number of points by latitude) / (2 * PI) .
!          PCOLON  - cosine of the g.p. longitude on the computational sphere.
!          PSILON  - sine of the g.p. longitude on the computational sphere.
!          PGEMU   - sine of the grid-point geographical latitude.
!          PGSQM2  - cosine of the grid-point geographical latitude.
!          PGECLO  - cosine of the grid-point geographical longitude.
!          PGESLO  - sine of the grid-point geographical longitude.
!          PCOSCO  - cos(Longitude-Longitude(grid-point))*cos(Latitude)
!                    of the interpolation point (geographical longitude
!                    and latitude).
!                    ! if LDPLANE: x - coordinate (fractional system).
!          PSINCO  - sin(Longitude-Longitude(grid-point))*cos(Latitude)
!                    of the interpolation point (geographical longitude
!                    and latitude).
!                    ! if LDPLANE: y - coordinate (fractional system).
!          PSINLA  - sine of the interpolation point geographical latitude.
!          PCOPHI  - cosine of the geographical angle between the
!                    interpolation point and the grid-point.
!          PLEV    - vertical coordinate of the interpolation point.
!          PCOSCO5 - cf. PCOSCO (trajectory)
!          PSINCO5 - cf. PSINCO (trajectory)
!          PSINLA5 - cf. PSINLA (trajectory)
!          PCOPHI5 - cf. PCOPHI (trajectory)
!          PLEV5   - cf. PLEV (trajectory)
!          PKAPPA  - kappa function ("coefficient of SLHD") based on the
!                    rescaled horizontal deformation of the flow evaluated
!                    at instant "t" for the final point F
!          PKAPPA5 - cf. PKAPPA (trajectory)
!          PURL0   - U-component of the wind.
!          PVRL0   - V-component of the wind.
!          PWRL0   - "etadot"-component of the wind.
!          PURL05  - cf. PURL0 (trajectory)
!          PVRL05  - cf. PVRL0 (trajectory)
!          PWRL05  - cf. PWRL0 (trajectory)
!          KVSEPC  - vertical separation for use in update loop (cubic).
!          KVSEPL  - vertical separation for use in update loop (linear).
!          KLOCK   - ??? (used for OpenMP purposes).
!          KDIM1,KDIM2 - dimensions of KINC, PINC
!          KINC    - addresses of interpolation increments in global buffer
!          PINC    - interpolation increments to global buffer (vector only)
!          PLON    - computational sphere longitude of interpolation point.
!          PLAT    - computational sphere latitude of interpolation point.
!          PO      - first element of the wind displacement matrix.
!          PQ      - second element of the wind displacement matrix.
!          PUF0    - Interpolated U-wind for SL trajectory research.
!          PVF0    - Interpolated V-wind for SL trajectory research.
!          PWF0    - Interpolated "etadot"-wind for SL trajectory research.
!          PLON5   - cf. PLON (trajectory)
!          PLAT5   - cf. PLAT (trajectory)
!          KL0     - index of the four western points
!                    of the 16 points interpolation grid.
!          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   - distances for vertical linear interpolation
!                    on a same vertical.
!          PVINTW  - Vertical cubic interpolation weights.
!          PVINTWSLD - vertical cubic interpolation weights, SLHD case
!          PDLO5   - cf. PDLO (trajectory)
!          PDLAT5  - cf. PDLAT (trajectory)
!          PDVER5  - cf. PDVER (trajectory)

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

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

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

!        Called by LARMESAD, ELARMESAD and LAPINEAAD

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

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

!     Modifications. (list for LARCINAD)
!     --------------
!      Original: 99/10/07
!      Modified 00-02-04 by C. Temperton: ZINC array transposed
!      Modified 00-02-07 by C. Temperton: removed redundant use of PX0
!                                         when NVLAG=3.
!      Modified 00-02-09 by C. Temperton: longer vectors in update loop.
!      Modified 00-02-17 by C. Temperton: more optimization....
!      Modified 00-03-01 by C. Temperton: precompute functions for
!                                         cubic interpolation.
!      Modified 00-06-15 by C. Temperton: make vectorization safe.
!      Modified 01-08-30 by K. YESSAD: pruning and some other cleanings.
!      Modified 01-02-27 by C. Temperton: LVECADIN option.
!      Modified 02-07-09 by C. Temperton: added check on IVSEP
!      Modified 03-04-14 by D. Salmond FIX for event logic
!        M.Hamrud      01-Oct-2003 CY28 Cleaning
!      Modified 05-07-09 by C. Temperton: streamlining.
!        D.Salmond     08-Feb-2005 New version LARCINAAD
!      Modified 08-Jan-2007 by F. Vana
!                           - LDPLANE=.T. (skipping adjoint in E-zone)
!                           - NEC-SX optimization
!      Modified 17-Jul-2007 by F. Vana: cleaning + further vect. optimization
!        G.Mozdzynski  21-Feb-2008 Use of locks made dynamic for performance
!      Modified 14-Aug-2008 by F. Vana: Weights driven interpolation, removing
!                             useless KDEP, NEC optim. (following LARCINBAD)
!      K. Yessad Nov 2008: rationalisation of dummy argument interfaces
!      F. Vana :     11-Dec-2008 OpenMP for vector platforms
!     ------------------------------------------------------------------

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

USE YOMCST   , ONLY : RPI
USE YOMDIM   , ONLY : NFLEVG   ,NPROMA   ,NFLSA    ,NFLEN    ,NDGSAH   ,&
 & NDGENH   ,NDLUNG   ,NDLUXG   ,NRLEVX
USE YOMLEG   , ONLY : RLATI    ,RIPI0    ,RIPI1    ,RIPI2    ,RSLD1    ,&
 & RSLD2    ,RSLD3    ,RSLDW
USE YOMGEM   , ONLY : VETAF    ,VCUICO   ,VSLD     ,VSLDW    ,&
 & NVAUTF   ,NSTTYP   ,RMUCEN   ,RLOCEN   ,RSTRET   ,R4JP     ,RC2P1    ,&
 & RC2M1    ,VRLEVX
USE YOMMP    , ONLY : NASLB1
USE PTRSLB1  , ONLY : MSLB1UR0 ,MSLB1VR0 ,MSLB1WR0 ,RPARSL1  
USE YOMSLREP , ONLY : LSLADREP, MASK_SLTOT, NADCORE, LSLCORE, LVECADIN
USE YOMVAR   , ONLY : NSIM4D
USE YOMLUN   , ONLY : NULERR, NULOUT
USE YOMCT0   , ONLY : NPROC
USE YOMMASK  , ONLY : MASK_SL1, LSLONDEM
USE YOM_YGFL , ONLY : YGFL     ,YGFLC
USE YOMSC2   , ONLY : NFLDSLB1
USE OML_MOD, ONLY : OML_INCR_EVENT, OML_OMP, OML_WAIT_EVENT

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

IMPLICIT NONE

INTEGER(KIND=JPIM),INTENT(IN)    :: KDIM
INTEGER(KIND=JPIM),INTENT(IN)    :: KSTGLO 
INTEGER(KIND=JPIM),INTENT(IN)    :: KST 
INTEGER(KIND=JPIM),INTENT(IN)    :: KPROF 
INTEGER(KIND=JPIM),INTENT(IN)    :: KSTABUF(NDGSAH:NDGENH) 
LOGICAL           ,INTENT(IN)    :: LDSLHD
LOGICAL           ,INTENT(IN)    :: LDSLHDQUAD
INTEGER(KIND=JPIM),INTENT(IN)    :: KTIP 
INTEGER(KIND=JPIM),INTENT(IN)    :: KROT 
LOGICAL           ,INTENT(IN)    :: LDPLANE 
LOGICAL           ,INTENT(IN)    :: LDOCK_UP 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PLSDEPI(NDGSAH:NDGENH) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PCOLON(NPROMA) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PSILON(NPROMA) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PGEMU(NPROMA) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PGSQM2(NPROMA) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PGECLO(NPROMA) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PGESLO(NPROMA) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PCOSCO(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PSINCO(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PSINLA(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PCOPHI(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PLEV(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PCOSCO5(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PSINCO5(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PSINLA5(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PCOPHI5(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PLEV5(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PKAPPA(NPROMA,NFLEVG)
REAL(KIND=JPRB)   ,INTENT(IN)    :: PKAPPA5(NPROMA,NFLEVG)
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PURL0(NASLB1,NFLSA:NFLEN)
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PVRL0(NASLB1,NFLSA:NFLEN)
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PWRL0(NASLB1,NFLSA:NFLEN)
REAL(KIND=JPRB)   ,INTENT(IN)    :: PURL05(NASLB1,NFLSA:NFLEN)
REAL(KIND=JPRB)   ,INTENT(IN)    :: PVRL05(NASLB1,NFLSA:NFLEN)
REAL(KIND=JPRB)   ,INTENT(IN)    :: PWRL05(NASLB1,NFLSA:NFLEN)
INTEGER(KIND=JPIM),INTENT(IN)    :: KVSEPC
INTEGER(KIND=JPIM),INTENT(IN)    :: KVSEPL
INTEGER(KIND=JPIM),INTENT(INOUT) :: KLOCK(:)
INTEGER(KIND=JPIM),INTENT(IN)    :: KDIM1
INTEGER(KIND=JPIM),INTENT(IN)    :: KDIM2
INTEGER(KIND=JPIM),INTENT(INOUT) :: KINC(KDIM1,KDIM2)
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PINC(KDIM1,KDIM2)
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PLON(NPROMA,NFLEVG)
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PLAT(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PO(NPROMA,NFLEVG)
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PQ(NPROMA,NFLEVG)
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PUF0(NPROMA,NFLEVG)
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PVF0(NPROMA,NFLEVG)
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PWF0(NPROMA,NFLEVG)
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PLON5(NPROMA,NFLEVG)
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PLAT5(NPROMA,NFLEVG) 
INTEGER(KIND=JPIM),INTENT(IN)    :: KL0(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(IN)    :: PDLO5(NPROMA,NFLEVG,0:3)
REAL(KIND=JPRB)   ,INTENT(IN)    :: PDLAT5(NPROMA,NFLEVG)
REAL(KIND=JPRB)   ,INTENT(IN)    :: PDVER5(NPROMA,NFLEVG)

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

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

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

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
REAL(KIND=JPRB) :: ZDSTRET, ZDEPI, ZPIS2

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

#include "abor1.intfb.h"
#include "laitli_init.intfb.h"
#include "laitlitlad.intfb.h"
#include "elarchead.intfb.h"
#include "elascawad.intfb.h"
#include "larchead.intfb.h"
#include "lascawad.intfb.h"

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

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

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

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

ZDSTRET=2.0_JPRB*RSTRET
ZDEPI=2.0_JPRB*RPI
ZPIS2=0.5_JPRB*RPI

IHOR=0    !!! for revised application of LAIDDITLAD

DO JFLD=1,NFLDSLB1
  IF(     RPARSL1(JFLD) ==  1.0_JPRB )THEN
    ISIGN(JFLD)=1
  ELSEIF( RPARSL1(JFLD) == -1.0_JPRB )THEN
    ISIGN(JFLD)=2
  ELSE
    CALL ABOR1("LARCINAAD: RPARSL1 invalid sign")
  ENDIF
ENDDO

!     * Input variable IWIS for LASCAW.
!     * Computation of ISEP
IF (KTIP == 1) THEN
  ! * trajectory research.
  IWIS=101
  ISEP=KVSEPL
ELSEIF (KTIP == 3) THEN
  ! * origin point interpolations.
  IWIS=103
  ISEP=KVSEPC
ELSE
  IWIS=-999
  CALL ABOR1('LARCINAAD: WRONG VALUE FOR IWIS')
ENDIF

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

!*       3.    INTERPOLATIONS OF WIND FOR TRAJECTORY RESEARCH.
!              -----------------------------------------------

IF (KTIP == 1) THEN

  IF( LSLADREP )THEN
    ALLOCATE(ZSIGN8 (NPROMA,8 ,NFLEVG,2))
    ALLOCATE(IMAP8  (NPROMA,8 ,NFLEVG))
    CALL LAITLI_INIT(NASLB1,NPROMA,KST,KPROF,NFLEVG,KL0(1,1,0),IMAP8,ZSIGN8)
  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

  ! ZERO COEFF ARRAYS:
  !CDIR COLLAPSE
  PDLAT(:,:)=0.0_JPRB
  !CDIR COLLAPSE
  PCLA(:,:,:)=0.0_JPRB
  !CDIR COLLAPSE
  PDLO(:,:,:)=0.0_JPRB
  !CDIR COLLAPSE
  PCLO(:,:,:,:)=0.0_JPRB
  !CDIR COLLAPSE
  PDVER(:,:)=0.0_JPRB
  !CDIR COLLAPSE
  PVINTW(:,:,:)=0.0_JPRB

  IF (LDSLHD) THEN
    !CDIR COLLAPSE
    PCLASLD(:,:,:)=0.0_JPRB
    !CDIR COLLAPSE
    PCLOSLD(:,:,:,:)=0.0_JPRB
    !CDIR COLLAPSE
    PVINTWSLD(:,:,:)=0.0_JPRB
  ENDIF

  !* Trilinear interpolations.

  INCA=1
  ILOCK=0

  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,MSLB1UR0,ISEP,IMAP8,ZSIGN8(1,1,1,ISIGN(MSLB1UR0)),&
   & LVECADIN,PDLAT,PDLO(1,1,1),KL0(1,1,1),PDVER,&
   & PDLAT5,PDLO5(1,1,1),PDVER5,&
   & KINC(INCA,1),PINC(INCA,1),KDIM,PURL0,PURL05,PUF0)  
  INCA=INCA+8
  IF (OML_OMP().AND..NOT.LVECADIN.AND.LDOCK_UP) CALL OML_INCR_EVENT(KPROF,KLOCK(ILOCK))

  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,MSLB1VR0,ISEP,IMAP8,ZSIGN8(1,1,1,ISIGN(MSLB1VR0)),&
   & LVECADIN,PDLAT,PDLO(1,1,1),KL0(1,1,1),PDVER,&
   & PDLAT5,PDLO5(1,1,1),PDVER5,&
   & KINC(INCA,1),PINC(INCA,1),KDIM,PVRL0,PVRL05,PVF0)  
  INCA=INCA+8
  IF (OML_OMP().AND..NOT.LVECADIN.AND.LDOCK_UP) CALL OML_INCR_EVENT(KPROF,KLOCK(ILOCK))

  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,MSLB1WR0,ISEP,IMAP8,ZSIGN8(1,1,1,ISIGN(MSLB1WR0)),&
   & LVECADIN,PDLAT,PDLO(1,1,1),KL0(1,1,1),PDVER,&
   & PDLAT5,PDLO5(1,1,1),PDVER5,&
   & KINC(INCA,1),PINC(INCA,1),KDIM,PWRL0,PWRL05,PWF0)  
  INCA=INCA+8
  IF (OML_OMP().AND..NOT.LVECADIN.AND.LDOCK_UP) CALL OML_INCR_EVENT(KPROF,KLOCK(ILOCK))

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


  IF (LVECADIN) THEN

    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('LARCINAAD: 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,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,2),NASLB1)+1
        MASK_SL1(IOFF)=1
        IOFF=MOD(KL0(JROF,JLEV,2)+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,8
!OCL NOVREC
        DO JROF=KST,KPROF
          IOFF=MOD(IMAP8(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

ENDIF

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

!*       2.    COMPUTATION OF LAT LON OF THE INTERPOLATION POINT.
!              IF KROT=1 COMPUTATION OF THE WIND DISPLACEMENT MATRIX
!              FROM THE INTERPOLATION POINT TO THE FINAL POINT.
!              ( T FOR LATITUDE THETA, L FOR LONGITUDE LAMBDA).
!              PO = ( 1 / (1+cos(PHI)) )
!                  *( cos(TG)*cos(T) + (1+sin(TG)*sin(T))*cos(L-LG) )
!              PQ = (-1 / (1+cos(PHI)) )
!                  *( sin(TG)+sin(T) ) * sin(L-LG)
!     ------------------------------------------------------------------

IF (LDPLANE) THEN

  CALL ELASCAWAD(NPROMA,KST,KPROF,NFLEVG,&
   & NDLUNG,NDLUXG,&
   & NFLSA,IWIS,IHOR,&
   & LDSLHD,LDSLHDQUAD,&
   & PCOSCO,PSINCO,PLEV,PKAPPA,PCOSCO5,PSINCO5,PLEV5,PKAPPA5,&
   & VETAF,NVAUTF,VCUICO,VSLD,VSLDW,NRLEVX,VRLEVX,&
   & PDLAT,PCLA,PCLASLD,PDLO,PCLO,PCLOSLD,PDVER,PVINTW,PVINTWSLD)

  IF (KROT == 1) THEN
    CALL ELARCHEAD(NPROMA,KST,KPROF,NFLEVG,&
     & PGEMU,PGSQM2,PGECLO,PGESLO,&
     & PCOSCO,PSINCO,PO,PQ,PLON,PLAT,&
     & PCOSCO5,PSINCO5,PLON5,PLAT5)
  ENDIF

ELSE

  CALL LASCAWAD(NPROMA,KST,KPROF,NFLEVG,NDGSAH,NDGENH,&
   & NFLSA,IWIS,IHOR,&
   & LDSLHD,LDSLHDQUAD,&
   & R4JP,ZPIS2,PLSDEPI,RLATI(NDGSAH),&
   & RIPI0(NDGSAH),RIPI1(NDGSAH),RIPI2(NDGSAH),&
   & RSLD1(NDGSAH),RSLD2(NDGSAH),RSLD3(NDGSAH),RSLDW(1,1,NDGSAH),&
   & PLON,PLAT,PLEV,PKAPPA,PLON5,PLAT5,PLEV5,PKAPPA5,&
   & VETAF,NVAUTF,VCUICO,VSLD,VSLDW,NRLEVX,VRLEVX,&
   & PDLAT,PCLA,PCLASLD,PDLO,PCLO,PCLOSLD,PDVER,PVINTW,PVINTWSLD)

  CALL LARCHEAD(NPROMA,KST,KPROF,NFLEVG,&
   & NSTTYP,ZDSTRET,RC2M1,RC2P1,RPI,ZDEPI,&
   & RLOCEN,RMUCEN,PCOLON,PSILON,&
   & PGEMU,PGSQM2,PGECLO,PGESLO,&
   & PCOSCO,PSINCO,PSINLA,PCOPHI,&
   & PCOSCO5,PSINCO5,PSINLA5,PCOPHI5,&
   & KROT,PLON,PLAT,PO,PQ)

ENDIF

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('LARCINAAD',1,ZHOOK_HANDLE)
END SUBROUTINE LARCINAAD
