SUBROUTINE CUCCDIATL &
 & (  KIDIA,    KFDIA,    KLON,    KLEV,&
 & KSTEP,    KCBOT,    KCTOP,&
 & LDCUM,    PQU5,     PLU5,     PMFU5,    PRAIN5,&
 & PARPRC5,  KTOPC,    KBASEC  )  

!**** *CUCCDIATL* UPDATES PRECIPITAION, CLOUD BASE AND CLOUD TOP
!                 FOR DIAGNOSTIC SCHEME FOR CONVECTIVE CLOUDS
!                 (Tangent linear)

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

!          Adapted from

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

!**   INTERFACE.
!     ----------

!          *CUCCDIATL* IS CALLED FROM *CUCALLNTL*

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

!    *KIDIA*        START POINT
!    *KFDIA*        END POINT
!    *KLON*         NUMBER OF GRID POINTS PER PACKET
!    *KLEV*         NUMBER OF LEVELS
!    *KSTEP*        CURRENT TIME STEP INDEX
!    *KCBOT*        CLOUD BASE LEVEL
!    *KCTOP*        CLOUD TOP LEVEL

!     INPUT PARAMETERS (LOGICAL)

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

!     INPUT PARAMETERS (REAL)

!    *PQU5*         SPEC. HUMIDITY IN UPDRAFTS                    (Trajectory)
!    *PLU5*         LIQUID WATER CONTENT IN UPDRAFTS              (Trajectory)
!    *PMFU5*        MASSFLUX UPDRAFTS                             (Trajectory)

!    UPDATED PARAMETERS (REAL):

!    *PARPRC5*      ACCUMULATED PRECIPITATION AMOUNT              (Trajectory)
!                   FOR RADIATION CALCULATION
!    *PARPRC*       ACCUMULATED PRECIPITATION AMOUNT              KG/(M2*S)
!                   FOR RADIATION CALCULATION
!    *KTOPC*        CONVECTIVE CLOUD TOP LEVEL FOR RADIATION
!    *KBASEC*       CONVECTIVE CLOUD BASE LEVEL FOR RADIATION

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

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

USE YOEPHY   , ONLY : LECUMF   ,LERADI
USE YOERAD   , ONLY : NRADFR
USE YOEPHLI  , ONLY : LPHYLIN

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)    :: KSTEP 
INTEGER(KIND=JPIM),INTENT(IN)    :: KCBOT(KLON) 
INTEGER(KIND=JPIM),INTENT(IN)    :: KCTOP(KLON) 
LOGICAL           ,INTENT(IN)    :: LDCUM(KLON) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PQU5(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PLU5(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PMFU5(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PRAIN5(KLON) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PARPRC5(KLON) 
INTEGER(KIND=JPIM),INTENT(INOUT) :: KTOPC(KLON) 
INTEGER(KIND=JPIM),INTENT(INOUT) :: KBASEC(KLON) 
!     ------------------------------------------------------------------

INTEGER(KIND=JPIM) :: IKB, IKT, JL

REAL(KIND=JPRB) :: Z1S5, ZDMFQ5, ZNORMR
REAL(KIND=JPRB) :: ZHOOK_HANDLE

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

!*    1.0          STORE CLOUD PARAMETERS FOR RADIATION CALCULATION
!                  -----------------------------------------------

!********************************
IF (LHOOK) CALL DR_HOOK('CUCCDIATL',0,ZHOOK_HANDLE)
IF (.NOT.LPHYLIN) THEN
!********************************      
  IF(LECUMF.AND.LERADI.AND.MOD(KSTEP+1,NRADFR) /= 0) THEN
    ZNORMR=1.0_JPRB/REAL(MAX(NRADFR-1,1),JPRB)
!DIR$ IVDEP
!OCL NOVREC
    DO JL=KIDIA,KFDIA
      IF(LDCUM(JL)) THEN
        KBASEC(JL)=MAX(KBASEC(JL),KCBOT(JL))
        KTOPC(JL) =MIN(KTOPC(JL) ,KCTOP(JL))
        IF(KTOPC(JL) == 1) KTOPC(JL)=KCTOP(JL)
        IKB=KCBOT(JL)
        IKT=KCTOP(JL)
        ZDMFQ5=PMFU5(JL,IKB)*MAX(PQU5(JL,IKB)+PLU5(JL,IKB)-&
         & PQU5(JL,IKT),PQU5(JL,IKB)*0.05_JPRB)  
        PARPRC5(JL)=PARPRC5(JL)+MAX(ZDMFQ5,PRAIN5(JL))*ZNORMR
      ENDIF
    ENDDO
  ENDIF
!********************************
ELSE
!********************************      
  IF(LECUMF) THEN
!DIR$ IVDEP
!OCL NOVREC
    DO JL=KIDIA,KFDIA
      IF(LDCUM(JL)) THEN
        KBASEC(JL)=KCBOT(JL)
        KTOPC(JL) =KCTOP(JL)
        IF(KTOPC(JL) == 1) KTOPC(JL)=KCTOP(JL)
        IKB=KCBOT(JL)
        IKT=KCTOP(JL)
!jfm            ZDMFQ5=PMFU5(JL,IKB)*MAX(PQU5(JL,IKB)+PLU5(JL,IKB)-
!jfm     1             PQU5(JL,IKT),PQU5(JL,IKB)*0.05)
!jfm            PARPRC5(JL)=MAX(ZDMFQ5,PRAIN5(JL))
        Z1S5 = PQU5(JL,IKB)+PLU5(JL,IKB)-PQU5(JL,IKT)
        IF (Z1S5 > PQU5(JL,IKB)*0.05_JPRB) THEN
          ZDMFQ5=PMFU5(JL,IKB)*Z1S5
        ELSE
          ZDMFQ5=PMFU5(JL,IKB)*PQU5(JL,IKB)*0.05_JPRB
        ENDIF
        IF (ZDMFQ5 > PRAIN5(JL)) THEN
          PARPRC5(JL)=ZDMFQ5
        ELSE
          PARPRC5(JL)=PRAIN5(JL)
        ENDIF
      ENDIF
    ENDDO
  ENDIF
!********************************        
ENDIF
!********************************      

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