!OPTIONS XOPT(HSFUN)
SUBROUTINE RADINTG  ( KLEV  , KMODE,&
 & PALBD , PALBP , PCCNL , PCCNO,&
 & PGEOH , PAPRS , PAPRSF, PCCO2 , PCLFR,&
 & PQO3  , PAER  , PAERO,&
 & PCLON , PSLON,&
 & PDP   , PEMIS , PEMIW ,&
 & PGELAM, PGEMU , PMU0  , PQ,&
 & PQS   , PQIWP , PQSWP , PQLWP , PQRAIN, PRAINT, PSLM  , PT,&
 & PECPO3, PTS,&
 & PEMTD , PEMTU , PTRSO , PTRSC , PEMTC , PNTOP , PNBAS,&
 & PEMIT , PTH   , PTRSOD, PSUDU , PUVDF , PPARF , PPARCF, PTINCF, &
 & PFDIR , PCDIR ,&
 & KLEVX , PEXTRA, PEXTR2, &
 & PCDNC, PICNC, PRE_LIQ, PRE_ICE, &
 & LZEROAERO )
 
!**** *RADINTG* - RADIATION INTERFACE TO ACTUAL RADIATION SCHEME

!     PURPOSE.
!     --------
!           CONTROLS THE SPACE INTERPOLATION FOR RADIATION FIELDS

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

!        EXPLICIT ARGUMENTS :
!        --------------------
! KLEV   : NUMBER OF LEVELS

! PAER   : (NGPTOT,6,KLEV)      ; OPTICAL THICKNESS OF THE AEROSOLS
! PAERP  : (NGPTOT,6,KLEV)      ; OPTICAL THICKNESS OF THE PROGNOSTIC AEROSOLS
! PAERO  : (NGPTOT,KLEV,NAERO)  ; MASS MIXING RATIO OF PROGNOSTIC AEROSOLS
! PALBD  : (NGPTOT,NTSW)        ; DIFFUSE ALBEDO IN THE NSW SW INTERVALS
! PALBP  : (NGPTOT,NTSW)        ; PARALLEL ALBEDO IN THE NSW SW INTERVALS
! PCCNL  : (NGPTOT)             ; CCNs CONCENTRATION OVER LAND
! PCCNO  : (NGPTOT)             ; CCNs CONCENTRATION OVER OCEAN
! PGEOH  : (NGPTOT,KLEV+1)      ; HALF LEVEL GEOPOTENTIAL HEIGHT
! PAPRS  : (NGPTOT,KLEV+1)      ; HALF LEVEL PRESSURE
! PAPRSF : (NGPTOT,KLEV )       ; FULL LEVEL PRESSURE
! PCCO2  :                      ; CONCENTRATION IN CO2 (PA/PA)
! PCLFR  : (NGPTOT,KLEV )       ; CLOUD FRACTIONAL COVER
! PQO3   : (NGPTOT,KLEV )       ; OZONE MIXING RATIO (MASS)
! PDP    : (NGPTOT,KLEV)        ; LAYER PRESSURE THICKNESS
! PEMIS  : (NGPTOT)             ; SURFACE EMISSIVITY
! PEMIW  : (NGPTOT)             ; SURFACE WINDOW EMISSIVITY
! PGELAM : (NGPTOT)             ; LONGITUDE
! PGEMU  : (NGPTOT)             ; SINE OF LATITUDE ON THE REAL EARTH
! PMU0   : (NGPTOT)             ; SOLAR ANGLE
! PNBAS  : (NGPTOT)             ; INDEX OF BASE OF CONVECTIVE LAYER
! PNTOP  : (NGPTOT)             ; INDEX OF TOP OF CONVECTIVE LAYER
! PQ     : (NGPTOT,KLEV )       ; SPECIFIC HUMIDITY PA/PA
! PQS    : (NGPTOT,KLEV )       ; SATURATION SPECIFIC HUMIDITY PA/PA
! PQIWP  : (NGPTOT,KLEV )       ; ICE WATER KG/KG
! PQSWP  : (NGPTOT,KLEV )       ; SNOW WATER KG/KG
! PQLWP  : (NGPTOT,KLEV )       ; LIQUID WATER KG/KG
! PQRAIN : (NGPTOT,KLEV )       ; RAIN   WATER KG/KG
! PRAINT : (NGPTOT,KLEV )       ; RAIN RATE M/S  
! PSLM   : (NGPTOT)             ; LAND-SEA MASK
! PT     : (NGPTOT,KLEV)        ; FULL LEVEL TEMPERATURE
! PECPO3 : (NGPTOT,KLEV)        ; FULL LEVEL PROGNOSTIC OZONE (ECMWF)
! PTS    : (NGPTOT)             ; SURFACE TEMPERATURE
!     ==== OUTPUTS ===
! PEMTD (NGPTOT,KLEV+1)         ; TOTAL DOWNWARD LONGWAVE EMISSIVITY
! PEMTU (NGPTOT,KLEV+1)         ; TOTAL UPWARD   LONGWAVE EMISSIVITY
! PTRSO (NGPTOT,KLEV+1)         ; TOTAL SHORTWAVE TRANSMISSIVITY
! PEMTC (NGPTOT,KLEV+1)         ; CLEAR-SKY LONGWAVE EMISSIVITY
! PTRSC (NGPTOT,KLEV+1)         ; CLEAR-SKY SHORTWAVE TRANSMISSIVITY
! PTH   (NGPTOT,KLEV+1)         ; HALF LEVEL TEMPERATURE
! PTRSOD(NGPTOT)                ; TOTAL-SKY SURFACE SW TRANSMISSITY
! PEMIT (NGPTOT)                ; SURFACE TOTAL LONGWAVE EMISSIVITY
! PSUDU (NGPTOT)                ; SUNSHINE DURATION
! PUVDF (NGPTOT)                ; UV(-B) DOWNWARD AT SURFACE
! PPARF (NGPTOT)                ; PHOTOSYNTHETICALLY ACTIVE RADIATION
! PPARCF(NGPTOT)                ; CLEAR-SKY PHOTOSYNTHETICALLY ACTIVE RADIATION
! PTINCF(NGPTOT)                ; TOA INCIDENT SOLAR RADIATION
! PFDIR (NGPTOT)                ; TOTAL SKY SURFACE DIRECT SW RADIATION 
! PCDIR (NGPTOT)                ; CLEAR-SKY SURFACE DIRECT SW RADIATION 
! KLEVX                         ; NUMBER OF LELELS FOR ADDITIONAL 3-D DIAGNOSTICS
! PEXTRA (NGPTOT,KLEVX,NRAD3D)  ; FIELD FOR FREE USE FOR ADDITIONAL 3-D DIAGNOSTICS
! PEXTR2 (NGPTOT,NRAD2D)      ; FIELD FOR FREE USE FOR ADDITIONAL 2-D DIAGNOSTICS
! PCDNC (NGPTOT,KLEV)           ; CLOUD DROPLET NUMBER CONCENTRATION [# CM-3]
! PICNC (NGPTOT,KLEV)           ; ICE CRYSTAL NUMBER CONCENTRATION [# CM-3]
! PRE_LIQ(NGPTOT,KLEV)          ; CLOUD DROPLET EFFECTIVE RADIUS
! PRE_ICE(NGPTOT,KLEV)          ; ICE CRYSTAL EFFECTIVE RADIUS

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

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

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

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

!     AUTHORS.
!     --------
!        G. MOZDZYNSKI  *ECMWF*

!     MODIFICATIONS.
!     --------------
!        01-11-08 : GMozdzynski      Original
!        01-10-10 : JJMorcrette      CCNs
!        01-11-08 : JJMorcrette      safety check
!        01-12-07 : JJMorcrette      safety check on interactive O3
!        02-10-01 : GMozdzynski      support on-demand radiation comms
!        03-03-31 : GMozdzynski      use minimum halo for radiation comms
!        03-05-15 : JJMorcrette      PAR, UVB
!        M.Hamrud      01-Oct-2003 CY28 Cleaning
!        M.Hamrud      10-Jan-2004 CY28R1 Cleaning
!        JJMorcrette 20060721 PP of clear-sky PAR and TOA incident solar radiation
!        JJMorcrette 20071015        3D climatological input fields for CO2, CH4, N2O, NO2, CFC11, CFC12, HCFC22 and CCL4
!        JJMorcrette 20080422        prognostic aerosols
!        D.Salmond   20080603        CO2-CL4 moved to from input to local
!        F. Vana     27-Aug-2008  new interpolation data-flow
!        K. Yessad Dec 2008: merge SLCOMM+SLCOMM1 -> SLCOMM.
!        K. Yessad Dec 2008: merge the different (E)SLEXTPOL.. -> (E)SLEXTPOL.
!        JJMorcrette 20091201        Total and clear sky downward direct SW flux at surface
!        T. van Noije Jan-2014       Modified for use of TM5 O3/CH4 fields
!        S. Boussetta March-2016    added option to use the anthropogenic aerosol MACv2 SP
!-----------------------------------------------------------------------

USE PARKIND1  ,ONLY : JPIM     ,JPRB
USE YOMHOOK   ,ONLY : LHOOK,   DR_HOOK
USE YOMDIM   , ONLY : NSPEC2   ,NDGSAH   ,NDGENH   ,&
 & NDGSAG  ,NDGSAL   ,NDGENG   ,NDGENL   ,NUMP     ,&
 & NDLON   ,NDGLG    ,NSMAX  
USE YOMPHY3  , ONLY : RII0
USE YOMCST   , ONLY : RMD      ,RMO3     ,RPI
USE YOMLUN   , ONLY : NULOUT   ,NULTMP   ,NULERR
USE YOERAD   , ONLY : NAER     ,NOZOCL   ,&
 & NSW      ,NTSW    ,NRADRES  ,NRADINT  ,NRPROMA ,NGHGRAD   ,&
 & LEPO3RA  ,LHVOLCA ,LSRTM    ,NPERTAER, NPERTOZ ,LNOTROAER ,&
 & LCMIP5   ,LCMIP6  ,&
 & ICPLO3   ,ICPLCH4 ,ICPLAOD  ,ICPLSSA  ,ICPLASF
USE YOERAD   , ONLY : LTM5O3   ,LTM5CH4  ,LTM5AER, &
 & LCMIP6_PI_AEROSOLS, LMAC2SP, L2RAD
USE YOECLDP,   ONLY : NCLOUDACT
USE YOESW    , ONLY : RADJUST
USE YOMPRAD  , ONLY : RADGRID  ,LRADONDEM,LRADONDEM_ACTIVE   ,&
 & NFIXRADFLD,MASK_RI1,MASK_RI2,MASK_RO1,MASK_RO2  
USE YOEAERD  , ONLY : RCAEROS
USE YOERDU   , ONLY : NIMP     ,NOUT     ,REPSCQ  ,REPSCO
USE YOERDI   , ONLY : RRAE     ,REPCLC   ,REPH2O   ,RCH4     ,&
 & RN2O   ,RNO2   ,RCFC11 ,RCFC12, RCFC22, RCCL4
USE YOMPHY   , ONLY :    LRAYFM
USE YOEPHLI  , ONLY : LPHYLIN
USE YOMGEM   , ONLY : NLOENG   ,NGPTOT   ,R4JP
USE YOMLEG   , ONLY : RLATI    ,RIPI0    ,RIPI1   ,RIPI2
USE YOMGC    , ONLY : GELAT    ,GELAM
USE YOMCT0   , ONLY : NPROC    ,NPRTRV
USE YOMCT3   , ONLY : NSTEP
USE YOMMP    , ONLY : MYSETV   ,NFRSTLOFF, NGLOBALINDEX ,&
 & MYFRSTACTLAT      ,MYLSTACTLAT         ,MYPROC ,&
 & NRISTA  ,NRIONL   ,NRIOFF    ,NRIEXT   ,NRICORE ,&
 & NRISENDPOS ,NRIRECVPOS ,NRISENDPTR ,NRIRECVPTR ,&
 & NARIB1  ,NRIPROCS ,NRISPT   ,NRIRPT ,&
 & NRICOMM ,&
 & NROSTA  ,NROONL   ,NROOFF    ,NROEXT   ,NROCORE ,&
 & NROSENDPOS ,NRORECVPOS ,NROSENDPTR ,NRORECVPTR ,&
 & NAROB1  ,NROPROCS ,NROSPT   ,NRORPT ,&
 & NROCOMM  
USE YOMLAP   , ONLY : MYMS,NASM0
USE YOMSC2   , ONLY : NRIWIDEN ,NRIWIDES ,NROWIDEN ,NROWIDES
!USE GRIDPOINT_BUFFERS_MIX , ONLY : GRIDPOINT_BUFFER 
USE YOM_YGFL , ONLY : YO3    , NAERO , NACTAERO
USE YOEAERATM, ONLY : REPSCAER
USE CPLNG    ! , ONLY : CPLNG_FLD, CPLNG_IDX, LEV_IDX_TM5
USE YOE_PI_AERO
USE YOE_AERO_M7_DATA, ONLY:   ICPLSU2, ICPLSU3, ICPLSU4, ICPLBC2, &
 & ICPLBC3, ICPLBC4, ICPLBC5, ICPLOM2, ICPLOM3, ICPLOM3, ICPLOM4, &
 & ICPLOM5, ICPLSS3, ICPLSS4, ICPLDD3, ICPLDD4, ICPLDD6, ICPLDD7
USE PHY_DIAG_MOD, ONLY: NRAD2D, NRAD3D
USE YOERADDIAG
!   -------------------------------------------------------------------

IMPLICIT NONE

INTEGER(KIND=JPIM),INTENT(IN)    :: KLEV 
INTEGER(KIND=JPIM),INTENT(IN)    :: KMODE 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PALBD(NGPTOT,NTSW) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PALBP(NGPTOT,NTSW) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PCCNL(NGPTOT) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PCCNO(NGPTOT)
REAL(KIND=JPRB)   ,INTENT(IN)    :: PGEOH(NGPTOT,KLEV+1) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PAPRS(NGPTOT,KLEV+1) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PAPRSF(NGPTOT,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PCCO2 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PCLFR(NGPTOT,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PQO3(NGPTOT,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PAER(NGPTOT,6,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PAERO(NGPTOT,KLEV,NAERO) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PCLON(NGPTOT) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PSLON(NGPTOT) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PDP(NGPTOT,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PEMIS(NGPTOT) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PEMIW(NGPTOT) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PGELAM(NGPTOT) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PGEMU(NGPTOT) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PMU0(NGPTOT) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PQ(NGPTOT,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PQS(NGPTOT,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PQIWP(NGPTOT,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PQSWP(NGPTOT,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PQLWP(NGPTOT,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PQRAIN(NGPTOT,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PRAINT(NGPTOT,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PSLM(NGPTOT) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PT(NGPTOT,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PECPO3(NGPTOT,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PTS(NGPTOT) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PCDNC(NGPTOT,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PICNC(NGPTOT,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PRE_LIQ(NGPTOT,KLEV) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PRE_ICE(NGPTOT,KLEV) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PEMTD(NGPTOT,KLEV+1) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PEMTU(NGPTOT,KLEV+1) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PTRSO(NGPTOT,KLEV+1) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PTRSC(NGPTOT,KLEV+1) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PEMTC(NGPTOT,KLEV+1) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PNTOP(NGPTOT) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PNBAS(NGPTOT) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PEMIT(NGPTOT) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PTH(NGPTOT,KLEV+1) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PTRSOD(NGPTOT) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PSUDU(NGPTOT) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PUVDF(NGPTOT) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PPARF(NGPTOT) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PPARCF(NGPTOT),PTINCF(NGPTOT)
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PFDIR(NGPTOT) ,PCDIR(NGPTOT)
INTEGER(KIND=JPIM),INTENT(IN)    :: KLEVX
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PEXTRA(NGPTOT,KLEVX,NRAD3D)
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PEXTR2(NGPTOT,NRAD2D)

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

REAL(KIND=JPRB) :: ZAMU0  (NGPTOT)
REAL(KIND=JPRB) :: ZQAER  (NRPROMA,6,KLEV)
REAL(KIND=JPRB) :: ZQOZ   (NRPROMA,KLEV)
REAL(KIND=JPRB) :: ZQCO2  (NRPROMA,KLEV)
REAL(KIND=JPRB) :: ZQCH4  (NRPROMA,KLEV)
REAL(KIND=JPRB) :: ZQN2O  (NRPROMA,KLEV)
REAL(KIND=JPRB) :: ZQNO2  (NRPROMA,KLEV)
REAL(KIND=JPRB) :: ZQC11  (NRPROMA,KLEV)
REAL(KIND=JPRB) :: ZQC12  (NRPROMA,KLEV)
REAL(KIND=JPRB) :: ZQOZO  (NRPROMA,KLEV)
REAL(KIND=JPRB) :: ZQC22  (NRPROMA,KLEV)
REAL(KIND=JPRB) :: ZQCL4  (NRPROMA,KLEV)
REAL(KIND=JPRB) :: ZLWFC  (NRPROMA,KLEV+1)
REAL(KIND=JPRB) :: ZSWFC  (NRPROMA,KLEV+1)
REAL(KIND=JPRB) :: ZFRTH  (NRPROMA,KLEV+1)
REAL(KIND=JPRB) :: ZFRSO  (NRPROMA,KLEV+1)
REAL(KIND=JPRB) :: ZFRSOD (NRPROMA)
REAL(KIND=JPRB) :: ZPQO3  (NRPROMA,KLEV)
REAL(KIND=JPRB) :: ZCAPH  (NRPROMA,KLEV+1)
REAL(KIND=JPRB) :: ZGEOH  (NRPROMA,KLEV+1)
REAL(KIND=JPRB) :: ZCHTI  (NRPROMA,KLEV+1)
REAL(KIND=JPRB) :: ZCLC   (NRPROMA,KLEV)
REAL(KIND=JPRB) :: ZQLWP  (NRPROMA,KLEV)
REAL(KIND=JPRB) :: ZQIWP  (NRPROMA,KLEV)
REAL(KIND=JPRB) :: ZQRWP  (NRPROMA,KLEV)
REAL(KIND=JPRB) :: ZQSWP  (NRPROMA,KLEV)
REAL(KIND=JPRB) :: ZTRSO  (NRPROMA,KLEV+1)
REAL(KIND=JPRB) :: ZEMTD  (NRPROMA,KLEV+1)
REAL(KIND=JPRB) :: ZEMTU  (NRPROMA,KLEV+1)
REAL(KIND=JPRB) :: ZTRSC  (NRPROMA,KLEV+1)
REAL(KIND=JPRB) :: ZEMTC  (NRPROMA,KLEV+1)
REAL(KIND=JPRB) :: ZTRSOD (NRPROMA)
REAL(KIND=JPRB) :: ZSUDU  (NRPROMA)
REAL(KIND=JPRB) :: ZUVDF  (NRPROMA)
REAL(KIND=JPRB) :: ZPARF  (NRPROMA)
REAL(KIND=JPRB) :: ZPARCF (NRPROMA), ZTINCF(NRPROMA)
REAL(KIND=JPRB) :: ZFDIR  (NRPROMA), ZCDIR (NRPROMA)
REAL(KIND=JPRB) :: ZEMIT  (NRPROMA)
REAL(KIND=JPRB) :: ZDUMMY (NRPROMA,KLEV, NSW)
REAL(KIND=JPRB) :: ZECPO3 (NRPROMA,KLEV)

REAL(KIND=JPRB) :: ZINUM_KS(NRPROMA,KLEV)
REAL(KIND=JPRB) :: ZINUM_AS(NRPROMA,KLEV)
REAL(KIND=JPRB) :: ZINUM_CS(NRPROMA,KLEV)
REAL(KIND=JPRB) :: ZSU2TM(NRPROMA,KLEV)
REAL(KIND=JPRB) :: ZSU3TM(NRPROMA,KLEV)
REAL(KIND=JPRB) :: ZSU4TM(NRPROMA,KLEV)
REAL(KIND=JPRB) :: ZBC2TM(NRPROMA,KLEV)
REAL(KIND=JPRB) :: ZBC3TM(NRPROMA,KLEV)
REAL(KIND=JPRB) :: ZBC4TM(NRPROMA,KLEV)
REAL(KIND=JPRB) :: ZBC5TM(NRPROMA,KLEV)
REAL(KIND=JPRB) :: ZOM2TM(NRPROMA,KLEV)
REAL(KIND=JPRB) :: ZOM3TM(NRPROMA,KLEV)
REAL(KIND=JPRB) :: ZOM4TM(NRPROMA,KLEV)
REAL(KIND=JPRB) :: ZOM5TM(NRPROMA,KLEV)
REAL(KIND=JPRB) :: ZSS3TM(NRPROMA,KLEV)
REAL(KIND=JPRB) :: ZSS4TM(NRPROMA,KLEV)
REAL(KIND=JPRB) :: ZDD3TM(NRPROMA,KLEV)
REAL(KIND=JPRB) :: ZDD4TM(NRPROMA,KLEV)
REAL(KIND=JPRB) :: ZDD6TM(NRPROMA,KLEV)
REAL(KIND=JPRB) :: ZDD7TM(NRPROMA,KLEV)

INTEGER(KIND=JPIM) :: INUMFLD(NPRTRV)
INTEGER(KIND=JPIM), ALLOCATABLE :: IVSETSC(:), ISTALAT(:)

REAL(KIND=JPRB), ALLOCATABLE :: ZRGP (:,:,:)
REAL(KIND=JPRB), ALLOCATABLE :: ZRGPBUF (:,:)
REAL(KIND=JPRB), ALLOCATABLE :: ZSPMOD(:,:)
REAL(KIND=JPRB), ALLOCATABLE :: ZSPRAD(:,:)
REAL(KIND=JPRB), ALLOCATABLE :: ZPARITY(:)
REAL(KIND=JPRB), ALLOCATABLE :: ZLSDEPI(:)

REAL(KIND=JPRB) :: ZDSLAT(NRPROMA,1)
REAL(KIND=JPRB) :: ZCSLA (NRPROMA,1,2:4)
REAL(KIND=JPRB) :: ZDSLON(NRPROMA,1,0:3)
REAL(KIND=JPRB) :: ZCSLO (NRPROMA,1,3,2)

REAL(KIND=JPRB) :: ZSFSWDIR(NRPROMA,NSW)
REAL(KIND=JPRB) :: ZSFSWDIF(NRPROMA,NSW)
REAL(KIND=JPRB) :: ZFSDNN(NRPROMA)
REAL(KIND=JPRB) :: ZFSDNV(NRPROMA)

INTEGER(KIND=JPIM) :: IL0S(NRPROMA,1,0:3)
INTEGER(KIND=JPIM) :: IL0ULI(NRPROMA,2,2), IL0UDI(NRPROMA,0:3,0:3)

INTEGER(KIND=JPIM) :: I,IBEG,IEND,IB,IK,IL,I1,I2,IM,IMD,IRD,ICNT,&
 & J,JIR,JB,JK,JL,JM,JN,JLEV,JRL,JSW,JSTGLO,JFLD,JGL,&
 & INEXT,IINBEG,IINEND,IOUTBEG,IOUTEND,IFLD,&
 & IFLDSIN,IFLDSOUT,IFLDSTOT,IGPBLKS,IGPBLKS_RAD,IGI,IGIX,&
 & IWIS,IFLDN,IFLDX,IGLGLO  

INTEGER(KIND=JPIM) :: IMU0,IAMU0,IALTE,IALTW,ITS,ISLM,IBAS,ITOP,IFRSOD,IEMIT,&
 & ISUDU,IUVDF,IPARF,IPARCF,ITINCF,IFDIR,ICDIR,IALD,IALP,ITI,IPR,IQS,IWV,ICLC,ILWA,IIWA,ISWA,IRWA,&
! & IRRA,IDP,IOZ,IHTI,IHPR,IFRSO,ISWFC,IFRTH,ILWFC,IAER,IAERP,IAERO,&
 & IRRA,IDP,IOZ,IHTI,IHPR,IFRSO,ISWFC,IFRTH,ILWFC,IAE,IAER,IAERO,&
 & IGEOH,IAPRS,IGELAM,IGEMU,ICLON,ISLON,IECPO3,ICCNL,ICCNO,&
 & ICO2,ICH4,IN2O,INO2,IC11,IC12,IC22,ICL4  
INTEGER(KIND=JPIM) :: IEXTRA, IEXTR2
INTEGER(KIND=JPIM) :: IDUMMY   

INTEGER(KIND=JPIM) :: ISW
INTEGER(KIND=JPIM) :: IO3TM,ICH4TM,IAODTM,ISSATM,IASFTM,ISU2TM,ISU3TM,ISU4TM,&
 & IBC2TM,IBC3TM,IBC4TM,IBC5TM,IOM2TM,IOM3TM,IOM4TM,IOM5TM,IDD3TM,IDD4TM,IDD6TM,IDD7TM,&
 & ISS3TM,ISS4TM

INTEGER(KIND=JPIM) :: ICDNC, IICNC, IRE_LIQ, IRE_ICE, JAER 

INTEGER(KIND=JPIM) :: IDUMARR(2)
REAL(KIND=JPRB) :: ZCRAE, ZRII0, ZDEPI, ZPIS2, Z4JP,ZDUM,ZREPALB
LOGICAL :: LLDEBUG, LLDEBUGRW, LLINC, LLDOLAST, LLERROR, LLREAD, LLPRINT, LLACTAERO
! BEN - introduce flag to activate aerosols in the radiation code
!>>dod not used, deleted <<

CHARACTER (LEN = 32) ::  CL_DEBUGFN
CHARACTER (LEN = 2), PARAMETER ::  CCATSTR(14) = (/ '01', '02', '03', '04', '05', '06', '07', &
 & '08', '09', '10', '11', '12', '13', '14' /)
REAL(KIND=JPRB) :: ZPERTAER,ZPERTOZ

REAL(KIND=JPRB) :: ZHOOK_HANDLE

! Double radiation
LOGICAL :: LZEROAERO2
REAL(KIND=JPRB) :: ZAMU1(NGPTOT)

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

INTERFACE
#include "dir_trans.h"
#include "inv_trans.h"
#include "surf_inq.h"
END INTERFACE

#include "abor1.intfb.h"
#include "laiddiobs.intfb.h"
#include "laidliobs.intfb.h"
#include "cmip6_piaer_mxr_interp.intfb.h"
#include "radact.intfb.h"
#include "radlsw.intfb.h"
#include "radlswr.intfb.h"
#include "radozc.intfb.h"
#include "radozv.intfb.h"
#include "radghg.intfb.h"
#include "rdscaw.intfb.h"
#include "slcomm.intfb.h"
#include "slcomm2.intfb.h"
#include "slextpol.intfb.h"

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

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

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

!*       1.    PREPARATORY WORK
!              ----------------

CALL SURF_INQ(PREPALB=ZREPALB)
NIMP=0
NOUT=0
ZRII0=RII0*RADJUST

IGPBLKS    =(NGPTOT        -1)/NRPROMA+1
IGPBLKS_RAD=(RADGRID%NGPTOT-1)/NRPROMA+1

IF( NSTEP == 0 )THEN
  LLDEBUG=.FALSE.
  LLDEBUGRW=.FALSE.
ELSE
  LLDEBUG=.FALSE.
  LLDEBUGRW=.FALSE.
ENDIF

LLACTAERO=.FALSE.
IF (NAERO > 0) THEN
  LLACTAERO=.TRUE.
ENDIF

LLDEBUG = .FALSE.
!*       1.01    PARAMETERS EXTRACTED FROM COMDECKS (NON-TRANSPORTABLE)
!                ------------------------------------------------------

!*       1.02    PARAMETERS FOR LOCAL DIAGNOSTICS
!                --------------------------------

ZPERTAER = FLOAT(NPERTAER)*1.E-2_JPRB
ZPERTOZ  = FLOAT(NPERTOZ )*1.E-2_JPRB

!*       1.03    LOCAL CONSTANTS
!                ---------------

ZCRAE=RRAE*(RRAE+2.0_JPRB)

! SET UP SOLAR ZENITH ANGLE, CORRECTED FOR EARTH'S CURVATURE

DO JL=1,NGPTOT
  IF (PMU0(JL) > 1.E-10_JPRB) THEN
    ZAMU0(JL)=RRAE/(SQRT(PMU0(JL)**2+ZCRAE)-PMU0(JL))
  ELSE
    ZAMU0(JL)= RRAE/SQRT(ZCRAE)
  ENDIF 
ENDDO

! INDICES TO COUPLING FIELDS FOR TM5 RUNS

IF (LTM5O3 .AND. ICPLO3 == -1) ICPLO3 = CPLNG_IDX('A_O3')
IF (LTM5CH4 .AND. ICPLCH4 == -1) ICPLCH4 = CPLNG_IDX('A_CH4')

IF (LTM5AER) THEN

  IF (ICPLAOD(1) == -1) THEN
    DO JSW=1,14
      ICPLAOD(JSW) = CPLNG_IDX('A_AOD_'//CCATSTR(JSW))
      ICPLSSA(JSW) = CPLNG_IDX('A_SSA_'//CCATSTR(JSW))
      ICPLASF(JSW) = CPLNG_IDX('A_ASF_'//CCATSTR(JSW))
    END DO
  END IF
  IF (ICPLSU2 == -1) THEN
    ICPLSU2 = CPLNG_IDX('A_SU2')
    ICPLSU3 = CPLNG_IDX('A_SU3')
    ICPLSU4 = CPLNG_IDX('A_SU4')
    ICPLBC2 = CPLNG_IDX('A_BC2')
    ICPLBC3 = CPLNG_IDX('A_BC3')
    ICPLBC4 = CPLNG_IDX('A_BC4')
    ICPLBC5 = CPLNG_IDX('A_BC5')
    ICPLOM2 = CPLNG_IDX('A_OM2')
    ICPLOM3 = CPLNG_IDX('A_OM3')
    ICPLOM4 = CPLNG_IDX('A_OM4')
    ICPLOM5 = CPLNG_IDX('A_OM5')
    ICPLSS3 = CPLNG_IDX('A_SS3')
    ICPLSS4 = CPLNG_IDX('A_SS4')
    ICPLDD3 = CPLNG_IDX('A_DD3')
    ICPLDD4 = CPLNG_IDX('A_DD4')
    ICPLDD6 = CPLNG_IDX('A_DD6')
    ICPLDD7 = CPLNG_IDX('A_DD7')
  END IF
END IF
  
!  INITIALISE INDICES FOR VARIABLE

! INDRAD is a CONTAIN'd function (at end of this routine)

INEXT  =1
IINBEG =1                        ! start of input variables
IDUMMY =INDRAD(1,.TRUE.)         ! dummy field for those elements with .false.
                                 ! in the second argument to INDRAD. 
                                 ! At present, must be the first call of INDRAD
IGI    =INDRAD(1,LLDEBUG)
IMU0   =INDRAD(1,.TRUE.)
IAMU0  =INDRAD(1,.TRUE.)
IALTE  =INDRAD(1,.TRUE.)
IALTW  =INDRAD(1,.TRUE.)
ITS    =INDRAD(1,.TRUE.)
ISLM   =INDRAD(1,.TRUE.)
ICCNL  =INDRAD(1,.TRUE.)
ICCNO  =INDRAD(1,.TRUE.)
IBAS   =INDRAD(1,.TRUE.)
ITOP   =INDRAD(1,.TRUE.)
IGELAM =INDRAD(1,.TRUE.)
IGEMU  =INDRAD(1,.TRUE.)
ICLON  =INDRAD(1,.TRUE.)
ISLON  =INDRAD(1,.TRUE.)
IALD   =INDRAD(NSW,.TRUE.)
IALP   =INDRAD(NSW,.TRUE.)
ITI    =INDRAD(KLEV,.TRUE.)
IPR    =INDRAD(KLEV,.TRUE.)
IQS    =INDRAD(KLEV,.TRUE.)
IWV    =INDRAD(KLEV,.TRUE.)
ICLC   =INDRAD(KLEV,.TRUE.)
ILWA   =INDRAD(KLEV,.TRUE.)
IIWA   =INDRAD(KLEV,.TRUE.)
ISWA   =INDRAD(KLEV,.TRUE.)
IRWA   =INDRAD(KLEV,.TRUE.)
IRRA   =INDRAD(KLEV,.TRUE.)
IDP    =INDRAD(KLEV,.TRUE.)
IOZ    =INDRAD(KLEV,LRAYFM)
IECPO3 =INDRAD(KLEV ,.NOT.LRAYFM.AND.LEPO3RA.AND.YO3%LGP)
IHPR   =INDRAD(KLEV+1,.TRUE.)
IAPRS  =INDRAD(KLEV+1,.TRUE.)
IGEOH  =INDRAD(KLEV+1,.TRUE.)
IHTI   =INDRAD(KLEV+1,.TRUE.)
IAERO  =INDRAD(NAERO*KLEV,.NOT.LRAYFM .AND. LLACTAERO)

!ICO2   =INDRAD(KLEV,.TRUE.)
!ICH4   =INDRAD(KLEV,.TRUE.)
!IN2O   =INDRAD(KLEV,.TRUE.)
!INO2   =INDRAD(KLEV,.TRUE.)
!IC11   =INDRAD(KLEV,.TRUE.)
!IC12   =INDRAD(KLEV,.TRUE.)
!IC22   =INDRAD(KLEV,.TRUE.)
!ICL4   =INDRAD(KLEV,.TRUE.)

IO3TM  =INDRAD(KLEV,LTM5O3)
ICH4TM =INDRAD(KLEV,LTM5CH4)
IAODTM =INDRAD(KLEV*14,LTM5AER)
ISSATM =INDRAD(KLEV*14,LTM5AER)
IASFTM =INDRAD(KLEV*14,LTM5AER)

ISU2TM =INDRAD(KLEV,LTM5AER)
ISU3TM =INDRAD(KLEV,LTM5AER)
ISU4TM =INDRAD(KLEV,LTM5AER)
IBC2TM =INDRAD(KLEV,LTM5AER)
IBC3TM =INDRAD(KLEV,LTM5AER)
IBC4TM =INDRAD(KLEV,LTM5AER)
IBC5TM =INDRAD(KLEV,LTM5AER)
IOM2TM =INDRAD(KLEV,LTM5AER)
IOM3TM =INDRAD(KLEV,LTM5AER)
IOM4TM =INDRAD(KLEV,LTM5AER)
IOM5TM =INDRAD(KLEV,LTM5AER)
IDD3TM =INDRAD(KLEV,LTM5AER)
IDD4TM =INDRAD(KLEV,LTM5AER)
IDD6TM =INDRAD(KLEV,LTM5AER)
IDD7TM =INDRAD(KLEV,LTM5AER)
ISS3TM =INDRAD(KLEV,LTM5AER)
ISS4TM =INDRAD(KLEV,LTM5AER)

ICDNC = INDRAD(KLEV, NCLOUDACT > 0)
IICNC = INDRAD(KLEV, NCLOUDACT > 0)
IRE_LIQ = INDRAD(KLEV, NCLOUDACT > 0)
IRE_ICE = INDRAD(KLEV, NCLOUDACT > 0)

!IAER   =INDRAD(KLEV*6,.TRUE.)
!IOZ    =INDRAD(KLEV,.NOT.LRAYFM)
!IAER = INDRAD(KLEV*6,NCLOUDACT==0)
!IOZ = INDRAD(KLEV, NCLOUDACT==0 .AND. (.NOT.LRAYFM))

IINEND =INEXT-1                  ! end of input variables

IOUTBEG=INEXT                    ! start of output variables

IFRSOD =INDRAD(1,.TRUE.)
IEMIT  =INDRAD(1,.TRUE.)
ISUDU  =INDRAD(1,.TRUE.)
IUVDF  =INDRAD(1,.TRUE.)
IPARF  =INDRAD(1,.TRUE.)
IPARCF =INDRAD(1,.TRUE.)
ITINCF =INDRAD(1,.TRUE.)
IFDIR  =INDRAD(1,.TRUE.)
ICDIR  =INDRAD(1,.TRUE.)
IFRSO  =INDRAD(KLEV+1,.TRUE.)
ISWFC  =INDRAD(KLEV+1,.TRUE.)
IFRTH  =INDRAD(KLEV+1,.TRUE.)
ILWFC  =INDRAD(KLEV+1,.TRUE.)
IGIX   =INDRAD(1,LLDEBUG)

IEXTRA = INDRAD(NRAD3D*KLEVX, NRAD3D>0)
IEXTR2 = INDRAD(NRAD2D, NRAD2D>0)

IOUTEND=INEXT-1                  ! end of output variables

                                 ! start of local variables
IAER   =INDRAD(KLEV*6,.TRUE.)
IOZ    =INDRAD(KLEV,.NOT.LRAYFM)
ICO2   =INDRAD(KLEV,.TRUE.)
ICH4   =INDRAD(KLEV,.TRUE.)
IN2O   =INDRAD(KLEV,.TRUE.)
INO2   =INDRAD(KLEV,.TRUE.)
IC11   =INDRAD(KLEV,.TRUE.)
IC12   =INDRAD(KLEV,.TRUE.)
IC22   =INDRAD(KLEV,.TRUE.)
ICL4   =INDRAD(KLEV,.TRUE.)

                                 ! end of local variables

IF( LLDEBUG )THEN
  WRITE(NULOUT,'("RADINTG: IMU0   =",I6)')IMU0
  WRITE(NULOUT,'("RADINTG: IAMU0  =",I6)')IAMU0
  WRITE(NULOUT,'("RADINTG: IALTE  =",I6)')IALTE
  WRITE(NULOUT,'("RADINTG: IALTW  =",I6)')IALTW
  WRITE(NULOUT,'("RADINTG: ITS    =",I6)')ITS
  WRITE(NULOUT,'("RADINTG: ISLM   =",I6)')ISLM
  WRITE(NULOUT,'("RADINTG: ICCNL  =",I6)')ICCNL
  WRITE(NULOUT,'("RADINTG: ICCNO  =",I6)')ICCNO
  WRITE(NULOUT,'("RADINTG: IBAS   =",I6)')IBAS
  WRITE(NULOUT,'("RADINTG: ITOP   =",I6)')ITOP
  WRITE(NULOUT,'("RADINTG: IGELAM =",I6)')IGELAM
  WRITE(NULOUT,'("RADINTG: IGEMU  =",I6)')IGEMU
  WRITE(NULOUT,'("RADINTG: ICLON  =",I6)')ICLON
  WRITE(NULOUT,'("RADINTG: ISLON  =",I6)')ISLON
  WRITE(NULOUT,'("RADINTG: IALD   =",I6)')IALD
  WRITE(NULOUT,'("RADINTG: IALP   =",I6)')IALP
  WRITE(NULOUT,'("RADINTG: ITI    =",I6)')ITI
  WRITE(NULOUT,'("RADINTG: IPR    =",I6)')IPR
  WRITE(NULOUT,'("RADINTG: IQS    =",I6)')IQS
  WRITE(NULOUT,'("RADINTG: IWV    =",I6)')IWV
  WRITE(NULOUT,'("RADINTG: ICLC   =",I6)')ICLC
  WRITE(NULOUT,'("RADINTG: ILWA   =",I6)')ILWA
  WRITE(NULOUT,'("RADINTG: IIWA   =",I6)')IIWA
  WRITE(NULOUT,'("RADINTG: ISWA   =",I6)')ISWA
  WRITE(NULOUT,'("RADINTG: IRWA   =",I6)')IRWA
  WRITE(NULOUT,'("RADINTG: IRRA   =",I6)')IRRA
  WRITE(NULOUT,'("RADINTG: IDP    =",I6)')IDP
  WRITE(NULOUT,'("RADINTG: IOZ    =",I6)')IOZ
  WRITE(NULOUT,'("RADINTG: IECPO3 =",I6)')IECPO3
  WRITE(NULOUT,'("RADINTG: IHPR   =",I6)')IHPR
  WRITE(NULOUT,'("RADINTG: IAPRS  =",I6)')IAPRS
  WRITE(NULOUT,'("RADINTG: IGEOH  =",I6)')IGEOH
  WRITE(NULOUT,'("RADINTG: IHTI   =",I6)')IHTI
  WRITE(NULOUT,'("RADINTG: IFRSOD =",I6)')IFRSOD
  WRITE(NULOUT,'("RADINTG: IEMIT  =",I6)')IEMIT
  WRITE(NULOUT,'("RADINTG: ISUDU  =",I6)')ISUDU
  WRITE(NULOUT,'("RADINTG: IUVDF  =",I6)')IUVDF
  WRITE(NULOUT,'("RADINTG: IPARF  =",I6)')IPARF
  WRITE(NULOUT,'("RADINTG: IPARCF =",I6)')IPARCF
  WRITE(NULOUT,'("RADINTG: ITINCF =",I6)')ITINCF
  WRITE(NULOUT,'("RADINTG: IFDIR  =",I6)')IFDIR
  WRITE(NULOUT,'("RADINTG: ICDIR  =",I6)')ICDIR
  WRITE(NULOUT,'("RADINTG: IFRSO  =",I6)')IFRSO
  WRITE(NULOUT,'("RADINTG: ISWFC  =",I6)')ISWFC
  WRITE(NULOUT,'("RADINTG: IFRTH  =",I6)')IFRTH
  WRITE(NULOUT,'("RADINTG: ILWFC  =",I6)')ILWFC
  WRITE(NULOUT,'("RADINTG: IGI    =",I6)')IGI
  WRITE(NULOUT,'("RADINTG: IAER   =",I6)')IAER
  WRITE(NULOUT,'("RADINTG: IAERO  =",I6)')IAERO
  WRITE(NULOUT,'("RADINTG: ICO2   =",I6)')ICO2
  WRITE(NULOUT,'("RADINTG: ICH4   =",I6)')ICH4
  WRITE(NULOUT,'("RADINTG: IN2O   =",I6)')IN2O
  WRITE(NULOUT,'("RADINTG: INO2   =",I6)')INO2
  WRITE(NULOUT,'("RADINTG: IC11   =",I6)')IC11
  WRITE(NULOUT,'("RADINTG: IC12   =",I6)')IC12
  WRITE(NULOUT,'("RADINTG: IC22   =",I6)')IC22
  WRITE(NULOUT,'("RADINTG: ICL4   =",I6)')ICL4
  WRITE(NULOUT,'("RADINTG: IO3TM   =",I6)')IO3TM
  WRITE(NULOUT,'("RADINTG: ICH4TM  =",I6)')ICH4TM
  WRITE(NULOUT,'("RADINTG: IAODTM  =",I6)')IAODTM
  WRITE(NULOUT,'("RADINTG: ISSATM  =",I6)')ISSATM
  WRITE(NULOUT,'("RADINTG: IASFTM  =",I6)')IASFTM

  WRITE(NULOUT,'("RADINTG: ISU2TM  =",I6)')ISU2TM
  WRITE(NULOUT,'("RADINTG: ISU3TM  =",I6)')ISU3TM
  WRITE(NULOUT,'("RADINTG: ISU4TM  =",I6)')ISU4TM
  WRITE(NULOUT,'("RADINTG: IBC2TM  =",I6)')IBC2TM
  WRITE(NULOUT,'("RADINTG: IBC3TM  =",I6)')IBC3TM
  WRITE(NULOUT,'("RADINTG: IBC4TM  =",I6)')IBC4TM
  WRITE(NULOUT,'("RADINTG: IBC5TM  =",I6)')IBC5TM
  WRITE(NULOUT,'("RADINTG: IOM2TM  =",I6)')IOM2TM
  WRITE(NULOUT,'("RADINTG: IOM3TM  =",I6)')IOM3TM
  WRITE(NULOUT,'("RADINTG: IOM4TM  =",I6)')IOM4TM
  WRITE(NULOUT,'("RADINTG: IOM5TM  =",I6)')IOM5TM
  WRITE(NULOUT,'("RADINTG: IDD3TM  =",I6)')IDD3TM
  WRITE(NULOUT,'("RADINTG: IDD4TM  =",I6)')IDD4TM
  WRITE(NULOUT,'("RADINTG: IDD6TM  =",I6)')IDD6TM
  WRITE(NULOUT,'("RADINTG: IDD7TM  =",I6)')IDD7TM
  WRITE(NULOUT,'("RADINTG: ISS3TM  =",I6)')ISS3TM
  WRITE(NULOUT,'("RADINTG: ISS4TM  =",I6)')ISS4TM
  WRITE(NULOUT,'("RADINTG: ICDNC   =",I6)')ICDNC
  WRITE(NULOUT,'("RADINTG: IICNC   =",I6)')IICNC
  WRITE(NULOUT,'("RADINTG: IRE_LIQ =",I6)')IRE_LIQ
  WRITE(NULOUT,'("RADINTG: IRE_ICE =",I6)')IRE_ICE

  WRITE(NULOUT,'("RADINTG: ICPLO3  =",I0)')ICPLO3
  WRITE(NULOUT,'("RADINTG: ICPLCH4 =",I0)')ICPLCH4
  WRITE(NULOUT,'("RADINTG: ICPLAOD =",14(1x,I0))')ICPLAOD(:)
  WRITE(NULOUT,'("RADINTG: ICPLSSA =",14(1x,I0))')ICPLSSA(:)
  WRITE(NULOUT,'("RADINTG: ICPLASF =",14(1x,I0))')ICPLASF(:)
ENDIF

IFLDSIN = IINEND - IINBEG +1
IFLDSOUT= IOUTEND-IOUTBEG +1
IFLDSTOT= INEXT  - 1

IF( NRADRES /= NSMAX )THEN
  ALLOCATE(ZRGP(NRPROMA,IFLDSIN,IGPBLKS))
ELSE
  ALLOCATE(ZRGP(NRPROMA,IFLDSTOT,IGPBLKS))
ENDIF
ZRGP=0.0_JPRB

!  INPUT LOOP

CALL GSTATS(1209,0)
!$OMP  PARALLEL DO SCHEDULE(STATIC)&
!$OMP& PRIVATE(JSTGLO,JK,JSW,JL,IAE,IBEG,IEND,IL,IB,&
!$OMP&        ZCLC,ZQLWP,ZQIWP,ZQRWP,ZQSWP,ZPQO3,ZGEOH,ZCAPH,ZCHTI)
DO JSTGLO=1,NGPTOT,NRPROMA
  IBEG=JSTGLO
  IEND=MIN(IBEG+NRPROMA-1,NGPTOT)
  IL=IEND-IBEG+1
  IB=(JSTGLO-1)/NRPROMA+1

!*         2.     FULL GRID COMPUTATIONS


!*         2.1    FULL-LEVEL QUANTITIES

  DO JK=1,KLEV
    ZCLC(1:IL,JK)=MIN(MAX(PCLFR(IBEG:IEND,JK), 0.0_JPRB ), 1.0_JPRB )
    DO JL=1,IL
      IF (ZCLC(JL,JK) > REPCLC) THEN
        ZQLWP(JL,JK)=PQLWP(IBEG+JL-1,JK)/ZCLC(JL,JK)
        ZQIWP(JL,JK)=PQIWP(IBEG+JL-1,JK)/ZCLC(JL,JK)
        ZQRWP(JL,JK)=PQRAIN(IBEG+JL-1,JK)/ZCLC(JL,JK)
        ZQSWP(JL,JK)=PQSWP(IBEG+JL-1,JK)/ZCLC(JL,JK)
      ELSE
        ZQLWP(JL,JK)=0.0_JPRB
        ZQIWP(JL,JK)=0.0_JPRB
        ZQRWP(JL,JK)=0.0_JPRB
        ZQSWP(JL,JK)=0.0_JPRB
      ENDIF
    ENDDO
  ENDDO

  IF (LRAYFM) THEN
    DO JK=1,KLEV
! PQO3 (kg/kg) -> ZPQO3 (ppm Pa/Pa)
      ZPQO3(1:IL,JK)=PQO3(IBEG:IEND,JK)* PDP(IBEG:IEND,JK)* RMD/RMO3
    ENDDO
  ENDIF

!*         2.2    HALF-LEVEL QUANTITIES

  DO JK=2,KLEV
    ZGEOH(1:IL,JK)=PGEOH(IBEG:IEND,JK)
    ZCAPH(1:IL,JK)=PAPRS(IBEG:IEND,JK)
    PTH(IBEG:IEND,JK)=(PT(IBEG:IEND,JK-1)*PAPRSF(IBEG:IEND,JK-1)&
     & *(PAPRSF(IBEG:IEND,JK)-PAPRS(IBEG:IEND,JK))&
     & +PT(IBEG:IEND,JK)*PAPRSF(IBEG:IEND,JK)*(PAPRS(IBEG:IEND,JK)&
     & -PAPRSF(IBEG:IEND,JK-1)))&
     & *(1.0_JPRB/(PAPRS(IBEG:IEND,JK)*(PAPRSF(IBEG:IEND,JK)-PAPRSF(IBEG:IEND,JK-1))))  
    ZCHTI(1:IL,JK)=PTH(IBEG:IEND,JK)
  ENDDO

!*         2.3     QUANTITIES AT BOUNDARIES

  ZGEOH(1:IL,1)=PGEOH(IBEG:IEND,1)
  ZGEOH(1:IL,KLEV+1)=PGEOH(IBEG:IEND,KLEV+1)
  ZCAPH(1:IL,1)=PAPRS(IBEG:IEND,1)
  ZCAPH(1:IL,KLEV+1)=PAPRS(IBEG:IEND,KLEV+1)
  PTH(IBEG:IEND,1)=PT(IBEG:IEND,1)-PAPRSF(IBEG:IEND,1)*(PT(IBEG:IEND,1)&
   & -PTH(IBEG:IEND,2))/(PAPRSF(IBEG:IEND,1)-PAPRS(IBEG:IEND,2))  
  PTH(IBEG:IEND,KLEV+1)=PTS(IBEG:IEND)
  ZCHTI(1:IL,KLEV+1)=PTH(IBEG:IEND,KLEV+1)
  ZCHTI(1:IL,1)=PTH(IBEG:IEND,1)

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

!*         3.      PREPARE INPUT ARRAYS

  IF( LLDEBUG )THEN
    ZRGP(1:IL,IGI               ,IB) =NGLOBALINDEX(IBEG:IEND)
  ENDIF
  ZRGP(1:IL,IMU0                ,IB) =PMU0   (IBEG:IEND)
  ZRGP(1:IL,IAMU0               ,IB) =ZAMU0  (IBEG:IEND)
  ZRGP(1:IL,IALTE               ,IB) =PEMIS  (IBEG:IEND)
  ZRGP(1:IL,IALTW               ,IB) =PEMIW  (IBEG:IEND)
  ZRGP(1:IL,ITS                 ,IB) =PTS    (IBEG:IEND)
  ZRGP(1:IL,ISLM                ,IB) =PSLM   (IBEG:IEND)
  ZRGP(1:IL,ICCNL               ,IB) =PCCNL  (IBEG:IEND)
  ZRGP(1:IL,ICCNO               ,IB) =PCCNO  (IBEG:IEND)
  ZRGP(1:IL,IBAS                ,IB) =PNBAS  (IBEG:IEND)
  ZRGP(1:IL,ITOP                ,IB) =PNTOP  (IBEG:IEND)
  ZRGP(1:IL,IGELAM              ,IB) =PGELAM (IBEG:IEND)
  ZRGP(1:IL,IGEMU               ,IB) =PGEMU  (IBEG:IEND)
  ZRGP(1:IL,ICLON               ,IB) =PCLON  (IBEG:IEND)
  ZRGP(1:IL,ISLON               ,IB) =PSLON  (IBEG:IEND)
  ZRGP(1:IL,IALD:IALD+NSW-1     ,IB) =PALBD  (IBEG:IEND,1:NSW)
  ZRGP(1:IL,IALP:IALP+NSW-1     ,IB) =PALBP  (IBEG:IEND,1:NSW)
  ZRGP(1:IL,ITI:ITI  +KLEV-1    ,IB) =PT     (IBEG:IEND,1:KLEV)
  ZRGP(1:IL,IPR:IPR  +KLEV-1    ,IB) =PAPRSF (IBEG:IEND,1:KLEV)
  ZRGP(1:IL,IQS:IQS  +KLEV-1    ,IB) =PQS    (IBEG:IEND,1:KLEV)
  ZRGP(1:IL,IWV:IWV  +KLEV-1    ,IB) =PQ     (IBEG:IEND,1:KLEV)
  ZRGP(1:IL,ICLC:ICLC+KLEV-1    ,IB) =ZCLC   (1:IL,1:KLEV)
  ZRGP(1:IL,ILWA:ILWA+KLEV-1    ,IB) =ZQLWP  (1:IL,1:KLEV)
  ZRGP(1:IL,IIWA:IIWA+KLEV-1    ,IB) =ZQIWP  (1:IL,1:KLEV)
  ZRGP(1:IL,ISWA:ISWA+KLEV-1    ,IB) =ZQSWP  (1:IL,1:KLEV)
  ZRGP(1:IL,IRWA:IRWA+KLEV-1    ,IB) =ZQRWP  (1:IL,1:KLEV)
!  ZRGP(1:IL,IRWA:IRWA+KLEV-1    ,IB) =PQRAIN (IBEG:IEND,1:KLEV)
  ZRGP(1:IL,IRRA:IRRA+KLEV-1    ,IB) =PRAINT (IBEG:IEND,1:KLEV)
  ZRGP(1:IL,IDP:IDP  +KLEV-1    ,IB) =PDP    (IBEG:IEND,1:KLEV)

  IF( LRAYFM )THEN
    ZRGP(1:IL,IOZ:IOZ+KLEV-1    ,IB) =ZPQO3  (1:IL,1:KLEV)
  ENDIF
  IF( .NOT.LRAYFM.AND.LEPO3RA.AND.YO3%LGP )THEN
    ZRGP(1:IL,IECPO3:IECPO3+KLEV-1,IB) =PECPO3 (IBEG:IEND,1:KLEV)
    ZECPO3(1:IL,1:KLEV)=PECPO3 (IBEG:IEND,1:KLEV)
  ENDIF

  LLPRINT=.FALSE.
  IF( .NOT.LRAYFM .AND. NACTAERO > 0) THEN
    DO JK=1,KLEV
      IAE=(JK-1)*NAERO
      ZRGP(1:IL,IAERO+IAE:IAERO+IAE+NAERO-1,IB) =MAX(REPSCAER, PAERO(IBEG:IEND,JK,1:NAERO))
    ENDDO
  ELSE
    DO JK=1,KLEV
      IAE=(JK-1)*NAERO
      ZRGP(1:IL,IAERO+IAE:IAERO+IAE+NAERO-1,IB) =0._JPRB
    ENDDO
  ENDIF
  ZRGP(1:IL,IGEOH:IGEOH+KLEV    ,IB) =ZGEOH  (1:IL,1:KLEV+1)
  ZRGP(1:IL,IHPR:IHPR+KLEV      ,IB) =ZCAPH  (1:IL,1:KLEV+1)
  ZRGP(1:IL,IAPRS:IAPRS+KLEV    ,IB) =PAPRS  (IBEG:IEND,1:KLEV+1)
  ZRGP(1:IL,IHTI:IHTI+KLEV      ,IB) =ZCHTI  (1:IL,1:KLEV+1)

  ! O3 mass mixing ratio in kg/kg times pressure difference
  ! Vertical integration is done in a similar way as the radoz* routines (see below).
  IF (LTM5O3) THEN
    DO JK=1,KLEV
      ZRGP(1:IL,IO3TM+JK-1,IB) = CPLNG_FLD(ICPLO3)%D(IBEG:IEND,LEV_IDX_TM5(JK),1) * &
           & ( PAPRS(IBEG:IEND,JK+1) - PAPRS(IBEG:IEND,JK) )
    ENDDO
  ENDIF

  ! CH4 mass mixing ratio in kg/kg
  IF (LTM5CH4) THEN
    DO JK=1,KLEV
      ZRGP(1:IL,ICH4TM+JK-1,IB) = CPLNG_FLD(ICPLCH4)%D(IBEG:IEND,LEV_IDX_TM5(JK),1)
    ENDDO
  ENDIF

  IF (LTM5AER) THEN
    ! Aerosol optical properties in 14 wavebands
    DO JK=1,KLEV
      ISW=(JK-1)*14 
      ! Include offset in case upper levels have not been received from TM5
      IK = LEV_IDX_TM5(JK) - NLEV_TM5 + NLEV_TM5_AER
      IF (IK >= 1) THEN
         DO JSW=1,14
           ! For the combined aerosol types in TM5: 
           ! Aerosol optical depth per wavelength (unitless, i.e. integrated over the layer)
           ! Mass weighting of AOD has been moved from TM5 to here.
           ZRGP(1:IL,IAODTM+ISW+JSW-1,IB) = CPLNG_FLD(ICPLAOD(JSW))%D(IBEG:IEND,IK,1) * &
                & ( PAPRS(IBEG:IEND,JK+1) - PAPRS(IBEG:IEND,JK) ) / &
                & ( PAPRS(IBEG:IEND,LEV_IDX_MAX(LEV_IDX_TM5(JK))+1) &
                & - PAPRS(IBEG:IEND,LEV_IDX_MIN(LEV_IDX_TM5(JK))) )
           ! Single-scattering albedo per wavelength (unitless)
           ZRGP(1:IL,ISSATM+ISW+JSW-1,IB) = CPLNG_FLD(ICPLSSA(JSW))%D(IBEG:IEND,IK,1)
           ! Asymmetry factor per wavelength (unitless)
           ZRGP(1:IL,IASFTM+ISW+JSW-1,IB) = CPLNG_FLD(ICPLASF(JSW))%D(IBEG:IEND,IK,1)
         ENDDO
         ! Aerosol component mass mixing ratios in kg/kg
         ! These are used for LW radiation only.
         ZRGP(1:IL,ISU2TM+JK-1,IB) = CPLNG_FLD(ICPLSU2)%D(IBEG:IEND,IK,1)
         ZRGP(1:IL,ISU3TM+JK-1,IB) = CPLNG_FLD(ICPLSU3)%D(IBEG:IEND,IK,1)
         ZRGP(1:IL,ISU4TM+JK-1,IB) = CPLNG_FLD(ICPLSU4)%D(IBEG:IEND,IK,1)
         ZRGP(1:IL,IBC2TM+JK-1,IB) = CPLNG_FLD(ICPLBC2)%D(IBEG:IEND,IK,1)
         ZRGP(1:IL,IBC3TM+JK-1,IB) = CPLNG_FLD(ICPLBC3)%D(IBEG:IEND,IK,1)
         ZRGP(1:IL,IBC4TM+JK-1,IB) = CPLNG_FLD(ICPLBC4)%D(IBEG:IEND,IK,1)
         ZRGP(1:IL,IBC5TM+JK-1,IB) = CPLNG_FLD(ICPLBC5)%D(IBEG:IEND,IK,1)
         ZRGP(1:IL,IOM2TM+JK-1,IB) = CPLNG_FLD(ICPLOM2)%D(IBEG:IEND,IK,1)
         ZRGP(1:IL,IOM3TM+JK-1,IB) = CPLNG_FLD(ICPLOM3)%D(IBEG:IEND,IK,1)
         ZRGP(1:IL,IOM4TM+JK-1,IB) = CPLNG_FLD(ICPLOM4)%D(IBEG:IEND,IK,1)
         ZRGP(1:IL,IOM5TM+JK-1,IB) = CPLNG_FLD(ICPLOM5)%D(IBEG:IEND,IK,1)
         ZRGP(1:IL,IDD3TM+JK-1,IB) = CPLNG_FLD(ICPLDD3)%D(IBEG:IEND,IK,1)
         ZRGP(1:IL,IDD4TM+JK-1,IB) = CPLNG_FLD(ICPLDD4)%D(IBEG:IEND,IK,1)
         ZRGP(1:IL,IDD6TM+JK-1,IB) = CPLNG_FLD(ICPLDD6)%D(IBEG:IEND,IK,1)
         ZRGP(1:IL,IDD7TM+JK-1,IB) = CPLNG_FLD(ICPLDD7)%D(IBEG:IEND,IK,1)
         ZRGP(1:IL,ISS3TM+JK-1,IB) = CPLNG_FLD(ICPLSS3)%D(IBEG:IEND,IK,1)
         ZRGP(1:IL,ISS4TM+JK-1,IB) = CPLNG_FLD(ICPLSS4)%D(IBEG:IEND,IK,1) 
      ELSE
         ! At levels not received from TM5,
         ! at least aerosol optical depth and component mass mixing ratios
         ! should be set to zero.
         ! Since AOD is zero,
         ! the single-scatter albedo can be set to unity (no absorption),
         ! and asymmetry factor to zero,
         ! or any other value.
         DO JSW=1,14
            ZRGP(1:IL,IAODTM+ISW+JSW-1,IB) = 0._JPRB
            ZRGP(1:IL,ISSATM+ISW+JSW-1,IB) = 1._JPRB
            ZRGP(1:IL,IASFTM+ISW+JSW-1,IB) = 0._JPRB
         ENDDO
         ZRGP(1:IL,ISU2TM+JK-1,IB) = 0._JPRB
         ZRGP(1:IL,ISU3TM+JK-1,IB) = 0._JPRB
         ZRGP(1:IL,ISU4TM+JK-1,IB) = 0._JPRB
         ZRGP(1:IL,IBC2TM+JK-1,IB) = 0._JPRB
         ZRGP(1:IL,IBC3TM+JK-1,IB) = 0._JPRB
         ZRGP(1:IL,IBC4TM+JK-1,IB) = 0._JPRB
         ZRGP(1:IL,IBC5TM+JK-1,IB) = 0._JPRB
         ZRGP(1:IL,IOM2TM+JK-1,IB) = 0._JPRB
         ZRGP(1:IL,IOM3TM+JK-1,IB) = 0._JPRB
         ZRGP(1:IL,IOM4TM+JK-1,IB) = 0._JPRB
         ZRGP(1:IL,IOM5TM+JK-1,IB) = 0._JPRB
         ZRGP(1:IL,IDD3TM+JK-1,IB) = 0._JPRB
         ZRGP(1:IL,IDD4TM+JK-1,IB) = 0._JPRB
         ZRGP(1:IL,IDD6TM+JK-1,IB) = 0._JPRB
         ZRGP(1:IL,IDD7TM+JK-1,IB) = 0._JPRB
         ZRGP(1:IL,ISS3TM+JK-1,IB) = 0._JPRB
         ZRGP(1:IL,ISS4TM+JK-1,IB) = 0._JPRB
      ENDIF
    ENDDO
  ENDIF

  IF (NCLOUDACT > 0) THEN
     ZRGP(1:IL,ICDNC:ICDNC+KLEV-1,IB) = PCDNC(IBEG:IEND,1:KLEV)
     ZRGP(1:IL,IICNC:IICNC+KLEV-1,IB) = PICNC(IBEG:IEND,1:KLEV)
     ZRGP(1:IL,IRE_LIQ:IRE_LIQ+KLEV-1,IB) = PRE_LIQ(IBEG:IEND,1:KLEV)
     ZRGP(1:IL,IRE_ICE:IRE_ICE+KLEV-1,IB) = PRE_ICE(IBEG:IEND,1:KLEV)
  END IF

ENDDO
!$OMP END PARALLEL DO
CALL GSTATS(1209,1)

!  INPUT INTERPOLATION IF REQUIRED

IF( NRADRES /= NSMAX )THEN

  IF( NRADINT == 1 )THEN

!  INTERPOLATE FROM MODEL GRID TO RADIATION GRID USING A SPECTRAL TRANSFORM

    INUMFLD(:)=IFLDSIN/NPRTRV
    DO J=1,MOD(IFLDSIN,NPRTRV)
      INUMFLD(J)=INUMFLD(J)+1
    ENDDO

    ALLOCATE(IVSETSC(IFLDSIN))
    IFLD=0
    DO JB=1,NPRTRV
      DO JFLD=1,INUMFLD(JB)
        IFLD=IFLD+1
        IVSETSC(IFLD)=JB
      ENDDO
    ENDDO

    ALLOCATE(ZSPMOD(INUMFLD(MYSETV),NSPEC2))
    CALL DIR_TRANS(PSPSCALAR=ZSPMOD(:,:),KPROMA=NRPROMA,KVSETSC=IVSETSC(:),&
     & PGP=ZRGP)  
    DEALLOCATE(ZRGP)
    ALLOCATE(ZSPRAD(INUMFLD(MYSETV),RADGRID%NSPEC2))
    ZSPRAD(:,:)=0.0_JPRB
    DO JM=1,NUMP
      IM=MYMS(JM)
      IF( IM <= RADGRID%NSMAX )THEN
        IF( IM /= RADGRID%MYMS(JM) )THEN
          CALL ABOR1('SUECRAD: MYMS AND RADGRID%MYMS DIFFERENT')
        ENDIF
        DO JIR=0,1
          DO JN=IM,RADGRID%NSMAX
            IMD=NASM0(IM)+2*(JN-IM)+JIR
            IRD=RADGRID%NASM0(IM)+2*(JN-IM)+JIR
            ZSPRAD(:,IRD)=ZSPMOD(:,IMD)
          ENDDO
        ENDDO
      ENDIF
    ENDDO
    DEALLOCATE(ZSPMOD)
    ALLOCATE(ZRGP(NRPROMA,IFLDSTOT,IGPBLKS_RAD))
    CALL INV_TRANS(PSPSCALAR=ZSPRAD(:,:),KPROMA=NRPROMA,KVSETSC=IVSETSC(:),&
     & PGP=ZRGP,KRESOL=RADGRID%NRESOL_ID)  
    DEALLOCATE(ZSPRAD)
    DEALLOCATE(IVSETSC)
  
  ELSEIF( NRADINT == 2 .OR. NRADINT == 3 )THEN

    ALLOCATE(ZRGPBUF(NARIB1,IFLDSIN))
    CALL GSTATS(1209,0)
!$OMP  PARALLEL DO SCHEDULE(STATIC) PRIVATE(JSTGLO,IBEG,IEND,IL,IB,JL,JFLD)
    DO JSTGLO=1,NGPTOT,NRPROMA
      IBEG=JSTGLO
      IEND=MIN(IBEG+NRPROMA-1,NGPTOT)
      IL=IEND-IBEG+1
      IB=(JSTGLO-1)/NRPROMA+1
      DO JFLD=1,IFLDSIN
        DO JL=1,IL
          ZRGPBUF(NRICORE(JL+JSTGLO-1),JFLD)=ZRGP(JL,JFLD,IB)
        ENDDO
      ENDDO
    ENDDO
!$OMP END PARALLEL DO
    CALL GSTATS(1209,1)
    DEALLOCATE(ZRGP)
    ALLOCATE(ZRGP(NRPROMA,IFLDSTOT,IGPBLKS_RAD))
    
    IF( LRADONDEM )THEN
      IF( .NOT.ALLOCATED(MASK_RI1).AND.&
         & .NOT.ALLOCATED(MASK_RI2) )THEN  
        LRADONDEM_ACTIVE=.FALSE.
        ALLOCATE(MASK_RI1(1))
        ALLOCATE(MASK_RI2(NARIB1+4))
        MASK_RI2(:)=0
      ENDIF
    ELSE
      IF(.NOT.ALLOCATED(MASK_RI1)) ALLOCATE(MASK_RI1(1))
      IF(.NOT.ALLOCATED(MASK_RI2)) ALLOCATE(MASK_RI2(1))
    ENDIF
    IF (NPROC > 1)THEN
      LLINC=.FALSE.
      CALL GSTATS(66,0)
      IF( LRADONDEM.AND.LRADONDEM_ACTIVE )THEN
        NFIXRADFLD(1)=1
        NFIXRADFLD(2)=0
        CALL SLCOMM2(NARIB1,NRIPROCS,NRIRPT,&
         & NRISPT,NRISENDPOS,NRIRECVPOS,NRISENDPTR,NRIRECVPTR,NRICOMM,&
         & NFIXRADFLD,MASK_RI1,MASK_RI2,&
         & IFLDSIN,LLINC,ZRGPBUF)  
        IF( LLDEBUG )THEN
          WRITE(NULERR,'("RADINTG:NARIB1,SUM(MASK_RI2)=",2(2X,I12))')&
           & NARIB1,SUM(MASK_RI2)  
        ENDIF
      ELSE
        CALL SLCOMM(NARIB1,NRIPROCS,NRIRPT,&
         & NRISPT,NRISENDPOS,NRIRECVPOS,NRISENDPTR,NRIRECVPTR,NRICOMM,&
         & IDUMARR,IFLDSIN,LLINC,0,ZRGPBUF)  
      ENDIF
      CALL GSTATS(66,1)
    ENDIF
    ALLOCATE(ZPARITY(1:IFLDSIN))
    ZPARITY(1:IFLDSIN)=1
    IF( LRADONDEM.AND..NOT.LRADONDEM_ACTIVE )THEN
      NFIXRADFLD(1)=1
      NFIXRADFLD(2)=IFLDSIN
      CALL SLEXTPOL(NRIWIDEN,NRIWIDES,&
       & NARIB1,NDGSAG,NDGENG,NDGSAL,NDGENL,IFLDSIN,NRISTA,NRIONL,NRIOFF,&
       & NDGLG,NLOENG,NFRSTLOFF,MYFRSTACTLAT,MYLSTACTLAT,NFIXRADFLD,3,&
       & ZPARITY,ZRGPBUF,KMASK2=MASK_RI2)  
    ELSE
      CALL SLEXTPOL(NRIWIDEN,NRIWIDES,&
       & NARIB1,NDGSAG,NDGENG,NDGSAL,NDGENL,IFLDSIN,NRISTA,NRIONL,NRIOFF,&
       & NDGLG,NLOENG,NFRSTLOFF,MYFRSTACTLAT,MYLSTACTLAT,IDUMARR,1,&
       & ZPARITY,ZRGPBUF)  
    ENDIF
    DEALLOCATE(ZPARITY)

    IF    ( NRADINT == 2 )THEN
      IWIS=201
    ELSEIF( NRADINT == 3 )THEN
      IWIS=203
    ENDIF
    IFLDN=1
    IFLDX=IFLDSIN
    ZDEPI=2.0_JPRB*RPI
    ZPIS2=0.5_JPRB*RPI
    ALLOCATE(ISTALAT(NDGSAH:NDGENH))
    ALLOCATE(ZLSDEPI(NDGSAH:NDGENH))
    DO JGL=MAX(NDGSAG,NDGSAL+NFRSTLOFF-NRIWIDEN)-NFRSTLOFF,&
       & MIN(NDGENG,NDGENL+NFRSTLOFF+NRIWIDES)-NFRSTLOFF  
      IGLGLO=JGL+NFRSTLOFF
      ZLSDEPI(JGL)=REAL(NLOENG(IGLGLO),JPRB)/ZDEPI
      ISTALAT(JGL)=NRIOFF(JGL)
    ENDDO

    CALL GSTATS(1209,0)
!$OMP PARALLEL DO SCHEDULE(DYNAMIC,1) &
!$OMP&PRIVATE(JSTGLO,IBEG,IEND,IL,IB,J,ZDSLAT)&
!$OMP&PRIVATE(ZCSLA,ZDSLON,ZCSLO,IL0S,IL0ULI,IL0UDI,JLEV)
    DO JSTGLO=1,RADGRID%NGPTOT,NRPROMA
      IBEG=JSTGLO
      IEND=MIN(IBEG+NRPROMA-1,RADGRID%NGPTOT)
      IL=IEND-IBEG+1
      IB=(JSTGLO-1)/NRPROMA+1
      CALL RDSCAW(NRPROMA,1,IL,NDGSAH,NDGENH,&
       & ISTALAT(NDGSAH),IWIS,NFRSTLOFF,NRIEXT,&
       & 1-NDLON,NDLON+NDLON,1-NRIWIDEN,NDGENL+NRIWIDES,&
       & R4JP,ZPIS2,ZLSDEPI(NDGSAH),RLATI(NDGSAH),&
       & RIPI0(NDGSAH),RIPI1(NDGSAH),RIPI2(NDGSAH),&
       & RADGRID%GELAM(IBEG:),RADGRID%GELAT(IBEG:),&
       & ZDSLAT,ZCSLA,ZDSLON,ZCSLO,IL0S,&
       & NARIB1,MASK_RI2)  

      IF    ( NRADINT == 2 )THEN
        DO J=1,IL
          IL0ULI(J,1,1) = IL0S(J,1,1)+1
          IL0ULI(J,1,2) = IL0S(J,1,1)+2
          IL0ULI(J,2,1) = IL0S(J,1,2)+1
          IL0ULI(J,2,2) = IL0S(J,1,2)+2
        ENDDO
        DO JLEV=1,IFLDSIN
          CALL LAIDLIOBS(NARIB1,NRPROMA,1,IL,JLEV,IFLDSIN,&
           & IFLDN,IFLDX,&
           & ZDSLAT,ZDSLON(1,1,1),IL0ULI,&
           & ZRGPBUF,ZRGP(1,1,IB))  
        ENDDO
      ELSEIF( NRADINT == 3 )THEN
        DO J=1,IL
          IL0UDI(J,0,0) = 0
          IL0UDI(J,0,1) = IL0S(J,1,0)+1
          IL0UDI(J,0,2) = IL0S(J,1,0)+2
          IL0UDI(J,0,3) = 0
          IL0UDI(J,1,0) = IL0S(J,1,1)+0
          IL0UDI(J,1,1) = IL0S(J,1,1)+1
          IL0UDI(J,1,2) = IL0S(J,1,1)+2
          IL0UDI(J,1,3) = IL0S(J,1,1)+3
          IL0UDI(J,2,0) = IL0S(J,1,2)+0
          IL0UDI(J,2,1) = IL0S(J,1,2)+1
          IL0UDI(J,2,2) = IL0S(J,1,2)+2
          IL0UDI(J,2,3) = IL0S(J,1,2)+3
          IL0UDI(J,3,0) = 0
          IL0UDI(J,3,1) = IL0S(J,1,3)+1
          IL0UDI(J,3,2) = IL0S(J,1,3)+2
          IL0UDI(J,3,3) = 0
        ENDDO
        DO JLEV=1,IFLDSIN
          CALL LAIDDIOBS(NARIB1,NRPROMA,1,IL,JLEV,IFLDSIN,&
           & IFLDN,IFLDX,&
           & ZCSLA,ZDSLON,ZCSLO,IL0UDI,&
           & ZRGPBUF,ZRGP(1,1,IB))  
        ENDDO
      ENDIF

    ENDDO
!$OMP END PARALLEL DO
    CALL GSTATS(1209,1)

    DEALLOCATE(ISTALAT)
    DEALLOCATE(ZLSDEPI)
    DEALLOCATE(ZRGPBUF)

  ELSE
    CALL ABOR1('RADINTG:INPUT - INVALID INTERPOLATION METHOD')
  ENDIF
  
  CALL GSTATS(1209,0)
!$OMP PARALLEL DO SCHEDULE(STATIC) PRIVATE(JSTGLO,IBEG,IEND,IL,IB,JL)
  DO JSTGLO=1,RADGRID%NGPTOT,NRPROMA
    IBEG=JSTGLO
    IEND=MIN(IBEG+NRPROMA-1,RADGRID%NGPTOT)
    IL=IEND-IBEG+1
    IB=(JSTGLO-1)/NRPROMA+1
    ZRGP(1:IL,IGELAM,IB)=RADGRID%GELAM(IBEG:IEND)
    ZRGP(1:IL,ICLON ,IB)=RADGRID%GECLO(IBEG:IEND)
    ZRGP(1:IL,ISLON ,IB)=RADGRID%GESLO(IBEG:IEND)
    ZRGP(1:IL,IGEMU ,IB)=RADGRID%GEMU (IBEG:IEND)
    DO JL=1,IL
      IF (ZRGP(JL,IMU0,IB) > 1.E-10_JPRB) THEN
        ZRGP(JL,IAMU0,IB)=RRAE/(SQRT(ZRGP(JL,IMU0,IB)**2+ZCRAE)-&
         & ZRGP(JL,IMU0,IB))  
      ELSE
        ZRGP(JL,IAMU0,IB)=RRAE/SQRT(ZCRAE)
      ENDIF 
    ENDDO
  ENDDO
!$OMP END PARALLEL DO
  CALL GSTATS(1209,1)

  IF( LLDEBUGRW )THEN
    WRITE(CL_DEBUGFN,'("DEBUG",I3.3)')MYPROC
    OPEN(NULTMP,FILE=CL_DEBUGFN,FORM='unformatted')
    LLERROR=.FALSE.
    LLREAD=.TRUE.
    ICNT=0
    DO JSTGLO=1,RADGRID%NGPTOT,NRPROMA
      IBEG=JSTGLO
      IEND=MIN(IBEG+NRPROMA-1,RADGRID%NGPTOT)
      IL=IEND-IBEG+1
      IB=(JSTGLO-1)/NRPROMA+1
      DO JL=1,IL
        ICNT=ICNT+1
        IF( LLREAD )THEN
          READ(NULTMP) ZDUM
          IF( ZDUM /= ZRGP(JL,IGI,IB) )THEN
            LLERROR=.TRUE.
            WRITE(NULERR,'("RADINTG: ICNT,ZDUM,ZRGP=",I12,2(2X,F20.5))')&
             & ICNT,ZDUM,ZRGP(JL,IGI,IB)  
            WRITE(NULOUT,'("RADINTG: ICNT,ZDUM,ZRGP=",I12,2(2X,F20.5))')&
             & ICNT,ZDUM,ZRGP(JL,IGI,IB)  
          ENDIF
        ELSE
          WRITE(NULTMP)ZRGP(JL,IGI,IB)
        ENDIF
      ENDDO
    ENDDO
    IF( LLREAD )THEN
      IF( LLERROR )THEN
        CALL ABOR1('RADINTG: INPUT INTERP PROBLEM')
      ENDIF
    ENDIF
  ENDIF

ENDIF

!  COMPUTATION OF AEROSOLS, OZONE ON RADIATION GRID
!  SECURITY CHECKS

CALL GSTATS(1209,0)
!$OMP  PARALLEL DO SCHEDULE(DYNAMIC,1)&
!$OMP& PRIVATE(JSTGLO,J,JLEV,JSW,JL,IAE,IBEG,IEND,I,I1,I2,IL,IB,LLDOLAST,&
!$OMP&         ZQAER,ZQOZ,ZQCO2,ZQCH4,ZQN2O,ZQNO2,ZQC11,ZQC12,ZQOZO,ZQC22,ZQCL4)
DO JSTGLO=1,RADGRID%NGPTOT,NRPROMA
  IBEG=JSTGLO
  IEND=MIN(IBEG+NRPROMA-1,RADGRID%NGPTOT)
  IL=IEND-IBEG+1
  IB=(JSTGLO-1)/NRPROMA+1

!  SECURITY COMPUTATIONS FOR CRITICAL VARIABLES.

  DO JSW=1,NSW
    DO JL=1,IL
      ZRGP(JL,IALD+JSW-1,IB) = MIN( 1.0_JPRB,MAX(ZREPALB,ZRGP(JL,IALD+JSW-1,IB)))
      ZRGP(JL,IALP+JSW-1,IB) = MIN( 1.0_JPRB,MAX(ZREPALB,ZRGP(JL,IALP+JSW-1,IB)))
    ENDDO
  ENDDO
  DO JL=1,IL
!-- original bounds from Martin et al. (1994) are 375/1500 and 36/280
!-- bounds from the relationship between 10m wind and CCNs
    ZRGP(JL,ICCNL,IB) = MIN( 1743._JPRB,MAX(292._JPRB,ZRGP(JL,ICCNL,IB)))
    ZRGP(JL,ICCNO,IB) = MIN(  287._JPRB,MAX( 32._JPRB,ZRGP(JL,ICCNO,IB)))
  ENDDO

  DO JLEV=1,KLEV
    DO JL=1,IL
      ZRGP(JL,IQS+JLEV-1 ,IB) = MAX(REPSCQ,&
       & MAX(2.0_JPRB*REPH2O,ZRGP(JL,IQS+JLEV-1,IB)))  
      ZRGP(JL,IWV+JLEV-1 ,IB) = MAX(REPSCQ,&
       & MAX(REPH2O,MIN(ZRGP(JL,IWV+JLEV-1,IB),&
       & ZRGP(JL,IQS+JLEV-1,IB)*(1.0_JPRB-REPH2O))))  
      ZRGP(JL,ICLC+JLEV-1,IB) = MAX( 0.0_JPRB ,MIN( 1.0_JPRB ,&
       & ZRGP(JL,ICLC+JLEV-1,IB)))  
      ZRGP(JL,ILWA+JLEV-1,IB) = MAX(  0.0_JPRB, MAX(REPH2O,ZRGP(JL,ILWA+JLEV-1,IB))&
       & *ZRGP(JL,ICLC+JLEV-1,IB))  
      ZRGP(JL,IIWA+JLEV-1,IB) = MAX(  0.0_JPRB, MAX(REPH2O,ZRGP(JL,IIWA+JLEV-1,IB))&
       & *ZRGP(JL,ICLC+JLEV-1,IB))  
      ZRGP(JL,ISWA+JLEV-1,IB) = MAX(  0.0_JPRB, MAX(REPH2O,ZRGP(JL,ISWA+JLEV-1,IB))&
       & *ZRGP(JL,ICLC+JLEV-1,IB))  
      ZRGP(JL,IRWA+JLEV-1,IB) = MAX(  0.0_JPRB, MAX(REPH2O,ZRGP(JL,IRWA+JLEV-1,IB))&
       & *ZRGP(JL,ICLC+JLEV-1,IB))  
!      ZRGP(JL,IRWA+JLEV-1,IB) =MAX(0.0_JPRB,ZRGP(JL,IRWA+JLEV-1,IB))
      ZRGP(JL,IRRA+JLEV-1,IB) =MAX(0.0_JPRB,ZRGP(JL,IRRA+JLEV-1,IB))
    ENDDO
  ENDDO

!  COMPUTE DISTRIBUTION OF CLIMATOLOGICAL AEROSOLS AND OZONE DIRECTLY ON THE REDUCED RADIATION GRID

  IF(.NOT.LRAYFM) THEN
    I1=1
    I2=99999999
    DO JL=1,IL
      IF( ZRGP(JL,IGEMU,IB) /= ZRGP(I1,IGEMU,IB) .OR. JL == IL )THEN
        LLDOLAST=.FALSE.
        IF( JL == IL )THEN
          IF( ZRGP(JL,IGEMU,IB) == ZRGP(I1,IGEMU,IB) )THEN
            I2=IL
          ELSE
            I2=IL-1
            LLDOLAST=.TRUE.
          ENDIF
        ELSE
          I2=JL-1
        ENDIF
        1000    CONTINUE

        IF (LCMIP6_PI_AEROSOLS) THEN
          IF (LPI_AERO_UPDATED) THEN !interpolate CMIP6 pre-industrial TM5 aerosol climatology#

            CALL CMIP6_PIAER_MXR_INTERP & 
              & ( I1 , I2 , NRPROMA , KLEV, &
              & 1 , I1-1, &
              & ZRGP(1,IAPRS,IB) , ZRGP(1,IGELAM,IB), ZRGP(1,IGEMU,IB)  ,&
              & ZINUM_KS,  ZINUM_AS,  ZINUM_CS, &
              & ZSU2TM,  ZSU3TM,  ZSU4TM, &
              & ZBC2TM,  ZBC3TM,  ZBC4TM, ZBC5TM, &
              & ZOM2TM,  ZOM3TM,  ZOM4TM, ZOM5TM, &
              & ZSS3TM,  ZSS4TM, &
              & ZDD3TM,  ZDD4TM,  ZDD6TM, ZDD7TM )

            PI_AERO(I1:I2,:,IPINUM_KS,IB) = ZINUM_KS(I1:I2,:)
            PI_AERO(I1:I2,:,IPINUM_AS,IB) = ZINUM_AS(I1:I2,:)
            PI_AERO(I1:I2,:,IPINUM_CS,IB) = ZINUM_CS(I1:I2,:)
            PI_AERO(I1:I2,:,IPIMSO4_KS,IB) = ZSU2TM(I1:I2,:)
            PI_AERO(I1:I2,:,IPIMSO4_AS,IB) = ZSU3TM(I1:I2,:)
            PI_AERO(I1:I2,:,IPIMSO4_CS,IB) = ZSU4TM(I1:I2,:)
            PI_AERO(I1:I2,:,IPIMBC_KS,IB) = ZBC2TM(I1:I2,:)
            PI_AERO(I1:I2,:,IPIMBC_AS,IB) = ZBC3TM(I1:I2,:)
            PI_AERO(I1:I2,:,IPIMBC_CS,IB) = ZBC4TM(I1:I2,:)
            PI_AERO(I1:I2,:,IPIMBC_KI,IB) = ZBC5TM(I1:I2,:)
            PI_AERO(I1:I2,:,IPIMOC_KS,IB) = ZOM2TM(I1:I2,:)
            PI_AERO(I1:I2,:,IPIMOC_AS,IB) = ZOM3TM(I1:I2,:)
            PI_AERO(I1:I2,:,IPIMOC_CS,IB) = ZOM4TM(I1:I2,:)
            PI_AERO(I1:I2,:,IPIMOC_KI,IB) = ZOM5TM(I1:I2,:)
            PI_AERO(I1:I2,:,IPIMSS_AS,IB) = ZSS3TM(I1:I2,:)
            PI_AERO(I1:I2,:,IPIMSS_CS,IB) = ZSS4TM(I1:I2,:)
            PI_AERO(I1:I2,:,IPIMDU_AS,IB) = ZDD3TM(I1:I2,:)
            PI_AERO(I1:I2,:,IPIMDU_CS,IB) = ZDD4TM(I1:I2,:)
            PI_AERO(I1:I2,:,IPIMDU_AI,IB) = ZDD6TM(I1:I2,:)
            PI_AERO(I1:I2,:,IPIMDU_CI,IB) = ZDD7TM(I1:I2,:)
          ELSE
            ZINUM_KS(I1:I2,:) = PI_AERO(I1:I2,:,IPINUM_KS,IB)
            ZINUM_AS(I1:I2,:) = PI_AERO(I1:I2,:,IPINUM_AS,IB)
            ZINUM_CS(I1:I2,:) = PI_AERO(I1:I2,:,IPINUM_CS,IB)
            ZSU2TM(I1:I2,:) = PI_AERO(I1:I2,:,IPIMSO4_KS,IB) 
            ZSU3TM(I1:I2,:) = PI_AERO(I1:I2,:,IPIMSO4_AS,IB) 
            ZSU4TM(I1:I2,:) = PI_AERO(I1:I2,:,IPIMSO4_CS,IB)
            ZBC2TM(I1:I2,:) = PI_AERO(I1:I2,:,IPIMBC_KS,IB)
            ZBC3TM(I1:I2,:) = PI_AERO(I1:I2,:,IPIMBC_AS,IB)
            ZBC4TM(I1:I2,:) = PI_AERO(I1:I2,:,IPIMBC_CS,IB) 
            ZBC5TM(I1:I2,:) = PI_AERO(I1:I2,:,IPIMBC_KI,IB)
            ZOM2TM(I1:I2,:) = PI_AERO(I1:I2,:,IPIMOC_KS,IB)
            ZOM3TM(I1:I2,:) = PI_AERO(I1:I2,:,IPIMOC_AS,IB)
            ZOM4TM(I1:I2,:) = PI_AERO(I1:I2,:,IPIMOC_CS,IB)
            ZOM5TM(I1:I2,:) = PI_AERO(I1:I2,:,IPIMOC_KI,IB)
            ZSS3TM(I1:I2,:) = PI_AERO(I1:I2,:,IPIMSS_AS,IB)
            ZSS4TM(I1:I2,:) = PI_AERO(I1:I2,:,IPIMSS_CS,IB)
            ZDD3TM(I1:I2,:) = PI_AERO(I1:I2,:,IPIMDU_AS,IB)
            ZDD4TM(I1:I2,:) = PI_AERO(I1:I2,:,IPIMDU_CS,IB)
            ZDD6TM(I1:I2,:) = PI_AERO(I1:I2,:,IPIMDU_AI,IB)
            ZDD7TM(I1:I2,:) = PI_AERO(I1:I2,:,IPIMDU_CI,IB)
          ENDIF 
        ENDIF


        IF (LTM5AER) THEN
          CALL  RADACT ( I1 ,I2 ,NRPROMA ,KLEV,&
           & 1 ,NRPROMA  ,NRPROMA  ,I1-1 ,1,&
           & ZRGP(1,IAPRS,IB) , ZRGP(1,IGELAM,IB) , ZRGP(1,IGEMU,IB),&
           & ZRGP(1,ICLON,IB) , ZRGP(1,ISLON ,IB) , ZRGP(1,IHTI ,IB),&
           & ZRGP(1,IWV  ,IB) , ZRGP(1,IQS   ,IB) , ZECPO3,&
           & ZQAER , ZQOZ,&
           & ZRGP(1,ISU2TM,IB), ZRGP(1,ISU3TM,IB) , ZRGP(1,ISU4TM,IB),&
           & ZRGP(1,IBC2TM,IB), ZRGP(1,IBC3TM,IB) , ZRGP(1,IBC4TM,IB), ZRGP(1,IBC5TM,IB),&
           & ZRGP(1,IOM2TM,IB), ZRGP(1,IOM3TM,IB) , ZRGP(1,IOM4TM,IB), ZRGP(1,IOM5TM,IB),&
           & ZRGP(1,IDD3TM,IB), ZRGP(1,IDD4TM,IB) , ZRGP(1,IDD6TM,IB), ZRGP(1,IDD7TM,IB),&
           & ZRGP(1,ISS3TM,IB), ZRGP(1,ISS4TM,IB) )
        ELSE IF (LCMIP6_PI_AEROSOLS) THEN
          CALL  RADACT ( I1 ,I2 ,NRPROMA ,KLEV,&
           & 1 ,NRPROMA  ,NRPROMA  ,I1-1 ,1,&
           & ZRGP(1,IAPRS,IB) , ZRGP(1,IGELAM,IB) , ZRGP(1,IGEMU,IB),&
           & ZRGP(1,ICLON,IB) , ZRGP(1,ISLON ,IB) , ZRGP(1,IHTI ,IB),&
           & ZRGP(1,IWV  ,IB) , ZRGP(1,IQS   ,IB) , ZECPO3,&
           & ZQAER , ZQOZ,&
           & ZSU2TM, ZSU3TM, ZSU4TM,&
           & ZBC2TM, ZBC3TM, ZBC4TM, ZBC5TM,&
           & ZOM2TM, ZOM3TM, ZOM4TM, ZOM5TM,&
           & ZDD3TM, ZDD4TM, ZDD6TM, ZDD7TM,&
           & ZSS3TM, ZSS4TM )
        ELSE
           CALL  RADACT ( I1 ,I2 ,NRPROMA ,KLEV,&
             & 1 ,NRPROMA  ,NRPROMA  ,I1-1 ,1,&
             & ZRGP(1,IAPRS,IB) , ZRGP(1,IGELAM,IB) , ZRGP(1,IGEMU,IB),&
             & ZRGP(1,ICLON,IB) , ZRGP(1,ISLON ,IB) , ZRGP(1,IHTI ,IB),&
             & ZRGP(1,IWV  ,IB) , ZRGP(1,IQS   ,IB) , ZECPO3,&
             & ZQAER , ZQOZ  )  
        ENDIF  

        IF (NOZOCL == 1.AND..NOT.LEPO3RA.AND..NOT.LPHYLIN) THEN
          IF ((LCMIP5.OR.LCMIP6) .AND. .NOT.LTM5O3) THEN

            CALL RADOZV ( I1, I2, NRPROMA, 1, KLEV,&
             & 1 , NRPROMA , I1-1,&
             & ZRGP(1,IAPRS,IB) , ZRGP(1,IGELAM,IB) , ZRGP(1,IGEMU,IB),&
             & ZQOZ   )

          ELSE IF (LTM5O3) THEN
            ! set corresponding part of ZQOZ equal to TM5 O3 field (kg/kg times pressure difference)
            ZQOZ(I1:I2,1:KLEV)=ZRGP(I1:I2,IO3TM:IO3TM+KLEV-1,IB)

          ELSE
            CALL RADOZC ( I1, I2, NRPROMA, KLEV,&
             & 1 , NRPROMA , I1-1,&
             & ZRGP(1,IAPRS,IB) , ZRGP(1,IGEMU,IB),&
             & ZQOZ   )  
          ENDIF
        ENDIF

        IF (NGHGRAD /= 0 .AND. .NOT.LPHYLIN) THEN
          CALL RADGHG ( I1, I2, NRPROMA, KLEV,&
           & 1 , NRPROMA , I1-1,&
           & ZRGP(1,IAPRS,IB) , ZRGP(1,IGEMU,IB),&
           & ZQCO2, ZQCH4, ZQN2O, ZQNO2, ZQC11, ZQC12, ZQOZO, ZQC22, ZQCL4 )  
        ENDIF

        IF (LTM5CH4) THEN
          ! set corresponding part of ZQCH4 equal to TM5 CH4 field (kg/kg)
          ! overwrites ZQCH4 returned from RADGHG
          ZQCH4(I1:I2,1:KLEV)=ZRGP(I1:I2,ICH4TM:ICH4TM+KLEV-1,IB)
        ENDIF

        I1=JL
        IF( LLDOLAST )THEN
          LLDOLAST=.FALSE.
          I2=IL
          GOTO 1000
        ENDIF
      ENDIF
    ENDDO

!-- Prognostic O3 with interaction with radiation is required (ECMWF)
    IF(LEPO3RA.AND.YO3%LGP) THEN
      ZRGP(1:IL,IOZ:IOZ+KLEV-1,IB) = MAX( REPSCO, ZRGP(1:IL,IECPO3:IECPO3+KLEV-1,IB)*&
       & ZRGP(1:IL,IDP:IDP+KLEV-1,IB) )  
    ELSE
!-- Climatological O3 possibly scaled is used for radiation   (ECMWF)
!-- or TM5 O3 if LTM5O3 is true.
      IF (NPERTOZ /= 0) ZQOZ(1:IL,1:KLEV) = ZQOZ(1:IL,1:KLEV) * (1.0_JPRB+ZPERTOZ)
      ZRGP(1:IL,IOZ:IOZ+KLEV-1,IB) = ZQOZ(1:IL,1:KLEV)
    ENDIF

! -- by default, globally averaged concentrations (mmr)
    ZRGP(1:IL,ICO2:ICO2+KLEV-1,IB) = PCCO2
    ZRGP(1:IL,ICH4:ICH4+KLEV-1,IB) = RCH4
    ZRGP(1:IL,IN2O:IN2O+KLEV-1,IB) = RN2O
    ZRGP(1:IL,INO2:INO2+KLEV-1,IB) = RNO2
    ZRGP(1:IL,IC11:IC11+KLEV-1,IB) = RCFC11
    ZRGP(1:IL,IC12:IC12+KLEV-1,IB) = RCFC12
    ZRGP(1:IL,IC22:IC22+KLEV-1,IB) = RCFC22
    ZRGP(1:IL,ICL4:ICL4+KLEV-1,IB) = RCCL4

    IF(NGHGRAD == 1 .OR. NGHGRAD >= 10) THEN
      ZRGP(1:IL,ICO2:ICO2+KLEV-1,IB) = ZQCO2(1:IL,1:KLEV)
    ENDIF
    IF(NGHGRAD == 2 .OR. NGHGRAD >= 11) THEN
      ZRGP(1:IL,ICH4:ICH4+KLEV-1,IB) = ZQCH4(1:IL,1:KLEV)
    ENDIF
    IF(NGHGRAD == 3 .OR. NGHGRAD >= 12) THEN
      ZRGP(1:IL,IN2O:IN2O+KLEV-1,IB) = ZQN2O(1:IL,1:KLEV)
    ENDIF
    IF(NGHGRAD == 4 .OR. NGHGRAD >= 20) THEN
      ZRGP(1:IL,INO2:INO2+KLEV-1,IB) = ZQNO2(1:IL,1:KLEV)
    ENDIF
    IF(NGHGRAD == 5 .OR. NGHGRAD >= 15) THEN
      ZRGP(1:IL,IC11:IC11+KLEV-1,IB) = ZQC11(1:IL,1:KLEV)
    ENDIF
    IF(NGHGRAD == 6 .OR. NGHGRAD >= 16) THEN
      ZRGP(1:IL,IC12:IC12+KLEV-1,IB) = ZQC12(1:IL,1:KLEV)
    ENDIF
    IF(NGHGRAD == 7 .OR. NGHGRAD == 17 .OR. NGHGRAD >= 21) THEN
      ZRGP(1:IL, IOZ:IOZ+KLEV-1 ,IB) = ZQOZO(1:IL,1:KLEV) *&
        & ZRGP(1:IL, IDP:IDP+KLEV-1, IB)
    ENDIF
    IF(NGHGRAD == 8 .OR. NGHGRAD >= 18) THEN
      ZRGP(1:IL,IC22:IC22+KLEV-1,IB) = ZQC22(1:IL,1:KLEV)
    ENDIF
    IF(NGHGRAD == 9 .OR. NGHGRAD >= 19) THEN
      ZRGP(1:IL,ICL4:ICL4+KLEV-1,IB) = ZQCL4(1:IL,1:KLEV)
    ENDIF

!-- Whether interaction of radiation with ECMWF prognostic aerosols is required or not,
!   get the climatological aerosols, with climatological aerosols possibly scaled is 
!   used for radiation   (ECMWF) 
    DO JLEV=1,KLEV
      IF (NPERTAER /= 0) ZQAER(1:IL,1:6,JLEV) = ZQAER(1:IL,1:6,JLEV) * (1.0_JPRB+ZPERTAER)
      I=(JLEV-1)*6
      ZRGP(1:IL,IAER+I:IAER+I+6-1,IB) = ZQAER(1:IL,1:6,JLEV)
    ENDDO
 ENDIF

  IF ( NACTAERO == 0 ) THEN 
    IF(.NOT.LRAYFM) THEN
      DO JLEV=1,KLEV
        IF (NPERTAER /= 0) ZQAER(1:IL,1:6,JLEV) = ZQAER(1:IL,1:6,JLEV) * (1.0_JPRB+ZPERTAER)
        I=(JLEV-1)*6
        ZRGP(1:IL,IAER+I:IAER+I+6-1,IB) = ZQAER(1:IL,1:6,JLEV)
      ENDDO
!correction to wrong Geleyn's O3 climatology done above 
    ELSEIF (NAER /= 0  .AND. .NOT.LHVOLCA) THEN
!  Supported but no transforms are performed (model grid = radiation grid)
      DO JLEV=1,KLEV
        I=(JLEV-1)*6
        ZRGP(1:IL,IAER+I:IAER+I+6-1,IB) = PAER(IBEG:IEND,1:6,JLEV)
      ENDDO
      ZRGP(1:IL,IOZ:IOZ+KLEV-1,IB) = PQO3(IBEG:IEND,1:KLEV)
    ELSE
      DO JLEV=1,KLEV
        I=(JLEV-1)*6
        ZRGP(1:IL,IAER+I:IAER+I+6-1,IB) = ZQAER(1:IL,1:6,JLEV)
      ENDDO
    ENDIF
 ENDIF

  IF (NAER == 0) THEN
    DO JLEV=1,KLEV
      I=(JLEV-1)*6
      ZRGP(1:IL,IAER+I:IAER+I+6-1,IB) = RCAEROS
    ENDDO
  ELSEIF (.NOT.LHVOLCA) THEN
    DO JLEV=1,KLEV
      I=(JLEV-1)*6
      ZRGP(1:IL,IAER+I+5-1,IB) = RCAEROS
    ENDDO
  ENDIF
 !--
  IF (NAER == 1 .AND. LNOTROAER) THEN
    DO JLEV=1,KLEV
      I=(JLEV-1)*6
      ZRGP(1:IL,IAER+I+1-1,IB) = RCAEROS
      ZRGP(1:IL,IAER+I+2-1,IB) = RCAEROS
      ZRGP(1:IL,IAER+I+3-1,IB) = RCAEROS
      ZRGP(1:IL,IAER+I+4-1,IB) = RCAEROS
      ZRGP(1:IL,IAER+I+6-1,IB) = RCAEROS
    ENDDO
  ENDIF

! Compute pressure thickness of layers

  DO JLEV=1,KLEV
    DO JL=1,IL
      ZRGP(JL,IDP+JLEV-1,IB)  =ZRGP(JL,IHPR+JLEV,IB)-ZRGP(JL,IHPR+JLEV-1,IB)
    ENDDO
  ENDDO

  IF( LLDEBUG )THEN
    ZRGP(:,IGIX,:)=ZRGP(:,IGI,:)
  ENDIF

ENDDO
!$OMP END PARALLEL DO

CALL GSTATS(1209,1)

!  PERFORM RADIATION COMPUTATIONS

CALL GSTATS(1210,0)

! Double radiation
! Note: the logical is only implemented for RADLSWR call.
IF (PRESENT(LZEROAERO)) THEN
   LZEROAERO2=LZEROAERO
ELSE
   LZEROAERO2=.FALSE.
END IF

!$OMP PARALLEL DO SCHEDULE(DYNAMIC,1)&
!$OMP&PRIVATE(JRL,IBEG,IEND,IL,IB)
DO JRL=1,RADGRID%NGPTOT,NRPROMA

  IBEG=JRL
  IEND=MIN(IBEG+NRPROMA-1,RADGRID%NGPTOT)
  IL=IEND-IBEG+1
  IB=(JRL-1)/NRPROMA+1

!*         4.2     CALL TO ACTUAL RADIATION SCHEME
  IF (.NOT.LSRTM) THEN 

    CALL RADLSW &
     & ( 1 , IL , NRPROMA , KLEV,&
     & KMODE ,NAER,&
     & ZRII0,&
     & ZRGP(1,IAER,IB)    ,ZRGP(1,IALD,IB)   ,ZRGP(1,IALP,IB),&
     & ZRGP(1,IHPR,IB)    ,ZRGP(1,IPR,IB),&
     & ZRGP(1,ICCNL,IB)   ,ZRGP(1,ICCNO,IB)  ,PCCO2,&
     & ZRGP(1,ICLC,IB)    ,ZRGP(1,IDP,IB)    ,ZRGP(1,IALTE,IB),&
     & ZRGP(1,IALTW,IB)   ,ZRGP(1,ISLM,IB)   ,ZRGP(1,IAMU0,IB),&
     & ZRGP(1,IOZ,IB)     ,ZRGP(1,IWV,IB)    ,ZRGP(1,IIWA,IB),& 
     & ZRGP(1,ILWA,IB)    ,ZRGP(1,IQS,IB)    ,&
     & ZRGP(1,IHTI,IB)   ,ZRGP(1,ITI,IB),&
     & ZRGP(1,ITS,IB)     ,ZRGP(1,IBAS,IB)   ,ZRGP(1,ITOP,IB),&
     ! FLUX OUTPUTS
     & ZRGP(1,IEMIT,IB)   ,ZRGP(1,ILWFC,IB)  ,ZRGP(1,IFRTH,IB),&
     & ZRGP(1,ISWFC,IB)   ,ZRGP(1,IFRSO,IB)  ,ZRGP(1,IFRSOD,IB),&
     & ZRGP(1,ISUDU,IB)   ,ZRGP(1,IUVDF,IB)  ,ZRGP(1,IPARF,IB),&
     & ZRGP(1,IPARCF,IB)  ,ZRGP(1,ITINCF,IB) ,&
     & ZSFSWDIR, ZSFSWDIF,ZFSDNN,ZFSDNV, &
     & .FALSE., ZDUMMY, ZDUMMY, ZDUMMY )   

  ELSE

    IF (.NOT.LTM5AER) THEN
     IF (LCMIP6_PI_AEROSOLS) THEN !prescribed CMIP6 pre-industrial TM5 aerosol climatology

      IF (NCLOUDACT == 0) THEN 
       CALL RADLSWR &
         & ( 1 , IL , NRPROMA , KLEV , IB , NAERO,&
         & ZRII0,&
         & ZRGP(1,IAER,IB)   ,ZRGP(1,IAERO,IB) ,&
         & ZRGP(1,IALD,IB)   ,ZRGP(1,IALP,IB)  ,&
         & ZRGP(1,IGEOH,IB)  ,ZRGP(1,IHPR,IB)  ,ZRGP(1,IPR,IB)   ,&
         & ZRGP(1,ICCNL,IB)  ,ZRGP(1,ICCNO,IB) ,&
         & ZRGP(1,IGELAM,IB) ,ZRGP(1,IGEMU,IB) ,&
         & ZRGP(1,ICO2,IB)   ,ZRGP(1,ICH4,IB)  ,ZRGP(1,IN2O,IB) ,&
         & ZRGP(1,INO2,IB)   ,ZRGP(1,IC11,IB)  ,ZRGP(1,IC12,IB) ,&
         & ZRGP(1,IC22,IB)   ,ZRGP(1,ICL4,IB)  ,&
         & ZRGP(1,ICLC,IB)   ,ZRGP(1,IDP,IB)   ,ZRGP(1,IALTE,IB),&
         & ZRGP(1,IALTW,IB)  ,ZRGP(1,ISLM,IB)  ,ZRGP(1,IAMU0,IB),&
         & ZRGP(1,IOZ,IB)    ,ZRGP(1,IWV,IB)   ,ZRGP(1,IIWA,IB), ZRGP(1,ISWA,IB),&
         & ZRGP(1,ILWA,IB)   ,ZRGP(1,IRWA,IB)  ,ZRGP(1,IHTI,IB) ,ZRGP(1,ITI,IB),&
         & ZRGP(1,ITS,IB)    ,&
         ! FLUX OUTPUTS
         & ZRGP(1,IEMIT,IB)  ,ZRGP(1,ILWFC,IB) ,ZRGP(1,IFRTH,IB),&
         & ZRGP(1,ISWFC,IB)  ,ZRGP(1,IFRSO,IB) ,ZRGP(1,IFRSOD,IB),&
         & ZRGP(1,ISUDU,IB)  ,ZRGP(1,IUVDF,IB) ,ZRGP(1,IPARF,IB), &
         & ZRGP(1,IPARCF,IB) ,ZRGP(1,ITINCF,IB),&
         & ZRGP(1,IFDIR,IB)  ,ZRGP(1,ICDIR,IB) ,&
         & KLEVX             ,ZRGP(1,IEXTRA,IB),ZRGP(1,IEXTR2,IB), &
         & LZEROAERO2 )   
      ELSE
        CALL RADLSWR &
         & ( 1 , IL , NRPROMA , KLEV , IB , NAERO,&
         & ZRII0,&
         & ZRGP(1,IAER,IB)   ,ZRGP(1,IAERO,IB) ,&
         & ZRGP(1,IALD,IB)   ,ZRGP(1,IALP,IB)  ,&
         & ZRGP(1,IGEOH,IB)  ,ZRGP(1,IHPR,IB)  ,ZRGP(1,IPR,IB)   ,&
         & ZRGP(1,ICCNL,IB)  ,ZRGP(1,ICCNO,IB) ,&
         & ZRGP(1,IGELAM,IB) ,ZRGP(1,IGEMU,IB) ,&
         & ZRGP(1,ICO2,IB)   ,ZRGP(1,ICH4,IB)  ,ZRGP(1,IN2O,IB) ,&
         & ZRGP(1,INO2,IB)   ,ZRGP(1,IC11,IB)  ,ZRGP(1,IC12,IB) ,&
         & ZRGP(1,IC22,IB)   ,ZRGP(1,ICL4,IB)  ,&
         & ZRGP(1,ICLC,IB)   ,ZRGP(1,IDP,IB)   ,ZRGP(1,IALTE,IB),&
         & ZRGP(1,IALTW,IB)  ,ZRGP(1,ISLM,IB)  ,ZRGP(1,IAMU0,IB),&
         & ZRGP(1,IOZ,IB)    ,ZRGP(1,IWV,IB)   ,ZRGP(1,IIWA,IB), ZRGP(1,ISWA,IB),&
         & ZRGP(1,ILWA,IB)   ,ZRGP(1,IRWA,IB)  ,ZRGP(1,IHTI,IB) ,ZRGP(1,ITI,IB),&
         & ZRGP(1,ITS,IB)    ,&
         ! FLUX OUTPUTS
         & ZRGP(1,IEMIT,IB)  ,ZRGP(1,ILWFC,IB) ,ZRGP(1,IFRTH,IB),&
         & ZRGP(1,ISWFC,IB)  ,ZRGP(1,IFRSO,IB) ,ZRGP(1,IFRSOD,IB),&
         & ZRGP(1,ISUDU,IB)  ,ZRGP(1,IUVDF,IB) ,ZRGP(1,IPARF,IB), &
         & ZRGP(1,IPARCF,IB) ,ZRGP(1,ITINCF,IB),&
         & ZRGP(1,IFDIR,IB)  ,ZRGP(1,ICDIR,IB) ,&
         & KLEVX             ,ZRGP(1,IEXTRA,IB),ZRGP(1,IEXTR2,IB), &
         & LZEROAERO2, &
         & PCDNC=ZRGP(1,ICDNC,IB),  PICNC=ZRGP(1,IICNC,IB), &
         & PRE_LIQ=ZRGP(1,IRE_LIQ,IB), PRE_ICE=ZRGP(1,IRE_ICE,IB) &
         & )   
      END IF
     ELSE ! Tegen
      IF (NCLOUDACT == 0) THEN 
       CALL RADLSWR &
         & ( 1 , IL , NRPROMA , KLEV , IB , NAERO,&
         & ZRII0,&
         & ZRGP(1,IAER,IB)   ,ZRGP(1,IAERO,IB) ,&
         & ZRGP(1,IALD,IB)   ,ZRGP(1,IALP,IB)  ,&
         & ZRGP(1,IGEOH,IB)  ,ZRGP(1,IHPR,IB)  ,ZRGP(1,IPR,IB)   ,&
         & ZRGP(1,ICCNL,IB)  ,ZRGP(1,ICCNO,IB) ,&
         & ZRGP(1,IGELAM,IB) ,ZRGP(1,IGEMU,IB) ,&
         & ZRGP(1,ICO2,IB)   ,ZRGP(1,ICH4,IB)  ,ZRGP(1,IN2O,IB) ,&
         & ZRGP(1,INO2,IB)   ,ZRGP(1,IC11,IB)  ,ZRGP(1,IC12,IB) ,&
         & ZRGP(1,IC22,IB)   ,ZRGP(1,ICL4,IB)  ,&
         & ZRGP(1,ICLC,IB)   ,ZRGP(1,IDP,IB)   ,ZRGP(1,IALTE,IB),&
         & ZRGP(1,IALTW,IB)  ,ZRGP(1,ISLM,IB)  ,ZRGP(1,IAMU0,IB),&
         & ZRGP(1,IOZ,IB)    ,ZRGP(1,IWV,IB)   ,ZRGP(1,IIWA,IB), ZRGP(1,ISWA,IB),&
         & ZRGP(1,ILWA,IB)   ,ZRGP(1,IRWA,IB)  ,ZRGP(1,IHTI,IB) ,ZRGP(1,ITI,IB),&
         & ZRGP(1,ITS,IB)    ,&
         ! FLUX OUTPUTS
         & ZRGP(1,IEMIT,IB)  ,ZRGP(1,ILWFC,IB) ,ZRGP(1,IFRTH,IB),&
         & ZRGP(1,ISWFC,IB)  ,ZRGP(1,IFRSO,IB) ,ZRGP(1,IFRSOD,IB),&
         & ZRGP(1,ISUDU,IB)  ,ZRGP(1,IUVDF,IB) ,ZRGP(1,IPARF,IB), &
         & ZRGP(1,IPARCF,IB) ,ZRGP(1,ITINCF,IB),&
         & ZRGP(1,IFDIR,IB)  ,ZRGP(1,ICDIR,IB) ,&
         & KLEVX             ,ZRGP(1,IEXTRA,IB),ZRGP(1,IEXTR2,IB), &
         & LZEROAERO2)   
      ELSE
        CALL RADLSWR &
         & ( 1 , IL , NRPROMA , KLEV , IB , NAERO,&
         & ZRII0,&
         & ZRGP(1,IAER,IB)   ,ZRGP(1,IAERO,IB) ,&
         & ZRGP(1,IALD,IB)   ,ZRGP(1,IALP,IB)  ,&
         & ZRGP(1,IGEOH,IB)  ,ZRGP(1,IHPR,IB)  ,ZRGP(1,IPR,IB)   ,&
         & ZRGP(1,ICCNL,IB)  ,ZRGP(1,ICCNO,IB) ,&
         & ZRGP(1,IGELAM,IB) ,ZRGP(1,IGEMU,IB) ,&
         & ZRGP(1,ICO2,IB)   ,ZRGP(1,ICH4,IB)  ,ZRGP(1,IN2O,IB) ,&
         & ZRGP(1,INO2,IB)   ,ZRGP(1,IC11,IB)  ,ZRGP(1,IC12,IB) ,&
         & ZRGP(1,IC22,IB)   ,ZRGP(1,ICL4,IB)  ,&
         & ZRGP(1,ICLC,IB)   ,ZRGP(1,IDP,IB)   ,ZRGP(1,IALTE,IB),&
         & ZRGP(1,IALTW,IB)  ,ZRGP(1,ISLM,IB)  ,ZRGP(1,IAMU0,IB),&
         & ZRGP(1,IOZ,IB)    ,ZRGP(1,IWV,IB)   ,ZRGP(1,IIWA,IB), ZRGP(1,ISWA,IB),&
         & ZRGP(1,ILWA,IB)   ,ZRGP(1,IRWA,IB)  ,ZRGP(1,IHTI,IB) ,ZRGP(1,ITI,IB),&
         & ZRGP(1,ITS,IB)    ,&
         ! FLUX OUTPUTS
         & ZRGP(1,IEMIT,IB)  ,ZRGP(1,ILWFC,IB) ,ZRGP(1,IFRTH,IB),&
         & ZRGP(1,ISWFC,IB)  ,ZRGP(1,IFRSO,IB) ,ZRGP(1,IFRSOD,IB),&
         & ZRGP(1,ISUDU,IB)  ,ZRGP(1,IUVDF,IB) ,ZRGP(1,IPARF,IB), &
         & ZRGP(1,IPARCF,IB) ,ZRGP(1,ITINCF,IB),&
         & ZRGP(1,IFDIR,IB)  ,ZRGP(1,ICDIR,IB) ,&
         & KLEVX             ,ZRGP(1,IEXTRA,IB),ZRGP(1,IEXTR2,IB), &
         & LZEROAERO2, &
         & PCDNC=ZRGP(1,ICDNC,IB),  PICNC=ZRGP(1,IICNC,IB), &
         & PRE_LIQ=ZRGP(1,IRE_LIQ,IB), PRE_ICE=ZRGP(1,IRE_ICE,IB) &
         & )
      END IF
     ENDIF

    ELSE

      IF (NCLOUDACT == 0) THEN
        CALL RADLSWR &
         & ( 1 , IL , NRPROMA , KLEV , IB , NAERO,&
         & ZRII0,&
         & ZRGP(1,IAER,IB)   ,ZRGP(1,IAERO,IB) ,&
         & ZRGP(1,IALD,IB)   ,ZRGP(1,IALP,IB)  ,&
         & ZRGP(1,IGEOH,IB)  ,ZRGP(1,IHPR,IB)  ,ZRGP(1,IPR,IB)   ,&
         & ZRGP(1,ICCNL,IB)  ,ZRGP(1,ICCNO,IB) ,&
         & ZRGP(1,IGELAM,IB) ,ZRGP(1,IGEMU,IB) ,&
         & ZRGP(1,ICO2,IB)   ,ZRGP(1,ICH4,IB)  ,ZRGP(1,IN2O,IB) ,&
         & ZRGP(1,INO2,IB)   ,ZRGP(1,IC11,IB)  ,ZRGP(1,IC12,IB) ,&
         & ZRGP(1,IC22,IB)   ,ZRGP(1,ICL4,IB)  ,&
         & ZRGP(1,ICLC,IB)   ,ZRGP(1,IDP,IB)   ,ZRGP(1,IALTE,IB),&
         & ZRGP(1,IALTW,IB)  ,ZRGP(1,ISLM,IB)  ,ZRGP(1,IAMU0,IB),&
         & ZRGP(1,IOZ,IB)    ,ZRGP(1,IWV,IB)   ,ZRGP(1,IIWA,IB), ZRGP(1,ISWA,IB),&
         & ZRGP(1,ILWA,IB)   ,ZRGP(1,IRWA,IB)  ,ZRGP(1,IHTI,IB) ,ZRGP(1,ITI,IB),&
         & ZRGP(1,ITS,IB)    ,&
         ! FLUX OUTPUTS
         & ZRGP(1,IEMIT,IB)  ,ZRGP(1,ILWFC,IB) ,ZRGP(1,IFRTH,IB),&
         & ZRGP(1,ISWFC,IB)  ,ZRGP(1,IFRSO,IB) ,ZRGP(1,IFRSOD,IB),&
         & ZRGP(1,ISUDU,IB)  ,ZRGP(1,IUVDF,IB) ,ZRGP(1,IPARF,IB), &
         & ZRGP(1,IPARCF,IB) ,ZRGP(1,ITINCF,IB),&
         & ZRGP(1,IFDIR,IB)  ,ZRGP(1,ICDIR,IB) ,&
         & KLEVX             ,ZRGP(1,IEXTRA,IB),ZRGP(1,IEXTR2,IB), &
         & LZEROAERO2, &
         ! AEROSOL OPTICAL PARAMETER FIELDS FROM TM
         & PAODTM=ZRGP(1,IAODTM,IB) ,PSSATM=ZRGP(1,ISSATM,IB),PASFTM=ZRGP(1,IASFTM,IB) &
         & ) 
      ELSE
        CALL RADLSWR &
         & ( 1 , IL , NRPROMA , KLEV , IB , NAERO,&
         & ZRII0,&
         & ZRGP(1,IAER,IB)   ,ZRGP(1,IAERO,IB) ,&
         & ZRGP(1,IALD,IB)   ,ZRGP(1,IALP,IB)  ,&
         & ZRGP(1,IGEOH,IB)  ,ZRGP(1,IHPR,IB)  ,ZRGP(1,IPR,IB)   ,&
         & ZRGP(1,ICCNL,IB)  ,ZRGP(1,ICCNO,IB) ,&
         & ZRGP(1,IGELAM,IB) ,ZRGP(1,IGEMU,IB) ,&
         & ZRGP(1,ICO2,IB)   ,ZRGP(1,ICH4,IB)  ,ZRGP(1,IN2O,IB) ,&
         & ZRGP(1,INO2,IB)   ,ZRGP(1,IC11,IB)  ,ZRGP(1,IC12,IB) ,&
         & ZRGP(1,IC22,IB)   ,ZRGP(1,ICL4,IB)  ,&
         & ZRGP(1,ICLC,IB)   ,ZRGP(1,IDP,IB)   ,ZRGP(1,IALTE,IB),&
         & ZRGP(1,IALTW,IB)  ,ZRGP(1,ISLM,IB)  ,ZRGP(1,IAMU0,IB),&
         & ZRGP(1,IOZ,IB)    ,ZRGP(1,IWV,IB)   ,ZRGP(1,IIWA,IB), ZRGP(1,ISWA,IB),&
         & ZRGP(1,ILWA,IB)   ,ZRGP(1,IRWA,IB)  ,ZRGP(1,IHTI,IB) ,ZRGP(1,ITI,IB),&
         & ZRGP(1,ITS,IB)    ,&
         ! FLUX OUTPUTS
         & ZRGP(1,IEMIT,IB)  ,ZRGP(1,ILWFC,IB) ,ZRGP(1,IFRTH,IB),&
         & ZRGP(1,ISWFC,IB)  ,ZRGP(1,IFRSO,IB) ,ZRGP(1,IFRSOD,IB),&
         & ZRGP(1,ISUDU,IB)  ,ZRGP(1,IUVDF,IB) ,ZRGP(1,IPARF,IB), &
         & ZRGP(1,IPARCF,IB) ,ZRGP(1,ITINCF,IB),&
         & ZRGP(1,IFDIR,IB)  ,ZRGP(1,ICDIR,IB) ,&
         & KLEVX             ,ZRGP(1,IEXTRA,IB),ZRGP(1,IEXTR2,IB), &
         & LZEROAERO2, &
         ! AEROSOL OPTICAL PARAMETER FIELDS FROM TM
         & PAODTM=ZRGP(1,IAODTM,IB) ,PSSATM=ZRGP(1,ISSATM,IB),PASFTM=ZRGP(1,IASFTM,IB), &
         & PCDNC=ZRGP(1,ICDNC,IB),  PICNC=ZRGP(1,IICNC,IB), &
         & PRE_LIQ=ZRGP(1,IRE_LIQ,IB), PRE_ICE=ZRGP(1,IRE_ICE,IB) &
         & ) 
      ENDIF
   ENDIF
  ENDIF

ENDDO
!$OMP END PARALLEL DO

CALL GSTATS(1210,1)

!  OUTPUT INTERPOLATION IF REQUIRED

IF( NRADRES /= NSMAX )THEN

  IF( NRADINT == 1 )THEN

!  INTERPOLATE FROM RADIATION GRID TO MODEL GRID USING A SPECTRAL TRANSFORM

    INUMFLD(:)=IFLDSOUT/NPRTRV
    DO J=1,MOD(IFLDSOUT,NPRTRV)
      INUMFLD(J)=INUMFLD(J)+1
    ENDDO
  
    ALLOCATE(IVSETSC(IFLDSOUT))
    IFLD=0
    DO JB=1,NPRTRV
      DO JFLD=1,INUMFLD(JB)
        IFLD=IFLD+1
        IVSETSC(IFLD)=JB
      ENDDO
    ENDDO
  
    ALLOCATE(ZSPRAD(INUMFLD(MYSETV),RADGRID%NSPEC2))
    CALL DIR_TRANS(PSPSCALAR=ZSPRAD(:,:),KPROMA=NRPROMA,KVSETSC=IVSETSC(:),&
     & PGP=ZRGP(:,IOUTBEG:IOUTEND,:),KRESOL=RADGRID%NRESOL_ID)  
    DEALLOCATE(ZRGP)
    ALLOCATE(ZSPMOD(INUMFLD(MYSETV),NSPEC2))
    ZSPMOD(:,:)=0.0_JPRB
    DO JM=1,RADGRID%NUMP
      IM=MYMS(JM)
      IF( IM /= RADGRID%MYMS(JM) )THEN
        CALL ABOR1('SUECRAD: MYMS AND RADGRID%MYMS DIFFERENT')
      ENDIF
      DO JIR=0,1
        DO JN=IM,RADGRID%NSMAX
          IMD=NASM0(IM)+2*(JN-IM)+JIR
          IRD=RADGRID%NASM0(IM)+2*(JN-IM)+JIR
          ZSPMOD(:,IMD)=ZSPRAD(:,IRD)
        ENDDO
      ENDDO
    ENDDO
    DEALLOCATE(ZSPRAD)
    ALLOCATE(ZRGP(NRPROMA,IFLDSOUT,IGPBLKS))
    CALL INV_TRANS(PSPSCALAR=ZSPMOD(:,:),KPROMA=NRPROMA,KVSETSC=IVSETSC(:),&
     & PGP=ZRGP)  
    DEALLOCATE(ZSPMOD)
    DEALLOCATE(IVSETSC)

  ELSEIF( NRADINT == 2 .OR. NRADINT == 3 )THEN
  
    ALLOCATE(ZRGPBUF(NAROB1,IFLDSOUT))
    CALL GSTATS(1211,0)
!$OMP  PARALLEL DO SCHEDULE(STATIC) PRIVATE(JSTGLO,IBEG,IEND,IL,IB,JL,JFLD)
    DO JSTGLO=1,RADGRID%NGPTOT,NRPROMA
      IBEG=JSTGLO
      IEND=MIN(IBEG+NRPROMA-1,RADGRID%NGPTOT)
      IL=IEND-IBEG+1
      IB=(JSTGLO-1)/NRPROMA+1
      DO JFLD=1,IFLDSOUT
        DO JL=1,IL
          ZRGPBUF(NROCORE(JL+JSTGLO-1),JFLD)=ZRGP(JL,IOUTBEG+JFLD-1,IB)
        ENDDO
      ENDDO
    ENDDO
!$OMP END PARALLEL DO
    CALL GSTATS(1211,1)
    DEALLOCATE(ZRGP)
    ALLOCATE(ZRGP(NRPROMA,IFLDSOUT,IGPBLKS))
   
    IF( LRADONDEM )THEN
      IF( .NOT.LRADONDEM_ACTIVE )THEN
        ALLOCATE(MASK_RO1(1))
        ALLOCATE(MASK_RO2(NAROB1+4))
        MASK_RO2(:)=0
      ENDIF
    ELSE
      IF(.NOT.ALLOCATED(MASK_RO1)) ALLOCATE(MASK_RO1(1))
      IF(.NOT.ALLOCATED(MASK_RO2)) ALLOCATE(MASK_RO2(1))
    ENDIF
    IF (NPROC > 1)THEN
      LLINC=.FALSE.
      CALL GSTATS(65,0)
      IF( LRADONDEM.AND.LRADONDEM_ACTIVE )THEN
        NFIXRADFLD(1)=1
        NFIXRADFLD(2)=0
        CALL SLCOMM2(NAROB1,NROPROCS,NRORPT,&
         & NROSPT,NROSENDPOS,NRORECVPOS,NROSENDPTR,NRORECVPTR,NROCOMM,&
         & NFIXRADFLD,MASK_RO1,MASK_RO2,&
         & IFLDSOUT,LLINC,ZRGPBUF)  
        IF( LLDEBUG )THEN
          WRITE(NULERR,'("RADINTG:NAROB1,SUM(MASK_RO2)=",2(2X,I12))')&
           & NAROB1,SUM(MASK_RO2)  
        ENDIF
      ELSE
        CALL SLCOMM(NAROB1,NROPROCS,NRORPT,&
         & NROSPT,NROSENDPOS,NRORECVPOS,NROSENDPTR,NRORECVPTR,NROCOMM,&
         & IDUMARR,IFLDSOUT,LLINC,0,ZRGPBUF)  
      ENDIF
      CALL GSTATS(65,1)
    ENDIF
    ALLOCATE(ZPARITY(1:IFLDSOUT))
    ZPARITY(1:IFLDSOUT)=1
    IF( LRADONDEM.AND..NOT.LRADONDEM_ACTIVE )THEN
      NFIXRADFLD(1)=1
      NFIXRADFLD(2)=IFLDSOUT
      CALL SLEXTPOL(NROWIDEN,NROWIDES,&
       & NAROB1,RADGRID%NDGSAG,RADGRID%NDGENG,RADGRID%NDGSAL,RADGRID%NDGENL,&
       & IFLDSOUT,NROSTA,NROONL,NROOFF,&
       & RADGRID%NDGLG,RADGRID%NLOENG,RADGRID%NFRSTLOFF,&
       & RADGRID%MYFRSTACTLAT,RADGRID%MYLSTACTLAT,NFIXRADFLD,3,&
       & ZPARITY,ZRGPBUF,KMASK2=MASK_RO2)  
    ELSE
      CALL SLEXTPOL(NROWIDEN,NROWIDES,&
       & NAROB1,RADGRID%NDGSAG,RADGRID%NDGENG,RADGRID%NDGSAL,RADGRID%NDGENL,&
       & IFLDSOUT,NROSTA,NROONL,NROOFF,&
       & RADGRID%NDGLG,RADGRID%NLOENG,RADGRID%NFRSTLOFF,&
       & RADGRID%MYFRSTACTLAT,RADGRID%MYLSTACTLAT,IDUMARR,1,&
       & ZPARITY,ZRGPBUF)  
    ENDIF
    DEALLOCATE(ZPARITY)

    IF    ( NRADINT == 2 )THEN
      IWIS=201
    ELSEIF( NRADINT == 3 )THEN
      IWIS=203
    ENDIF
    IFLDN=1
    IFLDX=IFLDSOUT
    ZDEPI=2.0_JPRB*RPI
    ZPIS2=0.5_JPRB*RPI
    Z4JP=(4._JPRB*REAL(RADGRID%NDGLG,JPRB)+2)/(4._JPRB*RPI)
    ALLOCATE(ISTALAT(RADGRID%NDGSAH:RADGRID%NDGENH))
    ALLOCATE(ZLSDEPI(RADGRID%NDGSAH:RADGRID%NDGENH))
    DO JGL=MAX(RADGRID%NDGSAG,&
       & RADGRID%NDGSAL+RADGRID%NFRSTLOFF-NROWIDEN)-RADGRID%NFRSTLOFF,&
       & MIN(RADGRID%NDGENG,&
       & RADGRID%NDGENL+RADGRID%NFRSTLOFF+NROWIDES)-RADGRID%NFRSTLOFF  
      IGLGLO=JGL+RADGRID%NFRSTLOFF
      ZLSDEPI(JGL)=REAL(RADGRID%NLOENG(IGLGLO),JPRB)/ZDEPI
      ISTALAT(JGL)=NROOFF(JGL)
    ENDDO

    CALL GSTATS(1212,0)
!$OMP PARALLEL DO SCHEDULE(DYNAMIC,1) &
!$OMP&PRIVATE(JSTGLO,IBEG,IEND,IL,IB,J,ZDSLAT) &
!$OMP&PRIVATE(ZCSLA,ZDSLON,ZCSLO,IL0S,IL0ULI,IL0UDI,JLEV)
    DO JSTGLO=1,NGPTOT,NRPROMA
      IBEG=JSTGLO
      IEND=MIN(IBEG+NRPROMA-1,NGPTOT)
      IL=IEND-IBEG+1
      IB=(JSTGLO-1)/NRPROMA+1
      CALL RDSCAW(NRPROMA,1,IL,RADGRID%NDGSAH,RADGRID%NDGENH,&
       & ISTALAT(RADGRID%NDGSAH),IWIS,RADGRID%NFRSTLOFF,NROEXT,&
       & 1-RADGRID%NDLON,RADGRID%NDLON+RADGRID%NDLON,&
       & 1-NROWIDEN,RADGRID%NDGENL+NROWIDES,&
       & Z4JP,ZPIS2,ZLSDEPI(RADGRID%NDGSAH),&
       & RADGRID%RLATI(RADGRID%NDGSAH:),&
       & RADGRID%RIPI0(RADGRID%NDGSAH:),&
       & RADGRID%RIPI1(RADGRID%NDGSAH:),&
       & RADGRID%RIPI2(RADGRID%NDGSAH:),&
       & GELAM(IBEG),GELAT(IBEG),&
       & ZDSLAT,ZCSLA,ZDSLON,ZCSLO,IL0S,&
       & NAROB1,MASK_RO2)  

      IF    ( NRADINT == 2 )THEN
        DO J=1,IL
          IL0ULI(J,1,1) = IL0S(J,1,1)+1
          IL0ULI(J,1,2) = IL0S(J,1,1)+2
          IL0ULI(J,2,1) = IL0S(J,1,2)+1
          IL0ULI(J,2,2) = IL0S(J,1,2)+2
        ENDDO
        DO JLEV=1,IFLDSOUT
          CALL LAIDLIOBS(NAROB1,NRPROMA,1,IL,JLEV,IFLDSOUT,&
           & IFLDN,IFLDX,&
           & ZDSLAT,ZDSLON(1,1,1),IL0ULI,&
           & ZRGPBUF,ZRGP(1,1,IB))  
        ENDDO
      ELSEIF( NRADINT == 3 )THEN
        DO J=1,IL
          IL0UDI(J,0,0) = 0
          IL0UDI(J,0,1) = IL0S(J,1,0)+1
          IL0UDI(J,0,2) = IL0S(J,1,0)+2
          IL0UDI(J,0,3) = 0
          IL0UDI(J,1,0) = IL0S(J,1,1)+0
          IL0UDI(J,1,1) = IL0S(J,1,1)+1
          IL0UDI(J,1,2) = IL0S(J,1,1)+2
          IL0UDI(J,1,3) = IL0S(J,1,1)+3
          IL0UDI(J,2,0) = IL0S(J,1,2)+0
          IL0UDI(J,2,1) = IL0S(J,1,2)+1
          IL0UDI(J,2,2) = IL0S(J,1,2)+2
          IL0UDI(J,2,3) = IL0S(J,1,2)+3
          IL0UDI(J,3,0) = 0
          IL0UDI(J,3,1) = IL0S(J,1,3)+1
          IL0UDI(J,3,2) = IL0S(J,1,3)+2
          IL0UDI(J,3,3) = 0
        ENDDO
        DO JLEV=1,IFLDSOUT
          CALL LAIDDIOBS(NAROB1,NRPROMA,1,IL,JLEV,IFLDSOUT,&
           & IFLDN,IFLDX,&
           & ZCSLA,ZDSLON,ZCSLO,IL0UDI,&
           & ZRGPBUF,ZRGP(1,1,IB))  
        ENDDO
      ENDIF

    ENDDO
!$OMP END PARALLEL DO
    CALL GSTATS(1212,1)

    IF(LRADONDEM.AND..NOT.LRADONDEM_ACTIVE)THEN
      LRADONDEM_ACTIVE=.TRUE.
    ENDIF
    DEALLOCATE(ISTALAT)
    DEALLOCATE(ZLSDEPI)
    DEALLOCATE(ZRGPBUF)

  ELSE
    CALL ABOR1('RADINTG:OUTPUT - INVALID INTERPOLATION METHOD')
  ENDIF
  
  IFRSOD=IFRSOD-IOUTBEG+1
  IEMIT =IEMIT -IOUTBEG+1
  ISUDU =ISUDU -IOUTBEG+1
  IUVDF =IUVDF -IOUTBEG+1
  IPARF =IPARF -IOUTBEG+1
  IPARCF=IPARCF-IOUTBEG+1
  ITINCF=ITINCF-IOUTBEG+1
  IFDIR =IFDIR -IOUTBEG+1
  ICDIR =ICDIR -IOUTBEG+1
  IFRSO =IFRSO -IOUTBEG+1
  ISWFC =ISWFC -IOUTBEG+1
  IFRTH =IFRTH -IOUTBEG+1
  ILWFC =ILWFC -IOUTBEG+1
  IF( LLDEBUG )THEN
    IGIX  =IGIX  -IOUTBEG+1
  ENDIF
  
  IF (NRAD2D > 0 .AND. L2RAD) THEN
    IEXTR2 = IEXTR2-IOUTBEG+1
  END IF

  IF (NRAD3D > 0) THEN
    IEXTRA = IEXTRA-IOUTBEG+1
  END IF

  IF( LLDEBUG )THEN
    DO JSTGLO=1,NGPTOT,NRPROMA
      IBEG=JSTGLO
      IEND=MIN(IBEG+NRPROMA-1,NGPTOT)
      IL=IEND-IBEG+1
      IB=(JSTGLO-1)/NRPROMA+1
      DO JL=1,IL
        WRITE(NULOUT,'("RADINTG3: GI=",I6,2X,E25.15)')&
         & NGLOBALINDEX(JSTGLO+JL-1),ZRGP(JL,IGIX,IB)  
      ENDDO
    ENDDO
    CALL FLUSH(NULOUT)
  ENDIF

  IF( LLDEBUGRW )THEN
    LLERROR=.FALSE.
    ICNT=0
    DO JSTGLO=1,NGPTOT,NRPROMA
      IBEG=JSTGLO
      IEND=MIN(IBEG+NRPROMA-1,NGPTOT)
      IL=IEND-IBEG+1
      IB=(JSTGLO-1)/NRPROMA+1
      DO JL=1,IL
        ICNT=ICNT+1
        IF( LLREAD )THEN
          READ(NULTMP) ZDUM
          IF( ZDUM /= ZRGP(JL,IGIX,IB) )THEN
            LLERROR=.TRUE.
            WRITE(NULERR,'("RADINTG: ICNT,ZDUM,ZRGP=",I12,2(2X,F20.5))')&
             & ICNT,ZDUM,ZRGP(JL,IGIX,IB)  
            WRITE(NULOUT,'("RADINTG: ICNT,ZDUM,ZRGP=",I12,2(2X,F20.5))')&
             & ICNT,ZDUM,ZRGP(JL,IGIX,IB)  
          ENDIF
        ELSE
          WRITE(NULTMP)ZRGP(JL,IGIX,IB)
        ENDIF
      ENDDO
    ENDDO
    IF( LLREAD )THEN
      IF( LLERROR )THEN
        CALL ABOR1('RADINTG: OUTPUT INTERP PROBLEM')
      ENDIF
    ENDIF
    CLOSE(NULTMP)
  ENDIF

ENDIF

IF( LLDEBUG )THEN
! CALL ALLOCATE_GRIDPOINT_BUFFER ('ZGP',ZGP,IFLDSTOT,1,0)
! IPCT=1
! DO JSTGLO=1,NGPTOT,NRPROMA
!   IBEG=JSTGLO
!   IEND=MIN(IBEG+NRPROMA-1,NGPTOT)
!   IL=IEND-IBEG+1
!   IB=(JSTGLO-1)/NRPROMA+1
!   CALL SC2WRG(ZGP,IPCT,JSTGLO,1,IL,ZRGP(1,1,IB))
! ENDDO
! DO JFLD=1,IFLDSTOT
!   WRITE(NULOUT,'("RADINTG4: NUMBER=",I4)')JFLD
!   CALL GPNORM2(1,JFLD,ZGP)
!   CALL FLUSH(NULOUT)
! ENDDO
! CALL DEALLOCATE_GRIDPOINT_BUFFER (ZGP)
ENDIF

!  OUTPUT LOOP

CALL GSTATS(1213,0)
!$OMP  PARALLEL DO SCHEDULE(STATIC) &
!$OMP& PRIVATE(JSTGLO,JK,IBEG,IEND,IL,IB,&
!$OMP&        ZFRSOD,ZEMIT,ZSUDU,ZUVDF,ZPARF,ZPARCF,ZTINCF,ZFDIR,ZCDIR,ZFRSO,ZSWFC,ZFRTH,ZLWFC,&
!$OMP&        ZTRSO,ZEMTD,ZEMTU,ZTRSC,ZEMTC,ZTRSOD)
DO JSTGLO=1,NGPTOT,NRPROMA
  IBEG =JSTGLO
  IEND=MIN(IBEG+NRPROMA-1,NGPTOT)
  IL=IEND-IBEG+1
  IB=(JSTGLO-1)/NRPROMA+1

  ZFRSOD (1:IL)          = ZRGP(1:IL,IFRSOD          ,IB)
  ZEMIT  (1:IL)          = ZRGP(1:IL,IEMIT           ,IB)
  ZSUDU  (1:IL)          = ZRGP(1:IL,ISUDU           ,IB)
  ZUVDF  (1:IL)          = ZRGP(1:IL,IUVDF           ,IB)
  ZPARF  (1:IL)          = ZRGP(1:IL,IPARF           ,IB)
  ZPARCF (1:IL)          = ZRGP(1:IL,IPARCF          ,IB)
  ZTINCF (1:IL)          = ZRGP(1:IL,ITINCF          ,IB)
  ZFDIR  (1:IL)          = ZRGP(1:IL,IFDIR           ,IB)
  ZCDIR  (1:IL)          = ZRGP(1:IL,ICDIR           ,IB)
  ZFRSO  (1:IL,1:KLEV+1) = ZRGP(1:IL,IFRSO:IFRSO+KLEV,IB)
  ZSWFC  (1:IL,1:KLEV+1) = ZRGP(1:IL,ISWFC:ISWFC+KLEV,IB)
  ZFRTH  (1:IL,1:KLEV+1) = ZRGP(1:IL,IFRTH:IFRTH+KLEV,IB)
  ZLWFC  (1:IL,1:KLEV+1) = ZRGP(1:IL,ILWFC:ILWFC+KLEV,IB)

  IF (NRAD3D > 0) THEN
     DO JN=1,NRAD3D
        DO JK=1,KLEVX
           PEXTRA(IBEG:IEND,JK,JN) = ZRGP(1:IL,IEXTRA+(JN-1)*KLEVX+JK-1,IB)
        END DO
     END DO
  END IF

  IF (NRAD2D > 0) THEN
     DO JN=1,NRAD2D
        PEXTR2(IBEG:IEND,JN) = ZRGP(1:IL,IEXTR2+JN-1  ,IB)
     END DO     
  END IF
  
!*         4.3     TRANSFORM FLUXES TO MODEL HISTORICAL VARIABLES

  DO JK=1,KLEV+1
    ZTRSO (1:IL,JK)=ZFRSO(1:IL,JK)/(ZRII0*ZAMU0(IBEG:IEND))
    ZEMTD (1:IL,JK)=ZFRTH(1:IL,JK)
    ZEMTU (1:IL,JK)=ZFRTH(1:IL,JK)
!-- clear-sky          
    ZTRSC (1:IL,JK)=ZSWFC(1:IL,JK)/(ZRII0*ZAMU0(IBEG:IEND))
    ZEMTC (1:IL,JK)=ZLWFC(1:IL,JK)
  ENDDO
  ZTRSOD(1:IL)=ZFRSOD(1:IL)/(ZRII0*ZAMU0(IBEG:IEND))
  ZEMIT (1:IL)=ZEMIT (1:IL)
  ZSUDU (1:IL)=ZSUDU (1:IL)/(ZRII0*ZAMU0(IBEG:IEND))
  ZUVDF (1:IL)=ZUVDF (1:IL)/(ZRII0*ZAMU0(IBEG:IEND))
  ZPARF (1:IL)=ZPARF (1:IL)/(ZRII0*ZAMU0(IBEG:IEND))
  ZPARCF(1:IL)=ZPARCF(1:IL)/(ZRII0*ZAMU0(IBEG:IEND))
  ZTINCF(1:IL)=ZTINCF(1:IL)/(ZRII0*ZAMU0(IBEG:IEND))
  ZFDIR (1:IL)=ZFDIR (1:IL)/(ZRII0*ZAMU0(IBEG:IEND))
  ZCDIR (1:IL)=ZCDIR (1:IL)/(ZRII0*ZAMU0(IBEG:IEND))

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

!*         5.     DISTRIBUTION OF RESULTS TO FULL GRID.
!                 ------------ -- ------- -- ---- -----

!***

!*         7.2    STORAGE OF TRANSMISSIVITY AND EMISSIVITIES

  DO JK=1,KLEV+1
    PTRSO(IBEG:IEND,JK)=ZTRSO(1:IL,JK)
    PTRSO(IBEG:IEND,JK)=MAX( 0.0_JPRB,MIN(1.0_JPRB,PTRSO(IBEG:IEND,JK)))
    PEMTD(IBEG:IEND,JK)=ZEMTD(1:IL,JK)
    PEMTU(IBEG:IEND,JK)=ZEMTU(1:IL,JK)
!-- clear-sky      
    PTRSC(IBEG:IEND,JK)=ZTRSC(1:IL,JK)
    PTRSC(IBEG:IEND,JK)=MAX( 0.0_JPRB,MIN(1.0_JPRB,PTRSC(IBEG:IEND,JK)))
    PEMTC(IBEG:IEND,JK)=ZEMTC(1:IL,JK)
  ENDDO
  PTRSOD(IBEG:IEND)=MAX( 0.0_JPRB,MIN(1.0_JPRB,ZTRSOD(1:IL)))
  PEMIT(IBEG:IEND) =MAX( 0.0_JPRB,MIN(1.0_JPRB,ZEMIT (1:IL)))
  PSUDU(IBEG:IEND) =MAX( 0.0_JPRB,MIN(1.0_JPRB,ZSUDU (1:IL)))
  PUVDF(IBEG:IEND) =MAX( 0.0_JPRB,MIN(1.0_JPRB,ZUVDF (1:IL)))
  PPARF(IBEG:IEND) =MAX( 0.0_JPRB,MIN(1.0_JPRB,ZPARF (1:IL)))
  PPARCF(IBEG:IEND)=MAX( 0.0_JPRB,MIN(1.0_JPRB,ZPARCF(1:IL)))
  PTINCF(IBEG:IEND)=MAX( 0.0_JPRB,MIN(1.0_JPRB,ZTINCF(1:IL)))
  PFDIR(IBEG:IEND) =MAX( 0.0_JPRB,MIN(1.0_JPRB,ZFDIR (1:IL)))
  PCDIR(IBEG:IEND) =MAX( 0.0_JPRB,MIN(1.0_JPRB,ZCDIR (1:IL)))

ENDDO
!$OMP END PARALLEL DO
CALL GSTATS(1213,1)

DEALLOCATE(ZRGP)

!***********************************************************************

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

IF (LHOOK) CALL DR_HOOK('RADINTG',1,ZHOOK_HANDLE)

CONTAINS

INTEGER(KIND=JPIM) FUNCTION INDRAD(KFLDS,LDUSE)
INTEGER(KIND=JPIM),INTENT(IN) :: KFLDS
LOGICAL,INTENT(IN) :: LDUSE
REAL(KIND=JPRB) :: ZHOOK_HANDLE
IF (LHOOK) CALL DR_HOOK('RADINTG:INDRAD',0,ZHOOK_HANDLE)
IF( LDUSE )THEN
  INDRAD=INEXT
  INEXT=INEXT+KFLDS
ELSE
  INDRAD=IDUMMY
ENDIF
IF (LHOOK) CALL DR_HOOK('RADINTG:INDRAD',1,ZHOOK_HANDLE)
  
END FUNCTION INDRAD

END SUBROUTINE RADINTG
