SUBROUTINE CUENTRTL &
 & ( KIDIA,    KFDIA,    KLON,    KLEV,&
 & KK,       KCBOT,&
 & LDCUM,    LDWORK,&
 & PQSEN5,   PAPH5,    PGEOH5,&
 & PMFU5,    PENTR5,&
 & PDMFEN5,  PDMFDE5 )  

!          J.F. MAHFOUF      E.C.M.W.F.     06/12/96

!          Adapted from

!          M.TIEDTKE         E.C.M.W.F.     12/89

!          PURPOSE.
!          --------
!          THIS ROUTINE CALCULATES ENTRAINMENT/DETRAINMENT RATES
!          FOR UPDRAFTS IN CUMULUS PARAMETERIZATION

!          INTERFACE
!          ---------

!          THIS ROUTINE IS CALLED FROM *CUASCTL*.
!          INPUT ARE ENVIRONMENTAL VALUES T,Q ETC
!          AND UPDRAFT VALUES T,Q ETC
!          IT RETURNS ENTRAINMENT/DETRAINMENT RATES

!          METHOD.
!          --------
!          M. TIEDTKE (1989)

!     PARAMETER     DESCRIPTION                                   UNITS
!     ---------     -----------                                   -----
!     INPUT PARAMETERS (INTEGER):

!    *KIDIA*        START POINT
!    *KFDIA*        END POINT
!    *KLON*         NUMBER OF GRID POINTS PER PACKET
!    *KLEV*         NUMBER OF LEVELS
!    *KK*           CURRENT LEVEL
!    *KCBOT*        CLOUD BASE LEVEL

!    INPUT PARAMETERS (LOGICAL):

!    *LDCUM*        FLAG: .TRUE. FOR CONVECTIVE POINTS

!    INPUT PARAMETERS (REAL):

!    *PQSEN5*       SATURATION SPEC. HUMIDITY                  (Trajectory) 
!    *PAPH5*        PROVISIONAL PRESSURE ON HALF LEVELS        (Trajectory) 
!    *PGEOH5*       PROVISIONAL GEOPOTENTIAL ON HALF LEVELS    (Trajectory) 
!    *PMFU5*        MASSFLUX IN UPDRAFTS                       (Trajectory) 
!    *PENTR5*       FRACTIONAL MASS ENTRAINMENT RATE           (Trajectory) 

!    OUTPUT PARAMETERS (REAL):

!    *PDMFEN5*      ENTRAINMENT RATE                           (Trajectory)
!    *PDMFDE5*      DETRAINMENT RATE                           (Trajectory)

!          EXTERNALS
!          ---------
!          NONE

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

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

USE YOECUMF  , ONLY : DETRPEN
USE YOMCST   , ONLY : RG

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 
INTEGER(KIND=JPIM),INTENT(IN)    :: KK 
INTEGER(KIND=JPIM),INTENT(IN)    :: KCBOT(KLON) 
LOGICAL           ,INTENT(IN)    :: LDCUM(KLON) 
LOGICAL           ,INTENT(IN)    :: LDWORK 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PQSEN5(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PAPH5(KLON,KLEV+1) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PGEOH5(KLON,KLEV+1) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PMFU5(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PENTR5(KLON) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PDMFEN5(KLON) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PDMFDE5(KLON) 

LOGICAL ::  LLO1

INTEGER(KIND=JPIM) :: JL

REAL(KIND=JPRB) :: ZDZ5, ZENTR5, ZRG5
REAL(KIND=JPRB) :: ZHOOK_HANDLE

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

!*    1.           CALCULATE ENTRAINMENT AND DETRAINMENT RATES
!                  -------------------------------------------

IF (LHOOK) CALL DR_HOOK('CUENTRTL',0,ZHOOK_HANDLE)
IF(LDWORK) THEN

  ZRG5=1.0_JPRB/RG
  DO JL=KIDIA,KFDIA
    PDMFEN5(JL)=0.0_JPRB
    PDMFDE5(JL)=0.0_JPRB
  ENDDO

!*    1.1          SPECIFY ENTRAINMENT RATES
!                  -------------------------

  DO JL=KIDIA,KFDIA
    IF(LDCUM(JL)) THEN
      ZDZ5=(PGEOH5(JL,KK)-PGEOH5(JL,KK+1))*ZRG5
      ZENTR5=PMFU5(JL,KK+1)*ZDZ5
      LLO1=KK < KCBOT(JL)
      IF(LLO1) THEN
        PDMFEN5(JL)=PENTR5(JL)*ZENTR5
        PDMFDE5(JL)=DETRPEN*ZENTR5

      !used in Cy32r3-Cy36r3, since only zoentr in cuascn
      ! IK1=MAX(1,KCBOT(JL))
      ! ZENTR25=PQSEN5(JL,KK)/PQSEN5(JL,IK1)
      ! ZENTR25=MIN(1.0_JPRB,ZENTR25)
      ! ZENTR25=4.0_JPRB*ZENTR25**2
      ! PDMFEN5(JL)=PDMFEN5(JL)*ZENTR25
      ENDIF
    ENDIF
  ENDDO

ENDIF

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