SUBROUTINE LARMES2AD(KASLB1,KPROMA,KSTART,KPROF,KGLN,KGLX,KFLDN,KFLDX,&
 & KSTABUF,&
 & KVLAG,KWLAG,&
 & KITER,LDPLANE,LDSETTLS,&
 & LDELTRA,KFLDSLB1,PSLBUF1,&
 & PURL0,PVRL0,PURL,PVRL,&
 & PURL05,PVRL05,PURL5,PVRL5,&
 & KSTTYP,PDSTRET,PC2M1,PC2P1,P4JP,PI,PDEPI,PIS2,&
 & PDTSA,PDTS62,PDTS22,&
 & PLOCEN,PMUCEN,PLSDEPI,PLATI,PIPI0,PIPI1,PIPI2,&
 & PCOLON,PSILON,PGEMU,PGSQM2,PGECLO,PGESLO,&
 & PNORDL,PNORDM,&
 & PLON,PLAT,PCOSCO,PSINCO,&
 & PSINLA,PCOPHI,&
 & PLON5,PLAT5,PCOSCO5,PSINCO5,&
 & PSINLA5,PCOPHI5,PR5,PS5,PUF5,PVF5)  

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

!**** *LARMES2AD - semi-LAgrangian scheme:  (adjoint version)
!                Research of the MEdium point on the Sphere (2-d model)
!                2D shallow-water model.

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

!     The computation of the location of the medium point I 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.

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

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

!        INPUT:
!          KASLB1  - horizontal dimension of SLBUF1.
!          KPROMA  - horizontal dimension.
!          KSTART  - first element of arrays where
!                    computations are performed.
!          KPROF   - depth of work.
!          KGLN    - lower dimension for latitude.
!          KGLX    - upper dimension for latitude.
!          KFLDN   - number of the first field.
!          KFLDX   - number of the last field.
!          KSTABUF - for a latitude IGL, KSTABUF(IGL) is the
!                    address of the element corresponding to
!                    (ILON=1,IGL) in the KPROMA arrays.
!          KVLAG   - Switch for different discretizations of continuity
!                    equation.
!          KWLAG   - Switch for different discretizations of momentum
!                    equations.
!          KITER   - Number of iterations for computing the medium
!                    point.
!          LDPLANE - switch: .T. = plane geometry; .F. = spherical geometry.
!          LDSETTLS- switch: .T. = SETTLS two-time-level scheme
!          LDELTRA - switch: .T. = "elegant" algorithm to find origin point
!          KFLDSLB1- second dimension of PSLBUF1
!----------------------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.
!          PVRL5   - V-component of the wind.
!-----------------------------------------------------------------------
!          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.
!          P4JP    - Approximative inverse of the differences of latitudes.
!          PI      - number PI
!          PDEPI   - 2 * PI
!          PIS2    - PI / 2
!          PDTSA   - (Delta t/a)
!          PDTS62  - (Delta t/a)*(Delta t/a)/6
!          PDTS22  - (Delta t/a)*(Delta t/a)/2
!          PLOCEN  - geographical longitude of the stretching pole.
!          PMUCEN  - sine of the geographical latitude of the
!                    pole.
!          PLSDEPI - (Number of points by latitude) / (2 * PI) .
!          PLATI   - latitude on the computational sphere.
!          PIPI0   - coefficients for the bicubic interpolations.
!          PIPI1   -      "
!          PIPI2   -      "
!          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.

!        INPUT, INPUT/OUTPUT or OUTPUT corresponding to INPUT/OUTPUT
!        in the TL code:
!          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.
!----------------------trajectory variables-----------------------------
!          PLON5   - computational sphere longitude of interpolation point.
!          PLAT5   - computational sphere latitude of interpolation point.
!          PCOSCO5 - cos(Longitude-Longitude(grid-point))*cos(Latitude)
!                    of the interpolation point (geographical longitude
!                    and latitude).
!          PSINCO5 - sin(Longitude-Longitude(grid-point))*cos(Latitude)
!                    of the interpolation point (geographical longitude
!                    and latitude).
!          PSINLA5 - sine of the interpolation point geographical latitude.
!          PCOPHI5 - cosine of the geographical angle between the
!                    interpolation point and the grid-point.
!          PR5     - first element of the wind displacement matrix.
!          PS5     - second element of the wind displacement matrix.
!          PUF5    - interpolated U-component of the wind
!          PVF5    - interpolated V-component of the wind
!----------------------------------------------------------------------

!        INPUT/OUTPUT:
!          PSLBUF1 - semi-Lagrangian buffers for interpolations.
!          PURL0   - U-component of the wind, to be interpolated.
!          PVRL0   - V-component of the wind, to be interpolated.
!          PURL    - U-component of the wind.
!          PVRL    - V-component of the wind.
!-----------------------------------------------------------------------

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

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

!     Externals.
!     ----------
!        Calls  LARCIN2AD.
!        Is called by LADINEAD (2D shallow water model).

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

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

!     Modifications.
!     --------------
!     Original : 98/10/21
!     Modified 98-12-23 by C.Temperton: Cleaning, following LARMES2.
!     Modified 99-01-06 by C.Temperton: NVLAG=1 option added.
!     Modified 99-01-11 by C.Temperton: KITER>1 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
!     K. Yessad (Sep 2008): update comments + cleanings.
!     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)    :: KGLN 
INTEGER(KIND=JPIM),INTENT(IN)    :: KGLX 
INTEGER(KIND=JPIM),INTENT(IN)    :: KFLDN 
INTEGER(KIND=JPIM),INTENT(IN)    :: KFLDX 
INTEGER(KIND=JPIM),INTENT(IN)    :: KITER 
INTEGER(KIND=JPIM),INTENT(IN)    :: KFLDSLB1 
INTEGER(KIND=JPIM),INTENT(IN)    :: KSTART 
INTEGER(KIND=JPIM),INTENT(IN)    :: KPROF 
INTEGER(KIND=JPIM),INTENT(IN)    :: KSTABUF(KGLN:KGLX) 
INTEGER(KIND=JPIM),INTENT(IN)    :: KVLAG 
INTEGER(KIND=JPIM),INTENT(IN)    :: KWLAG 
LOGICAL           ,INTENT(IN)    :: LDPLANE 
LOGICAL           ,INTENT(IN)    :: LDSETTLS 
LOGICAL           ,INTENT(IN)    :: LDELTRA 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PSLBUF1(KASLB1,KFLDSLB1) 
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(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) 
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)    :: P4JP 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PI 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PDEPI 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PIS2 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PDTSA 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PDTS62 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PDTS22 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PLOCEN 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PMUCEN 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PLSDEPI(KGLN:KGLX) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PLATI(KGLN:KGLX) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PIPI0(KGLN:KGLX) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PIPI1(KGLN:KGLX) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PIPI2(KGLN:KGLX) 
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)    :: PNORDL(KPROMA) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PNORDM(KPROMA) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PLON(KPROMA) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PLAT(KPROMA) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PCOSCO(KPROMA) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PSINCO(KPROMA) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PSINLA(KPROMA) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PCOPHI(KPROMA) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PLON5(KPROMA) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PLAT5(KPROMA) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PCOSCO5(KPROMA,KITER) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PSINCO5(KPROMA,KITER) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PSINLA5(KPROMA,KITER) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PCOPHI5(KPROMA,KITER) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PR5(KPROMA,KITER) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PS5(KPROMA,KITER) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PUF5(KPROMA,KITER) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PVF5(KPROMA,KITER) 

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

REAL(KIND=JPRB) :: ZUF(KPROMA)
REAL(KIND=JPRB) :: ZVF(KPROMA)
REAL(KIND=JPRB) :: ZR(KPROMA)
REAL(KIND=JPRB) :: ZS(KPROMA)

INTEGER(KIND=JPIM) :: IWISA
INTEGER(KIND=JPIM) :: IXLAG(6)

INTEGER(KIND=JPIM) :: IINC, IROT, JITER, JROF

REAL(KIND=JPRB) :: ZC0(1), ZC05(1), ZCL0(1), ZCL05(1), ZDTS22, ZDTS62,&
 & ZDTSA, ZINT, ZNOR2, ZNOR25, ZPU, ZPU5, ZPV, &
 & ZPV5, ZSPHSV, ZSPHSV5, ZU0(1), ZU05(1), ZUL0(1), &
 & ZUL05(1), ZV0(1), ZV05(1), ZVL0(1), &
 & ZVL05(1), ZZUZ0(1), ZZVZ0(1)  
REAL(KIND=JPRB) :: ZHOOK_HANDLE

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

#include "larcin2ad.intfb.h"

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

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

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

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

IXLAG(1)=KVLAG
IXLAG(4)=KWLAG

IF((LDSETTLS.OR.LDELTRA).AND.(KITER > 1)) THEN
  ZDTS22=PDTS22*4
  ZDTSA=PDTSA*2
  ZDTS62=PDTS62*4
ELSE
  ZDTS22=PDTS22
  ZDTSA=PDTSA
  ZDTS62=PDTS62
ENDIF

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

!*       2.    ITERATIONS.    (Adjoint)
!              -----------

DO JITER=KITER,1,-1

!*       2.2   DETERMINATION OF THE WIND AT THE MEDIUM POINT "I".

  IF(JITER /= KITER) THEN

    IWISA=1
    IROT=1

!          Warning: ZUL0,ZVL0,ZCL0,
!                   ZU0,ZV0,ZC0,
!                   ZZUZ0,ZZVZ0
!                   are not used in this call of LARCIN2.

!   * Compute number of updates for LARCIN2AD:
    IINC=8

    CALL LARCIN2AD(KASLB1,KPROMA,KSTART,KPROF,KGLN,KGLX,KFLDN,KFLDX,&
     & KSTABUF,&
     & IWISA,IXLAG,IROT,LDPLANE,&
     & IINC,KFLDSLB1,PSLBUF1,&
     & KSTTYP,PDSTRET,PC2M1,PC2P1,P4JP,PI,PDEPI,PIS2,&
     & PLOCEN,PMUCEN,PLSDEPI,PLATI,PIPI0,PIPI1,PIPI2,&
     & PCOLON,PSILON,PGEMU,PGSQM2,PGECLO,PGESLO,&
     & PCOSCO,PSINCO,PSINLA,PCOPHI,&
     & PCOSCO5(1,JITER),PSINCO5(1,JITER),&
     & PSINLA5(1,JITER),PCOPHI5(1,JITER),&
     & PURL0,PVRL0,&
     & ZUL0,ZVL0,ZCL0,ZUL0,ZVL0,ZCL0,&
     & PURL05,PVRL05,&
     & ZUL05,ZVL05,ZCL05,ZUL05,ZVL05,ZCL05,&
     & PLON,PLAT,&
     & ZR,ZS,&
     & ZUF,ZVF,&
     & ZU0,ZV0,ZC0,&
     & PLON5,PLAT5,&
     & PR5(1,JITER),PS5(1,JITER),&
     & PUF5(1,JITER),PVF5(1,JITER),&
     & ZU05,ZV05,ZC05,&
     & ZZUZ0,ZZVZ0)  

  ENDIF

  IF (JITER == 1) THEN

    DO JROF=KSTART,KPROF

!             computations on horizontal plans.

      ZNOR25= ( PURL5(JROF)*PURL5(JROF)+PVRL5(JROF)*PVRL5(JROF) )
      ZSPHSV5          =ZDTSA*(1.0_JPRB-ZDTS62*ZNOR25)

      ZSPHSV=-( PURL5(JROF)*PNORDM(JROF)&
       & -PVRL5(JROF)*PNORDL(JROF) )*PSINCO(JROF)  
      PURL(JROF)=PURL(JROF)-ZSPHSV5*PNORDM(JROF)*PSINCO(JROF)
      PVRL(JROF)=PVRL(JROF)+ZSPHSV5*PNORDL(JROF)*PSINCO(JROF)
      ZINT=PGEMU(JROF)*PCOSCO(JROF)
      PCOPHI(JROF)=PCOPHI(JROF)+PGSQM2(JROF)*PCOSCO(JROF)
      ZINT=ZINT-PGSQM2(JROF)*PSINLA(JROF)
      PCOPHI(JROF)=PCOPHI(JROF)+PGEMU(JROF)* PSINLA(JROF)
      ZSPHSV=ZSPHSV+( PURL5(JROF)*PNORDL(JROF)&
       & +PVRL5(JROF)*PNORDM(JROF) )*ZINT  
      PURL(JROF)=PURL(JROF)+ZSPHSV5*PNORDL(JROF)*ZINT
      PVRL(JROF)=PVRL(JROF)+ZSPHSV5*PNORDM(JROF)*ZINT
      ZNOR2=-ZDTSA*ZDTS62*ZSPHSV
      ZNOR2=ZNOR2-ZDTS22*PCOPHI(JROF)
      PURL(JROF)=PURL(JROF)+2.0_JPRB*PURL5(JROF)*ZNOR2
      PVRL(JROF)=PVRL(JROF)+2.0_JPRB*PVRL5(JROF)*ZNOR2
      PSINCO(JROF)=0.0_JPRB
      PCOSCO(JROF)=0.0_JPRB
      PSINLA(JROF)=0.0_JPRB
      PCOPHI(JROF)=0.0_JPRB

    ENDDO

  ELSE

    DO JROF=KSTART,KPROF

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

      IF(LDSETTLS) THEN
        ZPU5= 0.5_JPRB*(PR5(JROF,JITER-1)*PUF5(JROF,JITER-1)&
         & +PS5(JROF,JITER-1)*PVF5(JROF,JITER-1)&
         & +PURL5(JROF)*PNORDM(JROF)&
         & -PVRL5(JROF)*PNORDL(JROF))  
        ZPV5=0.5_JPRB*(-PS5(JROF,JITER-1)*PUF5(JROF,JITER-1)&
         & +PR5(JROF,JITER-1)*PVF5(JROF,JITER-1)&
         & +PURL5(JROF)*PNORDL(JROF)&
         & +PVRL5(JROF)*PNORDM(JROF))  
      ELSE
        ZPU5= PR5(JROF,JITER-1)*PUF5(JROF,JITER-1)&
         & +PS5(JROF,JITER-1)*PVF5(JROF,JITER-1)  
        ZPV5=-PS5(JROF,JITER-1)*PUF5(JROF,JITER-1)&
         & +PR5(JROF,JITER-1)*PVF5(JROF,JITER-1)  
      ENDIF
      ZNOR25       =(ZPU5*ZPU5+ZPV5*ZPV5)
      IF (JITER == KITER) THEN
        ZSPHSV5      =PDTSA*(1.0_JPRB-PDTS62*ZNOR25)
      ELSE
        ZSPHSV5      =ZDTSA*(1.0_JPRB-ZDTS62*ZNOR25)
      ENDIF

      ZPU=-ZSPHSV5*PSINCO(JROF)
      ZSPHSV=-ZPU5*PSINCO(JROF)
      ZINT=PGEMU(JROF)*PCOSCO(JROF)
      PCOPHI(JROF)=PCOPHI(JROF)+PGSQM2(JROF)*PCOSCO(JROF)
      ZINT=ZINT-PGSQM2(JROF)*PSINLA(JROF)
      PCOPHI(JROF)=PCOPHI(JROF)+PGEMU(JROF)*PSINLA(JROF)
      ZSPHSV=ZSPHSV+ZPV5*ZINT
      ZPV=ZSPHSV5*ZINT
      IF (JITER == KITER) THEN
        ZNOR2=-PDTSA*PDTS62*ZSPHSV-PDTS22*PCOPHI(JROF)
      ELSE
        ZNOR2=-ZDTSA*ZDTS62*ZSPHSV-ZDTS22*PCOPHI(JROF)
      ENDIF
      ZPU=ZPU+2.0_JPRB*ZPU5*ZNOR2
      ZPV=ZPV+2.0_JPRB*ZPV5*ZNOR2
      IF(LDSETTLS) THEN
        ZR(JROF)=0.5_JPRB*(PUF5(JROF,JITER-1)*ZPU+PVF5(JROF,JITER-1)*ZPV)
        ZS(JROF)=0.5_JPRB*(PVF5(JROF,JITER-1)*ZPU-PUF5(JROF,JITER-1)*ZPV)
        ZUF(JROF)=0.5_JPRB*(PR5(JROF,JITER-1)*ZPU-PS5(JROF,JITER-1)*ZPV)
        ZVF(JROF)=0.5_JPRB*(PS5(JROF,JITER-1)*ZPU+PR5(JROF,JITER-1)*ZPV)
        PURL(JROF)=PURL(JROF)+0.5_JPRB*(PNORDM(JROF)*ZPU+PNORDL(JROF)*ZPV)
        PVRL(JROF)=PVRL(JROF)+0.5_JPRB*(PNORDM(JROF)*ZPV-PNORDL(JROF)*ZPU)
      ELSE
        ZR(JROF)=PUF5(JROF,JITER-1)*ZPU+PVF5(JROF,JITER-1)*ZPV
        ZS(JROF)=PVF5(JROF,JITER-1)*ZPU-PUF5(JROF,JITER-1)*ZPV
        ZUF(JROF)=PR5(JROF,JITER-1)*ZPU-PS5(JROF,JITER-1)*ZPV
        ZVF(JROF)=PS5(JROF,JITER-1)*ZPU+PR5(JROF,JITER-1)*ZPV
      ENDIF

      PSINCO(JROF)=0.0_JPRB
      PCOSCO(JROF)=0.0_JPRB
      PSINLA(JROF)=0.0_JPRB
      PCOPHI(JROF)=0.0_JPRB

    ENDDO

  ENDIF

ENDDO

!     ------------------------------------------------------------------
IF (LHOOK) CALL DR_HOOK('LARMES2AD',1,ZHOOK_HANDLE)
END SUBROUTINE LARMES2AD
