SUBROUTINE CPG2LAG(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 PTRSLB1  , ONLY : MSLB1UR0 ,MSLB1VR0 ,MSLB1U0  ,MSLB1V0  ,&
 & MSLB1SP0 ,MSLB1U9  ,MSLB1V9  ,MSLB1SP9  
USE PTRSLB2  , ONLY : MSLB2USI,MSLB2VSI,MSLB2URL ,MSLB2VRL
USE YOMGMV   , ONLY : NDIMGMV,NDIMGMVS

!**** *CPG2LAG* - Grid point calculations 2D lagged part .

!     Purpose.
!     --------
!           Grid point calculations 2D lagged part.

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

!        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 semi-Lagrangian 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.
!     ----------
!      Calls LADINE.
!      Is called by SCAN2M.

!     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 94-10-17 by M. Tolstykh: CUD-5 interpolation for SL scheme.
!      K. YESSAD (JAN 1995):
!            - Simplification of treatment of NVLAG=2 formulation of
!              continuity equation (buffer SLB1WR0 no longer required).
!      Modified 95-03-01 by M.Hamrud (F90 re-write)
!      Modified 96-04-04 by L.Isaksen (Adapted for Message Passing)
!      Modified 97-06-20 by K. YESSAD (bug correction)
!      Modified 97-05-14 by C.Temperton (NWLAG=3, NVLAG=3 options added)
!      Modified 98-01-19 by C.Temperton (L2TLFF option in 2TL SL scheme)
!      Modified 98-03-04 by C.Temperton (LSETTLS option in 2TL SL scheme)
!      Modified 98-07-31 by K. YESSAD and C. TEMPERTON: cleaning
!        - removal of CUD-5 interpolations.
!        - use of PTRSLB1 and PTRSLB2 pointers.
!        - correction of false comments.
!        - complete declaration of dummy arguments.
!        - make the code more consistent with the one of CPGLAG, especially DM.
!        - adapt to LADINE cleanings.
!   01-Oct-2003 M. Hamrud   CY28 Cleaning
!   30-Jul-2008 J. Masek    Dataflow for new SLHD interpolators.
! End Modifications
!-------------------------------------------------------------------------------

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 "ladine.intfb.h"

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

IF (LHOOK) CALL DR_HOOK('CPG2LAG',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 LADINE(IST,IEND,KASLB1,NPROMA,1,IFLDX,&
   & PCOLON,PSILON,PGM,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),&
   & PB2(1,MSLB2USI),PB2(1,MSLB2VSI),&
   & PUT1,PVT1,PSPT1)  

ENDIF

CALL GPTF1(IST,IEND,LLLSTEP,PGMV,PGMVS,ZDUMARR)
 
!*       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('CPG2LAG',1,ZHOOK_HANDLE)
END SUBROUTINE CPG2LAG
