SUBROUTINE LATTE_KAPPATL(KST,KPROF,PDTS2,PSLHDA,PSLHDD0, &
 & PGMV,PGMV5,PB2)

!**** *LATTE_KAPPATL* input for SLHD diffusion. (tangent-liner version)
!                   Computation of the kappa function ("coefficient
!                   of diffusion") based on rescaled horizontal
!                   deformation of the flow to be evaluated at F, and put
!                   it in PB2.

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

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

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

!        INPUT:
!          KST     - first element of work.
!          KPROF   - depth of work.
!          PDTS2   - 0.5*"pdt", where "pdt" =
!                    time step for the first time-integration step of
!                    a leap-frog scheme or all time-integration steps of
!                    a two-time level scheme; 2*time step for the following
!                    time-integration steps of a leap-frog scheme.
!          PSLHDA  - Scaling factor of the deformation in f(d) function
!                    (including the model resolution correction)
!          PSLHDD0 - Treshold for deformation tensor enhancement
!          PGMV    - GMV variables at t-dt and t.
!          PGMV5   - GMV variables (trajectory) at t-dt and t.

!        INPUT/OUTPUT:
!          PB2     - "SLBUF2" buffer (containing both: increments + trajectory)

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

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

!     Externals.
!     ----------
!        Called by LACDYNTL.

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

!     Author.
!     -------
!        Original F. VANA : December 2008

!     Modifications.
!     --------------

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

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

USE YOMDIM   , ONLY : NPROMA   ,NFLEVG
USE YOMGMV   , ONLY : NDIMGMV  ,YT0     ,YT5
USE YOMSC2   , ONLY : NFLDSLB2
USE PTRSLB2  , ONLY : MSLB2KAPPA

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

IMPLICIT NONE

INTEGER(KIND=JPIM),INTENT(IN)    :: KST 
INTEGER(KIND=JPIM),INTENT(IN)    :: KPROF 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PDTS2 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PSLHDA(NPROMA)
REAL(KIND=JPRB)   ,INTENT(IN)    :: PSLHDD0(NPROMA)
REAL(KIND=JPRB)   ,INTENT(IN)    :: PGMV(NPROMA,NFLEVG,NDIMGMV)
REAL(KIND=JPRB)   ,INTENT(IN)    :: PGMV5(NPROMA,NFLEVG,YT5%NDIM)
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PB2(NPROMA,NFLDSLB2)

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

INTEGER(KIND=JPIM) :: JLEV

REAL(KIND=JPRB) :: ZKAPPA(NPROMA,NFLEVG) 

REAL(KIND=JPRB) :: ZHOOK_HANDLE

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

#include "gp_kappatl.intfb.h"

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

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

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

!*       1.   Kappa function computation

CALL GP_KAPPATL(NPROMA,KST,KPROF,NFLEVG,PDTS2,&
 & PGMV5(1,1,YT5%MUL),PGMV5(1,1,YT5%MVL),&
 & PGMV5(1,1,YT5%MVOR),PGMV5(1,1,YT5%MDIV),&
 & PGMV(1,1,YT0%MUL),PGMV(1,1,YT0%MVL),PGMV(1,1,YT0%MVOR),PGMV(1,1,YT0%MDIV),&
 & PSLHDA,PSLHDD0,ZKAPPA)

!*       2.   Fill PB2 with Kappa

DO JLEV=1,NFLEVG
  PB2(KST:KPROF,MSLB2KAPPA+JLEV-1) =ZKAPPA(KST:KPROF,JLEV)
ENDDO

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

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