SUBROUTINE RADLSWR &
 &( KIDIA, KFDIA , KLON , KLEV , KBL, KAERO ,&
 &  PRII0,&
 &  PAER , PAERO , PALBD, PALBP, PGEOH  , PAPH  , PAP  ,&
 &  PCCNL, PCCNO , PGELAM,PGEMU,&
 &  PCO2 , PCH4  , PN2O , PNO2 , PC11  , PC12 , PC22 , PCL4 ,&  
 &  PCLFR, PDP   , PEMIS, PEMIW, PLSM  , PMU0 , POZON,&
 &  PQ   , PQIWP , PQSWP, PQLWP, PQRWP ,&
 &  PTH  , PT    , PTS  ,&
 &  PEMIT, PFCT  , PFLT , PFCS , PFLS  , PFRSOD, &
 &  PSUDU, PUVDF , PPARF, PPARCF, PTINCF, &
 &  PFDIR, PCDIR , &
 &  KLEVX, PEXTRA, PEXTR2, &
 &  LZEROAERO, &
 &  PAODTM,PSSATM, PASFTM, & 
 &  PCDNC, PICNC, PRE_LIQ, PRE_ICE)

!**** *RADLSWR* - INTERFACE TO ECMWF McICA LW AND SW RADIATION SCHEMES 

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

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

!        EXPLICIT ARGUMENTS :
!        --------------------
! PAER   : (KLON,6,KLEV)     ; OPTICAL THICKNESS OF THE AEROSOLS
! PAERP  : (KLON,6,KLEV)     ; OPTICAL THICKNESS OF THE PROGNOSTIC AEROSOLS
! PAERO  : (KLON,KLEV,NAERO) ; PROGNOSTIC AEROSOL MIXIN RATIO
! PALBD  : (KLON,NSW)        ; SURF. SW ALBEDO FOR DIFFUSE RADIATION
! PALBP  : (KLON,NSW)        ; SURF. SW ALBEDO FOR PARALLEL RADIATION
! PGEOH  : (KLON,KLEV+1)     ; HALF LEVEL GEOPOTENTIAL
! PAPH   : (KLON,KLEV+1)     ; HALF LEVEL PRESSURE
! PAP    : (KLON,KLEV)       ; FULL LEVEL PRESSURE
! PCCNL  : (KLON)            ; CCN CONCENTRATION OVER LAND
! PCCNO  : (KLON)            ; CCN CONCENTRATION OVER OCEAN
! PCO2   : (KLON,KLEV)       ; CONCENTRATION IN CO2 (KG/KG)
! PCH4   : (KLON,KLEV)       ; CONCENTRATION IN CH4 (KG/KG)
! PN2O   : (KLON,KLEV)       ; CONCENTRATION IN N2O (KG/KG)
! PNO2   : (KLON,KLEV)       ; CONCENTRATION IN NO2 (KG/KG)
! PC11   : (KLON,KLEV)       ; CONCENTRATION IN CFC11 (KG/KG)
! PC12   : (KLON,KLEV)       ; CONCENTRATION IN CFC12 (KG/KG)
! PC22   : (KLON,KLEV)       ; CONCENTRATION IN HCFC22 (KG/KG)
! PCL4   : (KLON,KLEV)       ; CONCENTRATION IN CCL4  (KG/KG)
! PCLFR  : (KLON,KLEV)       ; CLOUD FRACTIONAL COVER
! PDP    : (KLON,KLEV)       ; LAYER PRESSURE THICKNESS
! PEMIS  : (KLON)            ; SURFACE LW EMISSIVITY
! PEMIW  : (KLON)            ; SURFACE LW WINDOW EMISSIVITY
! PGELAM : (KLON)            ; LONGITUDE (RADIANS)
! PGEMU  : (KLON)            ; SINE OF LATITUDE
! PLSM   : (KLON)            ; LAND-SEA MASK
! PMU0   : (KLON)            ; SOLAR ANGLE
! POZON  : (KLON,KLEV)       ; OZONE AMOUNT in LAYER (KG/KG*PA)
! PQ     : (KLON,KLEV)       ; SPECIFIC HUMIDITY KG/KG
! PQIWP  : (KLON,KLEV)       ; ICE (Small particles) KG/KG
! PQSWP  : (KLON,KLEV)       ; SNOW (Large particle) KG/KG
! PQLWP  : (KLON,KLEV)       ; LIQUID WATER KG/KG
! PQRWP  : (KLON,KLEV)       ; RAIN WATER KG/KG
! PTH    : (KLON,KLEV+1)     ; HALF LEVEL TEMPERATURE
! PT     : (KLON,KLEV)       ; FULL LEVEL TEMPERATURE
! PTS    : (KLON)            ; SURFACE TEMPERATURE
!     ==== OUTPUTS ===
! PFCT   : (KLON,KLEV+1)     ; CLEAR-SKY LW NET FLUXES
! PFLT   : (KLON,KLEV+1)     ; TOTAL LW NET FLUXES
! PFCS   : (KLON,KLEV+1)     ; CLEAR-SKY SW NET FLUXES
! PFLS   : (KLON,KLEV+1)     ; TOTAL SW NET FLUXES
! PFRSOD : (KLON)            ; TOTAL-SKY SURFACE SW DOWNWARD FLUX
! PEMIT  : (KLON)            ; SURFACE TOTAL LONGWAVE EMISSIVITY
! PSUDU  : (KLON)            ; SOLAR RADIANCE IN SUN'S DIRECTION
! PFDIR  : (KLON)            ; TOTAL SKY DIRECT SW DOWNWARD FLUX
! PCDIR  : (KLON)            ; CLAER-SKY DIRECT SW DOWNWARD FLUX
! KLEVX  :                   ; NUMBER OF LEVELS FOR ADDITIONAL 3-D DIAGNOSTICS
! PEXTRA : (KLON,KLEVX,NRAD3D)  ; ADDITIONAL 3-D DIAGNOSTICS
! PEXTR2 : (KLON,NRAD2D)     ; ADDITIONAL 2-D DIAGNOSTICS
! PAODTM : (KLON,14,KLEV)    ; OPTICAL THICKNESS OF THE AEROSOLS FROM TM5
! PSSATM : (KLON,14,KLEV)    ; SINGLE-SCATTERING ALBEDO OF THE AEROSOLS FROM TM5
! PASFTM : (KLON,14,KLEV)    ; ASYMMETRY FACTOR OF THE AEROSOLS FROM TM5

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

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

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

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

!     AUTHORS.
!     --------
!        J.-J. MORCRETTE         *ECMWF*

!     MODIFICATIONS.
!     --------------
!        ORIGINAL : 88-02-04
!        J.-J. MORCRETTE 94-11-15 DIRECT/DIFFUSE SURFACE ALBEDO
!        08/96: J.-J. Morcrette/Ph. Dandin: tests of eff. radius param.
!        9909 : JJMorcrette effect.radius + inhomogeneity factors
!        JJMorcrette 990128 : sunshine duration
!        JJMorcrette : 990831 RRTM-140gp
!        JJMorcrette : 010112 Sun-Rikus ice particle Diameter
!        JJMorcrette : 010301 cleaning liq/ice cloud optical properties
!        JJMorcrette : 011005 CCN --> Re liquid water clouds
!        JJMorcrette : 011108 Safety checks
!        JJMorcrette : 011108 Safety checks
!        DJSalmond   : 020211 Check before R-To-R
!        JJMorcrette : 030430 Interface to SRTM-224gp
!        M.Hamrud      01-Oct-2003 CY28 Cleaning
!        JJMorcrette 20060721 PP of clear-sky and TOA incident solar radiation
!        JJMorcrette : 060110 McICA approach to RRTM and SRTM-112g
!        JJMorcrette : 20071015 3D fields for CO2, CH4, N2O and NO2
!        JJMorcrette 20070321 Prognostic aerosols in radiation
!        R.Forbes    20071015 Add RDECORR_CF,RDECORR_CW
!        JJMorcrette 20080422 Prognostic aerosols in radiation
!        JJMorcrette 20090804 Change in the partition IW/LW and ice cloud De
!        JJMorcrette 20090805 Decorrelation=f(latitude) 
!        JJMorcrette 20091201 Total and clear-sky direct SW radiation flux at surface 
!        T.van Noije 20140122 Included aerosol optical properties fields from TM5 for EC-Earth
!        S. Boussetta March-2016 added option to use the anthropogenic aerosol MACv2 SP
!        M. Menegoz 2017 added option to read the CMIP6 stratospheric
!        aerosol
!-----------------------------------------------------------------------

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

USE YOMCT0   , ONLY : NSTART, NFRPOS 
USE YOMCT3   , ONLY : NSTEP
USE YOMDYN   , ONLY : TSTEP
USE YOMCST   , ONLY : RG       ,RD       ,RTT      ,RPI, RDAY
USE YOECLD   , ONLY : RDECORR_CF       ,RDECORR_CW
USE YOECLDP  , ONLY : NAERCLD, RCDNCOM, RCDNCSS , RCDNCSU, NCLOUDACT, &
                    & LAERICESED, LAERICEAUTO, LACI_DIAG !, RCLCRIT
USE YOERAD   , ONLY : MAC2SP_LAMDA,MAC2SP_NLAMDA, MAC2SP_NMON, NTSW, NCMIPFIXYR
USE YOERAD   , ONLY : LMAC2SP, LCMIP6_PI_AEROSOLS, LMAC2SPACI, LTM5AER, &
                    & L2RAD, L2RADACCU 
USE YOERAD   , ONLY : NSW      ,NOVLP  ,LRRTM    ,&
 & LCCNL  , LCCNO  , LDIFFC , NDECOLAT, &
 & NRADIP , NRADLP , NICEOPT, NLIQOPT, NMINICE, &
 & RCCNLND, RCCNSEA, NMcICA , RMINICE, RRe2De 
USE YOELW    , ONLY : NTRA     ,NUA
USE YOESW    , ONLY : REBCUG   ,REBCUH   ,&
 & RHSAVI   ,RFULIO   ,RFUETA  ,RFUETB   ,RFUETC   ,RLILIA   ,RLILIB  

USE YOESRTCOP , ONLY : &
 & RSYFWA   ,RSYFWB   ,RSYFWC   ,RSYFWD   ,RSYFWE   ,RSYFWF  &
 & , RSECIA   ,RSECIB   ,RSECIC   ,RSECID   ,RSECIE   ,RSECIF &
 & , RSASWA   ,RSASWB   ,RSASWC   ,RSASWD   ,RSASWE   ,RSASWF &
 & , RSFUA0   ,RSFUA1   ,RSFUB0   ,RSFUB1   ,RSFUB2   ,RSFUB3 &
 & , RSFUC0   ,RSFUC1   ,RSFUC2   ,RSFUC3   &
 & , RSFLA0   ,RSFLA1   ,RSFLB0   ,RSFLB1   ,RSFLB2   ,RSFLB3 &
 & , RSFLC0   ,RSFLC1   ,RSFLC2   ,RSFLC3   ,RSFLD0   ,RSFLD1 &
 & , RSFLD2   ,RSFLD3  

USE YOERDU   , ONLY : NUAER  ,NTRAER   ,REPLOG   ,REPSC    ,REPSCA  ,REPSCW   ,DIFF
USE YOETHF   , ONLY : RTICE
USE YOEPHLI  , ONLY : LPHYLIN
USE YOERRTFTR, ONLY : NGB
USE YOESRTWN , ONLY : NGBSW  ,NMPSRTM
USE YOEAERATM, ONLY : LAEROPT, LAERRAD
USE YOM_YGFL , ONLY : NACTAERO
USE YOMLUN   , ONLY : NULOUT, NULERR
USE YOMRIP   , ONLY : NINDAT, NSTADD
USE YOMCT0   , ONLY : LTWOTL ,LNF 
USE YOMCT2   , ONLY : NSTAR2
USE AER_MACV2SP_MOD, ONLY: SP_AOP_PROFILE, MAC2SP_YEAR_MIN, MAC2SP_YEAR_MAX
USE DAY_NUMBER_MOD,  ONLY: NUMBER_OF_DAY
USE YOE_PI_AERO,     ONLY: PI_AOD, PI_ABS, PI_XASY, LPI_AERO_UPDATED
USE YOERAD, ONLY : LCMIP6_STRATAER_FULL,LSTRATAERO_UPDATED, &
                   STRAT_AOD,STRAT_AAOD,STRAT_REFAOD, &
                   STRATO_CMIP6_NTB,STRAT_AAOD_LW,STRATO_CMIP6_NMONTH
USE YOE_AER_ACTIV, ONLY : PPMINCDNC,PPDEFCDNC, D_REFF
USE YOERADDIAG
USE PHY_DIAG_MOD, ONLY: NRAD2D, NRAD3D

IMPLICIT NONE

INTEGER(KIND=JPIM),INTENT(IN)    :: KLON
INTEGER(KIND=JPIM),INTENT(IN)    :: KLEV
INTEGER(KIND=JPIM),INTENT(IN)    :: KBL
INTEGER(KIND=JPIM),INTENT(IN)    :: KIDIA
INTEGER(KIND=JPIM),INTENT(IN)    :: KFDIA
INTEGER(KIND=JPIM),INTENT(IN)    :: KAERO
REAL(KIND=JPRB)   ,INTENT(IN)    :: PRII0
REAL(KIND=JPRB)   ,INTENT(IN)    :: PAER(KLON,6,KLEV)
REAL(KIND=JPRB)   ,INTENT(IN)    :: PAERO(KLON,KLEV,KAERO)
REAL(KIND=JPRB)   ,INTENT(IN)    :: PALBD(KLON,NSW) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PALBP(KLON,NSW) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PGEOH(KLON,KLEV+1)
REAL(KIND=JPRB)   ,INTENT(IN)    :: PAPH(KLON,KLEV+1)
REAL(KIND=JPRB)   ,INTENT(IN)    :: PAP(KLON,KLEV)
REAL(KIND=JPRB)   ,INTENT(IN)    :: PCCNL(KLON) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PCCNO(KLON) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PCO2(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PCH4(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PN2O(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PNO2(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PC11(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PC12(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PC22(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PCL4(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PCLFR(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PDP(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PEMIS(KLON) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PEMIW(KLON) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PGELAM(KLON), PGEMU(KLON)
REAL(KIND=JPRB)   ,INTENT(IN)    :: PLSM(KLON) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PMU0(KLON) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: POZON(KLON,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PQ(KLON,KLEV)
REAL(KIND=JPRB)   ,INTENT(IN)    :: PQIWP(KLON,KLEV) ! Ice 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PQSWP(KLON,KLEV) ! Snow
REAL(KIND=JPRB)   ,INTENT(IN)    :: PQLWP(KLON,KLEV) ! Liquid
REAL(KIND=JPRB)   ,INTENT(IN)    :: PQRWP(KLON,KLEV) ! Rain
REAL(KIND=JPRB)   ,INTENT(IN)    :: PTH(KLON,KLEV+1)
REAL(KIND=JPRB)   ,INTENT(IN)    :: PT(KLON,KLEV)
REAL(KIND=JPRB)   ,INTENT(IN)    :: PTS(KLON)
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PEMIT(KLON) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PFCT(KLON,KLEV+1) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PFLT(KLON,KLEV+1) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PFCS(KLON,KLEV+1) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PFLS(KLON,KLEV+1) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PFRSOD(KLON) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PSUDU(KLON) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PUVDF(KLON) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PPARF(KLON) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PPARCF(KLON), PTINCF(KLON) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PFDIR(KLON) , PCDIR(KLON) 
INTEGER(KIND=JPIM),INTENT(IN)    :: KLEVX
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PEXTRA(KLON,KLEVX,NRAD3D)
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PEXTR2(KLON,NRAD2D)
REAL(KIND=JPRB)   ,OPTIONAL, INTENT(IN) :: PAODTM(KLON,14,KLEV)
REAL(KIND=JPRB)   ,OPTIONAL, INTENT(IN) :: PSSATM(KLON,14,KLEV)
REAL(KIND=JPRB)   ,OPTIONAL, INTENT(IN) :: PASFTM(KLON,14,KLEV)
REAL(KIND=JPRB)   ,OPTIONAL, INTENT(IN) :: PCDNC(KLON,KLEV)
REAL(KIND=JPRB)   ,OPTIONAL, INTENT(IN) :: PICNC(KLON,KLEV)
REAL(KIND=JPRB)   ,OPTIONAL, INTENT(IN) :: PRE_LIQ(KLON,KLEV)
REAL(KIND=JPRB)   ,OPTIONAL, INTENT(IN) :: PRE_ICE(KLON,KLEV)

! Double radiation
LOGICAL, INTENT(IN) :: LZEROAERO

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

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

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

!-- ARRAYS FOR LOCAL VARIABLES -----------------------------------------
REAL(KIND=JPRB)    :: ZAODPI(KLON,KLEV,NTSW)
REAL(KIND=JPRB)    :: ZSSAPI(KLON,KLEV,NTSW)
REAL(KIND=JPRB)    :: ZASFPI(KLON,KLEV,NTSW)
! CMIP6 stratospheric aerosols
REAL(KIND=JPRB)       :: ZAODSTRAT_M(KLON,KLEV,NTSW,STRATO_CMIP6_NMONTH)
REAL(KIND=JPRB)       :: ZAAODSTRAT_M(KLON,KLEV,NTSW,STRATO_CMIP6_NMONTH)
REAL(KIND=JPRB)       :: ZREFAODSTRAT_M(KLON,KLEV,NTSW,STRATO_CMIP6_NMONTH)
REAL(KIND=JPRB)       :: ZAAODSTRAT_LW_M(KLON,KLEV,STRATO_CMIP6_NTB,STRATO_CMIP6_NMONTH)
REAL(KIND=JPRB)       :: ZAODSTRAT(KLON,KLEV,NTSW)
REAL(KIND=JPRB)       :: ZAAODSTRAT(KLON,KLEV,NTSW)
REAL(KIND=JPRB)       :: ZREFAODSTRAT(KLON,KLEV,NTSW)
REAL(KIND=JPRB)       :: ZAAODSTRAT_LW(KLON,KLEV,STRATO_CMIP6_NTB)
INTEGER(KIND=JPIM)    :: KTROPPAUSE(KLON)
!-- outputs from MAC2SP anthropogenic aerosol
REAL(KIND=JPRB)    :: ZMAC2SP_ASY(KLON,KLEV,MAC2SP_NLAMDA)
REAL(KIND=JPRB)    :: ZMAC2SP_SSA(KLON,KLEV,MAC2SP_NLAMDA)
REAL(KIND=JPRB)    :: ZMAC2SP_AOD(KLON,KLEV,MAC2SP_NLAMDA)
REAL(KIND=JPRB)    :: ZMAC2SP_CDNC_FACTOR(KLON)

REAL(KIND=JPRB)    :: AOD_MAC2SP(KLON,KLEV)
REAL(KIND=JPRB)    :: SSA_MAC2SP(KLON,KLEV)
REAL(KIND=JPRB)    :: ASY_MAC2SP(KLON,KLEV)
REAL(KIND=JPRB)    :: YEAR_FR, KNDY
INTEGER(KIND=JPIM) :: IDY0, IMN0, IYR0, IDY, IMN, IYR , IDOY, IWEEK,IFWEEK, WSTEP, IWSTEP
INTEGER(KIND=JPIM) :: ISTADD, ITIME
INTEGER(KIND=JPIM) :: IZT
INTEGER(KIND=JPIM) :: ILMONTH(12)
!-----------------------------------------------------------------------
REAL(KIND=JPRB) :: &
 & ZTAUCLD(KLON,KLEV,16), ZTCLEAR(KLON)  
REAL(KIND=JPRB) :: ZAER(KLON,6,KLEV) &
 & , ZCLDLW(KLON,KLEV)  , ZCLDSW(KLON,KLEV)&
 & , ZDT0(KLON)        &
 & , ZEMIS(KLON)        , ZEMIW(KLON)&
 & , ZFDIR(KLON,KLEV+1) , ZCDIR(KLON,KLEV+1), ZFDIF(KLON,KLEV+1), ZCDIF(KLON,KLEV+1)& 
 & , ZFLUX (KLON,2,KLEV+1)                  , ZFLUC(KLON,2,KLEV+1)&
 & , ZFIWP(KLON,KLEV)   , ZFSWP(KLON,KLEV) , ZFLWP(KLON,KLEV), ZFRWP(KLON,KLEV)&
 & , ZIWC(KLON,KLEV)    , ZSWC(KLON,KLEV)  , ZLWC(KLON,KLEV) , ZRWC(KLON,KLEV)&
 & , 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)&
 & , ZFSUPN(KLON)       , ZFSUPV(KLON)&
 & , ZFCUPN(KLON)       , ZFCUPV(KLON)&
 & , ZFSDNN(KLON)       , ZFSDNV(KLON)&
 & , ZFCDNN(KLON)       , ZFCDNV(KLON)  
REAL(KIND=JPRB) ::&
 & ZDESR(KLON), ZRADIP(KLON)       , ZRADLP(KLON)    , &
 !cc           , ZRADRD(KLON)
 & ZRAINT(KLON)       , ZEMIT(KLON)     
REAL(KIND=JPRB) :: ZSUDU(KLON), ZFUVF(KLON), ZFUVC(KLON), ZPARF(KLON), ZPARCF(KLON)

INTEGER(KIND=JPIM) :: IK, ILW16, ISW, ISW14
INTEGER(KIND=JPIM) :: JK, JKL, JKLP1, JKP1, JL, JRTM, JSW, ILAMDA
INTEGER(KIND=JPIM) :: JAER

REAL(KIND=JPRB) :: ZASYMX, ZCCN0, ZDIFFD, ZGI, ZGL, ZGR 
REAL(KIND=JPRB) :: ZIWGKG, ZSWGKG, ZLWGKG, ZRWGKG,&
 & ZMULTI, ZMULTL, ZOI, ZOL, &
 & ZOMGMX, ZOR, ZRMUZ, ZTAUD, ZTAUMX, ZTEMPC, &
 & ZTOI, ZTOL, ZTOR, ZDPOG, ZPODT  
REAL(KIND=JPRB) :: ZALND, ZASEA, ZDEN, ZNTOT, ZNUM, Z1RADI, Z1RADL,&
 & ZBETAI, ZOMGI, ZOMGP, ZFDEL, ZTCELS, ZFSR, ZAIWC, ZBIWC, &
 & ZDefRe, ZRefDe, ZEXTCF, Z1MOMG, ZRSAIA, ZRSAID, ZRSAIE, ZRSAIF, ZRSAIG, ZRSALD 

REAL(KIND=JPRB) :: ZSALBD(KLON,14)     , ZSALBP(KLON,14)
REAL(KIND=JPRB) :: ZSTAUC(KLON,14,KLEV), ZSASYC(KLON,14,KLEV), ZSOMGC(KLON,14,KLEV)
REAL(KIND=JPRB) :: ZFSUC(KLON,2,KLEV+1), ZFSUX(KLON,2,KLEV+1)

INTEGER(KIND=JPIM), PARAMETER :: ICOLSLW=140, ICOLSSW=112
INTEGER(KIND=JPIM) :: ICOLS, IJK, IPRINT(KLON,KLEV), JCOLS, ICLW, ICSW, JCLW, JCSW

REAL(KIND=JPRB)    :: ZCLFR(KLON,KLEV) , ZQIWP(KLON,KLEV) , ZQSWP(KLON,KLEV) 
REAL(KIND=JPRB)    :: ZQLWP(KLON,KLEV) , ZQRWP(KLON,KLEV) , ZETA(KLON,KLEV)
REAL(KIND=JPRB)    :: ZGLAT(KLON)      , ZGLON(KLON)
REAL(KIND=JPRB)    :: ZLC_CF(KLON,KLEV), ZLC_CW(KLON,KLEV), ZSIGQCW(KLON,KLEV), ZPS(KLON)
REAL(KIND=JPRB)    :: ZQI_SL(KLON,KLEV,ICOLSLW), ZQL_SL(KLON,KLEV,ICOLSLW)
REAL(KIND=JPRB)    :: ZQI_SS(KLON,KLEV,ICOLSSW), ZQL_SS(KLON,KLEV,ICOLSSW)
REAL(KIND=JPRB)    :: ZQS_SL(KLON,KLEV,ICOLSLW), ZQS_SS(KLON,KLEV,ICOLSSW)
REAL(KIND=JPRB)    :: ZQILW(KLON,ICOLSLW,KLEV) , ZQLLW(KLON,ICOLSLW,KLEV)
REAL(KIND=JPRB)    :: ZQISW(KLON,ICOLSLW,KLEV) , ZQLSW(KLON,ICOLSLW,KLEV)
REAL(KIND=JPRB)    :: ZQSLW(KLON,ICOLSLW,KLEV) , ZQSSW(KLON,ICOLSLW,KLEV)
INTEGER(KIND=JPIM) :: ICLDLW(KLON), ICLDSW(KLON)

REAL(KIND=JPRB)    :: ZRADLI(KLON,KLEV), ZRADIC(KLON,KLEV), ZDESIC(KLON,KLEV)

REAL(KIND=JPRB)    :: ZFCLW(KLON,ICOLSLW,KLEV), ZTOLW(KLON,KLEV,ICOLSLW)
REAL(KIND=JPRB)    :: ZFCSW(KLON,ICOLSSW,KLEV) , ZTOSW(KLON,ICOLSSW,KLEV)
REAL(KIND=JPRB)    :: ZASSW(KLON,ICOLSSW,KLEV) , ZOMSW(KLON,ICOLSSW,KLEV)
REAL(KIND=JPRB)    :: ZSWFC(KLON,ICOLSSW,KLEV) , ZLWFC(KLON,ICOLSLW,KLEV) 
INTEGER(KIND=JPIM) :: IFCLW(KLON,ICOLSLW,KLEV) , IFCSW(KLON,ICOLSSW,KLEV)

REAL(KIND=JPRB)    :: ZRG, ZTEMP, ZRPI

! Effective radius for water cloud
REAL(KIND=JPRB)    :: ZKSEA,ZKLAND
REAL(KIND=JPRB)    :: ZK(KLON)  ! constant relating rvol to reff for cloud droplets
REAL(KIND=JPRB)    :: ZKL ! constant relating rvol to reff for drizzle/rain droplets
REAL(KIND=JPRB)    :: ZKRATIO(KLON)   ! ratio of ZKL to ZK
REAL(KIND=JPRB)    :: ZRLRATIO  ! ratio of rain water content to liquid water content
REAL(KIND=JPRB)    :: ZREFACDEN ! Denominator for eff radius increase factor (Wood, 2000)
REAL(KIND=JPRB)    :: ZREFAC    ! Effective radius increase factor (Wood, 2000) 
REAL(KIND=JPRB)    :: ZCDNC(KLON,KLEV) ! number of cloud nuclei (liquid water clouds)

!* Indices and Arrays linked to prognostic aerosols
INTEGER(KIND=JPIM) :: IACTAERO, IRADLP, INWAVL, ITWAVL(19)
!INTEGER(KIND=JPIM) :: IKPJL(KLON), ICTJL
INTEGER(KIND=JPIM) :: JAERSS, JAERDD, JAEROM, JAERBC, JAERSU
REAL(KIND=JPRB)    :: ZCCN(KLON,KLEV), ZMAER(KLON,KLEV,5), ZMAERMN(5), ZAERO(KLON,KLEV,KAERO),&
  & ZRE_LIQ(KLON,KLEV), ZRHO(KLON,KLEV), ZTAUAER(KLON,6,KLEV), ZOMGAER(KLON,6,KLEV), ZASYAER(KLON,6,KLEV)

!* Decorrelation as a function of latitude
REAL(KIND=JPRB)    :: ZCLAT(KLON), ZDECORR_CF(KLON), ZDECORR_CW(KLON),ZLAT(KLON)

!* Arrays linked to minimum ice particle size
REAL(KIND=JPRB)    :: ZMINICE(KLON)

! Robert's Cloud generator
!  type(randomNumberStream) :: stream

! Raisanen and Barker's generator
!  REAL(KIND=JPRB) :: RLC_CF(klev), RLC_CW(klev), ZDROPS(klev), ZNUEFF(klev), ZRELW0(klev), ZREIW0(klev)
!  REAL(KIND=JPRB) :: ZF(klon,klev), ZRHOF(klon,klev), ZSIGQCW(klon,klev), ZCLDF(klev)
!  REAL(KIND=JPRB) :: YCF(ICOLSSW,klev), YQLW(ICOLSSW,klev), YQIW(ICOLSSW,klev), YRELW(ICOLSSW,klev), YREIW(ICOLSSW,klev)

LOGICAL :: LLCONST_RE, LLMAXRAN, LLPPH, LLPRINT

!-- end of McICA specific -----------------------

! For double call to radiation
INTEGER(KIND=JPIM)  :: IDIAGIX
REAL(KIND=JPRB)     :: ZAODTM(KLON,14,KLEV)

REAL(KIND=JPRB) :: ZHOOK_HANDLE

!#include "lw.intfb.h"
#include "cmip6_piaer_interp.intfb.h"
#include "cmip6_strato_aero_interp.intfb.h"
#include "cmip6_strato_aero_process.intfb.h"
#include "aer_rad.intfb.h"
#include "rrtm_rrtm_140gp.intfb.h"
#include "srtm_srtm_224gp.intfb.h"
#include "abor1.intfb.h"

!-- McICA specific -----------------------
#include "mcica_cld_gen.intfb.h"
#include "rrtm_rrtm_140gp_mcica.intfb.h"
#include "srtm_srtm_224gp_mcica.intfb.h"

#include "updcal.intfb.h"
#include "fcttim.h" 
!     -----------------------------------------------------------------
IF (LHOOK) CALL DR_HOOK('RADLSWR',0,ZHOOK_HANDLE)

!*         1.     PREPARATORY CALCULATIONS
!                 ------------------------

IF (NACTAERO > 0 .AND. LAERRAD) THEN
  DO JAER=1,NACTAERO
    DO JK=1,KLEV
      DO JL=KIDIA,KFDIA
        ZAERO(JL,JK,JAER)=MAX(0._JPRB,PAERO(JL,JK,JAER))
      ENDDO
    ENDDO
  ENDDO
ENDIF

! Double radiation
! Set aerosol fields to zero
IF (LZEROAERO) THEN
   IF (NACTAERO > 0 .AND. LAERRAD) THEN
      ZAERO(KIDIA:KFDIA,1:KLEV,1:KAERO)=0._JPRB
   ENDIF
END IF

IF (LTM5AER) THEN
   ! Set a local variable since can't touch the intent(in) one
   ZAODTM(KIDIA:KFDIA,:,:) = MERGE(0._JPRB, PAODTM(KIDIA:KFDIA,:,:), LZEROAERO)
END IF
   
!--- SAFETY CHECKS

!IF (NACTAERO > 0 .AND. (LAERRAD .OR. LAERCCN) ) THEN 
!  LLPOSIT=.TRUE.
!  DO JAER=1,NACTAERO
!    DO JK=1,KLEV
!      LLNEGAT=.FALSE.
!      IKPJL(KIDIA:KFDIA)=0
!      ICTJL=0
!      DO JL=KIDIA,KFDIA
!        IF (PAERO(JL,JK,JAER) < 0._JPRB .AND. PAERO(JL,JK,JAER) < -1.E-200_JPRB) THEN
!          LLNEGAT=.TRUE.
!          LLPOSIT=.FALSE.
!          ICTJL=ICTJL+1
!          IKPJL(ICTJL)=JL
!        ENDIF
!        ZAERO(JL,JK,JAER)=MAX(0._JPRB,PAERO(JL,JK,JAER))
!      ENDDO
!      IF(ICTJL /= 0) THEN
!        DO JL=1,ICTJL
!          WRITE(NULOUT,8001) JL,JK,IKPJL(JL),PAERO(IKPJL(JL),JK,JAER),ZAERO(IKPJL(JL),JK,JAER)
!8001      FORMAT(1X,'radlswr safecheck',3I4,2E13.5)
!        ENDDO
!      ENDIF
!    ENDDO
!  ENDDO
!  IF (LLPOSIT) THEN
!    WRITE(NULOUT,FMT='(" no negative PAERO has been found")')
!  ELSE
!    WRITE(NULOUT,FMT='(" RADLSWR: some unfiltered negative PAERO at STEP=",I5)') NSTEP
!    CALL ABOR1("RADLSWR: some PAERO negative : STOP")
!  ENDIF
!ENDIF





!          1.1    INITIALISATION OF FLUXES AND DIAGNOSTIC OUTPUT FIELDS 
!                 -----------------------------------------------------

ZRG=1.0_JPRB/RG
ZFCUP(:,:) = 0.0_JPRB
ZFSUP(:,:) = 0.0_JPRB
ZFCDWN(:,:) = 0.0_JPRB
ZFSDWN(:,:) = 0.0_JPRB
ZFCDWN(:,KLEV+1)=REPLOG
ZFSDWN(:,KLEV+1)=REPLOG
ZFLUX(:,:,:) = 0.0_JPRB
ZFLUC(:,:,:) = 0.0_JPRB
ZFSUX(:,:,:) = 0.0_JPRB
ZFSUC(:,:,:) = 0.0_JPRB
ZFSDNN(:) = 0.0_JPRB
ZFSDNV(:) = 0.0_JPRB
ZFCDNN(:) = 0.0_JPRB
ZFCDNV(:) = 0.0_JPRB
ZFSUPN(:) = 0.0_JPRB
ZFSUPV(:) = 0.0_JPRB
ZFCUPN(:) = 0.0_JPRB
ZFCUPV(:) = 0.0_JPRB

ZPSOL(KIDIA:KFDIA) = PAPH(KIDIA:KFDIA,KLEV+1)
ZPMB(KIDIA:KFDIA,1) = ZPSOL(KIDIA:KFDIA) *0.01_JPRB
ZDT0(KIDIA:KFDIA) = PTS(KIDIA:KFDIA) - PTH(KIDIA:KFDIA,KLEV+1)
ZEMIT(:) = 0.0_JPRB
ZSUDU(:) = 0.0_JPRB
PSUDU(:) = 0.0_JPRB
PUVDF(:) = 0.0_JPRB
PPARF(:) = 0.0_JPRB
PPARCF(:)= 0.0_JPRB
ZEMIS(:) = PEMIS(:)
ZEMIW(:) = PEMIW(:)
ZMU0(:)  = PMU0(:)

!define LAT/LON in degre

ZRPI=1.0_JPRB/RPI
DO JL=KIDIA,KFDIA
  ZLAT(JL) = ASIN(PGEMU(JL))
  ZGLAT(JL)= ZLAT(JL) * 180._JPRB*ZRPI
  ZGLON(JL)=PGELAM(JL)*180._JPRB*ZRPI
ENDDO
!     -------------------------------------------------------------------------

!*         1.2    CALL to MAC-SP anthropogenic simple plume model
!                 --------------------------------------------------------

!!!!! Further optimisation of the code:
!!!!! introduce the JPIM/JPRB into sp_aop_profile
!    IF (NSTEP == 0) THEN
! Initialisation of MAC2SP outputs arrays
ZMAC2SP_ASY(1:KLON,1:KLEV,1:MAC2SP_NLAMDA)= 0.001_JPRB
ZMAC2SP_SSA(1:KLON,1:KLEV,1:MAC2SP_NLAMDA)= 1.000_JPRB
ZMAC2SP_AOD(1:KLON,1:KLEV,1:MAC2SP_NLAMDA)= 0.001_JPRB
ZMAC2SP_CDNC_FACTOR(1:KLON)= 1._JPRB
!  ENDIF

IF (LMAC2SP) THEN
      
  ! prepare year fraction
  IF(.NOT.LNF.AND.NSTADD == 0) THEN
     ! IN CASE OF RESTART:
     ITIME=NINT(TSTEP,KIND(ITIME))
     IF (LTWOTL) THEN
        IZT=NINT(TSTEP*(REAL(NSTAR2,JPRB)+0.5_JPRB),KIND(IZT))
     ELSE
        IZT=INT(ITIME,KIND(IZT))*INT(NSTAR2,KIND(IZT))
     ENDIF
     ISTADD=INT(IZT/NINT(RDAY,KIND(IZT)),KIND(ISTADD))
  ELSE
     ISTADD=NSTADD
  ENDIF

  IYR0=NCCAA(NINDAT)
  IMN0=NMM(NINDAT)
  IDY0=NDD(NINDAT)

  CALL UPDCAL(IDY0,IMN0,IYR0, ISTADD, IDY,IMN,IYR, ILMONTH, NULOUT)

  ! Day number and total number of days for that year
  CALL NUMBER_OF_DAY(IDY,IMN,IYR,IDOY)

  IF(MOD(IYR,4) == 0 .AND. MOD(IYR,400) /= 100 &
       & .AND. MOD(IYR,400) /= 200 .AND. MOD(IYR,400) /= 300)THEN  
     KNDY=366._JPRB
  ELSE
     KNDY=365._JPRB
  ENDIF
  
  ! Replace IYR with NCMIPFIXYR
  IF (NCMIPFIXYR>0) IYR=NCMIPFIXYR  
  
  ! Limit IYR to available dataset
  IYR =  MIN(MAC2SP_YEAR_MAX, MAX(MAC2SP_YEAR_MIN, IYR))
  
  YEAR_FR = IYR + (REAL(IDOY,JPRB) - 0.5_JPRB)/KNDY
    
  DO ILAMDA = 1, MAC2SP_NLAMDA

     CALL SP_AOP_PROFILE (KLEV ,KIDIA ,KFDIA ,KLON ,MAC2SP_LAMDA(ILAMDA) ,ZGLON ,ZGLAT ,YEAR_FR ,PGEOH ,ZMAC2SP_CDNC_FACTOR ,AOD_MAC2SP ,SSA_MAC2SP ,ASY_MAC2SP )

     !put back the profiles on the actual model levels
     DO JK=1,KLEV
        DO JL=KIDIA,KFDIA
           ZMAC2SP_AOD(JL,JK,ILAMDA) = AOD_MAC2SP(JL,KLEV+1-JK)
           ZMAC2SP_SSA(JL,JK,ILAMDA) = SSA_MAC2SP(JL,KLEV+1-JK)
           ZMAC2SP_ASY(JL,JK,ILAMDA) = ASY_MAC2SP(JL,KLEV+1-JK)
        END DO
     END DO
  END DO ! Loop on LAMDA

  !ELSE

   !! DIAGNOSTIC OUTPUTS FOR DEBUGGING
  !     DO JK=1,KLEV
  !       DO JL=KIDIA,KFDIA
  !!        IF (NSTEP == 4 .and. ZGLON(JL) <= 22.5 .and. ZGLON(JL) > 22.4 .and. ZGLAT(JL) <= 45.7 .and. ZGLAT(JL) >= 45.6) THEN
  !        IF (JK == KLEV-5) THEN
  !          WRITE(NULOUT,'(A,2(1X,F8.3),3(1X,E12.5))') 'XXXXXXXX', ZGLON(JL), ZGLAT(JL), ZMAC2SP_AOD(JL,KLEV-5,10), ZMAC2SP_SSA(JL,KLEV-5,10), ZMAC2SP_ASY(JL,KLEV-5,10)
  !!          WRITE(NULOUT,'(A,2(1X,F8.3),1(1X,E12.5,1X),A)') 'XXXXXXXX', ZGLON(JL), ZGLAT(JL), ZMAC2SP_AOD(JL,KLEV-12,10), 'YYYYYYYY'
  !!          WRITE(6,'(A,2(1X,F8.3),3(1X,E12.5))') 'XXXXXXXX', ZGLON(JL), ZGLAT(JL), PGEOH(JL,JK+1), ZMAC2SP_AOD(JL,JK,10)
  !        ENDIF
  !
  !!!        IF (ZMAC2SP_AOD(JL,KLEV,1) > 10. .or. ZMAC2SP_AOD(JL,KLEV,1) < 0.) THEN
  !!!           print *, '============================================================================================================================================'
  !!!           print *, 'ZMAC2SP_AOD= ',ZMAC2SP_AOD(JL,KLEV,1), ' JL= ',JL, ' Lon= ',ZGLON(JL) ,' Lat= ',ZGLAT(JL),'PGEOH= ',PGEOH (JL,KLEV+1),' YEAR_FR= ',YEAR_FR
  !!!           print *, '============================================================================================================================================'
  !!!        ENDIF
  !       END DO   
  !     END DO
  !! END DIAGNOSTIC OUTPUTS FOR DEBUGGING
  
  !ENDIF

  ! Double radiation
  IF (LZEROAERO) THEN
     ZMAC2SP_AOD(KIDIA:KFDIA,1:KLEV,1:MAC2SP_NLAMDA)= 0._JPRB
     !ZMAC2SP_CDNC_FACTOR(KIDIA:KFDIA)= 1._JPRB
  END IF
  
ENDIF  ! END LMAC2SP


!! DIAGNOSTIC OUTPUTS FOR DEBUGGING
!     DO JK=1,KLEV
!       DO JL=KIDIA,KFDIA
!!        IF (NSTEP == 4 .and. ZGLON(JL) <= 22.5 .and. ZGLON(JL) > 22.4 .and. ZGLAT(JL) <= 45.7 .and. ZGLAT(JL) >= 45.6) THEN
!        IF (NSTEP == 4 .and. JK == KLEV-5) THEN
!          WRITE(NULOUT,'(A,2(1X,F8.3),3(1X,E12.5))') 'XXXXXXXX', ZGLON(JL), ZGLAT(JL), ZMAC2SP_AOD(JL,KLEV-5,10), ZMAC2SP_SSA(JL,KLEV-5,10), ZMAC2SP_ASY(JL,KLEV-5,10)
!!          WRITE(NULOUT,'(A,2(1X,F8.3),1(1X,E12.5,1X),A)') 'XXXXXXXX', ZGLON(JL), ZGLAT(JL), ZMAC2SP_AOD(JL,KLEV-12,10), 'YYYYYYYY'
!!          WRITE(6,'(A,2(1X,F8.3),3(1X,E12.5))') 'XXXXXXXX', ZGLON(JL), ZGLAT(JL), PGEOH(JL,JK+1), ZMAC2SP_AOD(JL,JK,10)
!        ENDIF

!!        IF (ZMAC2SP_AOD(JL,KLEV,1) > 10. .or. ZMAC2SP_AOD(JL,KLEV,1) < 0.) THEN
!!           print *, '============================================================================================================================================'
!!           print *, 'ZMAC2SP_AOD= ',ZMAC2SP_AOD(JL,KLEV,1), ' JL= ',JL, ' Lon= ',ZGLON(JL) ,' Lat= ',ZGLAT(JL),'PGEOH= ',PGEOH (JL,KLEV+1),' YEAR_FR= ',YEAR_FR
!!           print *, '============================================================================================================================================'
!!        ENDIF
!       END DO   
!     END DO
!! END DIAGNOSTIC OUTPUTS FOR DEBUGGING



IF (LCMIP6_PI_AEROSOLS) THEN
   IF (LPI_AERO_UPDATED) THEN

      CALL  CMIP6_PIAER_INTERP (  KIDIA,  KFDIA,  KLON, KLEV, 1 , 0,&
                            &     PAPH,   PGELAM, PGEMU, &
                            &     ZAODPI, ZSSAPI, ZASFPI )

      PI_AOD(KIDIA:KFDIA,:,:,KBL) = ZAODPI(KIDIA:KFDIA,:,:)
      PI_ABS(KIDIA:KFDIA,:,:,KBL) = ZSSAPI(KIDIA:KFDIA,:,:)
      PI_XASY(KIDIA:KFDIA,:,:,KBL)= ZASFPI(KIDIA:KFDIA,:,:)
      
      !! DIAGNOSTIC OUTPUTS FOR DEBUGGING
      !     DO JK=1,KLEV
      !       DO JL=KIDIA,KFDIA
      !        IF (NSTEP == 0) THEN
      !          WRITE(NULOUT,'(A,2(1X,F8.3),3(1X,E12.5))') 'DDDDDDDDD', ZGLON(JL), ZGLAT(JL), PAPH(JL,1), PAPH(JL,KLEV), PAPH(JL,KLEV-5)
      !        ENDIF
      !        IF (NSTEP == 4 .AND. JK == KLEV-7 ) THEN
      !          WRITE(NULOUT,'(A,2(1X,F8.3),3(1X,E12.5))') 'YYYYYYYY', ZGLON(JL), ZGLAT(JL), ZAODPI(JL,KLEV-7,4), ZSSAPI(JL,KLEV-7,4), ZASFPI(JL,KLEV-7,4)  
      !        ENDIF
      !       END DO   
      !     END DO
      !! END DIAGNOSTIC OUTPUTS FOR DEBUGGING
      
      !        ZAODPI(:,:,:) =0.001_JPRB   !!! ATTENTION PLEASE PLUG HERE THE ACTUAL PRE-INDUSTRIAL AEROSOL FIELDS
      !        ZSSAPI(:,:,:) =0.000_JPRB   !!! ATTENTION PLEASE PLUG HERE THE ACTUAL PRE-INDUSTRIAL AEROSOL FIELDS
      !        ZASFPI(:,:,:) =0.0001_JPRB   !!! ATTENTION PLEASE PLUG HERE THE ACTUAL PRE-INDUSTRIAL AEROSOL FIELDS
      !! END DIAGNOSTIC OUTPUTS FOR DEBUGGING
         
   ELSE
      ! no new TM5 data, use the last computed values
      ZAODPI(KIDIA:KFDIA,:,:) = PI_AOD(KIDIA:KFDIA,:,:,KBL)
      ZSSAPI(KIDIA:KFDIA,:,:) = PI_ABS(KIDIA:KFDIA,:,:,KBL)
      ZASFPI(KIDIA:KFDIA,:,:) = PI_XASY(KIDIA:KFDIA,:,:,KBL)
   ENDIF

   ! Double radiation
   IF (LZEROAERO) THEN
      ZAODPI(KIDIA:KFDIA,1:KLEV,:) = 0._JPRB
      ZSSAPI(KIDIA:KFDIA,1:KLEV,:) = 0._JPRB
      ZASFPI(KIDIA:KFDIA,1:KLEV,:) = 0._JPRB
   END IF
ENDIF

!     -------------------------------------------------------------------------
!          1.2 bis Use CMIP6 stratospheric aerosols [lat,alt,wave_bands,time]
!     -------------------------------------------------------------------------

IF (LCMIP6_STRATAER_FULL) THEN
   IF (LSTRATAERO_UPDATED) THEN
      
      ! Read the data, only one time per month
      CALL  CMIP6_STRATO_AERO_INTERP (  KIDIA,  KFDIA,  KLON, KLEV, 1 , 0,  &
                            &     PAPH,   PGELAM, PGEMU,                    &
                            &     ZAODSTRAT_M, ZAAODSTRAT_M, ZREFAODSTRAT_M, ZAAODSTRAT_LW_M)

      STRAT_AOD(KIDIA:KFDIA,:,:,:,KBL) = ZAODSTRAT_M(KIDIA:KFDIA,:,:,:)
      STRAT_AAOD(KIDIA:KFDIA,:,:,:,KBL) = ZAAODSTRAT_M(KIDIA:KFDIA,:,:,:)
      STRAT_REFAOD(KIDIA:KFDIA,:,:,:,KBL)= ZREFAODSTRAT_M(KIDIA:KFDIA,:,:,:)
      STRAT_AAOD_LW(KIDIA:KFDIA,:,:,:,KBL) = ZAAODSTRAT_LW_M(KIDIA:KFDIA,:,:,:)
      
   ELSE

!! DIAGNOSTIC OUTPUTS FOR DEBUGGING
!   DO JK=1,KLEV
!     DO JL=KIDIA,KFDIA
!       IF (NSTEP == 4 .AND. JK == KLEV-7 ) THEN
!         WRITE(NULOUT,*) 'STRATAERO:',ZGLON(JL), ZGLAT(JL),&
!         ZAODSTRAT_M(JL,KLEV-70,4,1), ZAAODSTRAT_M(JL,KLEV-70,4,1),&
!         ZREFAODSTRAT_M(JL,KLEV-70,4,1), ZAAODSTRAT_LW_M(JL,KLEV-70,4,1)   
!       ENDIF
!     END DO   
!   END DO
!! END DIAGNOSTIC OUTPUTS FOR DEBUGGING

      ! no new data, use the last computed values
      ZAODSTRAT_M(KIDIA:KFDIA,:,:,:) = STRAT_AOD(KIDIA:KFDIA,:,:,:,KBL)
      ZAAODSTRAT_M(KIDIA:KFDIA,:,:,:) = STRAT_AAOD(KIDIA:KFDIA,:,:,:,KBL)
      ZREFAODSTRAT_M(KIDIA:KFDIA,:,:,:) = STRAT_REFAOD(KIDIA:KFDIA,:,:,:,KBL)
      ZAAODSTRAT_LW_M(KIDIA:KFDIA,:,:,:) = STRAT_AAOD_LW(KIDIA:KFDIA,:,:,:,KBL)
   ENDIF

   ! Time interpolation and excluding the data below the tropopause, each timestep.
   CALL CMIP6_STRATO_AERO_PROCESS (KIDIA, KFDIA, KLON, KLEV, 1 , 0,                      &
                        &     NINDAT, NSTADD,                                            &
                        &     PAP, PAPH, PT, PTH, ZGLAT, PGELAM,                         &
                        &     ZAODSTRAT_M, ZAAODSTRAT_M, ZREFAODSTRAT_M, ZAAODSTRAT_LW_M,&
                        &     ZAODSTRAT, ZAAODSTRAT, ZREFAODSTRAT, ZAAODSTRAT_LW, KTROPPAUSE)

   ! Double radiation
   IF (LZEROAERO) THEN
     ZAODSTRAT(KIDIA:KFDIA,1:KLEV,:) = 0._JPRB
     ZAAODSTRAT(KIDIA:KFDIA,1:KLEV,:) = 0._JPRB
     ZREFAODSTRAT(KIDIA:KFDIA,1:KLEV,:) = 0._JPRB
     ZAAODSTRAT_LW(KIDIA:KFDIA,1:KLEV,:) = 0._JPRB     
   ENDIF

ENDIF

!! DIAGNOSTIC OUTPUTS FOR DEBUGGING
!   !DO JK=1,KLEV
!     DO JL=KIDIA,KFDIA
!       IF (NSTEP == 0 .AND. JL == 1) THEN
!         WRITE(NULOUT,*) 'STRATAERO before process:',ZGLON(JL),ZGLAT(JL)
!         WRITE(NULOUT,*) 'ZAODSTRAT_M(1,:,6,2)=',ZAODSTRAT_M(JL,:,6,2)
!         WRITE(NULOUT,*) 'ZAAODSTRAT_M(1,:,6,2)=',ZAAODSTRAT_M(JL,:,6,2)
!         WRITE(NULOUT,*) 'ZREFAODSTRAT_M(1,:,6,2)=',ZREFAODSTRAT_M(JL,:,6,2)
!         WRITE(NULOUT,*) 'ZAAODSTRAT_LW_M(1,:,6,2)=',ZAAODSTRAT_LW_M(JL,:,6,2)
!         WRITE(NULOUT,*) 'STRATAERO after process:',ZGLON(JL), ZGLAT(JL)
!         WRITE(NULOUT,*) 'ZAODSTRAT(1,:,6)=',ZAODSTRAT(JL,:,6)
!         WRITE(NULOUT,*) 'ZAAODSTRAT(1,:,6)=',ZAAODSTRAT(JL,:,6)
!         WRITE(NULOUT,*) 'ZREFAODSTRAT(1,:,6)=',ZREFAODSTRAT(JL,:,6)
!         WRITE(NULOUT,*) 'ZAAODSTRAT_LW(1,:,6)=',ZAAODSTRAT_LW(JL,:,6)
!         WRITE(NULOUT,*) 'PAP(1,:)=',PAP(JL,:)
!       ENDIF
!     END DO   
!   !END DO
!   WRITE(NULOUT,*) 'KLON=',KLON
!   WRITE(NULOUT,*) 'KIDIA=',KIDIA
!   WRITE(NULOUT,*) 'KFDIA=',KFDIA
   !PRINT*,'RADLSWR.F90: ZGLAT=',ZGLAT
!! END DIAGNOSTIC OUTPUTS FOR DEBUGGING

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

!*         1.3    SET-UP INPUT QUANTITIES FOR ALL RADIATION CONFIGURATIONS
!                 --------------------------------------------------------

!-- in-cloud ice and water mixing ratios; cloud ice and liquid contents and paths

DO JK=1,KLEV
  IJK=KLEV+1-JK
  DO JL=KIDIA,KFDIA
    ZCLFR(JL,JK)   = PCLFR(JL,JK)
    ZCLDSW(JL,IJK) = PCLFR(JL,JK)
    ZCLDLW(JL,IJK) = PCLFR(JL,JK)
    ZETA(JL,JK) =PAP(JL,JK)/PAPH(JL,KLEV+1)
    IF (PCLFR(JL,JK) >= 0.001_JPRB) THEN
      ZTEMP=1.0_JPRB/PCLFR(JL,JK)
      ZQIWP(JL,JK)=MAX(0._JPRB, PQIWP(JL,JK)*ZTEMP)
      ZQSWP(JL,JK)=MAX(0._JPRB, PQSWP(JL,JK)*ZTEMP)
! RMF SENS 20091223 Set snow to zero
!      ZQSWP(JL,JK)=0._JPRB
      ZQLWP(JL,JK)=MAX(0._JPRB, PQLWP(JL,JK)*ZTEMP)
      ZQRWP(JL,JK)=MAX(0._JPRB, PQRWP(JL,JK)*ZTEMP)
! RMF SENS 20100224 Set rain to zero
!      ZQRWP(JL,JK)=0._JPRB
      ZIWGKG=ZQIWP(JL,JK)*1000._JPRB
      ZSWGKG=ZQSWP(JL,JK)*1000._JPRB
      ZLWGKG=ZQLWP(JL,JK)*1000._JPRB 
      ZRWGKG=ZQRWP(JL,JK)*1000._JPRB 
    ELSE
      ZCLFR(JL,JK)=0._JPRB
      ZQIWP(JL,JK)=0._JPRB
      ZQSWP(JL,JK)=0._JPRB
      ZQLWP(JL,JK)=0._JPRB
      ZQRWP(JL,JK)=0._JPRB
      ZIWGKG=0._JPRB
      ZSWGKG=0._JPRB
      ZLWGKG=0._JPRB
      ZRWGKG=0._JPRB
    ENDIF
!    ZRWGKG=0._JPRB
    ZRAINT(JL)=0._JPRB
    ZDPOG=PDP(JL,JK)*ZRG
    ZFIWP(JL,JK) = ZIWGKG*ZDPOG
    ZFSWP(JL,JK) = ZSWGKG*ZDPOG
    ZFLWP(JL,JK) = ZLWGKG*ZDPOG
    ZFRWP(JL,JK) = ZRWGKG*ZDPOG
    ZPODT = PAP(JL,JK)/(RD*PT(JL,JK))
    ZRHO(JL,JK) = ZPODT 
    ZIWC(JL,JK) = ZIWGKG*ZPODT
    ZSWC(JL,JK) = ZSWGKG*ZPODT
    ZLWC(JL,JK) = ZLWGKG*ZPODT
    ZRWC(JL,JK) = ZRWGKG*ZPODT
  ENDDO
ENDDO


DO JL=KIDIA,KFDIA
  ZPS(JL)=PAPH(JL,KLEV+1)
  ZCLAT(JL)= COS(ZLAT(JL))
  IF (NDECOLAT == 0) THEN
    ZDECORR_CF(JL)=RDECORR_CF
    ZDECORR_CW(JL)=RDECORR_CW
  ELSEIF (NDECOLAT == 1) THEN
    ZDECORR_CF(JL)=2.899_JPRB-0.02759_JPRB*ABS(ZGLAT(JL))
    ZDECORR_CW(JL)=ZDECORR_CF(JL)*0.5_JPRB
  ELSEIF (NDECOLAT == 2) THEN
    ZDECORR_CF(JL)=0.75_JPRB + 2.149_JPRB*ZCLAT(JL)*ZCLAT(JL)
    ZDECORR_CW(JL)=ZDECORR_CF(JL)*0.5_JPRB
  ENDIF 
ENDDO

!-- by default, use the climatological aerosols adapted from Tegen et al. 1997

!-- climatological aerosols
!   1 = land   = organic + sulphate
!   2 = sea    = sea salt
!   3 = desert = dust
!   4 = urban  = black carbon
!   5 = volcanic
!   6 = stratospheric background

DO JAER=1,6
  DO JK=1,KLEV
    DO JL=KIDIA,KFDIA
      ZAER(JL,JAER,JK)=PAER(JL,JAER,JK)
    ENDDO
  ENDDO
ENDDO
IRADLP=NRADLP

! Double radiation
IF (LZEROAERO) THEN
   ZAER(KIDIA:KFDIA,1:6,1:KLEV)=0._JPRB
END IF
   
!-- otherwise, use the prognostic aerosols for computing the effective size 
!   of cloud particles and/or in the computation of aerosol optical thickness

!-- prognostic aerosols
!  PAERO are entered in kg/kg
!  ZMAER are in ug / m3              ( micrograms per m**3 )
!  ZCNN  are in 1/cm3
!  Menon et al., 2002: JAS, 59, 692-713 Eqns 1a, 1b

IACTAERO = NACTAERO

!-- first aerosol indirect effect: the relevant prognostic aerosols 
!   (OM, SS, SU) are used as cloud condensation nuclei further used
!   to determine the effective radius of droplets in LIQUID water 
!   clouds 
IF ( IACTAERO >= 12 .AND. NAERCLD > 0 ) THEN
  IRADLP=3 
  JAERSS=1
  JAEROM=2
  JAERBC=3
  JAERSU=4
  JAERDD=5
  ZMAERMN(JAERSS)=2.12E-10_JPRB*1.E9_JPRB 
  ZMAERMN(JAERDD)=1.01E-09_JPRB*1.E9_JPRB
  ZMAERMN(JAEROM)=3.05E-11_JPRB*1.E9_JPRB
  ZMAERMN(JAERBC)=3.05E-11_JPRB*1.E9_JPRB
  ZMAERMN(JAERSU)=1.02E-09_JPRB*1.E9_JPRB
  DO JK=1,KLEV
    DO JL=KIDIA,KFDIA
!-- 1st bin of SS
      ZMAER(JL,JK,1) = ZAERO(JL,JK, 1)*ZRHO(JL,JK)*1.E9_JPRB
!-- hydrophilic OM
      ZMAER(JL,JK,2) = ZAERO(JL,JK, 7)*ZRHO(JL,JK)*1.E9_JPRB
!-- hydrophilic BC
      ZMAER(JL,JK,3) = ZAERO(JL,JK, 9)*ZRHO(JL,JK)*1.E9_JPRB
!-- SO4
      ZMAER(JL,JK,4) = ZAERO(JL,JK,12)*ZRHO(JL,JK)*1.E9_JPRB
!-- 1 st bin of DD
      ZMAER(JL,JK,5) = ZAERO(JL,JK, 4)*ZRHO(JL,JK)*1.E9_JPRB
      ZCCN0      = 10.0_JPRB**(2.41+&
! CCNxx factors: for org.matter 0.13, sea salt 0.05, and sulphate 0.50
                    & RCDNCOM*LOG10(MAX(ZMAER(JL,JK,JAEROM),REPSCA)) +&
                    & RCDNCSS*LOG10(MAX(ZMAER(JL,JK,JAERSS),REPSCA)) +&
                    & RCDNCSU*LOG10(MAX(ZMAER(JL,JK,JAERSU),REPSCA)) )
      ZCCN(JL,JK) = MAX ( ZCCN0, 50._JPRB)
!-- ZRE_LIQ for subsequent radiative computations (in um once multiplied by 1.E+06)
      ZRE_LIQ(JL,JK) = 1.E+06_JPRB*(2.387e-10_JPRB*ZRHO(JL,JK)*ZQLWP(JL,JK)/ZCCN(JL,JK))**0.333_JPRB
    ENDDO
    IF (NSTEP == NSTART) THEN
      WRITE(NULOUT,8002) JK,(JL,ZCCN(JL,JK),ZRE_LIQ(JL,JK),ZRHO(JL,JK),JL=KIDIA,KFDIA,10)
8002  format(1x,'radlswr CCN RE_LIQ RHO:',I3,5(2X,I2,3E10.3))
    ENDIF
  ENDDO
ENDIF

!-- direct effect of aerosols: The prognostic aerosols are used to compute the 
!   optical thickness at 550 nm for the aerosol types recognized by the 
!   radiation scheme
IF ( IACTAERO >= 12 .AND. LAERRAD) THEN
!  WRITE(NULOUT,9003)
9003 format(1X,'about to enter AER_RAD from RADLSWR')
  INWAVL=1
  ITWAVL(:)=0
  ITWAVL(1)=9

  CALL AER_RAD ( &
   & KIDIA, KFDIA, KLON, 1 , KLEV , IACTAERO, INWAVL, ITWAVL, NSTART, NSTEP, &
   & PAP  , PAPH , PQ  , PT, ZAERO, &
   & ZTAUAER , ZOMGAER , ZASYAER  )

!  WRITE(NULOUT,9004)
9004 format(1X,'just coming out of AER_RAD in RADLSWR')


! NB: ZTAUAER have SS, DD, OM, BC, SU, Strat in that order and have to be
!     redistributed over the proper "radiative" aerosols
!
!     1 = land   = organic + sulphate
!     2 = sea    = sea salt
!     3 = desert = dust
!     4 = urban  = black carbon
!     5 = volcanic
!     6 = stratospheric background
!
!  In present configuration of prognostic aerosols, types 5 (volcanic =0.)
!     and 6 (stratospheric background) are still given by climatology.
!

  IF (LAEROPT(3)) THEN
    DO JK=1,KLEV
      DO JL=KIDIA,KFDIA
        ZAER(JL,1,JK)=ZTAUAER(JL,3,JK)                  ! organic
      ENDDO
    ENDDO
  ENDIF
  IF (LAEROPT(5)) THEN
    DO JK=1,KLEV
      DO JL=KIDIA,KFDIA
        ZAER(JL,1,JK)=ZTAUAER(JL,5,JK)                  ! sulphate
      ENDDO
    ENDDO
  ENDIF
  IF (LAEROPT(3).AND.LAEROPT(5)) THEN
    DO JK=1,KLEV
      DO JL=KIDIA,KFDIA
        ZAER(JL,1,JK)=ZTAUAER(JL,3,JK)+ZTAUAER(JL,5,JK) ! organic + sulphate
      ENDDO
    ENDDO
  ENDIF
  IF (LAEROPT(1)) THEN                                  !  sea salt
    DO JK=1,KLEV
      DO JL=KIDIA,KFDIA
        ZAER(JL,2,JK)=ZTAUAER(JL,1,JK)
      ENDDO
    ENDDO
  ENDIF
  IF (LAEROPT(2)) THEN                                  ! desert dust
    DO JK=1,KLEV
      DO JL=KIDIA,KFDIA
        ZAER(JL,3,JK)=ZTAUAER(JL,2,JK)
      ENDDO
    ENDDO
  ENDIF
  IF (LAEROPT(4)) THEN                                  ! black carbon
    DO JK=1,KLEV
      DO JL=KIDIA,KFDIA
        ZAER(JL,4,JK)=ZTAUAER(JL,4,JK)
      ENDDO
    ENDDO
  ENDIF
ENDIF

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

!*         1.4    EFFECTIVE RADII AND PARTICLE SIZE
!                 ---------------------------------

ZRefDe = RRe2De 
ZDefRe = 1.0_JPRB / ZRefDe

DO JL=KIDIA,KFDIA
  IF (NMINICE == 0) THEN
    ! Constant ice effective radius
    ZMINICE(JL) = RMINICE
  ELSEIF (NMINICE >= 1) THEN
    ! Ice effective radius varies with latitude, smaller at poles
    ZMINICE(JL) = 20._JPRB+40._JPRB*ZCLAT(JL)
  ENDIF
ENDDO


! set constants used for Martin et al r_eff parameterisation
IF (IRADLP == 2) THEN
  ! Spectral dispersion (d) of the droplet size distribution
  ! ZD=0.43_JPRB (land)
  ! ZD=0.33_JPRB (sea)
  ! Constant (k) relating volume radius to effective radius rv^3=k*re^3
  ! k = (1.0+ZD*ZD)^3)/((1.0+3.0*ZD*ZD)^2)
  ! ZK=(1.0_JPRB+ZD*ZD)**3/(1.0_JPRB+3.0_JPRB*ZD*ZD)**2
  ZKSEA=0.77_JPRB
  ZKLAND=0.69_JPRB
  ! MIN() is needed here because PLSM can become slightly larger than 1
  ! after the mapping on the radiation grid
  ZK(:)=(1._JPRB-MIN(PLSM(:),1._JPRB))*ZKSEA+MIN(PLSM(:),1._JPRB)*ZKLAND

  ! constants for drizzle adjustment to Martin_et_al(1994) effective radius 
  ! from Wood(2000) param (Eq. 19)
  ZKL       = 0.222_JPRB
  ZKRATIO(:)= (ZKL/ZK(:))**0.333_JPRB
ENDIF

IF (NCLOUDACT>0) THEN
  ! set default CDNC at first timestep and check minimum value at later times
  IF (NSTEP.EQ.0) THEN
    ZCDNC(KIDIA:KFDIA,:)=PPDEFCDNC
  ELSE
    ZCDNC(KIDIA:KFDIA,:)=MAX(PPMINCDNC,PCDNC(KIDIA:KFDIA,:))
  ENDIF
ENDIF

DO JK=1,KLEV
  DO JL = KIDIA,KFDIA
    ! --- EFFECTIVE RADIUS FOR WATER, ICE AND RAIN PARTICLES

    IF (IRADLP == 0) THEN
!-- very old parametrization as f(pressure) ERA-15
      ZRADLP(JL)=10.0_JPRB + (100000.0_JPRB-PAP(JL,JK))*3.5_JPRB

    ELSEIF (IRADLP == 1) THEN
!-- simple distinction between land (10) and ocean (13) Zhang and Rossow
      IF (PLSM(JL) < 0.5_JPRB) THEN
        ZRADLP(JL)=13.0_JPRB
      ELSE
        ZRADLP(JL)=10.0_JPRB
      ENDIF

    ELSEIF (IRADLP == 2) THEN
!-- based on Martin et al., 1994, JAS
      IF (NCLOUDACT==0) THEN
        IF (PLSM(JL) < 0.5_JPRB) THEN
          IF (LCCNO) THEN
            !           ZASEA=50.0_JPRB
            ZASEA=PCCNO(JL)
          ELSE  
            ZASEA=RCCNSEA
          ENDIF

          ! Spectral dispersion of the droplet size distribution over sea 
          ! ZD = 0.33_JPRB
          ! Constant (k) relating volume radius to effective radius rv^3=k*re^3
          ! k = (1.0+ZD*ZD)^3)/((1.0+3.0*ZD*ZD)^2)
          ! ZK=(1.0_JPRB+ZD*ZD)**3/(1.0_JPRB+3.0_JPRB*ZD*ZD)**2
          ZK(JL) = 0.77_JPRB

          ! Cloud droplet concentration in cm-3 (activated CCN) over ocean
          ZNTOT=-1.15E-03_JPRB*ZASEA*ZASEA+0.963_JPRB*ZASEA+5.30_JPRB

          IF (LMAC2SPACI) ZNTOT = ZNTOT*ZMAC2SP_CDNC_FACTOR(JL)

        ELSE
          IF (LCCNL) THEN 
            ! ZALND=900.0_JPRB
            ZALND=PCCNL(JL)
          ELSE  
            ZALND=RCCNLND
          ENDIF

          ! Spectral dispersion (d) of the droplet size distribution over land 
          ! ZD=0.43_JPRB
          ! Constant (k) relating volume radius to effective radius rv^3=k*re^3
          ! k = (1.0+ZD*ZD)^3)/((1.0+3.0*ZD*ZD)^2)
          ! ZK=(1.0_JPRB+ZD*ZD)**3/(1.0_JPRB+3.0_JPRB*ZD*ZD)**2
          ZK(JL) = 0.69_JPRB

          ! Cloud droplet concentration in cm-3 (activated CCN) over land
          ZNTOT=-2.10E-04_JPRB*ZALND*ZALND+0.568_JPRB*ZALND-27.9_JPRB

          IF (LMAC2SPACI) ZNTOT = ZNTOT*ZMAC2SP_CDNC_FACTOR(JL)

        ENDIF
      ELSE
        ZNTOT=ZCDNC(JL,JK)
      ENDIF

      ! ZNUM=3.0_JPRB*ZLWC(JL,JK)*(1.0_JPRB+3.0_JPRB*ZD*ZD)**2
      ! ZDEN=4.0_JPRB*RPI*ZNTOT*(1.0_JPRB+ZD*ZD)**3
      ! ZTEMP=1.0_JPRB/ZDEN

      ZNUM  = 3.0_JPRB*(ZLWC(JL,JK)+ZRWC(JL,JK))
      ! ZNUM  = 3.0_JPRB*ZLWC(JL,JK)
      ZDEN  = 4.0_JPRB*RPI*ZNTOT*ZK(JL) ! *density of water 1000 kg m-3
      ZTEMP = 1.0_JPRB/ZDEN
      ! So for ZTEMP in SI units
      ! g m-3 and cm-3 units cancel out with density of water 10^6/(1000*1000)
      ! Need a factor of 10^6 to convert to microns 
      ! and cubed root is factor of 100 which appears in ZRADLP equation below

      ! Adjustment to Martin_et_al(1994) effective radius 
      ! from Wood(2000) param (Eq. 19)
      IF (ZLWC(JL,JK) > REPSCW) THEN
        !      IF (ZLWC(JL,JK) > REPSCW .AND. PLSM(JL) < 0.5_JPRB) THEN
        ZRLRATIO  = ZRWC(JL,JK)/ZLWC(JL,JK)
        ZREFACDEN = 1.0_JPRB+0.2_JPRB*ZKRATIO(JL)*ZRLRATIO
        ZREFAC    = ((1.0_JPRB+ZRLRATIO)**0.666_JPRB)/ZREFACDEN
      ELSE
        ZREFAC    = 1.0_JPRB
      ENDIF

      IF((ZNUM*ZTEMP) > REPLOG)THEN

        ! R_eff=100*(ZNUM/ZDEN)^0.333, factor of 100 to convert from m to microns
        ZRADLP(JL)=100._JPRB*ZREFAC*EXP(0.333_JPRB*LOG(ZNUM*ZTEMP))

        ! ZRADLP(JL)=100._JPRB*EXP(0.333_JPRB*LOG(ZNUM*ZTEMP))
        ! ZRADLP(JL)=MAX(ZRADLP(JL), 4.0_JPRB)
        !! ZRADLP(JL)=MIN(ZRADLP(JL),16.0_JPRB)
        ! ZRADLP(JL)=MIN(ZRADLP(JL),30.0_JPRB)

        ! ! Factor of 2
        ! IF (ZQLWP(JL,JK) > 2.0_JPRB*RCLCRIT) THEN
        !   ZRADLP(JL)=2.0_JPRB*100._JPRB*EXP(0.333_JPRB*LOG(ZNUM*ZTEMP))
        ! ELSE
        !   ZRADLP(JL)=100._JPRB*EXP(0.333_JPRB*LOG(ZNUM*ZTEMP))
        ! ENDIF

        ! Limit effective radius to within defined range
        ZRADLP(JL)=MAX(ZRADLP(JL), 4.0_JPRB)
        ZRADLP(JL)=MIN(ZRADLP(JL),30.0_JPRB)
      ELSE
        ZRADLP(JL)=4.0_JPRB
      ENDIF
    ELSEIF (IRADLP == 3) THEN
!-- effective radius of droplets linked to prognostic aerosol 
!   using Memon et al's CCN (see above)
      ZRADLP(JL) = ZRE_LIQ(JL,JK)
      ZRADLP(JL)=MAX(ZRADLP(JL), 4.0_JPRB)
      ZRADLP(JL)=MIN(ZRADLP(JL),16.0_JPRB)
    ENDIF
    ZRADLI(JL,JK)=ZRADLP(JL)    

  ENDDO
END DO

! ice clouds
IF (NCLOUDACT > 0 .AND. (LAERICESED.OR.LAERICEAUTO))  THEN
  DO JK=1,KLEV
    DO JL = KIDIA,KFDIA
      ZRADIC(JL,JK) = MAX(PRE_ICE(JL,JK),40._JPRB)
      ZDESIC(JL,JK)= ZDefRe * ZRADIC(JL,JK)
    END DO
  END DO
ELSE
  DO JK=1,KLEV
    DO JL = KIDIA,KFDIA

! diagnosing the ice particle effective radius/diameter

!- ice particle effective radius =f(T) from Liou and Ou (1994)
 
      IF (PT(JL,JK) < RTICE) THEN
        ZTEMPC=PT(JL,JK)-RTT
      ELSE
        ZTEMPC=RTICE-RTT
      ENDIF
      ZRADIP(JL)=326.3_JPRB+ZTEMPC*(12.42_JPRB + ZTEMPC*(0.197_JPRB + ZTEMPC*&
        & 0.0012_JPRB))    
    
      IF (NRADIP == 0) THEN
!-- fixed 40 micron effective radius
        ZRADIP(JL)= 40.0_JPRB
        ZDESR(JL)= ZdefRe * ZRADIP(JL)
      
      ELSEIF (NRADIP == 1) THEN 
!-- old formulation based on Liou & Ou (1994) temperature (40-130microns)    
        ZRADIP(JL)=MAX(ZRADIP(JL), 40.0_JPRB)
        ZRADIP(JL)=MIN(ZRADIP(JL),130.0_JPRB)
        ZDESR(JL)= ZdefRe * ZRADIP(JL)
      
      ELSEIF (NRADIP == 2) THEN  
!-- formulation following Jakob, Klein modifications to ice content    
        ZRADIP(JL)=MAX(ZRADIP(JL),30.0_JPRB)
        ZRADIP(JL)=MIN(ZRADIP(JL),60.0_JPRB)
        ZDESR(JL)= ZDefRe * ZRADIP(JL)
 
      ELSEIF (NRADIP == 3  ) THEN
!- ice particle effective radius =f(T,IWC) from Sun and Rikus (1999)
! revised by Sun (2001)
        IF (ZIWC(JL,JK)+ZSWC(JL,JK) > 0.0_JPRB ) THEN
          ZTEMPC = PT(JL,JK)-83.15_JPRB
          ZTCELS = PT(JL,JK)-RTT
          ZFSR = 1.2351_JPRB +0.0105_JPRB * ZTCELS
! Sun, 2001 (corrected from Sun & Rikus, 1999)
          ZAIWC = 45.8966_JPRB * (ZIWC(JL,JK)+ZSWC(JL,JK))**0.2214_JPRB
          ZBIWC = 0.7957_JPRB * (ZIWC(JL,JK)+ZSWC(JL,JK))**0.2535_JPRB
          ZDESR(JL) = ZFSR * (ZAIWC + ZBIWC*ZTEMPC)
          ZDESR(JL) = MIN ( MAX( ZDESR(JL), ZMINICE(JL)), 155.0_JPRB)
          ZRADIP(JL)= ZRefDe * ZDESR(JL)
        ELSE
          ZDESR(JL) = 80.0_JPRB
          ZRADIP(JL)= ZRefDe * ZDESR(JL)
        ENDIF  
      ENDIF  
    
      ZRADIC(JL,JK)=ZRADIP(JL)
      ZDESIC(JL,JK)=ZDESR(JL)
    ENDDO
  ENDDO
END IF
 
!     -------------------------------------------------------------------------

!*         2.0    PREPARATION FOR McICA COMPUTATIONS
!                 ----------------------------------

!-- initialise all arrays to zero

! ZFCLW(:,:,:)=0._JPRB
! ZLWFC(:,:,:)=0._JPRB
! ZQILW(:,:,:)=0._JPRB
! ZQLLW(:,:,:)=0._JPRB
! ZTOLW(:,:,:)=0._JPRB

! ZFCSW(:,:,:)=0._JPRB
! ZSWFC(:,:,:)=0._JPRB
! ZQISW(:,:,:)=0._JPRB
! ZQLSW(:,:,:)=0._JPRB
! ZTOSW(:,:,:)=0._JPRB
! ZASSW(:,:,:)=0._JPRB
! ZOMSW(:,:,:)=0._JPRB

IF (NMcICA /= 0) THEN 
!  DO JL=KIDIA,KFDIA  ! Already defined above
!    ZGLON(JL)=PGELAM(JL)*180._JPRB*ZRPI
!  ENDDO



!*         2.1    SPECIFYING THE McICA CONFIGURATION
!                 ----------------------------------

  IF (NMcICA == 1) THEN

!-- equivalent PPH_MAXRAN

    LLCONST_RE= .true.
    LLMAXRAN  = .true.
    LLPPH     = .true.

    DO JK=1,KLEV
      DO JL=KIDIA,KFDIA  
        ZLC_CF(JL,JK) = ZDECORR_CF(JL) ! decorrelation depth for cloud fraction
        ZLC_CW(JL,JK) = ZDECORR_CW(JL) ! decorrelation depth for condensate
        ZSIGQCW(JL,JK)= 0._JPRB
!        ZDROPS(JK) = 100.0_JPRB    ! droplet concentration (cm^-3)
!        ZNUEFF(JK) = 0.1_JPRB      ! effective variance of drop size dist'n
!        ZRELW0(JK)  = 10.0_JPRB    ! droplet effective radius
!        ZREIW0(JK)  = 40.0_JPRB    ! ice crystal effective "radius"
      ENDDO
    ENDDO

  ELSEIF (NMcICA == 2) THEN

!-- equivalent GWTSA with Nu=1

    LLCONST_RE= .true.
    LLMAXRAN  = .false.
    LLPPH     = .false.

    DO JK=1,KLEV
      DO JL=KIDIA,KFDIA
        ZLC_CF(JL,JK) = ZDECORR_CF(JL) ! decorrelation depth for cloud fraction
        ZLC_CW(JL,JK) = ZDECORR_CW(JL) ! decorrelation depth for condensate
        ZSIGQCW(JL,JK)= 1._JPRB
!        ZDROPS(JK) = 0.0_JPRB! droplet concentration (cm^-3)
!        ZNUEFF(JK) = 0.0_JPRB! effective variance of drop size dist'n
!        ZRELW0(JK)  = 10.0_JPRB! droplet effective radius
!        ZREIW0(JK)  = 40.0_JPRB! ice crystal effective "radius"
      ENDDO
    ENDDO
  ENDIF

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

!*         2.2    CLOUD PARAMETERS FOR McICA COMPUTATIONS
!                 ---------------------------------------

! Before starting, copy original cloud fields for RRTM_LW and RRTM_SW
! done on cloud fraction and condensed ice and liquid water

!-- interface for Raisanen, Cole, Barker's cloud generator
!   it works from top to bottom: 
!   inputs are ZCLFR, ZQLWP, ZQIWP, ZQSWP 
!   outputs are ZQL_SL, ZQI_SL, and ICLDLW an index 0 or 1 for each layer and each g-point

!-- call cloud generator to create ICOLS=ICOLSLW for LW computations
  CALL McICA_CLD_GEN &
    &( ZCLFR  , ZQLWP, ZQIWP, ZQSWP, ZLC_CF, ZLC_CW, ZGLAT , ZGLON, &
    & ZSIGQCW, PT   , ZETA , ZPS   , KLON  , KIDIA , KFDIA, KLEV, ICOLSLW, &
    & LLPPH   , LLMAXRAN, &
    & ICLDLW , ZQL_SL, ZQI_SL, ZQS_SL )

  DO JK=1,KLEV
    IJK=KLEV+1-JK
    DO JL=KIDIA,KFDIA
      IF (ICLDLW(JL) /= 0) THEN
        IPRINT(JL,JK)=0
      ENDIF
    ENDDO
    DO JCOLS=1,ICOLSLW
      DO JL=KIDIA,KFDIA
        IF (ICLDLW(JL) /= 0) THEN
          ZFCLW(JL,JCOLS,JK)=0._JPRB
          IF (ZQL_SL(JL,JK,JCOLS)+ZQI_SL(JL,JK,JCOLS)+ZQS_SL(JL,JK,JCOLS) > 0._JPRB) THEN
            IFCLW(JL,JCOLS,JK)=1
            IPRINT(JL,JK)=IPRINT(JL,JK)+IFCLW(JL,JCOLS,JK)
            ZFCLW(JL,JCOLS,JK)=1._JPRB
            ZLWFC(JL,JCOLS,IJK)=1._JPRB
            ZQILW(JL,JCOLS,JK)=ZQI_SL(JL,JK,JCOLS)
            ZQSLW(JL,JCOLS,JK)=ZQS_SL(JL,JK,JCOLS)
            ZQLLW(JL,JCOLS,JK)=ZQL_SL(JL,JK,JCOLS)
          ELSE
            ZLWFC(JL,JCOLS,IJK)=0._JPRB
            ZQILW(JL,JCOLS,JK)=0._JPRB
            ZQSLW(JL,JCOLS,JK)=0._JPRB
            ZQLLW(JL,JCOLS,JK)=0._JPRB
          ENDIF

        ELSE
          ZFCLW(JL,JCOLS,JK)=0._JPRB
          ZLWFC(JL,JCOLS,IJK)=0._JPRB
          ZQILW(JL,JCOLS,JK)=0._JPRB
          ZQSLW(JL,JCOLS,JK)=0._JPRB
          ZQLLW(JL,JCOLS,JK)=0._JPRB
        ENDIF
      ENDDO
    ENDDO
  ENDDO

!-- call cloud generator to create ICOLS=ICOLSSW for SW computations
  CALL McICA_CLD_GEN &
    &( ZCLFR  , ZQLWP, ZQIWP, ZQSWP, ZLC_CF, ZLC_CW, ZGLAT , ZGLON, &
    & ZSIGQCW, PT   , ZETA , ZPS   , KLON  , KIDIA , KFDIA, KLEV, ICOLSSW, &
    & LLPPH   , LLMAXRAN, &
    & ICLDSW , ZQL_SS, ZQI_SS, ZQS_SS )

  DO JK=1,KLEV
    IJK=KLEV+1-JK 
    DO JL=KIDIA,KFDIA
      IF (ICLDSW(JL) /= 0) THEN
        IPRINT(JL,JK)=0
      ENDIF
    ENDDO
    DO JCOLS=1,ICOLSSW
      DO JL=KIDIA,KFDIA
        IF (ICLDSW(JL) /= 0) THEN
!! origianl, maybe wrong 
!!        ZFCSW(JL,JCOLS,IJK)=0._JPRB
!- as for LW
          ZFCSW(JL,JCOLS,JK)=0._JPRB
          IF (ZQL_SS(JL,JK,JCOLS)+ZQI_SS(JL,JK,JCOLS)+ZQS_SS(JL,JK,JCOLS) > 0._JPRB) THEN
            IFCSW(JL,JCOLS,JK)=1
            IPRINT(JL,JK)=IPRINT(JL,JK)+IFCSW(JL,JCOLS,JK)
            ZFCSW(JL,JCOLS,JK)=1._JPRB
            ZSWFC(JL,JCOLS,IJK)=1._JPRB
            ZQISW(JL,JCOLS,JK)=ZQI_SS(JL,JK,JCOLS)
            ZQSSW(JL,JCOLS,JK)=ZQS_SS(JL,JK,JCOLS)
            ZQLSW(JL,JCOLS,JK)=ZQL_SS(JL,JK,JCOLS)
          ELSE
            ZSWFC(JL,JCOLS,IJK)=0._JPRB
            ZQISW(JL,JCOLS,JK)=0._JPRB
            ZQSSW(JL,JCOLS,JK)=0._JPRB
            ZQLSW(JL,JCOLS,JK)=0._JPRB
          ENDIF
        ELSE
          ZFCSW(JL,JCOLS,JK)=0._JPRB
          ZSWFC(JL,JCOLS,IJK)=0._JPRB
          ZQISW(JL,JCOLS,JK)=0._JPRB
          ZQSSW(JL,JCOLS,JK)=0._JPRB
          ZQLSW(JL,JCOLS,JK)=0._JPRB
        ENDIF
      ENDDO
    ENDDO
  ENDDO

  ICLW=140
  ICSW=112

ELSE

!-- normal non-McICA calculations
  ILW16=16
  DO JCLW=1,ILW16
    DO JK=1,KLEV
      IJK=KLEV+1-JK
      DO JL=KIDIA,KFDIA
!        ZCLDLW(JL,IJK)   =PCLFR(JL,JK)
!        ZFCLW(JL,JCLW,JK)=PCLFR(JL,JK)
!        ZQILW(JL,JCLW,JK)=ZQIWP(JL,JK)
!        ZQLLW(JL,JCLW,JK)=ZQLWP(JL,JK)
      ENDDO
    ENDDO
  ENDDO

  ISW14=14   
  DO JCSW=1,ISW14   
    DO JK=1,KLEV  
      IJK=KLEV+1-JK
      DO JL=KIDIA,KFDIA
 !       ZCLDSW(JL,IJK)   =PCLFR(JL,JK)
 !       ZFCSW(JL,JCSW,JK)=PCLFR(JL,JK)
 !       ZQISW(JL,JCSW,JK)=ZQIWP(JL,JK)
 !       ZQLSW(JL,JCSW,JK)=ZQLWP(JL,JK)
      ENDDO
    ENDDO
  ENDDO
ENDIF

LLPRINT=.FALSE.

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

!*         3.0    INITIALIZE VARIOUS OTHER FIELDS
!                 -------------------------------

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

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

!*         3.2    SURFACE ALBEDO
!                 --------------

!-- mapping SW[1:6] surface albedo into albedo for SRTM[1:14]
ISW=14
DO JSW=1,ISW
  ISW14=NMPSRTM(JSW)
  DO JL = KIDIA,KFDIA
    ZSALBD(JL,JSW)=PALBD(JL,ISW14)
    ZSALBP(JL,JSW)=PALBP(JL,ISW14)
  ENDDO
ENDDO

!*        3.3     PUTTING FIELDS UPSIDE DOWN
!                 --------------------------

DO JK = 1 , KLEV
  JKP1 = JK + 1
  JKL = KLEV+ 1 - JK
  JKLP1 = JKL + 1
  DO JL = KIDIA,KFDIA
    ZPMB(JL,JK+1)=PAPH(JL,JKL)*0.01_JPRB

!-- ZOZ in cm.atm for SW scheme    
    ZOZ(JL,JK)   = POZON(JL,JKL) * 46.6968_JPRB *ZRG 
    ZTL(JL,JK)=PTH(JL,JKLP1)
    ZTAVE(JL,JK)=PT(JL,JKL)
  ENDDO
ENDDO

DO JL=KIDIA,KFDIA
  ZTL(JL,KLEV+1)= PTH(JL,1)
  ZPMB(JL,KLEV+1) = PAPH(JL,1)*0.01_JPRB
ENDDO

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

!*         4.     CLOUD AND AEROSOL PARAMETERS FOR REGULAR VERSIONS OF RT CODES
!                 ---------------------------- --------------------------------

IF (NMCICA == 0) THEN 

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

  ZTAUCLD(:,:,:)=0.0_JPRB
  ZSTAUC(:,:,:)= 0.0_JPRB
  ZSOMGC(:,:,:)= 1.0_JPRB
  ZSASYC(:,:,:)= 0.0_JPRB

  ISW14=14

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


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

    DO JSW=1,ISW14
      DO JL = KIDIA,KFDIA
        ZTOL=0.0_JPRB
        ZGL =0.0_JPRB
        ZOL =0.0_JPRB
        ZTOI=0.0_JPRB
        ZGI =0.0_JPRB
        ZOI =0.0_JPRB
        ZTOR=0.0_JPRB
        ZGR =0.0_JPRB
        ZOR =0.0_JPRB
  
        IF (ZFLWP(JL,JK) > REPSCW .OR. ZFIWP(JL,JK) > REPSCW &
     &    .OR. ZFSWP(JL,JK) > REPSCW ) THEN
          IF (ZFLWP(JL,JK) > REPSCW ) THEN
            IF (NLIQOPT /= 0 ) THEN
!-- SW: Slingo, 1989
              ZTOL = ZFLWP(JL,JK)*(RSASWA(JSW)+RSASWB(JSW)/ZRADLI(JL,JK))
              ZGL  = RSASWE(JSW)+RSASWF(JSW)*ZRADLI(JL,JK)
              ZOL  = 1. - RSASWC(JSW)-RSASWD(JSW)*ZRADLI(JL,JK)
            ELSE          
!-- SW: Fouquart, 1991
              ZTOL = ZFLWP(JL,JK)*(RSYFWA(JSW)+RSYFWB(JSW)/ZRADLI(JL,JK))
              ZGL  = RSYFWF(JSW)
              ZOL  = RSYFWC(JSW)-RSYFWD(JSW)*EXP(-RSYFWE(JSW)*ZTOL)
            ENDIF 
          ENDIF
  
          IF ((ZFIWP(JL,JK)+ZFSWP(JL,JK)) > REPSCW ) THEN
            IF (NICEOPT <= 1) THEN
!-- SW: Ebert-Curry          
              ZTOI = (ZFIWP(JL,JK)+ZFSWP(JL,JK))*(RSECIA(JSW)+RSECIB(JSW)/ZRADIC(JL,JK))
              ZGI  = RSECIE(JSW)+RSECIF(JSW)*ZRADIC(JL,JK)
              ZOI  = 1.0_JPRB - RSECIC(JSW)-RSECID(JSW)*ZRADIC(JL,JK)
            
            ELSEIF (NICEOPT == 2) THEN  
!-- SW: Fu-Liou 1993
              Z1RADI = 1.0_JPRB / ZDESIC(JL,JK)
              ZBETAI = RSFLA0(JSW)+Z1RADI* RSFLA1(JSW)
              ZTOI = (ZFIWP(JL,JK)+ZFSWP(JL,JK)) * ZBETAI
              ZOMGI= RSFLB0(JSW)+ZRADIC(JL,JK)*(RSFLB1(JSW) + ZRADIC(JL,JK) &
               & *(RSFLB2(JSW)+ZRADIC(JL,JK)* RSFLB3(JSW) ))              
              ZOI  = 1.0_JPRB - ZOMGI
              ZOMGP= RSFLC0(JSW)+ZRADIC(JL,JK)*(RSFLC1(JSW) + ZRADIC(JL,JK) &
               & *(RSFLC2(JSW)+ZRADIC(JL,JK)* RSFLC3(JSW) ))   
              ZFDEL= RSFLD0(JSW)+ZRADIC(JL,JK)*(RSFLD1(JSW) + ZRADIC(JL,JK) &
               & *(RSFLD2(JSW)+ZRADIC(JL,JK)* RSFLD3(JSW) ))   
              ZGI  = ((1.0_JPRB-ZFDEL)*ZOMGP + ZFDEL*3.0_JPRB) *0.33333_JPRB
            
            ELSEIF (NICEOPT == 3) THEN  
!-- SW: Fu 1996
              Z1RADI = 1.0_JPRB / ZDESIC(JL,JK)
              ZBETAI = RSFUA0(JSW)+Z1RADI* RSFUA1(JSW)
              ZTOI = (ZFIWP(JL,JK)+ZFSWP(JL,JK)) * ZBETAI
              ZOMGI= RSFUB0(JSW)+ZDESIC(JL,JK)*(RSFUB1(JSW) + ZDESIC(JL,JK) &
               & *(RSFUB2(JSW)+ZDESIC(JL,JK)* RSFUB3(JSW) ))              
              ZOI  = 1.0_JPRB - ZOMGI
              ZGI  = RSFUC0(JSW)+ZDESIC(JL,JK)*(RSFUC1(JSW) + ZDESIC(JL,JK) &
               & *(RSFUC2(JSW)+ZDESIC(JL,JK)* RSFUC3(JSW) ))   
              ZGI  = MIN(1.0_JPRB, ZGI) 
            ENDIF
          ENDIF

!  - MIX of WATER and ICE CLOUDS
          ZTAUMX= ZTOL + ZTOI + ZTOR
          ZOMGMX= ZTOL*ZOL + ZTOI*ZOI + ZTOR*ZOR
          ZASYMX= ZTOL*ZOL*ZGL + ZTOI*ZOI*ZGI + ZTOR*ZOR*ZGR
        
          ZASYMX= ZASYMX/ZOMGMX
          ZOMGMX= ZOMGMX/ZTAUMX

! --- SW FINAL CLOUD OPTICAL PARAMETERS

          ZSTAUC(JL,JSW,IJK) = ZTAUMX
          ZSOMGC(JL,JSW,IJK) = ZOMGMX
          ZSASYC(JL,JSW,IJK) = ZASYMX
        ENDIF
      ENDDO
    ENDDO


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

!   -------------------------
! --+ 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

    ILW16=16

    DO JRTM=1,ILW16
      DO JL = KIDIA,KFDIA
        ZRSALD = 0.0_JPRB
        ZRSAID = 0.0_JPRB
        
        IF (ZFLWP(JL,JK)+ZFIWP(JL,JK)+ZFSWP(JL,JK) > REPSCW) THEN
    
          IF (NLIQOPT == 0 .OR. NLIQOPT >= 3) THEN
! water cloud total emissivity a la Smith and Shi (1992)
            ZMULTL=1.2_JPRB-0.006_JPRB*ZRADLI(JL,JK)
            ZRSALD= 0.144_JPRB*ZMULTL * 0.60240_JPRB
            
          ELSEIF (NLIQOPT == 1) THEN
! water cloud spectral emissivity a la Savijarvi (1997)
            ZRSALD= RHSAVI(JRTM,1) + ZRADLI(JL,JK)&
             & *(RHSAVI(JRTM,2) + ZRADLI(JL,JK)*RHSAVI(JRTM,3))  
             
          ELSEIF (NLIQOPT == 2) THEN
! water cloud spectral emissivity a la Lindner and Li (2000)
            Z1RADL = 1.0_JPRB / ZRADLI(JL,JK)
            ZEXTCF = RLILIA(JRTM,1)+ZRADLI(JL,JK)*RLILIA(JRTM,2)+ Z1RADL*&
             & (RLILIA(JRTM,3) + Z1RADL*(RLILIA(JRTM,4) + Z1RADL*&
             & RLILIA(JRTM,5) ))  
            Z1MOMG = RLILIB(JRTM,1) + Z1RADL*RLILIB(JRTM,2) &
             & + ZRADLI(JL,JK) *(RLILIB(JRTM,3) + ZRADLI(JL,JK)*RLILIB(JRTM,4) )
            ZRSALD = Z1MOMG * ZEXTCF
          ENDIF  
         
          IF (NICEOPT == 0) THEN
! ice cloud spectral emissivity a la Smith & Shi (1992)
            ZMULTI=1.2_JPRB-0.006_JPRB*ZRADIC(JL,JK)
            ZRSAID= 0.103_JPRB*ZMULTI * 0.60240_JPRB
            
          ELSEIF (NICEOPT == 1) THEN
! ice cloud spectral emissivity a la Ebert-Curry (1992)
            ZRSAID= REBCUH(JRTM)+REBCUG(JRTM)/ZRADIC(JL,JK)
          
          ELSEIF (NICEOPT == 2) THEN
! ice cloud spectral emissivity a la Fu & Liou (1993)
            Z1RADI= 1.0_JPRB / ZDESIC(JL,JK)
            ZRSAID = RFULIO(JRTM,1) + Z1RADI &
             & *(RFULIO(JRTM,2) + Z1RADI*RFULIO(JRTM,3))  
             
          ELSEIF (NICEOPT == 3) THEN
! ice cloud spectral emissivity a la Fu et al (1998) including 
! parametrisation for LW scattering effect
            Z1RADI = 1.0_JPRB / ZDESIC(JL,JK)
            ZRSAIE = RFUETA(JRTM,1) + Z1RADI&
             & *(RFUETA(JRTM,2) + Z1RADI*RFUETA(JRTM,3))   
            ZRSAIA = Z1RADI*(RFUETB(JRTM,1) +ZDESIC(JL,JK)*( RFUETB(JRTM,2) +ZDESIC(JL,JK)*&
             & ( RFUETB(JRTM,3) +ZDESIC(JL,JK)* RFUETB(JRTM,4))))
            ZRSAIG = RFUETC(JRTM,1) +ZDESIC(JL,JK)*( RFUETC(JRTM,2) +ZDESIC(JL,JK)*&
             & ( RFUETC(JRTM,3) +ZDESIC(JL,JK)* RFUETC(JRTM,4))) 
            ZRSAIF = 0.5_JPRB + ZRSAIG*( 0.3738_JPRB + ZRSAIG*( 0.0076_JPRB + ZRSAIG*0.1186_JPRB ) )
            ZRSAID = (1.0_JPRB - ZRSAIA/ZRSAIE * ZRSAIF) * ZRSAIE
          ENDIF    
         
          ZTAUD = ZRSALD*ZFLWP(JL,JK)+ZRSAID*(ZFIWP(JL,JK)+ZFSWP(JL,JK))

! Diffusivity correction within clouds a la Savijarvi
          IF (LDIFFC) THEN
            ZDIFFD=MIN(MAX(1.517_JPRB-0.156_JPRB*LOG(ZTAUD) , 1.0_JPRB) , 2.0_JPRB)
          ELSE
            ZDIFFD=1.66_JPRB
          ENDIF
          ZTAUCLD(JL,IJK,JRTM) = ZTAUD*ZDIFFD
        ENDIF
        
      ENDDO
    ENDDO
  ENDDO

  ZTOLW(:,:,:) = 0.0_JPRB
  ZTOSW(:,:,:) = 0.0_JPRB
  ZASSW(:,:,:) = 0.0_JPRB
  ZOMSW(:,:,:) = 0.0_JPRB

ELSE


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

  ZTOLW(:,:,:) = 0.0_JPRB
! ZTOSW(:,:,:) = 0.0_JPRB
! ZASSW(:,:,:) = 0.0_JPRB
! ZOMSW(:,:,:) = 1.0_JPRB
  DO JK=1,KLEV
    DO JCSW=ICSW+1,ICOLSSW
      DO JL = KIDIA,KFDIA
        ZTOSW(JL,JCSW,JK) = 0.0_JPRB
        ZASSW(JL,JCSW,JK) = 0.0_JPRB
        ZOMSW(JL,JCSW,JK) = 1.0_JPRB
      ENDDO
    ENDDO
  ENDDO

!          5.2    SHORTWAVE OPTICAL PROPERTIES
!                 ----------------------------

  DO JCSW=1,ICSW
    JSW=NGBSW(JCSW)-15

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

!          5.3    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 (ZFCSW(JL,JCSW,JK) > REPSC ) THEN
!         ZLWGKG=MAX(ZQLSW(JL,JCSW,JK)*1000.0_JPRB,0.0_JPRB)
!         ZIWGKG=MAX(ZQISW(JL,JCSW,JK)*1000.0_JPRB,0.0_JPRB)
!       ELSE  
!         ZLWGKG=0.0_JPRB
!         ZIWGKG=0.0_JPRB
!       ENDIF
        ZLWGKG=0.0_JPRB
        ZIWGKG=0.0_JPRB
        ZSWGKG=0.0_JPRB
!        ZRWGKG=0.0_JPRB
        IF (ZFCSW(JL,JCSW,JK) > REPSC ) THEN
          ZLWGKG=500.0_JPRB*(ABS(ZQLSW(JL,JCSW,JK))+ZQLSW(JL,JCSW,JK))
          ZIWGKG=500.0_JPRB*(ABS(ZQISW(JL,JCSW,JK))+ZQISW(JL,JCSW,JK))
          ZSWGKG=500.0_JPRB*(ABS(ZQSSW(JL,JCSW,JK))+ZQSSW(JL,JCSW,JK))
!          ZRWGKG=500.0_JPRB*(ABS(ZQRSW(JL,JCSW,JK))+ZQRSW(JL,JCSW,JK))
        ENDIF
        ZRWGKG=0.0_JPRB
!       ZRAINT(JL)=0.0_JPRB  !  Not used in this loop

        ZDPOG=PDP(JL,JK)*ZRG
        ZFLWP(JL,JK)= ZLWGKG*ZDPOG
        ZFIWP(JL,JK)= ZIWGKG*ZDPOG
        ZFSWP(JL,JK)= ZSWGKG*ZDPOG
!       ZFRWP(JL,JK)= ZRWGKG*ZDPOG   ! Always zero
!       ZPODT=PAP(JL,JK)/(RD*PT(JL,JK)) ! Not used in this loop
!       ZLWC(JL,JK)=ZLWGKG*ZPODT    ! Not used in this loop
!       ZIWC(JL,JK)=ZIWGKG*ZPODT    ! Not used in this loop
!       ZSWC(JL,JK)=ZSWGKG*ZPODT    ! Not used in this loop
      ENDDO


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

      DO JL = KIDIA,KFDIA
        ZTOSW(JL,JCSW,IJK) = 0.0_JPRB
        ZOMSW(JL,JCSW,IJK) = 1.0_JPRB
        ZASSW(JL,JCSW,IJK) = 0.0_JPRB
      ENDDO
      DO JL = KIDIA,KFDIA
        ZTOL=0.0_JPRB
        ZGL =0.0_JPRB
        ZOL =0.0_JPRB
        ZTOI=0.0_JPRB
        ZGI =0.0_JPRB
        ZOI =0.0_JPRB
        ZTOR=0.0_JPRB
        ZGR =0.0_JPRB
        ZOR =0.0_JPRB

        IF (ZFLWP(JL,JK) > REPSCW .OR. ZFIWP(JL,JK) > REPSCW &
     &   .OR. ZFSWP(JL,JK) > REPSCW ) THEN
          IF (ZFLWP(JL,JK) > REPSCW ) THEN
            IF (NLIQOPT /= 0 ) THEN
!-- SW: Slingo, 1989
              ZTOL = ZFLWP(JL,JK)*(RSASWA(JSW)+RSASWB(JSW)/ZRADLI(JL,JK))
              ZGL  = RSASWE(JSW)+RSASWF(JSW)*ZRADLI(JL,JK)
              ZOL  = 1. - RSASWC(JSW)-RSASWD(JSW)*ZRADLI(JL,JK)
            ELSE          
!-- SW: Fouquart, 1991
              ZTOL = ZFLWP(JL,JK)*(RSYFWA(JSW)+RSYFWB(JSW)/ZRADLI(JL,JK))
              ZGL  = RSYFWF(JSW)
              ZOL  = RSYFWC(JSW)-RSYFWD(JSW)*EXP(-RSYFWE(JSW)*ZTOL)
            ENDIF 
          ENDIF
  
          IF ((ZFIWP(JL,JK)+ZFSWP(JL,JK)) > REPSCW ) THEN
            IF (NICEOPT <= 1) THEN
!-- SW: Ebert-Curry          
              ZTOI = (ZFIWP(JL,JK)+ZFSWP(JL,JK))*(RSECIA(JSW)+RSECIB(JSW)/ZRADIC(JL,JK))
              ZGI  = RSECIE(JSW)+RSECIF(JSW)*ZRADIC(JL,JK)
              ZOI  = 1.0_JPRB - RSECIC(JSW)-RSECID(JSW)*ZRADIC(JL,JK)
            
            ELSEIF (NICEOPT == 2) THEN  
!-- SW: Fu-Liou 1993
              Z1RADI = 1.0_JPRB / ZDESIC(JL,JK)
              ZBETAI = RSFLA0(JSW)+Z1RADI* RSFLA1(JSW)
              ZTOI = (ZFIWP(JL,JK)+ZFSWP(JL,JK)) * ZBETAI
              ZOMGI= RSFLB0(JSW)+ZRADIC(JL,JK)*(RSFLB1(JSW) + ZRADIC(JL,JK) &
               & *(RSFLB2(JSW)+ZRADIC(JL,JK)* RSFLB3(JSW) ))              
              ZOI  = 1.0_JPRB - ZOMGI
              ZOMGP= RSFLC0(JSW)+ZRADIC(JL,JK)*(RSFLC1(JSW) + ZRADIC(JL,JK) &
               & *(RSFLC2(JSW)+ZRADIC(JL,JK)* RSFLC3(JSW) ))   
              ZFDEL= RSFLD0(JSW)+ZRADIC(JL,JK)*(RSFLD1(JSW) + ZRADIC(JL,JK) &
               & *(RSFLD2(JSW)+ZRADIC(JL,JK)* RSFLD3(JSW) ))   
              ZGI  = ((1.0_JPRB-ZFDEL)*ZOMGP + ZFDEL*3.0_JPRB) *0.33333_JPRB
            
            ELSEIF (NICEOPT == 3) THEN  
!-- SW: Fu 1996
              Z1RADI = 1.0_JPRB / ZDESIC(JL,JK)
              ZBETAI = RSFUA0(JSW)+Z1RADI* RSFUA1(JSW)
              ZTOI = (ZFIWP(JL,JK)+ZFSWP(JL,JK)) * ZBETAI
              ZOMGI= RSFUB0(JSW)+ZDESIC(JL,JK)*(RSFUB1(JSW) + ZDESIC(JL,JK) &
               & *(RSFUB2(JSW)+ZDESIC(JL,JK)* RSFUB3(JSW) ))              
              ZOI  = 1.0_JPRB - ZOMGI
              ZGI  = RSFUC0(JSW)+ZDESIC(JL,JK)*(RSFUC1(JSW) + ZDESIC(JL,JK) &
               & *(RSFUC2(JSW)+ZDESIC(JL,JK)* RSFUC3(JSW) ))   
              ZGI  = MIN(1.0_JPRB, ZGI)
            ENDIF
          ENDIF

!  - MIX of WATER and ICE CLOUDS
          ZTAUMX= ZTOL + ZTOI + ZTOR
          ZOMGMX= ZTOL*ZOL + ZTOI*ZOI + ZTOR*ZOR
          ZASYMX= ZTOL*ZOL*ZGL + ZTOI*ZOI*ZGI + ZTOR*ZOR*ZGR
        
          ZASYMX= ZASYMX/ZOMGMX
          ZOMGMX= ZOMGMX/ZTAUMX

! --- SW FINAL CLOUD OPTICAL PARAMETERS

          ZTOSW(JL,JCSW,IJK) = ZTAUMX
          ZOMSW(JL,JCSW,IJK) = ZOMGMX
          ZASSW(JL,JCSW,IJK) = ZASYMX
        ENDIF
      ENDDO
    ENDDO
  ENDDO

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

!   -------------------------
! --+ 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 JCLW=1,ICLW
    JRTM=NGB(JCLW)
    DO JK=1,KLEV
      IJK=KLEV+1-JK

!          5.4    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 (ZFCLW(JL,JCLW,JK) > REPSC ) THEN
          ZLWGKG=MAX(ZQLLW(JL,JCLW,JK)*1000.0_JPRB,0.0_JPRB)
          ZIWGKG=MAX(ZQILW(JL,JCLW,JK)*1000.0_JPRB,0.0_JPRB)
          ZSWGKG=MAX(ZQSLW(JL,JCLW,JK)*1000.0_JPRB,0.0_JPRB)
        ELSE  
          ZLWGKG=0.0_JPRB
          ZIWGKG=0.0_JPRB
          ZSWGKG=0.0_JPRB
        ENDIF
        ZRWGKG=0.0_JPRB
!       ZRAINT(JL)=0.0_JPRB ! Not used in this loop

        ZDPOG=PDP(JL,JK)*ZRG
        ZFLWP(JL,JK)= ZLWGKG*ZDPOG
        ZFIWP(JL,JK)= ZIWGKG*ZDPOG
        ZFSWP(JL,JK)= ZSWGKG*ZDPOG
!       ZFRWP(JL,JK)= ZRWGKG*ZDPOG   ! Always zero
!       ZPODT=PAP(JL,JK)/(RD*PT(JL,JK)) ! Not used in this loop
!       ZLWC(JL,JK)=ZLWGKG*ZPODT  ! Not used in this loop
!       ZIWC(JL,JK)=ZIWGKG*ZPODT  ! Not used in this loop
!       ZSWC(JL,JK)=ZSWGKG*ZPODT  ! Not used in this loop
      ENDDO


!          5.5    CLOUD SHORTWAVE OPTICAL PROPERTIES
!                 ---------------------------------- 

      DO JL = KIDIA,KFDIA
        ZRSALD = 0.0_JPRB
        ZRSAID = 0.0_JPRB
        
        IF (ZFLWP(JL,JK)+ZFIWP(JL,JK)+ZFSWP(JL,JK) > REPSCW) THEN

          IF (NLIQOPT == 0 .OR. NLIQOPT >= 3) THEN
! water cloud total emissivity a la Smith and Shi (1992)
            ZMULTL=1.2_JPRB-0.006_JPRB*ZRADLI(JL,JK)
            ZRSALD= 0.144_JPRB*ZMULTL *0.60240_JPRB
            
          ELSEIF (NLIQOPT == 1) THEN
! water cloud spectral emissivity a la Savijarvi (1997)
            ZRSALD= RHSAVI(JRTM,1) + ZRADLI(JL,JK)&
             & *(RHSAVI(JRTM,2) + ZRADLI(JL,JK)*RHSAVI(JRTM,3))  
             
          ELSEIF (NLIQOPT == 2) THEN
! water cloud spectral emissivity a la Lindner and Li (2000)
            Z1RADL = 1.0_JPRB / ZRADLI(JL,JK)
          ZEXTCF = RLILIA(JRTM,1)+ZRADLI(JL,JK)*RLILIA(JRTM,2)+ Z1RADL*&
             & (RLILIA(JRTM,3) + Z1RADL*(RLILIA(JRTM,4) + Z1RADL*&
             & RLILIA(JRTM,5) ))  
            Z1MOMG = RLILIB(JRTM,1) + Z1RADL*RLILIB(JRTM,2) &
             & + ZRADLI(JL,JK) *(RLILIB(JRTM,3) + ZRADLI(JL,JK)*RLILIB(JRTM,4) )
            ZRSALD = Z1MOMG * ZEXTCF
          ENDIF  
         
          IF (NICEOPT == 0) THEN
! ice cloud spectral emissivity a la Smith & Shi (1992)
            ZMULTI=1.2_JPRB-0.006_JPRB*ZRADIC(JL,JK)
            ZRSAID= 0.103_JPRB*ZMULTI *0.60240_JPRB
            
          ELSEIF (NICEOPT == 1) THEN
! ice cloud spectral emissivity a la Ebert-Curry (1992)
            ZRSAID= REBCUH(JRTM)+REBCUG(JRTM)/ZRADIC(JL,JK)
          
          ELSEIF (NICEOPT == 2) THEN
! ice cloud spectral emissivity a la Fu & Liou (1993)
            Z1RADI= 1.0_JPRB / ZDESIC(JL,JK)
            ZRSAID = RFULIO(JRTM,1) + Z1RADI &
             & *(RFULIO(JRTM,2) + Z1RADI*RFULIO(JRTM,3))  
             
          ELSEIF (NICEOPT == 3) THEN
! ice cloud spectral emissivity a la Fu et al (1998) including 
! parametrisation for LW scattering effect
            Z1RADI = 1.0_JPRB / ZDESIC(JL,JK)
            ZRSAIE = RFUETA(JRTM,1) + Z1RADI&
             & *(RFUETA(JRTM,2) + Z1RADI*RFUETA(JRTM,3))   
            ZRSAIA = Z1RADI*(RFUETB(JRTM,1) +ZDESIC(JL,JK)*( RFUETB(JRTM,2) +ZDESIC(JL,JK)*&
             & ( RFUETB(JRTM,3) +ZDESIC(JL,JK)* RFUETB(JRTM,4))))
            ZRSAIG = RFUETC(JRTM,1) +ZDESIC(JL,JK)*( RFUETC(JRTM,2) +ZDESIC(JL,JK)*&
             & ( RFUETC(JRTM,3) +ZDESIC(JL,JK)* RFUETC(JRTM,4))) 
            ZRSAIF = 0.5_JPRB + ZRSAIG*( 0.3738_JPRB + ZRSAIG*( 0.0076_JPRB + ZRSAIG*0.1186_JPRB ) )
            ZRSAID = (1.0_JPRB - ZRSAIA/ZRSAIE * ZRSAIF) * ZRSAIE

            !>>dod temporary(?) pending further investigation, prevent negative cloud AOD:
            ! ZRSAID = MAX(ZRSAID, 0._JPRB)
            !<<dod
          ENDIF    
         
          ZTAUD = ZRSALD*ZFLWP(JL,JK)+ZRSAID*(ZFIWP(JL,JK)+ZFSWP(JL,JK))

! Diffusivity correction within clouds a la Savijarvi
          IF (LDIFFC) THEN
            ZDIFFD=MIN(MAX(1.517_JPRB-0.156_JPRB*LOG(ZTAUD) , 1.0_JPRB) , 2.0_JPRB)
          ELSE
            ZDIFFD=1.66_JPRB
          ENDIF
          ZTOLW(JL,IJK,JCLW) = ZTAUD*ZDIFFD
        ENDIF
        
      ENDDO
    ENDDO
  ENDDO

ENDIF

NUAER = NUA
NTRAER = NTRA

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

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

!*         6.1    FULL LONGWAVE RADIATION COMPUTATIONS
!                 ------------------------------------

IF (.NOT.LPHYLIN) THEN
  IF ( .NOT. LRRTM) THEN

    CALL ABOR1('RADLSWR: OLD LW SCHEME NOT AVAILABLE IN McICA CONFIGURATION')

  ELSE

!*         6.2    FULL LONGWAVE RADIATION COMPUTATIONS - RRTM
!                 ------------------------------------   ----

!  i)  pass ZOZN (ozone mass mixing ratio) to RRTM; remove pressure
!      weighting applied to POZON in driverMC (below)
!  ii) pass ZEMIS and ZEMIW to RRTM; return ZEMIT from RRTM
!  iii)pass ZTAUCLD, cloud optical depths (water+ice) to RRTM, 
!      computed from equations above
!  iv) pass ECRT arrays to RRTM arrays in interface routine ECRTATM
!      in module rrtm_ecrt.f

    DO JL = KIDIA,KFDIA
      DO JK = 1, KLEV
        ZOZN(JL,JK) = POZON(JL,JK)/PDP(JL,JK)
      ENDDO
    ENDDO

    ! Set TM5 AOD in the stratosphere to 0 if using the CMIP6 stratospheric aerosols
    IF (LTM5AER .OR. LCMIP6_PI_AEROSOLS) THEN
      IF (LCMIP6_STRATAER_FULL) THEN
        DO JL=KIDIA,KFDIA
          ZAER(JL,1:4,1:KTROPPAUSE(JL)-1) = 0.0_JPRB
        ENDDO
      ENDIF
    ENDIF

    IF (NMCICA == 0) THEN

     CALL RRTM_RRTM_140GP &
      & ( KIDIA , KFDIA , KLON  , KLEV,&
      & ZAER  , PAPH  , PAP,&
      & PTS   , PTH   , PT,&
      & ZEMIS , ZEMIW,&
      & PQ    , PCO2  , PCH4 , PN2O   , PNO2, PC11, PC12, PC22, PCL4, ZOZN, ZCLDSW, ZTAUCLD,&
      & ZEMIT , ZFLUX , ZFLUC, ZTCLEAR &
      & )  

    ELSE

      ICOLS=ICOLSLW

      CALL RRTM_RRTM_140GP_McICA &
       &( KIDIA, KFDIA, KLON , KLEV, ICOLS, ICLDLW ,&
       &  ZAER , ZAAODSTRAT_LW, PAPH , PAP  , &
       &  PTS  , PTH  , PT   , &
       &  ZEMIS, ZEMIW, &    
       &  PQ   , PCO2 , PCH4 , PN2O, PNO2 , PC11, PC12, PC22, PCL4, &
       &  ZOZN , ZLWFC , ZTOLW , ZCLDLW, &
       &  ZEMIT, ZFLUX, ZFLUC &
       & )  

    ENDIF

  ENDIF

  DO JK = 1 , KLEV+1
    IK=KLEV+2-JK
    DO JL=KIDIA,KFDIA
      PFLT(JL,JK) =-ZFLUX(JL,2,IK) - ZFLUX(JL,1,IK)
      PFCT(JL,JK) =-ZFLUC(JL,2,IK) - ZFLUC(JL,1,IK)
    ENDDO
  ENDDO

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

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

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

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

IF (NMCICA == 0) THEN

  CALL SRTM_SRTM_224GP &
    & ( KIDIA , KFDIA , KLON  , KLEV  , ISW , NOVLP,&    
    &   ZAER  , ZSALBD, ZSALBP, PAPH  , PAP ,&  
    &   PTS   , PTH   , PT    ,&  
    &   PQ    , PCO2  , PCH4  , PN2O  , PNO2, ZOZN , ZMU0  ,&
    &   ZCLDSW, ZSTAUC, ZSASYC, ZSOMGC,&
    &   ZFSUX , ZFSUC , ZFUVF ,ZSUDU )  

ELSE

  ICOLS=ICOLSSW

  ! Set TM5 AOD in the stratosphere to 0 if using the CMIP6 stratospheric aerosols
  IF (LTM5AER) THEN
     IF (LCMIP6_STRATAER_FULL) THEN
        DO JL=KIDIA,KFDIA
           ZAODTM(JL,:,1:KTROPPAUSE(JL)-1) = 0.0_JPRB
        ENDDO
     ENDIF
  ENDIF

  ! Set TM5-derived PI AOD in the stratosphere to 0 if using the CMIP6 stratospheric aerosols
  IF (LCMIP6_PI_AEROSOLS) THEN
     IF (LCMIP6_STRATAER_FULL) THEN
        DO JL=KIDIA,KFDIA
           ZAODPI(JL,1:KTROPPAUSE(JL)-1,:) = 0.0_JPRB
           ZSSAPI(JL,1:KTROPPAUSE(JL)-1,:) = 0.0_JPRB
           ZASFPI(JL,1:KTROPPAUSE(JL)-1,:) = 0.0_JPRB
        ENDDO
     ENDIF
  ENDIF
  
  CALL SRTM_SRTM_224GP_McICA &
   & ( KIDIA , KFDIA , KLON  , KLEV , ISW , ICOLS , ICLDSW ,&
   &   ZAER  , ZSALBD, ZSALBP, PAPH , PAP ,&
   &   PTS   , PTH   , PT    , &
   &   PQ    , PCO2  , PCH4  , PN2O , PNO2, ZOZN  , ZMU0  ,&
   &   ZSWFC , ZTOSW , ZASSW , ZOMSW,&
   &   ZFSUX , ZFSUC , ZFUVF , ZFUVC,ZPARF, ZPARCF, ZSUDU ,&
   &   ZFDIR , ZCDIR , ZFDIF , ZCDIF, &
   &   ZAODSTRAT, ZAAODSTRAT, ZREFAODSTRAT, &
   &   ZAODTM, PSSATM, PASFTM, &
   &   ZAODPI, ZSSAPI, ZASFPI, &
   &   ZMAC2SP_AOD, ZMAC2SP_SSA, ZMAC2SP_ASY)

ENDIF
 
!     ------------------------------------------------------------------

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

DO JK = 1 , KLEV+1
  IK=KLEV+2-JK
  DO JL = KIDIA,KFDIA
    PFLS(JL,JK) = ZFSUX(JL,2,JK) - ZFSUX(JL,1,JK)
    PFCS(JL,JK) = ZFSUC(JL,2,JK) - ZFSUC(JL,1,JK)
  ENDDO
ENDDO

DO JL = KIDIA,KFDIA
  PFRSOD(JL) = ZFSUX(JL,2,KLEV+1)
  PEMIT (JL) = ZEMIT(JL)
  PSUDU (JL) = ZSUDU(JL)
  PUVDF (JL) = ZFUVF(JL)
  PPARF (JL) = ZPARF(JL)
  PPARCF(JL) = ZPARCF(JL)
  PTINCF(JL) = PRII0 * ZMU0(JL)
  PFDIR (JL) = ZFDIR(JL,KLEV+1)
  PCDIR (JL) = ZCDIR(JL,KLEV+1)
ENDDO
!IF (NSTEP <= 5) THEN
!  WRITE(NULOUT,9401) (PUVDF(JL),JL=KIDIA,KFDIA)
!9401 FORMAT(1X,'RADLSWR ',20E10.3)
!ENDIF

! --------------------------------------------------------------
! DIAGNOSTICS
! --------------------------------------------------------------
!>>dod : removed MACv2SP and preindustrial aerosols diagnostics

! Effective radius if aerosol-cloud interaction diagnostics requested
IF (NRAD3D > 0 .AND. LACI_DIAG) THEN
   PEXTRA(KIDIA:KFDIA,:,D_REFF%IXRAD3D) = ZRADLI(KIDIA:KFDIA,:)
END IF

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