! This directive is necessary to stop pre-computing the reciprocal of ZCOSLA5
! leads to bad test of adjoint /MH
!OCL NOEVAL
SUBROUTINE LARCHETL(KPROMA,KSTART,KPROF,KFLEV,&
 & KSTTYP,PDSTRET,PC2M1,PC2P1,PI,PDEPI,&
 & PLOCEN,PMUCEN,PCOLON,PSILON,&
 & PGEMU,PGSQM2,PGECLO,PGESLO,&
 & PCOSCO,PSINCO,PSINLA,PCOPHI,&
 & PCOSCO5,PSINCO5,PSINLA5,PCOPHI5,&
 & KROT,PLON,PLAT,PO,PQ,&
 & PLON5,PLAT5,PO5,PQ5)  

!**** *LARCHETL - semi-LAgrangian scheme:   (tangent-linear version)
!                 Research of the Coordinates (of the medium or origin
!                 point).

!     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.

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

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

!        INPUT:
!          KPROMA  - horizontal dimension.
!          KSTART  - first element of arrays where computations are performed.
!          KPROF   - depth of work.
!          KFLEV   - vertical dimension.
!          KSTTYP  - 1: Not tilted pole;  2: Tilted pole.
!          PDSTRET - 2*c (where c is the stretching factor).
!          PC2M1   - c*c-1.
!          PC2P1   - c*c+1.
!          PI      - number PI
!          PDEPI   - 2 * PI
!          PLOCEN  - geographic longitude of the stretching pole.
!          PMUCEN  - sinus of the geographic latitude of the stretching pole.
!          PCOLON  - cosinus of the g.p. longitude on the computational sphere.
!          PSILON  - sinus of the g.p. longitude on the computational sphere.
!          PGEMU   - sinus of the grid-point geographic latitude.
!          PGSQM2  - cosinus of the grid-point geographic latitude.
!          PGECLO  - cosinus of the grid-point geographic longitude.
!          PGESLO  - sinus of the grid-point geographic longitude.
!          PCOSCO  - cos(Longitude-Longitude(grid-point))*cos(Latitude)
!                    of the interpolation point (geographic lon and lat).
!          PSINCO  - sin(Longitude-Longitude(grid-point))*cos(Latitude)
!                    of the interpolation point (geographic lon and lat).
!          PSINLA  - sinus of the interpolation point geographic latitude.
!          PCOPHI  - cosinus of the geographic angle between the
!                    interpolation point and the grid-point.
! ----------------------- trajectory variables -------------------------
!          PCOSCO5 - cos(Longitude-Longitude(grid-point))*cos(Latitude)
!                    of the interpolation point (geographic lon and lat).
!          PSINCO5 - sin(Longitude-Longitude(grid-point))*cos(Latitude)
!                    of the interpolation point (geographic lon and lat).
!          PSINLA5 - sinus of the interpolation point geographic latitude.
!          PCOPHI5 - cosinus of the geographic angle between the
!                    interpolation point and the grid-point.
! ----------------------------------------------------------------------
!          KROT    - KROT=1: computation of the elements po and pq
!                    of the wind displacement matrix.
!                    KROT=0: no computation.

!        OUTPUT:
!          PLON    - longitude of the interpolation point in the
!                    computational sphere.
!          PLAT    - latitude of the interpolation point in the
!                    computational sphere.
!          PO      - first element of the wind displacement matrix.
!          PQ      - second element of the wind displacement matrix.
! ----------------------- trajectory variables -------------------------
!          PLON5   - longitude of the interpolation point in the
!                    computational sphere.
!          PLAT5   - latitude of the interpolation point in the
!                    computational sphere.
!          PO5     - first element of the wind displacement matrix.
!          PQ5     - second element of the wind displacement matrix.
! ----------------------------------------------------------------------

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

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

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

!        No external.

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

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

!     Modifications.
!     --------------
!      Original : 98/06/10
!      Modified 00-06-09 by C. Temperton: Bugfix - remove MAX, MIN from
!                                         perturbation variables.
!      Modified 00-06-13 by C. Temperton: Split out case with no stretching.
!      Modified 00-06-14 by C. Temperton: Loop split to fix problem with
!                            compiler on VPP5000: it's ugly but it works!
!      Modified 00-11-10 by C. Temperton: bugfix (compatibility with AD)
!      Modified 00-11-29 by C. Temperton: original loop structure restored.
!      M.Hamrud      01-Oct-2003 CY28 Cleaning
!      K. Yessad: Aug 2005 : code AD+TL for variable mesh.
!      K. Yessad (Sep 2008): update comments + cleanings.
!     ------------------------------------------------------------------

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

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

IMPLICIT NONE

INTEGER(KIND=JPIM),INTENT(IN)    :: KPROMA 
INTEGER(KIND=JPIM),INTENT(IN)    :: KFLEV 
INTEGER(KIND=JPIM),INTENT(IN)    :: KSTART 
INTEGER(KIND=JPIM),INTENT(IN)    :: KPROF 
INTEGER(KIND=JPIM),INTENT(IN)    :: KSTTYP 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PDSTRET
REAL(KIND=JPRB)   ,INTENT(IN)    :: PC2M1 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PC2P1
REAL(KIND=JPRB)   ,INTENT(IN)    :: PI 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PDEPI 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PLOCEN
REAL(KIND=JPRB)   ,INTENT(IN)    :: PMUCEN
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)    :: PCOSCO(KPROMA,KFLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PSINCO(KPROMA,KFLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PSINLA(KPROMA,KFLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PCOPHI(KPROMA,KFLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PCOSCO5(KPROMA,KFLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PSINCO5(KPROMA,KFLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PSINLA5(KPROMA,KFLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PCOPHI5(KPROMA,KFLEV) 
INTEGER(KIND=JPIM),INTENT(IN)    :: KROT 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PLON(KPROMA,KFLEV) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PLAT(KPROMA,KFLEV) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PO(KPROMA,KFLEV) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PQ(KPROMA,KFLEV) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PLON5(KPROMA,KFLEV) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PLAT5(KPROMA,KFLEV) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PO5(KPROMA,KFLEV) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PQ5(KPROMA,KFLEV) 

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

INTEGER(KIND=JPIM) :: JLEV, JROF

REAL(KIND=JPRB) :: ZCOSLA5(KPROMA)
REAL(KIND=JPRB) :: ZCOSLA(KPROMA)
REAL(KIND=JPRB) :: ZXX5(KPROMA)
REAL(KIND=JPRB) :: ZYY5(KPROMA)
REAL(KIND=JPRB) :: ZYY(KPROMA)
REAL(KIND=JPRB) :: ZZW5(KPROMA)
REAL(KIND=JPRB) :: ZZA5(KPROMA)
REAL(KIND=JPRB) :: ZCOSLR5(KPROMA)
REAL(KIND=JPRB) :: ZCOSLR(KPROMA)
REAL(KIND=JPRB) :: ZCOSL2(KPROMA)
REAL(KIND=JPRB) :: ZDECO5(KPROMA)
REAL(KIND=JPRB) :: ZDI5(KPROMA)
REAL(KIND=JPRB) :: ZDI(KPROMA)
REAL(KIND=JPRB) :: Z1ST5(KPROMA)
REAL(KIND=JPRB) :: Z1STT5(KPROMA)
REAL(KIND=JPRB) :: ZZP5(KPROMA)
REAL(KIND=JPRB) :: ZZX5(KPROMA)
REAL(KIND=JPRB) :: ZZY5(KPROMA)
REAL(KIND=JPRB) :: ZZZ5(KPROMA)
REAL(KIND=JPRB) :: ZZZ(KPROMA)
REAL(KIND=JPRB) :: ZRP5(KPROMA)
REAL(KIND=JPRB) :: ZRQ5(KPROMA)
REAL(KIND=JPRB) :: ZCA5(KPROMA)
REAL(KIND=JPRB) :: ZSA5(KPROMA)
REAL(KIND=JPRB) :: ZFACT5(KPROMA)
REAL(KIND=JPRB) :: ZZSINLA5(KPROMA)
REAL(KIND=JPRB) :: ZZCOSLA5(KPROMA)
REAL(KIND=JPRB) :: ZZSILON5(KPROMA)
REAL(KIND=JPRB) :: ZCOSL25(KPROMA)

REAL(KIND=JPRB) :: ZFACT, ZCOSCO, ZSINCO, ZSINLA, Z1ST, Z1STT, ZDECO
REAL(KIND=JPRB) :: ZPSLAP, ZPCLAP, ZPSLOP, ZPCLOP
REAL(KIND=JPRB) :: ZMU, ZXX, ZZA, ZZW, ZZY, ZZX, ZZP, ZP, ZQ, ZCA, ZSA
REAL(KIND=JPRB) :: ZEPS1

LOGICAL         :: LLSTR

REAL(KIND=JPRB) :: ZHOOK_HANDLE

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

#include "larche5.intfb.h"

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

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

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

!*       1.    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)
!     ------------------------------------------------------------------

! K.Y.: definition of LLSTR (c>1) must be the same everywhere in the code.
ZEPS1=100.0_JPRB*TINY(1.0_JPRB)
LLSTR=(ABS(0.5_JPRB*PDSTRET-1.0_JPRB)>ZEPS1)

IF(KSTTYP == 1.AND.(.NOT.LLSTR)) THEN

  !        NO POLE STRETCHING, NO POLE TILTING.

  DO JLEV=1,KFLEV

    CALL LARCHE5(KPROMA,KSTART,KPROF,KFLEV,JLEV,&
     & KSTTYP,PDSTRET,PC2M1,PC2P1,PI,PDEPI,&
     & PLOCEN,PMUCEN,PCOLON,PSILON,&
     & PGEMU,PGSQM2,PGECLO,PGESLO,&
     & PCOSCO5,PSINCO5,PSINLA5,PCOPHI5,&
     & KROT,PLON5,PLAT5,PO5,PQ5,&
     & ZCOSLR5,ZCOSLA5,ZCOSL25,ZXX5,ZYY5,ZZW5,ZZA5,ZDECO5,Z1ST5,&
     & ZFACT5,ZZSINLA5,ZZCOSLA5,ZZSILON5,&
     & ZZY5,ZZX5,ZDI5,ZZZ5,ZZP5,Z1STT5,ZRP5,ZRQ5,ZCA5,ZSA5)

    DO JROF=KSTART,KPROF
      ZCOSLR(JROF)=(PCOSCO(JROF,JLEV)*PCOSCO5(JROF,JLEV)&
       & +PSINCO(JROF,JLEV)*PSINCO5(JROF,JLEV))/ZCOSLR5(JROF)  
      ZCOSLA(JROF)=ZCOSLR(JROF)

      ZMU=PSINLA(JROF,JLEV)
      PLAT(JROF,JLEV)=ZMU/ZCOSLA5(JROF)

      IF (ABS(ZZA5(JROF)) >= SQRT(0.5_JPRB)) THEN
        ZXX=PCOLON(JROF)*PCOSCO(JROF,JLEV) &
         & -PSILON(JROF)*PSINCO(JROF,JLEV)  
        ZZW=(ZXX-ZXX5(JROF)*ZCOSLA(JROF)/ZCOSLA5(JROF))/ZCOSLA5(JROF)
        PLON(JROF,JLEV)=-ZZW/ZZA5(JROF)
      ELSE
        ZYY(JROF)=PSILON(JROF)*PCOSCO(JROF,JLEV)&
         & +PCOLON(JROF)*PSINCO(JROF,JLEV)  
        ZZA=(ZYY(JROF)-ZYY5(JROF)*ZCOSLA(JROF)/ZCOSLA5(JROF))/ZCOSLA5(JROF)
        PLON(JROF,JLEV)=ZZA/ZZW5(JROF)
      ENDIF

    ENDDO

    IF (KROT == 1) THEN
      DO JROF=KSTART,KPROF

        ZDECO =-PCOPHI(JROF,JLEV)*ZDECO5(JROF)*ZDECO5(JROF)
        Z1ST  =-ZCOSLA(JROF)*Z1ST5(JROF)*Z1ST5(JROF)

        PO(JROF,JLEV)=(PGSQM2(JROF)*ZCOSLA5(JROF) &
         & +(1.0_JPRB+PGEMU(JROF)*PSINLA5(JROF,JLEV))&
         & *PCOSCO5(JROF,JLEV)*Z1ST5(JROF))*ZDECO &
         & +ZDECO5(JROF)*(PGSQM2(JROF)*ZCOSLA(JROF)+(1.0_JPRB+PGEMU(JROF)*&
         & PSINLA5(JROF,JLEV))*PCOSCO5(JROF,JLEV)*Z1ST &
         & +Z1ST5(JROF)*((1.0_JPRB+PGEMU(JROF)*PSINLA5(JROF,JLEV))*&
         & PCOSCO(JROF,JLEV)+PCOSCO5(JROF,JLEV)*PGEMU(JROF)&
         & *PSINLA(JROF,JLEV)))
        PQ(JROF,JLEV)=-PSINCO5(JROF,JLEV)*Z1ST5(JROF)*ZDECO5(JROF)*&
         & PSINLA(JROF,JLEV)-(PGEMU(JROF)+PSINLA5(JROF,JLEV))*&
         & (PSINCO5(JROF,JLEV)*Z1ST5(JROF)*ZDECO &
         & +PSINCO5(JROF,JLEV)*Z1ST*ZDECO5(JROF) &
         & +PSINCO(JROF,JLEV)*Z1ST5(JROF)*ZDECO5(JROF))  

      ENDDO
    ENDIF

  ENDDO

ELSEIF(KSTTYP == 1.AND.LLSTR) THEN

  !        POLE STRETCHING, NO POLE TILTING.

  ! K.Y.: this piece of code is also valid for ksttyp=1, c=1.

  DO JLEV=1,KFLEV

    CALL LARCHE5(KPROMA,KSTART,KPROF,KFLEV,JLEV,&
     & KSTTYP,PDSTRET,PC2M1,PC2P1,PI,PDEPI,&
     & PLOCEN,PMUCEN,PCOLON,PSILON,&
     & PGEMU,PGSQM2,PGECLO,PGESLO,&
     & PCOSCO5,PSINCO5,PSINLA5,PCOPHI5,&
     & KROT,PLON5,PLAT5,PO5,PQ5,&
     & ZCOSLR5,ZCOSLA5,ZCOSL25,ZXX5,ZYY5,ZZW5,ZZA5,ZDECO5,Z1ST5,&
     & ZFACT5,ZZSINLA5,ZZCOSLA5,ZZSILON5,&
     & ZZY5,ZZX5,ZDI5,ZZZ5,ZZP5,Z1STT5,ZRP5,ZRQ5,ZCA5,ZSA5)

    DO JROF=KSTART,KPROF
      ! * Intermediate quantities:
      ZCOSLR(JROF)=(PCOSCO(JROF,JLEV)*PCOSCO5(JROF,JLEV)&
       & +PSINCO(JROF,JLEV)*PSINCO5(JROF,JLEV))/ZCOSLR5(JROF)  
      ZFACT=(PC2M1/PDSTRET)*ZFACT5(JROF)*ZFACT5(JROF)*PSINLA(JROF,JLEV)
      ZCOSCO=PCOSCO5(JROF,JLEV)*ZFACT+ZFACT5(JROF)*PCOSCO(JROF,JLEV)
      ZSINCO=PSINCO5(JROF,JLEV)*ZFACT+ZFACT5(JROF)*PSINCO(JROF,JLEV)
      ZCOSLA(JROF)=ZCOSLR5(JROF)*ZFACT+ZFACT5(JROF)*ZCOSLR(JROF)
      ZSINLA=ZZSINLA5(JROF)*&
       & (PC2P1/(PC2P1*PSINLA5(JROF,JLEV)-PC2M1)&
       & +PC2M1/(PC2P1-PC2M1*PSINLA5(JROF,JLEV)))&
       & *PSINLA(JROF,JLEV)
      ZXX=PCOLON(JROF)*ZCOSCO-PSILON(JROF)*ZSINCO

      ! * PLAT:
      ZMU=ZSINLA
      PLAT(JROF,JLEV)=ZMU/ZZCOSLA5(JROF)

      ! * PLON:
      ZZW=ZZW5(JROF)*(ZXX/ZXX5(JROF)-ZCOSLA(JROF)/ZCOSLA5(JROF))
      ! * If zyy5>=0, do the differenciation of "plon=acos(zzw)"
      !   (in this case, plon5 is in [0,pi]);
      !   if zyy5<0, do the differenciation of "plon=2 pi - acos(zzw)"
      !   (in this case, plon5 is in ]pi,2pi[).
      !   In all cases, that yields plon=-zzw/zzsilon5.
      PLON(JROF,JLEV)=-ZZW/ZZSILON5(JROF)
    ENDDO

    IF (KROT == 1) THEN
      ! * Compute PO and PQ when required:
      DO JROF=KSTART,KPROF
        ZDECO=-ZDECO5(JROF)*ZDECO5(JROF)*PCOPHI(JROF,JLEV)
        Z1ST=-Z1ST5(JROF)*Z1ST5(JROF)*ZCOSLR(JROF)

        PO(JROF,JLEV)=(PGSQM2(JROF)*ZCOSLR5(JROF) &
         & +(1.0_JPRB+PGEMU(JROF)*PSINLA5(JROF,JLEV)) &
         & *PCOSCO5(JROF,JLEV)*Z1ST5(JROF) )*ZDECO &
         & +ZDECO5(JROF)*PGSQM2(JROF)*ZCOSLR(JROF) &
         & +ZDECO5(JROF)*PCOSCO5(JROF,JLEV)*Z1ST5(JROF)*PGEMU(JROF) &
         & *PSINLA(JROF,JLEV) &
         & +ZDECO5(JROF)*(1.0_JPRB+PGEMU(JROF)*PSINLA5(JROF,JLEV))*Z1ST5(JROF)&
         & *PCOSCO(JROF,JLEV) &
         & +ZDECO5(JROF)*(1.0_JPRB+PGEMU(JROF)*PSINLA5(JROF,JLEV))&
         & *PCOSCO5(JROF,JLEV)*Z1ST

        PQ(JROF,JLEV)= &
         & -PSINCO5(JROF,JLEV)*Z1ST5(JROF)*ZDECO5(JROF)*PSINLA(JROF,JLEV) &
         & -(PGEMU(JROF)+PSINLA5(JROF,JLEV)) &
         & *Z1ST5(JROF)*ZDECO5(JROF)*PSINCO(JROF,JLEV) &
         & -(PGEMU(JROF)+PSINLA5(JROF,JLEV)) &
         & *PSINCO5(JROF,JLEV)*ZDECO5(JROF)*Z1ST &
         & -(PGEMU(JROF)+PSINLA5(JROF,JLEV)) &
         & *PSINCO5(JROF,JLEV)*Z1ST5(JROF)*ZDECO
      ENDDO
    ENDIF

  ENDDO

ELSEIF(KSTTYP == 2) THEN

  !        POLE TILTING.

  ZPSLAP = PMUCEN
  ZPCLAP = SQRT(1.0_JPRB-PMUCEN*PMUCEN)
  ZPSLOP = SIN(PLOCEN)
  ZPCLOP = COS(PLOCEN)

  DO JLEV=1,KFLEV

    CALL LARCHE5(KPROMA,KSTART,KPROF,KFLEV,JLEV,&
     & KSTTYP,PDSTRET,PC2M1,PC2P1,PI,PDEPI,&
     & PLOCEN,PMUCEN,PCOLON,PSILON,&
     & PGEMU,PGSQM2,PGECLO,PGESLO,&
     & PCOSCO5,PSINCO5,PSINLA5,PCOPHI5,&
     & KROT,PLON5,PLAT5,PO5,PQ5,&
     & ZCOSLR5,ZCOSLA5,ZCOSL25,ZXX5,ZYY5,ZZW5,ZZA5,ZDECO5,Z1ST5,&
     & ZFACT5,ZZSINLA5,ZZCOSLA5,ZZSILON5,&
     & ZZY5,ZZX5,ZDI5,ZZZ5,ZZP5,Z1STT5,ZRP5,ZRQ5,ZCA5,ZSA5)

    DO JROF=KSTART,KPROF

      ! * Intermediate quantities:
      ZZY=PGESLO(JROF)*PCOSCO(JROF,JLEV)+PGECLO(JROF)*PSINCO(JROF,JLEV)
      ZZX=PGECLO(JROF)*PCOSCO(JROF,JLEV)-PGESLO(JROF)*PSINCO(JROF,JLEV)
      ZCOSL2(JROF)=2.0_JPRB*(ZZY5(JROF)*ZZY+ZZX5(JROF)*ZZX)
      ZCOSLR(JROF)=0.5_JPRB*ZCOSL2(JROF)/ZCOSLR5(JROF)
      ZZZ(JROF)=ZPCLOP*ZZX+ZPSLOP*ZZY
      ZZP=ZPSLAP*PSINLA(JROF,JLEV)+ZPCLAP*ZZZ(JROF)
      ZDI(JROF)=PC2M1*ZDI5(JROF)*ZDI5(JROF)*ZZP
      ZYY(JROF)=PDSTRET*ZDI5(JROF)*(-ZPCLOP*ZZY+ZPSLOP*ZZX) &
       & +PDSTRET*(-ZPCLOP*ZZY5(JROF)+ZPSLOP*ZZX5(JROF))*ZDI(JROF)
      ZXX=PDSTRET*ZDI5(JROF)*(ZPCLAP*PSINLA(JROF,JLEV)-ZPSLAP*ZZZ(JROF)) &
       & +PDSTRET*(ZPCLAP*PSINLA5(JROF,JLEV)-ZPSLAP*ZZZ5(JROF))*ZDI(JROF)
      ZCOSLA(JROF)=(ZXX5(JROF)*ZXX+ZYY5(JROF)*ZYY(JROF))/ZCOSLA5(JROF)
      ZSINLA=-(PC2M1-PC2P1*ZZP5(JROF))*ZDI(JROF)+PC2P1*ZDI5(JROF)*ZZP

      ! * PLAT:
      ZMU=ZSINLA
      PLAT(JROF,JLEV)=ZMU/ZZCOSLA5(JROF)

      ! * PLON:
      ZZW=ZZW5(JROF)*(ZXX/ZXX5(JROF)-ZCOSLA(JROF)/ZCOSLA5(JROF))
      ! * If zyy5>=0, do the differenciation of "plon=acos(zzw)"
      !   (in this case, plon5 is in [0,pi]);
      !   if zyy5<0, do the differenciation of "plon=2 pi - acos(zzw)"
      !   (in this case, plon5 is in ]pi,2pi[).
      !   In all cases, that yields plon=-zzw/zzsilon5.
      PLON(JROF,JLEV)=-ZZW/ZZSILON5(JROF)

    ENDDO

    IF (KROT == 1) THEN
      DO JROF=KSTART,KPROF

        ZDECO=-ZDECO5(JROF)*ZDECO5(JROF)*PCOPHI(JROF,JLEV)
        Z1ST=-Z1ST5(JROF)*Z1ST5(JROF)*ZCOSLR(JROF)

        ZP=(PGSQM2(JROF)*ZCOSLR5(JROF) &
         & +(1.0_JPRB+PGEMU(JROF)*PSINLA5(JROF,JLEV)) &
         & *PCOSCO5(JROF,JLEV)*Z1ST5(JROF) )*ZDECO &
         & +ZDECO5(JROF)*PGSQM2(JROF)*ZCOSLR(JROF) &
         & +ZDECO5(JROF)*PCOSCO5(JROF,JLEV)*Z1ST5(JROF)*PGEMU(JROF) &
         & *PSINLA(JROF,JLEV) &
         & +ZDECO5(JROF)*(1.0_JPRB+PGEMU(JROF)*PSINLA5(JROF,JLEV))*Z1ST5(JROF)&
         & *PCOSCO(JROF,JLEV) &
         & +ZDECO5(JROF)*(1.0_JPRB+PGEMU(JROF)*PSINLA5(JROF,JLEV))&
         & *PCOSCO5(JROF,JLEV)*Z1ST

        ZQ= &
         & -PSINCO5(JROF,JLEV)*Z1ST5(JROF)*ZDECO5(JROF)*PSINLA(JROF,JLEV) &
         & -(PGEMU(JROF)+PSINLA5(JROF,JLEV)) &
         & *Z1ST5(JROF)*ZDECO5(JROF)*PSINCO(JROF,JLEV) &
         & -(PGEMU(JROF)+PSINLA5(JROF,JLEV)) &
         & *PSINCO5(JROF,JLEV)*ZDECO5(JROF)*Z1ST &
         & -(PGEMU(JROF)+PSINLA5(JROF,JLEV)) &
         & *PSINCO5(JROF,JLEV)*Z1ST5(JROF)*ZDECO

        Z1STT=Z1STT5(JROF)*(Z1ST/Z1ST5(JROF)-ZCOSLA(JROF)/ZCOSLA5(JROF))
        ZCA=PDSTRET*(&
         & (ZPSLAP*ZCOSL25(JROF)-ZPCLAP*PSINLA5(JROF,JLEV)*ZZZ5(JROF)) &
         & *Z1STT5(JROF)*ZDI(JROF) &
         & +ZDI5(JROF)*Z1STT5(JROF)*ZPSLAP*ZCOSL2(JROF) &
         & -ZDI5(JROF)*Z1STT5(JROF)*ZPCLAP*ZZZ5(JROF)*PSINLA(JROF,JLEV)&
         & -ZDI5(JROF)*Z1STT5(JROF)*ZPCLAP*PSINLA5(JROF,JLEV)*ZZZ(JROF)&
         & +ZDI5(JROF) &
         & *(ZPSLAP*ZCOSL25(JROF)-ZPCLAP*PSINLA5(JROF,JLEV)*ZZZ5(JROF))*Z1STT )
        ZSA=-ZPCLAP*(ZYY5(JROF)*Z1STT+Z1STT5(JROF)*ZYY(JROF))
        PO(JROF,JLEV)=ZRP5(JROF)*ZCA+ZRQ5(JROF)*ZSA+ZCA5(JROF)*ZP+ZSA5(JROF)*ZQ
        PQ(JROF,JLEV)=ZRQ5(JROF)*ZCA-ZRP5(JROF)*ZSA-ZSA5(JROF)*ZP+ZCA5(JROF)*ZQ

      ENDDO
    ENDIF

  ENDDO

ENDIF

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

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

