!OPTIONS XOPT(HSFUN)
SUBROUTINE GWDRAGTL( KIDIA,KFDIA,KLON,KLEV,&
 & PTSPHY, KSTEP, KSTART,&
 & PAPHM15,PAPM15,PGEOM15,PTM15,PUM15,&
 & PVM15, PHSTD  , PGAMMA, PTHETA, PSIG,&
 & PAPHM1 ,PAPM1 ,PGEOM1 ,PTM1 ,PUM1,&
 & PVM1,&
 ! OUTPUTS
 & PUSTRGW5,PVSTRGW5,PVDISGW5,PVOL5,PVOM5,PTE5,&
 & PUSTRGW ,PVSTRGW ,PVDISGW ,PVOL ,PVOM ,PTE,&
 !  FLUX OUTPUTS
 & PSTRDU5,PSTRDV5,&
 & PSTRDU ,PSTRDV                             )  

!**** *GWDRAGTL* - DOES THE GRAVITY WAVE PARAMETRIZATION.
!                  (Tangent linear)

!     J.-F. MAHFOUF           E.C.M.W.F.               07/05/96

!     PURPOSE.
!     --------

!          THIS ROUTINE COMPUTES THE PHYSICAL TENDENCIES OF THE
!     PROGNOSTIC VARIABLES U,V  AND T DUE TO  VERTICAL TRANSPORTS BY
!     SUBGRIDSCALE OROGRAPHICALLY EXCITED GRAVITY WAVES

!**   INTERFACE.
!     ----------
!          CALLED FROM *CALLPARTL*.

!          THE ROUTINE TAKES ITS INPUT FROM THE LONG-TERM STORAGE:
!          U,V,T AND P AT T-1.

!        EXPLICIT ARGUMENTS :
!        --------------------

!     ==== INPUTS ===

!        *KIDIA*       START POINT
!        *KFDIA*       END POINT
!        *KLON*        NUMBER OF GRID POINTS PER PACKET
!        *KLEV*        NUMBER OF VERTICAL LEVELS
!        *KGL1*        ROW NUMBER FOR PRINTINGS (UNUSED)
!        *KSTEP*       CURRENT TIME STEP INDEX
!        *KSTART*      FIRST STEP OF THE MODEL
!        *PTSPHY*      TIME STEP OF THE PHYSICS
!        *PAPHM15*     PRESSURE AT HALF LEVELS AT T-1   (Trajectory)
!        *PAPM15*      PRESSURE AT FULL LEVELS AT T-1   (Trajectory)
!        *PGEOM15*     GEOPOTENTIAL AT T-1              (Trajectory)
!        *PTM15*       TEMPERATURE AT T-1               (Trajectory)
!        *PUM15*       X-VELOCITY COMPONENT AT T-1      (Trajectory)
!        *PVM15*       Y-VELOCITY COMPONENT AT T-1      (Trajectory)
!        *PHSTD*       STANDARD DEVIATION OF THE SUBGRID SCALE OROGRAPHY
!        *PTHETA*      GEOGRAPHICAL ORIENTATION 
!                      OF THE SUBGRID SCALE  OROGRAPHY
!        *PGAMMA*      ANISOTROPY OF THE SUBGRID SCALE OROGRAPHY
!        *PSIG*        SLOPE OF THE SUBGRID SCALE OROGRAPHY
!        *PAPHM1*      PRESSURE AT HALF LEVELS AT T-1
!        *PAPM1*       PRESSURE AT FULL LEVELS AT T-1
!        *PGEOM1*      GEOPOTENTIAL AT T-1
!        *PTM1*        TEMPERATURE AT T-1
!        *PUM1*        X-VELOCITY COMPONENT AT T-1
!        *PVM1*        Y-VELOCITY COMPONENT AT T-1

!     ==== OUTPUTS ===

!        *PUSTRGW5*    SURFACE FLUX OF U-MOMENTUM       (Trajectory)
!        *PVSTRGW5*    SURFACE FLUX OF V-MOMENTUM       (Trajectory)
!        *PVDISGW5*    DISSIPATION OF KINTIC ENERGY     (Trajectory) 
!        *PVOM5*       TENDENCY OF U-COMP. OF WIND      (Trajectory)
!        *PVOL5*       TENDENCY OF V-COMP. OF WIND      (Trajectory) 
!        *PTE5*        TEMPERATURE TENDENCY             (Trajectory)
!        *PUSTRGW*     SURFACE FLUX OF U-MOMENTUM
!        *PVSTRGW*     SURFACE FLUX OF V-MOMENTUM
!        *PVDISGW*     DISSIPATION OF KINETIC ENERGY 
!        *PVOM*        TENDENCY OF U-COMP. OF WIND 
!        *PVOL*        TENDENCY OF V-COMP. OF WIND
!        *PTE*         TEMPERATURE TENDENCY    
!        *PSTRDU5*     FLUX OF U-MOMENTUM               (Trajectory)
!        *PSTRDV5*     FLUX OF V-MOMENTUM               (Trajectory)
!        *PSTRDU*      FLUX OF U-MOMENTUM
!        *PSTRDV*      FLUX OF V-MOMENTUM

!        IMPLICIT ARGUMENTS :   NONE
!        --------------------

!     METHOD.
!     -------
!          THE SCHEME CONSISTS OF THREE PARTS,THE CALCULATION OF LOWLEVEL
!         DRAG DUE TO WAKE EFFECTS OF THE SUBGRID OROGRAPHY,THE GRAVITY 
!         WAVE STRESS AND THE STRESS PROFILE IN THE VERTICAL.
!         THE STRESS IS COMPUTED USING A LOW-LEVEL WIND,STATIC STABILITY
!         AND  SUBGRID OROGRAPHIC PARAMETERS.THESE ARE THE STANDARD 
!         DEVIATION OF THE HEIGHT,THE ANGLE RELATIVE TO EAST, THE
!         ANISOTROPY,AND THE SLOPE.
!         A WAVE RICHARDSON NUMBER IS COMPUTED AT EACH LEVEL AND BY
!         REQUIRING THAT ITS VALUE IS NEVER LESS THAN A CRITICAL ONE
!         A VALUE OF STRESS IS DETERMINED AT EACH MODEL LEVEL.
!         THE CRITICAL FROUDE NUMBER OF THE FLOW DETERMINES THE DEPTH OF
!         THE LOWLEVEL DRAG.  

!     EXTERNALS.
!     ----------

!     REFERENCE.
!     ----------
!         SEE MODEL DOCUMENTATION

!        SEE ECMWF RESEARCH DEPARTMENT DOCUMENTATION OF THE "I.F.S."

!     AUTHOR.
!     -------
!     M.MILLER + B.RITTER   E.C.M.W.F.     15/06/86.

!     MODIFICATIONS.
!     --------------
!     REVISED BY MARTIN MILLER   E.C.M.W.F.   22/03/89.
!        M.Hamrud      01-Oct-2003 CY28 Cleaning

!     NEW VERSION MARTIN MILLER  E.C.M.W.F.   1993

!     CODED FOR IFS BY F.LOTT    E.C.M.W.F.   22/11/93
!-----------------------------------------------------------------------

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

USE YOMCST   , ONLY : RG       ,RCPD
USE YOEGWD   , ONLY : GKDRAG   ,GKWAKE   ,NGWDLIM,   GTENLIM,&
                    & NGWDTOP  ,GRFPLM
USE YOEPHLI  , ONLY : LPHYLIN  ,RLPDRAG

IMPLICIT NONE

INTEGER(KIND=JPIM),INTENT(IN)    :: KLON 
INTEGER(KIND=JPIM),INTENT(IN)    :: KLEV 
INTEGER(KIND=JPIM),INTENT(IN)    :: KIDIA 
INTEGER(KIND=JPIM),INTENT(IN)    :: KFDIA 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PTSPHY 
INTEGER(KIND=JPIM),INTENT(IN)    :: KSTEP 
INTEGER(KIND=JPIM),INTENT(IN)    :: KSTART 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PAPHM15(KLON,KLEV+1) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PAPM15(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PGEOM15(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PTM15(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PUM15(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PVM15(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PHSTD(KLON) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PGAMMA(KLON) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PTHETA(KLON) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PSIG(KLON) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PAPHM1(KLON,KLEV+1) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PAPM1(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PGEOM1(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PTM1(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PUM1(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PVM1(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PUSTRGW5(KLON) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PVSTRGW5(KLON) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PVDISGW5(KLON) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PVOL5(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PVOM5(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PTE5(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PUSTRGW(KLON) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PVSTRGW(KLON) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PVDISGW(KLON) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PVOL(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PVOM(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PTE(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PSTRDU5(KLON,KLEV+1) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PSTRDV5(KLON,KLEV+1) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PSTRDU(KLON,KLEV+1) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PSTRDV(KLON,KLEV+1) 

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

!*       0.1   ARGUMENTS
!              ---------

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

!              ------------
INTEGER(KIND=JPIM) ::  &
 & ICRIT(KLON),&
 & IKCRITH(KLON),&
 & IKENVH(KLON),&
 & IKNU(KLON),&
 & IKNU2(KLON)  

LOGICAL :: LLGWD(KLON)

REAL(KIND=JPRB) ::   ZTAU5(KLON,KLEV+1),&
 & ZSTAB5(KLON,KLEV+1),&
 & ZVPH5(KLON,KLEV+1),&
 & ZRHO5(KLON,KLEV+1),&
 & ZRI5(KLON,KLEV+1),&
 & ZPSI5(KLON,KLEV+1),&
 & ZZDEP5(KLON,KLEV)  
REAL(KIND=JPRB) ::   ZDUDT5(KLON),&
 & ZDVDT5(KLON),&
 & ZDTDT5(KLON),&
 & ZDEDT5(KLON),&
 & ZVIDIS5(KLON),&
 & ZULOW5(KLON),&
 & ZVLOW5(KLON),&
 & ZNU5(KLON),&
 & ZD15(KLON),&
 & ZD25(KLON),&
 & ZDMOD5(KLON)  

REAL(KIND=JPRB) :: ZUEA5(KLON,KLEV),ZVEA5(KLON,KLEV)

REAL(KIND=JPRB) ::   ZTAU(KLON,KLEV+1),&
 & ZSTAB(KLON,KLEV+1),&
 & ZVPH(KLON,KLEV+1),&
 & ZRHO(KLON,KLEV+1),&
 & ZRI(KLON,KLEV+1),&
 & ZPSI(KLON,KLEV+1),&
 & ZZDEP(KLON,KLEV)  
REAL(KIND=JPRB) ::   ZDUDT(KLON),&
 & ZDVDT(KLON),&
 & ZDTDT(KLON),&
 & ZDEDT(KLON),&
 & ZVIDIS(KLON),&
 & ZULOW(KLON),&
 & ZVLOW(KLON),&
 & ZD1(KLON),&
 & ZD2(KLON),&
 & ZDMOD(KLON)  

REAL(KIND=JPRB) :: ZUEA(KLON,KLEV),ZVEA(KLON,KLEV)

INTEGER(KIND=JPIM) :: ILEVP1, ILONS, JK, JL, IKTOP

REAL(KIND=JPRB) :: ZABSV, ZABSV5, ZB, ZBET, ZBET5, ZBLOCK, ZBLOCK5, ZC,&
 & ZCONB, ZCONS1, ZCS, ZCS5, ZDELP, ZDELP5, ZDELP0, ZDELP05, &
 & ZDIAGT, ZDIS, ZDIS5, ZEFF, ZEFF5, ZGDPH, ZGDPH5, &
 & ZKDRAG, ZRATIO, ZRATIO5, ZRTMST, ZS1, ZS15, &
 & ZS2, ZS25, ZSS, ZSS5, ZSTD, ZTEMP, ZTEMP5, &
 & ZTMST, ZUST, ZUST5, ZVST, ZVST5, ZZD1, ZZD15, Z1D9, ZIDIV5
REAL(KIND=JPRB) :: ZHOOK_HANDLE

#include "gwprofiltl.intfb.h"
#include "gwsetuptl.intfb.h"

!*************************************************************

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

!*         1.    INITIALIZATION
!                --------------

IF (LHOOK) CALL DR_HOOK('GWDRAGTL',0,ZHOOK_HANDLE)
ILONS=KFDIA-KIDIA+1
!     ------------------------------------------------------------------

!*         1.1   COMPUTATIONAL CONSTANTS
!                -----------------------

ZTMST=PTSPHY
ZRTMST=1.0_JPRB/ZTMST
Z1D9=1.0_JPRB/9.0_JPRB
IF(KSTEP == KSTART) THEN
  ZDIAGT=ZTMST
ELSE
  ZDIAGT=0.5_JPRB*ZTMST
ENDIF
ZCONS1=1.0_JPRB/(RG*ZTMST)

ZBLOCK=0.0_JPRB

!       SELECT POINTS FOR SCHEME TO OPERATE(SGS OROG >50METRES)  ****

DO JL=KIDIA,KFDIA
  IF (PHSTD(JL) > 50._JPRB) THEN
    LLGWD(JL)=.TRUE.
  ELSE
    LLGWD(JL)=.FALSE.
  ENDIF
ENDDO

!       Constant for surface stress

IF (LPHYLIN) THEN
  ZKDRAG=RLPDRAG
ELSE
  ZKDRAG=GKDRAG
ENDIF

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

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

!*         1.4   SAVING PROGNOSTIC VARIABLES
!                ---------------------------

DO JK=1,KLEV
  DO JL=KIDIA,KFDIA
    ZUEA (JL,JK)=PVOM (JL,JK)
    ZVEA (JL,JK)=PVOL (JL,JK)
    ZUEA5(JL,JK)=PVOM5(JL,JK)
    ZVEA5(JL,JK)=PVOL5(JL,JK)
  ENDDO
ENDDO

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

!*         2.     PRECOMPUTE BASIC STATE VARIABLES.
!*                ---------- ----- ----- ----------

CALL GWSETUPTL &
 & ( KIDIA , KFDIA , KLON    , KLEV  , LLGWD,&
 & IKCRITH , ICRIT,&
 & IKENVH, IKNU    , IKNU2,&
 & PAPHM15, PAPM15 , PUM15   , PVM15 , PTM15 , PGEOM15, PHSTD,&
 & ZRHO5  , ZRI5   , ZSTAB5  , ZTAU5 , ZVPH5 , ZPSI5  , ZZDEP5,&
 & ZULOW5 , ZVLOW5,&
 & PTHETA , PGAMMA , ZNU5    , ZD15  , ZD25  , ZDMOD5,&
 & PAPHM1 , PAPM1  , PUM1    , PVM1  , PTM1  , PGEOM1,&
 & ZRHO   , ZRI    , ZSTAB   , ZTAU  , ZVPH  , ZPSI   , ZZDEP,&
 & ZULOW  , ZVLOW,&
 & ZD1    , ZD2    , ZDMOD  )  

!***********************************************************

!*         3.      COMPUTE THE SURFACE GRAVITY WAVE STRESS

DO JL=KIDIA,KFDIA
  IF(LLGWD(JL)) THEN
    ZBLOCK=PGEOM1(JL,IKENVH(JL))/RG
    ZBLOCK5=PGEOM15(JL,IKENVH(JL))/RG
    ZSTD=PHSTD(JL)
    ZEFF5=MAX(0.0_JPRB,3.0_JPRB*ZSTD-ZBLOCK5)
    IF (ZEFF5 == 0) THEN
      ZEFF=0.0_JPRB
    ELSE
      ZEFF=-ZBLOCK
    ENDIF
    ZTAU (JL,KLEV+1)=Z1D9*ZKDRAG*PSIG(JL)*&
     & (ZRHO(JL,KLEV+1)*ZEFF5**2*ZVPH5(JL,KLEV+1)*&
     & ZDMOD5(JL)*SQRT(ZSTAB5(JL,KLEV+1))+&
     & ZRHO5(JL,KLEV+1)*2.0_JPRB*ZEFF5*ZEFF*ZVPH5(JL,KLEV+1)*&
     & ZDMOD5(JL)*SQRT(ZSTAB5(JL,KLEV+1))+&
     & ZRHO5(JL,KLEV+1)*ZEFF5**2*ZVPH(JL,KLEV+1)*&
     & ZDMOD5(JL)*SQRT(ZSTAB5(JL,KLEV+1))+&
     & ZRHO5(JL,KLEV+1)*ZEFF5**2*ZVPH5(JL,KLEV+1)*&
     & ZDMOD(JL)*SQRT(ZSTAB5(JL,KLEV+1))+&
     & ZRHO5(JL,KLEV+1)*ZEFF5**2*ZVPH5(JL,KLEV+1)*&
     & ZDMOD5(JL)*ZSTAB(JL,KLEV+1)/&
     & (2.0_JPRB*SQRT(ZSTAB5(JL,KLEV+1))))/ZSTD   
    ZTAU5(JL,KLEV+1)=ZKDRAG*ZRHO5(JL,KLEV+1)*PSIG(JL)*ZEFF5**2 &
     & *Z1D9/ZSTD*ZVPH5(JL,KLEV+1)*ZDMOD5(JL)*SQRT(ZSTAB5(JL,KLEV+1))  
  ELSE
    ZTAU (JL,KLEV+1)=0.0_JPRB
    ZTAU5(JL,KLEV+1)=0.0_JPRB
  ENDIF

ENDDO

!*         4.      COMPUTE STRESS PROFILE.
!*                 ------- ------ --------

CALL GWPROFILTL &
 & ( KIDIA , KFDIA  , KLON , KLEV,&
 & LLGWD,&
 & IKCRITH, ICRIT , IKENVH, IKNU,&
 & IKNU2 , PAPHM15, ZRHO5  , ZSTAB5 , ZVPH5,&
 & ZRI5  , ZTAU5  , ZDMOD5 , PSIG   ,PHSTD,&
 & PAPHM1, ZRHO   , ZSTAB  , ZVPH,&
 & ZRI   , ZTAU   , ZDMOD )  

!*         5.      COMPUTE TENDENCIES.
!*                 -------------------

DO JL=KIDIA,KFDIA
  ZVIDIS (JL)=0.0_JPRB
  ZDUDT  (JL)=0.0_JPRB
  ZDVDT  (JL)=0.0_JPRB
  ZDTDT  (JL)=0.0_JPRB
  ZVIDIS5(JL)=0.0_JPRB
  ZDUDT5 (JL)=0.0_JPRB
  ZDVDT5 (JL)=0.0_JPRB
  ZDTDT5 (JL)=0.0_JPRB
ENDDO

ILEVP1=KLEV+1

IKTOP=NGWDTOP

!     COMPUTES AND ADDS THE LOWLEVEL DRAG TENDENCIES TO THE GWD ONES 
!     LOWLEVEL CALCULATION IN PARTLY IMPLICIT FORM

DO JK=1,KLEV

!OCL  VCT(CEX)
  DO JL=KIDIA,KFDIA
    IF(LLGWD(JL)) THEN
      ZDELP =PAPHM1 (JL,JK+1)-PAPHM1 (JL,JK)
      ZDELP5=PAPHM15(JL,JK+1)-PAPHM15(JL,JK)
! adjust in pressure < 10hPa
      IF( PAPM15(JL,JK) < GRFPLM) THEN
        ZDELP0 =PAPHM1 (JL,IKTOP+1)-PAPHM1 (JL,1)
        ZDELP05=PAPHM15(JL,IKTOP+1)-PAPHM15(JL,1)
        ZIDIV5=1._JPRB/(ZVPH5(JL,ILEVP1)*ZDELP05**2)
        ZTEMP=-RG*(((ZTAU(JL,IKTOP+1)-ZTAU(JL,1))*ZDELP5+&
         &         (ZTAU5(JL,IKTOP+1)-ZTAU5(JL,1))*ZDELP)*&
         &         (ZVPH5(JL,ILEVP1)*ZDELP05**2)-&
         &         (ZTAU5(JL,IKTOP+1)-ZTAU5(JL,1))*ZDELP5*&
         &         (2._JPRB*ZVPH5(JL,ILEVP1)*ZDELP05*ZDELP0+&
         &          ZVPH(JL,ILEVP1)*ZDELP05**2))*ZIDIV5**2
        ZTEMP5=-RG*(ZTAU5(JL,IKTOP+1)-ZTAU5(JL,1))*ZDELP5*ZIDIV5
      ELSE
        ZIDIV5=1._JPRB/(ZVPH5(JL,ILEVP1)*ZDELP5)
        ZTEMP  =-RG*((ZTAU(JL,JK+1)-ZTAU(JL,JK))*&
         & (ZVPH5(JL,ILEVP1)*ZDELP5)-&
         & (ZTAU5(JL,JK+1)-ZTAU5(JL,JK))*&
         & (ZVPH5(JL,ILEVP1)*ZDELP+ZVPH(JL,ILEVP1)*ZDELP5))*ZIDIV5**2
        ZTEMP5 =-RG*(ZTAU5(JL,JK+1)-ZTAU5(JL,JK))*ZIDIV5
      ENDIF

      ZS1 =(ZTEMP*ZDMOD5(JL)-ZTEMP5*ZDMOD(JL))/ZDMOD5(JL)**2
      ZS15=ZTEMP5/ZDMOD5(JL)
      ZDUDT (JL)=(ZULOW5(JL)*ZD15(JL)-ZVLOW5(JL)*ZD25(JL))*ZS1+&
       & (ZULOW5(JL)*ZD1 (JL)+ZULOW (JL)*ZD15(JL)-&
       & ZVLOW5(JL)*ZD2 (JL)-ZVLOW (JL)*ZD25(JL))*ZS15  
      ZDUDT5(JL)=(ZULOW5(JL)*ZD15(JL)-ZVLOW5(JL)*ZD25(JL))*ZS15
      ZDVDT (JL)=(ZVLOW5(JL)*ZD15(JL)+ZULOW5(JL)*ZD25(JL))*ZS1+&
       & (ZVLOW5(JL)*ZD1 (JL)+ZVLOW (JL)*ZD15(JL) +&
       & ZULOW5(JL)*ZD2 (JL)+ZULOW (JL)*ZD25(JL))*ZS15  
      ZDVDT5(JL)=(ZVLOW5(JL)*ZD15(JL)+ZULOW5(JL)*ZD25(JL))*ZS15
      
!LIMIT THE WIND TENDENCIES IN THE STRATOSPHERE
      IF(JK < NGWDLIM) THEN
        IF (ZDUDT5(JL)>GTENLIM) THEN
          ZDUDT (JL)= 0.0_JPRB
          ZDUDT5(JL)= GTENLIM
        ELSEIF (ZDUDT5(JL)<-GTENLIM) THEN
          ZDUDT (JL)= 0.0_JPRB
          ZDUDT5(JL)=-GTENLIM
        ENDIF    
        IF (ZDVDT5(JL)>GTENLIM) THEN
          ZDVDT (JL)= 0.0_JPRB
          ZDVDT5(JL)= GTENLIM
        ELSEIF (ZDVDT5(JL)<-GTENLIM) THEN
          ZDVDT (JL)= 0.0_JPRB
          ZDVDT5(JL)=-GTENLIM
        ENDIF    
      ENDIF

      IF(JK >= IKENVH(JL)) THEN
        ZB    =1.0_JPRB-0.18_JPRB*PGAMMA(JL)-0.04_JPRB*PGAMMA(JL)**2
        ZC    =0.48_JPRB*PGAMMA(JL)+0.3_JPRB*PGAMMA(JL)**2
        ZCS   =-2.0_JPRB*SIN(ZPSI5(JL,JK))*COS(ZPSI5(JL,JK))*ZPSI(JL,JK)
        ZCS5  =COS(ZPSI5(JL,JK))**2
        ZSS   =-ZCS
        ZSS5  =1.0_JPRB-ZCS5
        ZCONB =ZTMST*GKWAKE*PSIG(JL)/(2.0_JPRB*PHSTD(JL))
        ZABSV =0.5_JPRB*(PUM1(JL,JK)*PUM15(JL,JK)+&
         & PVM1(JL,JK)*PVM15(JL,JK))/&
         & SQRT(PUM15(JL,JK)**2+PVM15(JL,JK)**2)  
        ZABSV5=0.5_JPRB* SQRT(PUM15(JL,JK)**2+PVM15(JL,JK)**2)
        ZZD1  =ZB*ZCS +ZC*ZSS
        ZZD15 =ZB*ZCS5+ZC*ZSS5
        ZRATIO =((ZCS+PGAMMA(JL)*ZSS)*&
         & (PGAMMA(JL)*ZCS5+ZSS5)-&
         & (PGAMMA(JL)*ZCS +ZSS )*&
         & (ZCS5+PGAMMA(JL)*ZSS5))/(PGAMMA(JL)*ZCS5+ZSS5)**2  
        ZRATIO5=(ZCS5+PGAMMA(JL)*ZSS5) /(PGAMMA(JL)*ZCS5+ZSS5)
        ZS2 = ZRATIO/ZRATIO5**2
        ZS25= 2.0_JPRB-1.0_JPRB/ZRATIO5
        IF (ZS25 < 0.0_JPRB) THEN
          ZS2 = 0.0_JPRB
          ZS25= 0.0_JPRB
        ENDIF
        ZBET   =ZCONB*(ZS2 *ZZDEP5(JL,JK)*ZZD15*ZABSV5+&
         & ZS25*ZZDEP (JL,JK)*ZZD15*ZABSV5+&
         & ZS25*ZZDEP5(JL,JK)*ZZD1 *ZABSV5+&
         & ZS25*ZZDEP5(JL,JK)*ZZD15*ZABSV )  
        ZBET5  =ZCONB*ZS25*ZZDEP5(JL,JK)*ZZD15*ZABSV5
        ZDUDT (JL)=-PUM1 (JL,JK)/ZTMST-PVOM(JL,JK)
        ZDUDT5(JL)=-PUM15(JL,JK)/ZTMST-PVOM5(JL,JK)
        ZDVDT (JL)=-PVM1 (JL,JK)/ZTMST-PVOL(JL,JK)
        ZDVDT5(JL)=-PVM15(JL,JK)/ZTMST-PVOL5(JL,JK)
        ZDUDT (JL)=ZDUDT (JL)*(ZBET5/(1.0_JPRB+ZBET5))+&
         & ZDUDT5(JL)* ZBET /(1.0_JPRB+ZBET5)**2  
        ZDUDT5(JL)=ZDUDT5(JL)*(ZBET5/(1.0_JPRB+ZBET5))
        ZDVDT (JL)=ZDVDT (JL)*(ZBET5/(1.0_JPRB+ZBET5))+&
         & ZDVDT5(JL)* ZBET /(1.0_JPRB+ZBET5)**2  
        ZDVDT5(JL)=ZDVDT5(JL)*(ZBET5/(1.0_JPRB+ZBET5))
      ENDIF

      PVOM (JL,JK)=PVOM (JL,JK)+ZDUDT (JL)
      PVOM5(JL,JK)=PVOM5(JL,JK)+ZDUDT5(JL)
      PVOL (JL,JK)=PVOL (JL,JK)+ZDVDT (JL)
      PVOL5(JL,JK)=PVOL5(JL,JK)+ZDVDT5(JL)
      ZUST =PUM1 (JL,JK)+ZTMST*ZDUDT (JL)
      ZUST5=PUM15(JL,JK)+ZTMST*ZDUDT5(JL)
      ZVST =PVM1 (JL,JK)+ZTMST*ZDVDT (JL)
      ZVST5=PVM15(JL,JK)+ZTMST*ZDVDT5(JL)
      ZDIS=(PUM1(JL,JK)*PUM15(JL,JK)+PVM1(JL,JK)*PVM15(JL,JK)-&
       & ZUST*ZUST5-ZVST*ZVST5)  
      ZDIS5=0.5_JPRB*(PUM15(JL,JK)**2+PVM15(JL,JK)**2-ZUST5**2-ZVST5**2)
      ZDEDT (JL) =ZDIS /ZTMST
      ZDEDT5(JL) =ZDIS5/ZTMST
      ZVIDIS (JL)=ZVIDIS (JL)+ZDIS*ZDELP5+ZDIS5*ZDELP
      ZVIDIS5(JL)=ZVIDIS5(JL)+ZDIS5*ZDELP5
      ZDTDT (JL) =ZDEDT (JL)/RCPD
      ZDTDT5(JL) =ZDEDT5(JL)/RCPD
      PTE (JL,JK)=PTE (JL,JK)+ZDTDT (JL)
      PTE5(JL,JK)=PTE5(JL,JK)+ZDTDT5(JL)
    ENDIF
  ENDDO

ENDDO
!**
!**     5.3     UPDATE STRESS COMPONENTS AND DISSIPATION
!**
DO JL=KIDIA,KFDIA
  PUSTRGW (JL)=0.0_JPRB
  PVSTRGW (JL)=0.0_JPRB
  PVDISGW (JL)=0.0_JPRB
  PUSTRGW5(JL)=0.0_JPRB
  PVSTRGW5(JL)=0.0_JPRB
  PVDISGW5(JL)=0.0_JPRB
ENDDO

DO JL=KIDIA,KFDIA
  IF(LLGWD(JL)) THEN
    PVDISGW (JL)=ZCONS1*ZVIDIS (JL)
    PVDISGW5(JL)=ZCONS1*ZVIDIS5(JL)
  ENDIF
ENDDO

!*******************************************************************

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

!*         5.5    FLUX COMPUTATIONS
!                 --------- -------

DO JL=KIDIA,KFDIA
  PSTRDU (JL,1)=0.0_JPRB
  PSTRDV (JL,1)=0.0_JPRB
  PSTRDU5(JL,1)=0.0_JPRB
  PSTRDV5(JL,1)=0.0_JPRB
ENDDO

DO JK=1,KLEV
  DO JL=KIDIA,KFDIA
    ZGDPH = RG* (PAPHM1 (JL,JK+1)-PAPHM1 (JL,JK)) /&
     & (PAPHM15(JL,JK+1)-PAPHM15(JL,JK))**2  
    ZGDPH5=-RG  /(PAPHM15(JL,JK+1)-PAPHM15(JL,JK))
    PSTRDU (JL,JK+1)=((PVOM (JL,JK)-ZUEA (JL,JK))*ZGDPH5-&
     & (PVOM5(JL,JK)-ZUEA5(JL,JK))*ZGDPH)/ZGDPH5**2 +&
     & PSTRDU (JL,JK)  
    PSTRDU5(JL,JK+1)=(PVOM5(JL,JK)-ZUEA5(JL,JK))/ZGDPH5 +PSTRDU5(JL,JK)
    PSTRDV (JL,JK+1)=((PVOL (JL,JK)-ZVEA (JL,JK))*ZGDPH5-&
     & (PVOL5(JL,JK)-ZVEA5(JL,JK))*ZGDPH)/ZGDPH5**2 +&
     & PSTRDV (JL,JK)  
    PSTRDV5(JL,JK+1)=(PVOL5(JL,JK)-ZVEA5(JL,JK))/ZGDPH5 + PSTRDV5(JL,JK)
  ENDDO
ENDDO

DO JL=KIDIA,KFDIA
  PUSTRGW (JL)=PSTRDU (JL,KLEV+1)
  PVSTRGW (JL)=PSTRDV (JL,KLEV+1)
  PUSTRGW5(JL)=PSTRDU5(JL,KLEV+1)
  PVSTRGW5(JL)=PSTRDV5(JL,KLEV+1)
ENDDO

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

!     Possible problem: dT/dt does not appear anymore in the GWD code,
!       but is accounted for in new CPTEND, CPUTQY

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