SUBROUTINE LADINEAD(KSTART,KPROF,KASLB1,KPROMA,KFLDN,KFLDX,&
 & PCOLON,PSILON,PGEMU,PGSQM2,PGECLO,&
 & PGESLO,PGNORDL,PGNORDM,PINDX,PINDY,&
 & PSLBUF1,PURL0,PVRL0,PURL,PVRL,&
 & PUL0,PVL0,PCL0,PUL9,PVL9,PCL9,&
 & PURL05,PVRL05,PURL5,PVRL5,&
 & PUL05,PVL05,PCL05,PUL95,PVL95,PCL95,&
 & PUSI,PVSI,PUSI5,PVSI5,&
 & PUT1,PVT1,PSPT1,PUT15,PVT15 )  

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

USE YOMDIM   , ONLY : NDGSAG   ,NDGSAL   ,NDGENG   ,NDGENL   ,&
 & NDGUNG   ,NDGUXG   ,NDLUNG   ,NDLUXG   ,NDGSAH   ,NDGENH  
USE YOMCT0   , ONLY : LRPLANE
USE YOMDYN   , ONLY : NVLAG    ,NWLAG    ,NITMP    ,LADVF    ,LQMHW    ,&
 & LQMHP    ,LSETTLST ,L2TLFF   ,LELTRA  
USE YOMCST   , ONLY : RPI      ,ROMEGA   ,RA
USE YOMLEG   , ONLY : RLATI    ,RIPI0    ,RIPI1    ,RIPI2
USE YOMGEM   , ONLY : NLOENG   ,NSTTYP   ,&
 & RMUCEN   ,RLOCEN   ,RSTRET   ,R4JP     ,RC2P1    ,RC2M1  
USE YOMRIP   , ONLY : RDTSA    ,RDTS62   ,RDTS22   ,RTDT
USE YOMSC2   , ONLY : NSLWIDE  ,NFLDSLB1
USE YOMMP    , ONLY : NSLOFF   ,NFRSTLOFF

!**** *LADINEAD* - semi-LAgrangian scheme:   (adjoint version)
!                Interface subroutine for interpolations and lagrangian
!                trends. (Programme INterface d'Ensemble).
!                2D Shallow water.

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

!           Computes the medium point M and origin point O.
!           Does interpolations at O.
!           Computes lagrangian trends.

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

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

!        INPUT:
!          KSTART  - first element of arrays where
!                    computations are performed.
!          KPROF   - depth of work.
!          KASLB1  - horizontal dimension for semi-Lagrangian buffer.
!          KPROMA  - horizontal dimension.
!          KFLDN   - number of the first field for semi-lag variables.
!          KFLDX   - number of the last field for semi-lag variables.
!          PCOLON  - cosine of the grid-point longitude on the
!                    computational sphere.
!          PSILON  - sine of the grid-point 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.
!          PGNORDL - zonal component of the normalized vector directed
!                    towards the geographical north pole.
!          PGNORDM - meridian component of the normalized vector directed
!                    towards the geographical north pole.
!          PINDX   - x coordinate on the plane.
!          PINDY   - y coordinate on the plane.
! ---------------------------- trajectory variables ----------------------
!          PURL05  - U-component of the wind, to be interpolated.
!          PVRL05  - V-component of the wind, to be interpolated.
!          PURL5   - U-component of the wind for research of medium point.
!          PVRL5   - V-component of the wind for research of medium point.
!          PUL05   - Quantity to interpolate linearly at O in the
!                    U-wind equation if NWLAG=3.
!          PVL05   - Quantity to interpolate linearly at O in the
!                    V-wind equation if NWLAG=3.
!          PCL05   - Quantity to interpolate linearly at O in the
!                    continuity equation if NVLAG=3.
!          PUL95   - Quantity to interpolate at O in the U-wind equation.
!          PVL95   - Quantity to interpolate at O in the V-wind equation.
!          PCL95   - Quantity to interpolate at O in the continuity equation.
!          PUSI5   - Semi-implicit term in the U-equation  ) needed for
!          PVSI5   - Semi-implicit term in the V-equation  ) L2TLFF
!          PUT15   - t+dt U-wind                           )
!          PVT15   - t+dt V-wind                           )
! ------------------------------------------------------------------------

!        INPUT AND OUTPUT:
!          PSLBUF1 - semi-Lagrangian buffers for interpolations.
!          PUT1    - t+dt U-wind.
!          PVT1    - t+dt V-wind.
!          PSPT1   - t+dt equivalent height.
!          PURL0   - U-component of the wind, to be interpolated.
!          PVRL0   - V-component of the wind, to be interpolated.
!          PURL    - U-component of the wind for research of medium point.
!          PVRL    - V-component of the wind for research of medium point.
!          PUL0    - Quantity to interpolate linearly at O in the
!                    U-wind equation if NWLAG=3.
!          PVL0    - Quantity to interpolate linearly at O in the
!                    V-wind equation if NWLAG=3.
!          PCL0    - Quantity to interpolate linearly at O in the
!                    continuity equation if NVLAG=3.
!          PUL9    - Quantity to interpolate at O in the U-wind equation.
!          PVL9    - Quantity to interpolate at O in the V-wind equation.
!          PCL9    - Quantity to interpolate at O in the continuity equation.
!          PUSI    - Semi-implicit term in the U-equation  ) needed for
!          PVSI    - Semi-implicit term in the V-equation  ) L2TLFF

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

!     Method.
!     -------

!     Externals.    LARMES25 -Computes the medium point coordinates then
!     ----------              interpolations at this point. (repeat of
!                             LARMES2, intermediate results saved)
!                   LAINOR2  -Computes the origin point coordinates then
!                             interpolations at this point.
!                   LARMES2AD-Computes the medium point coordinates then
!                             interpolations at this point.
!                   LAINOR2AD-Computes the origin point coordinates then
!                             interpolations at this point.
!                   Called by CPG2LAGAD.

!     Reference.
!     ----------
!        ARPEGE documentation vol 2 ch 1 and vol 3 ch 6

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

!     Modifications.
!     --------------
!   Original : 98/10/22
!   Modified 98-12-22 by C.Temperton: Cleaning, following LADINE.
!   Modified 99-01-07 by C.Temperton: LCORAN option added.
!   Modified 99-01-15 by C.Temperton: Introduction of LARMES25.
!   Modified 99-03-15 by C.Temperton: allow LELTRA for trajectory
!    together with LSETTLS for RHS; fixes for LCUTRA
!   Modified 99-06-23 by C.Temperton: L2TLFF option added.
!   Modified 00-03-06 by C.Temperton: Repairs following optimization
!                                     of 3-D semi-Lagrangian adjoint.
!   Modified 01-08-30 by K. YESSAD: pruning and some other cleanings.
!   R. El Khatib : 01-08-07 Pruning options
!   M.Hamrud      01-Oct-2003 CY28 Cleaning
!   N. Wedi and K. Yessad (Jan 2008): different dev for NH model and PC scheme
!   K. Yessad Nov 2008: rationalisation of dummy argument interfaces
!     ------------------------------------------------------------------

IMPLICIT NONE

INTEGER(KIND=JPIM),INTENT(IN)    :: KASLB1 
INTEGER(KIND=JPIM),INTENT(IN)    :: KPROMA 
INTEGER(KIND=JPIM),INTENT(IN)    :: KFLDN 
INTEGER(KIND=JPIM),INTENT(IN)    :: KFLDX 
INTEGER(KIND=JPIM),INTENT(IN)    :: KSTART 
INTEGER(KIND=JPIM),INTENT(IN)    :: KPROF 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PCOLON(KPROMA) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PSILON(KPROMA) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PGEMU(KPROMA) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PGSQM2(KPROMA) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PGECLO(KPROMA) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PGESLO(KPROMA) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PGNORDL(KPROMA) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PGNORDM(KPROMA) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PINDX(KPROMA) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PINDY(KPROMA) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PSLBUF1(KASLB1,NFLDSLB1) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PURL0(KASLB1,KFLDN:KFLDX) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PVRL0(KASLB1,KFLDN:KFLDX) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PURL(KPROMA) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PVRL(KPROMA) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PUL0(KASLB1,KFLDN:KFLDX) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PVL0(KASLB1,KFLDN:KFLDX) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PCL0(KASLB1,KFLDN:KFLDX) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PUL9(KASLB1,KFLDN:KFLDX) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PVL9(KASLB1,KFLDN:KFLDX) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PCL9(KASLB1,KFLDN:KFLDX) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PURL05(KASLB1,KFLDN:KFLDX) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PVRL05(KASLB1,KFLDN:KFLDX) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PURL5(KPROMA) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PVRL5(KPROMA) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PUL05(KASLB1,KFLDN:KFLDX) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PVL05(KASLB1,KFLDN:KFLDX) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PCL05(KASLB1,KFLDN:KFLDX) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PUL95(KASLB1,KFLDN:KFLDX) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PVL95(KASLB1,KFLDN:KFLDX) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PCL95(KASLB1,KFLDN:KFLDX) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PUSI(KPROMA) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PVSI(KPROMA) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PUSI5(KPROMA) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PVSI5(KPROMA) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PUT1(KPROMA) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PVT1(KPROMA) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PSPT1(KPROMA) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PUT15(KPROMA) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PVT15(KPROMA) 

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

! - trigonometric arrays.
REAL(KIND=JPRB) :: ZSINCO(KPROMA)
REAL(KIND=JPRB) :: ZCOSCO(KPROMA)
REAL(KIND=JPRB) :: ZSINLA(KPROMA)
REAL(KIND=JPRB) :: ZCOPHI(KPROMA)
REAL(KIND=JPRB) :: ZP    (KPROMA)
REAL(KIND=JPRB) :: ZQ    (KPROMA)
REAL(KIND=JPRB) :: ZR    (KPROMA)
REAL(KIND=JPRB) :: ZS    (KPROMA)
REAL(KIND=JPRB) :: ZSINCO5(KPROMA,NITMP)
REAL(KIND=JPRB) :: ZCOSCO5(KPROMA,NITMP)
REAL(KIND=JPRB) :: ZSINLA5(KPROMA,NITMP)
REAL(KIND=JPRB) :: ZCOPHI5(KPROMA,NITMP)
REAL(KIND=JPRB) :: ZP5    (KPROMA)
REAL(KIND=JPRB) :: ZQ5    (KPROMA)
REAL(KIND=JPRB) :: ZR5    (KPROMA,NITMP)
REAL(KIND=JPRB) :: ZS5    (KPROMA,NITMP)
REAL(KIND=JPRB) :: ZSINCO6(KPROMA)
REAL(KIND=JPRB) :: ZCOSCO6(KPROMA)
REAL(KIND=JPRB) :: ZSINLA6(KPROMA)
REAL(KIND=JPRB) :: ZCOPHI6(KPROMA)
REAL(KIND=JPRB) :: ZP7    (KPROMA)
REAL(KIND=JPRB) :: ZQ7    (KPROMA)
REAL(KIND=JPRB) :: ZSINCO7(KPROMA)
REAL(KIND=JPRB) :: ZCOSCO7(KPROMA)
REAL(KIND=JPRB) :: ZSINLA7(KPROMA)
REAL(KIND=JPRB) :: ZCOPHI7(KPROMA)
REAL(KIND=JPRB) :: ZLON   (KPROMA)
REAL(KIND=JPRB) :: ZLAT   (KPROMA)
REAL(KIND=JPRB) :: ZLON5  (KPROMA)
REAL(KIND=JPRB) :: ZLAT5  (KPROMA)
REAL(KIND=JPRB) :: ZLON7  (KPROMA)
REAL(KIND=JPRB) :: ZLAT7  (KPROMA)
REAL(KIND=JPRB) :: ZLSDEPI(NDGSAH:NDGENH)
! - interpolated quantities arrays.
REAL(KIND=JPRB) :: ZU9(KPROMA)
REAL(KIND=JPRB) :: ZV9(KPROMA)
REAL(KIND=JPRB) :: ZC9(KPROMA)
REAL(KIND=JPRB) :: ZZUZ9(KPROMA)         ! To allow L2TLFF option
REAL(KIND=JPRB) :: ZZVZ9(KPROMA)         ! To allow L2TLFF option
REAL(KIND=JPRB) :: ZU95(KPROMA)
REAL(KIND=JPRB) :: ZV95(KPROMA)
REAL(KIND=JPRB) :: ZC95(KPROMA)
REAL(KIND=JPRB) :: ZU96(KPROMA)
REAL(KIND=JPRB) :: ZV96(KPROMA)
REAL(KIND=JPRB) :: ZUF5(KPROMA,NITMP)
REAL(KIND=JPRB) :: ZVF5(KPROMA,NITMP)
REAL(KIND=JPRB) :: ZZUZ95(KPROMA)         ! To allow L2TLFF option
REAL(KIND=JPRB) :: ZZVZ95(KPROMA)         ! To allow L2TLFF option
REAL(KIND=JPRB) :: ZU97(KPROMA)
REAL(KIND=JPRB) :: ZV97(KPROMA)
REAL(KIND=JPRB) :: ZUT15(KPROMA)
REAL(KIND=JPRB) :: ZVT15(KPROMA)

INTEGER(KIND=JPIM) :: ISTALAT(NDGSAH:NDGENH)

INTEGER(KIND=JPIM) :: IGLGLO, JGL, JROF

LOGICAL :: LLSETTLST

REAL(KIND=JPRB) :: ZCOPH, ZDEPI, ZDSTRET, ZPHI, ZPIS2, ZPP,&
 & ZPP5, ZQQ, ZQQ5, ZSINX,&
 & ZPP95, ZQQ95, ZZUT15, ZZVT15, ZPHI5, ZCOPH5, ZSINX5,&
 & ZPP1, ZQQ1, ZZUT1, ZZVT1, ZPP9, ZQQ9  
REAL(KIND=JPRB) :: ZHOOK_HANDLE

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

#include "lacone.intfb.h"
#include "laconead.intfb.h"
#include "lainor2.intfb.h"
#include "lainor2ad.intfb.h"
#include "larche.intfb.h"
#include "larchead.intfb.h"
#include "larmes2ad.intfb.h"
#include "larmes25.intfb.h"

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

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

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

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

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

ZDSTRET=2.0_JPRB*RSTRET
DO JGL=MAX(NDGSAG,NDGSAL+NFRSTLOFF-NSLWIDE)-NFRSTLOFF,&
   & MIN(NDGENG,NDGENL+NFRSTLOFF+NSLWIDE)-NFRSTLOFF  
  IGLGLO=JGL+NFRSTLOFF
  ZLSDEPI(JGL)=REAL(NLOENG(IGLGLO),JPRB)/ZDEPI
ENDDO

DO JGL=MAX(NDGSAH,LBOUND(NSLOFF,1)),MIN(NDGENH,UBOUND(NSLOFF,1))
  ISTALAT(JGL)=NSLOFF(JGL)
ENDDO

! * Zero local trig arrays:
ZSINCO(1:KPROMA)=0.0_JPRB
ZCOSCO(1:KPROMA)=0.0_JPRB
ZSINLA(1:KPROMA)=0.0_JPRB
ZCOPHI(1:KPROMA)=0.0_JPRB
ZP(1:KPROMA)=0.0_JPRB
ZQ(1:KPROMA)=0.0_JPRB
ZR(1:KPROMA)=0.0_JPRB
ZS(1:KPROMA)=0.0_JPRB
ZLON(1:KPROMA)=0.0_JPRB
ZLAT(1:KPROMA)=0.0_JPRB

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

!              FIRST RERUN TRAJECTORY CALCULATIONS
!              -----------------------------------

LLSETTLST=LSETTLST.AND.(.NOT.LELTRA)
CALL LARMES25(KASLB1,KPROMA,KSTART,KPROF,NDGSAH,NDGENH,&
 & KFLDN,KFLDX,NDLUNG,NDLUXG,NDGUNG,NDGUXG,&
 & ISTALAT,&
 & NVLAG,NWLAG,NITMP,&
 & LRPLANE,LLSETTLST,LELTRA,&
 & PURL05,PVRL05,PURL5,PVRL5,&
 & NSTTYP,ZDSTRET,RC2M1,RC2P1,R4JP,RPI,ZDEPI,ZPIS2,&
 & RDTSA,RDTS62,RDTS22,&
 & RLOCEN,RMUCEN,ZLSDEPI,RLATI(NDGSAH),RIPI0(NDGSAH),&
 & RIPI1(NDGSAH),RIPI2(NDGSAH),&
 & PCOLON,PSILON,PGEMU,PGSQM2,PGECLO,PGESLO,&
 & PGNORDL,PGNORDM,&
 & ZCOSCO5,ZSINCO5,ZSINLA5,ZCOPHI5,&
 & ZR5,ZS5,ZUF5,ZVF5)  

ZCOSCO6(KSTART:KPROF)=ZCOSCO5(KSTART:KPROF,NITMP)
ZSINCO6(KSTART:KPROF)=ZSINCO5(KSTART:KPROF,NITMP)
ZSINLA6(KSTART:KPROF)=ZSINLA5(KSTART:KPROF,NITMP)
ZCOPHI6(KSTART:KPROF)=ZCOPHI5(KSTART:KPROF,NITMP)

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

! Not all the output from LAINOR2 is useful!
! In the 3-d model it will be worth having a special version.

CALL LAINOR2(KASLB1,KPROMA,KSTART,KPROF,NDGSAH,NDGENH,KFLDN,KFLDX,&
 & NDLUNG,NDLUXG,NDGUNG,NDGUXG,&
 & ISTALAT,&
 & NVLAG,NWLAG,&
 & LRPLANE,LQMHW,LQMHP,&
 & PUL95,PVL95,PCL95,PUL05,PVL05,PCL05,&
 & PINDX,PINDY,&
 & NSTTYP,ZDSTRET,RC2M1,RC2P1,R4JP,RPI,ZDEPI,ZPIS2,&
 & RLOCEN,RMUCEN,ZLSDEPI,RLATI(NDGSAH),RIPI0(NDGSAH),&
 & RIPI1(NDGSAH),RIPI2(NDGSAH),&
 & PCOLON,PSILON,PGEMU,PGSQM2,PGECLO,PGESLO,&
 & ZCOSCO6,ZSINCO6,ZSINLA6,ZCOPHI6,&
 & ZLON5,ZLAT5,&
 & ZP5,ZQ5,&
 & ZU95,ZV95,ZC95,&
 & ZZUZ95,ZZVZ95)  

IF (L2TLFF) THEN

  DO JROF=KSTART,KPROF
    ZPP5=ZP5(JROF)*PGNORDM(JROF)-ZQ5(JROF)*PGNORDL(JROF)
    ZQQ5=ZQ5(JROF)*PGNORDM(JROF)+ZP5(JROF)*PGNORDL(JROF)
    ZUT15(JROF) = PUT15(JROF) + ZPP5*ZU95(JROF) + ZQQ5*ZV95(JROF)
    ZVT15(JROF) = PVT15(JROF) + ZPP5*ZV95(JROF) - ZQQ5*ZU95(JROF)
  ENDDO

  IF (LADVF) THEN

    CALL LACONE(KPROMA,KSTART,KPROF,1,NSTTYP,&
     & ROMEGA,ZDSTRET,RC2M1,RC2P1,RMUCEN,&
     & RA,RPI,ZLON5,ZLAT5,ZU96,ZV96)  

    DO JROF=KSTART,KPROF
      ZPP5=ZP5(JROF)*PGNORDM(JROF)-ZQ5(JROF)*PGNORDL(JROF)
      ZQQ5=ZQ5(JROF)*PGNORDM(JROF)+ZP5(JROF)*PGNORDL(JROF)
      ZUT15(JROF) = ZUT15(JROF) + ZPP5*ZU96(JROF) + ZQQ5*ZV96(JROF)
      ZVT15(JROF) = ZVT15(JROF) - ZQQ5*ZU96(JROF) + ZPP5*ZV96(JROF)
    ENDDO

  ENDIF

  ! * compute new origin point:
  DO JROF=KSTART,KPROF
    !   * old rotation and vector deplacement:
    ZPP5=ZP5(JROF)*PGNORDM(JROF)-ZQ5(JROF)*PGNORDL(JROF)
    ZQQ5=ZQ5(JROF)*PGNORDM(JROF)+ZP5(JROF)*PGNORDL(JROF)
    ZPP95=ZP5(JROF)
    ZQQ95=ZQ5(JROF)
    ZPP1=PGNORDM(JROF)
    ZQQ1=-PGNORDL(JROF)
    !   * new estimate of trajectory wind:
    ZZUT15=0.5_JPRB*(&
     & ZPP1*(ZUT15(JROF)-PUSI5(JROF))+ZQQ1*(ZVT15(JROF)-PVSI5(JROF))&
     & +ZPP95*ZZUZ95(JROF)+ZQQ95*ZZVZ95(JROF))  
    ZZVT15=0.5_JPRB*(&
     & -ZQQ1*(ZUT15(JROF)-PUSI5(JROF))+ZPP1*(ZVT15(JROF)-PVSI5(JROF))&
     & -ZQQ95*ZZUZ95(JROF)+ZPP95*ZZVZ95(JROF))  
    !   * 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)=PGEMU(JROF)*(2.0_JPRB*ZCOPH5*ZCOPH5-1.0_JPRB)&
     & -ZZVT15*PGSQM2(JROF)*ZSINX5  
    ZCOSCO7(JROF)=PGSQM2(JROF)*(2.0_JPRB*ZCOPH5*ZCOPH5-1.0_JPRB)&
     & +ZZVT15*PGEMU(JROF)*ZSINX5  
    ZSINCO7(JROF)=-ZZUT15*ZSINX5
    ZCOPHI7(JROF)=2.0_JPRB*ZCOPH5*ZCOPH5-1.0_JPRB
  ENDDO
  ! * compute rotation matrix and Coriolis term at the new origin point.
  CALL LARCHE(KPROMA,KSTART,KPROF,1,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(KPROMA,KSTART,KPROF,1,NSTTYP,&
   & ROMEGA,ZDSTRET,RC2M1,RC2P1,RMUCEN,&
   & RA,RPI,ZLON7,ZLAT7,ZU97,ZV97)  

ENDIF

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

!*       4.    COMPUTATION OF LAGRANGIAN TRENDS.
!              ---------------------------------

!*       4.1   MOMENTUM EQUATION.

ZU9(1:KPROMA)=0.0_JPRB
ZV9(1:KPROMA)=0.0_JPRB
ZZUZ9(1:KPROMA)=0.0_JPRB
ZZVZ9(1:KPROMA)=0.0_JPRB

IF (L2TLFF) THEN 
 
  ! * add new estimate of advected Coriolis term:
  DO JROF=KSTART,KPROF
    ZPP5=ZP7(JROF)*PGNORDM(JROF)-ZQ7(JROF)*PGNORDL(JROF)
    ZQQ5=ZQ7(JROF)*PGNORDM(JROF)+ZP7(JROF)*PGNORDL(JROF)
    ZU9(JROF)=ZU9(JROF)+ZPP5*PUT1(JROF)-ZQQ5*PVT1(JROF)
    ZV9(JROF)=ZV9(JROF)+ZQQ5*PUT1(JROF)+ZPP5*PVT1(JROF)
    ZPP=ZU97(JROF)*PUT1(JROF)+ZV97(JROF)*PVT1(JROF)
    ZQQ=ZV97(JROF)*PUT1(JROF)-ZU97(JROF)*PVT1(JROF)
    ZP(JROF)=ZP(JROF)+PGNORDM(JROF)*ZPP+PGNORDL(JROF)*ZQQ
    ZQ(JROF)=ZQ(JROF)+PGNORDM(JROF)*ZQQ-PGNORDL(JROF)*ZPP
  ENDDO

  ! * compute rotation matrix and Coriolis term at the new origin point.
  CALL LACONEAD(KPROMA,KSTART,KPROF,1,NSTTYP,&
   & ROMEGA,ZDSTRET,RC2M1,RC2P1,RMUCEN,&
   & RA,RPI,ZLON7,ZLAT7,ZU97,ZV97,ZLON,ZLAT,ZU9,ZV9)  
  CALL LARCHEAD(KPROMA,KSTART,KPROF,1,NSTTYP,ZDSTRET,RC2M1,RC2P1,&
   & RPI,ZDEPI,RLOCEN,RMUCEN,PCOLON,PSILON,PGEMU,PGSQM2,PGECLO,&
   & PGESLO,ZCOSCO,ZSINCO,ZSINLA,ZCOPHI,ZCOSCO7,ZSINCO7,&
   & ZSINLA7,ZCOPHI7,1,ZLON,ZLAT,ZP,ZQ)  
  ZU9(1:KPROMA)=0.0_JPRB
  ZV9(1:KPROMA)=0.0_JPRB

  ! * compute new origin point:
  DO JROF=KSTART,KPROF
    ZPP1=PGNORDM(JROF)
    ZQQ1=-PGNORDL(JROF)

    ! * old rotation and vector deplacement for traj:
    ZPP5=ZP5(JROF)*PGNORDM(JROF)-ZQ5(JROF)*PGNORDL(JROF)
    ZQQ5=ZQ5(JROF)*PGNORDM(JROF)+ZP5(JROF)*PGNORDL(JROF)
    ZPP95=ZP5(JROF)
    ZQQ95=ZQ5(JROF)
    ! * new estimate of trajectory wind for traj:
    ZZUT15=0.5_JPRB*(&
     & ZPP1*(ZUT15(JROF)-PUSI5(JROF))+ZQQ1*(ZVT15(JROF)-PVSI5(JROF))&
     & +ZPP95*ZZUZ95(JROF)+ZQQ95*ZZVZ95(JROF))  
    ZZVT15=0.5_JPRB*(&
     & -ZQQ1*(ZUT15(JROF)-PUSI5(JROF))+ZPP1*(ZVT15(JROF)-PVSI5(JROF))&
     & -ZQQ95*ZZUZ95(JROF)+ZPP95*ZZVZ95(JROF))  
    ! * subtract old estimate of advected Coriolis term for traj:
    ZUT15(JROF)=ZUT15(JROF)-ZPP5*ZU95(JROF)-ZQQ5*ZV95(JROF)
    ZVT15(JROF)=ZVT15(JROF)+ZQQ5*ZU95(JROF)-ZPP5*ZV95(JROF)
    ! * 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*ZCOPHI(JROF)
    ZZUT1=-ZSINX5*ZSINCO(JROF)
    ZSINX=-ZZUT15*ZSINCO(JROF)
    ZCOPH=ZCOPH+PGSQM2(JROF)*4.0_JPRB*ZCOPH5*ZCOSCO(JROF)
    ZZVT1=PGEMU(JROF)*ZSINX5*ZCOSCO(JROF)
    ZSINX=ZSINX+PGEMU(JROF)*ZZVT15*ZCOSCO(JROF)
    ZCOPH=ZCOPH+PGEMU(JROF)*4.0_JPRB*ZCOPH5*ZSINLA(JROF)
    ZZVT1=ZZVT1-PGSQM2(JROF)*ZSINX5*ZSINLA(JROF)
    ZSINX=ZSINX-PGSQM2(JROF)*ZZVT15*ZSINLA(JROF)
    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) = ZU9(JROF) -ZPP5*PUT1(JROF) +ZQQ5*PVT1(JROF)
    ZV9(JROF) = ZV9(JROF) -ZQQ5*PUT1(JROF) -ZPP5*PVT1(JROF)
    ZPP = -ZU96(JROF)*PUT1(JROF) -ZV96(JROF)*PVT1(JROF)
    ZQQ = -ZV96(JROF)*PUT1(JROF) +ZU96(JROF)*PVT1(JROF)
    ! * new estimate of trajectory wind:
    PUT1(JROF)=PUT1(JROF)+0.5_JPRB*(ZPP1*ZZUT1-ZQQ1*ZZVT1)
    PVT1(JROF)=PVT1(JROF)+0.5_JPRB*(ZQQ1*ZZUT1+ZPP1*ZZVT1)
    PUSI(JROF)=PUSI(JROF)-0.5_JPRB*(ZPP1*ZZUT1-ZQQ1*ZZVT1)
    PVSI(JROF)=PVSI(JROF)-0.5_JPRB*(ZQQ1*ZZUT1+ZPP1*ZZVT1)
    ZPP9=0.5_JPRB*(ZZUZ95(JROF)*ZZUT1+ZZVZ95(JROF)*ZZVT1)
    ZQQ9=0.5_JPRB*(ZZVZ95(JROF)*ZZUT1-ZZUZ95(JROF)*ZZVT1)
    ZZUZ9(JROF)=ZZUZ9(JROF)+0.5_JPRB*(ZPP95*ZZUT1-ZQQ95*ZZVT1)
    ZZVZ9(JROF)=ZZVZ9(JROF)+0.5_JPRB*(ZQQ95*ZZUT1+ZPP95*ZZVT1)
    ! * compute new origin point:
    ZP(JROF)=ZP(JROF)+ZPP9
    ZQ(JROF)=ZQ(JROF)+ZQQ9
    ZP(JROF)=ZP(JROF)+PGNORDM(JROF)*ZPP+PGNORDL(JROF)*ZQQ
    ZQ(JROF)=ZQ(JROF)-PGNORDL(JROF)*ZPP+PGNORDM(JROF)*ZQQ
  ENDDO

  ZSINCO(1:KPROMA)=0.0_JPRB
  ZCOSCO(1:KPROMA)=0.0_JPRB
  ZSINLA(1:KPROMA)=0.0_JPRB
  ZCOPHI(1:KPROMA)=0.0_JPRB

ENDIF

IF (LADVF) THEN     !! LRPLANE version not done !!
  ! - First run LACONE on trajectory values: (=> ZU96,ZV96)
  CALL LACONE(KPROMA,KSTART,KPROF,1,NSTTYP,&
   & ROMEGA,ZDSTRET,RC2M1,RC2P1,RMUCEN,&
   & RA,RPI,ZLON5,ZLAT5,ZU96,ZV96)  
  DO JROF=KSTART,KPROF
    ZPP5=ZP5(JROF)*PGNORDM(JROF)-ZQ5(JROF)*PGNORDL(JROF)
    ZQQ5=ZQ5(JROF)*PGNORDM(JROF)+ZP5(JROF)*PGNORDL(JROF)
    ZU9(JROF)=ZU9(JROF)+ZPP5*PUT1(JROF)-ZQQ5*PVT1(JROF)
    ZV9(JROF)=ZV9(JROF)+ZQQ5*PUT1(JROF)+ZPP5*PVT1(JROF)
    ZPP=ZU96(JROF)*PUT1(JROF)+ZV96(JROF)*PVT1(JROF)
    ZQQ=ZV96(JROF)*PUT1(JROF)-ZU96(JROF)*PVT1(JROF)
    ZP(JROF)=ZP(JROF)+PGNORDM(JROF)*ZPP+PGNORDL(JROF)*ZQQ
    ZQ(JROF)=ZQ(JROF)+PGNORDM(JROF)*ZQQ-PGNORDL(JROF)*ZPP
  ENDDO
  ! - N.B. ZU95 and ZV95 are not altered by LACONEAD:
  CALL LACONEAD(KPROMA,KSTART,KPROF,1,NSTTYP,&
   & ROMEGA,ZDSTRET,RC2M1,RC2P1,RMUCEN,&
   & RA,RPI,ZLON5,ZLAT5,ZU95,ZV95,ZLON,ZLAT,ZU9,ZV9)  
  ZU9(1:KPROMA)=0.0_JPRB
  ZV9(1:KPROMA)=0.0_JPRB
ENDIF

DO JROF=KSTART,KPROF
  ZPP5=ZP5(JROF)*PGNORDM(JROF)-ZQ5(JROF)*PGNORDL(JROF)
  ZQQ5=ZQ5(JROF)*PGNORDM(JROF)+ZP5(JROF)*PGNORDL(JROF)
  ZU9(JROF)=ZU9(JROF)+ZPP5*PUT1(JROF)-ZQQ5*PVT1(JROF)
  ZV9(JROF)=ZV9(JROF)+ZQQ5*PUT1(JROF)+ZPP5*PVT1(JROF)
  ZPP=ZU95(JROF)*PUT1(JROF)+ZV95(JROF)*PVT1(JROF)
  ZQQ=ZV95(JROF)*PUT1(JROF)-ZU95(JROF)*PVT1(JROF)
  ZP(JROF)=ZP(JROF)+PGNORDM(JROF)*ZPP+PGNORDL(JROF)*ZQQ
  ZQ(JROF)=ZQ(JROF)+PGNORDM(JROF)*ZQQ-PGNORDL(JROF)*ZPP
ENDDO

!*       4.2   CONTINUITY EQUATION.

DO JROF=KSTART,KPROF
  ZC9(JROF)=PSPT1(JROF)
ENDDO

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

!*       3.    COMPUTATION OF THE ORIGIN POINT AND
!              INTERPOLATIONS AT THIS POINT.
!              ------------------------------------

! - Restore:
ZCOSCO6(KSTART:KPROF)=ZCOSCO5(KSTART:KPROF,NITMP)
ZSINCO6(KSTART:KPROF)=ZSINCO5(KSTART:KPROF,NITMP)
ZSINLA6(KSTART:KPROF)=ZSINLA5(KSTART:KPROF,NITMP)
ZCOPHI6(KSTART:KPROF)=ZCOPHI5(KSTART:KPROF,NITMP)

CALL LAINOR2AD(KASLB1,KPROMA,KSTART,KPROF,NDGSAH,NDGENH,KFLDN,KFLDX,&
 & ISTALAT,&
 & NVLAG,NWLAG,&
 & LRPLANE,NFLDSLB1,PSLBUF1,&
 & PUL9,PVL9,PCL9,PUL0,PVL0,PCL0,&
 & PUL95,PVL95,PCL95,PUL05,PVL05,PCL05,&
 & PINDX,PINDY,&
 & NSTTYP,ZDSTRET,RC2M1,RC2P1,R4JP,RPI,ZDEPI,ZPIS2,&
 & RLOCEN,RMUCEN,ZLSDEPI,RLATI(NDGSAH),RIPI0(NDGSAH),&
 & RIPI1(NDGSAH),RIPI2(NDGSAH),&
 & PCOLON,PSILON,PGEMU,PGSQM2,PGECLO,PGESLO,&
 & ZCOSCO,ZSINCO,ZSINLA,ZCOPHI,&
 & ZCOSCO6,ZSINCO6,ZSINLA6,ZCOPHI6,&
 & ZLON,ZLAT,&
 & ZP,ZQ,&
 & ZU9,ZV9,ZC9,&
 & ZLON5,ZLAT5,&
 & ZP5,ZQ5,&
 & ZU95,ZV95,ZC95,&
 & ZZUZ9,ZZVZ9)  

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

!*       2.    COMPUTATION OF THE MEDIUM POINT AND
!              INTERPOLATIONS AT THIS POINT.
!              ------------------------------------

LLSETTLST=LSETTLST.AND.(.NOT.LELTRA)
CALL LARMES2AD(KASLB1,KPROMA,KSTART,KPROF,NDGSAH,NDGENH,KFLDN,KFLDX,&
 & ISTALAT,&
 & NVLAG,NWLAG,NITMP,&
 & LRPLANE,LLSETTLST,LELTRA,&
 & NFLDSLB1,PSLBUF1,&
 & PURL0,PVRL0,PURL,PVRL,&
 & PURL05,PVRL05,PURL5,PVRL5,&
 & NSTTYP,ZDSTRET,RC2M1,RC2P1,R4JP,RPI,ZDEPI,ZPIS2,&
 & RDTSA,RDTS62,RDTS22,&
 & RLOCEN,RMUCEN,ZLSDEPI,RLATI(NDGSAH),RIPI0(NDGSAH),&
 & RIPI1(NDGSAH),RIPI2(NDGSAH),&
 & PCOLON,PSILON,PGEMU,PGSQM2,PGECLO,PGESLO,&
 & PGNORDL,PGNORDM,&
 & ZLON,ZLAT,&
 & ZCOSCO,ZSINCO,ZSINLA,ZCOPHI,&
 & ZLON5,ZLAT5,&
 & ZCOSCO5,ZSINCO5,ZSINLA5,ZCOPHI5,&
 & ZR5,ZS5,ZUF5,ZVF5)  

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

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