SUBROUTINE RADLSWAD &
 & (  KIDIA , KFDIA  , KLON  , KLEV, KMODE, KAER,&
 & PRII05,&
 & PAER5 , PALBD5 , PALBP5, PAPH5 , PAP5,&
 & PCCNL5, PCCNO5,&
 & PCCO25, PCLFR5 , PDP5  , PEMIR5, PEMIW5 , POZON5,&
 & PLSM5 , PMU05,&
 & PQ5   , PQIWP5 , PQLWP5, PQS5  ,&
 & PTH5  , PT5    , PTS5,&
 & PFLT5  , PFLS5  , PFRSOD5,&
 & PAER  , PALBD  , PALBP , PAPH  , PAP,&
 & PCCO2 , PCLFR  , PDP   , PEMIR , PEMIW  , POZON,&
 & PQ    , PQIWP  , PQLWP , PQS   ,&
 & PTH   , PT     , PTS,&
 & PFLT  , PFLS   , PFRSOD    &
 & )  

!**** *RADLSWAD* - INTERFACE TO ECMWF LW AND SW RADIATION SCHEMES
!                  (Adjoint)

!     PURPOSE.
!     --------
!           CONTROLS RADIATION COMPUTATIONS

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

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

! PAER   : (KLON,6,KLEV)     ; OPTICAL THICKNESS OF THE AEROSOLS
! PALBD  : (KLON,NSW)        ; SURF. SW ALBEDO FOR DIFFUSE RADIATION
! PALBP  : (KLON,NSW)        ; SURF. SW ALBEDO FOR PARALLEL RADIATION
! PAPH   : (KLON,KLEV+1)     ; HALF LEVEL PRESSURE
! PAP    : (KLON,KLEV)       ; FULL LEVEL PRESSURE
! PCCO2  :                   ; CONCENTRATION IN CO2 (KG/KG)
! PCLFR  : (KLON,KLEV)       ; CLOUD FRACTIONAL COVER
! PDP    : (KLON,KLEV)       ; LAYER PRESSURE THICKNESS
! PEMIR  : (KLON)            ; SURFACE EMISSIVITY OUTSIDE LW WINDOW
! PEMIW  : (KLON)            ; SURFACE LW WINDOW EMISSIVITY
! PLSM5  : (KLON)            ; LAND-SEA MASK
! PMU05   : (KLON)           ; SOLAR ANGLE
! POZON  : (KLON,KLEV)       ; OZONE AMOUNT IN LAYER (KG/KG*PA)
! PQ     : (KLON,KLEV)       ; SPECIFIC HUMIDITY KG/KG
! PQIWP  : (KLON,KLEV)       ; SOLID  WATER KG/KG
! PQLWP  : (KLON,KLEV)       ; LIQUID WATER KG/KG
! PQS    : (KLON,KLEV)       ; SATURATION WATER VAPOR  KG/KG
! PTH    : (KLON,KLEV+1)     ; HALF LEVEL TEMPERATURE
! PT     : (KLON,KLEV)       ; FULL LEVEL TEMPERATURE
! PTS    : (KLON)            ; SURFACE TEMPERATURE

!     ==== OUTPUTS ===

! PFLT   : (KLON,KLEV+1)     ; TOTAL LW NET FLUXES
! PFLS   : (KLON,KLEV+1)     ; TOTAL SW NET FLUXES
! PFRSOD : (KLON)            ; TOTAL-SKY SURFACE SW DOWNWARD FLUX

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

!     METHOD.
!     -------
!        SEE DOCUMENTATION

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

!     REFERENCE.
!     ----------
!        ECMWF RESEARCH DEPARTMENT DOCUMENTATION OF THE IFS

!     AUTHORS.
!     --------
!        M. JANISKOVA           *ECMWF*

!        adapted from RADLSW and RADLSWTL 

!        J.-J. MORCRETTE        *ECMWF*
!        J.-F. MAHFOUF          *ECMWF*

!     MODIFICATIONS.
!     --------------
!        M.Hamrud      01-Oct-2003 CY28 Cleaning

!        ORIGINAL: 99-04-16
!        Modified: 2000-02-28 M.Janiskova - adoption for modifications
!                             for effect.radius, inhomogenity factors
!                             and RRTM-140gp
!                  JJMorcrette 011029 CCNs
!                  2002-05-08 M. Janiskova - nearly completely re-written
!                                    due to all modifications of JJM      
!                                          - call for linearized LW  
!                  JJM/MJ 04-12-02 revision ice cloud optical properties 
!                  2006-02-03 M. Janiskova - call to LWTL instead of LWPTL
!                  2008-04-18 M. Janiskova - cleaning & modified computation
!                                            of net fluxes
!-----------------------------------------------------------------------

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

USE YOMCST   , ONLY : RG       ,RD       ,RTT      ,RPI
USE YOERAD   , ONLY : NSW      ,LRRTM    ,LCCNL    ,LCCNO  ,LDIFFC,&
 & NRADIP , NRADLP , NICEOPT, NLIQOPT, NINHOM, RCCNLND, RCCNSEA, RLWINHF, &
 & RSWINHF, RRe2De
USE YOELW    , ONLY : NSIL     ,NTRA     ,NUA      ,TSTAND   ,XP
USE YOESW    , ONLY : RYFWCA   ,RYFWCB   ,RYFWCC   ,RYFWCD   ,&
 & RYFWCE   ,RYFWCF   ,REBCUA   ,REBCUB   ,REBCUC   ,&
 & REBCUD   ,REBCUE   ,REBCUF   ,REBCUI   ,REBCUJ   ,&
 & REBCUG   ,REBCUH   ,RHSAVI   ,RFULIO   ,RFLAA0   ,&
 & RFLAA1   ,RFLBB0   ,RFLBB1   ,RFLBB2   ,RFLBB3   ,&
 & RFLCC0   ,RFLCC1   ,RFLCC2   ,RFLCC3   ,RFLDD0   ,&
 & RFLDD1   ,RFLDD2   ,RFLDD3   ,RFUETA   ,RFUETB   ,RFUETC  ,RASWCA   ,&
 & RASWCB   ,RASWCC   ,RASWCD   ,RASWCE   ,RASWCF   ,&
 & RFUAA0   ,RFUAA1   ,RFUBB0   ,RFUBB1   ,RFUBB2   ,&
 & RFUBB3   ,RFUCC0   ,RFUCC1   ,RFUCC2   ,RFUCC3   ,&
 & RLILIA   ,RLILIB
USE YOERDU   , ONLY : NUAER    ,NTRAER   ,REPLOG   ,REPSC    ,REPSCW   ,DIFF
USE YOETHF   , ONLY : RTICE
USE YOPHNC   , ONLY : LERADSW2 ,LERADN2  ,LERADLW2 ,LH2OCO2
USE YOEPHLI  , ONLY : LPHYLIN
USE YOERRTWN , ONLY : DELWAVE, TOTPLNK
USE YOMCT3   , ONLY : NSTEP
USE YOMCT0   , ONLY : NSTOP
USE YOELWRAD , ONLY : NLEVLWC, NLWFR,  LWLCLHR

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)    :: KMODE
INTEGER(KIND=JPIM),INTENT(IN)    :: KAER 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PRII05 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PAER5(KLON,6,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PALBD5(KLON,NSW) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PALBP5(KLON,NSW) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PAPH5(KLON,KLEV+1) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PAP5(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PCCNL5(KLON) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PCCNO5(KLON) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PCCO25 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PCLFR5(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PDP5(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PEMIR5(KLON) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PEMIW5(KLON) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: POZON5(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PLSM5(KLON) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PMU05(KLON) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PQ5(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PQIWP5(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PQLWP5(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PQS5(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PTH5(KLON,KLEV+1) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PT5(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PTS5(KLON) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PFLT5(KLON,KLEV+1) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PFLS5(KLON,KLEV+1) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PFRSOD5(KLON) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PAER(KLON,6,KLEV) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PALBD(KLON,NSW) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PALBP(KLON,NSW) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PAPH(KLON,KLEV+1) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PAP(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PCCO2 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PCLFR(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PDP(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PEMIR(KLON) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PEMIW(KLON) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: POZON(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PQ(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PQIWP(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PQLWP(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PQS(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PTH(KLON,KLEV+1) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PT(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PTS(KLON) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PFLT(KLON,KLEV+1) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PFLS(KLON,KLEV+1) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PFRSOD(KLON) 
!-----------------------------------------------------------------------

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

!*       0.1   ARGUMENTS.
!              ----------
!     ==== COMPUTED IN RADLSW ===
!     -----------------------------------------------------------------

!*       0.2   LOCAL ARRAYS.
!              -------------
!     -----------------------------------------------------------------

!-- ARRAYS FOR LOCAL VARIABLES -----------------------------------------

!   1.0  Trajectory arrays 

REAL(KIND=JPRB) ::&
 & ZALBD5(KLON,NSW)    , ZALBP5(KLON,NSW)&
 & , ZCG5(KLON,NSW,KLEV) , ZOMEGA5(KLON,NSW,KLEV)&
 & , ZTAU5 (KLON,NSW,KLEV) &
 & , ZTAUCLD5(KLON,KLEV,16)    
REAL(KIND=JPRB) ::&
 & ZCLDLD5(KLON,KLEV)  , ZCLDLU5(KLON,KLEV)&
 & , ZCLDSW5(KLON,KLEV) &
 & , ZDESR5(KLON,KLEV)   , ZDT05(KLON)        &
 & , ZEMIR5(KLON)        , ZEMIW5(KLON)&
 & , ZFLUX5 (KLON,2,KLEV+1)                 , ZFLUC5(KLON,2,KLEV+1)&
 & , ZMU05(KLON)         , ZOZ5(KLON,KLEV)  , ZPMB5(KLON,KLEV+1) &
 & , ZPSOL5(KLON)&
 & , ZTAVE5 (KLON,KLEV)  , ZTL5(KLON,KLEV+1)&
 & , ZVIEW5(KLON)  
REAL(KIND=JPRB) ::&
 & ZFCDWN5(KLON,KLEV+1), ZFCUP5(KLON,KLEV+1)&
 & , ZFSDWN5(KLON,KLEV+1), ZFSUP5(KLON,KLEV+1)
REAL(KIND=JPRB) :: ZEMIT5(KLON)
REAL(KIND=JPRB) :: ZFACT5(KLON)
!cc           , ZRADRD5(KLON)

!   2.0 Perturbation arrays

REAL(KIND=JPRB) ::&
 & ZALBD(KLON,NSW)    , ZALBP(KLON,NSW)&
 & , ZCG(KLON,NSW,KLEV) , ZOMEGA(KLON,NSW,KLEV)&
 & , ZTAU (KLON,NSW,KLEV) &
 & , ZTAUCLD(KLON,KLEV,16)   
REAL(KIND=JPRB) ::&
 & ZCLDLD(KLON,KLEV)  , ZCLDLU(KLON,KLEV)&
 & , ZCLDSW(KLON,KLEV) &
 & , ZDT0(KLON)        &
 & , ZEMIR(KLON)        , ZEMIW(KLON)&
 & , ZFLUX (KLON,2,KLEV+1)                 , ZFLUC(KLON,2,KLEV+1)&
 & , ZFIWP(KLON)        , ZFLWP(KLON)      , ZFRWP(KLON)&
 & , ZIWC(KLON)         , ZLWC(KLON)&
 !cc            , ZRWC(KLON)
 & , ZMU0(KLON)         , ZOZ(KLON,KLEV)   , ZOZN(KLON,KLEV)&
 & , ZPMB(KLON,KLEV+1)  , ZPSOL(KLON)&
 & , ZTAVE (KLON,KLEV)  , ZTL(KLON,KLEV+1)&
 & , ZVIEW(KLON)  
REAL(KIND=JPRB) ::&
 & ZFCDWN(KLON,KLEV+1), ZFCUP(KLON,KLEV+1)&
 & , ZFSDWN(KLON,KLEV+1), ZFSUP(KLON,KLEV+1)
REAL(KIND=JPRB) ::&
 & ZALFICE(KLON)      , ZGAMICE(KLON)     , ZBICE(KLON)&
 & , ZRADIP(KLON)       , ZRADLP(KLON)      , ZRES(KLON)&
 !cc           , ZRADRD(KLON)
 & , ZTICE(KLON)        , ZEMIT(KLON)       , ZDESR(KLON)  
REAL(KIND=JPRB) :: ZCLFR(KLON,KLEV)
REAL(KIND=JPRB) :: ZBICFU(KLON), ZKICFU(KLON)

!     ==== EXTRA STORAGE FOR TRAJECTORY ===
!*
!          new arrays

REAL(KIND=JPRB) :: &
 &   ZLWGKG5(KLON,KLEV), ZIWGKG5(KLON,KLEV)&
 & , ZRWGKG5(KLON,KLEV), ZLWGKG15(KLON,KLEV),ZIWGKG15(KLON,KLEV)&
 & , ZTEMPC5(KLON,KLEV), ZRADIP15(KLON,KLEV)&
 & , ZGAMICE15(KLON,KLEV), ZALFICE15(KLON,KLEV)&
 & , ZMULTL5(KLON,KLEV), ZMSALD5(KLON,KLEV), ZMSALU5(KLON,KLEV)&
 & , ZMSAID5(KLON,KLEV), ZMSAIU5(KLON,KLEV), ZZFLWP5(KLON,KLEV)&
 & , ZZFIWP5(KLON,KLEV), ZRSALD5(KLON,KLEV,16), ZRSAID5(KLON,KLEV,16)  
REAL(KIND=JPRB) :: ZRAINT5(KLON,KLEV), ZDPOG5(KLON,KLEV), ZPODT5(KLON,KLEV)&
 & , ZNUM5(KLON,KLEV), ZRADLP15(KLON,KLEV), Z1RADI5(KLON,KLEV)&
 & , ZRATIO5(KLON,KLEV), ZMABSD5(KLON,KLEV,16)   
REAL(KIND=JPRB) :: ZTOL5(KLON,NSW,KLEV)   , ZGL5(KLON,NSW,KLEV)&
 & , ZOL5(KLON,NSW,KLEV)    , ZTOI5(KLON,NSW,KLEV)&
 & , ZGI5(KLON,NSW,KLEV)    , ZGI15(KLON,NSW,KLEV)&
 & , ZOI5(KLON,NSW,KLEV)&
 & , ZTOR5(KLON,NSW,KLEV)   , ZGR5(KLON,NSW,KLEV)&
 & , ZOR5(KLON,NSW,KLEV)    , ZTAUMX5(KLON,NSW,KLEV)&
 & , ZOMGMX5(KLON,NSW,KLEV) , ZASYMX5(KLON,NSW,KLEV)&
 & , ZOMGMX15(KLON,NSW,KLEV), ZASYMX15(KLON,NSW,KLEV)   
REAL(KIND=JPRB) :: ZBETAI5(KLON,NSW,KLEV),  ZOMGP5(KLON,NSW,KLEV)&
 & , ZFDEL5(KLON,NSW,KLEV)  
REAL(KIND=JPRB) :: ZTAUD5(KLON,KLEV,16) 
   
REAL(KIND=JPRB) :: ZDESR15(KLON,KLEV), ZMULTI5(KLON,KLEV), Z1RADL5(KLON,KLEV)
REAL(KIND=JPRB) :: ZADDPLK5(KLON,KLEV,16), ZPLANCK5(KLON,KLEV,16)

!          arrays with changed dimensions

REAL(KIND=JPRB) :: ZFLWP5(KLON,KLEV) , ZFIWP5(KLON,KLEV)&
 & , ZFRWP5(KLON,KLEV)  , ZLWC5(KLON,KLEV)  &
 & , ZIWC5(KLON,KLEV)   , ZRADLP5(KLON,KLEV)&
 & , ZRADIP5(KLON,KLEV) , ZTICE5(KLON,KLEV) &
 & , ZALFICE5(KLON,KLEV), ZGAMICE5(KLON,KLEV)&
 & , ZBICE5(KLON,KLEV)  , ZRES5(KLON,KLEV) &
 & , ZTCELS5(KLON,KLEV) , ZFSR5(KLON,KLEV) &
 & , ZAIWC5(KLON,KLEV)  , ZBIWC5(KLON,KLEV) &
 & , ZTBLAY5(KLON,KLEV)
REAL(KIND=JPRB) :: ZBICFU5(KLON,KLEV), ZDIFFD5(KLON,KLEV,16) &
 & , ZKICFU5(KLON,KLEV), ZKICFU15(KLON,KLEV), ZOMGI5(KLON,NSW,KLEV) &
 & , ZEXTCF5(KLON,KLEV,16), Z1MOMG5(KLON,KLEV,16)
REAL(KIND=JPRB) :: ZEXPRS5(KLON,KLEV,16)
REAL(KIND=JPRB) :: ZRSAIE5(KLON,KLEV,16), ZRSAIA5(KLON,KLEV,16)
REAL(KIND=JPRB) :: ZRSAIG5(KLON,KLEV,16), ZRSAIF5(KLON,KLEV,16)

INTEGER(KIND=JPIM) :: IKL, INDLAY(KLON), JK, JKL, JKLP1, JKP1, JL, JNU, JSW, JRTM
INTEGER(KIND=JPIM) :: ITOPC, IUAER

REAL(KIND=JPRB) ::  ZASYMX, ZGI, ZGL, ZGR, ZINTER1,&
 & ZINTER2, ZIWGKG, ZLWGKG, ZMSAID, ZMSAIU, &
 & ZMSALD, ZMSALU, ZRSALD, ZRSAID, &
 & ZMULTL, ZOI, ZOL, ZRAINT,&
 & ZOMGMX, ZOR, ZPMBM, ZRII0, ZRMUZ, ZRWGKG, ZTAUD,&
 & ZTAUMX, ZTEMPC, ZTOI, ZTOL, ZTOR, ZZFIWP, &
 & ZZFLWP, ZDPOG, ZPODT  
REAL(KIND=JPRB) :: ZALND, ZASEA, ZD, ZDEN, ZNTOT, ZNUM, ZRATIO, Z1RADI,&
 & ZBETAI, ZOMGI, ZOMGP, ZFDEL, Z1RADL, ZMULTI  
REAL(KIND=JPRB) :: ZAIWC , ZBIWC , ZFSR , ZTCELS
REAL(KIND=JPRB) :: ZDefRe, ZRefDe
REAL(KIND=JPRB) :: ZEXPRS, ZDIFFD
REAL(KIND=JPRB) :: ZRSAIE , ZRSAIA , ZRSAIG , ZRSAIF

REAL(KIND=JPRB) :: ZTBLAY, ZPLANCK, ZEXTCF, Z1MOMG, ZMABSD

REAL(KIND=JPRB) :: ZCOND5(KLON,KLEV)
INTEGER(KIND=JPIM) :: ILEV(KLON),ILEVR
INTEGER(KIND=JPIM) :: ISTEP

REAL(KIND=JPRB) :: ZHOOK_HANDLE

#include "abor1.intfb.h"
#include "lwpad.intfb.h"
#include "lwad.intfb.h"
#include "swad.intfb.h"

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

!*         1.     SET-UP INPUT QUANTITIES FOR RADIATION
!                 -------------------------------------

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

ZRefDe = RRe2De
ZDefRe = 1.0_JPRB / ZRefDe
ZRII0 = 0.0_JPRB

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

!                 ----- TRAJECTORY COMPUTATIONS ------

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

DO JL = KIDIA,KFDIA
  ZFCUP5(JL,KLEV+1) = 0.0_JPRB
  ZFCDWN5(JL,KLEV+1) = REPLOG
  ZFSUP5(JL,KLEV+1) = 0.0_JPRB
  ZFSDWN5(JL,KLEV+1) = REPLOG
  ZFLUX5(JL,1,KLEV+1) = 0.0_JPRB
  ZFLUX5(JL,2,KLEV+1) = 0.0_JPRB
  ZFLUC5(JL,1,KLEV+1) = 0.0_JPRB
  ZFLUC5(JL,2,KLEV+1) = 0.0_JPRB
  ZPSOL5(JL) = PAPH5(JL,KLEV+1)
  ZPMB5(JL,1) = ZPSOL5(JL) / 100.0_JPRB
  ZDT05(JL) = PTS5(JL) - PTH5(JL,KLEV+1)
ENDDO

!*         1.1    INITIALIZE VARIOUS FIELDS
!                 -------------------------

DO JSW=1,NSW
  DO JL = KIDIA,KFDIA
    ZALBD5(JL,JSW)=PALBD5(JL,JSW)
    ZALBP5(JL,JSW)=PALBP5(JL,JSW)
  ENDDO
ENDDO
DO JL = KIDIA,KFDIA
  ZEMIR5(JL)  =PEMIR5(JL)
  ZEMIW5(JL)  =PEMIW5(JL)
  ZMU05(JL)   =PMU05(JL)
ENDDO

DO JK = 1 , KLEV
  JKP1 = JK + 1
  JKL = KLEV+ 1 - JK
  JKLP1 = JKL + 1
  DO JL = KIDIA,KFDIA
    ZPMB5(JL,JK+1)=PAPH5(JL,JKL)/100.0_JPRB
!-- ZOZ in cm.atm for SW scheme
    ZOZ5(JL,JK)   = POZON5(JL,JKL) * 46.6968_JPRB / RG

    ZFCUP5(JL,JK) = 0.0_JPRB
    ZFCDWN5(JL,JK) = 0.0_JPRB
    ZFSUP5(JL,JK) = 0.0_JPRB
    ZFSDWN5(JL,JK) = 0.0_JPRB
    ZFLUX5(JL,1,JK) = 0.0_JPRB
    ZFLUX5(JL,2,JK) = 0.0_JPRB
    ZFLUC5(JL,1,JK) = 0.0_JPRB
    ZFLUC5(JL,2,JK) = 0.0_JPRB
  ENDDO
ENDDO

DO JK=1,KLEV
  JKL=KLEV+1-JK
  JKLP1=JKL+1
  DO JL=KIDIA,KFDIA
    ZTL5(JL,JK)=PTH5(JL,JKLP1)
    ZTAVE5(JL,JK)=PT5(JL,JKL)
  ENDDO
ENDDO
DO JL=KIDIA,KFDIA
  ZTL5(JL,KLEV+1)= PTH5(JL,1)
  ZPMB5(JL,KLEV+1) = PAPH5(JL,1)/100.0_JPRB
ENDDO
!***

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

!*         2.     CLOUD AND AEROSOL PARAMETERS
!                 ----------------------------

ZBICFU5(:,:) = 0.0_JPRB
ZKICFU5(:,:) = 0.0_JPRB
ZKICFU15(:,:)   = 0.0_JPRB
ZPLANCK5(:,:,:) = 0.0_JPRB
ZADDPLK5(:,:,:) = 0.0_JPRB

DO JK = 1 , KLEV
  IKL = KLEV + 1 - JK

!          2.1    INITIALIZE OPTICAL PROPERTIES TO CLEAR SKY VALUES
!                 -------------------------------------------------

  DO JSW = 1,NSW
    DO JL = KIDIA,KFDIA
      ZTAU5(JL,JSW,JK)  = 0.0_JPRB
      ZOMEGA5(JL,JSW,JK)= 1.0_JPRB
      ZCG5(JL,JSW,JK)   = 0.0_JPRB
    ENDDO
  ENDDO
  DO JL = KIDIA,KFDIA
    ZCLDSW5(JL,JK)  = 0.0_JPRB
    ZCLDLD5(JL,JK)  = 0.0_JPRB
    ZCLDLU5(JL,JK)  = 0.0_JPRB
  ENDDO

!          2.2    CLOUD ICE AND LIQUID CONTENT AND PATH
!                 -------------------------------------

  DO JL = KIDIA,KFDIA

! --- LIQUID WATER CONTENT (g.m-3) AND LIQUID WATER PATH (g.m-2)
    IF (PCLFR5(JL,IKL) > REPSC ) THEN
    
      IF (PQLWP5(JL,IKL)*1000.0_JPRB  >= 0.0_JPRB) THEN
        ZLWGKG15(JL,JK)= PQLWP5(JL,IKL)*1000.0_JPRB
      ELSE
        ZLWGKG15(JL,JK)= 0.0_JPRB
      ENDIF
      IF (PQIWP5(JL,IKL)*1000.0_JPRB  >= 0.0_JPRB) THEN
        ZIWGKG15(JL,JK)= PQIWP5(JL,IKL)*1000.0_JPRB
      ELSE
        ZIWGKG15(JL,JK)= 0.0_JPRB
      ENDIF
          
      ZLWGKG5(JL,JK)=ZLWGKG15(JL,JK)/PCLFR5(JL,IKL)
      ZIWGKG5(JL,JK)=ZIWGKG15(JL,JK)/PCLFR5(JL,IKL)
    ELSE
      ZLWGKG5(JL,JK)=0.0_JPRB
      ZIWGKG5(JL,JK)=0.0_JPRB
    ENDIF
    ZRWGKG5(JL,JK)=0.0_JPRB
    ZRAINT5(JL,JK)=0.0_JPRB
    
! --- RAIN LIQUID WATER CONTENT (g.m-3) AND LIQUID WATER PATH (g.m-2)
!      IF (PRAINT5(JL,IKL) <= REPSCW ) THEN
!         ZRWGKG5=MAX(PQRAIN5(JL,IKL)*1000., 0.0)
!         ZRAINT5(JL)=PRAINT5(JL,IKL)*3600.*1000.
!- no radiative effect of rain (for the moment)
!         ZRWGKG5=0.
!         ZRAINT5(JL)=0.
! ===========================================================

! Modifications Martin et al.
!      ELSE
!      ENDIF

    ZDPOG5(JL,IKL) = PDP5(JL,IKL)/RG
    ZFLWP5(JL,JK)=ZLWGKG5(JL,JK)*ZDPOG5(JL,IKL)
    ZFIWP5(JL,JK)=ZIWGKG5(JL,JK)*ZDPOG5(JL,IKL)
    ZFRWP5(JL,JK)=ZRWGKG5(JL,JK)*ZDPOG5(JL,IKL)
    ZPODT5(JL,IKL) = PAP5(JL,IKL)/(RD*PT5(JL,IKL))
    ZLWC5(JL,JK)=ZLWGKG5(JL,JK)*ZPODT5(JL,IKL)
    ZIWC5(JL,JK)=ZIWGKG5(JL,JK)*ZPODT5(JL,IKL)
  ENDDO
  
  DO JL = KIDIA,KFDIA

! --- EFFECTIVE RADIUS FOR WATER AND ICE PARTICLES

    IF (NRADLP == 0) THEN
!-- very old parametrization as f(pressure) ERA-15
      ZRADLP15(JL,JK)=10.0_JPRB + (100000.0_JPRB-PAP5(JL,IKL))*3.5_JPRB
      ZRADLP5 (JL,JK) = ZRADLP15(JL,JK)

    ELSEIF (NRADLP == 1) THEN
! simple distinction between land (10) and ocean (13) Zhang and Rossow
      IF (PLSM5(JL) < 0.5_JPRB) THEN
        ZRADLP15(JL,JK)=13.0_JPRB
      ELSE
        ZRADLP15(JL,JK)=10.0_JPRB
      ENDIF
      ZRADLP5 (JL,JK) = ZRADLP15(JL,JK)
      
    ELSEIF (NRADLP == 2) THEN
!--  based on Martin et al., 1994, JAS
      IF (PLSM5(JL) < 0.5_JPRB) THEN
        IF (LCCNO) THEN
          ZASEA=PCCNO5(JL)
        ELSE  
          ZASEA=RCCNSEA
        ENDIF  
        ZD=0.33_JPRB
        ZNTOT=-1.15E-03_JPRB*ZASEA*ZASEA+0.963_JPRB*ZASEA+5.30_JPRB
      ELSE
        IF (LCCNL) THEN 
          ZALND=PCCNL5(JL)
        ELSE  
          ZALND=RCCNLND
        ENDIF  
        ZD=0.43_JPRB
        ZNTOT=-2.10E-04_JPRB*ZALND*ZALND+0.568_JPRB*ZALND-27.9_JPRB
      ENDIF
      
      ZDEN=4.0_JPRB*RPI*ZNTOT*(1.0_JPRB+ZD*ZD)**3
      ZNUM5(JL,JK) = 3.0_JPRB*ZLWC5(JL,JK) &
       & *(1.0_JPRB+3.0_JPRB*ZD*ZD)**2  
      IF ((ZNUM5(JL,JK)/ZDEN) > REPLOG) THEN
        ZRADLP15(JL,JK) = 100.0_JPRB*EXP(0.333_JPRB*LOG(ZNUM5(JL,JK)/ZDEN)) 
        ZRADLP5 (JL,JK) = ZRADLP15(JL,JK)
        IF (ZRADLP15(JL,JK) < 4.0_JPRB) THEN
          ZRADLP5 (JL,JK) = 4.0_JPRB
        ENDIF
        IF (ZRADLP15(JL,JK) > 16.0_JPRB) THEN
          ZRADLP5 (JL,JK) = 16.0_JPRB
        ENDIF
      ELSE
        ZRADLP5 (JL,JK) = 4.0_JPRB
      ENDIF
    ENDIF

! ===========================================================
! ___________________________________________________________

! rain drop from          : unused as ZRAINT is 0.
!      ZRADRD5(JL)=500.0_JPRB*ZRAINT5(JL)**0.22_JPRB
!      IF (ZFLWP5(JL).GT.0.) THEN
!         ZRADRD5(JL)=ZRADLP5(JL)+ZRADRD5(JL)
!      ENDIF   

  ENDDO
  DO JL = KIDIA,KFDIA
  
! diagnosing the ice particle effective radius/diameter

!- ice particle effective radius =f(T) from Liou and Ou (1994)
    IF (PT5(JL,IKL) < RTICE) THEN
      ZTEMPC5(JL,JK)=PT5(JL,IKL)-RTT
    ELSE
      ZTEMPC5(JL,JK)=RTICE-RTT
    ENDIF

    ZRADIP15(JL,JK)=326.3_JPRB+ZTEMPC5(JL,JK)&
     & *(12.42_JPRB + ZTEMPC5(JL,JK)*(   0.197_JPRB + &
     & ZTEMPC5(JL,JK)*0.0012_JPRB))  
    ZRADIP5(JL,JK)=ZRADIP15(JL,JK)
    
    IF (NRADIP == 0) THEN
!-- fixed 40 micron effective radius
      ZRADIP5(JL,JK)= 40.0_JPRB
      ZDESR5(JL,JK) = ZDefRe * ZRADIP5(JL,JK)
      
    ELSEIF (NRADIP == 1) THEN 
!-- old formulation based on Liou & Ou (1994) temperature (40-130microns)    
      IF (ZRADIP5(JL,JK) < 40.0_JPRB) THEN
        ZRADIP5(JL,JK)=40.0_JPRB
      ENDIF
      ZDESR5(JL,JK) = ZDefRe * ZRADIP5(JL,JK)
      
    ELSEIF (NRADIP == 2) THEN  
!-- formulation following Jakob, Klein modifications to ice content    
      IF (ZRADIP5(JL,JK) < 30.0_JPRB) THEN
        ZRADIP5(JL,JK)=30.0_JPRB
      ENDIF
      IF (ZRADIP5(JL,JK) > 60.0_JPRB) THEN
        ZRADIP5(JL,JK)=60.0_JPRB
      ENDIF
      ZDESR5(JL,JK) = ZDefRe * ZRADIP5(JL,JK)
      
    ELSEIF (NRADIP == 3 ) THEN
      IF ( ZIWC5(JL,JK) > 0.0_JPRB ) THEN
!- ice particle effective radius =f(T,IWC) from Sun and Rikus (1999)
! revised by Sun (2001)
        ZTEMPC5(JL,JK) = PT5(JL,IKL)-83.15_JPRB
        ZTCELS5(JL,JK) = PT5(JL,IKL)-RTT
        ZFSR5(JL,JK) = 1.2351_JPRB +0.0105_JPRB * ZTCELS5(JL,JK)
! Sun, 2001
        ZAIWC5(JL,JK) = 45.8966_JPRB * ZIWC5(JL,JK)**0.2214_JPRB
        ZBIWC5(JL,JK) = 0.7957_JPRB * ZIWC5(JL,JK)**0.2535_JPRB
        ZDESR5(JL,JK) = ZFSR5(JL,JK)* &
         & (ZAIWC5(JL,JK)+ZBIWC5(JL,JK)*ZTEMPC5(JL,JK))  
        ZDESR15(JL,JK) = ZDESR5(JL,JK)
        IF (ZDESR5(JL,JK) < 30.0_JPRB) THEN
          ZDESR5(JL,JK) = 30.0_JPRB
        ENDIF
        IF (ZDESR5(JL,JK) > 155.0_JPRB) THEN
          ZDESR5(JL,JK) = 155.0_JPRB
        ENDIF
        ZRADIP5(JL,JK)= ZRefDe * ZDESR5(JL,JK)
      
      ELSE
        ZDESR5(JL,JK) = 80.0_JPRB
        ZRADIP5(JL,JK)= ZRefDe * ZDESR5(JL,JK)
      ENDIF
    ENDIF 
  ENDDO

!          2.3    CLOUD SHORTWAVE OPTICAL PROPERTIES
!                 ----------------------------------

!   -------------------------
! --+ SW OPTICAL PARAMETERS +  Water clouds after Fouquart (1987)
!   -------------------------  Ice clouds (Ebert, Curry, 1992)

  IF (LERADSW2) THEN
    DO JSW=1,NSW
      DO JL = KIDIA,KFDIA
        ZTOL5(JL,JSW,JK)=0.0_JPRB
        ZGL5(JL,JSW,JK) =0.0_JPRB
        ZOL5 (JL,JSW,JK)=0.0_JPRB
        ZTOI5(JL,JSW,JK)=0.0_JPRB
        ZGI5(JL,JSW,JK) =0.0_JPRB
        ZOI5(JL,JSW,JK) =0.0_JPRB
        ZTOR5(JL,JSW,JK)=0.0_JPRB
        ZGR5(JL,JSW,JK) =0.0_JPRB
        ZOR5(JL,JSW,JK) =0.0_JPRB
        IF (ZFLWP5(JL,JK)+ZFIWP5(JL,JK)+ZFRWP5(JL,JK)  >= REPSCW) THEN
          IF (ZFLWP5(JL,JK)  >=  REPSCW) THEN
            IF (NLIQOPT /= 0 ) THEN
!-- SW: Slingo, 1989
              ZTOL5(JL,JSW,JK)= ZFLWP5(JL,JK)&
               & *(RASWCA(JSW)+RASWCB(JSW)/ZRADLP5(JL,JK))  
              ZGL5(JL,JSW,JK)=RASWCE(JSW)+RASWCF(JSW)*ZRADLP5(JL,JK)
              ZOL5(JL,JSW,JK)=1.0_JPRB-RASWCC(JSW)-RASWCD(JSW)*ZRADLP5(JL,JK)
            ELSE
!-- SW: Fouquart, 1991
              ZTOL5(JL,JSW,JK)= ZFLWP5(JL,JK)&
               & *(RYFWCA(JSW)+RYFWCB(JSW)/ZRADLP5(JL,JK))  
              ZGL5(JL,JSW,JK)=RYFWCF(JSW)
              ZOL5(JL,JSW,JK)=RYFWCC(JSW)-RYFWCD(JSW)&
               & *EXP(-RYFWCE(JSW)*ZTOL5(JL,JSW,JK))  
            ENDIF
          ENDIF

          IF (ZFIWP5(JL,JK)  >=  REPSCW) THEN
            IF (NICEOPT <= 1) THEN
!-- SW: Ebert-Curry
              ZTOI5(JL,JSW,JK)= ZFIWP5(JL,JK)&
               & *(REBCUA(JSW)+REBCUB(JSW)/ZRADIP5(JL,JK))  
              ZGI5(JL,JSW,JK)=REBCUE(JSW)+REBCUF(JSW)*ZRADIP5(JL,JK)
! modification to avoid noise in TL/AD
              IF (JSW == 4) THEN
                ZOI5(JL,JSW,JK)=1.0_JPRB - REBCUC(JSW)/10.0_JPRB&
                 & -REBCUD(JSW)*ZRADIP5(JL,JK)  
              ELSE
! end modif
                ZOI5(JL,JSW,JK)=1.0_JPRB - REBCUC(JSW)&
                 & -REBCUD(JSW)*ZRADIP5(JL,JK)  
              ENDIF
            
            ELSEIF (NICEOPT == 2) THEN  
!-- SW: Fu-Liou 1993
              Z1RADI5(JL,JK)= 1.0_JPRB/ZDESR5(JL,JK)      
              ZBETAI5(JL,JSW,JK)=RFLAA0(JSW)+Z1RADI5(JL,JK)&
               & * RFLAA1(JSW)  
              ZTOI5(JL,JSW,JK)= ZFIWP5(JL,JK) * ZBETAI5(JL,JSW,JK)  
              ZOI5(JL,JSW,JK)=1.0_JPRB &
               & -(RFLBB0(JSW)+ZRADIP5(JL,JK)&
               & *(RFLBB1(JSW)+ZRADIP5(JL,JK)&
               & *(RFLBB2(JSW)+ZRADIP5(JL,JK)* RFLBB3(JSW) )))  
              ZOMGP5(JL,JSW,JK)=RFLCC0(JSW)+ZRADIP5(JL,JK)&
               & *(RFLCC1(JSW)+ZRADIP5(JL,JK)&
               & *(RFLCC2(JSW)+ZRADIP5(JL,JK)* RFLCC3(JSW) ))  
              ZFDEL5(JL,JSW,JK)=RFLDD0(JSW)+ZRADIP5(JL,JK)&
               & *(RFLDD1(JSW)+ZRADIP5(JL,JK)&
               & *(RFLDD2(JSW)+ZRADIP5(JL,JK)* RFLDD3(JSW) ))  
              ZGI5(JL,JSW,JK)=((1.0_JPRB-ZFDEL5(JL,JSW,JK))&
               & *ZOMGP5(JL,JSW,JK) + ZFDEL5(JL,JSW,JK)&
               & *3.0_JPRB)/3.0_JPRB  
            
            ELSEIF (NICEOPT == 3) THEN  
!-- SW: Fu 1996
              Z1RADI5(JL,JK) = 1.0_JPRB / ZDESR5(JL,JK)
              ZBETAI5(JL,JSW,JK)=RFUAA0(JSW)+Z1RADI5(JL,JK)* RFUAA1(JSW)
              ZTOI5(JL,JSW,JK) = ZFIWP5(JL,JK)*ZBETAI5(JL,JSW,JK)
              ZOMGI5(JL,JSW,JK)= RFUBB0(JSW) &
                &   +ZDESR5(JL,JK)*(RFUBB1(JSW) + ZDESR5(JL,JK) &
                &   *(RFUBB2(JSW)+ZDESR5(JL,JK)* RFUBB3(JSW) ))            
              ZOI5(JL,JSW,JK) = 1.0_JPRB - ZOMGI5(JL,JSW,JK)
              ZGI15(JL,JSW,JK) = RFUCC0(JSW) &
               &   +ZDESR5(JL,JK)*(RFUCC1(JSW) + ZDESR5(JL,JK) &
               &   *(RFUCC2(JSW)+ZDESR5(JL,JK)* RFUCC3(JSW) )) 
              ZGI5(JL,JSW,JK) = MIN(1.0_JPRB, ZGI15(JL,JSW,JK))
            ENDIF
          ENDIF

!  - MIX of WATER and ICE CLOUDS
          ZTAUMX5(JL,JSW,JK)=ZTOL5(JL,JSW,JK)+ZTOI5(JL,JSW,JK)+ZTOR5(JL,JSW,JK)
          ZOMGMX15(JL,JSW,JK)=ZTOL5(JL,JSW,JK)*ZOL5(JL,JSW,JK)&
           & + ZTOI5(JL,JSW,JK)*ZOI5(JL,JSW,JK) &
           & + ZTOR5(JL,JSW,JK)*ZOR5(JL,JSW,JK)  
          ZASYMX15(JL,JSW,JK)=ZTOL5(JL,JSW,JK)*ZOL5(JL,JSW,JK)&
           & *ZGL5(JL,JSW,JK) &
           & + ZTOI5(JL,JSW,JK)*ZOI5(JL,JSW,JK)*ZGI5(JL,JSW,JK) &
           & + ZTOR5(JL,JSW,JK)*ZOR5(JL,JSW,JK)*ZGR5(JL,JSW,JK)  

          ZASYMX5(JL,JSW,JK)= ZASYMX15(JL,JSW,JK)/ZOMGMX15(JL,JSW,JK)
          ZOMGMX5(JL,JSW,JK)= ZOMGMX15(JL,JSW,JK)/ZTAUMX5(JL,JSW,JK)

! --- SW FINAL CLOUD OPTICAL PARAMETERS

          ZCLDSW5(JL,JK)  = PCLFR5(JL,IKL)
          ZTAU5(JL,JSW,JK)  = ZTAUMX5(JL,JSW,JK)
          ZOMEGA5(JL,JSW,JK)= ZOMGMX5(JL,JSW,JK)
          ZCG5(JL,JSW,JK)   = ZASYMX5(JL,JSW,JK)
        ENDIF
      ENDDO
    ENDDO
  ENDIF

!          2.4    CLOUD LONGWAVE OPTICAL PROPERTIES FOR EC-OPE
!                 --------------------------------------------

!   -------------------------
! --+ LW OPTICAL PARAMETERS +  Water and Ice from Smith and Shi (1992)
!   -------------------------

  IF (LERADN2) THEN
    IF (.NOT.LRRTM .OR. LPHYLIN) THEN
      DO JL = KIDIA,KFDIA
        ZALFICE15(JL,JK)=0.0_JPRB
        ZGAMICE15(JL,JK)=0.0_JPRB
        ZBICE5(JL,JK)=0.0_JPRB
        ZTICE5(JL,JK)=(ZTAVE5(JL,JK)-TSTAND)/TSTAND
        IF (NICEOPT == 1) THEN
          ZBICFU5(JL,JK) = 1.0_JPRB
        ELSE
          ZBICFU5(JL,JK) = 0.0_JPRB
        ENDIF
        ZKICFU15(JL,JK) = 0.0_JPRB
      ENDDO

      DO JNU= 1,NSIL
        DO JL = KIDIA,KFDIA
          ZRES5(JL,JK)=XP(1,JNU)&
           & +ZTICE5(JL,JK)*(XP(2,JNU)+ZTICE5(JL,JK)&
           & *(XP(3,JNU)+ZTICE5(JL,JK)*(XP(4,JNU)+ZTICE5(JL,JK)&
           & *(XP(5,JNU)+ZTICE5(JL,JK)*(XP(6,JNU))))))  
          ZBICE5(JL,JK) = ZBICE5(JL,JK)+ZRES5(JL,JK)
          ZGAMICE15(JL,JK) = ZGAMICE15(JL,JK) + REBCUI(JNU)&
           & *ZRES5(JL,JK)  
          ZALFICE15(JL,JK) = ZALFICE15(JL,JK) + REBCUJ(JNU)&
           & *ZRES5(JL,JK)  
        ENDDO
      ENDDO

      IF (NICEOPT == 2 .OR. NICEOPT == 3) THEN
!-- Fu-type parametrisations with M'91 (and Neuro-Net) LW scheme
          DO JL=KIDIA,KFDIA
            IF (PT5(JL,IKL) < 160.0_JPRB) THEN
              INDLAY(JL)=1
              ZTBLAY5(JL,JK)=PT5(JL,IKL)-160.0_JPRB
            ELSEIF (PT5(JL,IKL) < 339.0_JPRB) THEN
              INDLAY(JL)=PT5(JL,IKL)-159.0_JPRB
              INDLAY(JL)=MAX(INDLAY(JL),1)
              ZTBLAY5(JL,JK)=PT5(JL,IKL)-INT(PT5(JL,IKL))
            ELSE
              INDLAY(JL)=180
              ZTBLAY5(JL,JK)=PT5(JL,IKL)-339.0_JPRB
            ENDIF
          ENDDO
        DO JRTM=1,16
          DO JL=KIDIA,KFDIA
            ZADDPLK5(JL,JK,JRTM) = TOTPLNK(INDLAY(JL)+1,JRTM)-TOTPLNK(INDLAY(JL),JRTM)
            ZPLANCK5(JL,JK,JRTM)= DELWAVE(JRTM) &
             & * (TOTPLNK(INDLAY(JL),JRTM) + ZTBLAY5(JL,JK)*ZADDPLK5(JL,JK,JRTM))
            ZBICFU5(JL,JK)=ZBICFU5(JL,JK) + ZPLANCK5(JL,JK,JRTM)

            IF (ZIWC5(JL,JK) > 0.0_JPRB ) THEN
              ZRATIO5(JL,JK)= 1.0_JPRB /  ZDESR5(JL,JK)
              IF (NICEOPT == 2) THEN
! ice cloud spectral emissivity a la Fu & Liou (1993)
                ZMABSD5(JL,JK,JRTM) = RFULIO(JRTM,1) + ZRATIO5(JL,JK) &
                 & * (RFULIO(JRTM,2) + ZRATIO5(JL,JK)*RFULIO(JRTM,3))

! ice cloud spectral emissivity a la Fu et al. (1998)
              ELSEIF (NICEOPT == 3) THEN 
                ZMABSD5(JL,JK,JRTM) = RFUETA(JRTM,1) + ZRATIO5(JL,JK) &
                 & * (RFUETA(JRTM,2) + ZRATIO5(JL,JK)*RFUETA(JRTM,3))
              ENDIF
              ZKICFU15(JL,JK) = ZKICFU15(JL,JK) &
               & + ZMABSD5(JL,JK,JRTM) * ZPLANCK5(JL,JK,JRTM)
            ENDIF
          ENDDO
        ENDDO
      ENDIF
      
      DO JL = KIDIA,KFDIA
        ZGAMICE5(JL,JK) = ZGAMICE15(JL,JK) / ZBICE5(JL,JK)
        ZALFICE5(JL,JK) = ZALFICE15(JL,JK) / ZBICE5(JL,JK)
        ZKICFU5(JL,JK)  = ZKICFU15(JL,JK) / ZBICFU5(JL,JK)

        IF (ZFLWP5(JL,JK)+ZFIWP5(JL,JK) >= REPSCW) THEN

          IF (NLIQOPT == 0) THEN
! water cloud emissivity a la Smith-Shi
            ZMULTL5(JL,JK)=1.2_JPRB-0.006_JPRB*ZRADLP5(JL,JK)
            ZMSALD5(JL,JK)= 0.158_JPRB*ZMULTL5(JL,JK)
            ZMSALU5(JL,JK)= 0.130_JPRB*ZMULTL5(JL,JK)
          ELSE
! water cloud emissivity a la Savijarvi (1997)
            ZMSALU5(JL,JK)= 0.2441_JPRB-0.0105_JPRB*ZRADLP5(JL,JK)
            ZMSALD5(JL,JK)= 1.2154_JPRB*ZMSALU5(JL,JK)
          ENDIF

          IF (NICEOPT == 0) THEN
! ice cloud emissivity a la Smith & Shi (1992)
            ZMULTI5(JL,JK)=1.2_JPRB-0.006_JPRB*ZRADIP5(JL,JK)
            ZMSAID5(JL,JK)= 0.113_JPRB*ZMULTI5(JL,JK)
            ZMSAIU5(JL,JK)= 0.093_JPRB*ZMULTI5(JL,JK)

          ELSEIF (NICEOPT == 1) THEN
! ice cloud emissivity a la Ebert-Curry
            ZMSAID5(JL,JK)= 1.66_JPRB*(ZALFICE5(JL,JK)&
             & +ZGAMICE5(JL,JK)/ZRADIP5(JL,JK))  
            ZMSAIU5(JL,JK)= ZMSAID5(JL,JK)

          ELSEIF (NICEOPT == 2 .OR. NICEOPT == 3) THEN   
            ZMSAID5(JL,JK) = 1.66_JPRB * ZKICFU5(JL,JK) 
            ZMSAIU5(JL,JK) = ZMSAID5(JL,JK)
          ENDIF

          IF (NINHOM == 1) THEN
            ZZFLWP5(JL,JK)= ZFLWP5(JL,JK) * RLWINHF
            ZZFIWP5(JL,JK)= ZFIWP5(JL,JK) * RLWINHF
          ELSEIF (NINHOM == 0) THEN
            ZZFLWP5(JL,JK)= ZFLWP5(JL,JK) 
            ZZFIWP5(JL,JK)= ZFIWP5(JL,JK)
          ELSE
            CALL ABOR1('AD model cannot be used with NINHOM > 1')
          ENDIF
! effective cloudiness accounting for condensed water
          ZCLDLD5(JL,JK) = PCLFR5(JL,IKL)&
           & *(1.0_JPRB-EXP(-ZMSALD5(JL,JK)*ZZFLWP5(JL,JK)&
           & -ZMSAID5(JL,JK)*ZZFIWP5(JL,JK)))  
          ZCLDLU5(JL,JK) = PCLFR5(JL,IKL)&
           & *(1.0_JPRB-EXP(-ZMSALU5(JL,JK)*ZZFLWP5(JL,JK)&
           & -ZMSAIU5(JL,JK)*ZZFIWP5(JL,JK)))  
        ENDIF
      ENDDO

    ELSE

!          2.5    CLOUD LONGWAVE OPTICAL PROPERTIES FOR RRTM
!                 ------------------------------------------

! Actually, no need for these following computations as long as LERADN2 is true

!   -------------------------
! --+ LW OPTICAL PARAMETERS +  Water (and Ice) from Savijarvi (1998)
!   -------------------------  Ice clouds (Ebert, Curry, 1992)

! No need for a fixed diffusivity factor, accounted for spectrally below
! The detailed spectral structure does not require defining upward and
! downward effective optical properties

      DO JRTM=1,16
        DO JL = KIDIA,KFDIA
          ZTAUCLD5(JL,JK,JRTM) = 0.0_JPRB
          ZRSALD5(JL,JK,JRTM) = 0.0_JPRB
          ZRSAID5(JL,JK,JRTM) = 0.0_JPRB

          IF (ZFLWP5(JL,JK)+ZFIWP5(JL,JK) >= REPSCW) THEN

            IF (NLIQOPT == 0 .OR. NLIQOPT == 3) THEN
 ! water cloud total emissivity a la Smith and Shi (1992)
              ZMULTL5(JL,JK) = 1.2_JPRB-0.006_JPRB*ZRADLP5(JL,JK)
              ZRSALD5(JL,JK,JRTM) = 0.144_JPRB*ZMULTL5(JL,JK)/1.66_JPRB

            ELSEIF (NLIQOPT == 1) THEN                        
! water cloud spectral emissivity a la Savijarvi (1997)
              ZRSALD5(JL,JK,JRTM)= RHSAVI(JRTM,1)+ZRADLP5(JL,JK)&
               & *(RHSAVI(JRTM,2)+ZRADLP5(JL,JK)*RHSAVI(JRTM,3))  
            ELSEIF (NLIQOPT == 2) THEN
! water cloud spectral emissivity a la Lindner and Li (2000)
              Z1RADL5(JL,JK) = 1.0_JPRB / ZRADLP5(JL,JK)
              ZEXTCF5(JL,JK,JRTM) = RLILIA(JRTM,1) &
               & +ZRADLP5(JL,JK)*RLILIA(JRTM,2) &
               & + Z1RADL5(JL,JK)*(RLILIA(JRTM,3) &
               & + Z1RADL5(JL,JK)*(RLILIA(JRTM,4) &
               & + Z1RADL5(JL,JK)* RLILIA(JRTM,5) )) 
              Z1MOMG5(JL,JK,JRTM) = RLILIB(JRTM,1) &
               & + Z1RADL5(JL,JK)*RLILIB(JRTM,2) &
               & + ZRADLP5(JL,JK) * (RLILIB(JRTM,3) &
               & + ZRADLP5(JL,JK) *  RLILIB(JRTM,4) )
              ZRSALD5(JL,JK,JRTM) = Z1MOMG5(JL,JK,JRTM) * ZEXTCF5(JL,JK,JRTM)  
            ENDIF

            IF (NICEOPT == 0) THEN
! ice cloud spectral emissivity a la Smith & Shi (1992)
              ZMULTI5(JL,JK)= 1.2_JPRB-0.006_JPRB*ZRADIP5(JL,JK)
              ZRSAID5(JL,JK,JRTM)= 0.103_JPRB*ZMULTI5(JL,JK)/1.66_JPRB  
            ELSEIF (NICEOPT == 1) THEN
! ice cloud spectral emissivity a la Ebert-Curry (1992)
              ZRSAID5(JL,JK,JRTM) = REBCUH(JRTM) &
               & +REBCUG(JRTM)/ZRADIP5(JL,JK)  
            ELSEIF (NICEOPT == 2) THEN
! ice cloud spectral emissivity a la Fu & Liou (1993)
              Z1RADI5(JL,JK) = 1.0_JPRB / ZDESR5(JL,JK)
              ZRSAID5(JL,JK,JRTM) = RFULIO(JRTM,1)+Z1RADI5(JL,JK)&
               & *(RFULIO(JRTM,2)+Z1RADI5(JL,JK)*RFULIO(JRTM,3))  
            ELSEIF (NICEOPT==3) THEN
! ice cloud spectral emissivity a la Fu et al (1998)
              Z1RADI5(JL,JK) = 1.0_JPRB / ZDESR5(JL,JK)
              ZRSAIE5(JL,JK,JRTM) = RFUETA(JRTM,1) + Z1RADI5(JL,JK) &
               & *(RFUETA(JRTM,2) + Z1RADI5(JL,JK) * RFUETA(JRTM,3))
              ZRSAIA5(JL,JK,JRTM) = Z1RADI5(JL,JK)*(RFUETB(JRTM,1) &
               & +ZDESR5(JL,JK)*( RFUETB(JRTM,2) &
               & +ZDESR5(JL,JK)*( RFUETB(JRTM,3) &
               & +ZDESR5(JL,JK)*RFUETB(JRTM,4))))
              ZRSAIG5(JL,JK,JRTM) = RFUETC(JRTM,1) &
               & +ZDESR5(JL,JK)*( RFUETC(JRTM,2) &
               & +ZDESR5(JL,JK)*( RFUETC(JRTM,3) &
               & +ZDESR5(JL,JK)* RFUETC(JRTM,4)))
              ZRSAIF5(JL,JK,JRTM) = 0.5_JPRB &
               & + ZRSAIG5(JL,JK,JRTM)*( 0.3738_JPRB &
               & + ZRSAIG5(JL,JK,JRTM)*( 0.0076_JPRB &
               & + ZRSAIG5(JL,JK,JRTM)*0.1186_JPRB ) )
              ZRSAID5(JL,JK,JRTM) = ZRSAIE5(JL,JK,JRTM) &
               & - ZRSAIA5(JL,JK,JRTM)*ZRSAIF5(JL,JK,JRTM)
            ENDIF

            ZTAUD5(JL,JK,JRTM) = ZRSALD5(JL,JK,JRTM)*ZFLWP5(JL,JK)&
             & +ZRSAID5(JL,JK,JRTM)*ZFIWP5(JL,JK)  

! Diffusivity correction within clouds a la Savijarvi
            IF (LDIFFC) THEN 
              ZEXPRS5(JL,JK,JRTM) = 1.517_JPRB &
               & -0.156_JPRB*LOG(ZTAUD5(JL,JK,JRTM))
              IF (ZEXPRS5(JL,JK,JRTM) > 1.0_JPRB) THEN
                ZDIFFD5(JL,JK,JRTM) = ZEXPRS5(JL,JK,JRTM)
              ELSE
                ZDIFFD5(JL,JK,JRTM) = 1.0_JPRB
              ENDIF
              IF (ZDIFFD5(JL,JK,JRTM) >= 2.0_JPRB) THEN
                ZDIFFD5(JL,JK,JRTM) = 2.0_JPRB
              ENDIF
            ELSE
              ZDIFFD5(JL,JK,JRTM)= 1.66_JPRB
            ENDIF
            ZTAUCLD5(JL,JK,JRTM) = ZTAUD5(JL,JK,JRTM)*ZDIFFD5(JL,JK,JRTM)
          ENDIF

        ENDDO
      ENDDO

    ENDIF
  ENDIF

ENDDO

NUAER = NUA
NTRAER = NTRA

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

!*         2.6    SCALING OF OPTICAL THICKNESS
!                 ----------------------------

IF (NINHOM == 1) THEN
!-- simple scaling a la Tiedtke (1996) with RSWINHF in SW and RLWINHF in LW
DO JSW=1,NSW
  DO JK=1,KLEV
    DO JL=KIDIA,KFDIA
      ZTAU5(JL,JSW,JK) = ZTAU5(JL,JSW,JK) * RSWINHF
    ENDDO
  ENDDO
ENDDO

!-- LW scaling for EC-OPE already done  

ELSEIF (NINHOM >= 2) THEN     
  CALL ABOR1('AD model cannot be used with NINHOM > 1')
ENDIF

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

!*         2.7    DIFFUSIVITY FACTOR OR SATELLITE VIEWING ANGLE
!                 ---------------------------------------------

DO JL = KIDIA,KFDIA
  ZVIEW5(JL) = DIFF
ENDDO

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

!*         3.     CALL LONGWAVE RADIATION CODE
!                 ----------------------------

!*         3.1    FULL LONGWAVE RADIATION COMPUTATIONS
!                 ------------------------------------

! Initialization of output variables from longwave radiation
! computation

ZEMIT5(:)=0.0_JPRB
!ZFLUX5(:,:,:)=0.0_JPRB
!ZFLUC5(:,:,:)=0.0_JPRB

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

!*         4.     CALL SHORTWAVE RADIATION CODE
!                 -----------------------------

!IF (ZRMUZ.GT.0.) THEN
!  CALL SW 
!ENDIF

! Comments: since intermediatte trajectory outputs from SW and LW 
! are not needed at the level of this routine, they are only 
! computed afterwards from SWAD and LW_PAD to be used in RADINAAD
! See computation:
! 5.     FILL UP THE MODEL NET LW AND SW RADIATIVE FLUXES
! at the end of this routine

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

!                 ----- ADJOINT COMPUTATION ------

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

!*                        INITIALIZATIONS
!                         ---------------

!     arrays with the dimensions (KLON,KLEV+1)

ZPMB(:,:)=0.0_JPRB
ZFCUP(:,:)=0.0_JPRB
ZFCDWN(:,:)=0.0_JPRB
ZFSUP(:,:)=0.0_JPRB
ZFSDWN(:,:)=0.0_JPRB
ZTL(:,:)=0.0_JPRB

!     arrays with the dimensions (KLON,2,KLEV+1)

ZFLUX(:,:,:)=0.0_JPRB
ZFLUC(:,:,:)=0.0_JPRB

!     arrays with the dimensions (KLON,NSW,KLEV)

ZTAU(:,:,:)=0.0_JPRB
ZOMEGA(:,:,:)=0.0_JPRB
ZCG(:,:,:)=0.0_JPRB
 
!     arrays with the dimensions (KLON,KLEV,16)

ZTAUCLD(:,:,:)=0.0_JPRB

!     arrays with the dimensions (KLON,KLEV)

ZOZ(:,:)=0.0_JPRB
ZTAVE(:,:)=0.0_JPRB
ZCLDSW(:,:)=0.0_JPRB
ZCLDLD(:,:)=0.0_JPRB
ZCLDLU(:,:)=0.0_JPRB
ZOZN(:,:)=0.0_JPRB
ZCLFR(:,:)=0.0_JPRB

!     arrays with the dimensions (KLON,NSW)

ZALBD(:,:)=0.0_JPRB
ZALBP(:,:)=0.0_JPRB

!     arrays with the dimension (KLON)

ZPSOL(:)=0.0_JPRB
ZDT0(:)=0.0_JPRB
ZEMIR(:)=0.0_JPRB
ZEMIW(:)=0.0_JPRB
ZMU0(:)=0.0_JPRB
ZFLWP(:)=0.0_JPRB
ZFIWP(:)=0.0_JPRB
ZFRWP(:)=0.0_JPRB
ZLWC(:)=0.0_JPRB
ZIWC(:)=0.0_JPRB
ZRADLP(:)=0.0_JPRB
ZRADIP(:)=0.0_JPRB
ZALFICE(:)=0.0_JPRB
ZGAMICE(:)=0.0_JPRB
ZBICE(:)=0.0_JPRB
ZTICE(:)=0.0_JPRB
ZRES(:)=0.0_JPRB
ZVIEW(:)=0.0_JPRB
ZEMIT(:)=0.0_JPRB
ZDESR(:)=0.0_JPRB
ZBICFU(:)=0.0_JPRB
ZKICFU(:)=0.0_JPRB

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

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

!*         5.     FILL UP THE MODEL NET LW AND SW RADIATIVE FLUXES
!                 ------------------------------------------------

DO JL = KIDIA,KFDIA
  ZFSDWN(JL,1)=ZFSDWN(JL,1)+PFRSOD(JL)
  PFRSOD(JL)=0.0_JPRB
ENDDO

DO JKL = KLEV+1,1,-1
  JK = KLEV+1 + 1 - JKL
  DO JL = KIDIA,KFDIA
! diagnostic clear sky quantities
!    ZFLUC (JL,1,JK)=ZFLUC (JL,1,JK)-PFCT (JL,JKL)
!    ZFLUC (JL,2,JK)=ZFLUC (JL,2,JK)-PFCT (JL,JKL)
!    PFCT (JL,JKL)=0.0_JPRB

!    ZFCDWN (JL,JK)=ZFCDWN (JL,JK)+PFCS (JL,JKL)
!    ZFCUP (JL,JK)=ZFCUP (JL,JK)-PFCS (JL,JKL)
!    PFCS (JL,JKL)=0.0_JPRB

    ZFLUX (JL,1,JK)=ZFLUX (JL,1,JK)-PFLT (JL,JKL)
    ZFLUX (JL,2,JK)=ZFLUX (JL,2,JK)-PFLT (JL,JKL)
    PFLT (JL,JKL)=0.0_JPRB

    ZFSDWN (JL,JK)=ZFSDWN (JL,JK)+PFLS (JL,JKL)
    ZFSUP (JL,JK)=ZFSUP (JL,JK)-PFLS (JL,JKL)
    PFLS (JL,JKL)=0.0_JPRB
  ENDDO
ENDDO

DO JL = KIDIA,KFDIA
  ZFACT5(JL) = ZMU05(JL)*PRII05
ENDDO

DO JK = KLEV+1,1,-1
  DO JL = KIDIA,KFDIA
    ZFSUP  (JL,JK) = ZFSUP(JL,JK)*ZFACT5(JL)
    ZFSDWN (JL,JK) = ZFSDWN(JL,JK)*ZFACT5(JL)

! diagnostic clear sky quantities
!    ZFCUP  (JL,JK) = ZFCUP(JL,JK)*ZFACT5(JL)
!    ZFCDWN (JL,JK) = ZFCDWN(JL,JK)*ZFACT5(JL)
  ENDDO
ENDDO

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

!*         4.     CALL SHORTWAVE RADIATION CODE
!                 -----------------------------

ZRMUZ=0.0_JPRB
DO JL = KIDIA,KFDIA
  ZRMUZ = MAX (ZRMUZ, ZMU05(JL))
ENDDO

IF (ZRMUZ > 0.0_JPRB .AND. LERADSW2) THEN

  CALL SWAD &
   & ( KIDIA  , KFDIA  , KLON , KLEV   , KAER,&
   & PRII05 , PCCO25 , ZPSOL5 , ZALBD5 , ZALBP5 , PQ5   , PQS5,&
   & ZMU05  , ZCG5   , ZCLDSW5, ZOMEGA5, ZOZ5   , ZPMB5 ,&
   & ZTAU5  , ZTAVE5 , PAER5,&
   & ZFACT5 , ZFSDWN5, ZFSUP5,&
!   & ZFCDWN5, ZFCUP5,&
   & ZRII0  , PCCO2  , ZPSOL  , ZALBD  , ZALBP  , PQ    , PQS,&
   & ZMU0   , ZCG    , ZCLDSW , ZOMEGA , ZOZ    , ZPMB  ,&
   & ZTAU   , ZTAVE  , PAER,&
   & ZFSDWN , ZFSUP&
!   & ZFCDWN , ZFCUP &
   & )       
ENDIF

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

!*         3.     CALL LONGWAVE RADIATION CODE
!                 ----------------------------

!*         3.1    FULL LONGWAVE RADIATION COMPUTATIONS
!                 ------------------------------------

IF (LERADN2) THEN

  IF (LERADLW2) THEN
    ISTEP = MOD(NSTEP,NLWFR)

    IF (ISTEP == 0 .OR. NSTEP == (NSTOP-1)) THEN

!* Computation of the cloud top level up to which cloud contribution
!  is computed in lwc.F90
      IF (LWLCLHR) THEN
        DO JL = KIDIA,KFDIA
          ILEV(JL)=KLEV
        ENDDO
        DO JK = 1 , KLEV
          DO JL = KIDIA,KFDIA
            ZCOND5(JL,JK) = PQLWP5(JL,JK)+PQIWP5(JL,JK)
            IF (PCLFR5(JL,JK)>=1.E-04_JPRB &
             & .AND. ZCOND5(JL,JK)>=0.5E-08_JPRB) THEN
              ILEV(JL) = MIN(ILEV(JL),JK)
            ENDIF
          ENDDO
        ENDDO

        ILEVR=KLEV
        DO JL = KIDIA,KFDIA
          ILEVR = MAX(NLEVLWC,MIN(ILEVR,ILEV(JL)))
        ENDDO
!orig      ITOPC = KLEV-ILEVR
        ITOPC = KLEV-ILEVR+5
      ELSE
        ITOPC = KLEV
      ENDIF
!* End of the cloud top computation

!or   IF (LPHYLIN .AND. LH2OCO2) THEN
      IF (LH2OCO2) THEN
        IUAER  = 9
      ELSE
        IUAER  = NUAER
      ENDIF

      CALL LWAD &
       & ( KIDIA , KFDIA  , KLON   , KLEV   , KMODE, ITOPC,IUAER,&
       & PCCO25  , ZVIEW5 , PCLFR5 , ZCLDLD5, ZCLDLU5,&
       & PDP5    , ZDT05  , ZEMIR5 , ZEMIW5,&
       & ZPMB5   , POZON5 , ZTL5   ,&
       & PAER5   , ZTAVE5 , PQ5    ,&
       & ZEMIT5  , ZFLUX5 , ZFLUC5 ,&
!       & PCLFR   , ZCLDLD , ZCLDLU ,&
       & ZCLFR   , ZCLDLD , ZCLDLU ,&
       & PDP     , ZDT0   , ZEMIR  , ZEMIW ,&
       & ZPMB    , POZON  , ZTL    ,&
       & PAER    , ZTAVE  , PQ     ,&
       & ZEMIT   , ZFLUX  , ZFLUC  &
       & )
    ENDIF

  ELSE

    CALL LWPAD &
     & ( KIDIA , KFDIA  , KLON  , KLEV ,&
     & PCCO25, ZCLDLD5, ZCLDLU5, PCLFR5,&
     & PDP5  , ZDT05,&
     & ZPMB5 , POZON5 , ZTL5,&
     & ZTAVE5 , PQ5,&
     & ZEMIT5 , ZFLUX5, ZFLUC5,&
     !  &, PCCO2 , ZCLDLD , ZCLDLU , PCLFR &
     & ZCLDLD , ZCLDLU , ZCLFR,&
     & ZDT0   , ZPMB  , ZTL,&
     & ZTAVE  , PQ,&
     & ZEMIT  , ZFLUX , ZFLUC &
     & )

  ENDIF
ENDIF

ZFLUC (:,:,:)=0.0_JPRB
ZFLUX (:,:,:)=0.0_JPRB
ZEMIT (:)=0.0_JPRB

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

!*         2.7    DIFFUSIVITY FACTOR OR SATELLITE VIEWING ANGLE
!                 ---------------------------------------------

DO JL = KIDIA,KFDIA
  ZVIEW (JL) = 0.0_JPRB
ENDDO

!***

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

!*         2.6    SCALING OF OPTICAL THICKNESS
!                 ----------------------------

IF (NINHOM == 1) THEN
!-- simple scaling a la Tiedtke (1996) with RSWINHF in SW and RLWINHF in LW
  DO JSW=1,NSW
    DO JK=1,KLEV
      DO JL=KIDIA,KFDIA
        ZTAU(JL,JSW,JK) = ZTAU(JL,JSW,JK) * RSWINHF
      ENDDO
    ENDDO
  ENDDO
!ELSEIF (NINHOM == 0) THEN
! no weighting necessary: ZTAU is taken as is
ENDIF

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

!*         2.     CLOUD AND AEROSOL PARAMETERS
!                 ----------------------------

DO JK = KLEV, 1, -1
  IKL = KLEV + 1 - JK

!          2.4    CLOUD LONGWAVE OPTICAL PROPERTIES FOR EC-OPE 
!                 --------------------------------------------

!   -------------------------
! --+ LW OPTICAL PARAMETERS +  Water and Ice from Smith and Shi (1992)
!   -------------------------

  IF (LERADN2) THEN
    IF (.NOT.LRRTM .OR. LPHYLIN) THEN
      DO JL = KIDIA,KFDIA
        ZMSALU=0.0_JPRB
        ZZFLWP=0.0_JPRB
        ZMSAIU=0.0_JPRB
        ZZFIWP=0.0_JPRB
        ZMSALD=0.0_JPRB
        ZMSAID=0.0_JPRB
        ZMULTL=0.0_JPRB
        ZMULTI=0.0_JPRB

        IF (ZFLWP5(JL,JK)+ZFIWP5(JL,JK) >= REPSCW) THEN

! effective cloudiness accounting for condensed water 

          ZINTER1=EXP(-ZMSALU5(JL,JK)*ZZFLWP5(JL,JK)&
           & -ZMSAIU5(JL,JK)*ZZFIWP5(JL,JK))  
!          PCLFR (JL,IKL)=PCLFR (JL,IKL)+ZCLDLU (JL,JK)*(_ONE_-ZINTER1)
          ZCLFR (JL,IKL)=ZCLFR (JL,IKL)+ZCLDLU (JL,JK)*(1.0_JPRB-ZINTER1)
          ZMSALU=ZMSALU+ZCLDLU (JL,JK)*PCLFR5(JL,IKL)*ZZFLWP5(JL,JK)&
           & *ZINTER1  
          ZZFLWP=ZZFLWP+ZCLDLU (JL,JK)*PCLFR5(JL,IKL)*ZMSALU5(JL,JK)&
           & *ZINTER1  
          ZMSAIU=ZMSAIU+ZCLDLU (JL,JK)*PCLFR5(JL,IKL)*ZZFIWP5(JL,JK)&
           & *ZINTER1  
          ZZFIWP=ZZFIWP+ZCLDLU (JL,JK)*PCLFR5(JL,IKL)*ZMSAIU5(JL,JK)&
           & *ZINTER1  
          ZCLDLU (JL,JK)=0.0_JPRB

          ZINTER2=EXP(-ZMSALD5(JL,JK)*ZZFLWP5(JL,JK)&
           & -ZMSAID5(JL,JK)*ZZFIWP5(JL,JK))  
!          PCLFR (JL,IKL)=PCLFR (JL,IKL)+ZCLDLD (JL,JK)*(_ONE_-ZINTER2)
          ZCLFR (JL,IKL)=ZCLFR (JL,IKL)+ZCLDLD (JL,JK)*(1.0_JPRB-ZINTER2)
          ZMSALD=ZMSALD+ZCLDLD (JL,JK)*PCLFR5(JL,IKL)*ZZFLWP5(JL,JK)&
           & *ZINTER2  
          ZZFLWP=ZZFLWP+ZCLDLD (JL,JK)*PCLFR5(JL,IKL)*ZMSALD5(JL,JK)&
           & *ZINTER2  
          ZMSAID=ZMSAID+ZCLDLD (JL,JK)*PCLFR5(JL,IKL)*ZZFIWP5(JL,JK)&
           & *ZINTER2  
          ZZFIWP=ZZFIWP+ZCLDLD (JL,JK)*PCLFR5(JL,IKL)*ZMSAID5(JL,JK)&
           & *ZINTER2  
          ZCLDLD (JL,JK)=0.0_JPRB

! introduce inhomogeneity factor also in LW
          IF (NINHOM == 1) THEN 
            ZFIWP (JL)=ZFIWP (JL) + ZZFIWP * RLWINHF
            ZFLWP (JL)=ZFLWP (JL) + ZZFLWP * RLWINHF
          ELSEIF (NINHOM == 0) THEN
            ZFIWP (JL)=ZFIWP (JL) + ZZFIWP
            ZFLWP (JL)=ZFLWP (JL) + ZZFLWP
          ELSE
            CALL ABOR1('AD model cannot be used with NINHOM > 1')
          ENDIF

          IF (NICEOPT == 0) THEN
! ice cloud emissivity a la Smith & Shi (1992)
            ZMULTI = ZMULTI + 0.093_JPRB*ZMSAIU
            ZMULTI = ZMULTI + 0.113_JPRB*ZMSAID
            ZRADIP(JL) = ZRADIP(JL) -0.006_JPRB*ZMULTI
          ELSEIF (NICEOPT == 1) THEN
! ice cloud emissivity a la Ebert & Curry (1992)
            ZMSAID=ZMSAID+ZMSAIU

            ZALFICE (JL)=ZALFICE (JL)+1.66_JPRB*ZMSAID
            ZGAMICE (JL)=ZGAMICE (JL)+1.66_JPRB*ZMSAID/ZRADIP5(JL,JK)
            ZRADIP(JL)=ZRADIP(JL)-1.66_JPRB*ZMSAID*ZGAMICE5(JL,JK)&
             & /ZRADIP5(JL,JK)**2  
          ELSEIF (NICEOPT == 2 .OR. NICEOPT == 3) THEN
            ZMSAID = ZMSAID+ZMSAIU
            ZKICFU(JL) = ZKICFU(JL) + 1.66_JPRB*ZMSAID
          ENDIF

          IF (NLIQOPT == 0) THEN
! water cloud emissivity a la Smith-Shi
            ZMULTL=ZMULTL+0.130_JPRB*ZMSALU
            ZMULTL=ZMULTL+0.158_JPRB*ZMSALD
            ZRADLP (JL)=ZRADLP (JL)-0.006_JPRB*ZMULTL
          ELSE
! water cloud emissivity a la Savijarvi (1997)
            ZMSALU = ZMSALU + 1.2154_JPRB*ZMSALD
            ZRADLP(JL) = ZRADLP(JL) - 0.0105_JPRB*ZMSALU
          ENDIF
            
        ENDIF

        ZBICFU(JL) = ZBICFU(JL) &
         &         - ZKICFU(JL) * ZKICFU15(JL,JK)/ZBICFU5(JL,JK)**2 
        ZKICFU(JL) = ZKICFU(JL) / ZBICFU5(JL,JK)

        ZBICE (JL)=ZBICE (JL)-ZALFICE (JL)*ZALFICE15(JL,JK)&
         & /ZBICE5(JL,JK)**2  
        ZALFICE (JL)=ZALFICE (JL)/ZBICE5(JL,JK)

        ZBICE (JL)=ZBICE (JL)-ZGAMICE (JL)*ZGAMICE15(JL,JK)&
         & /ZBICE5(JL,JK)**2  
        ZGAMICE (JL)=ZGAMICE (JL)/ZBICE5(JL,JK)

      ENDDO


      IF (NICEOPT == 2 .OR. NICEOPT == 3) THEN
        DO JRTM=16,1,-1
          DO JL=KIDIA,KFDIA
            ZMABSD = 0.0_JPRB
            ZTBLAY = 0.0_JPRB
            ZPLANCK= 0.0_JPRB
            ZRATIO = 0.0_JPRB

            IF (ZIWC5(JL,JK) > 0.0_JPRB) THEN
              ZMABSD = ZMABSD + ZKICFU(JL) * ZPLANCK5(JL,JK,JRTM)
              ZPLANCK=ZPLANCK + ZKICFU(JL) * ZMABSD5(JL,JK,JRTM)

              IF (NICEOPT == 2) THEN
                ZRATIO = ZRATIO + ZMABSD * (RFULIO(JRTM,2) &
                 &     + 2.0_JPRB*ZRATIO5(JL,JK)*RFULIO(JRTM,3))
              ELSEIF (NICEOPT == 3) THEN
                ZRATIO = ZRATIO + ZMABSD * (RFUETA(JRTM,2) &
                 &     + 2.0_JPRB*ZRATIO5(JL,JK)*RFUETA(JRTM,3))
              ENDIF
              ZDESR(JL) = ZDESR(JL) -ZRATIO / (ZDESR5(JL,JK)**2)
            ENDIF

            ZPLANCK = ZPLANCK + ZBICFU(JL)
            ZTBLAY = ZTBLAY + ZPLANCK * DELWAVE(JRTM) * ZADDPLK5(JL,JK,JRTM)

            PT(JL,IKL) = PT(JL,IKL) + ZTBLAY

          ENDDO
        ENDDO
      ENDIF

      DO JNU=NSIL,1,-1
        DO JL = KIDIA,KFDIA
          ZRES (JL)=ZRES (JL)+REBCUJ(JNU)*ZALFICE (JL)
          ZRES (JL)=ZRES (JL)+REBCUI(JNU)*ZGAMICE (JL)
          ZRES (JL)=ZRES (JL)+ZBICE (JL)

          ZTICE (JL)=ZTICE (JL)+ZRES (JL)&
           & *(XP(2,JNU)+ZTICE5(JL,JK)*(2.0_JPRB*XP(3,JNU)+ZTICE5(JL,JK)&
           & *(3.0_JPRB*XP(4,JNU)+ZTICE5(JL,JK)&
           & *(4.0_JPRB*XP(5,JNU)+ZTICE5(JL,JK)*(5.0_JPRB*XP(6,JNU))))))  
          ZRES (JL)=0.0_JPRB
        ENDDO
      ENDDO

      DO JL = KIDIA,KFDIA
        ZTAVE (JL,JK)=ZTAVE (JL,JK)+ZTICE (JL)/TSTAND
        ZTICE (JL)=0.0_JPRB

        ZBICE (JL)=0.0_JPRB
        ZGAMICE (JL)=0.0_JPRB
        ZALFICE (JL)=0.0_JPRB

        ZBICFU (JL) =0.0_JPRB
        ZKICFU (JL) =0.0_JPRB
      ENDDO

    ELSE

!          2.5    CLOUD LONGWAVE OPTICAL PROPERTIES FOR RRTM
!                 ------------------------------------------

!   -------------------------
! --+ LW OPTICAL PARAMETERS +  Water (and Ice) from Savijarvi (1998)
!   -------------------------  Ice clouds (Ebert, Curry, 1992)

! NOT RELEVANT FOR THE TIME BEING, as RRTM_AD does not exist

      DO JRTM=16,1,-1
        DO JL = KIDIA,KFDIA
          ZTAUD =0.0_JPRB
          ZRSALD=0.0_JPRB
          ZRSAID=0.0_JPRB
          ZMULTL=0.0_JPRB
          ZMULTI=0.0_JPRB
          Z1RADI=0.0_JPRB
          Z1RADL=0.0_JPRB
          ZEXTCF=0.0_JPRB
          Z1MOMG=0.0_JPRB
          ZEXPRS=0.0_JPRB
          ZDIFFD=0.0_JPRB
          ZRSAIE=0.0_JPRB
          ZRSAIA=0.0_JPRB
          ZRSAIG=0.0_JPRB
          ZRSAIF=0.0_JPRB

          IF (ZFLWP5(JL,JK)+ZFIWP5(JL,JK) >= REPSCW) THEN

! Diffusivity correction within clouds a la Savijarvi
            ZTAUD=ZTAUD + ZDIFFD5(JL,JK,JRTM) * ZTAUCLD(JL,JK,JRTM)
            ZDIFFD=ZDIFFD+ZTAUD5(JL,JK,JRTM)*ZTAUCLD(JL,JK,JRTM) 
            ZTAUCLD(JL,JK,JRTM)=0.0_JPRB
            IF (LDIFFC) THEN
              IF (ZDIFFD5(JL,JK,JRTM) >= 2.0_JPRB) THEN
                ZDIFFD = 0.0_JPRB
              ENDIF
              IF (ZEXPRS5(JL,JK,JRTM) > 1.0_JPRB) THEN
                ZEXPRS = ZEXPRS+ZDIFFD
              ENDIF
              ZTAUD = ZTAUD-0.156_JPRB*ZEXPRS/ZTAUD5(JL,JK,JRTM)
            ENDIF
  
            ZFLWP(JL)=ZFLWP(JL)+ZRSALD5(JL,JK,JRTM)*ZTAUD
            ZRSALD   =ZRSALD+ZFLWP5(JL,JK)*ZTAUD
            ZFIWP(JL)=ZFIWP(JL)+ZRSAID5(JL,JK,JRTM)*ZTAUD
            ZRSAID   =ZRSAID+ZFIWP5(JL,JK)*ZTAUD

            IF (NICEOPT == 0) THEN
! ice cloud spectral emissivity a la Smith & Shi (1992)
              ZMULTI = ZMULTI + 0.103_JPRB*ZRSAID/1.66_JPRB
              ZRADIP(JL) = ZRADIP(JL) - 0.006_JPRB*ZMULTI
            ELSEIF (NICEOPT == 1) THEN
! ice cloud spectral emissivity a la Ebert-Curry (1992)
              ZRADIP(JL)=ZRADIP(JL)-REBCUG(JRTM)*ZRSAID&
               & /ZRADIP5(JL,JK)**2  
            ELSEIF (NICEOPT == 2) THEN                
 ! ice cloud spectral emissivity a la Fu & Liou (1993)
              Z1RADI = Z1RADI + (RFULIO(JRTM,2) &
               &    + 2.0_JPRB*RFULIO(JRTM,3) *Z1RADI5(JK,JL))*ZRSAID  
              ZDESR(JL) = ZDESR(JL) - Z1RADI / ZDESR5(JL,JK)**2
            ELSEIF (NICEOPT==3) THEN
! ice cloud spectral emissivity a la Fu et al (1998)
              ZRSAIE = ZRSAIE+ZRSAID
              ZRSAIF = ZRSAIF-ZRSAIA5(JL,JK,JRTM)*ZRSAID
              ZRSAIA = ZRSAIA-ZRSAIF5(JL,JK,JRTM)*ZRSAID
              ZRSAIG = ZRSAIG+(0.3738_JPRB+ZRSAIG5(JL,JK,JRTM)*(2*0.0076_JPRB &
               & +3*0.1186_JPRB*ZRSAIG5(JL,JK,JRTM)))*ZRSAIF
              ZDESR(JL) = ZDESR(JL)+(RFUETC(JRTM,2) &
               & +ZDESR5(JL,JK)*(2*RFUETC(JRTM,3) &
               & +3*RFUETC(JRTM,4)*ZDESR5(JL,JK)))*ZRSAIG
              Z1RADI = Z1RADI+(RFUETB(JRTM,1)+ZDESR5(JL,JK)*( RFUETB(JRTM,2) &
               & +ZDESR5(JL,JK)*( RFUETB(JRTM,3) &
               & +ZDESR5(JL,JK)*RFUETB(JRTM,4))))*ZRSAIA
              ZDESR(JL) = ZDESR(JL)+Z1RADI5(JL,JK)*(RFUETB(JRTM,2) &
               & +ZDESR5(JL,JK)*(2*RFUETB(JRTM,3) &
               & +3*RFUETB(JRTM,4)*ZDESR5(JL,JK)))*ZRSAIA
              Z1RADI = Z1RADI+(RFUETA(JRTM,2) &
               & +2*RFUETA(JRTM,3)*Z1RADI5(JL,JK))*ZRSAIE
              ZDESR(JL) = ZDESR(JL) - Z1RADI / (ZDESR5(JL,JK)**2)
            ENDIF

            IF (NLIQOPT == 0 .OR. NLIQOPT >= 3) THEN
! water cloud total emissivity a la Smith and Shi (1992)
              ZMULTL=ZMULTL+0.144_JPRB*ZRSALD/1.66_JPRB
              ZRADLP(JL)=ZRADLP(JL)-0.006_JPRB*ZMULTL
            ELSEIF (NLIQOPT == 1) THEN 
! water cloud spectral emissivity a la Savijarvi (1997)
              ZRADLP(JL)=ZRADLP(JL)+(RHSAVI(JRTM,2)&
               & +2.0_JPRB*RHSAVI(JRTM,3)&
               & *ZRADLP5(JL,JK))*ZRSALD  
            ELSEIF (NLIQOPT == 2) THEN
! water cloud spectral emissivity a la Lindner and Li (2000)
              Z1MOMG = Z1MOMG + ZRSALD * ZEXTCF5(JL,JK,JRTM)
              ZEXTCF = ZEXTCF + ZRSALD * Z1MOMG5(JL,JK,JRTM)
              Z1RADL = Z1RADL + Z1MOMG * RLILIB(JRTM,2)
              ZRADLP(JL) = ZRADLP(JL) + Z1MOMG *(RLILIB(JRTM,3)&
               &         + 2.0_JPRB*ZRADLP5(JL,JK)*RLILIB(JRTM,4))
              ZRADLP(JL) = ZRADLP(JL) + ZEXTCF * RLILIA(JRTM,2)
              Z1RADL = Z1RADL + (RLILIA(JRTM,3) &
               & + 2.0_JPRB*RLILIA(JRTM,4)*Z1RADL5(JL,JK) &
               & + 3.0_JPRB*RLILIA(JRTM,5)*Z1RADL5(JL,JK)**2)*ZEXTCF  
              ZRADLP(JL) = ZRADLP(JL) - Z1RADL/ZRADLP5(JL,JK)**2
            ENDIF
          ENDIF

          ZRSAID = 0.0_JPRB
          ZRSALD = 0.0_JPRB
          ZTAUCLD(JL,JK,JRTM) = 0.0_JPRB

        ENDDO
      ENDDO

    ENDIF
  ENDIF

!          2.3    CLOUD SHORTWAVE OPTICAL PROPERTIES
!                 ----------------------------------

!   -------------------------
! --+ SW OPTICAL PARAMETERS +  Water clouds after Fouquart (1987)
!   -------------------------  Ice clouds (Ebert, Curry, 1992)

  IF (LERADSW2) THEN
    DO JSW=NSW,1,-1
      DO JL = KIDIA,KFDIA

        ZASYMX=0.0_JPRB
        ZOMGMX=0.0_JPRB
        ZTAUMX=0.0_JPRB
        ZGL=0.0_JPRB
        ZGI=0.0_JPRB
        ZGR=0.0_JPRB
        ZTOL=0.0_JPRB
        ZTOI=0.0_JPRB
        ZTOR=0.0_JPRB
        ZOL=0.0_JPRB
        ZOI=0.0_JPRB
        ZOR=0.0_JPRB
        Z1RADI=0.0_JPRB
        ZBETAI=0.0_JPRB
        ZOMGI=0.0_JPRB
        ZOMGP=0.0_JPRB
        ZFDEL=0.0_JPRB

        IF (ZFLWP5(JL,JK)+ZFIWP5(JL,JK)+ZFRWP5(JL,JK) >= REPSCW) THEN

! --- SW FINAL CLOUD OPTICAL PARAMETERS

          ZASYMX=ZASYMX+ZCG (JL,JSW,JK)
          ZCG (JL,JSW,JK)=0.0_JPRB

          ZOMGMX=ZOMGMX+ZOMEGA (JL,JSW,JK)
          ZOMEGA (JL,JSW,JK)=0.0_JPRB

          ZTAUMX=ZTAUMX+ZTAU (JL,JSW,JK)
          ZTAU (JL,JSW,JK)=0.0_JPRB

          PCLFR (JL,IKL)=PCLFR (JL,IKL)+ZCLDSW (JL,JK)
          ZCLDSW (JL,JK)=0.0_JPRB

!  - MIX of WATER and ICE CLOUDS

          ZTAUMX=ZTAUMX-ZOMGMX*ZOMGMX15(JL,JSW,JK)/ZTAUMX5(JL,JSW,JK)**2
          ZOMGMX=ZOMGMX/ZTAUMX5(JL,JSW,JK)

          ZOMGMX=ZOMGMX-ZASYMX*ZASYMX15(JL,JSW,JK)&
           & /ZOMGMX15(JL,JSW,JK)**2  
          ZASYMX=ZASYMX/ZOMGMX15(JL,JSW,JK)

          ZGL=ZGL+ZTOL5(JL,JSW,JK)*ZOL5(JL,JSW,JK)*ZASYMX
          ZGI=ZGI+ZTOI5(JL,JSW,JK)*ZOI5(JL,JSW,JK)*ZASYMX
          ZGR=ZGR+ZTOR5(JL,JSW,JK)*ZOR5(JL,JSW,JK)*ZASYMX
          ZTOL=ZTOL+ZOL5(JL,JSW,JK)*ZGL5(JL,JSW,JK)*ZASYMX
          ZTOI=ZTOI+ZOI5(JL,JSW,JK)*ZGI5(JL,JSW,JK)*ZASYMX
          ZTOR=ZTOR+ZOR5(JL,JSW,JK)*ZGR5(JL,JSW,JK)*ZASYMX
          ZOL=ZOL+ZTOL5(JL,JSW,JK)*ZGL5(JL,JSW,JK)*ZASYMX
          ZOI=ZOI+ZTOI5(JL,JSW,JK)*ZGI5(JL,JSW,JK)*ZASYMX
          ZOR=ZOR+ZTOR5(JL,JSW,JK)*ZGR5(JL,JSW,JK)*ZASYMX

          ZOL=ZOL+ZTOL5(JL,JSW,JK)*ZOMGMX
          ZOI=ZOI+ZTOI5(JL,JSW,JK)*ZOMGMX
          ZOR=ZOR+ZTOR5(JL,JSW,JK)*ZOMGMX
          ZTOL=ZTOL+ZOL5(JL,JSW,JK)*ZOMGMX
          ZTOI=ZTOI+ZOI5(JL,JSW,JK)*ZOMGMX
          ZTOR=ZTOR+ZOR5(JL,JSW,JK)*ZOMGMX

          ZTOL=ZTOL+ZTAUMX
          ZTOI=ZTOI+ZTAUMX
          ZTOR=ZTOR+ZTAUMX

          IF (ZFIWP5(JL,JK)  >=  REPSCW) THEN
            IF (NICEOPT <= 1) THEN
!-- SW: Ebert-Curry
              ZRADIP (JL)=ZRADIP (JL)-REBCUD(JSW)*ZOI
              ZRADIP (JL)=ZRADIP (JL)+REBCUF(JSW)*ZGI

              ZFIWP (JL)=ZFIWP (JL)+ ZTOI*(REBCUA(JSW)&
               & +REBCUB(JSW)/ZRADIP5(JL,JK))  
              ZRADIP(JL)=ZRADIP(JL)- ZTOI*ZFIWP5(JL,JK)&
               & *REBCUB(JSW)/ZRADIP5(JL,JK)**2  

            ELSEIF (NICEOPT == 2) THEN 
!-- SW: Fu-Liou
              ZFDEL=ZFDEL+(3.0_JPRB-ZOMGP5(JL,JSW,JK))*ZGI/3.0_JPRB
              ZOMGP=ZOMGP+(1.0_JPRB-ZFDEL5(JL,JSW,JK))*ZGI/3.0_JPRB

              ZRADIP(JL)=ZRADIP(JL)+(RFLDD1(JSW)+2.0_JPRB*RFLDD2(JSW)&
               & *ZRADIP5(JL,JK)&
               & +3.0_JPRB*RFLDD3(JSW)*ZRADIP5(JL,JK)**2)*ZFDEL  
            
              ZRADIP(JL)=ZRADIP(JL)+(RFLCC1(JSW)+2.0_JPRB*RFLCC2(JSW)&
               & *ZRADIP5(JL,JK)&
               & +3.0_JPRB*RFLCC3(JSW)*ZRADIP5(JL,JK)**2)*ZOMGP  

              ZOMGI=ZOMGI-ZOI
              ZRADIP(JL)=ZRADIP(JL)+(RFLBB1(JSW)+2.0_JPRB*RFLBB2(JSW)&
               & *ZRADIP5(JL,JK)&
               & +3.0_JPRB*RFLBB3(JSW)*ZRADIP5(JL,JK)**2)*ZOMGI  
    
              ZBETAI=ZBETAI+ ZFIWP5(JL,JK)*ZTOI
              ZFIWP(JL)=ZFIWP(JL)+ ZBETAI5(JL,JSW,JK)*ZTOI

              Z1RADI = Z1RADI + RFLAA1(JSW)*ZBETAI
              ZDESR(JL) = ZDESR(JL) - Z1RADI/ZDESR5(JL,JK)**2
            ELSEIF (NICEOPT==3) THEN
!-- SW: Fu 1996
              IF (ZGI15(JL,JSW,JK) > 1.0_JPRB) THEN
                ZGI = 0.0_JPRB
              ENDIF
              ZDESR(JL) = ZDESR(JL)+ZGI*(RFUCC1(JSW) &
                &       + 2.0_JPRB *ZDESR5(JL,JK)*RFUCC2(JSW) &
                &       +3.0_JPRB*ZDESR5(JL,JK)*RFUCC3(JSW)) 
              ZOMGI = ZOMGI - ZOI
              ZDESR(JL) = ZDESR(JL)+ZOMGI*(RFUBB1(JSW) &
                &       + 2.0_JPRB *ZDESR5(JL,JK)*RFUBB2(JSW) &
                &       +3.0_JPRB*ZDESR5(JL,JK)*RFUBB3(JSW))
              ZFIWP (JL) = ZFIWP (JL)+ ZBETAI5(JL,JSW,JK)*ZTOI
              ZBETAI = ZBETAI + ZFIWP5(JL,JK)*ZTOI
              Z1RADI = Z1RADI + RFUAA1(JSW)*ZBETAI
              ZDESR(JL) = ZDESR(JL) - Z1RADI/ZDESR5(JL,JK)**2
            ENDIF
          ENDIF

          IF (ZFLWP5(JL,JK)  >=  REPSCW) THEN
            IF (NLIQOPT /= 0) THEN

!-- SW: Slingo, 1989
              ZRADLP(JL)=ZRADLP(JL)-RASWCD(JSW)*ZOL
              ZRADLP(JL)=ZRADLP(JL)+RASWCF(JSW)*ZGL

              ZFLWP(JL)=ZFLWP(JL)+ ZTOL&
               & *(RASWCA(JSW)+RASWCB(JSW)/ZRADLP5(JL,JK))              
              ZRADLP(JL)=ZRADLP(JL)- ZTOL*RASWCB(JSW)&
               & *ZFLWP5(JL,JK)/ZRADLP5(JL,JK)**2   
            ELSE

!-- SW: Fouquart, 1991
              ZTOL=ZTOL+ZOL*RYFWCE(JSW)*RYFWCD(JSW)&
               & *EXP(-RYFWCE(JSW)*ZTOL5(JL,JSW,JK))  

              ZGL = 0.0_JPRB

              ZFLWP (JL)=ZFLWP (JL)+ ZTOL*(RYFWCA(JSW)&
               & +RYFWCB(JSW)/ZRADLP5(JL,JK))  
              ZRADLP(JL)=ZRADLP(JL)- ZTOL*ZFLWP5(JL,JK)&
               & *RYFWCB(JSW)/ZRADLP5(JL,JK)**2  
            ENDIF
          ENDIF
        ENDIF

      ENDDO
    ENDDO
  ENDIF

!          2.2    CLOUD ICE AND LIQUID CONTENT AND PATH
!                 -------------------------------------

  DO JL = KIDIA,KFDIA
    ZTEMPC=0.0_JPRB
    ZTCELS=0.0_JPRB
    ZFSR=0.0_JPRB
    ZAIWC=0.0_JPRB
    ZBIWC=0.0_JPRB
    
! --- EFFECTIVE RADIUS FOR WATER AND ICE PARTICLES

! diagnosing the ice particle effective radius/diameter

    IF (NRADIP == 0) THEN
!-- fixed 40 micron effective radius
      ZRADIP(JL) = ZRADIP(JL) + ZDefRe *ZDESR(JL)
      ZDESR(JL) = 0.0_JPRB
      
      ZRADIP(JL)= 0.0_JPRB
      
    ELSEIF (NRADIP == 1) THEN 
!-- old formulation based on Liou & Ou (1994) temperature (40-130microns)
      ZRADIP(JL) = ZRADIP(JL) + ZDefRe *ZDESR(JL)
      ZDESR(JL) = 0.0_JPRB
      IF (ZRADIP15(JL,JK) < 40.0_JPRB) THEN
        ZRADIP (JL)=0.0_JPRB
      ENDIF

    ELSEIF (NRADIP == 2) THEN  
!-- formulation following Jakob, Klein modifications to ice content    
      ZRADIP(JL) = ZRADIP(JL) + ZDefRe *ZDESR(JL)
      ZDESR(JL) = 0.0_JPRB
      IF (ZRADIP15(JL,JK) > 60.0_JPRB) THEN
        ZRADIP (JL)=0.0_JPRB
      ENDIF
      IF (ZRADIP15(JL,JK) < 30.0_JPRB) THEN
        ZRADIP (JL)=0.0_JPRB
      ENDIF

    ELSEIF (NRADIP == 3 ) THEN
      IF ( ZIWC5(JL,JK) > 0.0_JPRB ) THEN
!- ice particle effective radius =f(T,IWC) from Sun and Rikus (1999)
! revised by Sun (2001)
        ZDESR(JL) = ZDESR(JL) + ZRefDe * ZRADIP(JL)
        ZRADIP(JL) = 0.0_JPRB

        IF (ZDESR15(JL,JK) > 155.0_JPRB) THEN
          ZDESR(JL) = 0.0_JPRB
        ENDIF
        IF (ZDESR15(JL,JK) < 30.0_JPRB) THEN
          ZDESR(JL) = 0.0_JPRB
        ENDIF
       
        ZFSR = ZFSR + (ZAIWC5(JL,JK) &
         & + ZBIWC5(JL,JK)*ZTEMPC5(JL,JK))*ZDESR(JL)   
        ZAIWC = ZAIWC + ZFSR5(JL,JK)*ZDESR(JL)
        ZBIWC = ZBIWC + ZFSR5(JL,JK)*ZTEMPC5(JL,JK)*ZDESR(JL)
        ZTEMPC = ZTEMPC + ZFSR5(JL,JK)*ZBIWC5(JL,JK)*ZDESR(JL)
        ZDESR(JL) = 0.0_JPRB
        
        ZIWC(JL) = ZIWC(JL) + 0.2535_JPRB* &
         & ZBIWC5(JL,JK) * ZBIWC / ZIWC5(JL,JK)
                                  
        ZIWC(JL) = ZIWC(JL) + 0.2214_JPRB* &
         & ZAIWC5(JL,JK) * ZAIWC / ZIWC5(JL,JK)
         
        ZTCELS = ZTCELS + 0.0105_JPRB *ZFSR
        PT (JL,IKL) = PT (JL,IKL) + ZTCELS
        PT (JL,IKL) = PT (JL,IKL) + ZTEMPC
        ZTEMPC = 0.0_JPRB
      
      ELSE
        ZDESR(JL) = ZDESR(JL) + ZRefDe * ZRADIP(JL)
        ZRADIP(JL) = 0.0_JPRB
        ZDESR(JL) = 0.0_JPRB
      ENDIF
    ENDIF

    ZTEMPC=ZTEMPC+ZRADIP (JL)*(12.42_JPRB + ZTEMPC5(JL,JK)&
     & *(2.0_JPRB*0.197_JPRB + 3.0_JPRB*ZTEMPC5(JL,JK)*0.0012_JPRB))  
    ZRADIP (JL)=0.0_JPRB

    IF (PT5(JL,IKL) < RTICE) THEN
      PT (JL,IKL)=PT (JL,IKL)+ZTEMPC
    ELSE
      ZTEMPC=0.0_JPRB
    ENDIF
  ENDDO
  
  DO JL = KIDIA,KFDIA  
    ZNUM=0.0_JPRB
    
! very old parametrization as f(pressure)

    IF (NRADLP == 0) THEN
      PAP(JL,IKL) = PAP(JL,IKL) - 3.5_JPRB*ZRADLP(JL)
      ZRADLP(JL) = 0.0_JPRB

    ELSEIF (NRADLP == 1) THEN
! old simple distinction between land (10) and ocean (13)
      ZRADLP(JL) = 0.0_JPRB

    ELSEIF (NRADLP == 2) THEN
!--  based on Martin et al., 1994, JAS
      IF (PLSM5(JL) < 0.5_JPRB) THEN
        IF (LCCNO) THEN
          ZASEA=PCCNO5(JL)
        ELSE  
          ZASEA=RCCNSEA
        ENDIF  
        ZD=0.33_JPRB
        ZNTOT=-1.15E-03_JPRB*ZASEA*ZASEA+0.963_JPRB*ZASEA+5.30_JPRB
      ELSE
        IF (LCCNL) THEN 
          ZALND=PCCNL5(JL)
        ELSE  
          ZALND=RCCNLND
        ENDIF  
        ZD=0.43_JPRB
        ZNTOT=-2.10E-04_JPRB*ZALND*ZALND+0.568_JPRB*ZALND-27.9_JPRB
      ENDIF
      ZDEN=4.0_JPRB*RPI*ZNTOT*(1.0_JPRB+ZD*ZD)**3

      IF ((ZNUM5(JL,JK)/ZDEN) > REPLOG) THEN
        IF (ZRADLP15(JL,JK) > 16.0_JPRB) THEN
          ZRADLP(JL) = 0.0_JPRB
        ENDIF
        IF (ZRADLP15(JL,JK) < 4.0_JPRB) THEN
          ZRADLP(JL) = 0.0_JPRB
        ENDIF
        ZNUM = ZNUM + (0.333_JPRB*ZRADLP15(JL,JK)/ZNUM5(JL,JK))*ZRADLP(JL)
        ZRADLP(JL) = 0.0_JPRB
      ELSE
        ZRADLP(JL) = 0.0_JPRB
      ENDIF
      
      ZLWC(JL)=ZLWC(JL)+3.0_JPRB*ZNUM*(1.0_JPRB+3.0_JPRB*ZD*ZD)**2  

    ENDIF
  ENDDO

  DO JL = KIDIA,KFDIA    
    ZTEMPC=0.0_JPRB
    ZIWGKG=0.0_JPRB
    ZPMBM=0.0_JPRB
    ZLWGKG=0.0_JPRB
    ZRWGKG=0.0_JPRB
    ZDPOG=0.0_JPRB
    ZPODT=0.0_JPRB
  
! --- RAIN LIQUID WATER CONTENT (g.m-3) AND LIQUID WATER PATH (g.m-2)

    ZPODT=ZPODT+ZIWGKG5(JL,JK)*ZIWC(JL)
    ZIWGKG=ZIWGKG+ZPODT5(JL,IKL)*ZIWC(JL)
    ZIWC (JL)=0.0_JPRB 

    ZPODT=ZPODT+ZLWGKG5(JL,JK)*ZLWC(JL)
    ZLWGKG=ZLWGKG+ZPODT5(JL,IKL)*ZLWC(JL)
    ZLWC(JL)=0.0_JPRB

    PAP(JL,IKL)=PAP(JL,IKL)+ZPODT/(RD*PT5(JL,IKL))
    PT(JL,IKL)=PT(JL,IKL)-PAP5(JL,IKL)*ZPODT&
     & /(RD*PT5(JL,IKL)**2)   

    ZRWGKG=ZRWGKG+ZDPOG5(JL,IKL)*ZFRWP (JL)
    ZDPOG =ZDPOG+ZRWGKG5(JL,JK)*ZFRWP (JL)
    ZFRWP (JL)=0.0_JPRB

    ZIWGKG=ZIWGKG+ZDPOG5(JL,IKL)*ZFIWP (JL)
    ZDPOG =ZDPOG+ZIWGKG5(JL,JK)*ZFIWP (JL)
    ZFIWP (JL)=0.0_JPRB

    ZLWGKG=ZLWGKG+ZDPOG5(JL,IKL)*ZFLWP (JL)
    ZDPOG =ZDPOG+ZLWGKG5(JL,JK)*ZFLWP (JL)
    ZFLWP (JL)=0.0_JPRB

    PDP(JL,IKL)=PDP(JL,IKL)+ZDPOG/RG 

    ZRWGKG =0.0_JPRB
    ZRAINT =0.0_JPRB

! --- LIQUID WATER CONTENT (g.m-3) AND LIQUID WATER PATH (g.m-2)

    IF (PCLFR5(JL,IKL) > REPSC ) THEN
      PCLFR (JL,IKL)=PCLFR (JL,IKL)-ZIWGKG*ZIWGKG15(JL,JK)/PCLFR5(JL,IKL)**2
      ZIWGKG =ZIWGKG /PCLFR5(JL,IKL)

      PCLFR (JL,IKL)=PCLFR (JL,IKL)-ZLWGKG*ZLWGKG15(JL,JK)/PCLFR5(JL,IKL)**2
      ZLWGKG =ZLWGKG /PCLFR5(JL,IKL)

      IF (PQIWP5(JL,IKL)*1000.0_JPRB  >= 0.0_JPRB) THEN
        PQIWP (JL,IKL)=PQIWP (JL,IKL)+ZIWGKG*1000.0_JPRB
      ELSE
        ZIWGKG = 0.0_JPRB
      ENDIF

      IF (PQLWP5(JL,IKL)*1000.0_JPRB  >= 0.0_JPRB) THEN
        PQLWP (JL,IKL)=PQLWP (JL,IKL)+ZLWGKG*1000.0_JPRB
      ELSE
        ZLWGKG = 0.0_JPRB
      ENDIF
    ELSE
      ZIWGKG =0.0_JPRB
      ZLWGKG =0.0_JPRB
    ENDIF

  ENDDO

!          2.1    INITIALIZE OPTICAL PROPERTIES TO CLEAR SKY VALUES
!                 -------------------------------------------------

  DO JL = KIDIA,KFDIA
!mj
    IF (LERADLW2) THEN
      PCLFR (JL,IKL) = PCLFR (JL,IKL) + ZCLFR (JL,IKL)/3.0_JPRB
    ELSE
      PCLFR (JL,IKL) = PCLFR (JL,IKL) + ZCLFR (JL,IKL)/10.0_JPRB
    ENDIF
    ZCLFR (JL,IKL) = 0.0_JPRB
!mj
    ZCLDLU (JL,JK)  = 0.0_JPRB
    ZCLDLD (JL,JK)  = 0.0_JPRB
    ZCLDSW (JL,JK)  = 0.0_JPRB
  ENDDO

  DO JSW = 1,NSW
    DO JL = KIDIA,KFDIA
      ZCG (JL,JSW,JK)   = 0.0_JPRB
      ZOMEGA (JL,JSW,JK)= 0.0_JPRB
      ZTAU (JL,JSW,JK)  = 0.0_JPRB
    ENDDO
  ENDDO
ENDDO

!*         1.1    INITIALIZE VARIOUS FIELDS
!                 -------------------------

DO JL=KIDIA,KFDIA
  PAPH (JL,1)=PAPH (JL,1)+ZPMB (JL,KLEV+1)/100.0_JPRB
  ZPMB (JL,KLEV+1)=0.0_JPRB

  PTH (JL,1)=PTH (JL,1)+ZTL (JL,KLEV+1)
  ZTL (JL,KLEV+1)=0.0_JPRB
ENDDO

DO JK=KLEV,1,-1
  JKL=KLEV+1-JK
  JKLP1=JKL+1
  DO JL=KIDIA,KFDIA
    PT (JL,JKL)=PT (JL,JKL)+ZTAVE (JL,JK)
    ZTAVE (JL,JK)=0.0_JPRB

    PTH (JL,JKLP1)=PTH (JL,JKLP1)+ZTL (JL,JK)
    ZTL (JL,JK)=0.0_JPRB
  ENDDO
ENDDO

DO JK = KLEV, 1, -1
  JKP1 = JK + 1
  JKL = KLEV+ 1 - JK
  JKLP1 = JKL + 1
  DO JL = KIDIA,KFDIA
    ZFLUC (JL,2,JK) = 0.0_JPRB
    ZFLUC (JL,1,JK) = 0.0_JPRB
    ZFLUX (JL,2,JK) = 0.0_JPRB
    ZFLUX (JL,1,JK) = 0.0_JPRB
    ZFSDWN (JL,JK) = 0.0_JPRB
    ZFSUP (JL,JK) = 0.0_JPRB
    ZFCDWN (JL,JK) = 0.0_JPRB
    ZFCUP (JL,JK) = 0.0_JPRB
    POZON (JL,JKL)=POZON (JL,JKL)+ZOZ (JL,JK)*46.6968_JPRB/RG
    ZOZ (JL,JK)=0.0_JPRB
    PAPH (JL,JKL)=PAPH (JL,JKL)+ZPMB (JL,JK+1)/100.0_JPRB
    ZPMB (JL,JK+1)=0.0_JPRB
  ENDDO
ENDDO

DO JL = KIDIA,KFDIA
  ZMU0 (JL)   =0.0_JPRB
  PEMIW (JL)=PEMIW (JL)+ZEMIW (JL)
  ZEMIW (JL)=0.0_JPRB
  PEMIR (JL)=PEMIR (JL)+ZEMIR (JL)
  ZEMIR (JL)=0.0_JPRB
ENDDO

DO JSW=1,NSW
  DO JL = KIDIA,KFDIA
    PALBP (JL,JSW)=PALBP (JL,JSW)+ZALBP (JL,JSW)
    ZALBP (JL,JSW)=0.0_JPRB

    PALBD (JL,JSW)=PALBD (JL,JSW)+ZALBD (JL,JSW)
    ZALBD (JL,JSW)=0.0_JPRB
  ENDDO
ENDDO

!*         1.     SET-UP INPUT QUANTITIES FOR RADIATION
!                 -------------------------------------

DO JL = KIDIA,KFDIA
  PTS (JL)=PTS (JL)+ZDT0 (JL)
  PTH (JL,KLEV+1)=PTH (JL,KLEV+1)-ZDT0 (JL)
  ZDT0 (JL)=0.0_JPRB

  ZPSOL (JL)=ZPSOL (JL)+ZPMB (JL,1)/100.0_JPRB
  ZPMB (JL,1)=0.0_JPRB

  PAPH (JL,KLEV+1)=PAPH (JL,KLEV+1)+ZPSOL (JL)
  ZPSOL (JL)=0.0_JPRB

  ZFLUC (JL,2,KLEV+1) = 0.0_JPRB
  ZFLUC (JL,1,KLEV+1) = 0.0_JPRB
  ZFLUX (JL,2,KLEV+1) = 0.0_JPRB
  ZFLUX (JL,1,KLEV+1) = 0.0_JPRB
  ZFSDWN (JL,KLEV+1) = 0.0_JPRB
  ZFSUP (JL,KLEV+1) = 0.0_JPRB
  ZFCDWN (JL,KLEV+1) = 0.0_JPRB
  ZFCUP (JL,KLEV+1) = 0.0_JPRB
ENDDO

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

!*         5.     FILL UP THE MODEL NET LW AND SW RADIATIVE FLUXES
!                 ------------------------------------------------

DO JK = 1 , KLEV+1
  DO JL = KIDIA,KFDIA
    ZFSUP5 (JL,JK) = ZFSUP5(JL,JK) * ZFACT5(JL)
    ZFSDWN5(JL,JK) = ZFSDWN5(JL,JK) * ZFACT5(JL)

! diagnostic clear sky quantities
!    ZFCUP5 (JL,JK) = ZFCUP5(JL,JK) * ZFACT5(JL)
!    ZFCDWN5(JL,JK) = ZFCDWN5(JL,JK) * ZFACT5(JL)
  ENDDO
ENDDO

DO JKL = 1 , KLEV+1
  JK = KLEV+1 + 1 - JKL
  DO JL = KIDIA,KFDIA
    PFLS5(JL,JKL) = ZFSDWN5(JL,JK) - ZFSUP5(JL,JK)
    PFLT5(JL,JKL) = - ZFLUX5(JL,1,JK) - ZFLUX5(JL,2,JK)

! diagnostic clear sky quantities
!    PFCS5(JL,JKL) = ZFCDWN5(JL,JK) - ZFCUP5(JL,JK)
!    PFCT5(JL,JKL) = - ZFLUC5(JL,1,JK) - ZFLUC5(JL,2,JK)
  ENDDO
ENDDO

DO JL = KIDIA,KFDIA
  PFRSOD5(JL)=ZFSDWN5(JL,1)
ENDDO

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

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