SUBROUTINE CPG2LAGTL(KNUMB,KASLB1,&
 & PB1,PB2,PGMV,PGMVS,PGM,PGEMU,PGSQM2,PGECLO,PGESLO,&
 & PGNORDL,PGNORDM,PCOLON,PSILON,PRINDX,PRINDY,&
 & PUT1,PVT1,PSPT1)  

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

USE YOMDIM   , ONLY : NPROMA
USE YOMCT0   , ONLY : LSLAG
USE YOMCT2   , ONLY : NSTOP2
USE YOMCT3   , ONLY : NSTEP
USE YOMSC2   , ONLY : NFLDSLB1 ,NFLDSLB2 
USE PTRSLB2  , ONLY : &
 & MSLB2URL ,MSLB2VRL ,MSLB2URL5,MSLB2VRL5,&
 & MSLB2USI ,MSLB2VSI ,MSLB2USI5,MSLB2VSI5,&
 & MSLB2U15 ,MSLB2V15  
USE PTRSLB1  , ONLY : MSLB1U9  ,MSLB1V9  ,MSLB1SP9 ,MSLB1U0  ,&
 & MSLB1V0  ,MSLB1SP0 ,MSLB1UR0 ,MSLB1VR0  
USE PTRSLB15  , ONLY : MSLB1U95 ,&
 & MSLB1V95 ,MSLB1SP95,MSLB1U05 ,MSLB1V05 ,MSLB1SP05,&
 & MSLB1UR05,MSLB1VR05  
USE YOMGMV   , ONLY : NDIMGMV,NDIMGMVS

!**** *CPG2LAGTL* - Grid point calculations 2D lagged part .(T.L.)

!     Purpose.
!     --------
!           Grid point calculations 2D lagged part (tangent linear).

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

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

!        INPUT and INPUT-OUTPUT:
!         KNUMB     : number of elements of arrays for which computations
!                     are performed (used in message passing version).
!         KASLB1    : horizontal dimension for semi-Lagrangian buffer.
!         PB1       : buffer for quantities to be interpolated.
!         PB2       : buffer for quantities at the arrival grid-point.
!         PGMV      : "t-dt" and "t" upper air GMV variables.
!         PGMVS     : "t-dt" and "t" surface GMV variables.
!         PGM       : mapping factor.
!         PGEMU     : sinus of the grid-point geographical latitude.
!         PGSQM2    : cosinus of the grid-point geographical latitude.
!         PGECLO    : cosinus of the grid-point geographical longitude.
!         PGESLO    : sinus 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.
!         PCOLON    : cosinus of the grid-point longitude on the
!                     computational sphere.
!         PSILON    : sinus of the grid-point longitude on the
!                     computational sphere.
!         PRINDX    : x coordinate on the plane.
!         PRINDY    : y coordinate on the plane.

!        OUTPUT:
!         PUT1      : t+dt U-wind.
!         PVT1      : t+dt V-wind.
!         PSPT1     : t+dt equivalent height.

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

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

!     Externals.
!     ----------
!      Is called by SCAN2MTL.

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

!     Author.
!     -------
!        Mats Hamrud  *ECMWF*

!     Modifications.
!     --------------
!      Original : 92-02-01
!      D.Dent   : 92-06-25   Remove event logic
!      Modified 95-03-01 by M.Hamrud (F90 re-write)
!      Modified 96-04-04 by L.Isaksen (Adapted for Message Passing)
!      Modified 98-08-05 by K. YESSAD: cleanings according to the CPG2LAG ones.
!      Modified 98-06-16 by C.Temperton (TL of semi-Lagrangian)
!      Modified 99-03-10 by C.Temperton (bugfix for LMESSP=.T.)
!      Modified 99-06-16 by C.Temperton (L2TLFF option added)
!      M.Hamrud      01-Oct-2003 CY28 Cleaning
!      K. Yessad Nov 2008: rationalisation of dummy argument interfaces
!     ------------------------------------------------------------------

IMPLICIT NONE

INTEGER(KIND=JPIM),INTENT(IN)    :: KASLB1 
INTEGER(KIND=JPIM),INTENT(IN)    :: KNUMB 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PB1(KASLB1,NFLDSLB1) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PB2(NPROMA,NFLDSLB2) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PGMV(NPROMA,1,NDIMGMV) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PGMVS(NPROMA,NDIMGMVS) 
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)    :: PCOLON(NPROMA) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PSILON(NPROMA) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PRINDX(NPROMA) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PRINDY(NPROMA) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PUT1(NPROMA) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PVT1(NPROMA) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PSPT1(NPROMA) 

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

INTEGER(KIND=JPIM) :: IEND, IFLDX, IST, JROF
REAL(KIND=JPRB)    :: ZDUMARR(1,1,1)
LOGICAL   :: LLLSTEP
REAL(KIND=JPRB) :: ZHOOK_HANDLE

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

#include "gptf1.intfb.h"
#include "ladinetl.intfb.h"

!     ------------------------------------------------------------------
IF (LHOOK) CALL DR_HOOK('CPG2LAGTL',0,ZHOOK_HANDLE)
!     ------------------------------------------------------------------

!*       1.    PRELIMINARY COMPUTATIONS.
!              -------------------------

!*       1.1   COMPUTE "IST", "IEND"

IST =1
IEND=KNUMB
IF(NSTEP < NSTOP2) THEN
  LLLSTEP=.FALSE.
ELSE
  LLLSTEP=.TRUE.
ENDIF

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

!*       2.   LAGGED PART OF GRIDPOINT COMPUTATIONS
!             -------------------------------------

!*       2.1  LAGGED SEMI-LAGRANGIAN CALCULATIONS

IF(LSLAG) THEN

  IFLDX=NFLDSLB1
  CALL LADINETL(IST,IEND,KASLB1,NPROMA,1,IFLDX,&
   & PCOLON,PSILON,PGEMU,PGSQM2,PGECLO,PGESLO,&
   & PGNORDL,PGNORDM,PRINDX,PRINDY,&
   & PB1(1,MSLB1UR0),PB1(1,MSLB1VR0),&
   & PB2(1,MSLB2URL)  ,PB2(1,MSLB2VRL),&
   & PB1(1,MSLB1U0) ,PB1(1,MSLB1V0),PB1(1,MSLB1SP0),&
   & PB1(1,MSLB1U9) ,PB1(1,MSLB1V9),PB1(1,MSLB1SP9),&
   & PB1(1,MSLB1UR05),PB1(1,MSLB1VR05),&
   & PB2(1,MSLB2URL5)  ,PB2(1,MSLB2VRL5),&
   & PB1(1,MSLB1U05) ,PB1(1,MSLB1V05),PB1(1,MSLB1SP05),&
   & PB1(1,MSLB1U95) ,PB1(1,MSLB1V95),PB1(1,MSLB1SP95),&
   & PB2(1,MSLB2USI),PB2(1,MSLB2VSI),&
   & PB2(1,MSLB2USI5),PB2(1,MSLB2VSI5),&
   & PUT1,PVT1,PSPT1,&
   & PB2(1,MSLB2U15),PB2(1,MSLB2V15))  

ENDIF

CALL GPTF1(IST,IEND,LLLSTEP,PGMV,PGMVS,ZDUMARR)
 
!*       2.2  COMMON PART FOR LAGGED EUL AND SL CALCULATIONS.

!*       2.4  DIVIDE BY MAP FACTOR

DO JROF=IST,IEND
  PUT1(JROF)=PUT1(JROF)/PGM(JROF)
  PVT1(JROF)=PVT1(JROF)/PGM(JROF)
ENDDO

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

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