SUBROUTINE LWCAD &
 & ( KIDIA , KFDIA, KLON  , KLEV, KTOPC,&
 & PBINT5 , PBSUI5, PCLFR5, PCLDLD5, PCLDLU5,&
 & PCNTRB5, PEMIT5, PFLUC5,&
 & PFLUX5 ,&
 & PBINT  , PBSUI , PCLFR , PCLDLD , PCLDLU ,&
 & PCNTRB , PEMIT , PFLUC ,&
 & PFLUX  &
 & )

!**** *LWCAD*   - LONGWAVE RADIATION, CLOUD EFFECTS
!                      (adjoint)

!     PURPOSE.
!     --------
!           INTRODUCES CLOUD EFFECTS ON LONGWAVE FLUXES OR
!           RADIANCES

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

!        EXPLICIT ARGUMENTS :
!        --------------------
!     ==== INPUTS ===
!  Trajectory  Perturbation  Description                         Dimension
!  PBINT5      PBINT         HALF LEVEL PLANCK FUNCTION          (KLON,KLEV+1)
!  PBSUI5      PBSUI         SURFACE PLANCK FUNCTION             (KLON)
!  PCLFR5      PCLFR         CLOUD FRACTIONAL COVER              (KLON,KLEV)
!  PCLDLD5     PCLDLD        DOWNWARD EFFECTIVE CLOUD FRACTION   (KLON,KLEV)
!  PCLDLU5     PCLDLU        UPWARD EFFECTIVE CLOUD FRACTION     (KLON,KLEV)
!  PCNTRB5     PCNTRB        CLEAR-SKY ENERGY EXCHANGE 
!                            MATRIX                        (KLON,KLEV+1,KLEV+1)
!  PEMIT5      PEMIT         SURFACE TOTAL LW EMISSIVITY         (KLON)
!  PFLUC5      PFLUC         CLEAR-SKY LW RADIATIVE FLUXES      (KLON,2,KLEV+1)

!     ==== OUTPUTS ===
!  Trajectory  Perturbation  Description                         Dimension
!  PFLUX5      PFLUX         TOTAL SKY LW RADIATIVE FLUXES      (KLON,2,KLEV+1)
!                     1  ==>  UPWARD   FLUX TOTAL
!                     2  ==>  DOWNWARD FLUX TOTAL

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

!     METHOD.
!     -------

!          1. INITIALIZES ALL FLUXES TO CLEAR-SKY VALUES
!          2. EFFECT OF ONE OVERCAST UNITY EMISSIVITY CLOUD LAYER
!          3. EFFECT OF SEMI-TRANSPARENT, PARTIAL OR MULTI-LAYERED
!     CLOUDS

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

!          NONE

!     REFERENCE.
!     ----------

!        SEE RADIATION'S PART OF THE MODEL'S DOCUMENTATION AND
!        ECMWF RESEARCH DEPARTMENT DOCUMENTATION OF THE IFS

!     AUTHOR.
!     -------
!        M. Janiskova  *ECMWF*       12-Dec-2006

!     MODIFICATIONS.
!     --------------
!        D. Salmond  02-Jun-2008 code optimization

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

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

USE YOERAD   , ONLY : NOVLP
USE YOERDI   , ONLY : REPCLC
USE YOEOVLP  , ONLY : RA1OVLP
USE YOEPHLI  , ONLY : LRAISANEN

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)    :: KTOPC
REAL(KIND=JPRB)   ,INTENT(IN)    :: PBINT5(KLON,KLEV+1) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PBSUI5(KLON)
REAL(KIND=JPRB)   ,INTENT(IN)    :: PCLFR5(KLON,KLEV)
REAL(KIND=JPRB)   ,INTENT(IN)    :: PCLDLD5(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PCLDLU5(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PCNTRB5(KLON,KLEV+1,KLEV+1) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PEMIT5(KLON) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PFLUC5(KLON,2,KLEV+1) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PFLUX5(KLON,2,KLEV+1) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PBINT(KLON,KLEV+1) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PBSUI(KLON)
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PCLFR(KLON,KLEV)
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PCLDLD(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PCLDLU(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PCNTRB(KLON,KLEV+1,KLEV+1) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PEMIT(KLON) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PFLUC(KLON,2,KLEV+1) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PFLUX(KLON,2,KLEV+1)

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

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

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

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

REAL(KIND=JPRB) :: ZCLEAR(KIDIA:KFDIA), ZCLOUD(KIDIA:KFDIA)
REAL(KIND=JPRB) :: ZCLM(KIDIA:KFDIA,KLEV+1,KLEV+1)
REAL(KIND=JPRB) :: ZDNF(KIDIA:KFDIA,KLEV+1,KLEV+1)
REAL(KIND=JPRB) :: ZFD(KIDIA:KFDIA), ZFU(KIDIA:KFDIA)
REAL(KIND=JPRB) :: ZUPF(KIDIA:KFDIA,KLEV+1,KLEV+1)  
REAL(KIND=JPRB) :: ZCLFR(KIDIA:KFDIA,KLEV), ZEMIS(KIDIA:KFDIA,KLEV)
REAL(KIND=JPRB) :: ZACLFR(KLON,KLEV),ZCLDLD(KLON,KLEV),ZCLDLU(KLON,KLEV)
REAL(KIND=JPRB) :: ZSUM(KIDIA:KFDIA)
REAL(KIND=JPRB) :: ZTMP1(KIDIA:KFDIA,KLEV+1), ZTMP3(KIDIA:KFDIA,KLEV+1)
REAL(KIND=JPRB) :: ZTMP4(KIDIA:KFDIA,KLEV+1), ZTMP5(KIDIA:KFDIA,KLEV+1)

REAL(KIND=JPRB) :: ZCLEAR5(KIDIA:KFDIA,KLEV+1,KLEV+1)
REAL(KIND=JPRB) :: ZCLOUD5(KIDIA:KFDIA,KLEV+1,KLEV+1)
REAL(KIND=JPRB) :: ZCLEARA5(KIDIA:KFDIA,KLEV+1,KLEV+1)
REAL(KIND=JPRB) :: ZCLOUDA5(KIDIA:KFDIA,KLEV+1,KLEV+1)
REAL(KIND=JPRB) :: ZCLEARB5(KIDIA:KFDIA,KLEV+1,KLEV+1)
REAL(KIND=JPRB) :: ZCLOUDB5(KIDIA:KFDIA,KLEV+1,KLEV+1)
REAL(KIND=JPRB) :: ZCLM5(KIDIA:KFDIA,KLEV+1,KLEV+1)
REAL(KIND=JPRB) :: ZDNF5(KIDIA:KFDIA,KLEV+1,KLEV+1)
REAL(KIND=JPRB) :: ZSUMA5(KIDIA:KFDIA,KLEV+1,KLEV+1)
REAL(KIND=JPRB) :: ZSUMB5(KIDIA:KFDIA,KLEV+1,KLEV+1)
REAL(KIND=JPRB) :: ZTR15(KIDIA:KFDIA,KLEV+1,KLEV+1)
REAL(KIND=JPRB) :: ZTR25(KIDIA:KFDIA,KLEV+1,KLEV+1)
REAL(KIND=JPRB) :: ZNUM5(KIDIA:KFDIA,KLEV+1,KLEV+1)
REAL(KIND=JPRB) :: ZDEN5(KIDIA:KFDIA,KLEV+1,KLEV+1)
REAL(KIND=JPRB) :: ZCFRAC5(KIDIA:KFDIA,KLEV+1,KLEV+1)
REAL(KIND=JPRB) :: ZDIV25(KIDIA:KFDIA,KLEV+1,KLEV+1)
REAL(KIND=JPRB) :: ZDIV35(KIDIA:KFDIA,KLEV+1,KLEV+1)
REAL(KIND=JPRB) :: ZDIV55(KIDIA:KFDIA,KLEV+1,KLEV+1)
REAL(KIND=JPRB) :: ZDIV65(KIDIA:KFDIA,KLEV+1,KLEV+1)
REAL(KIND=JPRB) :: ZUPF5(KIDIA:KFDIA,KLEV+1,KLEV+1)
REAL(KIND=JPRB) :: ZTMPA15(KIDIA:KFDIA,KLEV+1), ZTMPA35(KIDIA:KFDIA,KLEV+1)
REAL(KIND=JPRB) :: ZTMPA45(KIDIA:KFDIA,KLEV+1), ZTMPA55(KIDIA:KFDIA,KLEV+1)
REAL(KIND=JPRB) :: ZTMPB15(KIDIA:KFDIA,KLEV+1), ZTMPB35(KIDIA:KFDIA,KLEV+1)
REAL(KIND=JPRB) :: ZTMPB45(KIDIA:KFDIA,KLEV+1), ZTMPB55(KIDIA:KFDIA,KLEV+1) 
REAL(KIND=JPRB) :: ZEMISA5(KIDIA:KFDIA,KLEV), ZEMISB5(KIDIA:KFDIA,KLEV)
REAL(KIND=JPRB) :: ZCLFR5(KIDIA:KFDIA,KLEV),ZACLFR5(KIDIA:KFDIA,KLEV)
REAL(KIND=JPRB) :: ZCLDLD5(KLON,KLEV),ZCLDLU5(KLON,KLEV)
REAL(KIND=JPRB) :: ZCLFRA5(KIDIA:KFDIA,KLEV),ZCLFRB5(KIDIA:KFDIA,KLEV)
REAL(KIND=JPRB) :: ZCADJA5(KIDIA:KFDIA,KLEV), ZCADJB5(KIDIA:KFDIA,KLEV)
REAL(KIND=JPRB) :: ZDIV15(KIDIA:KFDIA,KLEV), ZDIV45(KIDIA:KFDIA,KLEV)
REAL(KIND=JPRB) :: ZFD5(KIDIA:KFDIA), ZFU5(KIDIA:KFDIA) 

INTEGER(KIND=JPIM) :: IKCP1, IKM1, IKP1, IMAXC, JCLOUD,&
 & JK, JK1, JK2, JKJ, JL, IKL, IJK, ICL

REAL(KIND=JPRB) :: ZALPHA1, ZCFRAC, ZNUM, ZDEN
REAL(KIND=JPRB) :: ZTR1, ZTR2, ZCADJ

REAL(KIND=JPRB) :: ZHOOK_HANDLE

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

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

!100  CONTINUE

!      print *,' Enter LWC '
IF (LHOOK) CALL DR_HOOK('LWCAD',0,ZHOOK_HANDLE)

DO JK = 1 , KLEV+1
  DO JL = KIDIA,KFDIA
    PFLUX5(JL,1,JK) = PFLUC5(JL,1,JK)
    PFLUX5(JL,2,JK) = PFLUC5(JL,2,JK)
  ENDDO
ENDDO

!GM*******
IMAXC=KLEV
!GM*******

!Experimentation with reduced ITOPC 
!ITOPC=KLEV-10
!ITOPC=KLEV-20
!ITOPC=KLEV

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

!*         2.      EFFECT OF CLOUDINESS ON LONGWAVE FLUXES
!                  ---------------------------------------

!*         2.0     INITIALIZE TO CLEAR-SKY FLUXES
!                  ------------------------------

!200  CONTINUE

DO JK = 1,KTOPC+1
  DO JL = KIDIA,KFDIA
    ZDNF5(JL,1,JK) = PFLUC5(JL,2,JK)
  ENDDO
ENDDO

DO JK = 1,KLEV+1
  DO JL = KIDIA,KFDIA
    ZUPF5(JL,1,JK) = PFLUC5(JL,1,JK)
  ENDDO
ENDDO

!      print *,' LWC after Initialisation to clear-sky fluxes'

!*         2.1     FLUXES FOR ONE OVERCAST UNITY EMISSIVITY CLOUD
!                  ----------------------------------------------

!210  CONTINUE

DO JCLOUD = 1 , KTOPC
  IKCP1=JCLOUD+1

!*         2.1.1   ABOVE THE CLOUD
!                  ---------------

!2110 CONTINUE

  DO JK=IKCP1,KLEV+1
    IKM1=JK-1
    DO JL = KIDIA,KFDIA
      ZFU5(JL)=0.0_JPRB
    ENDDO

    IF (JK  >  IKCP1) THEN
      DO JKJ=IKCP1,IKM1
        DO JL = KIDIA,KFDIA
          ZFU5(JL) = ZFU5(JL) + PCNTRB5(JL,JK,JKJ)
        ENDDO
      ENDDO
    ENDIF

    DO JL = KIDIA,KFDIA
      ZUPF5(JL,IKCP1,JK) = PBINT5(JL,JK)-ZFU5(JL)
    ENDDO
  ENDDO

!*         2.1.2   BELOW THE CLOUD
!                  ---------------

!2120 CONTINUE

  DO JK=1,JCLOUD
    IKP1=JK+1
    DO JL = KIDIA,KFDIA
      ZFD5(JL) = 0.0_JPRB
    ENDDO

    IF (JK  <  JCLOUD) THEN
      DO JKJ=IKP1,JCLOUD
        DO JL = KIDIA,KFDIA
          ZFD5(JL) = ZFD5(JL) + PCNTRB5(JL,JK,JKJ)
        ENDDO
      ENDDO
    ENDIF

    DO JL = KIDIA,KFDIA
      ZDNF5(JL,IKCP1,JK) = -PBINT5(JL,JK)-ZFD5(JL)
    ENDDO
  ENDDO

ENDDO
!      print *,' LWC after 213: Fluxes for unity emissivity'

!*         2.2     CLOUD COVER MATRIX
!                  ------------------

!*    ZCLM(JK1,JK2) IS THE OBSCURATION FACTOR BY CLOUD LAYERS BETWEEN
!     HALF-LEVELS JK1 AND JK2 AS SEEN FROM JK1

!220  CONTINUE

! matrix notation for ZCLM is not standard, but:
!    z11  z21  z31  ...
!    z12  z22  z32  ...
!    z13  z23  z33  ...
!     :    :    :    :

!DO JK = KTOPC,KLEV+1
!  DO JL = KIDIA,KFDIA
!    ZCLM5(JL,KTOPC,JK) = 0.0_JPRB
!    ZCLM5(JL,KTOPC+1,JK) = 0.0_JPRB
!  ENDDO
!ENDDO

DO JK2 = KTOPC , KLEV+1
  DO JK1 = KTOPC , KLEV+1
    DO JL = KIDIA,KFDIA
      ZCLM5(JL,JK1,JK2) = 0.0
    ENDDO
  ENDDO
ENDDO

IF (.NOT.LRAISANEN) THEN
  DO JK = KTOPC+2,KLEV
    DO JL = KIDIA,KFDIA
      ZCLM5(JL,JK,JK+1) = 0.0_JPRB
    ENDDO
  ENDDO
ENDIF

! Securities

!DO JK = 1,KLEV
!  IKL = KLEV + 1 - JK
!  DO JL = KIDIA,KFDIA
!    IF (PCLFR5(JL,IKL) <= REPCLC) THEN
!      ZCLDLD5(JL,JK) = REPCLC
!      ZCLDLU5(JL,JK) = REPCLC
!    ELSE
!      ZCLDLD5(JL,JK) = PCLDLD5(JL,JK)
!      ZCLDLU5(JL,JK) = PCLDLU5(JL,JK)
!    ENDIF
!  ENDDO
!ENDDO

IF (KTOPC /= KLEV) THEN
  DO JK = 1,KTOPC
    IKL = KLEV + 1 - JK
    DO JL = KIDIA,KFDIA
      ZACLFR5(JL,IKL) = PCLFR5(JL,IKL)

      ZCLDLD5(JL,JK) = PCLDLD5(JL,JK)
      ZCLDLU5(JL,JK) = PCLDLU5(JL,JK)
    ENDDO
  ENDDO
  DO JK = KTOPC+1,KLEV
    IKL = KLEV + 1 - JK
    DO JL = KIDIA,KFDIA
      ZACLFR5(JL,IKL) = REPCLC

      ZCLDLD5(JL,JK) = 0.0_JPRB
      ZCLDLU5(JL,JK) = 0.0_JPRB
    ENDDO
  ENDDO
ELSE
  DO JK = 1,KLEV
    IKL = KLEV + 1 - JK
    DO JL = KIDIA,KFDIA
      ZACLFR5(JL,IKL) = PCLFR5(JL,IKL)

      ZCLDLD5(JL,JK) = PCLDLD5(JL,JK)
      ZCLDLU5(JL,JK) = PCLDLU5(JL,JK)
    ENDDO
  ENDDO
ENDIF


IF (LRAISANEN) THEN
  DO JK = 1,KLEV
    IKL = KLEV + 1 - JK
    DO JL = KIDIA,KFDIA
      IF (PCLDLU5(JL,JK) <= REPCLC .OR. PCLDLD5(JL,JK) <= REPCLC) THEN
        ZACLFR5(JL,IKL) = REPCLC
      ELSE
        ZACLFR5(JL,IKL) = ZACLFR5(JL,IKL)
      ENDIF
    ENDDO
  ENDDO
ENDIF


!      print *,' LWC after Initialisation CC matrix'

!*         2.4     CLOUD COVER BELOW THE LEVEL OF CALCULATION
!                  ------------------------------------------

!240  CONTINUE

IF (LRAISANEN) THEN
!* maximum-random (Raisanen 1998)

  ZEMISB5(:,:) = 0.0_JPRB
  DO JK = 1,KLEV
    IKL = KLEV + 1 - JK
    DO JL = KIDIA,KFDIA
      ZCLFR5(JL,IKL) = ZACLFR5(JL,IKL)
      IF (ZCLFR5(JL,IKL) <= REPCLC) THEN
        ZCLFR5(JL,IKL) = REPCLC
      ENDIF
      IF (ZCLFR5(JL,IKL) >= 1.0_JPRB-REPCLC) THEN
        ZCLFR5(JL,IKL) = 1.0_JPRB-REPCLC
      ENDIF
      ZDIV15(JL,JK) = 1.0_JPRB/ZCLFR5(JL,IKL)
      ZEMISB5(JL,JK) = ZCLDLU5(JL,JK)*ZDIV15(JL,JK)
    ENDDO
  ENDDO

  DO JK = 1,KTOPC-1
    IKL = KLEV + 1 - JK
    DO JL = KIDIA,KFDIA
      IF (ZCLDLU5(JL,JK+1) <= REPCLC) THEN
        ZTMPB15(JL,JK) = 1.0_JPRB/REPCLC
      ELSE
        ZTMPB15(JL,JK) = 1.0_JPRB/ZCLDLU5(JL,JK+1)
      ENDIF
      IF (ZCLFR5(JL,IKL) <= ZCLFR5(JL,IKL-1)) THEN
        ZCADJB5(JL,JK) = ZCLFR5(JL,IKL)
      ELSE
        ZCADJB5(JL,JK) = ZCLFR5(JL,IKL-1)
      ENDIF      
!* Modified for regularization
      ZCLFRB5(JL,IKL-1) = ZCLFR5(JL,IKL-1)
      IF (ZCLFR5(JL,IKL-1) > 0.999_JPRB) THEN
        ZCLFR5(JL,IKL-1) = 0.999_JPRB
      ENDIF
!* End of modification
      ZTMPB35(JL,JK) = 1.0_JPRB/(1.0_JPRB-ZCLFR5(JL,IKL-1))
      ZTMPB45(JL,JK) = ZCADJB5(JL,JK)*(1.0_JPRB-ZEMISB5(JL,JK+1))
      ZTMPB55(JL,JK) = ZCLFR5(JL,IKL)-ZCADJB5(JL,JK)
    ENDDO
  ENDDO

  DO JK1 = 2 , KLEV+1
    DO JL = KIDIA,KFDIA
      ZCLOUD5(JL,JK1-1,JK1) = ZCLDLU5(JL,JK1-1)
      ZSUMB5(JL,JK1-1,JK1)  = ZCLOUD5(JL,JK1-1,JK1)
      ZCLM5(JL,JK1-1,JK1) = ZSUMB5(JL,JK1-1,JK1)
    ENDDO

    IJK=MIN(KTOPC+1,JK1)
    DO JK = IJK - 2 , 1 , -1
      IKL = KLEV+1 - JK
      IF (JK == KTOPC-1) THEN
        ICL = JK1-1
      ELSE
        ICL = JK+1
      ENDIF
      DO JL = KIDIA,KFDIA
        ZTR15(JL,JK,JK1) = ZCLOUD5(JL,ICL,JK1)*ZTMPB15(JL,JK)
        ZTR25(JL,JK,JK1) = (1.0_JPRB-(ZSUMB5(JL,ICL,JK1) &
         & -ZCLOUD5(JL,ICL,JK1))-ZTR15(JL,JK,JK1) &
         & *ZCLFR5(JL,IKL-1))*ZTMPB35(JL,JK)
        ZCLOUD5(JL,JK,JK1) = ZEMISB5(JL,JK) &
         & * (ZTMPB45(JL,JK)*ZTR15(JL,JK,JK1) &
         & + ZTMPB55(JL,JK)*ZTR25(JL,JK,JK1))  
        ZSUMB5(JL,JK,JK1) = ZSUMB5(JL,ICL,JK1) + ZCLOUD5(JL,JK,JK1)
        ZCLM5(JL,JK,JK1) = ZSUMB5(JL,JK,JK1)
      ENDDO
    ENDDO
  ENDDO

ELSE

  DO JK1 = 2 , KLEV+1
    DO JL = KIDIA,KFDIA
      ZCLEARB5(JL,JK1,JK1)=1.0_JPRB
      ZCLOUDB5(JL,JK1,JK1)=0.0_JPRB
    ENDDO

    IJK=MIN(KTOPC,JK1)
    DO JK = IJK - 1 , 1, -1
      ZALPHA1=RA1OVLP(KLEV+1-JK)
      IF (JK1 >= KTOPC+1) THEN
        ICL = JK1
      ELSE
        ICL = JK+1
      ENDIF
      DO JL = KIDIA,KFDIA
        IF (JK == IJK-1) THEN
          ZCLEARB5(JL,JK,JK1)  = ZCLEARB5(JL,ICL,JK1)
          ZCLOUDB5(JL,JK,JK1)  = ZCLOUDB5(JL,ICL,JK1)
        ELSE
          ZCLEARB5(JL,JK,JK1)  =  ZCLEAR5(JL,JK+1,JK1)
          ZCLOUDB5(JL,JK,JK1)  =  ZCLOUD5(JL,JK+1,JK1) 
        ENDIF

        IF (NOVLP == 1) THEN
!* maximum-random    Geleyn and Hollingsworth 1979
          IF (ZCLDLU5(JL,JK) >= ZCLOUDB5(JL,JK,JK1)) THEN
            ZNUM5(JL,JK,JK1) = ZCLDLU5(JL,JK)
          ELSE
            ZNUM5(JL,JK,JK1) = ZCLOUDB5(JL,JK,JK1)
          ENDIF
          IF (ZCLOUDB5(JL,JK,JK1) <= 1.0_JPRB-REPCLC) THEN
            ZDEN5(JL,JK,JK1) = ZCLOUDB5(JL,JK,JK1)
          ELSE
            ZDEN5(JL,JK,JK1)= 1.0_JPRB-REPCLC
          ENDIF
          ZDIV25(JL,JK,JK1) = 1.0_JPRB/(1.0_JPRB-ZDEN5(JL,JK,JK1))
          ZCLEAR5(JL,JK,JK1) = ZCLEARB5(JL,JK,JK1) &
           & *(1.0_JPRB-ZNUM5(JL,JK,JK1))*ZDIV25(JL,JK,JK1)
          ZCLM5(JL,JK,JK1) = 1.0_JPRB - ZCLEAR5(JL,JK,JK1)
          ZCLOUD5(JL,JK,JK1) = ZCLDLU5(JL,JK)
        ELSEIF (NOVLP == 2) THEN
!* maximum
          IF (ZCLDLU5(JL,JK) >= ZCLOUDB5(JL,JK,JK1)) THEN
            ZCLOUD5(JL,JK,JK1) = ZCLDLU5(JL,JK)
          ELSE
            ZCLOUD5(JL,JK,JK1) = ZCLOUDB5(JL,JK,JK1)
          ENDIF
          ZCLM5(JL,JK,JK1) = ZCLOUD5(JL,JK,JK1)
        ELSEIF (NOVLP == 3) THEN
!* random
          ZCLEAR5(JL,JK,JK1) = ZCLEARB5(JL,JK,JK1) &
           & *(1.0_JPRB - ZCLDLU5(JL,JK))  
          ZCLOUD5(JL,JK,JK1) = 1.0_JPRB - ZCLEAR5(JL,JK,JK1)
          ZCLM5(JL,JK,JK1) = ZCLOUD5(JL,JK,JK1)
        ELSEIF (NOVLP == 4) THEN
!** Hogan & Illingworth (2001)
          IF (ZCLDLU5(JL,JK) >= ZCLOUDB5(JL,JK,JK1)) THEN
            ZNUM5(JL,JK,JK1) = ZCLDLU5(JL,JK)
          ELSE
            ZNUM5(JL,JK,JK1) = ZCLOUDB5(JL,JK,JK1)
          ENDIF
          IF (ZCLOUDB5(JL,JK,JK1) <= 1.0_JPRB-REPCLC) THEN
            ZDEN5(JL,JK,JK1) = ZCLOUDB5(JL,JK,JK1)
          ELSE
            ZDEN5(JL,JK,JK1) = 1.0_JPRB-REPCLC
          ENDIF         
          ZDIV35(JL,JK,JK1) = 1.0_JPRB/(1.0_JPRB-ZDEN5(JL,JK,JK1))
          ZCLEAR5(JL,JK,JK1) = ZCLEARB5(JL,JK,JK1) &
           & * (ZALPHA1*(1.0_JPRB-ZNUM5(JL,JK,JK1))*ZDIV35(JL,JK,JK1) &
           & + (1.0_JPRB-ZALPHA1)*(1.0_JPRB-ZCLDLU5(JL,JK)) ) 
          ZCLM5(JL,JK,JK1) = 1.0_JPRB - ZCLEAR5(JL,JK,JK1)
          ZCLOUD5(JL,JK,JK1) = ZCLDLU5(JL,JK)
        ENDIF
      ENDDO
    ENDDO

  ENDDO

ENDIF

!      print *,' LWC after 244: CC below level of calculation'

!*         2.5     CLOUD COVER ABOVE THE LEVEL OF CALCULATION
!                  ------------------------------------------

!250  CONTINUE

IF (LRAISANEN) THEN
!* maximum-random (Raisanen 1998)

  ZEMISA5(:,:) = 0.0_JPRB

  DO JK = 1,KLEV
    IKL = KLEV + 1 - JK
    DO JL = KIDIA,KFDIA
      ZDIV45(JL,JK) = 1.0_JPRB/ZCLFR5(JL,IKL)
      ZEMISA5(JL,JK) = ZCLDLD5(JL,JK)*ZDIV45(JL,JK)
    ENDDO
  ENDDO

  DO JK = 2,KTOPC
    IKL = KLEV + 1 - JK
    DO JL = KIDIA,KFDIA
      IF (ZCLDLD5(JL,JK-1) <= REPCLC) THEN
        ZTMPA15(JL,JK) = 1.0_JPRB/REPCLC
      ELSE
        ZTMPA15(JL,JK) = 1.0_JPRB/ZCLDLD5(JL,JK-1)
      ENDIF
      IF (ZCLFR5(JL,IKL) <= ZCLFR5(JL,IKL+1)) THEN
        ZCADJA5(JL,JK) = ZCLFR5(JL,IKL)
      ELSE
        ZCADJA5(JL,JK) = ZCLFR5(JL,IKL+1)
      ENDIF
!* Modified for regularization
      ZCLFRA5(JL,IKL+1) = ZCLFR5(JL,IKL+1)
      IF (ZCLFR5(JL,IKL+1) > 0.999_JPRB) THEN
        ZCLFR5(JL,IKL+1) = 0.999_JPRB
      ENDIF
!* End of modification
      ZTMPA35(JL,JK) = 1.0_JPRB/(1.0_JPRB-ZCLFR5(JL,IKL+1))
      ZTMPA45(JL,JK) = ZCADJA5(JL,JK)*(1.0_JPRB-ZEMISA5(JL,JK-1))
      ZTMPA55(JL,JK) = ZCLFR5(JL,IKL)-ZCADJA5(JL,JK)
    ENDDO
  ENDDO

  DO JK1 = 1 ,KTOPC 
    DO JL = KIDIA,KFDIA
      ZCLOUDA5(JL,JK1,JK1) = ZCLDLD5(JL,JK1)
      ZSUMA5(JL,JK1,JK1)   = ZCLOUDA5(JL,JK1,JK1)
      ZCLM5(JL,JK1,JK1)    = ZSUMA5(JL,JK1,JK1)
    ENDDO

    DO JK = JK1+1 , KTOPC
      IKL = KLEV + 1 - JK
      DO JL = KIDIA,KFDIA
        ZTR15(JL,JK,JK1) = ZCLOUDA5(JL,JK-1,JK1)*ZTMPA15(JL,JK)
        ZTR25(JL,JK,JK1) = (1.0_JPRB-(ZSUMA5(JL,JK-1,JK1) &
         & -ZCLOUDA5(JL,JK-1,JK1))-ZTR15(JL,JK,JK1) &
         & *ZCLFR5(JL,IKL+1))*ZTMPA35(JL,JK)  
        ZCLOUDA5(JL,JK,JK1) = ZEMISA5(JL,JK) &
         & * (ZTMPA45(JL,JK)*ZTR15(JL,JK,JK1) &
         & + ZTMPA55(JL,JK)*ZTR25(JL,JK,JK1))  
        ZSUMA5(JL,JK,JK1) = ZSUMA5(JL,JK-1,JK1) + ZCLOUDA5(JL,JK,JK1)
        ZCLM5(JL,JK,JK1 ) = ZSUMA5(JL,JK,JK1)
      ENDDO
    ENDDO
  ENDDO

ELSE

  DO JK1 = 1 , KTOPC
    DO JL = KIDIA,KFDIA
      ZCLEARA5(JL,JK1,JK1)=1.0_JPRB
      ZCLOUDA5(JL,JK1,JK1)=0.0_JPRB
    ENDDO

    DO JK = JK1 , KTOPC
      ZALPHA1=RA1OVLP(KLEV+1-JK)
      
      DO JL = KIDIA,KFDIA
        IF (JK /= JK1) THEN
          ZCLOUDA5(JL,JK,JK1)=ZCLOUD5(JL,JK-1,JK1)
          ZCLEARA5(JL,JK,JK1)=ZCLEAR5(JL,JK-1,JK1)
        ENDIF
        IF (NOVLP == 1) THEN
!* maximum-random
          IF (ZCLDLD5(JL,JK) >= ZCLOUDA5(JL,JK,JK1)) THEN
            ZNUM5(JL,JK,JK1) = ZCLDLD5(JL,JK)
          ELSE
            ZNUM5(JL,JK,JK1) = ZCLOUDA5(JL,JK,JK1)
          ENDIF
          IF (ZCLOUDA5(JL,JK,JK1) <= 1.0_JPRB-REPCLC) THEN
            ZDEN5(JL,JK,JK1) = ZCLOUDA5(JL,JK,JK1)
          ELSE
            ZDEN5(JL,JK,JK1) = 1.0_JPRB-REPCLC
          ENDIF
          ZDIV55(JL,JK,JK1) = 1.0_JPRB/(1.0_JPRB-ZDEN5(JL,JK,JK1))
          ZCLEAR5(JL,JK,JK1)=ZCLEARA5(JL,JK,JK1) &
           & *(1.0_JPRB-ZNUM5(JL,JK,JK1))*ZDIV55(JL,JK,JK1)
          ZCLM5(JL,JK,JK1) = 1.0_JPRB - ZCLEAR5(JL,JK,JK1)
          ZCLOUD5(JL,JK,JK1) = ZCLDLD5(JL,JK)
        ELSEIF (NOVLP == 2) THEN
!* maximum
          IF (ZCLDLD5(JL,JK) >= ZCLOUDA5(JL,JK,JK1)) THEN
            ZCLOUD5(JL,JK,JK1) = ZCLDLD5(JL,JK)
          ELSE
            ZCLOUD5(JL,JK,JK1) = ZCLOUDA5(JL,JK,JK1)
          ENDIF
          ZCLM5(JL,JK,JK1) = ZCLOUD5(JL,JK,JK1)
        ELSEIF (NOVLP == 3) THEN
!* random
          ZCLEAR5(JL,JK,JK1) = ZCLEARA5(JL,JK,JK1) &
           & *(1.0_JPRB - ZCLDLD5(JL,JK))  
          ZCLOUD5(JL,JK,JK1) = 1.0_JPRB - ZCLEAR5(JL,JK,JK1)
          ZCLM5(JL,JK,JK1) = ZCLOUD5(JL,JK,JK1)
        ELSEIF (NOVLP == 4) THEN
!** Hogan & Illingworth (2001)
          IF (ZCLDLD5(JL,JK) >= ZCLOUDA5(JL,JK,JK1)) THEN
            ZNUM5(JL,JK,JK1) = ZCLDLD5(JL,JK)
          ELSE
            ZNUM5(JL,JK,JK1) = ZCLOUDA5(JL,JK,JK1)
          ENDIF
          IF (ZCLOUDA5(JL,JK,JK1) <= 1.0_JPRB-REPCLC) THEN
             ZDEN5(JL,JK,JK1) = ZCLOUDA5(JL,JK,JK1)
          ELSE
            ZDEN5(JL,JK,JK1) = 1.0_JPRB-REPCLC
          ENDIF
          ZDIV65(JL,JK,JK1) = 1.0_JPRB/(1.0_JPRB-ZDEN5(JL,JK,JK1))
          ZCLEAR5(JL,JK,JK1)=ZCLEARA5(JL,JK,JK1) &
           & * (ZALPHA1*(1.0_JPRB-ZNUM5(JL,JK,JK1))*ZDIV65(JL,JK,JK1) &
           & + (1.0_JPRB-ZALPHA1)*(1.0_JPRB-ZCLDLD5(JL,JK)) ) 
          ZCLM5(JL,JK,JK1) = 1.0_JPRB - ZCLEAR5(JL,JK,JK1)
          ZCLOUD5(JL,JK,JK1) = ZCLDLD5(JL,JK)
        ENDIF
      ENDDO
    ENDDO
  ENDDO

ENDIF

!      print *,' LWC after 254: CC above level of calculation'

!*         3.      FLUXES FOR PARTIAL/MULTIPLE LAYERED CLOUDINESS
!                  ----------------------------------------------

!300  CONTINUE

!*         3.1     DOWNWARD FLUXES
!                  ---------------

!310  CONTINUE

DO JL = KIDIA,KFDIA
  PFLUX5(JL,2,KLEV+1) = 0.0_JPRB
ENDDO

DO JK1 = 1, KTOPC

!*                 CONTRIBUTION FROM CLEAR-SKY FRACTION

  DO JL = KIDIA,KFDIA
    ZFD5(JL) = (1.0_JPRB - ZCLM5(JL,KTOPC,JK1))*ZDNF5(JL,1,JK1)

!*                 CONTRIBUTION FROM ADJACENT CLOUD

    ZFD5(JL) = ZFD5(JL) + ZCLM5(JL,JK1,JK1) * ZDNF5(JL,JK1+1,JK1)
  ENDDO

!*                 CONTRIBUTION FROM OTHER CLOUDY FRACTIONS

  DO JK = JK1, KTOPC-1 
    DO JL = KIDIA,KFDIA
      ZCFRAC5(JL,JK,JK1) = ZCLM5(JL,JK+1,JK1) - ZCLM5(JL,JK,JK1)
      ZFD5(JL) = ZFD5(JL)+ZCFRAC5(JL,JK,JK1)*ZDNF5(JL,JK+2,JK1)
    ENDDO
  ENDDO

  DO JL = KIDIA,KFDIA
    PFLUX5(JL,2,JK1) = ZFD5(JL)
  ENDDO

ENDDO
!      print *,' LWC after 317: Downward fluxes'

!*         3.2     UPWARD FLUX AT THE SURFACE
!                  --------------------------

!320  CONTINUE

DO JL = KIDIA,KFDIA
  PFLUX5(JL,1,1) = PEMIT5(JL)*PBSUI5(JL) &
   & -(1.0_JPRB-PEMIT5(JL))*PFLUX5(JL,2,1)
ENDDO

!*         3.3     UPWARD FLUXES
!                  -------------

!330  CONTINUE

DO JK1 = 2 , KLEV+1

!*                 CONTRIBUTION FROM CLEAR-SKY FRACTION

  DO JL = KIDIA,KFDIA
    ZFU5(JL) = (1.0_JPRB - ZCLM5(JL,1,JK1)) * ZUPF5(JL,1,JK1)
  ENDDO

!*                 CONTRIBUTION FROM OTHER CLOUDY FRACTIONS

  IJK=MIN(KTOPC+1,JK1)
  DO JK = 2 , IJK-1
    DO JL = KIDIA,KFDIA
      ZCFRAC5(JL,JK,JK1) = ZCLM5(JL,JK-1,JK1) - ZCLM5(JL,JK,JK1)
      ZFU5(JL) = ZFU5(JL) + ZCFRAC5(JL,JK,JK1) * ZUPF5(JL,JK,JK1)
    ENDDO
  ENDDO

!*                 CONTRIBUTION FROM ADJACENT CLOUD

  DO JL = KIDIA,KFDIA
    ZFU5(JL) = ZFU5(JL) + ZCLM5(JL,JK1-1,IJK) * ZUPF5(JL,IJK,IJK)
  ENDDO

  DO JL = KIDIA,KFDIA
    PFLUX5(JL,1,JK1) = ZFU5(JL)
  ENDDO

ENDDO

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

!*         0.    ADJOINT CALCULATIONS
!                --------------------

!* Set local variables to zero

ZCLM(:,:,:) = 0.0_JPRB
ZDNF(:,:,:) = 0.0_JPRB
ZUPF(:,:,:) = 0.0_JPRB
ZACLFR(:,:) = 0.0_JPRB
ZCLDLD(:,:) = 0.0_JPRB
ZCLDLU(:,:) = 0.0_JPRB
ZTMP1(:,:) = 0.0_JPRB
ZTMP3(:,:) = 0.0_JPRB
ZTMP4(:,:) = 0.0_JPRB
ZTMP5(:,:) = 0.0_JPRB
ZCLFR(:,:) = 0.0_JPRB
ZEMIS(:,:) = 0.0_JPRB
ZCLEAR(:) = 0.0_JPRB
ZCLOUD(:) = 0.0_JPRB
ZSUM(:) = 0.0_JPRB
!ZFD(:) = 0.0_JPRB
!ZFU(:) = 0.0_JPRB

!*         1.3.    FLUXES FOR PARTIAL/MULTIPLE LAYERED CLOUDINESS
!                  ----------------------------------------------

!*         1.3.3   UPWARD FLUXES
!                  -------------

!330  CONTINUE

DO JK1 = KLEV+1 , 2 , -1

!*                 CONTRIBUTION FROM ADJACENT CLOUD

  DO JL = KIDIA,KFDIA
    ZFU(JL) = PFLUX(JL,1,JK1)
    PFLUX(JL,1,JK1) = 0.0_JPRB
  ENDDO

  IJK=MIN(KTOPC+1,JK1)
  DO JL = KIDIA,KFDIA
    ZUPF(JL,IJK,IJK) = ZUPF(JL,IJK,IJK)+ZCLM5(JL,JK1-1,IJK)*ZFU(JL)
    ZCLM(JL,JK1-1,IJK) = ZCLM(JL,JK1-1,IJK)+ZUPF5(JL,IJK,IJK)*ZFU(JL)
  ENDDO

!*                 CONTRIBUTION FROM OTHER CLOUDY FRACTIONS

!  IJK=MIN(KTOPC+1,JK1)
  DO JK = IJK-1, 2 , -1
    DO JL = KIDIA,KFDIA
      ZUPF(JL,JK,JK1) = ZUPF(JL,JK,JK1)+ZCFRAC5(JL,JK,JK1)*ZFU(JL)
      ZCFRAC = ZUPF5(JL,JK,JK1)*ZFU(JL)
      ZCLM (JL,JK-1,JK1) = ZCLM (JL,JK-1,JK1)+ZCFRAC
      ZCLM (JL,JK,JK1) = ZCLM (JL,JK,JK1)-ZCFRAC
    ENDDO
  ENDDO

!*                 CONTRIBUTION FROM CLEAR-SKY FRACTION

  DO JL = KIDIA,KFDIA
    ZUPF(JL,1,JK1) = ZUPF(JL,1,JK1)+(1.0_JPRB-ZCLM5(JL,1,JK1))*ZFU(JL)
    ZCLM(JL,1,JK1) = ZCLM(JL,1,JK1)-ZUPF5(JL,1,JK1)*ZFU(JL)
!    ZFU(JL) = 0.0_JPRB
  ENDDO
ENDDO

!*         1.3.2   UPWARD FLUX AT THE SURFACE
!                  --------------------------

!320  CONTINUE

DO JL = KIDIA,KFDIA
  PBSUI(JL) = PBSUI(JL)+PEMIT5(JL)*PFLUX(JL,1,1)
  PEMIT(JL) = PEMIT(JL)+PBSUI5(JL)*PFLUX(JL,1,1)
  PFLUX(JL,2,1) = PFLUX(JL,2,1)-(1.0_JPRB-PEMIT5(JL))*PFLUX(JL,1,1)
  PEMIT(JL) = PEMIT(JL)+PFLUX5(JL,2,1)*PFLUX(JL,1,1)
  PFLUX(JL,1,1) = 0.0_JPRB
ENDDO

!*         1.3.1   DOWNWARD FLUXES
!                  ---------------

!310  CONTINUE

DO JK1 = KTOPC , 1 , -1

!*                 CONTRIBUTION FROM OTHER CLOUDY FRACTIONS

  DO JL = KIDIA,KFDIA
    ZFD(JL) = PFLUX(JL,2,JK1)
    PFLUX(JL,2,JK1) = 0.0_JPRB
  ENDDO

  DO JK = KTOPC-1, JK1, -1 
    DO JL = KIDIA,KFDIA
      ZDNF(JL,JK+2,JK1) = ZDNF(JL,JK+2,JK1)+ZCFRAC5(JL,JK,JK1)*ZFD(JL)
      ZCFRAC = ZDNF5(JL,JK+2,JK1)*ZFD(JL)
      ZCLM(JL,JK+1,JK1) = ZCLM(JL,JK+1,JK1)+ZCFRAC
      ZCLM (JL,JK,JK1) = ZCLM (JL,JK,JK1)-ZCFRAC
    ENDDO
  ENDDO

  DO JL = KIDIA,KFDIA

!*                 CONTRIBUTION FROM ADJACENT CLOUD
    ZDNF(JL,JK1+1,JK1) = ZDNF(JL,JK1+1,JK1)+ZCLM5(JL,JK1,JK1)*ZFD(JL)
    ZCLM(JL,JK1,JK1) = ZCLM(JL,JK1,JK1)+ZDNF5(JL,JK1+1,JK1)*ZFD(JL)

!*                 CONTRIBUTION FROM CLEAR-SKY FRACTION

    ZDNF(JL,1,JK1) = ZDNF(JL,1,JK1)+(1.0_JPRB-ZCLM5(JL,KTOPC,JK1))*ZFD(JL)
    ZCLM(JL,KTOPC,JK1) = ZCLM(JL,KTOPC,JK1)-ZDNF5(JL,1,JK1)*ZFD(JL)
!    ZFD(JL) = 0.0_JPRB
  ENDDO
ENDDO

DO JL = KIDIA,KFDIA
  PFLUX(JL,2,KLEV+1) = 0.0_JPRB
ENDDO

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

!*         1.2.    EFFECT OF CLOUDINESS ON LONGWAVE FLUXES
!   

!*         1.2.5   CLOUD COVER ABOVE THE LEVEL OF CALCULATION
!                  ------------------------------------------

!250  CONTINUE


IF (LRAISANEN) THEN
!* maximum-random (Raisanen 1998)

  DO JK1 = KTOPC, 1, -1
    DO JK = KTOPC, JK1+1, -1
      IKL = KLEV + 1 - JK
      DO JL = KIDIA,KFDIA
        ZSUM(JL) = ZSUM(JL)+ZCLM(JL,JK,JK1)
        ZCLM(JL,JK,JK1) = 0.0_JPRB
        ZCLOUD(JL) = ZCLOUD(JL)+ZSUM(JL)

        ZEMIS(JL,JK) = ZEMIS(JL,JK) &
         & + (ZTR15(JL,JK,JK1)*ZTMPA45(JL,JK) &
         & + ZTR25(JL,JK,JK1)*ZTMPA55(JL,JK)) &
         & *ZCLOUD(JL)  
        ZTR1 = ZEMISA5(JL,JK)*ZTMPA45(JL,JK)*ZCLOUD(JL)
        ZTMP4(JL,JK) = ZTMP4(JL,JK)+ZEMISA5(JL,JK)*ZTR15(JL,JK,JK1) &
         & * ZCLOUD(JL)  
        ZTR2 = ZEMISA5(JL,JK)*ZTMPA55(JL,JK)*ZCLOUD(JL)
        ZTMP5(JL,JK) = ZTMP5(JL,JK)+ZEMISA5(JL,JK)*ZTR25(JL,JK,JK1) &
         & * ZCLOUD(JL)  
        ZCLOUD(JL)=0.0_JPRB

        ZSUM(JL) = ZSUM(JL) - ZTMPA35(JL,JK)*ZTR2
        ZCLOUD(JL) = ZCLOUD(JL) + ZTMPA35(JL,JK)*ZTR2
        ZTR1 = ZTR1 - ZCLFR5(JL,IKL+1)*ZTMPA35(JL,JK)*ZTR2 
        ZCLFR(JL,IKL+1) = ZCLFR(JL,IKL+1) &
         & - ZTR15(JL,JK,JK1)*ZTMPA35(JL,JK)*ZTR2  
        ZTMP3(JL,JK) = ZTMP3(JL,JK) &
         & + (1.0_JPRB-ZSUMA5(JL,JK-1,JK1)+ZCLOUDA5(JL,JK-1,JK1) &
         & - ZTR15(JL,JK,JK1)*ZCLFR5(JL,IKL+1))*ZTR2

        ZCLOUD(JL) = ZCLOUD(JL) + ZTMPA15(JL,JK)*ZTR1
        ZTMP1(JL,JK) = ZTMP1(JL,JK)+ZCLOUDA5(JL,JK-1,JK1)*ZTR1
      ENDDO
    ENDDO

    DO JL = KIDIA,KFDIA
      ZSUM(JL) = ZSUM(JL) + ZCLM (JL,JK1,JK1)
      ZCLM (JL,JK1,JK1) = 0.0_JPRB
      ZCLOUD(JL) = ZCLOUD(JL) + ZSUM (JL)
      ZSUM (JL) = 0.0_JPRB
      ZCLDLD(JL,JK1) = ZCLDLD(JL,JK1) + ZCLOUD (JL)
      ZCLOUD (JL) = 0.0_JPRB
    ENDDO
  ENDDO

  DO JK = KTOPC,2,-1
    IKL = KLEV + 1 - JK
    DO JL = KIDIA,KFDIA
      ZCLFR(JL,IKL) = ZCLFR(JL,IKL)+ZTMP5(JL,JK)
      ZCADJ = -ZTMP5(JL,JK)
      ZTMP5(JL,JK) = 0.0_JPRB
      ZCADJ = ZCADJ+(1.0_JPRB-ZEMISA5(JL,JK-1))*ZTMP4(JL,JK)
      ZEMIS(JL,JK-1) = ZEMIS(JL,JK-1)-ZCADJA5(JL,JK)*ZTMP4(JL,JK)
      ZTMP4(JL,JK) = 0.0_JPRB
      ZCLFR(JL,IKL+1) = ZCLFR(JL,IKL+1) &
       & + ZTMPA35(JL,JK)*ZTMPA35(JL,JK)*ZTMP3(JL,JK)
      ZTMP3(JL,JK) = 0.0_JPRB
!* Modified for regularization 
      IF (ZCLFRA5(JL,IKL+1) > 0.999_JPRB) THEN
        ZCLFR(JL,IKL+1) = 0.0_JPRB
      ENDIF
!* End of modification
      IF (ZCLFR5(JL,IKL) <= ZCLFRA5(JL,IKL+1)) THEN
        ZCLFR(JL,IKL) = ZCLFR(JL,IKL)+ZCADJ
      ELSE
        ZCLFR(JL,IKL+1) = ZCLFR(JL,IKL+1)+ZCADJ
      ENDIF
      IF (ZCLDLD5(JL,JK-1) > REPCLC) THEN
        ZCLDLD(JL,JK-1) = ZCLDLD(JL,JK-1) &
         & - ZTMPA15(JL,JK)*ZTMPA15(JL,JK)*ZTMP1(JL,JK)
      ENDIF
      ZTMP1(JL,JK) = 0.0_JPRB
    ENDDO
  ENDDO

  DO JK = KLEV, 1, -1
    IKL = KLEV + 1 - JK
    DO JL = KIDIA,KFDIA
      ZCLDLD(JL,JK) = ZCLDLD(JL,JK)+ZDIV45(JL,JK)*ZEMIS(JL,JK)
      ZCLFR(JL,IKL) = ZCLFR(JL,IKL) &
       & - ZCLDLD5(JL,JK)*ZDIV45(JL,JK)*ZDIV45(JL,JK)*ZEMIS(JL,JK)
      ZEMIS(JL,JK) = 0.0_JPRB
    ENDDO
  ENDDO

  ZEMIS(:,:)  = 0.0_JPRB

ELSE

  DO JK1 = KTOPC, 1, -1

    DO JK = KTOPC, JK1, -1
      ZALPHA1=RA1OVLP(KLEV+1-JK)

      DO JL = KIDIA,KFDIA

        IF (NOVLP == 1) THEN
!* maximum-random
          ZCLDLD(JL,JK) = ZCLDLD(JL,JK) + ZCLOUD (JL)
          ZCLOUD (JL) = 0.0_JPRB
          ZCLEAR(JL) = ZCLEAR(JL) - ZCLM (JL,JK,JK1)
          ZCLM (JL,JK,JK1) = 0.0_JPRB
          ZNUM = -ZCLEARA5(JL,JK,JK1)*ZDIV55(JL,JK,JK1)*ZCLEAR(JL)
          ZDEN = ZCLEARA5(JL,JK,JK1)*(1.0_JPRB-ZNUM5(JL,JK,JK1)) &
           & * ZDIV55(JL,JK,JK1)*ZDIV55(JL,JK,JK1)*ZCLEAR(JL)
          ZCLEAR(JL)=ZCLEAR(JL) &
           & * (1.0_JPRB-ZNUM5(JL,JK,JK1))*ZDIV55(JL,JK,JK1)
          IF (ZCLOUDA5(JL,JK,JK1) <= 1.0_JPRB-REPCLC) THEN  
            ZCLOUD(JL) = ZCLOUD(JL) + ZDEN
          ENDIF
          IF (ZCLDLD5(JL,JK) >= ZCLOUDA5(JL,JK,JK1)) THEN
            ZCLDLD (JL,JK) = ZCLDLD (JL,JK) + ZNUM
          ELSE
            ZCLOUD(JL) = ZCLOUD(JL) + ZNUM
          ENDIF

        ELSEIF (NOVLP == 2) THEN
!* maximum
          ZCLOUD(JL) = ZCLOUD(JL) + ZCLM (JL,JK,JK1)
          ZCLM (JL,JK,JK1) = 0.0_JPRB
          IF (ZCLDLD5(JL,JK) >= ZCLOUDA5(JL,JK,JK1)) THEN
            ZCLDLD(JL,JK) = ZCLDLD(JL,JK) + ZCLOUD (JL)
            ZCLOUD (JL) = 0.0_JPRB
          ENDIF

        ELSEIF (NOVLP == 3) THEN
!* random
          ZCLOUD(JL) = ZCLOUD(JL) + ZCLM (JL,JK,JK1)
          ZCLM (JL,JK,JK1) = 0.0_JPRB
          ZCLEAR(JL) = ZCLEAR(JL) - ZCLOUD (JL)
          ZCLOUD (JL) = 0.0_JPRB
          ZCLDLD(JL,JK) = ZCLDLD(JL,JK) - ZCLEAR(JL) &
           & * ZCLEARA5(JL,JK,JK1)  
          ZCLEAR(JL)  = ZCLEAR(JL)*(1.0_JPRB - ZCLDLD5(JL,JK))

        ELSEIF (NOVLP == 4) THEN
!** Hogan & Illingworth (2001)
          ZCLDLD(JL,JK) = ZCLDLD(JL,JK)+ZCLOUD(JL)
          ZCLOUD(JL) = 0.0_JPRB
          ZCLEAR(JL) = ZCLEAR(JL)-ZCLM(JL,JK,JK1)
          ZCLM(JL,JK,JK1) = 0.0_JPRB
          ZNUM = -(ZALPHA1*ZCLEARA5(JL,JK,JK1)*ZDIV65(JL,JK,JK1))*ZCLEAR(JL)
          ZDEN = (ZALPHA1*ZCLEARA5(JL,JK,JK1)*(1.0_JPRB-ZNUM5(JL,JK,JK1)) &
           & * ZDIV65(JL,JK,JK1)*ZDIV65(JL,JK,JK1))*ZCLEAR(JL) 
          ZCLDLD(JL,JK) = ZCLDLD(JL,JK) &
           & - (1.0_JPRB-ZALPHA1)*ZCLEARA5(JL,JK,JK1)*ZCLEAR(JL)
          ZCLEAR(JL) = ZCLEAR(JL) &
           & * (ZALPHA1*(1.0_JPRB-ZNUM5(JL,JK,JK1))*ZDIV65(JL,JK,JK1) &
           & + (1.0_JPRB-ZALPHA1)*(1.0_JPRB-ZCLDLD5(JL,JK)))
          IF (ZCLOUDA5(JL,JK,JK1) <= 1.0_JPRB-REPCLC) THEN
            ZCLOUD(JL) = ZCLOUD(JL)+ZDEN
          ENDIF
          IF (ZCLDLD5(JL,JK) >= ZCLOUDA5(JL,JK,JK1)) THEN
            ZCLDLD(JL,JK) = ZCLDLD(JL,JK)+ZNUM
          ELSE
            ZCLOUD(JL) = ZCLOUD(JL)+ZNUM
          ENDIF
        ENDIF
      ENDDO
    ENDDO
    DO JL = KIDIA,KFDIA
      ZCLOUD(JL)=0.0_JPRB
      ZCLEAR(JL)=0.0_JPRB
    ENDDO
  ENDDO

ENDIF

!*         1.2.4   CLOUD COVER BELOW THE LEVEL OF CALCULATION
!                  ------------------------------------------

!240  CONTINUE

IF (LRAISANEN) THEN
!* maximum-random (Raisanen 1998)

  DO JK1 = KLEV+1, 2, -1
    IJK=MIN(KTOPC+1,JK1)

    DO JK = 1, IJK - 2
      IKL = KLEV+1 - JK
      IF (JK == KTOPC-1) THEN
        ICL = JK1-1
      ELSE
        ICL = JK+1
      ENDIF

      DO JL = KIDIA,KFDIA
        ZSUM(JL) = ZSUM(JL)+ZCLM(JL,JK,JK1)
        ZCLM(JL,JK,JK1) = 0.0_JPRB
        ZCLOUD(JL) = ZCLOUD(JL) + ZSUM(JL)
        
        ZEMIS(JL,JK) = ZEMIS(JL,JK) &
         & + (ZTR15(JL,JK,JK1)*ZTMPB45(JL,JK) &
         & + ZTR25(JL,JK,JK1)*ZTMPB55(JL,JK))*ZCLOUD(JL)
        ZTR1 = ZEMISB5(JL,JK)*ZTMPB45(JL,JK)*ZCLOUD(JL)
        ZTMP4(JL,JK) = ZTMP4(JL,JK) &
         & + ZEMISB5(JL,JK)*ZTR15(JL,JK,JK1)*ZCLOUD(JL)
        ZTR2 = ZEMISB5(JL,JK)*ZTMPB55(JL,JK)*ZCLOUD(JL)
        ZTMP5(JL,JK) = ZTMP5(JL,JK) &
         & + ZEMISB5(JL,JK)*ZTR25(JL,JK,JK1)*ZCLOUD(JL)
        ZCLOUD(JL) = 0.0_JPRB

        ZSUM(JL) = ZSUM(JL) - ZTMPB35(JL,JK)*ZTR2
        ZCLOUD(JL) = ZCLOUD(JL) + ZTMPB35(JL,JK)*ZTR2
        ZTR1 = ZTR1 - ZTMPB35(JL,JK)*ZCLFR5(JL,IKL-1)*ZTR2
        ZCLFR(JL,IKL-1) = ZCLFR(JL,IKL-1) &
         & - ZTR15(JL,JK,JK1)*ZTMPB35(JL,JK)*ZTR2
        ZTMP3(JL,JK) = ZTMP3(JL,JK)+ (1.0_JPRB -ZSUMB5(JL,ICL,JK1) &
         & + ZCLOUD5(JL,ICL,JK1) &
         & - ZTR15(JL,JK,JK1)*ZCLFR5(JL,IKL-1))*ZTR2

        ZCLOUD(JL) = ZCLOUD(JL) + ZTMPB15(JL,JK)*ZTR1
        ZTMP1(JL,JK) = ZTMP1(JL,JK)+ZCLOUD5(JL,ICL,JK1)*ZTR1
      ENDDO
    ENDDO

    DO JL = KIDIA,KFDIA
      ZSUM(JL) = ZSUM(JL) + ZCLM (JL,JK1-1,JK1)
      ZCLM (JL,JK1-1,JK1) = 0.0_JPRB
      ZCLOUD(JL) = ZCLOUD(JL) + ZSUM (JL)
      ZSUM (JL) = 0.0_JPRB
      ZCLDLU(JL,JK1-1) = ZCLDLU(JL,JK1-1) + ZCLOUD (JL)
      ZCLOUD (JL) = 0.0_JPRB
    ENDDO
  ENDDO

  DO JK = KTOPC-1,1,-1
    IKL = KLEV + 1 - JK
    DO JL = KIDIA,KFDIA
      ZCLFR(JL,IKL) = ZCLFR(JL,IKL)+ZTMP5(JL,JK)
      ZCADJ = -ZTMP5(JL,JK)
      ZTMP5(JL,JK) = 0.0_JPRB
      ZCADJ = ZCADJ+(1.0_JPRB-ZEMISB5(JL,JK+1))*ZTMP4(JL,JK)
      ZEMIS(JL,JK+1) = ZEMIS(JL,JK+1)-ZCADJB5(JL,JK)*ZTMP4(JL,JK)
      ZTMP4(JL,JK) = 0.0_JPRB
      ZCLFR(JL,IKL-1) = ZCLFR(JL,IKL-1) &
       & + ZTMPB35(JL,JK)*ZTMPB35(JL,JK)*ZTMP3(JL,JK)
      ZTMP3(JL,JK) = 0.0_JPRB
!* Modified for regularization 
      IF (ZCLFRB5(JL,IKL-1) > 0.999_JPRB) THEN
        ZCLFR(JL,IKL-1) = 0.0_JPRB
      ENDIF
!* End of modification
      IF (ZCLFR5(JL,IKL) <= ZCLFRB5(JL,IKL-1)) THEN
        ZCLFR(JL,IKL) = ZCLFR(JL,IKL)+ZCADJ
      ELSE
        ZCLFR(JL,IKL-1) = ZCLFR(JL,IKL-1)+ZCADJ
      ENDIF
      IF (ZCLDLU5(JL,JK+1) > REPCLC) THEN
        ZCLDLU(JL,JK+1) = ZCLDLU(JL,JK+1) &
         & - ZTMPB15(JL,JK)*ZTMPB15(JL,JK)*ZTMP1(JL,JK)
      ENDIF
      ZTMP1(JL,JK) = 0.0_JPRB
    ENDDO
  ENDDO

  DO JK = KLEV, 1, -1
    IKL = KLEV + 1 - JK
    DO JL = KIDIA,KFDIA
      ZCLDLU(JL,JK) = ZCLDLU(JL,JK) + ZDIV15(JL,JK)*ZEMIS(JL,JK)
      ZCLFR(JL,IKL) = ZCLFR(JL,IKL) &
       & - ZCLDLU5(JL,JK)*ZDIV15(JL,JK)*ZDIV15(JL,JK)*ZEMIS(JL,JK)
      ZEMIS(JL,JK) = 0.0_JPRB
      IF (ZCLFR5(JL,IKL) >= 1.0_JPRB-REPCLC) THEN
        ZCLFR (JL,IKL) = 0.0_JPRB
      ENDIF
      IF (ZCLFR5(JL,IKL) <= REPCLC) THEN
        ZCLFR (JL,IKL) = 0.0_JPRB
      ENDIF
      ZACLFR (JL,IKL) = ZACLFR (JL,IKL) + ZCLFR (JL,IKL)
      ZCLFR (JL,IKL) = 0.0_JPRB
    ENDDO
  ENDDO

  ZEMIS(:,:)  = 0.0_JPRB

ELSE

  DO JK1 = KLEV+1, 2, -1

    IJK=MIN(KTOPC,JK1)
    DO JK = 1,IJK - 1
      ZALPHA1=RA1OVLP(KLEV+1-JK)

      DO JL = KIDIA,KFDIA

        IF (NOVLP == 1) THEN
!* maximum-random    Geleyn and Hollingsworth 1979
          ZCLDLU(JL,JK) = ZCLDLU(JL,JK) + ZCLOUD (JL)
          ZCLOUD (JL) = 0.0_JPRB
          ZCLEAR(JL) = ZCLEAR(JL) - ZCLM (JL,JK,JK1)
          ZCLM (JL,JK,JK1) = 0.0_JPRB
          ZNUM = - ZDIV25(JL,JK,JK1)*ZCLEARB5(JL,JK,JK1)*ZCLEAR(JL)
          ZDEN = ZDIV25(JL,JK,JK1)*ZDIV25(JL,JK,JK1) &
           & * ZCLEARB5(JL,JK,JK1)*(1.0_JPRB-ZNUM5(JL,JK,JK1))*ZCLEAR(JL)
          ZCLEAR(JL)=ZCLEAR(JL)*(1.0_JPRB-ZNUM5(JL,JK,JK1))*ZDIV25(JL,JK,JK1)

          IF (ZCLOUDB5(JL,JK,JK1) <= 1.0_JPRB-REPCLC) THEN
            ZCLOUD(JL) = ZCLOUD(JL) + ZDEN
          ENDIF
          IF (ZCLDLU5(JL,JK) >= ZCLOUDB5(JL,JK,JK1)) THEN
            ZCLDLU (JL,JK) = ZCLDLU (JL,JK) + ZNUM
          ELSE
            ZCLOUD(JL) = ZCLOUD(JL) + ZNUM
          ENDIF

        ELSEIF (NOVLP == 2) THEN
!* maximum
          ZCLOUD(JL) = ZCLOUD(JL) + ZCLM(JL,JK,JK1)
          ZCLM (JL,JK,JK1) = 0.0_JPRB
          IF (ZCLDLU5(JL,JK) >= ZCLOUDB5(JL,JK,JK1)) THEN
            ZCLDLU(JL,JK) =  ZCLDLU(JL,JK) + ZCLOUD (JL)
            ZCLOUD (JL) = 0.0_JPRB
          ENDIF

        ELSEIF (NOVLP == 3) THEN
!* random
          ZCLOUD(JL) = ZCLOUD(JL) + ZCLM(JL,JK,JK1)
          ZCLM(JL,JK,JK1) = 0.0_JPRB
          ZCLEAR(JL) = ZCLEAR(JL) - ZCLOUD (JL)
          ZCLOUD (JL) = 0.0_JPRB
          ZCLDLU(JL,JK) = ZCLDLU(JL,JK) - ZCLEAR(JL) &
           & *ZCLEARB5(JL,JK,JK1)
          ZCLEAR(JL)  = ZCLEAR(JL)*(1.0_JPRB - ZCLDLU5(JL,JK))

        ELSEIF (NOVLP == 4) THEN
!** Hogan & Illingworth (2001)
          ZCLDLU(JL,JK) = ZCLDLU(JL,JK)+ZCLOUD(JL)
          ZCLOUD(JL) = 0.0_JPRB
          ZCLEAR(JL) = ZCLEAR(JL)-ZCLM(JL,JK,JK1)
          ZCLM(JL,JK,JK1) = 0.0_JPRB
          ZNUM = -(ZALPHA1*ZCLEARB5(JL,JK,JK1)*ZDIV35(JL,JK,JK1))*ZCLEAR(JL)
          ZDEN = (ZALPHA1*ZCLEARB5(JL,JK,JK1)*(1.0_JPRB-ZNUM5(JL,JK,JK1)) &
           & * ZDIV35(JL,JK,JK1)*ZDIV35(JL,JK,JK1))*ZCLEAR(JL)
          ZCLDLU(JL,JK) = ZCLDLU(JL,JK) &
           & - (1.0_JPRB-ZALPHA1)*ZCLEARB5(JL,JK,JK1)*ZCLEAR(JL)
          ZCLEAR(JL) = ZCLEAR(JL) &
           & *(ZALPHA1*(1.0_JPRB-ZNUM5(JL,JK,JK1))*ZDIV35(JL,JK,JK1) &
           & + (1.0_JPRB-ZALPHA1)*(1.0_JPRB-ZCLDLU5(JL,JK)))

          IF (ZCLOUDB5(JL,JK,JK1) <= 1.0_JPRB-REPCLC) THEN
            ZCLOUD(JL) = ZCLOUD(JL)+ZDEN
          ENDIF
          IF (ZCLDLU5(JL,JK) >= ZCLOUDB5(JL,JK,JK1)) THEN
            ZCLDLU(JL,JK) = ZCLDLU(JL,JK)+ZNUM
          ELSE
            ZCLOUD(JL) = ZCLOUD(JL)+ZNUM
          ENDIF
        ENDIF
      ENDDO
    ENDDO

    DO JL = KIDIA,KFDIA
      ZCLOUD(JL) =0.0_JPRB
      ZCLEAR(JL) =0.0_JPRB
    ENDDO
  ENDDO

ENDIF

!*         1.2.2   CLOUD COVER MATRIX
!                  ------------------

! Securities

IF (LRAISANEN) THEN
  DO JK = KLEV,1,-1
    IKL = KLEV + 1 - JK
    DO JL = KIDIA,KFDIA
      IF (PCLDLU5(JL,JK) <= REPCLC .OR. PCLDLD5(JL,JK) <= REPCLC) THEN
        ZACLFR (JL,IKL) = 0.0_JPRB
      ELSE
        PCLFR (JL,IKL) = PCLFR (JL,IKL)+ZACLFR (JL,IKL)
        ZACLFR (JL,IKL) = 0.0_JPRB
      ENDIF
    ENDDO
  ENDDO
ENDIF

!DO JK = KLEV,1,-1
!  IKL = KLEV + 1 - JK
!  DO JL = KIDIA,KFDIA
!    IF (PCLFR5(JL,IKL) <= REPCLC) THEN
!      ZCLDLD (JL,JK) = 0.0_JPRB
!      ZCLDLU (JL,JK) = 0.0_JPRB
!    ELSE
!      PCLDLD (JL,JK) = PCLDLD (JL,JK)+ZCLDLD (JL,JK)
!      ZCLDLD (JL,JK) = 0.0_JPRB
!      PCLDLU (JL,JK) = PCLDLU (JL,JK)+ZCLDLU (JL,JK)
!      ZCLDLU (JL,JK) = 0.0_JPRB
!    ENDIF
!  ENDDO
!ENDDO

IF (KTOPC /= KLEV) THEN
  DO JK = KLEV,KTOPC+1,-1
    IKL = KLEV + 1 - JK
    DO JL = KIDIA,KFDIA
      ZACLFR (JL,IKL) = 0.0_JPRB
      ZCLDLD (JL,JK) = 0.0_JPRB
      ZCLDLU (JL,JK) = 0.0_JPRB
    ENDDO
  ENDDO
  DO JK = KTOPC,1,-1
    IKL = KLEV + 1 - JK
    DO JL = KIDIA,KFDIA
      PCLFR (JL,IKL) = PCLFR (JL,IKL) + ZACLFR (JL,IKL)
      ZACLFR (JL,IKL) = 0.0_JPRB
 
      PCLDLD (JL,JK) = PCLDLD (JL,JK) + ZCLDLD (JL,JK)
      ZCLDLD (JL,JK) = 0.0_JPRB
      PCLDLU (JL,JK) = PCLDLU (JL,JK) + ZCLDLU (JL,JK)
      ZCLDLU (JL,JK) = 0.0_JPRB
    ENDDO
  ENDDO
ELSE
  DO JK = KLEV,1,-1
    IKL = KLEV + 1 - JK
    DO JL = KIDIA,KFDIA
      PCLFR (JL,IKL) = PCLFR (JL,IKL) + ZACLFR (JL,IKL)
      ZACLFR (JL,IKL) = 0.0_JPRB
 
      PCLDLD (JL,JK) = PCLDLD (JL,JK) + ZCLDLD (JL,JK)
      ZCLDLD (JL,JK) = 0.0_JPRB
      PCLDLU (JL,JK) = PCLDLU (JL,JK) + ZCLDLU (JL,JK)
      ZCLDLU (JL,JK) = 0.0_JPRB
    ENDDO
  ENDDO
ENDIF



!IF (.NOT.LRAISANEN) THEN
!  DO JK = KTOPC+2,KLEV
!    DO JL = KIDIA,KFDIA
!      ZCLM (JL,JK,JK+1) = 0.0_JPRB
!    ENDDO
!  ENDDO
!ENDIF

!DO JK = KTOPC,KLEV+1
!  DO JL = KIDIA,KFDIA
!    ZCLM (JL,KTOPC+1,JK) = 0.0_JPRB
!    ZCLM (JL,KTOPC,JK) = 0.0_JPRB
!  ENDDO
!ENDDO

!*         1.2.1   FLUXES FOR ONE OVERCAST UNITY EMISSIVITY CLOUD
!                  ----------------------------------------------

!210  CONTINUE

!DO JCLOUD = KTOPC, 1, -1
DO JCLOUD = 1,KTOPC
  IKCP1=JCLOUD+1

!*         1.2.1.2   BELOW THE CLOUD
!                    ---------------

!2120 CONTINUE

  DO JK=JCLOUD,1,-1
    IKP1=JK+1

    DO JL = KIDIA,KFDIA
      PBINT(JL,JK) = PBINT(JL,JK)-ZDNF(JL,IKCP1,JK)
      ZFD(JL) = -ZDNF(JL,IKCP1,JK)
!      ZDNF(JL,IKCP1,JK) = 0.0_JPRB
    ENDDO

    IF (JK  <  JCLOUD) THEN
      DO JKJ=JCLOUD,IKP1,-1
        DO JL = KIDIA,KFDIA
          PCNTRB(JL,JK,JKJ) = PCNTRB(JL,JK,JKJ)+ZFD(JL)
        ENDDO
      ENDDO
    ENDIF

!    DO JL = KIDIA,KFDIA
!      ZFD(JL) = 0.0_JPRB
!    ENDDO
  ENDDO


!*         1.2.1.1   ABOVE THE CLOUD
!                    ---------------

!2110 CONTINUE

  DO JK=KLEV+1,IKCP1,-1
    IKM1=JK-1

    DO JL = KIDIA,KFDIA
      PBINT(JL,JK) = PBINT(JL,JK)+ZUPF(JL,IKCP1,JK)
      ZFU(JL) = -ZUPF(JL,IKCP1,JK)
!      ZUPF(JL,IKCP1,JK) = 0.0_JPRB
    ENDDO

    IF (JK  >  IKCP1) THEN
      DO JKJ=IKM1, IKCP1, -1
        DO JL = KIDIA,KFDIA
          PCNTRB(JL,JK,JKJ) = PCNTRB(JL,JK,JKJ)+ZFU(JL)
        ENDDO
      ENDDO
    ENDIF

!    DO JL = KIDIA,KFDIA
!      ZFU (JL) = 0.0_JPRB
!    ENDDO
  ENDDO

ENDDO

!*         1.2.0   INITIALIZE TO CLEAR-SKY FLUXES
!                  ------------------------------

!200  CONTINUE

DO JK = 1,KLEV+1
  DO JL = KIDIA,KFDIA
    PFLUC(JL,1,JK) = PFLUC(JL,1,JK)+ZUPF(JL,1,JK)
!    ZUPF(JL,1,JK) = 0.0_JPRB
  ENDDO
ENDDO

DO JK = 1,KTOPC+1
  DO JL = KIDIA,KFDIA
    PFLUC(JL,2,JK) = PFLUC(JL,2,JK)+ZDNF(JL,1,JK)
!    ZDNF(JL,1,JK) = 0.0_JPRB
  ENDDO
ENDDO

!*         1.1.   INITIALIZATION
!                 --------------

!100  CONTINUE

DO JK = 1 , KLEV+1
  DO JL = KIDIA,KFDIA
    PFLUC(JL,2,JK) = PFLUC(JL,2,JK)+PFLUX(JL,2,JK)
    PFLUX(JL,2,JK) = 0.0_JPRB
    PFLUC(JL,1,JK) = PFLUC(JL,1,JK)+PFLUX(JL,1,JK)
    PFLUX(JL,1,JK) = 0.0_JPRB
  ENDDO
ENDDO

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

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