SUBROUTINE LARMESTL(KST,KPROF,KSTABUF,LDSETTLS,PB1,PB15,PB2,&
 & PLSDEPI,PCOLON,PSILON,PGEMU,PGSQM2,PGECLO,PGESLO,PNORDL,PNORDM,&
 & PLON,PLAT,PCOSCO,PSINCO,PSINLA,PCOPHI,PLEV,PR,PS,&
 & KL0,KLH0,PDLO,PDLAT,PCLA,KLEV,PDVER,PVINTW,&
 & PLON5,PLAT5,PCOSCO5,PSINCO5,PSINLA5,PCOPHI5,PLEV5,PR5,PS5,PUF5,PVF5,&
 & PDLO5,PDLAT5,PCLA5,PDVER5,PVINTW5)  

!**** *LARMESTL - semi-LAgrangian scheme:  (tangent-linear version)
!                Research of the MEdium point on the Sphere.
!                (and also the origin point).

!     Purpose.
!     --------

!      The computation of the location of the medium point "M" of
!     the lagrangian trajectory is performed by an iterative
!     method described by Robert and adapted to the sphere by M. Rochas.
!     Trajectories are great circles.
!     Finally we find the departure (origin) point "O".

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

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

!        INPUT:
!          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.
!          LDSETTLS- .T./.F.: Stable/Conventional algorithm of trajectory
!                    research in the 2TLSL scheme.
!          PB1     - SLBUF1-buffer for interpolations.
!          PB15    - SLBUF1-buffer for interpolations (trajectory).
!          PB2     - SLBUF2-buf to communicate info from non lag. to lag. dyn.
!          PLSDEPI - (Number of points by latitude) / (2 * PI) .
!          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.
!          PNORDL  - zonal component of the normalized vector directed
!                    towards the geographical north pole.
!          PNORDM  - meridian component of the normalized vector directed
!                    towards the geographical north pole.

!        OUTPUT:
!          PLON    - computational sphere longitude of interpolation point.
!          PLAT    - computational sphere latitude of interpolation point.
!          PCOSCO  - cos(Longitude-Longitude(grid-point))*cos(Latitude)
!                    of the interpolation point (geographical longitude
!                    and latitude).
!          PSINCO  - sin(Longitude-Longitude(grid-point))*cos(Latitude)
!                    of the interpolation point (geographical longitude
!                    and latitude).
!          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.
!          PR      - first element of the wind displacement matrix.
!          PS      - second element of the wind displacement matrix.
!          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)
!          PDLAT   - distance for horizontal linear interpolations
!                    in latitude
!          PCLA    - weights (distances) for horizontal cubic interpolation
!                    on a same latitude.
!          KLEV    - lower level of the vertical interpolation
!                    grid needed for vertical interpolations.
!          PDVER   - distance for vertical linear interpolation
!          PVINTW  - Vertical cubic interpolation weights.

!        TRAJECTORY:
!          PLON5   - cf. PLON                                       (out)
!          PLAT5   - cf. PLAT                                       (out)
!          PCOSCO5 - cf. PCOSCO                                     (in)
!          PSINCO5 - cf. PSINCO                                     (in)
!          PSINLA5 - cf. PSINLA                                     (in)
!          PCOPHI5 - cf. PCOPHI                                     (in)
!          PLEV5   - cf. PLEV                                       (in)
!          PR5     - cf. PR                                         (out)
!          PS5     - cf. PS                                         (out)
!          PUF5    - interpolated U-wind.                           (in)
!          PVF5    - interpolated V-wind.                           (in)
!          PDLO5   - cf. PDLO                                       (out)
!          PDLAT5  - cf. PDLAT                                      (out)
!          PCLA5   - cf. PCLA5                                      (out)
!          PDVER5  - cf. PDVER                                      (out)
!          PVINTW5 - cf. PVINTW                                     (out)

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

!     Method.
!     -------
!        See documentation about semi-Lagrangian scheme.

!     Externals.
!     ----------
!        Calls  LARCINATL.
!        Is called by LAPINEATL (3D model) 

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

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

!     Modifications.
!     --------------
!      Original : 99/07/12
!      Modified 00-06-12 by C. Temperton: Bugfixes related to vertical
!                                         bounding of medium point.
!      Renamed August 2000 by Deborah Salmond for split into _traj and _int
!      Modified 00-11-09 by C. Temperton: streamlining.
!      Modified 00-11-23 by C. Temperton: renamed _TRAJ and _INT routines.
!      Modified 01-08-30 by K. YESSAD: pruning and some other cleanings.
!      Modified 03-04-09 by C. Temperton: some trajectory recomputations
!                                         already done by calling SLADJTR
!        M.Hamrud      01-Oct-2003 CY28 Cleaning
!      Modified 05-01-11 by C. Temperton: streamlining.
!      Modified 05-01-14 by C. Temperton: transfer computations from
!                              start of LAIDEP to end of LARMES.
!      Modified 06-09-04 by F. Vana: - bugfix of vertical bounding when
!                                      LSETTLS=LELTRA=.F.
!                                    - removing useless LDPLANE blocks
!      Modified 08-Jun-27 by F. Vana: update of arguments for LARCINATL
!      K. Yessad Nov 2008: rationalisation of dummy argument interfaces
!     ------------------------------------------------------------------

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

USE YOMDIM    , ONLY : NFLEVG   ,NPROMA   ,NFLSA    ,NFLEN    ,NDGSAH   ,&
 & NDGENH   ,NDLUNG   ,NDLUXG   ,NDGUXG   ,NRLEVX
USE YOMDYN    , ONLY : NITMP    ,LELTRA   ,VETAON   ,VETAOX
USE YOMGEM    , ONLY : VETAH    ,VETAF
USE YOMMP     , ONLY : NASLB1
USE YOMRIP    , ONLY : RDTSA    ,RDTS62   ,RDTS22   ,RTDT
USE YOMSC2    , ONLY : NFLDSLB1 ,NFLDSLB15,NFLDSLB2
USE PTRSLB1   , ONLY : MSLB1UR0 ,MSLB1VR0 ,MSLB1WR0
USE PTRSLB15  , ONLY : MSLB1UR05,MSLB1VR05,MSLB1WR05
USE PTRSLB2   , ONLY : MSLB2URL ,MSLB2VRL ,MSLB2WRL ,MSLB2URL5,MSLB2VRL5

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

IMPLICIT NONE

INTEGER(KIND=JPIM),INTENT(IN)    :: KST 
INTEGER(KIND=JPIM),INTENT(IN)    :: KPROF 
INTEGER(KIND=JPIM),INTENT(IN)    :: KSTABUF(NDGSAH:NDGENH) 
LOGICAL           ,INTENT(IN)    :: LDSETTLS 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PB1(NASLB1,NFLDSLB1)
REAL(KIND=JPRB)   ,INTENT(IN)    :: PB15(NASLB1,NFLDSLB15)
REAL(KIND=JPRB)   ,INTENT(IN)    :: PB2(NPROMA,NFLDSLB2)
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(IN)    :: PNORDL(NPROMA) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PNORDM(NPROMA) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PLON(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PLAT(NPROMA,NFLEVG) 
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(INOUT) :: PR(NPROMA,NFLEVG)
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PS(NPROMA,NFLEVG)
INTEGER(KIND=JPIM),INTENT(INOUT) :: KL0(NPROMA,NFLEVG,0:3,NITMP) 
INTEGER(KIND=JPIM),INTENT(INOUT) :: KLH0(NPROMA,NFLEVG,0:3) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PDLO(NPROMA,NFLEVG,0:3) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PDLAT(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PCLA(NPROMA,NFLEVG,3) 
INTEGER(KIND=JPIM),INTENT(INOUT) :: KLEV(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PDVER(NPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PVINTW(NPROMA,NFLEVG,3) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PLON5(NPROMA,NFLEVG,NITMP) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PLAT5(NPROMA,NFLEVG,NITMP) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PCOSCO5(NPROMA,NFLEVG,NITMP) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PSINCO5(NPROMA,NFLEVG,NITMP) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PSINLA5(NPROMA,NFLEVG,NITMP) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PCOPHI5(NPROMA,NFLEVG,NITMP) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PLEV5(NPROMA,NFLEVG,NITMP) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PR5(NPROMA,NFLEVG,NITMP) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PS5(NPROMA,NFLEVG,NITMP) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PUF5(NPROMA,NFLEVG,NITMP-1) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PVF5(NPROMA,NFLEVG,NITMP-1) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PDLO5(NPROMA,NFLEVG,0:3,NITMP) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PDLAT5(NPROMA,NFLEVG,NITMP) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PCLA5(NPROMA,NFLEVG,3) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PDVER5(NPROMA,NFLEVG,NITMP) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PVINTW5(NPROMA,NFLEVG,3) 

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

INTEGER(KIND=JPIM) :: IROT, ITIP, JITER, JLEV, JROF

LOGICAL :: LLO
LOGICAL :: LLSLHD,LLSLHDQUAD

REAL(KIND=JPRB) :: ZDTS22, ZDTS62, ZDTSA, ZINT, &
 & ZLEVO, ZNOR2, ZPU, ZPV, ZSPHSV, &
 & ZVETAON, ZVETAOX, ZNOR25, ZSPHSV5, ZLEVO5, ZPU5, ZPV5

REAL(KIND=JPRB) :: ZUF(NPROMA,NFLEVG)
REAL(KIND=JPRB) :: ZVF(NPROMA,NFLEVG)
REAL(KIND=JPRB) :: ZWF(NPROMA,NFLEVG)

! unused arguments to LARCINATL (they can be passed to LAPINEATL
!  but there's no reason for it, as the linear interpolation only
!  is concerned at this stage)
! a) input arrays
REAL(KIND=JPRB) :: ZUN_KAPPA(1)
REAL(KIND=JPRB) :: ZUN_KAPPA5(1)
! b) output arrays - dimensions kept for safety
REAL(KIND=JPRB) :: ZUN_CLO(NPROMA,NFLEVG,3,2)
REAL(KIND=JPRB) :: ZUN_CLOSLD(NPROMA,NFLEVG,3,2)
REAL(KIND=JPRB) :: ZUN_CLASLD(NPROMA,NFLEVG,3)
REAL(KIND=JPRB) :: ZUN_VINTWSLD(NPROMA,NFLEVG,3)
REAL(KIND=JPRB) :: ZUN_CLO5(NPROMA,NFLEVG,3,2)
REAL(KIND=JPRB) :: ZUN_CLOSLD5(NPROMA,NFLEVG,3,2)
REAL(KIND=JPRB) :: ZUN_CLASLD5(NPROMA,NFLEVG,3)
REAL(KIND=JPRB) :: ZUN_VINTWSLD5(NPROMA,NFLEVG,3)

REAL(KIND=JPRB) :: ZHOOK_HANDLE

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

#include "larcinatl.intfb.h"

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

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

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

!*       1.    PRELIMINARY INITIALISATIONS AND TESTS.
!              --------------------------------------

!*       1.2   Miscellaneous preliminary initialisations.

LLO=LDSETTLS

IF(LLO.OR.LELTRA) THEN
  ZDTS22=RDTS22*4
  ZDTSA=RDTSA*2
  ZDTS62=RDTS62*4
ELSE
  ZDTS22=RDTS22
  ZDTSA=RDTSA
  ZDTS62=RDTS62
ENDIF

! deactivate computation of SLHD weights
LLSLHD     =.FALSE.
LLSLHDQUAD =.FALSE.

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

!*       2.    ITERATIONS.
!              -----------

DO JITER=1,NITMP

  !*       2.1   DETERMINATION OF THE MEDIUM POINT "M" OR THE ORIGIN POINT "O".

  ! Computation of the norm of the real "(a/rs)*wind" vector.
  ! Computation of the angle (PHI=DT . NORM OF V ON RADIUS)**2
  ! then computation of the coordinates of the medium point "M".
  ! If (LLO=T or LELTRA=T) the origin point "O" is computed
  ! instead of the medium point "M".

  ZVETAON=(1.0_JPRB-VETAON)*VETAH(0)+VETAON*VETAF(1)
  ZVETAOX=(1.0_JPRB-VETAOX)*VETAH(NFLEVG)+VETAOX*VETAF(NFLEVG)

  IF (JITER == 1) THEN

    DO JLEV=1,NFLEVG
      DO JROF=KST,KPROF

        ! * computations on horizontal plans.

        ZNOR25=( PB2(JROF,MSLB2URL5+JLEV-1)*PB2(JROF,MSLB2URL5+JLEV-1)&
         & +PB2(JROF,MSLB2VRL5+JLEV-1)*PB2(JROF,MSLB2VRL5+JLEV-1) )  
        ZSPHSV5=ZDTSA*(1.0_JPRB-ZDTS62*ZNOR25)
        ZNOR2=2.0_JPRB*(PB2(JROF,MSLB2URL+JLEV-1)*PB2(JROF,MSLB2URL5+JLEV-1)+&
         & PB2(JROF,MSLB2VRL+JLEV-1)*PB2(JROF,MSLB2VRL5+JLEV-1))  
        PCOPHI(JROF,JLEV)=-ZDTS22*ZNOR2
        ZSPHSV=-ZDTSA*ZDTS62*ZNOR2
        ZINT=( PB2(JROF,MSLB2URL+JLEV-1)*PNORDL(JROF)&
         & +PB2(JROF,MSLB2VRL+JLEV-1)*PNORDM(JROF))*ZSPHSV5 + &
         & ( PB2(JROF,MSLB2URL5+JLEV-1)*PNORDL(JROF)&
         & +PB2(JROF,MSLB2VRL5+JLEV-1)*PNORDM(JROF))*ZSPHSV  
        PSINLA(JROF,JLEV)= PGEMU(JROF)*PCOPHI(JROF,JLEV)-ZINT*PGSQM2(JROF)
        PCOSCO(JROF,JLEV)= PGSQM2(JROF)*PCOPHI(JROF,JLEV)+ZINT* PGEMU(JROF)
        PSINCO(JROF,JLEV)=-( PB2(JROF,MSLB2URL+JLEV-1)*PNORDM(JROF)&
         & -PB2(JROF,MSLB2VRL+JLEV-1)*PNORDL(JROF) )*ZSPHSV5 - &
         & ( PB2(JROF,MSLB2URL5+JLEV-1)*PNORDM(JROF)&
         & -PB2(JROF,MSLB2VRL5+JLEV-1)*PNORDL(JROF) )*ZSPHSV  

        ! * computations on a vertical.

        ZWF(JROF,JLEV)=PB2(JROF,MSLB2WRL+JLEV-1)
        ZLEVO=-RTDT*PB2(JROF,MSLB2WRL+JLEV-1)
        IF(LLO.OR.LELTRA) THEN
          ZLEVO5=PLEV5(JROF,JLEV,JITER)
          IF (ZLEVO5 <= ZVETAON) THEN
            ZLEVO=0.0_JPRB
          ELSEIF (ZLEVO5 >= ZVETAOX) THEN
            ZLEVO=0.0_JPRB
          ENDIF
          PLEV(JROF,JLEV)=ZLEVO
        ELSE
          ZLEVO5=2.0_JPRB*PLEV5(JROF,JLEV,JITER)-VETAF(JLEV)
          IF (ZLEVO5 <= ZVETAON) THEN
            ZLEVO=0.0_JPRB
          ELSEIF (ZLEVO5 >= ZVETAOX) THEN
            ZLEVO=0.0_JPRB
          ENDIF
          PLEV(JROF,JLEV)=0.5_JPRB*ZLEVO
        ENDIF

      ENDDO
    ENDDO

  ELSE

    DO JLEV=1,NFLEVG
      DO JROF=KST,KPROF

        ! * ZPU,ZPV are the coordinates of VM in the local repere
        !   related to F.

        IF(LLO) THEN
          ZPU5= 0.5_JPRB*(PR5(JROF,JLEV,JITER-1)*PUF5(JROF,JLEV,JITER-1)&
           & +PS5(JROF,JLEV,JITER-1)*PVF5(JROF,JLEV,JITER-1)&
           & +PB2(JROF,MSLB2URL5+JLEV-1)*PNORDM(JROF)&
           & -PB2(JROF,MSLB2VRL5+JLEV-1)*PNORDL(JROF))  
          ZPU= 0.5_JPRB*(PR(JROF,JLEV)*PUF5(JROF,JLEV,JITER-1)&
           & +PR5(JROF,JLEV,JITER-1)*ZUF(JROF,JLEV)&
           & +PS(JROF,JLEV)*PVF5(JROF,JLEV,JITER-1)&
           & +PS5(JROF,JLEV,JITER-1)*ZVF(JROF,JLEV)&
           & +PB2(JROF,MSLB2URL+JLEV-1)*PNORDM(JROF)&
           & -PB2(JROF,MSLB2VRL+JLEV-1)*PNORDL(JROF))  
          ZPV5=0.5_JPRB*(-PS5(JROF,JLEV,JITER-1)*PUF5(JROF,JLEV,JITER-1)&
           & +PR5(JROF,JLEV,JITER-1)*PVF5(JROF,JLEV,JITER-1)&
           & +PB2(JROF,MSLB2URL5+JLEV-1)*PNORDL(JROF)&
           & +PB2(JROF,MSLB2VRL5+JLEV-1)*PNORDM(JROF))  
          ZPV=0.5_JPRB*(-PS(JROF,JLEV)*PUF5(JROF,JLEV,JITER-1)&
           & -PS5(JROF,JLEV,JITER-1)*ZUF(JROF,JLEV)&
           & +PR(JROF,JLEV)*PVF5(JROF,JLEV,JITER-1)&
           & +PR5(JROF,JLEV,JITER-1)*ZVF(JROF,JLEV)&
           & +PB2(JROF,MSLB2URL+JLEV-1)*PNORDL(JROF)&
           & +PB2(JROF,MSLB2VRL+JLEV-1)*PNORDM(JROF))  
          ZWF(JROF,JLEV)=0.5_JPRB*(ZWF(JROF,JLEV)+PB2(JROF,MSLB2WRL+JLEV-1))
        ELSE
          ZPU5= PR5(JROF,JLEV,JITER-1)*PUF5(JROF,JLEV,JITER-1)&
           & +PS5(JROF,JLEV,JITER-1)*PVF5(JROF,JLEV,JITER-1)  
          ZPU= PR(JROF,JLEV)*PUF5(JROF,JLEV,JITER-1)&
           & +PR5(JROF,JLEV,JITER-1)*ZUF(JROF,JLEV)&
           & +PS(JROF,JLEV)*PVF5(JROF,JLEV,JITER-1)&
           & +PS5(JROF,JLEV,JITER-1)*ZVF(JROF,JLEV)  
          ZPV5=-PS5(JROF,JLEV,JITER-1)*PUF5(JROF,JLEV,JITER-1)&
           & +PR5(JROF,JLEV,JITER-1)*PVF5(JROF,JLEV,JITER-1)  
          ZPV=-PS(JROF,JLEV)*PUF5(JROF,JLEV,JITER-1)&
           & -PS5(JROF,JLEV,JITER-1)*ZUF(JROF,JLEV)&
           & +PR(JROF,JLEV)*PVF5(JROF,JLEV,JITER-1)&
           & +PR5(JROF,JLEV,JITER-1)*ZVF(JROF,JLEV)  
        ENDIF
        ZNOR25            =(ZPU5*ZPU5+ZPV5*ZPV5)
        ZNOR2             =2.0_JPRB*(ZPU*ZPU5+ZPV*ZPV5)
        PCOPHI(JROF,JLEV) =-ZDTS22*ZNOR2
        ZSPHSV5           =ZDTSA*(1.0_JPRB-ZDTS62*ZNOR25)
        ZSPHSV            =-ZDTSA*ZDTS62*ZNOR2
        ZINT              =ZPV*ZSPHSV5+ZPV5*ZSPHSV
        PSINLA(JROF,JLEV) = PGEMU(JROF)*PCOPHI(JROF,JLEV)-ZINT*PGSQM2(JROF)
        PCOSCO(JROF,JLEV) = PGSQM2(JROF)*PCOPHI(JROF,JLEV)+ZINT*PGEMU(JROF)
        PSINCO(JROF,JLEV) =-ZPU*ZSPHSV5-ZPU5*ZSPHSV

        ! * computations on a vertical.

        ZLEVO=-RTDT*ZWF(JROF,JLEV)
        IF(LLO.OR.LELTRA) THEN
          ZLEVO5=PLEV5(JROF,JLEV,JITER)
          IF (ZLEVO5 <= ZVETAON) THEN
            ZLEVO=0.0_JPRB
          ELSEIF (ZLEVO5 >= ZVETAOX) THEN
            ZLEVO=0.0_JPRB
          ENDIF
          PLEV(JROF,JLEV)=ZLEVO
        ELSE
          ZLEVO5=2.0_JPRB*PLEV5(JROF,JLEV,JITER)-VETAF(JLEV)
          IF (ZLEVO5 <= ZVETAON) THEN
            ZLEVO=0.0_JPRB
          ELSEIF (ZLEVO5 >= ZVETAOX) THEN
            ZLEVO=0.0_JPRB
          ENDIF
          PLEV(JROF,JLEV)=0.5_JPRB*ZLEVO
        ENDIF

      ENDDO
    ENDDO

  ENDIF

  !*       2.2   DETERMINATION OF THE "(a/rs)*wind" AT "M" OR "O".

  IF(JITER /= NITMP) THEN

    ! If (LLO=T or LELTRA=T)
    ! and JITER < NITMP "(a/rs)*wind" is interpolated at
    ! the origin point "O" instead of at the medium point "M".
    ! In the other cases the wind is interpolated at "M".

    IROT=1
    ITIP=1

    CALL LARCINATL(KST,KPROF,KSTABUF,LLSLHD,LLSLHDQUAD,ITIP,IROT,.FALSE.,&
     & PLSDEPI,&
     & PCOLON,PSILON,PGEMU,PGSQM2,PGECLO,PGESLO,&
     & PCOSCO,PSINCO,PSINLA,PCOPHI,PLEV,&
     & PCOSCO5(1,1,JITER),PSINCO5(1,1,JITER),PSINLA5(1,1,JITER),&
     & PCOPHI5(1,1,JITER),PLEV5(1,1,JITER),&
     & ZUN_KAPPA,ZUN_KAPPA5,&
     & PB1(1,MSLB1UR0),PB1(1,MSLB1VR0),PB1(1,MSLB1WR0),&
     & PB15(1,MSLB1UR05),PB15(1,MSLB1VR05),PB15(1,MSLB1WR05),&
     & PLON,PLAT,PR,PS,&
     & ZUF,ZVF,ZWF,&
     & PLON5(1,1,JITER),PLAT5(1,1,JITER),PR5(1,1,JITER),PS5(1,1,JITER),&
     & KL0(1,1,0,JITER),KLH0,PDLO,ZUN_CLO,ZUN_CLOSLD,&
     & PDLAT,PCLA,ZUN_CLASLD,KLEV,PDVER,PVINTW,ZUN_VINTWSLD,&
     & PDLO5(1,1,0,JITER),ZUN_CLO5,ZUN_CLOSLD5,&
     & PDLAT5(1,1,JITER),PCLA5,ZUN_CLASLD5,PDVER5(1,1,JITER),PVINTW5,&
     & ZUN_VINTWSLD5)  

  ENDIF

ENDDO

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

!*       3.    COMPUTATION OF THE ORIGIN POINT "O" COORDINATES.
!              ------------------------------------------------

IF (.NOT.(LLO.OR.LELTRA)) THEN

  ZVETAON=(1.0_JPRB-VETAON)*VETAH(0)+VETAON*VETAF(1)
  ZVETAOX=(1.0_JPRB-VETAOX)*VETAH(NFLEVG)+VETAOX*VETAF(NFLEVG)

  DO JLEV=1,NFLEVG
    DO JROF=KST,KPROF

      ! * computations on horizontal plans.

      PSINLA(JROF,JLEV)=2.0_JPRB*(PCOPHI(JROF,JLEV)*PSINLA5(JROF,JLEV,NITMP)&
       & +PCOPHI5(JROF,JLEV,NITMP)*PSINLA(JROF,JLEV))
      PSINCO(JROF,JLEV)=2.0_JPRB*(PCOPHI(JROF,JLEV)*PSINCO5(JROF,JLEV,NITMP)&
       & +PCOPHI5(JROF,JLEV,NITMP)*PSINCO(JROF,JLEV))
      PCOSCO(JROF,JLEV)=2.0_JPRB*(PCOPHI(JROF,JLEV)*PCOSCO5(JROF,JLEV,NITMP)&
       & +PCOPHI5(JROF,JLEV,NITMP)*PCOSCO(JROF,JLEV))

      ! * computations on a vertical.

      PLEV(JROF,JLEV)=2.0_JPRB*PLEV(JROF,JLEV)
      IF (PLEV5(JROF,JLEV,NITMP) <= ZVETAON) THEN
        PLEV(JROF,JLEV)=0.0_JPRB
      ELSEIF (PLEV5(JROF,JLEV,NITMP) >= ZVETAOX) THEN
        PLEV(JROF,JLEV)=0.0_JPRB
      ENDIF

      ! * Computation of the angle <0,G>.

      PCOPHI(JROF,JLEV)=4._JPRB*PCOPHI(JROF,JLEV)*PCOPHI5(JROF,JLEV,NITMP)

    ENDDO
  ENDDO

ENDIF

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

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