SUBROUTINE LAPINEBAD(KST,KPROF,KSTGLO,&
 & PCOLON,PSILON,PGM,PGEMU,PGSQM2,PGECLO,PGESLO,&
 & PGNORDL,PGNORDM,PINDX,PINDY,&
 & PB1,PB15,PGMVT1,PGMVT1S,PGFLT1,PB2,&
 & PINC,KINC,KDIM,KDIM1,KDIM2,&
 ! -----------------------------------------------------------------------
 & PLON,PLAT,PQX,PQY,&
 & PLON5,PLAT5,PQX5,PQY5,&
 ! -----------------------------------------------------------------------
 & KL0,KLH0,PDLO,PCLO,PCLOSLD,&
 & PDLAT,PCLA,PCLASLD,PDVER,PVINTW,PVINTWSLD,&
 ! -----------------------------------------------------------------------
 & PDLO5,PCLO5,PCLOSLD5,PDLAT5,PCLA5,PCLASLD5,PDVER5,PVINTW5,PVINTWSLD5,&
 ! -----------------------------------------------------------------------
 & PCOSCO,PSINCO,PCOPHI,PSINLA,&
 & PLEV,&
 ! -----------------------------------------------------------------------
 & KDEP,&
 ! -----------------------------------------------------------------------
 & KLOCK)  

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

USE YOMDIM   , ONLY : NDGUNG   ,NDGUXG   ,NDLUNG   ,NDLUXG   ,NPROMA   ,&
 & NFLEVG   ,NFLSA    ,NFLEN
USE YOMCT0   , ONLY : LRPLANE
USE YOMDYNA  , ONLY : LSLHD
USE YOMDYN   , ONLY : NVLAG    ,LADVF    ,L2TLFF   
USE YOMCST   , ONLY : RPI      ,ROMEGA   ,RA
USE YOMGEM   , ONLY : VDELB    ,NSTTYP   ,RMUCEN   ,RLOCEN   ,RSTRET   ,&
 & RC2P1    ,RC2M1    ,VFE_RDETAH
USE YOMCVER  , ONLY : LVERTFE
USE YOMRIP   , ONLY : RTDT
USE YOEPHY   , ONLY : LEPHYS   ,LAGPHY
USE YOMPHY   , ONLY : LMPHYS
USE YOM_YGFL , ONLY : YGFL     ,YGFLC
USE YEMGEO   , ONLY : EDELX    ,EDELY
USE YOMSC2   , ONLY : NFLDSLB1 ,NFLDSLB15,NFLDSLB2
USE YOMGMV   , ONLY : YT1
USE YOMMP    , ONLY : NASLB1
USE PTRSLB2  , ONLY : MSLB2U15 ,MSLB2V15

!**** *LAPINEBAD* - semi-LAgrangian scheme:(Interpolation -Part B)
!                                               (adjoint version)
!                Interface subroutine for interpolations and lagrangian
!                trends. (Programme INterface d'Ensemble).

!     Purpose.
!     --------
!       Grid point calculations in dynamics.

!       Does the interpolations at the origin point O of the SL-trajectory.
!       Then adds the interpolated quantities of the RHS of equations to
!       yield a provisional value for X(t+dt) for each prognostic variable X.

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

!        Explicit arguments :
!        --------------------
!          KST     - first element of arrays where computations are performed.
!          KPROF   - depth of work.
!          KSTGLO  - global offset into nproma buffer.
!          PCOLON  - cos(computational sphere longitude).
!          PSILON  - sin(computational sphere longitude).
!          PGM     - mapping factor.
!          PGEMU   - sin(geographical latitude).
!          PGSQM2  - cos(geographical latitude).
!          PGECLO  - cos(geographical longitude).
!          PGESLO  - sin(geographical longitude).
!          PGNORDL - zonal component of the vector pointed towards the
!                    true North pole.
!          PGNORDM - meridian component of the vector pointed towards the
!                    true North pole.
!          PINDX   - x coordinate on the plane.
!          PINDY   - y coordinate on the plane.
!          PB1     - "SLBUF1" buffer for interpolations.
!          PB15    - "SLBUF1" buffer for interpolations (trajectory).
!          KDIM    - number of updates for high order interpolation
!          KDIM1,KDIM2 - dimensions of KINC, PINC
!          KINC    - addresses of interpolation increments in global buffer
!          PINC    - interpolation increments to global buffer (vector only)
! -----------------------------------------------------------------------
!          PGMVT1  - t+dt GMV (upper air) variables.
!          PGMVT1S - t+dt GMVS (surface) variables.
!          PGFLT1  - t+dt GFL
!          PB2     - "SLBUF2" buffer.
! -----------------------------------------------------------------------
!          PLON    - computational sphere longitude of interpolation point.
!          PLAT    - computational sphere latitude of interpolation point.
!          PQX     - first element of the wind displacement matrix (pt O).
!          PQY     - second element of the wind displacement matrix (pt O).
! ----------------------- trajectory variables --------------------------
!          PLON5,PLAT5,PQX5,PQY5: cf. PLON,PLAT,PQX,PQY for trajectory.
! -----------------------------------------------------------------------
!          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
!          PDLO5,PCLO5,PCLOSLD5,PDLAT5,PCLA5,PCLASLD5,PDVER5,PVINTW5,PVINTWSLD5:
!                    cf. PDLO,PCLO,PCLOSLD,PDLAT,..... for trajectory.
! -----------------------------------------------------------------------
!          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).
!          PCOPHI  - cosine of the geographical angle between the
!                    interpolation point and the grid-point.
!          PSINLA  - sine of the interpolation point geographical latitude.
! -----------------------------------------------------------------------
!          PLEV    - vertical coordinate of the interpolation point.
!                    interpolation point and the grid-point.
!          KDEP    - indication of the interpolation stencil latitudial
!                    dependences (used for LVECADIN=.T. option in ALADIN)
!          KLOCK   - ??? (used for OpenMP purposes).

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

!     Method.
!     -------

!     Externals.    
!     ----------
!       Called by CALL_SL_AD

!     Reference.
!     ----------
!        ARPEGE documentation about semi-Lagrangian scheme.

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

! Modifications
! -------------
!   Original : 08/02/05
!   D.Salmond     08-Feb-2005 New LAPINEBAD
!   C.Temperton: 03/03/05: Re-use results of LARCHE from LAPINE5
!   C.Temperton: 07/03/05: Re-use results of LASCAW from LAPINE5
!   F. Vana :  26/09/06 LRPLANE=.T.
!   F. Vana :  08-Jan-2007 KDEP array for LAM
!   N. Wedi and K. Yessad (Jan 2008): different dev for NH model and PC scheme
!   30-Jun-2008 J. Masek   Argument PCLO5 transferred to LARCINB5.
!   F. Vana :  13-Aug-2008 Weights driven interpolation
!   K. Yessad Nov 2008: rationalisation of dummy argument interfaces
!   F. Vana : 11-Dec-2008 OpenMP for vector platforms
!------------------------------------------------------------------------------

IMPLICIT NONE

INTEGER(KIND=JPIM),INTENT(IN)    :: KST 
INTEGER(KIND=JPIM),INTENT(IN)    :: KPROF 
INTEGER(KIND=JPIM),INTENT(IN)    :: KSTGLO 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PCOLON(NPROMA) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PSILON(NPROMA) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PGM(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(IN)    :: PGNORDL(NPROMA) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PGNORDM(NPROMA) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PINDX(NPROMA) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PINDY(NPROMA) 
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)    :: KDIM
INTEGER(KIND=JPIM),INTENT(IN)    :: KDIM1
INTEGER(KIND=JPIM),INTENT(IN)    :: KDIM2
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PGMVT1(NPROMA,NFLEVG,YT1%NDIM) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PGMVT1S(NPROMA,YT1%NDIMS)
REAL(KIND=JPRB)   ,INTENT(IN)    :: PGFLT1(NPROMA,NFLEVG,YGFL%NDIM1) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PB2(NPROMA,NFLDSLB2)
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PLON(NPROMA,NFLEVG)
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PLAT(NPROMA,NFLEVG)
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PQX(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PQY(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PLON5(NPROMA,NFLEVG)
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PLAT5(NPROMA,NFLEVG)
REAL(KIND=JPRB)   ,INTENT(IN)    :: PQX5(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PQY5(NPROMA,NFLEVG) 
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(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)   ,INTENT(INOUT) :: PCOSCO(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PSINCO(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PCOPHI(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PSINLA(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PLEV(NPROMA,NFLEVG) 
INTEGER(KIND=JPIM),INTENT(IN)    :: KDEP(NPROMA,NFLEVG)
INTEGER(KIND=JPIM),INTENT(INOUT) :: KLOCK(:) 

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

REAL(KIND=JPRB)   :: ZDP9(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   :: ZU9(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   :: ZV9(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   :: ZT9(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   :: ZGFL9(NPROMA,NFLEVG,YGFL%NUMFLDS) 
REAL(KIND=JPRB)   :: ZC9(NPROMA,NFLEVG) 

!     trigonometric arrays.

REAL(KIND=JPRB) :: ZP5    (NPROMA,NFLEVG)
REAL(KIND=JPRB) :: ZQ5    (NPROMA,NFLEVG)
REAL(KIND=JPRB) :: ZP7    (NPROMA,NFLEVG)
REAL(KIND=JPRB) :: ZQ7    (NPROMA,NFLEVG)
REAL(KIND=JPRB) :: ZSINCO7(NPROMA,NFLEVG)
REAL(KIND=JPRB) :: ZCOSCO7(NPROMA,NFLEVG)
REAL(KIND=JPRB) :: ZSINLA7(NPROMA,NFLEVG)
REAL(KIND=JPRB) :: ZCOPHI7(NPROMA,NFLEVG)
REAL(KIND=JPRB) :: ZLON7  (NPROMA,NFLEVG)
REAL(KIND=JPRB) :: ZLAT7  (NPROMA,NFLEVG)
REAL(KIND=JPRB) :: ZLON8  (NPROMA,NFLEVG)
REAL(KIND=JPRB) :: ZLAT8  (NPROMA,NFLEVG)

!     interpolated quantities arrays.

REAL(KIND=JPRB) :: ZU95(NPROMA,NFLEVG)
REAL(KIND=JPRB) :: ZV95(NPROMA,NFLEVG)
REAL(KIND=JPRB) :: ZU96(NPROMA,NFLEVG)
REAL(KIND=JPRB) :: ZV96(NPROMA,NFLEVG)
REAL(KIND=JPRB) :: ZU97(NPROMA,NFLEVG)
REAL(KIND=JPRB) :: ZV97(NPROMA,NFLEVG)
REAL(KIND=JPRB) :: ZUT15(NPROMA,NFLEVG)
REAL(KIND=JPRB) :: ZVT15(NPROMA,NFLEVG)
REAL(KIND=JPRB) :: ZSPT1(NPROMA,NFLEVG)
REAL(KIND=JPRB) :: ZSPTO(NPROMA,NFLEVG+1)
! The following arrays are for the L2TLFF option:
REAL(KIND=JPRB) :: ZZUZ9(NPROMA,NFLEVG)
REAL(KIND=JPRB) :: ZZVZ9(NPROMA,NFLEVG)
REAL(KIND=JPRB) :: ZZUZ95(NPROMA,NFLEVG)
REAL(KIND=JPRB) :: ZZVZ95(NPROMA,NFLEVG)

!     geographical parameters.

REAL(KIND=JPRB) :: ZGMDTX(NPROMA)
REAL(KIND=JPRB) :: ZGMDTY(NPROMA)
REAL(KIND=JPRB) :: ZINEZV(NPROMA)

!     miscellaneous

INTEGER(KIND=JPIM) :: JLEV, JROF, JGFL  
INTEGER(KIND=JPIM) :: IOUT(NPROMA,NFLEVG)

LOGICAL :: LL2TLFFO
LOGICAL :: LLVERCOR, LLADVFW, LLCOMPUTE_OMVAK_O

REAL(KIND=JPRB) :: ZCOPH, ZDEPI, &
 & ZDSTRET, ZPHI, &
 & ZPP, ZPP1, ZPP9, ZQQ, ZQQ1, ZQQ9, ZSINX, &
 & ZZUT1, ZZVT1, &
 & ZCOPH5, ZPHI5, ZPP5, ZPP95, ZQQ5, ZQQ95, &
 & ZSINX5, ZZUT15, ZZVT15, ZDLUN, ZDLUX, ZDGUN, ZDGUX, &
 & ZTXO, ZTYO, ZTXO5, ZTYO5 

REAL(KIND=JPRB) :: ZHOOK_HANDLE

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

#include "lacone.intfb.h"
#include "laconead.intfb.h"
#include "larcinb5.intfb.h"
#include "larcinbad.intfb.h"
#include "larche.intfb.h"
#include "elarche.intfb.h"
#include "larchead.intfb.h"
#include "elarchead.intfb.h"
#include "verintad.intfb.h"

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

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

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

!*       1.    PRELIMINAR INITIALISATIONS:

!*       1.1   preliminar initialisations:

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

LL2TLFFO=L2TLFF.AND.(LMPHYS.OR.LEPHYS).AND.(.NOT.LAGPHY)

IF(LRPLANE) THEN
  ZDLUN=REAL(NDLUNG,JPRB)
  ZDLUX=REAL(NDLUXG,JPRB)
  ZDGUN=REAL(NDGUNG,JPRB)
  ZDGUX=REAL(NDGUXG,JPRB)
  DO JROF = KST, KPROF
    ZGMDTX (JROF)=0.5_JPRB*PGM(JROF)*RTDT/EDELX
    ZGMDTY (JROF)=0.5_JPRB*PGM(JROF)*RTDT/EDELY
    ZINEZV(JROF)=MAX(0.0_JPRB,SIGN(1.0_JPRB,(PINDX(JROF)-ZDLUN)*&
     & (ZDLUX-PINDX(JROF))))*&
     & MAX(0.0_JPRB,SIGN(1.0_JPRB,(PINDY(JROF)-ZDGUN)*(ZDGUX-PINDY(JROF))))
  ENDDO
  ! * Retrieval of the origin point coordinates from LAPINEA5
  !   is not needed. Here we use directly "2 Omega vectorial a k"
  !   stored to PLON5, PLAT5. (There's no additional computation
  !   since trajectories were already computed.)
ENDIF

!*       1.2   settings to zero:

! Zero local trig arrays:
!CDIR COLLAPSE
PLON(:,:)=0.0_JPRB
!CDIR COLLAPSE
PLAT(:,:)=0.0_JPRB

! Zero input arrays used as work space:
!CDIR COLLAPSE
PSINCO(:,:)=0.0_JPRB
!CDIR COLLAPSE
PCOSCO(:,:)=0.0_JPRB
!CDIR COLLAPSE
PSINLA(:,:)=0.0_JPRB
!CDIR COLLAPSE
PCOPHI(:,:)=0.0_JPRB
!CDIR COLLAPSE
PLEV(:,:)=0.0_JPRB
!CDIR COLLAPSE
PQX(:,:)=0.0_JPRB
!CDIR COLLAPSE
PQY(:,:)=0.0_JPRB

! Zero interpolated quantities:
!CDIR COLLAPSE
ZDP9(:,:)=0.0_JPRB
!CDIR COLLAPSE
ZU9(:,:)=0.0_JPRB
!CDIR COLLAPSE
ZV9(:,:)=0.0_JPRB
!CDIR COLLAPSE
ZT9(:,:)=0.0_JPRB
!CDIR COLLAPSE
ZGFL9(:,:,:)=0.0_JPRB
!CDIR COLLAPSE
ZC9(:,:)=0.0_JPRB

!CDIR COLLAPSE
ZZUZ9(:,:)=0.0_JPRB
!CDIR COLLAPSE
ZZVZ9(:,:)=0.0_JPRB

! Zero interpolation coefficients:
!CDIR COLLAPSE
PDLO(:,:,:)=0.0_JPRB
!CDIR COLLAPSE
PCLO(:,:,:,:)=0.0_JPRB
!CDIR COLLAPSE
PDLAT(:,:)=0.0_JPRB
!CDIR COLLAPSE
PCLA(:,:,:)=0.0_JPRB
!CDIR COLLAPSE
PDVER(:,:)=0.0_JPRB
!CDIR COLLAPSE
PVINTW(:,:,:)=0.0_JPRB

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

!CDIR COLLAPSE
IOUT(:,:)=0

!*       1.3   AD-trajectory:
!              (K.Y.: this part can be put in a new routine LAPINEB5)

CALL LARCINB5(KST,KPROF,&
 & KL0,PDLO5,PCLO5,PCLOSLD5,&
 & PDLAT5,PCLA5,PCLASLD5,PDVER5,PVINTW5,PVINTWSLD5,PB15,&
 & ZU95,ZV95,ZZUZ95,ZZVZ95)

!!! Temporary:
DO JLEV=1,NFLEVG
  DO JROF=KST,KPROF
    ZP5(JROF,JLEV)=PQX5(JROF,JLEV)
    ZQ5(JROF,JLEV)=PQY5(JROF,JLEV)
  ENDDO
ENDDO

IF (L2TLFF) THEN

  DO JLEV=1,NFLEVG
    DO JROF=KST,KPROF
      ZPP5=ZP5(JROF,JLEV)*PGNORDM(JROF)-ZQ5(JROF,JLEV)*PGNORDL(JROF)
      ZQQ5=ZQ5(JROF,JLEV)*PGNORDM(JROF)+ZP5(JROF,JLEV)*PGNORDL(JROF)
      ZUT15(JROF,JLEV)=PB2(JROF,MSLB2U15-1+JLEV) &
       & +ZPP5*ZU95(JROF,JLEV)+ZQQ5*ZV95(JROF,JLEV)  
      ZVT15(JROF,JLEV)=PB2(JROF,MSLB2V15-1+JLEV) &
       & +ZPP5*ZV95(JROF,JLEV)-ZQQ5*ZU95(JROF,JLEV)  
    ENDDO
  ENDDO

  IF (LRPLANE) THEN
    ZU96(KST:KPROF,1:NFLEVG)=PLON5(KST:KPROF,1:NFLEVG)
    ZV96(KST:KPROF,1:NFLEVG)=PLAT5(KST:KPROF,1:NFLEVG)
  ELSE
    CALL LACONE(NPROMA,KST,KPROF,NFLEVG,NSTTYP,&
     & ROMEGA,ZDSTRET,RC2M1,RC2P1,RMUCEN,RA,RPI,&
     & PLON5,PLAT5,ZU96,ZV96)  
  ENDIF

  DO JLEV=1,NFLEVG
    DO JROF=KST,KPROF
      ZPP5=ZP5(JROF,JLEV)*PGNORDM(JROF)-ZQ5(JROF,JLEV)*PGNORDL(JROF)
      ZQQ5=ZQ5(JROF,JLEV)*PGNORDM(JROF)+ZP5(JROF,JLEV)*PGNORDL(JROF)
      ZUT15(JROF,JLEV)=ZUT15(JROF,JLEV) &
       & +ZPP5*ZU96(JROF,JLEV)+ZQQ5*ZV96(JROF,JLEV)  
      ZVT15(JROF,JLEV)=ZVT15(JROF,JLEV) &
       & -ZQQ5*ZU96(JROF,JLEV)+ZPP5*ZV96(JROF,JLEV)  
    ENDDO
  ENDDO

  IF (LRPLANE) THEN
    DO JLEV=1,NFLEVG
      DO JROF=KST,KPROF
        ! * compute new origin point:
        ZPP5=ZP5(JROF,JLEV)*PGNORDM(JROF)-ZQ5(JROF,JLEV)*PGNORDL(JROF)
        ZQQ5=ZQ5(JROF,JLEV)*PGNORDM(JROF)+ZP5(JROF,JLEV)*PGNORDL(JROF)
        ! * new estimate of trajectory wind:
        ZZUT15=0.5_JPRB*(ZUT15(JROF,JLEV)+ZZUZ95(JROF,JLEV))
        ZZVT15=0.5_JPRB*(ZVT15(JROF,JLEV)+ZZVZ95(JROF,JLEV))  
        ! * compute the new origin point
        ZTXO5=PINDX(JROF)-2.0_JPRB*ZZUT15*ZGMDTX(JROF)
        ZTYO5=PINDY(JROF)-2.0_JPRB*ZZVT15*ZGMDTY(JROF)
        ZLON7(JROF,JLEV)=ZTXO5*ZINEZV(JROF)+PINDX(JROF)*(1.0_JPRB-ZINEZV(JROF))
        ZLAT7(JROF,JLEV)=ZTYO5*ZINEZV(JROF)+PINDY(JROF)*(1.0_JPRB-ZINEZV(JROF))
        IF((ZTXO5 > ZDLUN).OR.(ZTXO5 < ZDLUX)) IOUT(JROF,JLEV)=1
        IF((ZTYO5 > ZDGUN).OR.(ZTYO5 < ZDGUX)) &
          & IOUT(JROF,JLEV)=IOUT(JROF,JLEV)+2
        ZTXO5=MIN(MAX(ZTXO5,ZDLUN),ZDLUX)
        ZTYO5=MIN(MAX(ZTYO5,ZDGUN),ZDGUX)
        ZCOSCO7(JROF,JLEV)=ZTXO5*ZINEZV(JROF)+PINDX(JROF)*(1.0_JPRB-ZINEZV(JROF))
        ZSINCO7(JROF,JLEV)=ZTYO5*ZINEZV(JROF)+PINDY(JROF)*(1.0_JPRB-ZINEZV(JROF))
      ENDDO
    ENDDO
    ! * compute rotation matrix and Coriolis term "2 Omega wedge a k"
    !   at the new origine point ON.
    ZLON8(:,:)=ZLON7(:,:)
    ZLAT8(:,:)=ZLAT7(:,:)
    CALL ELARCHE(NPROMA,KST,KPROF,NFLEVG,&
     & PGEMU,PGSQM2,PGECLO,PGESLO,&
     & ZCOSCO7,ZSINCO7,ZP7,ZQ7,ZLON8,ZLAT8)  
    ZU97(KST:KPROF,1:NFLEVG)=ZLON8(KST:KPROF,1:NFLEVG)
    ZV97(KST:KPROF,1:NFLEVG)=ZLAT8(KST:KPROF,1:NFLEVG)
  ELSE
    ! * compute new origin point:
    DO JLEV=1,NFLEVG
      DO JROF=KST,KPROF
        ZPP5=ZP5(JROF,JLEV)*PGNORDM(JROF)-ZQ5(JROF,JLEV)*PGNORDL(JROF)
        ZQQ5=ZQ5(JROF,JLEV)*PGNORDM(JROF)+ZP5(JROF,JLEV)*PGNORDL(JROF)
        ZPP95=ZP5(JROF,JLEV)
        ZQQ95=ZQ5(JROF,JLEV)
        ZPP1=PGNORDM(JROF)
        ZQQ1=-PGNORDL(JROF)
        ! * new estimate of trajectory wind:
        ZZUT15=0.5_JPRB*(&
         & ZPP1*ZUT15(JROF,JLEV)+ZQQ1*ZVT15(JROF,JLEV)&
         & +ZPP95*ZZUZ95(JROF,JLEV)+ZQQ95*ZZVZ95(JROF,JLEV))  
        ZZVT15=0.5_JPRB*(&
         & -ZQQ1*ZUT15(JROF,JLEV)+ZPP1*ZVT15(JROF,JLEV)&
         & -ZQQ95*ZZUZ95(JROF,JLEV)+ZPP95*ZZVZ95(JROF,JLEV))  
        ! * compute new origin point:
        ZPHI5=0.5_JPRB*RTDT*SQRT(ZZUT15*ZZUT15+ZZVT15*ZZVT15)/RA
        ZCOPH5=1.0_JPRB-0.5_JPRB*ZPHI5*ZPHI5
        ZSINX5=ZCOPH5*RTDT*(1.0_JPRB-ZPHI5*ZPHI5/6.0_JPRB)/RA
        ZSINLA7(JROF,JLEV)=PGEMU(JROF)*(2.0_JPRB*ZCOPH5*ZCOPH5-1.0_JPRB)&
         & -ZZVT15*PGSQM2(JROF)*ZSINX5  
        ZCOSCO7(JROF,JLEV)=PGSQM2(JROF)*(2.0_JPRB*ZCOPH5*ZCOPH5-1.0_JPRB)&
         & +ZZVT15*PGEMU(JROF)*ZSINX5  
        ZSINCO7(JROF,JLEV)=-ZZUT15*ZSINX5
        ZCOPHI7(JROF,JLEV)=2.0_JPRB*ZCOPH5*ZCOPH5-1.0_JPRB
      ENDDO
    ENDDO
    ! * compute rotation matrix and Coriolis term at the new origin point.
    CALL LARCHE(NPROMA,KST,KPROF,NFLEVG,NSTTYP,ZDSTRET,&
     & RC2M1,RC2P1,RPI,ZDEPI,RLOCEN,RMUCEN,&
     & PCOLON,PSILON,PGEMU,PGSQM2,PGECLO,PGESLO,&
     & ZCOSCO7,ZSINCO7,ZSINLA7,ZCOPHI7,1,ZLON7,ZLAT7,ZP7,ZQ7)  
    CALL LACONE(NPROMA,KST,KPROF,NFLEVG,NSTTYP,&
     & ROMEGA,ZDSTRET,RC2M1,RC2P1,RMUCEN,RA,RPI,&
     & ZLON7,ZLAT7,ZU97,ZV97)  
  ENDIF

ENDIF

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

!*       4.    ADD QUANTITIES INTERPOLATED AT THE MEDIUM AND ORIGIN
!              POINTS TO ARRAYS P(X)T1 FOR EQUATIONS OTHER THAN
!              CONTINUITY EQUATION.
!              ----------------------------------------------------

!        4.4   SPECIAL TREATMENT OF CORIOLIS TERM:
!              CASE "L2TLFF=T".

! * Refined calculation of the origin point.
!   Refined treatment of Coriolis term in 2TL scheme (or in 3TL scheme).
!   Works for the following configurations:
!    - LVERCOR=.F.
!    - 3TL scheme, LADVF=.T. or 2TL SL scheme, LADVF=.T.
!    - NWLAG=3.
!    - RW2TLFF=1. (RW2TLFF in ]0,1[ not coded in AD code).

IF (L2TLFF) THEN

  IF (LRPLANE) THEN
    ! * add new estimate of advected Coriolis term:
    DO JLEV=1,NFLEVG
      DO JROF=KST,KPROF
        ZPP5=ZP7(JROF,JLEV)*PGNORDM(JROF)-ZQ7(JROF,JLEV)*PGNORDL(JROF)
        ZQQ5=ZQ7(JROF,JLEV)*PGNORDM(JROF)+ZP7(JROF,JLEV)*PGNORDL(JROF)
        ZU9(JROF,JLEV)=ZU9(JROF,JLEV)&
         & +ZPP5*PGMVT1(JROF,JLEV,YT1%MU)-ZQQ5*PGMVT1(JROF,JLEV,YT1%MV)  
        ZV9(JROF,JLEV)=ZV9(JROF,JLEV)&
         & +ZQQ5*PGMVT1(JROF,JLEV,YT1%MU)+ZPP5*PGMVT1(JROF,JLEV,YT1%MV)  
        ZPP=ZU97(JROF,JLEV)*PGMVT1(JROF,JLEV,YT1%MU)&
         & +ZV97(JROF,JLEV)*PGMVT1(JROF,JLEV,YT1%MV)  
        ZQQ=ZV97(JROF,JLEV)*PGMVT1(JROF,JLEV,YT1%MU)&
         & -ZU97(JROF,JLEV)*PGMVT1(JROF,JLEV,YT1%MV)  
        PQX(JROF,JLEV)=PQX(JROF,JLEV)&
         & +PGNORDM(JROF)*ZPP+PGNORDL(JROF)*ZQQ  
        PQY(JROF,JLEV)=PQY(JROF,JLEV)&
         & +PGNORDM(JROF)*ZQQ-PGNORDL(JROF)*ZPP  
      ENDDO
    ENDDO

    ! * compute rotation matrix and Coriolis term at the new origin point.
    DO JLEV=1,NFLEVG
      DO JROF=KST,KPROF
        PLON(JROF,JLEV)=PLON(JROF,JLEV)+ZU9(JROF,JLEV)
        PLAT(JROF,JLEV)=PLAT(JROF,JLEV)+ZV9(JROF,JLEV)
      ENDDO
    ENDDO
    ZU9(:,:)=0.0_JPRB
    ZV9(:,:)=0.0_JPRB
    CALL ELARCHEAD(NPROMA,KST,KPROF,NFLEVG,&
     & PGEMU,PGSQM2,PGECLO,PGESLO,&
     & PCOSCO,PSINCO,PQX,PQY,PLON,PLAT,&
     & ZCOSCO7,ZSINCO7,ZLON7,ZLAT7)

    ! * compute new origin point:
    DO JLEV=1,NFLEVG
      DO JROF=KST,KPROF
        ! * compute the new origin point ON.
        ZTXO=ZINEZV(JROF)*PCOSCO(JROF,JLEV)
        ZTYO=ZINEZV(JROF)*PSINCO(JROF,JLEV)
        PCOSCO(JROF,JLEV)=0.0_JPRB
        PSINCO(JROF,JLEV)=0.0_JPRB
        IF ((IOUT(JROF,JLEV) == 1).OR.(IOUT(JROF,JLEV) == 3)) ZTXO=0.0_JPRB
        IF  (IOUT(JROF,JLEV) >= 2) ZTYO=0.0_JPRB
        ZTXO=ZTXO+PLON(JROF,JLEV)*ZINEZV(JROF)
        ZTYO=ZTYO+PLAT(JROF,JLEV)*ZINEZV(JROF)
        PLON(JROF,JLEV)=0.0_JPRB
        PLAT(JROF,JLEV)=0.0_JPRB
        ZZUT1=-2.0_JPRB*ZTXO*ZGMDTX(JROF)
        ZZVT1=-2.0_JPRB*ZTYO*ZGMDTY(JROF)
        ZTXO=0.0_JPRB
        ZTYO=0.0_JPRB
        ! * subtract old estimate of advected coriolis term
        ZPP5=ZP5(JROF,JLEV)*PGNORDM(JROF)-ZQ5(JROF,JLEV)*PGNORDL(JROF)
        ZQQ5=ZQ5(JROF,JLEV)*PGNORDM(JROF)+ZP5(JROF,JLEV)*PGNORDL(JROF)
        ZU9(JROF,JLEV)=ZU9(JROF,JLEV) &
         & -ZPP5*PGMVT1(JROF,JLEV,YT1%MU)+ZQQ5*PGMVT1(JROF,JLEV,YT1%MV)
        ZV9(JROF,JLEV)=ZV9(JROF,JLEV) &
         & -ZQQ5*PGMVT1(JROF,JLEV,YT1%MU)-ZPP5*PGMVT1(JROF,JLEV,YT1%MV)
        ZPP=-ZU96(JROF,JLEV)*PGMVT1(JROF,JLEV,YT1%MU) &
         & -ZV96(JROF,JLEV)*PGMVT1(JROF,JLEV,YT1%MV)
        ZQQ=-ZV96(JROF,JLEV)*PGMVT1(JROF,JLEV,YT1%MU) &
         & +ZU96(JROF,JLEV)*PGMVT1(JROF,JLEV,YT1%MV)
        ! * new estimate of trajectory
        ZZUZ9(JROF,JLEV)=ZZUZ9(JROF,JLEV)+0.5_JPRB*ZZUT1
        ZZVZ9(JROF,JLEV)=ZZVZ9(JROF,JLEV)+0.5_JPRB*ZZVT1
        PGMVT1(JROF,JLEV,YT1%MU)=PGMVT1(JROF,JLEV,YT1%MU)+0.5_JPRB*ZZUT1
        PGMVT1(JROF,JLEV,YT1%MV)=PGMVT1(JROF,JLEV,YT1%MV)+0.5_JPRB*ZZVT1
        ! * compute new origin point
        PQX(JROF,JLEV)=PQX(JROF,JLEV)+PGNORDM(JROF)*ZPP+PGNORDL(JROF)*ZQQ
        PQY(JROF,JLEV)=PQY(JROF,JLEV)-PGNORDL(JROF)*ZPP+PGNORDM(JROF)*ZQQ
      ENDDO
    ENDDO

  ELSE

    ! * add new estimate of advected Coriolis term:
    DO JLEV=1,NFLEVG
      DO JROF=KST,KPROF
        ZPP5=ZP7(JROF,JLEV)*PGNORDM(JROF)-ZQ7(JROF,JLEV)*PGNORDL(JROF)
        ZQQ5=ZQ7(JROF,JLEV)*PGNORDM(JROF)+ZP7(JROF,JLEV)*PGNORDL(JROF)
        ZU9(JROF,JLEV)=ZU9(JROF,JLEV)&
         & +ZPP5*PGMVT1(JROF,JLEV,YT1%MU)-ZQQ5*PGMVT1(JROF,JLEV,YT1%MV)  
        ZV9(JROF,JLEV)=ZV9(JROF,JLEV)&
         & +ZQQ5*PGMVT1(JROF,JLEV,YT1%MU)+ZPP5*PGMVT1(JROF,JLEV,YT1%MV)  
        ZPP=ZU97(JROF,JLEV)*PGMVT1(JROF,JLEV,YT1%MU)&
         & +ZV97(JROF,JLEV)*PGMVT1(JROF,JLEV,YT1%MV)  
        ZQQ=ZV97(JROF,JLEV)*PGMVT1(JROF,JLEV,YT1%MU)&
         & -ZU97(JROF,JLEV)*PGMVT1(JROF,JLEV,YT1%MV)  
        PQX(JROF,JLEV)=PQX(JROF,JLEV)&
         & +PGNORDM(JROF)*ZPP+PGNORDL(JROF)*ZQQ  
        PQY(JROF,JLEV)=PQY(JROF,JLEV)&
         & +PGNORDM(JROF)*ZQQ-PGNORDL(JROF)*ZPP  
      ENDDO
    ENDDO

    ! * compute rotation matrix and Coriolis term at the new origin point.
    CALL LACONEAD(NPROMA,KST,KPROF,NFLEVG,NSTTYP,&
     & ROMEGA,ZDSTRET,RC2M1,RC2P1,RMUCEN,RA,RPI,&
     & ZLON7,ZLAT7,ZU97,ZV97,PLON,PLAT,ZU9,ZV9)  
    CALL LARCHEAD(NPROMA,KST,KPROF,NFLEVG,NSTTYP,ZDSTRET,&
     & RC2M1,RC2P1,RPI,ZDEPI,RLOCEN,RMUCEN,&
     & PCOLON,PSILON,PGEMU,PGSQM2,PGECLO,PGESLO,&
     & PCOSCO,PSINCO,PSINLA,PCOPHI,&
     & ZCOSCO7,ZSINCO7,ZSINLA7,ZCOPHI7,1,&
     & PLON,PLAT,PQX,PQY)  
    ZU9(:,:)=0.0_JPRB
    ZV9(:,:)=0.0_JPRB

    ! * compute new origin point:
    DO JLEV=1,NFLEVG
      DO JROF=KST,KPROF
        ZPP1=PGNORDM(JROF)
        ZQQ1=-PGNORDL(JROF)

        ZPP5=ZP5(JROF,JLEV)*PGNORDM(JROF)-ZQ5(JROF,JLEV)*PGNORDL(JROF)
        ZQQ5=ZQ5(JROF,JLEV)*PGNORDM(JROF)+ZP5(JROF,JLEV)*PGNORDL(JROF)
        ZPP95=ZP5(JROF,JLEV)
        ZQQ95=ZQ5(JROF,JLEV)
        ! * new estimate of trajectory wind for traj:
        ZZUT15=0.5_JPRB*(&
         & ZPP1*ZUT15(JROF,JLEV)+ZQQ1*ZVT15(JROF,JLEV)&
         & +ZPP95*ZZUZ95(JROF,JLEV)+ZQQ95*ZZVZ95(JROF,JLEV))  
        ZZVT15=0.5_JPRB*(&
         & -ZQQ1*ZUT15(JROF,JLEV)+ZPP1*ZVT15(JROF,JLEV)&
         & -ZQQ95*ZZUZ95(JROF,JLEV)+ZPP95*ZZVZ95(JROF,JLEV))  
        ! * subtract old estimate of advected Coriolis term for traj:
        ZUT15(JROF,JLEV)=ZUT15(JROF,JLEV)&
         & -ZPP5*ZU95(JROF,JLEV)-ZQQ5*ZV95(JROF,JLEV)  
        ZVT15(JROF,JLEV)=ZVT15(JROF,JLEV)&
         & +ZQQ5*ZU95(JROF,JLEV)-ZPP5*ZV95(JROF,JLEV)  
        ! * compute new origin point for traj:
        ZPHI5=0.5_JPRB*RTDT*SQRT(ZZUT15*ZZUT15+ZZVT15*ZZVT15)/RA
        ZCOPH5=1.0_JPRB-0.5_JPRB*ZPHI5*ZPHI5
        ZSINX5=ZCOPH5*RTDT*(1.0_JPRB-ZPHI5*ZPHI5/6.0_JPRB)/RA

        ! * compute new origin point:
        ZCOPH=4.0_JPRB*ZCOPH5*PCOPHI(JROF,JLEV)
        ZZUT1=-ZSINX5*PSINCO(JROF,JLEV)
        ZSINX=-ZZUT15*PSINCO(JROF,JLEV)
        ZCOPH=ZCOPH+PGSQM2(JROF)*4.0_JPRB*ZCOPH5*PCOSCO(JROF,JLEV)
        ZZVT1=PGEMU(JROF)*ZSINX5*PCOSCO(JROF,JLEV)
        ZSINX=ZSINX+PGEMU(JROF)*ZZVT15*PCOSCO(JROF,JLEV)
        ZCOPH=ZCOPH+PGEMU(JROF)*4.0_JPRB*ZCOPH5*PSINLA(JROF,JLEV)
        ZZVT1=ZZVT1-PGSQM2(JROF)*ZSINX5*PSINLA(JROF,JLEV)
        ZSINX=ZSINX-PGSQM2(JROF)*ZZVT15*PSINLA(JROF,JLEV)
        ZCOPH=ZCOPH+RTDT*(1.0_JPRB-ZPHI5*ZPHI5/6.0_JPRB)*ZSINX/RA
        ZPHI=-RTDT*(ZCOPH5*ZPHI5/3.0_JPRB)*ZSINX/RA
        ZPHI=ZPHI-ZPHI5*ZCOPH
        ZZUT1=ZZUT1+0.5_JPRB*RTDT*ZZUT15*ZPHI/&
         & (RA*SQRT(ZZUT15*ZZUT15+ZZVT15*ZZVT15))  
        ZZVT1=ZZVT1+0.5_JPRB*RTDT*ZZVT15*ZPHI/&
         & (RA*SQRT(ZZUT15*ZZUT15+ZZVT15*ZZVT15))  
        ! * subtract old estimate of advected Coriolis term:
        ZU9(JROF,JLEV) = ZU9(JROF,JLEV) &
         & -ZPP5*PGMVT1(JROF,JLEV,YT1%MU) +ZQQ5*PGMVT1(JROF,JLEV,YT1%MV)  
        ZV9(JROF,JLEV) = ZV9(JROF,JLEV) &
         & -ZQQ5*PGMVT1(JROF,JLEV,YT1%MU) -ZPP5*PGMVT1(JROF,JLEV,YT1%MV)  
        ZPP=-ZU96(JROF,JLEV)*PGMVT1(JROF,JLEV,YT1%MU) &
         & -ZV96(JROF,JLEV)*PGMVT1(JROF,JLEV,YT1%MV)  
        ZQQ=-ZV96(JROF,JLEV)*PGMVT1(JROF,JLEV,YT1%MU) &
         & +ZU96(JROF,JLEV)*PGMVT1(JROF,JLEV,YT1%MV)  
        ! * new estimate of trajectory wind:
        PGMVT1(JROF,JLEV,YT1%MU)=PGMVT1(JROF,JLEV,YT1%MU) &
         & +0.5_JPRB*(ZPP1*ZZUT1-ZQQ1*ZZVT1)
        PGMVT1(JROF,JLEV,YT1%MV)=PGMVT1(JROF,JLEV,YT1%MV) &
         & +0.5_JPRB*(ZQQ1*ZZUT1+ZPP1*ZZVT1)
        ZPP9=0.5_JPRB*(ZZUZ95(JROF,JLEV)*ZZUT1+ZZVZ95(JROF,JLEV)*ZZVT1)
        ZQQ9=0.5_JPRB*(ZZVZ95(JROF,JLEV)*ZZUT1-ZZUZ95(JROF,JLEV)*ZZVT1)
        ZZUZ9(JROF,JLEV)=ZZUZ9(JROF,JLEV)+0.5_JPRB*(ZPP95*ZZUT1-ZQQ95*ZZVT1)  
        ZZVZ9(JROF,JLEV)=ZZVZ9(JROF,JLEV)+0.5_JPRB*(ZQQ95*ZZUT1+ZPP95*ZZVT1)  
        ! * compute new origin point:
        PQX(JROF,JLEV)=PQX(JROF,JLEV)+ZPP9
        PQY(JROF,JLEV)=PQY(JROF,JLEV)+ZQQ9
        PQX(JROF,JLEV)=PQX(JROF,JLEV)+PGNORDM(JROF)*ZPP+PGNORDL(JROF)*ZQQ  
        PQY(JROF,JLEV)=PQY(JROF,JLEV)-PGNORDL(JROF)*ZPP+PGNORDM(JROF)*ZQQ  
        PSINCO(JROF,JLEV)=0.0_JPRB
        PCOSCO(JROF,JLEV)=0.0_JPRB
        PSINLA(JROF,JLEV)=0.0_JPRB
        PCOPHI(JROF,JLEV)=0.0_JPRB
      ENDDO
    ENDDO

  ENDIF

ENDIF

!        4.3   ADD CORIOLIS TERM AT "F" WHEN NOT DONE IN ROUTINE "LATTEX"

! * Involves the cases of lvercor=.true. when "rs/a" is needed at t+dt.
!   In this case work cannot be done in routine "LATTEX" because
!   at this stage of calculations "rs/a"(t+dt) is not yet available.
!   ==> AD not yet coded.

!        4.2   SPECIAL TREATMENT OF CORIOLIS TERM.

! * Relaxation of thin layer hypothesis is currently not coded in TL code.
LLVERCOR=.FALSE.
LLADVFW=.FALSE.

LLCOMPUTE_OMVAK_O= &
 & (((.NOT.LLVERCOR).AND.LADVF).OR.(LLVERCOR.AND.(LADVF.OR.LLADVFW)))

IF (LLCOMPUTE_OMVAK_O) THEN
  ! First compute trajectory
  IF(LRPLANE) THEN
    ! calculation of LACONE done already in ELARCHE -> results are in
    !  zlon, zlat tables. 
    ZU96(KST:KPROF,1:NFLEVG)=PLON5(KST:KPROF,1:NFLEVG)
    ZV96(KST:KPROF,1:NFLEVG)=PLAT5(KST:KPROF,1:NFLEVG)
  ELSE
    ! First run LACONE on trajectory values: (=> ZU96,ZV96)
    CALL LACONE(NPROMA,KST,KPROF,NFLEVG,NSTTYP,&
     & ROMEGA,ZDSTRET,RC2M1,RC2P1,RMUCEN,&
     & RA,RPI,PLON5,PLAT5,ZU96,ZV96)  
  ENDIF
  DO JLEV=1,NFLEVG
    DO JROF=KST,KPROF
      ZPP5=ZP5(JROF,JLEV)*PGNORDM(JROF)-ZQ5(JROF,JLEV)*PGNORDL(JROF)
      ZQQ5=ZQ5(JROF,JLEV)*PGNORDM(JROF)+ZP5(JROF,JLEV)*PGNORDL(JROF)
      ZU9(JROF,JLEV)=ZU9(JROF,JLEV) &
       & +ZPP5*PGMVT1(JROF,JLEV,YT1%MU)-ZQQ5*PGMVT1(JROF,JLEV,YT1%MV)  
      ZV9(JROF,JLEV)=ZV9(JROF,JLEV) &
       & +ZQQ5*PGMVT1(JROF,JLEV,YT1%MU)+ZPP5*PGMVT1(JROF,JLEV,YT1%MV)  
      ZPP=ZU96(JROF,JLEV)*PGMVT1(JROF,JLEV,YT1%MU) &
       & +ZV96(JROF,JLEV)*PGMVT1(JROF,JLEV,YT1%MV)  
      ZQQ=ZV96(JROF,JLEV)*PGMVT1(JROF,JLEV,YT1%MU) &
       & -ZU96(JROF,JLEV)*PGMVT1(JROF,JLEV,YT1%MV)  
      PQX(JROF,JLEV)=PQX(JROF,JLEV)+PGNORDM(JROF)*ZPP+PGNORDL(JROF)*ZQQ
      PQY(JROF,JLEV)=PQY(JROF,JLEV)+PGNORDM(JROF)*ZQQ-PGNORDL(JROF)*ZPP
    ENDDO
  ENDDO
  IF(LRPLANE) THEN
    DO JLEV=1,NFLEVG
      DO JROF=KST,KPROF
        PLON(JROF,JLEV)=PLON(JROF,JLEV)+ZU9(JROF,JLEV)
        PLAT(JROF,JLEV)=PLAT(JROF,JLEV)+ZV9(JROF,JLEV)
      ENDDO
    ENDDO
  ELSE
    ! N.B. ZU95 and ZV95 are not altered by LACONEAD:
    CALL LACONEAD(NPROMA,KST,KPROF,NFLEVG,NSTTYP,&
     & ROMEGA,ZDSTRET,RC2M1,RC2P1,RMUCEN,&
     & RA,RPI,PLON5,PLAT5,ZU95,ZV95,PLON,PLAT,ZU9,ZV9)  
  ENDIF
  ZU9(:,:)=0.0_JPRB
  ZV9(:,:)=0.0_JPRB
ENDIF

!        4.1   ADD CONTRIBUTIONS.

DO JLEV=1,NFLEVG
  DO JROF=KST,KPROF
    ZPP5=ZP5(JROF,JLEV)*PGNORDM(JROF)-ZQ5(JROF,JLEV)*PGNORDL(JROF)
    ZQQ5=ZQ5(JROF,JLEV)*PGNORDM(JROF)+ZP5(JROF,JLEV)*PGNORDL(JROF)
    ZU9(JROF,JLEV)=ZU9(JROF,JLEV) &
     & +ZPP5*PGMVT1(JROF,JLEV,YT1%MU)-ZQQ5*PGMVT1(JROF,JLEV,YT1%MV)  
    ZV9(JROF,JLEV)=ZV9(JROF,JLEV) &
     & +ZQQ5*PGMVT1(JROF,JLEV,YT1%MU)+ZPP5*PGMVT1(JROF,JLEV,YT1%MV)  
    ZPP=ZU95(JROF,JLEV)*PGMVT1(JROF,JLEV,YT1%MU) &
     & +ZV95(JROF,JLEV)*PGMVT1(JROF,JLEV,YT1%MV)  
    ZQQ=ZV95(JROF,JLEV)*PGMVT1(JROF,JLEV,YT1%MU) &
     & -ZU95(JROF,JLEV)*PGMVT1(JROF,JLEV,YT1%MV)  
    PQX(JROF,JLEV)=PQX(JROF,JLEV)+PGNORDM(JROF)*ZPP+PGNORDL(JROF)*ZQQ
    PQY(JROF,JLEV)=PQY(JROF,JLEV)+PGNORDM(JROF)*ZQQ-PGNORDL(JROF)*ZPP
  ENDDO
ENDDO

DO JLEV=1,NFLEVG
  DO JROF=KST,KPROF
    ZT9(JROF,JLEV)=ZT9(JROF,JLEV)+PGMVT1(JROF,JLEV,YT1%MT)
  ENDDO
ENDDO

DO JGFL=1,YGFL%NUMFLDS
  IF(YGFLC(JGFL)%LADV) THEN
    DO JLEV=1,NFLEVG
      DO JROF=KST,KPROF
        ZGFL9(JROF,JLEV,JGFL)=ZGFL9(JROF,JLEV,JGFL)+ &
         & PGFLT1(JROF,JLEV,YGFLC(JGFL)%MP1)  
      ENDDO
    ENDDO
  ENDIF
ENDDO

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

!*       3.    ADD QUANTITIES INTERPOLATED AT THE ORIGIN POINT
!              TO ARRAYS P(X)T1 FOR CONTINUITY EQUATION.
!              -----------------------------------------------

IF (NVLAG == 2) THEN   !!! TL/AD not done !!!

ELSEIF (NVLAG == 3) THEN

  IF(LVERTFE) THEN
    ZSPTO(KST:KPROF,1:NFLEVG)=0.0_JPRB
    ZSPTO(KST:KPROF,NFLEVG+1)=PGMVT1S(KST:KPROF,YT1%MSP)
    CALL VERINTAD(NPROMA,KST,KPROF,NFLEVG,ZSPT1,ZSPTO,0)
    DO JLEV=1,NFLEVG
      DO JROF=KST,KPROF
        ZC9(JROF,JLEV)=ZC9(JROF,JLEV)&
         & +VDELB(JLEV)*VFE_RDETAH(JLEV)*ZSPT1(JROF,JLEV)  
        ZDP9(JROF,JLEV)=ZDP9(JROF,JLEV)&
         & +VDELB(JLEV)*VFE_RDETAH(JLEV)*ZSPT1(JROF,JLEV)  
      ENDDO
    ENDDO
  ELSE
    DO JLEV=1,NFLEVG
      DO JROF=KST,KPROF
        ZDP9(JROF,JLEV)=ZDP9(JROF,JLEV)+VDELB(JLEV)*PGMVT1S(JROF,YT1%MSP)
        ZC9(JROF,JLEV)=ZC9(JROF,JLEV)+VDELB(JLEV)*PGMVT1S(JROF,YT1%MSP)
      ENDDO
    ENDDO
  ENDIF

ENDIF

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

!*       2.    INTERPOLATIONS AT THE ORIGIN POINT
!              ----------------------------------

CALL LARCINBAD(KSTGLO,KST,KPROF,LL2TLFFO,KDIM,KDEP,KLOCK,KL0,KLH0,&
 & PDLO,PCLO,PCLOSLD,PDLAT,PCLA,PCLASLD,PDVER,PVINTW,PVINTWSLD,PB1,PB15,&
 & PINC,KINC,KDIM1,KDIM2,&
 & ZDP9,ZU9,ZV9,ZT9,ZGFL9,ZC9,ZZUZ9,ZZVZ9,&
 & PDLO5,PCLO5,PCLOSLD5,PDLAT5,PCLA5,PCLASLD5,PDVER5,PVINTW5,PVINTWSLD5)

IF(LRPLANE) THEN
  ! * The PLON,PLAT perturbations are passed to
  !   LAPINEAAD in the PSINLA,PCOPHY arrays similarly
  !   to the NL code arrangement.
  DO JLEV=1,NFLEVG
    DO JROF=KST,KPROF
      PSINLA(JROF,JLEV)= PLON(JROF,JLEV)+PSINLA(JROF,JLEV)
      PCOPHI(JROF,JLEV)= PLAT(JROF,JLEV)+PCOPHI(JROF,JLEV)
    ENDDO
  ENDDO
  PLON(KST:KPROF,:) = 0.0_JPRB
  PLAT(KST:KPROF,:) = 0.0_JPRB
ENDIF
!     ------------------------------------------------------------------

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