Index: /LMDZ6/trunk/DefLists/namelist_ecrad
===================================================================
--- /LMDZ6/trunk/DefLists/namelist_ecrad	(revision 4852)
+++ /LMDZ6/trunk/DefLists/namelist_ecrad	(revision 4853)
@@ -52,7 +52,8 @@
  use_aerosols		= false,          ! Include aerosols in radiation calculations?
  n_aerosol_types         = 13,             
- !aerosol_optics_override_file_name = "aerosol_optics_lmdz.nc"
+ !aerosol_optics_override_file_name = "aer_opt_LMDZ_ECCKD.nc",
+ !aerosol_optics_override_file_name = "aer_opt_LMDZ_RRTMG.nc",
  do_save_spectral_flux   = false,          ! Save spectral fluxes in output file?
  do_save_gpoint_flux     = false,          ! Save fluxes per g-point in output file?
- gas_model_name          = "RRTMG-IFS",    ! Gas model: "Monochromatic", *"RRTMG-IFS"*, "RRTMG-PSRAD"
+ gas_model_name          = "ECCKD",    ! Gas model: "Monochromatic", "RRTMG-IFS", "ECCKD"
 /
Index: /LMDZ6/trunk/bld.cfg.ecrad
===================================================================
--- /LMDZ6/trunk/bld.cfg.ecrad	(revision 4852)
+++ /LMDZ6/trunk/bld.cfg.ecrad	(revision 4853)
@@ -35,4 +35,5 @@
 src::ext_src %EXT_SRC
 src::Ocean_skin %SRC_PATH/%PHYS/Ocean_skin
+src::lmdz %RAD/lmdz
 src::radiation %RAD/radiation
 src::ifsrrtm %RAD/ifsrrtm
Index: /LMDZ6/trunk/libf/phylmd/ecrad/CHANGELOG
===================================================================
--- /LMDZ6/trunk/libf/phylmd/ecrad/CHANGELOG	(revision 4852)
+++ /LMDZ6/trunk/libf/phylmd/ecrad/CHANGELOG	(revision 4853)
@@ -15,4 +15,23 @@
 	- Increased security value in single-precision SW
 	  reflectance-transmittance calculation from 1e-12 to 1e-6
+	- Added radiation/ecrad_config.h file to provide site-specific
+	  optimization options as preprocessor parameters
+	- Replaced slow "sum" intrinsic function in McICA and Tripleclouds
+	  solvers with optimized versions for x86-64 and DWD's NEC
+	- Enable different gas optics models for shortwave and longwave:
+	  namelist gas_model_name can still be used, or use
+	  sw_gas_model_name and lw_gas_model_name to specify separate models
+	- Fix the general aerosol optics + RRTMG combination, so that
+	  optical properties correctly weighted by solar or terrestrial
+	  Planck function, rather than unweighted. This changes fluxes by up
+	  to 0.3 W m-2 in SW and 0.03 in LW, heating rates by up to 0.015
+	  K/d in SW and 0.0015 in LW. Reverts bug introduced between git
+	  commits a405cca (5 Dec 2022) and 7182230 (8 Dec 2022).
+	- Added ifs/satur.F90, used in the IFS to compute relative
+	  humidity for aerosol hydration, and the ability to call it from
+	  ecrad_driver.F90, but note that this routine computes saturation
+	  with respect to ice at colder temperatures. If used, the impact on
+	  fluxes is up to around 1 W m-2 in the SW and 0.05 in the LW, and
+	  for heating rates 0.002 K/d in the SW and 0.003 in the LW.
 
 version 1.6.0 (27 April 2023)
Index: /LMDZ6/trunk/libf/phylmd/ecrad/driver/Makefile
===================================================================
--- /LMDZ6/trunk/libf/phylmd/ecrad/driver/Makefile	(revision 4852)
+++ /LMDZ6/trunk/libf/phylmd/ecrad/driver/Makefile	(revision 4853)
@@ -20,4 +20,6 @@
 test_programs: $(TEST_PROGRAMS)
 
+# Link ecrad executable; add "-lifs" if you want to use the "satur"
+# routine in ecrad_driver.F90
 $(EXECUTABLE): $(OBJECTS) ../lib/*.a ecrad_driver.o
 	$(FC) $(FCFLAGS) ecrad_driver.o $(OBJECTS) $(LIBS) -o $(EXECUTABLE)
Index: /LMDZ6/trunk/libf/phylmd/ecrad/driver/ecrad_driver.F90
===================================================================
--- /LMDZ6/trunk/libf/phylmd/ecrad/driver/ecrad_driver.F90	(revision 4852)
+++ /LMDZ6/trunk/libf/phylmd/ecrad/driver/ecrad_driver.F90	(revision 4853)
@@ -55,4 +55,7 @@
   implicit none
 
+  ! Uncomment this if you want to use the "satur" routine below
+!#include "satur.intfb.h"
+  
   ! The NetCDF file containing the input profiles
   type(netcdf_file)         :: file
@@ -269,7 +272,17 @@
 
   ! Compute saturation with respect to liquid (needed for aerosol
-  ! hydration) call
+  ! hydration) call...
   call thermodynamics%calc_saturation_wrt_liquid(driver_config%istartcol,driver_config%iendcol)
 
+  ! ...or alternatively use the "satur" function in the IFS (requires
+  ! adding -lifs to the linker command line) but note that this
+  ! computes saturation with respect to ice at colder temperatures,
+  ! which is almost certainly incorrect
+  !allocate(thermodynamics%h2o_sat_liq(ncol,nlev))
+  !call satur(driver_config%istartcol, driver_config%iendcol, ncol, 1, nlev, .false., &
+  !     0.5_jprb * (thermodynamics.pressure_hl(:,1:nlev)+thermodynamics.pressure_hl(:,2:nlev)), &
+  !     0.5_jprb * (thermodynamics.temperature_hl(:,1:nlev)+thermodynamics.temperature_hl(:,2:nlev)), &
+  !     thermodynamics%h2o_sat_liq, 2)
+  
   ! Check inputs are within physical bounds, printing message if not
   is_out_of_bounds =     gas%out_of_physical_bounds(driver_config%istartcol, driver_config%iendcol, &
Index: /LMDZ6/trunk/libf/phylmd/ecrad/ifs/Makefile
===================================================================
--- /LMDZ6/trunk/libf/phylmd/ecrad/ifs/Makefile	(revision 4852)
+++ /LMDZ6/trunk/libf/phylmd/ecrad/ifs/Makefile	(revision 4853)
@@ -2,5 +2,5 @@
 	radiation_scheme.F90 radiation_setup.F90 yoerdu.F90 \
 	yomrip.F90 yoephy.F90 yoecld.F90 yoe_spectral_planck.F90 \
-	cloud_overlap_decorr_len.F90 yoerad.F90
+	cloud_overlap_decorr_len.F90 yoerad.F90 yoethf.F90 satur.F90
 
 OBJECTS := $(SOURCES:.F90=.o)
@@ -31,2 +31,3 @@
 cos_sza.o ice_effective_radius.o liquid_effective_radius.o radiation_scheme.o radiation_setup.o: yoerad.o
 yoerad.o: yoe_spectral_planck.o
+satur.o: yoethf.o
Index: /LMDZ6/trunk/libf/phylmd/ecrad/ifs/yoephy.F90
===================================================================
--- /LMDZ6/trunk/libf/phylmd/ecrad/ifs/yoephy.F90	(revision 4852)
+++ /LMDZ6/trunk/libf/phylmd/ecrad/ifs/yoephy.F90	(revision 4853)
@@ -11,5 +11,5 @@
 
 USE PARKIND1, ONLY : JPRB, JPIM
-USE ISO_C_BINDING
+!USE ISO_C_BINDING
 
 IMPLICIT NONE
Index: /LMDZ6/trunk/libf/phylmd/ecrad/ifsaux/yomcst.F90
===================================================================
--- /LMDZ6/trunk/libf/phylmd/ecrad/ifsaux/yomcst.F90	(revision 4852)
+++ /LMDZ6/trunk/libf/phylmd/ecrad/ifsaux/yomcst.F90	(revision 4853)
@@ -71,3 +71,6 @@
 REAL(KIND=JPRB), PARAMETER :: RMCCL4 = 153.823_JPRB
 
+REAL(KIND=JPRB), PARAMETER :: RCPD  = 3.5_JPRB*RD
+REAL(KIND=JPRB), PARAMETER :: RLMLT = RLSTT-RLVTT
+
 END MODULE YOMCST
Index: /LMDZ6/trunk/libf/phylmd/ecrad/lmdz/aeropt_5wv_ecrad.F90
===================================================================
--- /LMDZ6/trunk/libf/phylmd/ecrad/lmdz/aeropt_5wv_ecrad.F90	(revision 4853)
+++ /LMDZ6/trunk/libf/phylmd/ecrad/lmdz/aeropt_5wv_ecrad.F90	(revision 4853)
@@ -0,0 +1,100 @@
+!aeropt_5wv_ecrad.F90 2022-09-20 A. Idelkadi et O. Boucher 
+!
+     SUBROUTINE AEROPT_5WV_ECRAD(istartcol,iendcol,istartlev,iendlev, &
+                                 config,thermodynamics,aerosol)
+
+
+      USE DIMPHY
+      USE aero_mod
+      USE phys_local_var_mod, ONLY: od443aer,od550aer,od865aer
+!                                      dryod550aer, 
+!                                      ec550aer,od550lt1aer,abs550aer
+!        USE phys_output_var_mod, ONLY: dryaod_diag
+!        USE YOMCST, ONLY: RD,RG
+      USE phys_local_var_mod, ONLY: rhcl
+
+      use parkind1,                      only : jprb
+      use radiation_config,              only : config_type
+      use radiation_thermodynamics,      only : thermodynamics_type
+      use radiation_aerosol,             only : aerosol_type
+      use radiation_constants,           only : AccelDueToGravity
+      use radiation_aerosol_optics_data, only : aerosol_optics_type, &
+         &  IAerosolClassUndefined,   IAerosolClassIgnored, &
+         &  IAerosolClassHydrophobic, IAerosolClassHydrophilic
+
+      IMPLICIT NONE
+
+      !---ATTENTION n_mono est a redéfinir proprement
+
+      ! Range of levels over which aerosols are present
+      integer, intent(in) :: istartlev, iendlev, istartcol,iendcol
+      type(config_type), intent(in), target :: config
+      type(thermodynamics_type),intent(in)  :: thermodynamics
+      type(aerosol_type),       intent(in)  :: aerosol
+      type(aerosol_optics_type), pointer :: ao
+
+      ! Loop indices for column, level, g point, band and aerosol type, and relative humidity
+      integer :: jcol, jlev, jtype, irh
+      ! indice wavelength in aerosol_optics_lmdz.nc
+      INTEGER, PARAMETER :: la443 = 1
+      INTEGER, PARAMETER :: la550 = 2
+!      INTEGER, PARAMETER :: la670 = 3
+!      INTEGER, PARAMETER :: la765 = 4
+      INTEGER, PARAMETER :: la865 = 5
+      real(jprb) :: factor
+      ! n_bands_sw
+      real(jprb), dimension(config%aerosol_optics%n_mono_wl) :: od_aerosol_mono, local_od_mono
+
+      !--initialization
+      od443aer = 0.0_jprb
+      od550aer = 0.0_jprb
+      od865aer = 0.0_jprb
+
+      ao => config%aerosol_optics
+
+      ! Loop over level
+     do jlev = istartlev,iendlev
+
+        ! Loop over column
+        do jcol = istartcol,iendcol
+
+          ! Compute relative humidity with respect to liquid
+          ! saturation and the index to the relative-humidity index of
+          ! hydrophilic-aerosol data
+          irh = ao%calc_rh_index(rhcl(jcol,jlev))
+
+          factor = ( thermodynamics%pressure_hl(jcol,jlev+1) &
+               &    -thermodynamics%pressure_hl(jcol,jlev  )  ) &
+               &   / AccelDueToGravity
+
+          ! Reset temporary arrays
+          od_aerosol_mono = 0.0_jprb
+
+          do jtype = 1,config%n_aerosol_types
+            ! Add the optical depth for this aerosol type to the total for all aerosols.  
+            ! Note that the following expressions are array-wise
+            if (ao%iclass(jtype) == IAerosolClassHydrophobic) then
+              local_od_mono = factor * aerosol%mixing_ratio(jcol,jlev,jtype) &
+                   &  * ao%mass_ext_mono_phobic(:,ao%itype(jtype))
+              od_aerosol_mono = od_aerosol_mono + local_od_mono
+            else if (ao%iclass(jtype) == IAerosolClassHydrophilic) then
+              ! Hydrophilic aerosols require the look-up tables to
+              ! be indexed with irh
+              local_od_mono = factor * aerosol%mixing_ratio(jcol,jlev,jtype) &
+                   &  * ao%mass_ext_mono_philic(:,irh,ao%itype(jtype))
+              od_aerosol_mono = od_aerosol_mono + local_od_mono
+            end if
+
+          end do ! Loop over aerosol type
+
+          !--ATTENTION A BIEN FAIRE CORRESPONDRE LES INDICES
+          od443aer(jcol) = od443aer(jcol) + od_aerosol_mono(la443)
+          od550aer(jcol) = od550aer(jcol) + od_aerosol_mono(la550)
+          od865aer(jcol) = od865aer(jcol) + od_aerosol_mono(la865)
+
+        end do ! Loop over column
+
+      end do ! Loop over level
+
+     END SUBROUTINE AEROPT_5WV_ECRAD
+
Index: /LMDZ6/trunk/libf/phylmd/ecrad/lmdz/radiation_scheme_mod.F90
===================================================================
--- /LMDZ6/trunk/libf/phylmd/ecrad/lmdz/radiation_scheme_mod.F90	(revision 4853)
+++ /LMDZ6/trunk/libf/phylmd/ecrad/lmdz/radiation_scheme_mod.F90	(revision 4853)
@@ -0,0 +1,1369 @@
+! AI mars 2021
+! ====================== Interface between ECRAD and LMDZ ====================
+! radiation_scheme.F90 appelee dans radlwsw_m.F90 si iflag_rttm = 2
+! revoir toutes les parties avec "AI ATTENTION" 
+! Mars 2021 :
+!             - Revoir toutes les parties commentees AI ATTENTION
+!             1. Traitement des aerosols
+!             2. Verifier les parametres times issus de LMDZ (calcul issed)
+!             3. Configuration a partir de namelist
+!             4. frac_std = 0.75      
+! Juillet 2023 :
+!             
+! ============================================================================
+module interface_lmdz_ecrad
+
+IMPLICIT NONE        
+
+contains
+
+SUBROUTINE RADIATION_SCHEME &
+! Inputs
+     & (KIDIA, KFDIA, KLON, KLEV, KAEROSOL, NSW, &
+     &  namelist_file, ok_3Deffect, &
+     &  debut, ok_volcan, flag_aerosol_strat, &
+     &  IDAY, TIME, &
+     &  PSOLAR_IRRADIANCE, &
+     &  PMU0, PTEMPERATURE_SKIN, &
+     &  PALBEDO_DIF, PALBEDO_DIR, &
+     &  PEMIS, PEMIS_WINDOW, &
+     &  PGELAM, PGEMU, &
+     &  PPRESSURE_H, PTEMPERATURE_H, PQ, PQSAT, &
+     &  PCO2, PCH4, PN2O, PNO2, PCFC11, PCFC12, PHCFC22, &
+     &  PCCL4, PO3, PO2, &
+     &  PCLOUD_FRAC, PQ_LIQUID, PQ_ICE, PQ_SNOW, &
+     &  ZRE_LIQUID_UM, ZRE_ICE_UM, &
+     &  PAEROSOL_OLD, PAEROSOL, &
+! Outputs
+     &  PFLUX_SW, PFLUX_LW, PFLUX_SW_CLEAR, PFLUX_LW_CLEAR, &
+     &  PFLUX_SW_DN, PFLUX_LW_DN, PFLUX_SW_DN_CLEAR, PFLUX_LW_DN_CLEAR, &
+     &  PFLUX_SW_UP, PFLUX_LW_UP, PFLUX_SW_UP_CLEAR, PFLUX_LW_UP_CLEAR, &
+     &  PFLUX_DIR, PFLUX_DIR_CLEAR, PFLUX_DIR_INTO_SUN, &
+     &  PFLUX_UV, PFLUX_PAR, PFLUX_PAR_CLEAR, &
+     &  PEMIS_OUT, PLWDERIVATIVE, &
+     &  PSWDIFFUSEBAND, PSWDIRECTBAND, &
+     &  ecrad_cloud_cover_sw)
+
+! RADIATION_SCHEME - Interface to modular radiation scheme
+!
+! (C) Copyright 2015- ECMWF.
+!
+! This software is licensed under the terms of the Apache Licence Version 2.0
+! which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
+!
+! In applying this licence, ECMWF does not waive the privileges and immunities
+! granted to it by virtue of its status as an intergovernmental organisation
+! nor does it submit to any jurisdiction.
+!
+! PURPOSE
+! -------
+!   The modular radiation scheme is contained in a separate
+!   library. This routine puts the the IFS arrays into appropriate
+!   objects, computing the additional data that is required, and sends
+!   it to the radiation scheme.  It returns net fluxes and surface
+!   flux components needed by the rest of the model. 
+!
+!   Lower case is used for variables and types taken from the
+!   radiation library
+!
+! INTERFACE
+! ---------
+!    RADIATION_SCHEME is called from RADLSWR. The
+!    SETUP_RADIATION_SCHEME routine (in the RADIATION_SETUP module)
+!    should have been run first.
+!
+! AUTHOR
+! ------
+!   Robin Hogan, ECMWF
+!   Original: 2015-09-16
+!
+! MODIFICATIONS
+! -------------
+!
+! TO DO
+! -----
+!
+!-----------------------------------------------------------------------
+
+! Modules from ifs or ifsaux libraries
+USE PARKIND1 , ONLY : JPIM, JPRB
+USE YOMHOOK  , ONLY : LHOOK, DR_HOOK
+USE RADIATION_SETUP
+USE YOMCST   , ONLY : RSIGMA ! Stefan-Boltzmann constant
+!USE RADIATION_SETUP, ONLY : SETUP_RADIATION_SCHEME, &
+!                         &  config_type, driver_config_type, &
+!                         &  NWEIGHT_UV,  IBAND_UV,  WEIGHT_UV, &
+!                         &  NWEIGHT_PAR, IBAND_PAR, WEIGHT_PAR, &
+!                         &  ITYPE_TROP_BG_AER,  TROP_BG_AER_MASS_EXT, &
+!                         &  ITYPE_STRAT_BG_AER, STRAT_BG_AER_MASS_EXT, &
+!                         &  ISolverSpartacus
+
+! Modules from radiation library
+USE radiation_single_level,   ONLY : single_level_type
+USE radiation_thermodynamics, ONLY : thermodynamics_type
+USE radiation_gas
+USE radiation_cloud,          ONLY : cloud_type
+USE radiation_aerosol,        ONLY : aerosol_type
+USE radiation_flux,           ONLY : flux_type
+USE radiation_interface,      ONLY : radiation, set_gas_units
+USE radiation_save,           ONLY : save_inputs
+
+USE mod_phys_lmdz_para
+
+IMPLICIT NONE
+
+! INPUT ARGUMENTS
+! *** Array dimensions and ranges
+INTEGER(KIND=JPIM),INTENT(IN) :: KIDIA    ! Start column to process
+INTEGER(KIND=JPIM),INTENT(IN) :: KFDIA    ! End column to process
+!INTEGER, INTENT(IN) :: KIDIA, KFDIA
+INTEGER(KIND=JPIM),INTENT(IN) :: KLON     ! Number of columns
+INTEGER(KIND=JPIM),INTENT(IN) :: KLEV     ! Number of levels
+!INTEGER, INTENT(IN) :: KLON, KLEV
+!INTEGER(KIND=JPIM),INTENT(IN) :: KAEROLMDZ ! Number of aerosol types
+INTEGER(KIND=JPIM),INTENT(IN) :: KAEROSOL
+INTEGER(KIND=JPIM),INTENT(IN) :: NSW ! Numbe of bands
+
+! AI ATTENTION
+!INTEGER, PARAMETER :: KAEROSOL = 12
+
+! *** Single-level fields
+REAL(KIND=JPRB),   INTENT(IN) :: PSOLAR_IRRADIANCE ! (W m-2)
+REAL(KIND=JPRB),   INTENT(IN) :: PMU0(KLON) ! Cosine of solar zenith ang
+REAL(KIND=JPRB),   INTENT(IN) :: PTEMPERATURE_SKIN(KLON) ! (K)
+! Diffuse and direct components of surface shortwave albedo
+!REAL(KIND=JPRB),   INTENT(IN) :: PALBEDO_DIF(KLON,YRERAD%NSW)
+!REAL(KIND=JPRB),   INTENT(IN) :: PALBEDO_DIR(KLON,YRERAD%NSW)
+REAL(KIND=JPRB),   INTENT(IN) :: PALBEDO_DIF(KLON,NSW)
+REAL(KIND=JPRB),   INTENT(IN) :: PALBEDO_DIR(KLON,NSW)
+! Longwave emissivity outside and inside the window region
+REAL(KIND=JPRB),   INTENT(IN) :: PEMIS(KLON)
+REAL(KIND=JPRB),   INTENT(IN) :: PEMIS_WINDOW(KLON)
+! Longitude (radians), sine of latitude
+REAL(KIND=JPRB),   INTENT(IN) :: PGELAM(KLON)
+REAL(KIND=JPRB),   INTENT(IN) :: PGEMU(KLON)
+! Land-sea mask
+!REAL(KIND=JPRB),   INTENT(IN) :: PLAND_SEA_MASK(KLON) 
+
+! *** Variables on half levels
+REAL(KIND=JPRB),   INTENT(IN) :: PPRESSURE_H(KLON,KLEV+1)    ! (Pa)
+REAL(KIND=JPRB),   INTENT(IN) :: PTEMPERATURE_H(KLON,KLEV+1) ! (K)
+
+! *** Gas mass mixing ratios on full levels
+REAL(KIND=JPRB),   INTENT(IN) :: PQ(KLON,KLEV) 
+! AI
+REAL(KIND=JPRB),   INTENT(IN) :: PQSAT(KLON,KLEV)
+REAL(KIND=JPRB),   INTENT(IN) :: PCO2
+REAL(KIND=JPRB),   INTENT(IN) :: PCH4 
+REAL(KIND=JPRB),   INTENT(IN) :: PN2O 
+REAL(KIND=JPRB),   INTENT(IN) :: PNO2 
+REAL(KIND=JPRB),   INTENT(IN) :: PCFC11
+REAL(KIND=JPRB),   INTENT(IN) :: PCFC12
+REAL(KIND=JPRB),   INTENT(IN) :: PHCFC22
+REAL(KIND=JPRB),   INTENT(IN) :: PCCL4
+REAL(KIND=JPRB),   INTENT(IN) :: PO3(KLON,KLEV) ! AI (kg/kg) ATTENTION (Pa*kg/kg) 
+REAL(KIND=JPRB),   INTENT(IN) :: PO2
+
+! *** Cloud fraction and hydrometeor mass mixing ratios
+REAL(KIND=JPRB),   INTENT(IN) :: PCLOUD_FRAC(KLON,KLEV)
+REAL(KIND=JPRB),   INTENT(IN) :: PQ_LIQUID(KLON,KLEV)
+REAL(KIND=JPRB),   INTENT(IN) :: PQ_ICE(KLON,KLEV)
+!REAL(KIND=JPRB),   INTENT(IN) :: PQ_RAIN(KLON,KLEV)
+REAL(KIND=JPRB),   INTENT(IN) :: PQ_SNOW(KLON,KLEV)
+
+! *** Aerosol mass mixing ratios
+REAL(KIND=JPRB),   INTENT(IN) :: PAEROSOL_OLD(KLON,6,KLEV)
+REAL(KIND=JPRB),   INTENT(IN) :: PAEROSOL(KLON,KLEV,KAEROSOL)
+
+!REAL(KIND=JPRB),   INTENT(IN) :: PCCN_LAND(KLON) 
+!REAL(KIND=JPRB),   INTENT(IN) :: PCCN_SEA(KLON) 
+
+!AI mars 2021
+INTEGER(KIND=JPIM), INTENT(IN) :: IDAY
+REAL(KIND=JPRB), INTENT(IN)    :: TIME
+
+! Name of file names specified on command line
+character(len=512), INTENT(IN) :: namelist_file
+logical, INTENT(IN)            :: ok_3Deffect, debut, ok_volcan
+INTEGER(KIND=JPIM), INTENT(IN) :: flag_aerosol_strat
+
+
+! OUTPUT ARGUMENTS
+
+! *** Net fluxes on half-levels (W m-2)
+REAL(KIND=JPRB),  INTENT(OUT) :: PFLUX_SW(KLON,KLEV+1) 
+REAL(KIND=JPRB),  INTENT(OUT) :: PFLUX_LW(KLON,KLEV+1) 
+REAL(KIND=JPRB),  INTENT(OUT) :: PFLUX_SW_CLEAR(KLON,KLEV+1) 
+REAL(KIND=JPRB),  INTENT(OUT) :: PFLUX_LW_CLEAR(KLON,KLEV+1) 
+
+!*** DN and UP flux on half-levels (W m-2)
+REAL(KIND=JPRB),  INTENT(OUT) :: PFLUX_SW_DN(KLON,KLEV+1)
+REAL(KIND=JPRB),  INTENT(OUT) :: PFLUX_LW_DN(KLON,KLEV+1)
+REAL(KIND=JPRB),  INTENT(OUT) :: PFLUX_SW_DN_CLEAR(KLON,KLEV+1)
+REAL(KIND=JPRB),  INTENT(OUT) :: PFLUX_LW_DN_CLEAR(KLON,KLEV+1)
+REAL(KIND=JPRB),  INTENT(OUT) :: PFLUX_SW_UP(KLON,KLEV+1)
+REAL(KIND=JPRB),  INTENT(OUT) :: PFLUX_LW_UP(KLON,KLEV+1)
+REAL(KIND=JPRB),  INTENT(OUT) :: PFLUX_SW_UP_CLEAR(KLON,KLEV+1)
+REAL(KIND=JPRB),  INTENT(OUT) :: PFLUX_LW_UP_CLEAR(KLON,KLEV+1)
+
+! Direct component of surface flux into horizontal plane
+REAL(KIND=JPRB),  INTENT(OUT) :: PFLUX_DIR(KLON)
+REAL(KIND=JPRB),  INTENT(OUT) :: PFLUX_DIR_CLEAR(KLON)
+! As PFLUX_DIR but into a plane perpendicular to the sun
+REAL(KIND=JPRB),  INTENT(OUT) :: PFLUX_DIR_INTO_SUN(KLON)
+
+! *** Ultraviolet and photosynthetically active radiation (W m-2)
+REAL(KIND=JPRB),  INTENT(OUT) :: PFLUX_UV(KLON)
+REAL(KIND=JPRB),  INTENT(OUT) :: PFLUX_PAR(KLON)
+REAL(KIND=JPRB),  INTENT(OUT) :: PFLUX_PAR_CLEAR(KLON)
+
+! Diagnosed longwave surface emissivity across the whole spectrum
+REAL(KIND=JPRB),  INTENT(OUT) :: PEMIS_OUT(KLON)   
+
+! Partial derivative of total-sky longwave upward flux at each level
+! with respect to upward flux at surface, used to correct heating
+! rates at gridpoints/timesteps between calls to the full radiation
+! scheme.  Note that this version uses the convention of level index
+! increasing downwards, unlike the local variable ZLwDerivative that
+! is returned from the LW radiation scheme.
+REAL(KIND=JPRB),  INTENT(OUT) :: PLWDERIVATIVE(KLON,KLEV+1)
+
+! Surface diffuse and direct downwelling shortwave flux in each
+! shortwave albedo band, used in RADINTG to update the surface fluxes
+! accounting for high-resolution albedo information
+REAL(KIND=JPRB),  INTENT(OUT) :: PSWDIFFUSEBAND(KLON,NSW)
+REAL(KIND=JPRB),  INTENT(OUT) :: PSWDIRECTBAND (KLON,NSW)
+
+!AI Nov 2023
+REAL(KIND=JPRB),  INTENT(OUT) :: ecrad_cloud_cover_sw(KLON)
+
+! LOCAL VARIABLES
+! AI ATTENTION
+type(config_type),save         :: rad_config
+!!$OMP THREADPRIVATE(rad_config)
+type(driver_config_type),save  :: driver_config
+!!$OMP THREADPRIVATE(driver_config)
+!type(config_type)        :: rad_config
+!type(driver_config_type)  :: driver_config
+TYPE(single_level_type)   :: single_level
+TYPE(thermodynamics_type) :: thermodynamics
+TYPE(gas_type)            :: gas
+TYPE(cloud_type)          :: cloud
+TYPE(aerosol_type)        :: aerosol
+TYPE(flux_type)           :: flux
+
+! Mass mixing ratio of ozone (kg/kg)
+REAL(KIND=JPRB)           :: ZO3(KLON,KLEV)
+
+! Cloud effective radii in microns
+REAL(KIND=JPRB)           :: ZRE_LIQUID_UM(KLON,KLEV)
+REAL(KIND=JPRB)           :: ZRE_ICE_UM(KLON,KLEV)
+
+! Cloud overlap decorrelation length for cloud boundaries in km
+REAL(KIND=JPRB)           :: ZDECORR_LEN_KM(KLON)
+
+! Ratio of cloud overlap decorrelation length for cloud water
+! inhomogeneities to that for cloud boundaries (typically 0.5)
+!REAL(KIND=JPRB)           :: ZDECORR_LEN_RATIO = 0.5_jprb
+
+! The surface net longwave flux if the surface was a black body, used
+! to compute the effective broadband surface emissivity
+REAL(KIND=JPRB)           :: ZBLACK_BODY_NET_LW(KIDIA:KFDIA)
+
+! Layer mass in kg m-2
+REAL(KIND=JPRB)           :: ZLAYER_MASS(KIDIA:KFDIA,KLEV)
+
+! Time integers
+INTEGER :: ITIM
+
+! Loop indices
+INTEGER :: JLON, JLEV, JBAND, JB_ALBEDO, JAER
+
+REAL(KIND=JPRB) :: ZHOOK_HANDLE
+
+! AI ATTENTION traitement aerosols
+INTEGER, PARAMETER :: NAERMACC = 1
+
+logical :: loutput=.true.
+logical :: lprint_input=.false.
+logical :: lprint_config=.false.
+logical, save :: debut_ecrad=.true.
+!$OMP THREADPRIVATE(debut_ecrad)
+integer, save :: itap_ecrad=0
+!$OMP THREADPRIVATE(itap_ecrad)
+
+REAL(KIND=JPRB) ::  inv_cloud_effective_size(KLON,KLEV)
+REAL(KIND=JPRB) ::  inv_inhom_effective_size(KLON,KLEV)
+
+integer :: irang
+
+
+IF (LHOOK) CALL DR_HOOK('RADIATION_SCHEME',0,ZHOOK_HANDLE)
+
+  print*,'Entree radiation_scheme, ok_3Deffect, namelist_file = ', &
+          ok_3Deffect, namelist_file
+! A.I juillet 2023 : 
+! Initialisation dans radiation_setup au 1er passage dans Ecrad
+!$OMP MASTER
+!if (.not.ok_3Deffect) then
+  if (debut_ecrad) then
+   call SETUP_RADIATION_SCHEME(loutput,namelist_file,rad_config,driver_config)
+   debut_ecrad=.false. 
+  endif 
+!else
+!   call SETUP_RADIATION_SCHEME(loutput,namelist_file,rad_config,driver_config)
+!endif
+!$OMP END MASTER
+!$OMP BARRIER 
+! Fin partie initialisation et configuration 
+
+!AI print fichiers namelist utilise
+!if (is_omp_root) then
+! itap_ecrad=itap_ecrad+1
+! print*,'Dans radiation_scheme itap_ecrad, mpi_rank, omp_rank, namelist_file : ', &
+!         itap_ecrad, mpi_rank, omp_rank, namelist_file
+!else
+! print*,'mpi_rank omp_rank, namelist_file :', mpi_rank, omp_rank, namelist_file
+!endif
+
+! AI 11 23 Allocates depplaces au debut
+print*,'*********** ALLOCATES *******************************'
+! AI ATTENTION
+! Allocate memory in radiation objects
+! emissivite avec une seule bande
+CALL single_level%allocate(KLON, NSW, 1, &
+     &                     use_sw_albedo_direct=.TRUE.)
+CALL thermodynamics%allocate(KLON, KLEV, use_h2o_sat=.true.)
+CALL cloud%allocate(KLON, KLEV)
+CALL aerosol%allocate(KLON, 1, KLEV, KAEROSOL)
+CALL gas%allocate(KLON, KLEV)
+CALL flux%allocate(rad_config, 1, KLON, KLEV)
+
+print*,'************* THERMO (input) ************************************'
+! Set thermodynamic profiles: simply copy over the half-level
+! pressure and temperature
+! AI
+! pressure_hl > paprs
+! temperature_hl calculee dans radlsw de la meme facon que pour RRTM
+thermodynamics%pressure_hl   (KIDIA:KFDIA,:) = PPRESSURE_H   (KIDIA:KFDIA,:)
+thermodynamics%temperature_hl(KIDIA:KFDIA,:) = PTEMPERATURE_H(KIDIA:KFDIA,:)
+!print*,'Compute saturation specific humidity'
+! Compute saturation specific humidity, used to hydrate aerosols. The
+! "2" for the last argument indicates that the routine is not being
+! called from within the convection scheme.
+!CALL SATUR(KIDIA, KFDIA, KLON, 1, KLEV, &
+!     &  PPRESSURE, PTEMPERATURE, thermodynamics%h2o_sat_liq, 2)
+! Alternative approximate version using temperature and pressure from
+! the thermodynamics structure
+!CALL thermodynamics%calc_saturation_wrt_liquid(KIDIA, KFDIA)
+!AI ATTENTION
+thermodynamics%h2o_sat_liq = PQSAT
+
+print*,'********** SINGLE LEVEL VARS **********************************'
+!AI ATTENTION
+! Set single-level fileds
+single_level%solar_irradiance              = PSOLAR_IRRADIANCE
+single_level%cos_sza(KIDIA:KFDIA)          = PMU0(KIDIA:KFDIA)
+single_level%skin_temperature(KIDIA:KFDIA) = PTEMPERATURE_SKIN(KIDIA:KFDIA)
+single_level%sw_albedo(KIDIA:KFDIA,:)      = PALBEDO_DIF(KIDIA:KFDIA,:)
+single_level%sw_albedo_direct(KIDIA:KFDIA,:)=PALBEDO_DIR(KIDIA:KFDIA,:)
+single_level%lw_emissivity(KIDIA:KFDIA,1)  = PEMIS(KIDIA:KFDIA)
+!single_level%lw_emissivity(KIDIA:KFDIA,2)  = PEMIS_WINDOW(KIDIA:KFDIA)
+
+! Create the relevant seed from date and time get the starting day
+! and number of minutes since start
+!IDAY = NDD(NINDAT)
+!cur_day
+!ITIM = NINT(NSTEP * YRRIP%TSTEP / 60.0_JPRB)
+!ITIM = NINT(TIME / 60.0_JPRB)
+!current_time
+!allocate(single_level%iseed(KIDIA:KFDIA))
+!DO JLON = KIDIA, KFDIA
+  ! This method gives a unique value for roughly every 1-km square
+  ! on the globe and every minute.  ASIN(PGEMU)*60 gives rough
+  ! latitude in degrees, which we multiply by 100 to give a unique
+  ! value for roughly every km. PGELAM*60*100 gives a unique number
+  ! for roughly every km of longitude around the equator, which we
+  ! multiply by 180*100 so there is no overlap with the latitude
+  ! values.  The result can be contained in a 32-byte integer (but
+  ! since random numbers are generated with the help of integer
+  ! overflow, it should not matter if the number did overflow).
+!  single_level%iseed(JLON) = ITIM + IDAY & 
+!       &  +  NINT(PGELAM(JLON)*108000000.0_JPRB &
+!       &          + ASIN(PGEMU(JLON))*6000.0_JPRB)
+!ENDDO
+!AI Nov 23
+! Simple initialization of the seeds for the Monte Carlo scheme
+call single_level%init_seed_simple(kidia, kfdia)
+
+print*,'********** CLOUDS (allocate + input) *******************************************'
+!print*,'Appel Allocate clouds'
+! Set cloud fields
+cloud%q_liq(KIDIA:KFDIA,:)    = PQ_LIQUID(KIDIA:KFDIA,:)
+cloud%q_ice(KIDIA:KFDIA,:)    = PQ_ICE(KIDIA:KFDIA,:) + PQ_SNOW(KIDIA:KFDIA,:)
+cloud%fraction(KIDIA:KFDIA,:) = PCLOUD_FRAC(KIDIA:KFDIA,:)
+!!! ok AI ATTENTION a voir avec JL
+! Compute effective radi and convert to metres
+! AI. : on passe directement les champs de LMDZ
+cloud%re_liq(KIDIA:KFDIA,:) = ZRE_LIQUID_UM(KIDIA:KFDIA,:)
+cloud%re_ice(KIDIA:KFDIA,:) = ZRE_ICE_UM(KIDIA:KFDIA,:)
+! Get the cloud overlap decorrelation length (for cloud boundaries),
+! in km, according to the parameterization specified by NDECOLAT,
+! and insert into the "cloud" object. Also get the ratio of
+! decorrelation lengths for cloud water content inhomogeneities and
+! cloud boundaries, and set it in the "rad_config" object.
+! IFS :
+!CALL CLOUD_OVERLAP_DECORR_LEN(KIDIA, KFDIA, KLON, PGEMU, YRERAD%NDECOLAT, &
+!     &    ZDECORR_LEN_KM, PDECORR_LEN_RATIO=ZDECORR_LEN_RATIO)
+! AI valeur dans namelist
+! rad_config%cloud_inhom_decorr_scaling = ZDECORR_LEN_RATIO
+!AI ATTENTION meme valeur que dans offline
+! A mettre dans namelist
+ZDECORR_LEN_KM = driver_config%overlap_decorr_length
+DO JLON = KIDIA,KFDIA
+  CALL cloud%set_overlap_param(thermodynamics, &
+       &                 ZDECORR_LEN_KM(JLON), &
+       &                 istartcol=JLON, iendcol=JLON)
+ENDDO
+! IFS :
+! Cloud water content fractional standard deviation is configurable
+! from namelist NAERAD but must be globally constant. Before it was
+! hard coded at 1.0.
+!CALL cloud%create_fractional_std(KLON, KLEV, YRERAD%RCLOUD_FRAC_STD)
+! AI ATTENTION frac_std=0.75 meme valeur que dans la version offline
+CALL cloud%create_fractional_std(KLON, KLEV, driver_config%frac_std)
+
+!if (ok_3Deffect) then
+! if (driver_config%ok_effective_size) then
+!     call cloud%create_inv_cloud_effective_size_eta(klon, klev, &
+!               &  thermodynamics%pressure_hl, &
+!               &  driver_config%low_inv_effective_size, &
+!               &  driver_config%middle_inv_effective_size, &
+!               &  driver_config%high_inv_effective_size, 0.8_jprb, 0.45_jprb, &
+!               &  KIDIA, KFDIA)
+!   else if (driver_config%ok_separation) then
+!     call cloud%param_cloud_effective_separation_eta(klon, klev, &
+!               &  thermodynamics%pressure_hl, &
+!               &  driver_config%cloud_separation_scale_surface, &
+!               &  driver_config%cloud_separation_scale_toa, &
+!               &  driver_config%cloud_separation_scale_power, &
+!               &  driver_config%cloud_inhom_separation_factor, &
+!               &  KIDIA, KFDIA)
+!   endif     
+! else  
+ if (rad_config%i_solver_sw == ISolverSPARTACUS &
+      & .or.   rad_config%i_solver_lw == ISolverSPARTACUS) then
+   ! AI ! Read cloud properties needed by SPARTACUS
+   if (driver_config%ok_effective_size) then
+     call cloud%create_inv_cloud_effective_size_eta(klon, klev, &
+               &  thermodynamics%pressure_hl, &
+               &  driver_config%low_inv_effective_size, &
+               &  driver_config%middle_inv_effective_size, &
+               &  driver_config%high_inv_effective_size, 0.8_jprb, 0.45_jprb, &
+               &  KIDIA, KFDIA)
+   else if (driver_config%ok_separation) then
+     call cloud%param_cloud_effective_separation_eta(klon, klev, &
+               &  thermodynamics%pressure_hl, &
+               &  driver_config%cloud_separation_scale_surface, &
+               &  driver_config%cloud_separation_scale_toa, &
+               &  driver_config%cloud_separation_scale_power, &
+               &  driver_config%cloud_inhom_separation_factor, &
+               &  KIDIA, KFDIA)
+   endif
+ endif  
+!endif
+
+print*,'******** AEROSOLS (input) **************************************'
+!IF (NAERMACC > 0) THEN
+!ELSE
+!  CALL aerosol%allocate(KLON, 1, KLEV, 6) ! Tegen climatology
+!ENDIF
+! Compute the dry mass of each layer neglecting humidity effects, in
+! kg m-2, needed to scale some of the aerosol inputs
+! AI commente ATTENTION
+!CALL thermodynamics%get_layer_mass(ZLAYER_MASS)
+
+! Copy over aerosol mass mixing ratio
+!IF (NAERMACC > 0) THEN
+
+  ! MACC aerosol climatology - this is already in mass mixing ratio
+  ! units with the required array orientation so we can copy it over
+  ! directly
+  aerosol%mixing_ratio(KIDIA:KFDIA,:,:) = PAEROSOL(KIDIA:KFDIA,:,:)
+
+  ! Add the tropospheric and stratospheric backgrounds contained in the
+  ! old Tegen arrays - this is very ugly!
+! AI ATTENTION
+!  IF (TROP_BG_AER_MASS_EXT > 0.0_JPRB) THEN
+!    aerosol%mixing_ratio(KIDIA:KFDIA,:,ITYPE_TROP_BG_AER) &
+!         &  = aerosol%mixing_ratio(KIDIA:KFDIA,:,ITYPE_TROP_BG_AER) &
+!         &  + PAEROSOL_OLD(KIDIA:KFDIA,1,:) &
+!         &  / (ZLAYER_MASS * TROP_BG_AER_MASS_EXT)
+!  ENDIF
+!  IF (STRAT_BG_AER_MASS_EXT > 0.0_JPRB) THEN
+!    aerosol%mixing_ratio(KIDIA:KFDIA,:,ITYPE_STRAT_BG_AER) &
+!         &  = aerosol%mixing_ratio(KIDIA:KFDIA,:,ITYPE_STRAT_BG_AER) &
+!         &  + PAEROSOL_OLD(KIDIA:KFDIA,6,:) &
+!         &  / (ZLAYER_MASS * STRAT_BG_AER_MASS_EXT)
+!  ENDIF
+
+!ELSE
+
+  ! Tegen aerosol climatology - the array PAEROSOL_OLD contains the
+  ! 550-nm optical depth in each layer. The optics data file
+  ! aerosol_ifs_rrtm_tegen.nc does not contain mass extinction
+  ! coefficient, but a scaling factor that the 550-nm optical depth
+  ! should be multiplied by to obtain the optical depth in each
+  ! spectral band.  Therefore, in order for the units to work out, we
+  ! need to divide by the layer mass (in kg m-2) to obtain the 550-nm
+  ! cross-section per unit mass of dry air (so in m2 kg-1).  We also
+  ! need to permute the array.
+!  DO JLEV = 1,KLEV
+!    DO JAER = 1,6
+!      aerosol%mixing_ratio(KIDIA:KFDIA,JLEV,JAER) &
+!         &  = PAEROSOL_OLD(KIDIA:KFDIA,JAER,JLEV) &
+!         &  / ZLAYER_MASS(KIDIA:KFDIA,JLEV)
+!    ENDDO
+!  ENDDO
+!ENDIF
+
+print*,'********** GAS (input) ************************************************'
+!print*,'Appel Allocate gas'
+! Convert ozone Pa*kg/kg to kg/kg
+! AI ATTENTION
+!DO JLEV = 1,KLEV
+!  DO JLON = KIDIA,KFDIA
+!    ZO3(JLON,JLEV) = PO3_DP(JLON,JLEV) &
+!         &         / (PPRESSURE_H(JLON,JLEV+1)-PPRESSURE_H(JLON,JLEV))
+!  ENDDO
+!ENDDO
+!  Insert gas mixing ratios
+!print*,'Insert gas mixing ratios'
+CALL gas%put(IH2O,    IMassMixingRatio, PQ)
+CALL gas%put(IO3,     IMassMixingRatio, PO3)
+CALL gas%put_well_mixed(ICO2,    IMAssMixingRatio, PCO2)
+CALL gas%put_well_mixed(ICH4,    IMassMixingRatio, PCH4)
+CALL gas%put_well_mixed(IN2O,    IMassMixingRatio, PN2O)
+CALL gas%put_well_mixed(ICFC11,  IMassMixingRatio, PCFC11)
+CALL gas%put_well_mixed(ICFC12,  IMassMixingRatio, PCFC12)
+CALL gas%put_well_mixed(IHCFC22, IMassMixingRatio, PHCFC22)
+CALL gas%put_well_mixed(ICCL4,   IMassMixingRatio, PCCL4)
+CALL gas%put_well_mixed(IO2,     IMassMixingRatio, PO2)
+! Ensure the units of the gas mixing ratios are what is required by
+! the gas absorption model
+call set_gas_units(rad_config, gas)
+
+! Call radiation scheme
+!print*,'*** Appel radiation *** namelist **** omp_rank ****', &
+!         omp_rank, namelist_file
+!   if (rad_config%i_solver_sw == ISolverSPARTACUS) then 
+!    if (driver_config%ok_separation) then
+!      print*,'Avant radiation, mpi_rank, omp_rank, size, chape inv_cloud = ',&
+!              mpi_rank, omp_rank, &
+!              shape(cloud%inv_cloud_effective_size), &
+!              size(cloud%inv_cloud_effective_size)      
+!      do jlon=KIDIA, KFDIA      
+!        do jlev=1,klev
+!         print*,' Avant radiation mpi_rank, omp_rank, jlon, jlev, &
+!            &     cloud%inv_cloud_effective_size =', mpi_rank, &
+!            &     omp_rank, jlon, jlev, &
+!            &     cloud%inv_cloud_effective_size(jlon,jlev)
+!        enddo
+!      enddo
+!       cloud%inv_cloud_effective_size=inv_cloud_effective_size
+!       cloud%inv_inhom_effective_size=inv_inhom_effective_size
+!    endif
+!   endif
+CALL radiation(KLON, KLEV, KIDIA, KFDIA, rad_config, &
+     &  single_level, thermodynamics, gas, cloud, aerosol, flux)
+
+ if (rad_config%use_aerosols) then
+    if (rad_config%i_gas_model_sw == IGasModelIFSRRTMG .or. &
+     &  rad_config%i_gas_model_lw == IGasModelIFSRRTMG) then     
+       CALL aeropt_5wv_ecrad(kidia, kfdia, 1, klev,     &
+     &                       rad_config,thermodynamics, aerosol)
+    endif                 
+
+    if (flag_aerosol_strat.eq.2) then
+       CALL readaerosolstrato_ecrad(rad_config, debut, ok_volcan)
+    endif
+ endif               
+
+print*,'*********** Sortie flux ****************'
+! Cloud cover
+ecrad_cloud_cover_sw = flux%cloud_cover_sw
+! Compute required output fluxes
+! DN and UP flux
+PFLUX_SW_DN(KIDIA:KFDIA,:) = flux%sw_dn(KIDIA:KFDIA,:)
+PFLUX_SW_UP(KIDIA:KFDIA,:) = flux%sw_up(KIDIA:KFDIA,:)
+PFLUX_LW_DN(KIDIA:KFDIA,:) = flux%lw_dn(KIDIA:KFDIA,:)
+PFLUX_LW_UP(KIDIA:KFDIA,:) = flux%lw_up(KIDIA:KFDIA,:)
+PFLUX_SW_DN_CLEAR(KIDIA:KFDIA,:) = flux%sw_dn_clear(KIDIA:KFDIA,:)
+PFLUX_SW_UP_CLEAR(KIDIA:KFDIA,:) = flux%sw_up_clear(KIDIA:KFDIA,:)
+PFLUX_LW_DN_CLEAR(KIDIA:KFDIA,:) = flux%lw_dn_clear(KIDIA:KFDIA,:)
+PFLUX_LW_UP_CLEAR(KIDIA:KFDIA,:) = flux%lw_up_clear(KIDIA:KFDIA,:)
+! First the net fluxes
+PFLUX_SW(KIDIA:KFDIA,:) = flux%sw_dn(KIDIA:KFDIA,:) - flux%sw_up(KIDIA:KFDIA,:)
+PFLUX_LW(KIDIA:KFDIA,:) = flux%lw_dn(KIDIA:KFDIA,:) - flux%lw_up(KIDIA:KFDIA,:)
+PFLUX_SW_CLEAR(KIDIA:KFDIA,:) &
+     &  = flux%sw_dn_clear(KIDIA:KFDIA,:) - flux%sw_up_clear(KIDIA:KFDIA,:)
+PFLUX_LW_CLEAR(KIDIA:KFDIA,:) &
+     &  = flux%lw_dn_clear(KIDIA:KFDIA,:) - flux%lw_up_clear(KIDIA:KFDIA,:)
+! Now the surface fluxes
+!PFLUX_SW_DN_SURF(KIDIA:KFDIA) = flux%sw_dn(KIDIA:KFDIA,KLEV+1)
+!PFLUX_LW_DN_SURF(KIDIA:KFDIA) = flux%lw_dn(KIDIA:KFDIA,KLEV+1)
+!PFLUX_SW_UP_SURF(KIDIA:KFDIA) = flux%sw_up(KIDIA:KFDIA,KLEV+1)
+!PFLUX_LW_UP_SURF(KIDIA:KFDIA) = flux%lw_up(KIDIA:KFDIA,KLEV+1)
+!PFLUX_SW_DN_CLEAR_SURF(KIDIA:KFDIA) = flux%sw_dn_clear(KIDIA:KFDIA,KLEV+1)
+!PFLUX_LW_DN_CLEAR_SURF(KIDIA:KFDIA) = flux%lw_dn_clear(KIDIA:KFDIA,KLEV+1)
+!PFLUX_SW_UP_CLEAR_SURF(KIDIA:KFDIA) = flux%sw_up_clear(KIDIA:KFDIA,KLEV+1)
+!PFLUX_LW_UP_CLEAR_SURF(KIDIA:KFDIA) = flux%lw_up_clear(KIDIA:KFDIA,KLEV+1)
+PFLUX_DIR(KIDIA:KFDIA) = flux%sw_dn_direct(KIDIA:KFDIA,KLEV+1)
+PFLUX_DIR_CLEAR(KIDIA:KFDIA) = flux%sw_dn_direct_clear(KIDIA:KFDIA,KLEV+1)
+PFLUX_DIR_INTO_SUN(KIDIA:KFDIA) = 0.0_JPRB
+WHERE (PMU0(KIDIA:KFDIA) > EPSILON(1.0_JPRB))
+  PFLUX_DIR_INTO_SUN(KIDIA:KFDIA) = PFLUX_DIR(KIDIA:KFDIA) / PMU0(KIDIA:KFDIA)
+END WHERE
+! Top-of-atmosphere downwelling flux
+!PFLUX_SW_DN_TOA(KIDIA:KFDIA) = flux%sw_dn(KIDIA:KFDIA,1)
+!PFLUX_SW_UP_TOA(KIDIA:KFDIA) = flux%sw_up(KIDIA:KFDIA,1)
+!PFLUX_LW_DN_TOA(KIDIA:KFDIA) = flux%lw_dn(KIDIA:KFDIA,1)
+!PFLUX_LW_UP_TOA(KIDIA:KFDIA) = flux%lw_up(KIDIA:KFDIA,1)
+!AI ATTENTION
+if (0.eq.1) then
+PFLUX_UV       (KIDIA:KFDIA) = 0.0_JPRB
+DO JBAND = 1,NWEIGHT_UV
+  PFLUX_UV(KIDIA:KFDIA) = PFLUX_UV(KIDIA:KFDIA) + WEIGHT_UV(JBAND) &
+       &  * flux%sw_dn_surf_band(IBAND_UV(JBAND),KIDIA:KFDIA)
+ENDDO
+! Compute photosynthetically active radiation similarly
+PFLUX_PAR      (KIDIA:KFDIA) = 0.0_JPRB
+PFLUX_PAR_CLEAR(KIDIA:KFDIA) = 0.0_JPRB
+DO JBAND = 1,NWEIGHT_PAR
+  PFLUX_PAR(KIDIA:KFDIA) = PFLUX_PAR(KIDIA:KFDIA) + WEIGHT_PAR(JBAND) &
+       &  * flux%sw_dn_surf_band(IBAND_PAR(JBAND),KIDIA:KFDIA)
+  PFLUX_PAR_CLEAR(KIDIA:KFDIA) = PFLUX_PAR_CLEAR(KIDIA:KFDIA) &
+       &  + WEIGHT_PAR(JBAND) &
+       &  * flux%sw_dn_surf_clear_band(IBAND_PAR(JBAND),KIDIA:KFDIA)
+ENDDO
+endif
+! Compute effective broadband emissivity
+ZBLACK_BODY_NET_LW = flux%lw_dn(KIDIA:KFDIA,KLEV+1) &
+     &  - RSIGMA*PTEMPERATURE_SKIN(KIDIA:KFDIA)**4
+PEMIS_OUT(KIDIA:KFDIA) = PEMIS(KIDIA:KFDIA)
+WHERE (ABS(ZBLACK_BODY_NET_LW) > 1.0E-5) 
+  PEMIS_OUT(KIDIA:KFDIA) = PFLUX_LW(KIDIA:KFDIA,KLEV+1) / ZBLACK_BODY_NET_LW
+END WHERE
+! Copy longwave derivatives
+! AI ATTENTION
+!IF (YRERAD%LAPPROXLWUPDATE) THEN
+IF (rad_config%do_lw_derivatives) THEN
+  PLWDERIVATIVE(KIDIA:KFDIA,:) = flux%lw_derivatives(KIDIA:KFDIA,:)
+END IF
+! Store the shortwave downwelling fluxes in each albedo band
+!AI ATTENTION
+!IF (YRERAD%LAPPROXSWUPDATE) THEN
+if (0.eq.1) then
+IF (rad_config%do_surface_sw_spectral_flux) THEN
+  PSWDIFFUSEBAND(KIDIA:KFDIA,:) = 0.0_JPRB
+  PSWDIRECTBAND (KIDIA:KFDIA,:) = 0.0_JPRB
+  DO JBAND = 1,rad_config%n_bands_sw
+    JB_ALBEDO = rad_config%i_albedo_from_band_sw(JBAND)
+    DO JLON = KIDIA,KFDIA
+      PSWDIFFUSEBAND(JLON,JB_ALBEDO) = PSWDIFFUSEBAND(JLON,JB_ALBEDO) &
+           &  + flux%sw_dn_surf_band(JBAND,JLON) &
+           &  - flux%sw_dn_direct_surf_band(JBAND,JLON)
+      PSWDIRECTBAND(JLON,JB_ALBEDO)  = PSWDIRECTBAND(JLON,JB_ALBEDO) &
+           &  + flux%sw_dn_direct_surf_band(JBAND,JLON)
+    ENDDO
+  ENDDO
+ENDIF
+endif
+
+print*,'********** DEALLOCATIONS ************************'
+CALL single_level%deallocate
+CALL thermodynamics%deallocate
+CALL gas%deallocate
+CALL cloud%deallocate
+CALL aerosol%deallocate
+CALL flux%deallocate
+
+IF (LHOOK) CALL DR_HOOK('RADIATION_SCHEME',1,ZHOOK_HANDLE)
+
+END SUBROUTINE RADIATION_SCHEME
+
+SUBROUTINE RADIATION_SCHEME_S2 &
+! Inputs
+     & (KIDIA, KFDIA, KLON, KLEV, KAEROSOL, NSW, &
+     &  namelist_file, ok_3Deffect, &
+     &  debut, ok_volcan, flag_aerosol_strat, &
+     &  IDAY, TIME, &
+     &  PSOLAR_IRRADIANCE, &
+     &  PMU0, PTEMPERATURE_SKIN, &
+     &  PALBEDO_DIF, PALBEDO_DIR, &
+     &  PEMIS, PEMIS_WINDOW, &
+     &  PGELAM, PGEMU, &
+     &  PPRESSURE_H, PTEMPERATURE_H, PQ, PQSAT, &
+     &  PCO2, PCH4, PN2O, PNO2, PCFC11, PCFC12, PHCFC22, &
+     &  PCCL4, PO3, PO2, &
+     &  PCLOUD_FRAC, PQ_LIQUID, PQ_ICE, PQ_SNOW, &
+     &  ZRE_LIQUID_UM, ZRE_ICE_UM, &
+     &  PAEROSOL_OLD, PAEROSOL, &
+! Outputs
+     &  PFLUX_SW, PFLUX_LW, PFLUX_SW_CLEAR, PFLUX_LW_CLEAR, &
+     &  PFLUX_SW_DN, PFLUX_LW_DN, PFLUX_SW_DN_CLEAR, PFLUX_LW_DN_CLEAR, &
+     &  PFLUX_SW_UP, PFLUX_LW_UP, PFLUX_SW_UP_CLEAR, PFLUX_LW_UP_CLEAR, &
+     &  PFLUX_DIR, PFLUX_DIR_CLEAR, PFLUX_DIR_INTO_SUN, &
+     &  PFLUX_UV, PFLUX_PAR, PFLUX_PAR_CLEAR, &
+     &  PEMIS_OUT, PLWDERIVATIVE, &
+     &  PSWDIFFUSEBAND, PSWDIRECTBAND, &
+     &  ecrad_cloud_cover_sw)
+
+! RADIATION_SCHEME - Interface to modular radiation scheme
+!
+! (C) Copyright 2015- ECMWF.
+!
+! This software is licensed under the terms of the Apache Licence Version 2.0
+! which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
+!
+! In applying this licence, ECMWF does not waive the privileges and immunities
+! granted to it by virtue of its status as an intergovernmental organisation
+! nor does it submit to any jurisdiction.
+!
+! PURPOSE
+! -------
+!   The modular radiation scheme is contained in a separate
+!   library. This routine puts the the IFS arrays into appropriate
+!   objects, computing the additional data that is required, and sends
+!   it to the radiation scheme.  It returns net fluxes and surface
+!   flux components needed by the rest of the model. 
+!
+!   Lower case is used for variables and types taken from the
+!   radiation library
+!
+! INTERFACE
+! ---------
+!    RADIATION_SCHEME is called from RADLSWR. The
+!    SETUP_RADIATION_SCHEME routine (in the RADIATION_SETUP module)
+!    should have been run first.
+!
+! AUTHOR
+! ------
+!   Robin Hogan, ECMWF
+!   Original: 2015-09-16
+!
+! MODIFICATIONS
+! -------------
+!
+! TO DO
+! -----
+!
+!-----------------------------------------------------------------------
+
+! Modules from ifs or ifsaux libraries
+USE PARKIND1 , ONLY : JPIM, JPRB
+USE YOMHOOK  , ONLY : LHOOK, DR_HOOK
+USE RADIATION_SETUP
+USE YOMCST   , ONLY : RSIGMA ! Stefan-Boltzmann constant
+!USE RADIATION_SETUP, ONLY : SETUP_RADIATION_SCHEME, &
+!                         &  config_type, driver_config_type, &
+!                         &  NWEIGHT_UV,  IBAND_UV,  WEIGHT_UV, &
+!                         &  NWEIGHT_PAR, IBAND_PAR, WEIGHT_PAR, &
+!                         &  ITYPE_TROP_BG_AER,  TROP_BG_AER_MASS_EXT, &
+!                         &  ITYPE_STRAT_BG_AER, STRAT_BG_AER_MASS_EXT, &
+!                         &  ISolverSpartacus
+
+! Modules from radiation library
+USE radiation_single_level,   ONLY : single_level_type
+USE radiation_thermodynamics, ONLY : thermodynamics_type
+USE radiation_gas
+USE radiation_cloud,          ONLY : cloud_type
+USE radiation_aerosol,        ONLY : aerosol_type
+USE radiation_flux,           ONLY : flux_type
+USE radiation_interface,      ONLY : radiation, set_gas_units
+USE radiation_save,           ONLY : save_inputs
+
+USE mod_phys_lmdz_para
+
+IMPLICIT NONE
+
+! INPUT ARGUMENTS
+! *** Array dimensions and ranges
+INTEGER(KIND=JPIM),INTENT(IN) :: KIDIA    ! Start column to process
+INTEGER(KIND=JPIM),INTENT(IN) :: KFDIA    ! End column to process
+!INTEGER, INTENT(IN) :: KIDIA, KFDIA
+INTEGER(KIND=JPIM),INTENT(IN) :: KLON     ! Number of columns
+INTEGER(KIND=JPIM),INTENT(IN) :: KLEV     ! Number of levels
+!INTEGER, INTENT(IN) :: KLON, KLEV
+!INTEGER(KIND=JPIM),INTENT(IN) :: KAEROLMDZ ! Number of aerosol types
+INTEGER(KIND=JPIM),INTENT(IN) :: KAEROSOL
+INTEGER(KIND=JPIM),INTENT(IN) :: NSW ! Numbe of bands
+
+! AI ATTENTION
+!INTEGER, PARAMETER :: KAEROSOL = 12
+
+! *** Single-level fields
+REAL(KIND=JPRB),   INTENT(IN) :: PSOLAR_IRRADIANCE ! (W m-2)
+REAL(KIND=JPRB),   INTENT(IN) :: PMU0(KLON) ! Cosine of solar zenith ang
+REAL(KIND=JPRB),   INTENT(IN) :: PTEMPERATURE_SKIN(KLON) ! (K)
+! Diffuse and direct components of surface shortwave albedo
+!REAL(KIND=JPRB),   INTENT(IN) :: PALBEDO_DIF(KLON,YRERAD%NSW)
+!REAL(KIND=JPRB),   INTENT(IN) :: PALBEDO_DIR(KLON,YRERAD%NSW)
+REAL(KIND=JPRB),   INTENT(IN) :: PALBEDO_DIF(KLON,NSW)
+REAL(KIND=JPRB),   INTENT(IN) :: PALBEDO_DIR(KLON,NSW)
+! Longwave emissivity outside and inside the window region
+REAL(KIND=JPRB),   INTENT(IN) :: PEMIS(KLON)
+REAL(KIND=JPRB),   INTENT(IN) :: PEMIS_WINDOW(KLON)
+! Longitude (radians), sine of latitude
+REAL(KIND=JPRB),   INTENT(IN) :: PGELAM(KLON)
+REAL(KIND=JPRB),   INTENT(IN) :: PGEMU(KLON)
+! Land-sea mask
+!REAL(KIND=JPRB),   INTENT(IN) :: PLAND_SEA_MASK(KLON) 
+
+! *** Variables on half levels
+REAL(KIND=JPRB),   INTENT(IN) :: PPRESSURE_H(KLON,KLEV+1)    ! (Pa)
+REAL(KIND=JPRB),   INTENT(IN) :: PTEMPERATURE_H(KLON,KLEV+1) ! (K)
+
+! *** Gas mass mixing ratios on full levels
+REAL(KIND=JPRB),   INTENT(IN) :: PQ(KLON,KLEV) 
+! AI
+REAL(KIND=JPRB),   INTENT(IN) :: PQSAT(KLON,KLEV)
+REAL(KIND=JPRB),   INTENT(IN) :: PCO2
+REAL(KIND=JPRB),   INTENT(IN) :: PCH4 
+REAL(KIND=JPRB),   INTENT(IN) :: PN2O 
+REAL(KIND=JPRB),   INTENT(IN) :: PNO2 
+REAL(KIND=JPRB),   INTENT(IN) :: PCFC11
+REAL(KIND=JPRB),   INTENT(IN) :: PCFC12
+REAL(KIND=JPRB),   INTENT(IN) :: PHCFC22
+REAL(KIND=JPRB),   INTENT(IN) :: PCCL4
+REAL(KIND=JPRB),   INTENT(IN) :: PO3(KLON,KLEV) ! AI (kg/kg) ATTENTION (Pa*kg/kg) 
+REAL(KIND=JPRB),   INTENT(IN) :: PO2
+
+! *** Cloud fraction and hydrometeor mass mixing ratios
+REAL(KIND=JPRB),   INTENT(IN) :: PCLOUD_FRAC(KLON,KLEV)
+REAL(KIND=JPRB),   INTENT(IN) :: PQ_LIQUID(KLON,KLEV)
+REAL(KIND=JPRB),   INTENT(IN) :: PQ_ICE(KLON,KLEV)
+!REAL(KIND=JPRB),   INTENT(IN) :: PQ_RAIN(KLON,KLEV)
+REAL(KIND=JPRB),   INTENT(IN) :: PQ_SNOW(KLON,KLEV)
+
+! *** Aerosol mass mixing ratios
+REAL(KIND=JPRB),   INTENT(IN) :: PAEROSOL_OLD(KLON,6,KLEV)
+REAL(KIND=JPRB),   INTENT(IN) :: PAEROSOL(KLON,KLEV,KAEROSOL)
+
+!REAL(KIND=JPRB),   INTENT(IN) :: PCCN_LAND(KLON) 
+!REAL(KIND=JPRB),   INTENT(IN) :: PCCN_SEA(KLON) 
+
+!AI mars 2021
+INTEGER(KIND=JPIM), INTENT(IN) :: IDAY
+REAL(KIND=JPRB), INTENT(IN)    :: TIME
+
+! Name of file names specified on command line
+character(len=512), INTENT(IN) :: namelist_file
+logical, INTENT(IN)            :: ok_3Deffect, debut, ok_volcan
+INTEGER(KIND=JPIM), INTENT(IN) :: flag_aerosol_strat
+
+
+! OUTPUT ARGUMENTS
+
+! *** Net fluxes on half-levels (W m-2)
+REAL(KIND=JPRB),  INTENT(OUT) :: PFLUX_SW(KLON,KLEV+1) 
+REAL(KIND=JPRB),  INTENT(OUT) :: PFLUX_LW(KLON,KLEV+1) 
+REAL(KIND=JPRB),  INTENT(OUT) :: PFLUX_SW_CLEAR(KLON,KLEV+1) 
+REAL(KIND=JPRB),  INTENT(OUT) :: PFLUX_LW_CLEAR(KLON,KLEV+1) 
+
+!*** DN and UP flux on half-levels (W m-2)
+REAL(KIND=JPRB),  INTENT(OUT) :: PFLUX_SW_DN(KLON,KLEV+1)
+REAL(KIND=JPRB),  INTENT(OUT) :: PFLUX_LW_DN(KLON,KLEV+1)
+REAL(KIND=JPRB),  INTENT(OUT) :: PFLUX_SW_DN_CLEAR(KLON,KLEV+1)
+REAL(KIND=JPRB),  INTENT(OUT) :: PFLUX_LW_DN_CLEAR(KLON,KLEV+1)
+REAL(KIND=JPRB),  INTENT(OUT) :: PFLUX_SW_UP(KLON,KLEV+1)
+REAL(KIND=JPRB),  INTENT(OUT) :: PFLUX_LW_UP(KLON,KLEV+1)
+REAL(KIND=JPRB),  INTENT(OUT) :: PFLUX_SW_UP_CLEAR(KLON,KLEV+1)
+REAL(KIND=JPRB),  INTENT(OUT) :: PFLUX_LW_UP_CLEAR(KLON,KLEV+1)
+
+! Direct component of surface flux into horizontal plane
+REAL(KIND=JPRB),  INTENT(OUT) :: PFLUX_DIR(KLON)
+REAL(KIND=JPRB),  INTENT(OUT) :: PFLUX_DIR_CLEAR(KLON)
+! As PFLUX_DIR but into a plane perpendicular to the sun
+REAL(KIND=JPRB),  INTENT(OUT) :: PFLUX_DIR_INTO_SUN(KLON)
+
+! *** Ultraviolet and photosynthetically active radiation (W m-2)
+REAL(KIND=JPRB),  INTENT(OUT) :: PFLUX_UV(KLON)
+REAL(KIND=JPRB),  INTENT(OUT) :: PFLUX_PAR(KLON)
+REAL(KIND=JPRB),  INTENT(OUT) :: PFLUX_PAR_CLEAR(KLON)
+
+! Diagnosed longwave surface emissivity across the whole spectrum
+REAL(KIND=JPRB),  INTENT(OUT) :: PEMIS_OUT(KLON)   
+
+! Partial derivative of total-sky longwave upward flux at each level
+! with respect to upward flux at surface, used to correct heating
+! rates at gridpoints/timesteps between calls to the full radiation
+! scheme.  Note that this version uses the convention of level index
+! increasing downwards, unlike the local variable ZLwDerivative that
+! is returned from the LW radiation scheme.
+REAL(KIND=JPRB),  INTENT(OUT) :: PLWDERIVATIVE(KLON,KLEV+1)
+
+! Surface diffuse and direct downwelling shortwave flux in each
+! shortwave albedo band, used in RADINTG to update the surface fluxes
+! accounting for high-resolution albedo information
+REAL(KIND=JPRB),  INTENT(OUT) :: PSWDIFFUSEBAND(KLON,NSW)
+REAL(KIND=JPRB),  INTENT(OUT) :: PSWDIRECTBAND (KLON,NSW)
+
+!AI Nov 2023
+REAL(KIND=JPRB),  INTENT(OUT) :: ecrad_cloud_cover_sw(KLON)
+
+! LOCAL VARIABLES
+! AI ATTENTION
+type(config_type),save         :: rad_config
+!!$OMP THREADPRIVATE(rad_config)
+type(driver_config_type),save  :: driver_config
+!!$OMP THREADPRIVATE(driver_config)
+!type(config_type)        :: rad_config
+!type(driver_config_type)  :: driver_config
+TYPE(single_level_type)   :: single_level
+TYPE(thermodynamics_type) :: thermodynamics
+TYPE(gas_type)            :: gas
+TYPE(cloud_type)          :: cloud
+TYPE(aerosol_type)        :: aerosol
+TYPE(flux_type)           :: flux
+
+! Mass mixing ratio of ozone (kg/kg)
+REAL(KIND=JPRB)           :: ZO3(KLON,KLEV)
+
+! Cloud effective radii in microns
+REAL(KIND=JPRB)           :: ZRE_LIQUID_UM(KLON,KLEV)
+REAL(KIND=JPRB)           :: ZRE_ICE_UM(KLON,KLEV)
+
+! Cloud overlap decorrelation length for cloud boundaries in km
+REAL(KIND=JPRB)           :: ZDECORR_LEN_KM(KLON)
+
+! Ratio of cloud overlap decorrelation length for cloud water
+! inhomogeneities to that for cloud boundaries (typically 0.5)
+!REAL(KIND=JPRB)           :: ZDECORR_LEN_RATIO = 0.5_jprb
+
+! The surface net longwave flux if the surface was a black body, used
+! to compute the effective broadband surface emissivity
+REAL(KIND=JPRB)           :: ZBLACK_BODY_NET_LW(KIDIA:KFDIA)
+
+! Layer mass in kg m-2
+REAL(KIND=JPRB)           :: ZLAYER_MASS(KIDIA:KFDIA,KLEV)
+
+! Time integers
+INTEGER :: ITIM
+
+! Loop indices
+INTEGER :: JLON, JLEV, JBAND, JB_ALBEDO, JAER
+
+REAL(KIND=JPRB) :: ZHOOK_HANDLE
+
+! AI ATTENTION traitement aerosols
+INTEGER, PARAMETER :: NAERMACC = 1
+
+logical :: loutput=.true.
+logical :: lprint_input=.false.
+logical :: lprint_config=.false.
+logical, save :: debut_ecrad=.true.
+!$OMP THREADPRIVATE(debut_ecrad)
+integer, save :: itap_ecrad=0
+!$OMP THREADPRIVATE(itap_ecrad)
+
+REAL(KIND=JPRB) ::  inv_cloud_effective_size(KLON,KLEV)
+REAL(KIND=JPRB) ::  inv_inhom_effective_size(KLON,KLEV)
+
+integer :: irang
+
+
+IF (LHOOK) CALL DR_HOOK('RADIATION_SCHEME',0,ZHOOK_HANDLE)
+
+   print*,'Entree radiation_scheme_s2, ok_3Deffect, namelist_file = ', &
+          ok_3Deffect, namelist_file
+! A.I juillet 2023 : 
+! Initialisation dans radiation_setup au 1er passage dans Ecrad
+!$OMP MASTER
+!if (.not.ok_3Deffect) then
+  if (debut_ecrad) then
+   call SETUP_RADIATION_SCHEME(loutput,namelist_file,rad_config,driver_config)
+   debut_ecrad=.false. 
+  endif 
+!else
+!   call SETUP_RADIATION_SCHEME(loutput,namelist_file,rad_config,driver_config)
+!endif
+!$OMP END MASTER
+!$OMP BARRIER 
+! Fin partie initialisation et configuration 
+
+!AI print fichiers namelist utilise
+!if (is_omp_root) then
+! itap_ecrad=itap_ecrad+1
+! print*,'Dans radiation_scheme itap_ecrad, mpi_rank, omp_rank, namelist_file : ', &
+!         itap_ecrad, mpi_rank, omp_rank, namelist_file
+!else
+! print*,'mpi_rank omp_rank, namelist_file :', mpi_rank, omp_rank, namelist_file
+!endif
+
+! AI 11 23 Allocates depplaces au debut
+print*,'*********** ALLOCATES *******************************'
+! AI ATTENTION
+! Allocate memory in radiation objects
+! emissivite avec une seule bande
+CALL single_level%allocate(KLON, NSW, 1, &
+     &                     use_sw_albedo_direct=.TRUE.)
+CALL thermodynamics%allocate(KLON, KLEV, use_h2o_sat=.true.)
+CALL cloud%allocate(KLON, KLEV)
+CALL aerosol%allocate(KLON, 1, KLEV, KAEROSOL)
+CALL gas%allocate(KLON, KLEV)
+CALL flux%allocate(rad_config, 1, KLON, KLEV)
+
+print*,'************* THERMO (input) ************************************'
+! Set thermodynamic profiles: simply copy over the half-level
+! pressure and temperature
+! AI
+! pressure_hl > paprs
+! temperature_hl calculee dans radlsw de la meme facon que pour RRTM
+thermodynamics%pressure_hl   (KIDIA:KFDIA,:) = PPRESSURE_H   (KIDIA:KFDIA,:)
+thermodynamics%temperature_hl(KIDIA:KFDIA,:) = PTEMPERATURE_H(KIDIA:KFDIA,:)
+!print*,'Compute saturation specific humidity'
+! Compute saturation specific humidity, used to hydrate aerosols. The
+! "2" for the last argument indicates that the routine is not being
+! called from within the convection scheme.
+!CALL SATUR(KIDIA, KFDIA, KLON, 1, KLEV, &
+!     &  PPRESSURE, PTEMPERATURE, thermodynamics%h2o_sat_liq, 2)
+! Alternative approximate version using temperature and pressure from
+! the thermodynamics structure
+!CALL thermodynamics%calc_saturation_wrt_liquid(KIDIA, KFDIA)
+!AI ATTENTION
+thermodynamics%h2o_sat_liq = PQSAT
+
+print*,'********** SINGLE LEVEL VARS **********************************'
+!AI ATTENTION
+! Set single-level fileds
+single_level%solar_irradiance              = PSOLAR_IRRADIANCE
+single_level%cos_sza(KIDIA:KFDIA)          = PMU0(KIDIA:KFDIA)
+single_level%skin_temperature(KIDIA:KFDIA) = PTEMPERATURE_SKIN(KIDIA:KFDIA)
+single_level%sw_albedo(KIDIA:KFDIA,:)      = PALBEDO_DIF(KIDIA:KFDIA,:)
+single_level%sw_albedo_direct(KIDIA:KFDIA,:)=PALBEDO_DIR(KIDIA:KFDIA,:)
+single_level%lw_emissivity(KIDIA:KFDIA,1)  = PEMIS(KIDIA:KFDIA)
+!single_level%lw_emissivity(KIDIA:KFDIA,2)  = PEMIS_WINDOW(KIDIA:KFDIA)
+
+! Create the relevant seed from date and time get the starting day
+! and number of minutes since start
+!IDAY = NDD(NINDAT)
+!cur_day
+!ITIM = NINT(NSTEP * YRRIP%TSTEP / 60.0_JPRB)
+!ITIM = NINT(TIME / 60.0_JPRB)
+!current_time
+!allocate(single_level%iseed(KIDIA:KFDIA))
+!DO JLON = KIDIA, KFDIA
+  ! This method gives a unique value for roughly every 1-km square
+  ! on the globe and every minute.  ASIN(PGEMU)*60 gives rough
+  ! latitude in degrees, which we multiply by 100 to give a unique
+  ! value for roughly every km. PGELAM*60*100 gives a unique number
+  ! for roughly every km of longitude around the equator, which we
+  ! multiply by 180*100 so there is no overlap with the latitude
+  ! values.  The result can be contained in a 32-byte integer (but
+  ! since random numbers are generated with the help of integer
+  ! overflow, it should not matter if the number did overflow).
+!  single_level%iseed(JLON) = ITIM + IDAY & 
+!       &  +  NINT(PGELAM(JLON)*108000000.0_JPRB &
+!       &          + ASIN(PGEMU(JLON))*6000.0_JPRB)
+!ENDDO
+!AI Nov 23
+! Simple initialization of the seeds for the Monte Carlo scheme
+call single_level%init_seed_simple(kidia, kfdia)
+
+print*,'********** CLOUDS (allocate + input) *******************************************'
+!print*,'Appel Allocate clouds'
+! Set cloud fields
+cloud%q_liq(KIDIA:KFDIA,:)    = PQ_LIQUID(KIDIA:KFDIA,:)
+cloud%q_ice(KIDIA:KFDIA,:)    = PQ_ICE(KIDIA:KFDIA,:) + PQ_SNOW(KIDIA:KFDIA,:)
+cloud%fraction(KIDIA:KFDIA,:) = PCLOUD_FRAC(KIDIA:KFDIA,:)
+!!! ok AI ATTENTION a voir avec JL
+! Compute effective radi and convert to metres
+! AI. : on passe directement les champs de LMDZ
+cloud%re_liq(KIDIA:KFDIA,:) = ZRE_LIQUID_UM(KIDIA:KFDIA,:)
+cloud%re_ice(KIDIA:KFDIA,:) = ZRE_ICE_UM(KIDIA:KFDIA,:)
+! Get the cloud overlap decorrelation length (for cloud boundaries),
+! in km, according to the parameterization specified by NDECOLAT,
+! and insert into the "cloud" object. Also get the ratio of
+! decorrelation lengths for cloud water content inhomogeneities and
+! cloud boundaries, and set it in the "rad_config" object.
+! IFS :
+!CALL CLOUD_OVERLAP_DECORR_LEN(KIDIA, KFDIA, KLON, PGEMU, YRERAD%NDECOLAT, &
+!     &    ZDECORR_LEN_KM, PDECORR_LEN_RATIO=ZDECORR_LEN_RATIO)
+! AI valeur dans namelist
+! rad_config%cloud_inhom_decorr_scaling = ZDECORR_LEN_RATIO
+!AI ATTENTION meme valeur que dans offline
+! A mettre dans namelist
+ZDECORR_LEN_KM = driver_config%overlap_decorr_length
+DO JLON = KIDIA,KFDIA
+  CALL cloud%set_overlap_param(thermodynamics, &
+       &                 ZDECORR_LEN_KM(JLON), &
+       &                 istartcol=JLON, iendcol=JLON)
+ENDDO
+! IFS :
+! Cloud water content fractional standard deviation is configurable
+! from namelist NAERAD but must be globally constant. Before it was
+! hard coded at 1.0.
+!CALL cloud%create_fractional_std(KLON, KLEV, YRERAD%RCLOUD_FRAC_STD)
+! AI ATTENTION frac_std=0.75 meme valeur que dans la version offline
+CALL cloud%create_fractional_std(KLON, KLEV, driver_config%frac_std)
+
+!if (ok_3Deffect) then
+! if (driver_config%ok_effective_size) then
+!     call cloud%create_inv_cloud_effective_size_eta(klon, klev, &
+!               &  thermodynamics%pressure_hl, &
+!               &  driver_config%low_inv_effective_size, &
+!               &  driver_config%middle_inv_effective_size, &
+!               &  driver_config%high_inv_effective_size, 0.8_jprb, 0.45_jprb, &
+!               &  KIDIA, KFDIA)
+!   else if (driver_config%ok_separation) then
+!     call cloud%param_cloud_effective_separation_eta(klon, klev, &
+!               &  thermodynamics%pressure_hl, &
+!               &  driver_config%cloud_separation_scale_surface, &
+!               &  driver_config%cloud_separation_scale_toa, &
+!               &  driver_config%cloud_separation_scale_power, &
+!               &  driver_config%cloud_inhom_separation_factor, &
+!               &  KIDIA, KFDIA)
+!   endif     
+! else  
+ if (rad_config%i_solver_sw == ISolverSPARTACUS &
+      & .or.   rad_config%i_solver_lw == ISolverSPARTACUS) then
+   ! AI ! Read cloud properties needed by SPARTACUS
+   if (driver_config%ok_effective_size) then
+     call cloud%create_inv_cloud_effective_size_eta(klon, klev, &
+               &  thermodynamics%pressure_hl, &
+               &  driver_config%low_inv_effective_size, &
+               &  driver_config%middle_inv_effective_size, &
+               &  driver_config%high_inv_effective_size, 0.8_jprb, 0.45_jprb, &
+               &  KIDIA, KFDIA)
+   else if (driver_config%ok_separation) then
+     call cloud%param_cloud_effective_separation_eta(klon, klev, &
+               &  thermodynamics%pressure_hl, &
+               &  driver_config%cloud_separation_scale_surface, &
+               &  driver_config%cloud_separation_scale_toa, &
+               &  driver_config%cloud_separation_scale_power, &
+               &  driver_config%cloud_inhom_separation_factor, &
+               &  KIDIA, KFDIA)
+   endif
+ endif  
+!endif
+
+print*,'******** AEROSOLS (input) **************************************'
+!IF (NAERMACC > 0) THEN
+!ELSE
+!  CALL aerosol%allocate(KLON, 1, KLEV, 6) ! Tegen climatology
+!ENDIF
+! Compute the dry mass of each layer neglecting humidity effects, in
+! kg m-2, needed to scale some of the aerosol inputs
+! AI commente ATTENTION
+!CALL thermodynamics%get_layer_mass(ZLAYER_MASS)
+
+! Copy over aerosol mass mixing ratio
+!IF (NAERMACC > 0) THEN
+
+  ! MACC aerosol climatology - this is already in mass mixing ratio
+  ! units with the required array orientation so we can copy it over
+  ! directly
+  aerosol%mixing_ratio(KIDIA:KFDIA,:,:) = PAEROSOL(KIDIA:KFDIA,:,:)
+
+  ! Add the tropospheric and stratospheric backgrounds contained in the
+  ! old Tegen arrays - this is very ugly!
+! AI ATTENTION
+!  IF (TROP_BG_AER_MASS_EXT > 0.0_JPRB) THEN
+!    aerosol%mixing_ratio(KIDIA:KFDIA,:,ITYPE_TROP_BG_AER) &
+!         &  = aerosol%mixing_ratio(KIDIA:KFDIA,:,ITYPE_TROP_BG_AER) &
+!         &  + PAEROSOL_OLD(KIDIA:KFDIA,1,:) &
+!         &  / (ZLAYER_MASS * TROP_BG_AER_MASS_EXT)
+!  ENDIF
+!  IF (STRAT_BG_AER_MASS_EXT > 0.0_JPRB) THEN
+!    aerosol%mixing_ratio(KIDIA:KFDIA,:,ITYPE_STRAT_BG_AER) &
+!         &  = aerosol%mixing_ratio(KIDIA:KFDIA,:,ITYPE_STRAT_BG_AER) &
+!         &  + PAEROSOL_OLD(KIDIA:KFDIA,6,:) &
+!         &  / (ZLAYER_MASS * STRAT_BG_AER_MASS_EXT)
+!  ENDIF
+
+!ELSE
+
+  ! Tegen aerosol climatology - the array PAEROSOL_OLD contains the
+  ! 550-nm optical depth in each layer. The optics data file
+  ! aerosol_ifs_rrtm_tegen.nc does not contain mass extinction
+  ! coefficient, but a scaling factor that the 550-nm optical depth
+  ! should be multiplied by to obtain the optical depth in each
+  ! spectral band.  Therefore, in order for the units to work out, we
+  ! need to divide by the layer mass (in kg m-2) to obtain the 550-nm
+  ! cross-section per unit mass of dry air (so in m2 kg-1).  We also
+  ! need to permute the array.
+!  DO JLEV = 1,KLEV
+!    DO JAER = 1,6
+!      aerosol%mixing_ratio(KIDIA:KFDIA,JLEV,JAER) &
+!         &  = PAEROSOL_OLD(KIDIA:KFDIA,JAER,JLEV) &
+!         &  / ZLAYER_MASS(KIDIA:KFDIA,JLEV)
+!    ENDDO
+!  ENDDO
+!ENDIF
+
+print*,'********** GAS (input) ************************************************'
+!print*,'Appel Allocate gas'
+! Convert ozone Pa*kg/kg to kg/kg
+! AI ATTENTION
+!DO JLEV = 1,KLEV
+!  DO JLON = KIDIA,KFDIA
+!    ZO3(JLON,JLEV) = PO3_DP(JLON,JLEV) &
+!         &         / (PPRESSURE_H(JLON,JLEV+1)-PPRESSURE_H(JLON,JLEV))
+!  ENDDO
+!ENDDO
+!  Insert gas mixing ratios
+!print*,'Insert gas mixing ratios'
+CALL gas%put(IH2O,    IMassMixingRatio, PQ)
+CALL gas%put(IO3,     IMassMixingRatio, PO3)
+CALL gas%put_well_mixed(ICO2,    IMAssMixingRatio, PCO2)
+CALL gas%put_well_mixed(ICH4,    IMassMixingRatio, PCH4)
+CALL gas%put_well_mixed(IN2O,    IMassMixingRatio, PN2O)
+CALL gas%put_well_mixed(ICFC11,  IMassMixingRatio, PCFC11)
+CALL gas%put_well_mixed(ICFC12,  IMassMixingRatio, PCFC12)
+CALL gas%put_well_mixed(IHCFC22, IMassMixingRatio, PHCFC22)
+CALL gas%put_well_mixed(ICCL4,   IMassMixingRatio, PCCL4)
+CALL gas%put_well_mixed(IO2,     IMassMixingRatio, PO2)
+! Ensure the units of the gas mixing ratios are what is required by
+! the gas absorption model
+call set_gas_units(rad_config, gas)
+
+! Call radiation scheme
+!print*,'*** Appel radiation *** namelist **** omp_rank ****', &
+!         omp_rank, namelist_file
+!   if (rad_config%i_solver_sw == ISolverSPARTACUS) then 
+!    if (driver_config%ok_separation) then
+!      print*,'Avant radiation, mpi_rank, omp_rank, size, chape inv_cloud = ',&
+!              mpi_rank, omp_rank, &
+!              shape(cloud%inv_cloud_effective_size), &
+!              size(cloud%inv_cloud_effective_size)      
+!      do jlon=KIDIA, KFDIA      
+!        do jlev=1,klev
+!         print*,' Avant radiation mpi_rank, omp_rank, jlon, jlev, &
+!            &     cloud%inv_cloud_effective_size =', mpi_rank, &
+!            &     omp_rank, jlon, jlev, &
+!            &     cloud%inv_cloud_effective_size(jlon,jlev)
+!        enddo
+!      enddo
+!       cloud%inv_cloud_effective_size=inv_cloud_effective_size
+!       cloud%inv_inhom_effective_size=inv_inhom_effective_size
+!    endif
+!   endif
+CALL radiation(KLON, KLEV, KIDIA, KFDIA, rad_config, &
+     &  single_level, thermodynamics, gas, cloud, aerosol, flux)
+
+ if (rad_config%use_aerosols) then
+    if (rad_config%i_gas_model_sw == IGasModelIFSRRTMG .or. &
+     &    rad_config%i_gas_model_lw == IGasModelIFSRRTMG) then     
+       CALL aeropt_5wv_ecrad(kidia, kfdia, 1, klev, &
+                             rad_config,thermodynamics,aerosol)
+    endif                 
+    if (flag_aerosol_strat.eq.2) then
+       CALL readaerosolstrato_ecrad(rad_config, debut, ok_volcan)
+    endif
+ endif               
+
+print*,'*********** Sortie flux ****************'
+! Cloud cover
+ecrad_cloud_cover_sw = flux%cloud_cover_sw
+! Compute required output fluxes
+! DN and UP flux
+PFLUX_SW_DN(KIDIA:KFDIA,:) = flux%sw_dn(KIDIA:KFDIA,:)
+PFLUX_SW_UP(KIDIA:KFDIA,:) = flux%sw_up(KIDIA:KFDIA,:)
+PFLUX_LW_DN(KIDIA:KFDIA,:) = flux%lw_dn(KIDIA:KFDIA,:)
+PFLUX_LW_UP(KIDIA:KFDIA,:) = flux%lw_up(KIDIA:KFDIA,:)
+PFLUX_SW_DN_CLEAR(KIDIA:KFDIA,:) = flux%sw_dn_clear(KIDIA:KFDIA,:)
+PFLUX_SW_UP_CLEAR(KIDIA:KFDIA,:) = flux%sw_up_clear(KIDIA:KFDIA,:)
+PFLUX_LW_DN_CLEAR(KIDIA:KFDIA,:) = flux%lw_dn_clear(KIDIA:KFDIA,:)
+PFLUX_LW_UP_CLEAR(KIDIA:KFDIA,:) = flux%lw_up_clear(KIDIA:KFDIA,:)
+! First the net fluxes
+PFLUX_SW(KIDIA:KFDIA,:) = flux%sw_dn(KIDIA:KFDIA,:) - flux%sw_up(KIDIA:KFDIA,:)
+PFLUX_LW(KIDIA:KFDIA,:) = flux%lw_dn(KIDIA:KFDIA,:) - flux%lw_up(KIDIA:KFDIA,:)
+PFLUX_SW_CLEAR(KIDIA:KFDIA,:) &
+     &  = flux%sw_dn_clear(KIDIA:KFDIA,:) - flux%sw_up_clear(KIDIA:KFDIA,:)
+PFLUX_LW_CLEAR(KIDIA:KFDIA,:) &
+     &  = flux%lw_dn_clear(KIDIA:KFDIA,:) - flux%lw_up_clear(KIDIA:KFDIA,:)
+! Now the surface fluxes
+!PFLUX_SW_DN_SURF(KIDIA:KFDIA) = flux%sw_dn(KIDIA:KFDIA,KLEV+1)
+!PFLUX_LW_DN_SURF(KIDIA:KFDIA) = flux%lw_dn(KIDIA:KFDIA,KLEV+1)
+!PFLUX_SW_UP_SURF(KIDIA:KFDIA) = flux%sw_up(KIDIA:KFDIA,KLEV+1)
+!PFLUX_LW_UP_SURF(KIDIA:KFDIA) = flux%lw_up(KIDIA:KFDIA,KLEV+1)
+!PFLUX_SW_DN_CLEAR_SURF(KIDIA:KFDIA) = flux%sw_dn_clear(KIDIA:KFDIA,KLEV+1)
+!PFLUX_LW_DN_CLEAR_SURF(KIDIA:KFDIA) = flux%lw_dn_clear(KIDIA:KFDIA,KLEV+1)
+!PFLUX_SW_UP_CLEAR_SURF(KIDIA:KFDIA) = flux%sw_up_clear(KIDIA:KFDIA,KLEV+1)
+!PFLUX_LW_UP_CLEAR_SURF(KIDIA:KFDIA) = flux%lw_up_clear(KIDIA:KFDIA,KLEV+1)
+PFLUX_DIR(KIDIA:KFDIA) = flux%sw_dn_direct(KIDIA:KFDIA,KLEV+1)
+PFLUX_DIR_CLEAR(KIDIA:KFDIA) = flux%sw_dn_direct_clear(KIDIA:KFDIA,KLEV+1)
+PFLUX_DIR_INTO_SUN(KIDIA:KFDIA) = 0.0_JPRB
+WHERE (PMU0(KIDIA:KFDIA) > EPSILON(1.0_JPRB))
+  PFLUX_DIR_INTO_SUN(KIDIA:KFDIA) = PFLUX_DIR(KIDIA:KFDIA) / PMU0(KIDIA:KFDIA)
+END WHERE
+! Top-of-atmosphere downwelling flux
+!PFLUX_SW_DN_TOA(KIDIA:KFDIA) = flux%sw_dn(KIDIA:KFDIA,1)
+!PFLUX_SW_UP_TOA(KIDIA:KFDIA) = flux%sw_up(KIDIA:KFDIA,1)
+!PFLUX_LW_DN_TOA(KIDIA:KFDIA) = flux%lw_dn(KIDIA:KFDIA,1)
+!PFLUX_LW_UP_TOA(KIDIA:KFDIA) = flux%lw_up(KIDIA:KFDIA,1)
+!AI ATTENTION
+if (0.eq.1) then
+PFLUX_UV       (KIDIA:KFDIA) = 0.0_JPRB
+DO JBAND = 1,NWEIGHT_UV
+  PFLUX_UV(KIDIA:KFDIA) = PFLUX_UV(KIDIA:KFDIA) + WEIGHT_UV(JBAND) &
+       &  * flux%sw_dn_surf_band(IBAND_UV(JBAND),KIDIA:KFDIA)
+ENDDO
+! Compute photosynthetically active radiation similarly
+PFLUX_PAR      (KIDIA:KFDIA) = 0.0_JPRB
+PFLUX_PAR_CLEAR(KIDIA:KFDIA) = 0.0_JPRB
+DO JBAND = 1,NWEIGHT_PAR
+  PFLUX_PAR(KIDIA:KFDIA) = PFLUX_PAR(KIDIA:KFDIA) + WEIGHT_PAR(JBAND) &
+       &  * flux%sw_dn_surf_band(IBAND_PAR(JBAND),KIDIA:KFDIA)
+  PFLUX_PAR_CLEAR(KIDIA:KFDIA) = PFLUX_PAR_CLEAR(KIDIA:KFDIA) &
+       &  + WEIGHT_PAR(JBAND) &
+       &  * flux%sw_dn_surf_clear_band(IBAND_PAR(JBAND),KIDIA:KFDIA)
+ENDDO
+endif
+! Compute effective broadband emissivity
+ZBLACK_BODY_NET_LW = flux%lw_dn(KIDIA:KFDIA,KLEV+1) &
+     &  - RSIGMA*PTEMPERATURE_SKIN(KIDIA:KFDIA)**4
+PEMIS_OUT(KIDIA:KFDIA) = PEMIS(KIDIA:KFDIA)
+WHERE (ABS(ZBLACK_BODY_NET_LW) > 1.0E-5) 
+  PEMIS_OUT(KIDIA:KFDIA) = PFLUX_LW(KIDIA:KFDIA,KLEV+1) / ZBLACK_BODY_NET_LW
+END WHERE
+! Copy longwave derivatives
+! AI ATTENTION
+!IF (YRERAD%LAPPROXLWUPDATE) THEN
+IF (rad_config%do_lw_derivatives) THEN
+  PLWDERIVATIVE(KIDIA:KFDIA,:) = flux%lw_derivatives(KIDIA:KFDIA,:)
+END IF
+! Store the shortwave downwelling fluxes in each albedo band
+!AI ATTENTION
+!IF (YRERAD%LAPPROXSWUPDATE) THEN
+if (0.eq.1) then
+IF (rad_config%do_surface_sw_spectral_flux) THEN
+  PSWDIFFUSEBAND(KIDIA:KFDIA,:) = 0.0_JPRB
+  PSWDIRECTBAND (KIDIA:KFDIA,:) = 0.0_JPRB
+  DO JBAND = 1,rad_config%n_bands_sw
+    JB_ALBEDO = rad_config%i_albedo_from_band_sw(JBAND)
+    DO JLON = KIDIA,KFDIA
+      PSWDIFFUSEBAND(JLON,JB_ALBEDO) = PSWDIFFUSEBAND(JLON,JB_ALBEDO) &
+           &  + flux%sw_dn_surf_band(JBAND,JLON) &
+           &  - flux%sw_dn_direct_surf_band(JBAND,JLON)
+      PSWDIRECTBAND(JLON,JB_ALBEDO)  = PSWDIRECTBAND(JLON,JB_ALBEDO) &
+           &  + flux%sw_dn_direct_surf_band(JBAND,JLON)
+    ENDDO
+  ENDDO
+ENDIF
+endif
+
+print*,'********** DEALLOCATIONS ************************'
+CALL single_level%deallocate
+CALL thermodynamics%deallocate
+CALL gas%deallocate
+CALL cloud%deallocate
+CALL aerosol%deallocate
+CALL flux%deallocate
+
+IF (LHOOK) CALL DR_HOOK('RADIATION_SCHEME',1,ZHOOK_HANDLE)
+
+END SUBROUTINE RADIATION_SCHEME_S2
+
+end module interface_lmdz_ecrad
Index: /LMDZ6/trunk/libf/phylmd/ecrad/lmdz/radiation_setup.F90
===================================================================
--- /LMDZ6/trunk/libf/phylmd/ecrad/lmdz/radiation_setup.F90	(revision 4853)
+++ /LMDZ6/trunk/libf/phylmd/ecrad/lmdz/radiation_setup.F90	(revision 4853)
@@ -0,0 +1,150 @@
+MODULE RADIATION_SETUP
+
+! RADIATION_SETUP - Setting up modular radiation scheme
+!
+! AUTHOR
+! ------
+!   Robin Hogan, ECMWF
+!   Original: 2015-09-16
+!
+! MODIFICATIONS
+! -------------
+!   Abderrahmane Idelkadi LMD, juillet 2023
+!
+!-----------------------------------------------------------------------
+
+  USE PARKIND1,         ONLY : JPRB
+  USE radiation_config, ONLY : config_type, &
+       &                       ISolverMcICA, ISolverSpartacus, &
+       &                       ILiquidModelSlingo, ILiquidModelSOCRATES, &
+       &                       IIceModelFu, IIceModelBaran, IGasModelECCKD, &
+       &                       IGasModelIFSRRTMG, IOverlapExponentialRandom
+
+  USE radiation_interface,      ONLY : setup_radiation
+  USE setup_config_from_lmdz,   ONLY : driver_config_type
+
+  IMPLICIT NONE
+
+
+  ! Ultraviolet weightings
+  INTEGER         :: NWEIGHT_UV
+  INTEGER         :: IBAND_UV(100)
+  REAL(KIND=JPRB) :: WEIGHT_UV(100)
+  ! Photosynthetically active radiation weightings
+  INTEGER         :: NWEIGHT_PAR
+  INTEGER         :: IBAND_PAR(100)
+  REAL(KIND=JPRB) :: WEIGHT_PAR(100)
+
+  ! Background aerosol is specified in an ugly way: using the old
+  ! Tegen fields that are in terms of optical depth, and converted to
+  ! mass mixing ratio via the relevant mass-extinction coefficient
+  INTEGER, PARAMETER :: ITYPE_TROP_BG_AER = 8 ! hydrophobic organic
+  INTEGER, PARAMETER :: ITYPE_STRAT_BG_AER=12 ! non-absorbing sulphate
+  REAL(KIND=JPRB)    :: TROP_BG_AER_MASS_EXT
+  REAL(KIND=JPRB)    :: STRAT_BG_AER_MASS_EXT
+
+CONTAINS
+
+  ! This routine copies information between the LMDZ radiation
+  ! configuration (stored in global variables) and the radiation
+  ! configuration of the modular radiation scheme (stored in
+  ! rad_config).  The optional input logical LOUTPUT controls whether
+  ! to print lots of information during the setup stage (default is
+  ! no).
+! AI At the end of the routine, the parameters are read in namelist
+!    
+  SUBROUTINE SETUP_RADIATION_SCHEME(LOUTPUT,file_name,rad_config,driver_config)
+
+!    USE radiation_config, ONLY : config_type, &
+!        &                       ISolverMcICA, ISolverSpartacus, &
+!        &                       ILiquidModelSlingo, ILiquidModelSOCRATES, &
+!        &                       IIceModelFu, IIceModelBaran, &
+!        &                       IOverlapExponentialRandom
+    USE mod_phys_lmdz_para
+      
+    USE YOMHOOK,  ONLY : LHOOK, DR_HOOK
+    USE YOMLUN,   ONLY : NULOUT, NULERR
+    USE YOESRTWN, ONLY : NMPSRTM
+
+ !   USE radiation_interface,      ONLY : setup_radiation
+ !   USE setup_config_from_lmdz,   ONLY : driver_config_type
+
+    ! Whether or not to provide information on the radiation scheme
+    ! configuration
+    LOGICAL, INTENT(IN), OPTIONAL :: LOUTPUT
+
+    REAL(KIND=JPRB) :: ZHOOK_HANDLE
+
+    character(len=512) :: file_name
+
+    logical :: lprint_setp=.TRUE.
+
+    ! Store configuration information for the radiation scheme in a
+    ! global variable
+    type(config_type) :: rad_config
+    type(driver_config_type) :: driver_config
+
+    IF (LHOOK) CALL DR_HOOK('RADIATION_SETUP:SETUP_RADIATION_SCHEME',0,ZHOOK_HANDLE)
+
+    ! *** GENERAL SETUP ***
+
+    ! Configure verbosity of setup of radiation scheme
+ 
+    print*,'********** Dans radiation_setup *****************'
+
+! AI ATTENTION (parameters read in namelist file)
+!    file_name="namelist_ecrad"
+    call rad_config%read(file_name=file_name)
+    call driver_config%read(file_name)
+
+    ! Use configuration data to set-up radiation scheme, including
+    ! reading scattering datafiles
+    CALL setup_radiation(rad_config)
+
+    ! Populate the mapping between the 14 RRTM shortwave bands and the
+    ! 6 albedo inputs. The mapping according to the stated wavelength
+    ! ranges of the 6-band model does not match the hard-wired mapping
+    ! in NMPSRTM, but only the hard-wired values produce sensible
+    ! results...
+    ! Note that NMPSRTM(:)=(/  6, 6, 5, 5, 5, 5, 5, 4, 4, 3, 2, 2, 1, 6 /)
+! AI (6 albedo SW bands) 
+    call rad_config%define_sw_albedo_intervals(6, &
+       &  [0.25e-6_jprb, 0.44e-6_jprb, 0.69e-6_jprb, &
+       &   1.19e-6_jprb, 2.38e-6_jprb], [1,2,3,4,5,6])
+    ! Likewise between the 16 RRTM longwave bands and the 2 emissivity
+    ! inputs (info taken from rrtm_ecrt_140gp_mcica.F90) representing
+    ! outside and inside the window region of the spectrum
+!     rad_config%i_emiss_from_band_lw = (/ 1,1,1,1,1,2,2,2,1,1,1,1,1,1,1,1 /)
+! AI ATTENTION ?????
+!!    call rad_config%define_lw_emiss_intervals(3, &
+!!         &  (/ 8.0e-6_jprb,13.0e-6_jprb /),  (/ 1,2,1 /))
+
+!    ! Get spectral weightings for UV and PAR
+    call rad_config%get_sw_weights(0.2e-6_jprb, 0.4415e-6_jprb, &
+         &  NWEIGHT_UV, IBAND_UV, WEIGHT_UV, 'ultraviolet')
+    call rad_config%get_sw_weights(0.4e-6_jprb, 0.7e-6_jprb, &
+         &  NWEIGHT_PAR, IBAND_PAR, WEIGHT_PAR, &
+         &  'photosynthetically active radiation, PAR')
+
+     rad_config%i_aerosol_type_map(1:13) = (/ &
+           &  -1, &  ! Sea salt, size bin 1 (OPAC)
+           &  -2, &  ! Sea salt, size bin 2 (OPAC)
+           &  -3, &  ! Sea salt, size bin 3 (OPAC)
+           &  -4, &  ! Hydrophilic organic matter (OPAC)
+           &  -5, &  ! Ammonium sulphate (OPAC)
+           &  -6, &
+           &  -7, &
+           &   1, &
+           &   2, &
+           &   3, &
+           &  -8, &
+           &  -9, &
+           &   4 /)  ! Stratospheric sulphate (hand edited from OPAC)
+   rad_config%aerosol_optics_override_file_name = 'aerosol_optics_lmdz.nc'
+
+
+    IF (LHOOK) CALL DR_HOOK('RADIATION_SETUP:SETUP_RADIATION_SCHEME',1,ZHOOK_HANDLE)
+
+  END SUBROUTINE SETUP_RADIATION_SCHEME
+
+END MODULE RADIATION_SETUP
Index: /LMDZ6/trunk/libf/phylmd/ecrad/lmdz/readaerosol_optic_ecrad.F90
===================================================================
--- /LMDZ6/trunk/libf/phylmd/ecrad/lmdz/readaerosol_optic_ecrad.F90	(revision 4853)
+++ /LMDZ6/trunk/libf/phylmd/ecrad/lmdz/readaerosol_optic_ecrad.F90	(revision 4853)
@@ -0,0 +1,311 @@
+! $Id: readaerosol_optic_ecrad.F90
+!
+SUBROUTINE readaerosol_optic_ecrad(debut, aerosol_couple, ok_alw, ok_volcan, &
+     flag_aerosol, flag_bc_internal_mixture, itap, rjourvrai, &
+     pdtphys, pplay, paprs, t_seri, rhcl, presnivs, &
+     tr_seri, mass_solu_aero, mass_solu_aero_pi) 
+!     tau_aero, piz_aero, cg_aero, &
+!     tausum_aero, drytausum_aero, tau3d_aero )
+
+  ! This routine will :
+  ! 1) recevie the aerosols(already read and interpolated) corresponding to flag_aerosol
+  ! 2) calculate the optical properties for the aerosols
+  !
+
+  USE dimphy
+  USE aero_mod
+  USE phys_local_var_mod, only: sconcso4,sconcno3,sconcoa,sconcbc,sconcss,sconcdust, &
+       concso4,concno3,concoa,concbc,concss,concdust,loadso4,loadoa,loadbc,loadss,loaddust, &
+       loadno3,load_tmp1,load_tmp2,load_tmp3,load_tmp4,load_tmp5,load_tmp6,load_tmp7, & 
+       load_tmp8,load_tmp9,load_tmp10,m_allaer
+
+  USE infotrac_phy, ONLY: tracers, nqtot, nbtr
+  USE YOMCST
+
+  IMPLICIT NONE
+
+  include "clesphys.h"
+
+  ! Input arguments
+  !****************************************************************************************
+  LOGICAL, INTENT(IN)                      :: debut
+  LOGICAL, INTENT(IN)                      :: aerosol_couple
+  LOGICAL, INTENT(IN)                      :: ok_alw
+  LOGICAL, INTENT(IN)                      :: ok_volcan
+  INTEGER, INTENT(IN)                      :: flag_aerosol
+  LOGICAL, INTENT(IN)                      :: flag_bc_internal_mixture
+  INTEGER, INTENT(IN)                      :: itap
+  REAL, INTENT(IN)                         :: rjourvrai
+  REAL, INTENT(IN)                         :: pdtphys
+  REAL, DIMENSION(klon,klev), INTENT(IN)   :: pplay
+  REAL, DIMENSION(klon,klev+1), INTENT(IN) :: paprs
+  REAL, DIMENSION(klon,klev), INTENT(IN)   :: t_seri
+  REAL, DIMENSION(klon,klev), INTENT(IN)   :: rhcl   ! humidite relative ciel clair
+  REAL, DIMENSION(klev), INTENT(IN)        :: presnivs
+  REAL, DIMENSION(klon,klev,nbtr), INTENT(IN) :: tr_seri ! concentration tracer
+
+  ! Output arguments
+  !****************************************************************************************
+  REAL, DIMENSION(klon,klev), INTENT(OUT)     :: mass_solu_aero    ! Total mass for all soluble aerosols
+  REAL, DIMENSION(klon,klev), INTENT(OUT)     :: mass_solu_aero_pi !     -"-     preindustrial values
+!  REAL, DIMENSION(klon,klev,2,NSW), INTENT(OUT) :: tau_aero    ! Aerosol optical thickness
+!  REAL, DIMENSION(klon,klev,2,NSW), INTENT(OUT) :: piz_aero    ! Single scattering albedo aerosol
+!  REAL, DIMENSION(klon,klev,2,NSW), INTENT(OUT) :: cg_aero     ! asymmetry parameter aerosol
+!  REAL, DIMENSION(klon,nwave,naero_tot), INTENT(OUT)       :: tausum_aero
+!  REAL, DIMENSION(klon,naero_tot), INTENT(OUT)             :: drytausum_aero
+!  REAL, DIMENSION(klon,klev,nwave,naero_tot), INTENT(OUT)  :: tau3d_aero
+
+  ! Local variables
+  !****************************************************************************************
+  REAL, DIMENSION(klon)        :: aerindex      ! POLDER aerosol index 
+  REAL, DIMENSION(klon,klev)   :: sulfacc       ! SO4 accumulation concentration [ug/m3]
+  REAL, DIMENSION(klon,klev)   :: sulfcoarse    ! SO4 coarse concentration [ug/m3]
+  REAL, DIMENSION(klon,klev)   :: bcsol         ! BC soluble concentration [ug/m3]
+  REAL, DIMENSION(klon,klev)   :: bcins         ! BC insoluble concentration [ug/m3]
+  REAL, DIMENSION(klon,klev)   :: pomsol        ! POM soluble concentration [ug/m3]
+  REAL, DIMENSION(klon,klev)   :: pomins        ! POM insoluble concentration [ug/m3]
+  REAL, DIMENSION(klon,klev)   :: cidust        ! DUST aerosol concentration  [ug/m3]
+  REAL, DIMENSION(klon,klev)   :: sscoarse      ! SS Coarse concentration [ug/m3]
+  REAL, DIMENSION(klon,klev)   :: sssupco       ! SS Super Coarse concentration [ug/m3]
+  REAL, DIMENSION(klon,klev)   :: ssacu         ! SS Acumulation concentration [ug/m3]
+  REAL, DIMENSION(klon,klev)   :: nitracc       ! nitrate accumulation concentration [ug/m3]
+  REAL, DIMENSION(klon,klev)   :: nitrcoarse    ! nitrate coarse concentration [ug/m3]
+  REAL, DIMENSION(klon,klev)   :: nitrinscoarse ! nitrate insoluble coarse concentration [ug/m3]
+  REAL, DIMENSION(klon,klev)   :: sulfacc_pi
+  REAL, DIMENSION(klon,klev)   :: sulfcoarse_pi
+  REAL, DIMENSION(klon,klev)   :: bcsol_pi
+  REAL, DIMENSION(klon,klev)   :: bcins_pi
+  REAL, DIMENSION(klon,klev)   :: pomsol_pi
+  REAL, DIMENSION(klon,klev)   :: pomins_pi
+  REAL, DIMENSION(klon,klev)   :: cidust_pi
+  REAL, DIMENSION(klon,klev)   :: sscoarse_pi
+  REAL, DIMENSION(klon,klev)   :: sssupco_pi
+  REAL, DIMENSION(klon,klev)   :: ssacu_pi
+  REAL, DIMENSION(klon,klev)   :: nitracc_pi
+  REAL, DIMENSION(klon,klev)   :: nitrcoarse_pi
+  REAL, DIMENSION(klon,klev)   :: nitrinscoarse_pi
+  REAL, DIMENSION(klon,klev)   :: pdel, zrho
+!  REAL, DIMENSION(klon,klev,naero_tot) :: m_allaer
+  REAL, DIMENSION(klon,klev,naero_tot) :: m_allaer_pi !RAF  
+
+  integer :: id_ASBCM, id_ASPOMM, id_ASSO4M, id_ASMSAM, id_CSSO4M, id_CSMSAM, id_SSSSM
+  integer :: id_CSSSM, id_ASSSM, id_CIDUSTM, id_AIBCM, id_AIPOMM, id_ASNO3M, id_CSNO3M, id_CINO3M
+  INTEGER :: k, i, iq, itr
+
+  !--air density
+  zrho(:,:)=pplay(:,:)/t_seri(:,:)/RD                     !--kg/m3
+
+  !****************************************************************************************
+  ! 1) Get aerosol mass
+  !    
+  !****************************************************************************************
+  !
+  !
+  IF (aerosol_couple) THEN   !--we get aerosols from tr_seri array from INCA
+     !
+     !--copy fields from INCA tr_seri 
+     !--convert to ug m-3 unit for consistency with offline fields
+     !
+     itr = 0
+     DO iq = 1,nqtot
+        IF(.NOT. tracers(iq)%isInPhysics) CYCLE
+        itr = itr+1
+        SELECT CASE(trim(tracers(iq)%name))
+           CASE ("ASBCM");  id_ASBCM  = itr
+           CASE ("ASPOMM"); id_ASPOMM = itr
+           CASE ("ASSO4M"); id_ASSO4M = itr
+           CASE ("ASMSAM"); id_ASMSAM = itr
+           CASE ("CSSO4M"); id_CSSO4M = itr
+           CASE ("CSMSAM"); id_CSMSAM = itr
+           CASE ("SSSSM");  id_SSSSM  = itr
+           CASE ("CSSSM");  id_CSSSM  = itr
+           CASE ("ASSSM");  id_ASSSM  = itr
+           CASE ("CIDUSTM");id_CIDUSTM= itr
+           CASE ("AIBCM");  id_AIBCM  = itr
+           CASE ("AIPOMM"); id_AIPOMM = itr
+           CASE ("ASNO3M"); id_ASNO3M = itr
+           CASE ("CSNO3M"); id_CSNO3M = itr
+           CASE ("CINO3M"); id_CINO3M = itr
+        END SELECT
+     END DO
+
+     bcsol(:,:)        =   tr_seri(:,:,id_ASBCM)                         *zrho(:,:)*1.e9  ! ASBCM
+     pomsol(:,:)       =   tr_seri(:,:,id_ASPOMM)                        *zrho(:,:)*1.e9  ! ASPOMM
+     sulfacc(:,:)      =  (tr_seri(:,:,id_ASSO4M)+tr_seri(:,:,id_ASMSAM))*zrho(:,:)*1.e9  ! ASSO4M (=SO4) + ASMSAM (=MSA)
+     sulfcoarse(:,:)   =  (tr_seri(:,:,id_CSSO4M)+tr_seri(:,:,id_CSMSAM))*zrho(:,:)*1.e9  ! CSSO4M (=SO4) + CSMSAM (=MSA)
+     sssupco(:,:)      =   tr_seri(:,:,id_SSSSM)                         *zrho(:,:)*1.e9  ! SSSSM
+     sscoarse(:,:)     =   tr_seri(:,:,id_CSSSM)                         *zrho(:,:)*1.e9  ! CSSSM
+     ssacu(:,:)        =   tr_seri(:,:,id_ASSSM)                         *zrho(:,:)*1.e9  ! ASSSM
+     cidust(:,:)       =   tr_seri(:,:,id_CIDUSTM)                       *zrho(:,:)*1.e9  ! CIDUSTM
+     bcins(:,:)        =   tr_seri(:,:,id_AIBCM)                         *zrho(:,:)*1.e9  ! AIBCM
+     pomins(:,:)       =   tr_seri(:,:,id_AIPOMM)                        *zrho(:,:)*1.e9  ! AIPOMM
+     nitracc(:,:)      =   tr_seri(:,:,id_ASNO3M)                        *zrho(:,:)*1.e9  ! ASNO3M
+     nitrcoarse(:,:)   =   tr_seri(:,:,id_CSNO3M)                        *zrho(:,:)*1.e9  ! CSNO3M
+     nitrinscoarse(:,:)=   tr_seri(:,:,id_CINO3M)                        *zrho(:,:)*1.e9  ! CINO3M
+     !
+     bcsol_pi(:,:)        =   0.0 ! ASBCM pre-ind
+     pomsol_pi(:,:)       =   0.0 ! ASPOMM pre-ind
+     sulfacc_pi(:,:)      =   0.0 ! ASSO4M (=SO4) + ASMSAM (=MSA) pre-ind
+     sulfcoarse_pi(:,:)   =   0.0 ! CSSO4M (=SO4) + CSMSAM (=MSA) pre-ind
+     sssupco_pi(:,:)      =   0.0 ! SSSSM pre-ind
+     sscoarse_pi(:,:)     =   0.0 ! CSSSM pre-ind
+     ssacu_pi(:,:)        =   0.0 ! ASSSM pre-ind
+     cidust_pi(:,:)       =   0.0 ! CIDUSTM pre-ind
+     bcins_pi(:,:)        =   0.0 ! AIBCM pre-ind
+     pomins_pi(:,:)       =   0.0 ! AIPOMM pre-ind
+     nitracc_pi(:,:)      =   0.0 ! ASNO3M pre-ind
+     nitrcoarse_pi(:,:)   =   0.0 ! CSNO3M pre-ind
+     nitrinscoarse_pi(:,:)=   0.0 ! CINO3M
+     !
+  ELSE !--not aerosol_couple
+     !
+     ! Read and interpolate sulfate
+     IF ( flag_aerosol .EQ. 1 .OR. flag_aerosol .EQ. 6 .OR. flag_aerosol .EQ. 7 ) THEN 
+
+        CALL readaerosol_interp(id_ASSO4M_phy, itap, pdtphys, rjourvrai, debut, pplay, paprs, t_seri, sulfacc, sulfacc_pi,loadso4)
+     ELSE
+        sulfacc(:,:) = 0. ; sulfacc_pi(:,:) = 0.
+        loadso4=0.
+     ENDIF
+
+     ! Read and interpolate bcsol and bcins
+     IF ( flag_aerosol .EQ. 2 .OR. flag_aerosol .EQ. 6 .OR. flag_aerosol .EQ. 7 ) THEN 
+
+        ! Get bc aerosol distribution 
+        CALL readaerosol_interp(id_ASBCM_phy, itap, pdtphys, rjourvrai, debut, pplay, paprs, t_seri, bcsol, bcsol_pi, load_tmp1 )
+        CALL readaerosol_interp(id_AIBCM_phy, itap, pdtphys, rjourvrai, debut, pplay, paprs, t_seri, bcins, bcins_pi, load_tmp2 )
+        loadbc(:)=load_tmp1(:)+load_tmp2(:)
+     ELSE
+        bcsol(:,:) = 0. ; bcsol_pi(:,:) = 0.
+        bcins(:,:) = 0. ; bcins_pi(:,:) = 0.
+        loadbc=0.
+     ENDIF
+
+     ! Read and interpolate pomsol and pomins
+     IF ( flag_aerosol .EQ. 3 .OR. flag_aerosol .EQ. 6 .OR. flag_aerosol .EQ. 7 ) THEN
+
+        CALL readaerosol_interp(id_ASPOMM_phy, itap, pdtphys, rjourvrai, debut, pplay, paprs, t_seri, pomsol, pomsol_pi, load_tmp3)
+        CALL readaerosol_interp(id_AIPOMM_phy, itap, pdtphys, rjourvrai, debut, pplay, paprs, t_seri, pomins, pomins_pi, load_tmp4)
+        loadoa(:)=load_tmp3(:)+load_tmp4(:)
+     ELSE
+        pomsol(:,:) = 0. ; pomsol_pi(:,:) = 0.
+        pomins(:,:) = 0. ; pomins_pi(:,:) = 0.
+        loadoa=0.
+     ENDIF
+
+     ! Read and interpolate csssm, ssssm, assssm
+     IF (flag_aerosol .EQ. 4 .OR. flag_aerosol .EQ. 6 .OR. flag_aerosol .EQ. 7 ) THEN 
+
+        CALL readaerosol_interp(id_SSSSM_phy ,itap, pdtphys,rjourvrai, &
+        debut, pplay, paprs, t_seri, sssupco, sssupco_pi, load_tmp5) 
+        CALL readaerosol_interp(id_CSSSM_phy ,itap, pdtphys,rjourvrai, &
+        debut, pplay, paprs, t_seri, sscoarse,sscoarse_pi, load_tmp6) 
+        CALL readaerosol_interp(id_ASSSM_phy ,itap, pdtphys,rjourvrai, &
+        debut, pplay, paprs, t_seri, ssacu, ssacu_pi, load_tmp7) 
+        loadss(:)=load_tmp5(:)+load_tmp6(:)+load_tmp7(:)
+     ELSE
+        sscoarse(:,:) = 0. ; sscoarse_pi(:,:) = 0. 
+        ssacu(:,:)    = 0. ; ssacu_pi(:,:) = 0. 
+        sssupco(:,:)  = 0. ; sssupco_pi = 0. 
+        loadss=0.
+     ENDIF
+
+     ! Read and interpolate cidustm
+     IF (flag_aerosol .EQ. 5 .OR. flag_aerosol .EQ. 6 .OR. flag_aerosol .EQ. 7 ) THEN 
+
+        CALL readaerosol_interp(id_CIDUSTM_phy, itap, pdtphys, rjourvrai, debut, pplay, paprs, t_seri, cidust, cidust_pi, loaddust) 
+
+     ELSE
+        cidust(:,:) = 0. ; cidust_pi(:,:) = 0. 
+        loaddust=0.
+     ENDIF
+     !
+     ! Read and interpolate asno3m, csno3m, cino3m
+     IF (flag_aerosol .EQ. 6 .OR. flag_aerosol .EQ. 7 ) THEN 
+
+        CALL readaerosol_interp(id_ASNO3M_phy, itap, pdtphys, rjourvrai, & 
+        debut, pplay, paprs, t_seri, nitracc, nitracc_pi, load_tmp8) 
+        CALL readaerosol_interp(id_CSNO3M_phy, itap, pdtphys, rjourvrai, & 
+        debut, pplay, paprs, t_seri, nitrcoarse, nitrcoarse_pi, load_tmp9) 
+        CALL readaerosol_interp(id_CINO3M_phy, itap, pdtphys, rjourvrai, & 
+        debut, pplay, paprs, t_seri, nitrinscoarse, nitrinscoarse_pi, load_tmp10) 
+        loadno3(:)=load_tmp8(:)+load_tmp9(:)+load_tmp10(:)
+
+     ELSE
+        nitracc(:,:)         =   0.0 ; nitracc_pi(:,:)      =   0.0 
+        nitrcoarse(:,:)      =   0.0 ; nitrcoarse_pi(:,:)   =   0.0
+        nitrinscoarse(:,:)   =   0.0 ; nitrinscoarse_pi(:,:)=   0.0
+        loadno3(:)=0.0
+     ENDIF
+     !
+     ! CSSO4M is set to 0 as not reliable
+     sulfcoarse(:,:)      =   0.0 ! CSSO4M (=SO4) + CSMSAM (=MSA) 
+     sulfcoarse_pi(:,:)   =   0.0 ! CSSO4M (=SO4) + CSMSAM (=MSA) pre-ind
+
+  ENDIF !--not aerosol_couple
+
+  !
+  ! Store all aerosols mixing ratios in one variable for radiation scheme (unit kg/kg for ECRAD)
+  ! present-day values
+  m_allaer(:,:,id_ASBCM_phy)  = bcsol(:,:)        /1.e9/zrho(:,:) ! ASBCM
+  m_allaer(:,:,id_ASPOMM_phy) = pomsol(:,:)       /1.e9/zrho(:,:) ! ASPOMM
+  m_allaer(:,:,id_ASSO4M_phy) = sulfacc(:,:)      /1.e9/zrho(:,:) ! ASSO4M (= SO4) 
+  m_allaer(:,:,id_CSSO4M_phy) = sulfcoarse(:,:)   /1.e9/zrho(:,:) ! CSSO4M 
+  m_allaer(:,:,id_SSSSM_phy)  = sssupco(:,:)      /1.e9/zrho(:,:) ! SSSSM
+  m_allaer(:,:,id_CSSSM_phy)  = sscoarse(:,:)     /1.e9/zrho(:,:) ! CSSSM
+  m_allaer(:,:,id_ASSSM_phy)  = ssacu(:,:)        /1.e9/zrho(:,:) ! ASSSM
+  m_allaer(:,:,id_CIDUSTM_phy)= cidust(:,:)       /1.e9/zrho(:,:) ! CIDUSTM
+  m_allaer(:,:,id_AIBCM_phy)  = bcins(:,:)        /1.e9/zrho(:,:) ! AIBCM
+  m_allaer(:,:,id_ASNO3M_phy) = nitracc(:,:)      /1.e9/zrho(:,:) ! ASNO3M
+  m_allaer(:,:,id_CSNO3M_phy) = nitrcoarse(:,:)   /1.e9/zrho(:,:) ! CSNO3M
+  m_allaer(:,:,id_CINO3M_phy) = nitrinscoarse(:,:)/1.e9/zrho(:,:) ! CINO3M
+  m_allaer(:,:,id_AIPOMM_phy) = pomins(:,:)       /1.e9/zrho(:,:) ! AIPOMM
+  m_allaer(:,:,id_STRAT_phy)  = 0.0
+
+  !  pre-industrial (pi) values
+  m_allaer_pi(:,:,id_ASBCM_phy)  = bcsol_pi(:,:)        /1.e9/zrho(:,:) ! ASBCM pre-ind
+  m_allaer_pi(:,:,id_ASPOMM_phy) = pomsol_pi(:,:)       /1.e9/zrho(:,:) ! ASPOMM pre-ind
+  m_allaer_pi(:,:,id_ASSO4M_phy) = sulfacc_pi(:,:)      /1.e9/zrho(:,:) ! ASSO4M (= SO4) pre-ind
+  m_allaer_pi(:,:,id_CSSO4M_phy) = sulfcoarse_pi(:,:)   /1.e9/zrho(:,:) ! CSSO4M pre-ind
+  m_allaer_pi(:,:,id_SSSSM_phy)  = sssupco_pi(:,:)      /1.e9/zrho(:,:) ! SSSSM pre-ind
+  m_allaer_pi(:,:,id_CSSSM_phy)  = sscoarse_pi(:,:)     /1.e9/zrho(:,:) ! CSSSM pre-ind
+  m_allaer_pi(:,:,id_ASSSM_phy)  = ssacu_pi(:,:)        /1.e9/zrho(:,:) ! ASSSM pre-ind
+  m_allaer_pi(:,:,id_CIDUSTM_phy)= cidust_pi(:,:)       /1.e9/zrho(:,:) ! CIDUSTM pre-ind
+  m_allaer_pi(:,:,id_AIBCM_phy)  = bcins_pi(:,:)        /1.e9/zrho(:,:) ! AIBCM pre-ind
+  m_allaer_pi(:,:,id_ASNO3M_phy) = nitracc_pi(:,:)      /1.e9/zrho(:,:) ! ASNO3M pre-ind
+  m_allaer_pi(:,:,id_CSNO3M_phy) = nitrcoarse_pi(:,:)   /1.e9/zrho(:,:) ! CSNO3M pre-ind
+  m_allaer_pi(:,:,id_CINO3M_phy) = nitrinscoarse_pi(:,:)/1.e9/zrho(:,:) ! CINO3M pre-ind
+  m_allaer_pi(:,:,id_AIPOMM_phy) = pomins_pi(:,:)       /1.e9/zrho(:,:) ! AIPOMM pre-ind
+  m_allaer_pi(:,:,id_STRAT_phy)  = 0.0
+
+  !
+  ! Calculate the total mass of all soluble aersosols (in unit ug /m3)
+  ! to be revisited for AR6
+  mass_solu_aero(:,:)    = sulfacc(:,:)    + bcsol(:,:)    + pomsol(:,:)    + nitracc(:,:)    + ssacu(:,:)
+  mass_solu_aero_pi(:,:) = sulfacc_pi(:,:) + bcsol_pi(:,:) + pomsol_pi(:,:) + nitracc_pi(:,:) + ssacu_pi(:,:)
+
+  !****************************************************************************************
+  ! 2) Calculate optical properties for the aerosols
+  !
+  !****************************************************************************************
+  DO k = 1, klev
+     DO i = 1, klon
+        pdel(i,k) = paprs(i,k) - paprs (i,k+1)
+     ENDDO
+  ENDDO
+
+  ! Diagnostics calculation for CMIP5 protocol unit (in unit kg/m3)
+  sconcso4(:)  =m_allaer(:,1,id_ASSO4M_phy)*1.e-9
+  sconcno3(:)  =(m_allaer(:,1,id_ASNO3M_phy)+m_allaer(:,1,id_CSNO3M_phy)+m_allaer(:,1,id_CINO3M_phy))*1.e-9
+  sconcoa(:)   =(m_allaer(:,1,id_ASPOMM_phy)+m_allaer(:,1,id_AIPOMM_phy))*1.e-9
+  sconcbc(:)   =(m_allaer(:,1,id_ASBCM_phy)+m_allaer(:,1,id_AIBCM_phy))*1.e-9
+  sconcss(:)   =(m_allaer(:,1,id_ASSSM_phy)+m_allaer(:,1,id_CSSSM_phy)+m_allaer(:,1,id_SSSSM_phy))*1.e-9
+  sconcdust(:) =m_allaer(:,1,id_CIDUSTM_phy)*1.e-9
+  concso4(:,:) =m_allaer(:,:,id_ASSO4M_phy)*1.e-9
+  concno3(:,:) =(m_allaer(:,:,id_ASNO3M_phy)+m_allaer(:,:,id_CSNO3M_phy)+m_allaer(:,:,id_CINO3M_phy))*1.e-9
+  concoa(:,:)  =(m_allaer(:,:,id_ASPOMM_phy)+m_allaer(:,:,id_AIPOMM_phy))*1.e-9
+  concbc(:,:)  =(m_allaer(:,:,id_ASBCM_phy)+m_allaer(:,:,id_AIBCM_phy))*1.e-9
+  concss(:,:)  =(m_allaer(:,:,id_ASSSM_phy)+m_allaer(:,:,id_CSSSM_phy)+m_allaer(:,:,id_SSSSM_phy))*1.e-9
+  concdust(:,:)=m_allaer(:,:,id_CIDUSTM_phy)*1.e-9
+
+END SUBROUTINE readaerosol_optic_ecrad
Index: /LMDZ6/trunk/libf/phylmd/ecrad/lmdz/readaerosolstrato_ecrad.F90
===================================================================
--- /LMDZ6/trunk/libf/phylmd/ecrad/lmdz/readaerosolstrato_ecrad.F90	(revision 4853)
+++ /LMDZ6/trunk/libf/phylmd/ecrad/lmdz/readaerosolstrato_ecrad.F90	(revision 4853)
@@ -0,0 +1,564 @@
+!
+! $Id: readaerosolstrato_ecrad.F90 tlurton $
+!
+SUBROUTINE readaerosolstrato_ecrad(config, debut, ok_volcan)
+
+    USE netcdf95, ONLY: nf95_close, nf95_gw_var, nf95_inq_dimid, & 
+                        nf95_inq_varid, nf95_open
+    USE netcdf, ONLY: nf90_get_var, nf90_noerr, nf90_nowrite
+
+    USE phys_cal_mod, ONLY : mth_cur
+    USE mod_grid_phy_lmdz, ONLY: nbp_lon, nbp_lat, klon_glo, grid2dTo1d_glo, grid_type, unstructured
+    USE mod_phys_lmdz_mpi_data
+    USE mod_phys_lmdz_omp_data
+    USE mod_phys_lmdz_para 
+    USE phys_state_var_mod
+    USE phys_local_var_mod
+!    USE physiq_mod, ONLY : ok_volcan
+    USE aero_mod
+    USE dimphy
+!    USE YOERAD
+    USE radiation_config, ONLY : config_type
+    USE YOMCST
+#ifdef CPP_XIOS
+    USE xios
+#endif
+
+    IMPLICIT NONE
+
+    INCLUDE "clesphys.h"
+
+    CHARACTER (len = 80) :: abort_message
+    CHARACTER (LEN=20) :: modname = 'readaerosolstrato_ecrad'
+
+! Variable input
+    LOGICAL, INTENT(IN) ::  debut
+    LOGICAL, INTENT(IN) ::  ok_volcan !activate volcanic diags
+
+! Variables locales
+    INTEGER n_lat   ! number of latitudes in the input data
+    INTEGER n_lon   ! number of longitudes
+    INTEGER n_lev   ! number of levels in the input data
+    INTEGER n_month ! number of months in the input data
+    INTEGER n_wav   ! number of wavelengths in the input data
+    REAL, ALLOCATABLE:: latitude(:)
+    REAL, ALLOCATABLE:: time(:)
+    REAL, ALLOCATABLE:: lev(:)
+    REAL, ALLOCATABLE:: wav(:)
+    INTEGER i,k,wave,band
+    INTEGER, SAVE :: mth_pre=1
+!$OMP THREADPRIVATE(mth_pre)
+
+    REAL, ALLOCATABLE, DIMENSION(:,:,:), SAVE :: tau_aer_strat
+    REAL, ALLOCATABLE, DIMENSION(:,:,:), SAVE :: piz_aer_strat
+    REAL, ALLOCATABLE, DIMENSION(:,:,:), SAVE :: cg_aer_strat
+    REAL, ALLOCATABLE, DIMENSION(:,:,:), SAVE :: taulw_aer_strat
+! add ThL
+    REAL, ALLOCATABLE, DIMENSION(:,:,:), SAVE :: pizlw_aer_strat
+    REAL, ALLOCATABLE, DIMENSION(:,:,:), SAVE :: cglw_aer_strat
+! end add ThL
+! mod ThL
+!$OMP THREADPRIVATE(tau_aer_strat,piz_aer_strat,cg_aer_strat,taulw_aer_strat,pizlw_aer_strat,cglw_aer_strat)
+! end mod ThL
+
+! Champs reconstitues
+    REAL, ALLOCATABLE:: tauaerstrat(:, :, :, :)
+    REAL, ALLOCATABLE:: pizaerstrat(:, :, :, :)
+    REAL, ALLOCATABLE:: cgaerstrat(:, :, :, :)
+    REAL, ALLOCATABLE:: taulwaerstrat(:, :, :, :)
+! add ThL
+    REAL, ALLOCATABLE:: pizlwaerstrat(:, :, :, :)
+    REAL, ALLOCATABLE:: cglwaerstrat(:, :, :, :)
+! end add ThL
+
+    REAL, ALLOCATABLE:: tauaerstrat_mois(:, :, :, :)
+    REAL, ALLOCATABLE:: pizaerstrat_mois(:, :, :, :)
+    REAL, ALLOCATABLE:: cgaerstrat_mois(:, :, :, :)
+    REAL, ALLOCATABLE:: taulwaerstrat_mois(:, :, :, :)
+! add ThL
+    REAL, ALLOCATABLE:: pizlwaerstrat_mois(:, :, :, :)
+    REAL, ALLOCATABLE:: cglwaerstrat_mois(:, :, :, :)
+! end add ThL
+
+    REAL, ALLOCATABLE:: tauaerstrat_mois_glo(:, :, :)
+    REAL, ALLOCATABLE:: pizaerstrat_mois_glo(:, :, :)
+    REAL, ALLOCATABLE:: cgaerstrat_mois_glo(:, :, :)
+    REAL, ALLOCATABLE:: taulwaerstrat_mois_glo(:, :, :)
+! add ThL
+    REAL, ALLOCATABLE:: pizlwaerstrat_mois_glo(:, :, :)
+    REAL, ALLOCATABLE:: cglwaerstrat_mois_glo(:, :, :) 
+! end add ThL
+    REAL, ALLOCATABLE:: tauaerstrat_mpi(:, :, :)
+    REAL, ALLOCATABLE:: pizaerstrat_mpi(:, :, :)
+    REAL, ALLOCATABLE:: cgaerstrat_mpi(:, :, :)
+    REAL, ALLOCATABLE:: taulwaerstrat_mpi(:, :, :)
+! add ThL
+    REAL, ALLOCATABLE:: pizlwaerstrat_mpi(:, :, :)
+    REAL, ALLOCATABLE:: cglwaerstrat_mpi(:, :, :)
+! end add ThL
+
+! For NetCDF:
+    INTEGER ncid_in  ! IDs for input files
+    INTEGER varid, ncerr
+
+    TYPE(config_type), INTENT(IN) :: config
+
+!--------------------------------------------------------
+
+    IF (.not.ALLOCATED(tau_aer_strat)) ALLOCATE(tau_aer_strat(klon,klev,config%n_bands_sw))
+    IF (.not.ALLOCATED(piz_aer_strat)) ALLOCATE(piz_aer_strat(klon,klev,config%n_bands_sw))
+    IF (.not.ALLOCATED(cg_aer_strat))  ALLOCATE(cg_aer_strat(klon,klev,config%n_bands_sw))
+
+    IF (.not.ALLOCATED(taulw_aer_strat)) ALLOCATE(taulw_aer_strat(klon,klev,config%n_bands_lw))
+! add ThL    
+    IF (.not.ALLOCATED(pizlw_aer_strat)) ALLOCATE(pizlw_aer_strat(klon,klev,config%n_bands_lw))
+    IF (.not.ALLOCATED(cglw_aer_strat)) ALLOCATE(cglw_aer_strat(klon,klev,config%n_bands_lw))
+! end add ThL
+
+!--we only read monthly strat aerosol data
+    IF (debut.OR.mth_cur.NE.mth_pre) THEN
+
+!--only root reads the data
+      IF (is_mpi_root.AND.is_omp_root) THEN
+
+!--check mth_cur
+        IF (mth_cur.LT.1.OR.mth_cur.GT.12) THEN
+          print *,'probleme avec le mois dans readaerosolstrat =', mth_cur
+        ENDIF
+
+!--initialize n_lon as input data is 2D (lat-alt) only
+        n_lon = nbp_lon
+
+!--Starts with SW optical properties
+
+        CALL nf95_open("tauswstrat.2D.nc", nf90_nowrite, ncid_in)
+
+        CALL nf95_inq_varid(ncid_in, "LEV", varid)
+        CALL nf95_gw_var(ncid_in, varid, lev)
+        n_lev = size(lev)
+        IF (n_lev.NE.klev) THEN 
+           abort_message='Le nombre de niveaux n est pas egal a klev'
+           CALL abort_physic(modname,abort_message,1)
+        ENDIF
+
+        CALL nf95_inq_varid(ncid_in, "LAT", varid)
+        CALL nf95_gw_var(ncid_in, varid, latitude)
+        n_lat = size(latitude)
+
+        IF (grid_type/=unstructured) THEN
+           IF (n_lat.NE.nbp_lat) THEN 
+             print *, 'latitude=', n_lat, nbp_lat
+             abort_message='Le nombre de lat n est pas egal a nbp_lat'
+             CALL abort_physic(modname,abort_message,1)
+           ENDIF
+        ENDIF
+
+        CALL nf95_inq_varid(ncid_in, "TIME", varid)
+        CALL nf95_gw_var(ncid_in, varid, time)
+        n_month = size(time)
+        IF (n_month.NE.12) THEN 
+           abort_message='Le nombre de month n est pas egal a 12'
+           CALL abort_physic(modname,abort_message,1)
+        ENDIF
+
+        CALL nf95_inq_varid(ncid_in, "WAV", varid)
+        CALL nf95_gw_var(ncid_in, varid, wav)
+        n_wav = size(wav)
+        print *, 'WAV aerosol strato=', n_wav, wav
+!        IF (n_wav.NE.config%n_bands_sw) THEN 
+!           abort_message='Le nombre de wav n est pas egal a config%n_bands_sw'
+!           CALL abort_physic(modname,abort_message,1)
+!        ENDIF
+
+        ALLOCATE(tauaerstrat(n_lat, n_lev, n_wav, n_month))
+        ALLOCATE(pizaerstrat(n_lat, n_lev, n_wav, n_month))
+        ALLOCATE(cgaerstrat(n_lat, n_lev, n_wav, n_month))
+
+!--reading stratospheric aerosol tau per layer
+        CALL nf95_inq_varid(ncid_in, "TAU_SUN", varid)
+        ncerr = nf90_get_var(ncid_in, varid, tauaerstrat)
+        print *,'code erreur readaerosolstrato=', ncerr, varid
+
+!--reading stratospheric aerosol omega per layer
+        CALL nf95_inq_varid(ncid_in, "OME_SUN", varid)
+        ncerr = nf90_get_var(ncid_in, varid, pizaerstrat)
+        print *,'code erreur readaerosolstrato=', ncerr, varid
+
+!--reading stratospheric aerosol g per layer
+        CALL nf95_inq_varid(ncid_in, "GGG_SUN", varid)
+        ncerr = nf90_get_var(ncid_in, varid, cgaerstrat)
+        print *,'code erreur readaerosolstrato sw=', ncerr, varid
+
+        CALL nf95_close(ncid_in)
+
+       
+        IF (grid_type/=unstructured) THEN
+          ALLOCATE(tauaerstrat_mois(n_lon, n_lat, n_lev, n_wav))
+          ALLOCATE(pizaerstrat_mois(n_lon, n_lat, n_lev, n_wav))
+          ALLOCATE(cgaerstrat_mois(n_lon, n_lat, n_lev, n_wav))
+
+          ALLOCATE(tauaerstrat_mois_glo(klon_glo, n_lev, n_wav))
+          ALLOCATE(pizaerstrat_mois_glo(klon_glo, n_lev, n_wav))
+          ALLOCATE(cgaerstrat_mois_glo(klon_glo, n_lev, n_wav))
+!--select the correct month
+!--and copy into 1st longitude
+          tauaerstrat_mois(1,:,:,:) = tauaerstrat(:,:,:,mth_cur)
+          pizaerstrat_mois(1,:,:,:) = pizaerstrat(:,:,:,mth_cur)
+          cgaerstrat_mois(1,:,:,:)  = cgaerstrat(:,:,:,mth_cur)
+
+!--copy longitudes
+          DO i=2, n_lon
+           tauaerstrat_mois(i,:,:,:) = tauaerstrat_mois(1,:,:,:)
+           pizaerstrat_mois(i,:,:,:) = pizaerstrat_mois(1,:,:,:)
+           cgaerstrat_mois(i,:,:,:)  = cgaerstrat_mois(1,:,:,:)
+          ENDDO
+
+!---reduce to a klon_glo grid 
+          DO band=1, config%n_bands_sw
+            CALL grid2dTo1d_glo(tauaerstrat_mois(:,:,:,band),tauaerstrat_mois_glo(:,:,band))
+            CALL grid2dTo1d_glo(pizaerstrat_mois(:,:,:,band),pizaerstrat_mois_glo(:,:,band))
+            CALL grid2dTo1d_glo(cgaerstrat_mois(:,:,:,band),cgaerstrat_mois_glo(:,:,band))
+          ENDDO
+        ENDIF
+!--Now LW optical properties
+!
+
+        CALL nf95_open("taulwstrat.2D.nc", nf90_nowrite, ncid_in)
+
+        CALL nf95_inq_varid(ncid_in, "LEV", varid)
+        CALL nf95_gw_var(ncid_in, varid, lev)
+        n_lev = size(lev)
+        IF (n_lev.NE.klev) THEN 
+           abort_message='Le nombre de niveaux n est pas egal a klev'
+           CALL abort_physic(modname,abort_message,1)
+        ENDIF
+
+        CALL nf95_inq_varid(ncid_in, "LAT", varid)
+        CALL nf95_gw_var(ncid_in, varid, latitude)
+        n_lat = size(latitude)
+
+        IF (grid_type/=unstructured) THEN
+          IF (n_lat.NE.nbp_lat) THEN 
+             abort_message='Le nombre de lat n est pas egal a nbp_lat'
+             CALL abort_physic(modname,abort_message,1)
+          ENDIF
+        ENDIF
+        
+        CALL nf95_inq_varid(ncid_in, "TIME", varid)
+        CALL nf95_gw_var(ncid_in, varid, time)
+        n_month = size(time)
+        IF (n_month.NE.12) THEN 
+           abort_message='Le nombre de month n est pas egal a 12'
+           CALL abort_physic(modname,abort_message,1)
+        ENDIF
+
+        CALL nf95_inq_varid(ncid_in, "WAV", varid)
+        CALL nf95_gw_var(ncid_in, varid, wav)
+        n_wav = size(wav)
+        print *, 'WAV aerosol strato=', n_wav, wav
+!        IF (n_wav.NE.config%n_bands_lw) THEN 
+!           abort_message='Le nombre de wav n est pas egal a config%n_bands_lw'
+!           CALL abort_physic(modname,abort_message,1)
+!        ENDIF
+
+        ALLOCATE(taulwaerstrat(n_lat, n_lev, n_wav, n_month))
+! add ThL
+        ALLOCATE(pizlwaerstrat(n_lat, n_lev, n_wav, n_month))
+        ALLOCATE(cglwaerstrat(n_lat, n_lev, n_wav, n_month))
+! end add ThL
+
+!--reading stratospheric aerosol lw tau per layer
+        CALL nf95_inq_varid(ncid_in, "TAU_EAR", varid)
+        ncerr = nf90_get_var(ncid_in, varid, taulwaerstrat)
+        print *,'code erreur readaerosolstrato lw=', ncerr, varid
+
+! add/mod ThL
+!--with ECRAd, we also read omega and g:
+       !--reading stratospheric aerosol omega per layer
+        CALL nf95_inq_varid(ncid_in, "OME_EAR", varid)
+        ncerr = nf90_get_var(ncid_in, varid, pizlwaerstrat)
+        print *,'code erreur readaerosolstrato lw=', ncerr, varid
+
+!--reading stratospheric aerosol g per layer
+        CALL nf95_inq_varid(ncid_in, "GGG_EAR", varid)
+        ncerr = nf90_get_var(ncid_in, varid, cglwaerstrat)
+        print *,'code erreur readaerosolstrato lw=', ncerr, varid
+
+        CALL nf95_close(ncid_in)
+
+        IF (grid_type/=unstructured) THEN
+
+          ALLOCATE(taulwaerstrat_mois(n_lon, n_lat, n_lev, n_wav))
+          ALLOCATE(pizlwaerstrat_mois(n_lon, n_lat, n_lev, n_wav))
+          ALLOCATE(cglwaerstrat_mois(n_lon, n_lat, n_lev, n_wav))
+
+          ALLOCATE(taulwaerstrat_mois_glo(klon_glo, n_lev, n_wav))
+          ALLOCATE(pizlwaerstrat_mois_glo(klon_glo, n_lev, n_wav))
+          ALLOCATE(cglwaerstrat_mois_glo(klon_glo, n_lev, n_wav))
+!--select the correct month
+!--and copy into 1st longitude
+          taulwaerstrat_mois(1,:,:,:) = taulwaerstrat(:,:,:,mth_cur)
+          pizlwaerstrat_mois(1,:,:,:) = pizlwaerstrat(:,:,:,mth_cur)
+          cglwaerstrat_mois(1,:,:,:) = cglwaerstrat(:,:,:,mth_cur)
+!--copy longitudes
+          DO i=2, n_lon
+            taulwaerstrat_mois(i,:,:,:) = taulwaerstrat_mois(1,:,:,:)
+            pizlwaerstrat_mois(i,:,:,:) = pizlwaerstrat_mois(1,:,:,:)
+            cglwaerstrat_mois(i,:,:,:) = cglwaerstrat_mois(1,:,:,:)
+          ENDDO
+
+!---reduce to a klon_glo grid 
+          DO band=1, config%n_bands_lw
+            CALL grid2dTo1d_glo(taulwaerstrat_mois(:,:,:,band),taulwaerstrat_mois_glo(:,:,band))
+            CALL grid2dTo1d_glo(pizlwaerstrat_mois(:,:,:,band),pizlwaerstrat_mois_glo(:,:,band))
+            CALL grid2dTo1d_glo(cglwaerstrat_mois(:,:,:,band),cglwaerstrat_mois_glo(:,:,band))
+          ENDDO
+        ENDIF
+      
+      ELSE !--proc other than mpi_root and omp_root
+           !--dummy allocation needed for debug mode
+
+        ALLOCATE(tauaerstrat_mois_glo(1,1,1))
+        ALLOCATE(pizaerstrat_mois_glo(1,1,1))
+        ALLOCATE(cgaerstrat_mois_glo(1,1,1))
+        ALLOCATE(taulwaerstrat_mois_glo(1,1,1))
+        ALLOCATE(pizlwaerstrat_mois_glo(1,1,1))
+        ALLOCATE(cglwaerstrat_mois_glo(1,1,1))
+
+        ALLOCATE(tauaerstrat(0,0,0,12))
+        ALLOCATE(pizaerstrat(0,0,0,12))
+        ALLOCATE(cgaerstrat(0,0,0,12))
+        ALLOCATE(taulwaerstrat(0,0,0,12))
+        ALLOCATE(pizlwaerstrat(0,0,0,12))
+        ALLOCATE(cglwaerstrat(0,0,0,12))
+! end add/mod ThL
+
+      ENDIF !--is_mpi_root and is_omp_root
+
+!$OMP BARRIER
+
+!--keep memory of previous month
+      mth_pre=mth_cur
+
+      IF (grid_type==unstructured) THEN
+
+#ifdef CPP_XIOS
+
+        IF (is_omp_master) THEN
+          ALLOCATE(tauaerstrat_mpi(klon_mpi, klev, config%n_bands_sw))
+          ALLOCATE(pizaerstrat_mpi(klon_mpi, klev, config%n_bands_sw))
+          ALLOCATE(cgaerstrat_mpi(klon_mpi, klev, config%n_bands_sw))        
+          ALLOCATE(taulwaerstrat_mpi(klon_mpi, klev, config%n_bands_lw))
+! add ThL
+          ALLOCATE(pizlwaerstrat_mpi(klon_mpi, klev, config%n_bands_lw))
+          ALLOCATE(cglwaerstrat_mpi(klon_mpi, klev, config%n_bands_lw))
+! end add ThL
+
+          CALL xios_send_field("tauaerstrat_in",SPREAD(tauaerstrat(:,:,:,mth_cur),1,8))
+          CALL xios_recv_field("tauaerstrat_out",tauaerstrat_mpi)
+          CALL xios_send_field("pizaerstrat_in",SPREAD(pizaerstrat(:,:,:,mth_cur),1,8))
+          CALL xios_recv_field("pizaerstrat_out",pizaerstrat_mpi)
+          CALL xios_send_field("cgaerstrat_in",SPREAD(cgaerstrat(:,:,:,mth_cur),1,8))
+          CALL xios_recv_field("cgaerstrat_out",cgaerstrat_mpi)
+          CALL xios_send_field("taulwaerstrat_in",SPREAD(taulwaerstrat(:,:,:,mth_cur),1,8))
+          CALL xios_recv_field("taulwaerstrat_out",taulwaerstrat_mpi)
+! add ThL
+          CALL xios_send_field("pizlwaerstrat_in",SPREAD(pizlwaerstrat(:,:,:,mth_cur),1,8))
+          CALL xios_recv_field("pizlwaerstrat_out",pizlwaerstrat_mpi)
+          CALL xios_send_field("cglwaerstrat_in",SPREAD(cglwaerstrat(:,:,:,mth_cur),1,8))
+          CALL xios_recv_field("cglwaerstrat_out",cglwaerstrat_mpi)
+! end add ThL
+        ELSE
+          ALLOCATE(tauaerstrat_mpi(0, 0, 0))
+          ALLOCATE(pizaerstrat_mpi(0, 0, 0))
+          ALLOCATE(cgaerstrat_mpi(0, 0, 0))        
+          ALLOCATE(taulwaerstrat_mpi(0, 0, 0))
+! add ThL
+          ALLOCATE(pizlwaerstrat_mpi(0, 0, 0))
+          ALLOCATE(cglwaerstrat_mpi(0, 0, 0))
+! end add ThL
+        ENDIF  
+        
+        CALL scatter_omp(tauaerstrat_mpi,tau_aer_strat)
+        CALL scatter_omp(pizaerstrat_mpi,piz_aer_strat)
+        CALL scatter_omp(cgaerstrat_mpi,cg_aer_strat)
+        CALL scatter_omp(taulwaerstrat_mpi,taulw_aer_strat)
+! add ThL
+        CALL scatter_omp(pizlwaerstrat_mpi,pizlw_aer_strat)
+        CALL scatter_omp(cglwaerstrat_mpi,cglw_aer_strat)
+! end add ThL
+#endif
+      ELSE  
+        
+!--scatter on all proc
+        CALL scatter(tauaerstrat_mois_glo,tau_aer_strat)
+        CALL scatter(pizaerstrat_mois_glo,piz_aer_strat)
+        CALL scatter(cgaerstrat_mois_glo,cg_aer_strat)
+        CALL scatter(taulwaerstrat_mois_glo,taulw_aer_strat)
+! add ThL
+        CALL scatter(pizlwaerstrat_mois_glo,pizlw_aer_strat)
+        CALL scatter(cglwaerstrat_mois_glo,cglw_aer_strat) 
+! end add ThL
+        IF (is_mpi_root.AND.is_omp_root)  DEALLOCATE(tauaerstrat_mois, pizaerstrat_mois, cgaerstrat_mois, taulwaerstrat_mois, pizlwaerstrat_mois, cglwaerstrat_mois) ! mod ThL
+
+      ENDIF 
+
+      IF (is_mpi_root.AND.is_omp_root) THEN
+        DEALLOCATE(tauaerstrat, pizaerstrat, cgaerstrat, taulwaerstrat, pizlwaerstrat, cglwaerstrat) ! mod ThL
+      ENDIF
+      
+
+!$OMP BARRIER
+
+    ENDIF !--debut ou nouveau mois
+
+!--total vertical aod at the SW wavelengths
+!--for now use ECRAD band #10 AOD into all wavelengths
+!--it is only a reasonable approximation for 550 nm
+!--WAV(10)=0.53 µm
+!--<!!!> This is considering that wavebands are in their original order,
+!--and have NOT been re-ordered monotonously, i.e. with
+!--WAV(1) = 3.46 µm
+!--WAV(2) = 2.79 µm
+!--(...)
+!--WAV(last-1) = 0.23 µm
+!--WAV(last)= 8.02 µm
+!--If bands were to be re-ordered, i.e. last band be put in 1st position,
+!--then we should consider band=11 to fetch WAV=0.53 µm.
+    band=10
+    DO i=1, klon
+    DO k=1, klev
+      IF (stratomask(i,k).GT.0.999999) THEN
+        DO wave=1, config%n_bands_sw
+          tausum_aero(i,wave,id_STRAT_phy)=tausum_aero(i,wave,id_STRAT_phy)+tau_aer_strat(i,k,band)
+        ENDDO
+      ENDIF
+    ENDDO
+    ENDDO
+
+    IF (.NOT. ok_volcan) THEN
+!
+!--this is the default case 
+!--stratospheric aerosols are added to both index 2 and 1 for double radiation calls
+!--weighted average for cg, piz and tau, adding strat aerosols on top of tropospheric ones
+    DO band=1, config%n_bands_sw
+      WHERE (stratomask.GT.0.999999)
+!--strat aerosols are added to index 2: natural and anthropogenic aerosols for bands 1 to config%n_bands_sw 
+        cg_aero_sw_rrtm(:,:,2,band)  = ( cg_aero_sw_rrtm(:,:,2,band)*piz_aero_sw_rrtm(:,:,2,band)*tau_aero_sw_rrtm(:,:,2,band) + &
+                                         cg_aer_strat(:,:,band)*piz_aer_strat(:,:,band)*tau_aer_strat(:,:,band) ) /              &
+                                    MAX( piz_aero_sw_rrtm(:,:,2,band)*tau_aero_sw_rrtm(:,:,2,band) +                             &
+                                         piz_aer_strat(:,:,band)*tau_aer_strat(:,:,band), 1.e-15 )
+        piz_aero_sw_rrtm(:,:,2,band) = ( piz_aero_sw_rrtm(:,:,2,band)*tau_aero_sw_rrtm(:,:,2,band) +                             &
+                                         piz_aer_strat(:,:,band)*tau_aer_strat(:,:,band) ) /                                     &
+                                    MAX( tau_aero_sw_rrtm(:,:,2,band) + tau_aer_strat(:,:,band), 1.e-15 )
+        tau_aero_sw_rrtm(:,:,2,band)  = tau_aero_sw_rrtm(:,:,2,band) + tau_aer_strat(:,:,band)
+!--strat aerosols are added to index 1: natural aerosols only for bands 1 to config%n_bands_sw
+        cg_aero_sw_rrtm(:,:,1,band)  = ( cg_aero_sw_rrtm(:,:,1,band)*piz_aero_sw_rrtm(:,:,1,band)*tau_aero_sw_rrtm(:,:,1,band) + &
+                                         cg_aer_strat(:,:,band)*piz_aer_strat(:,:,band)*tau_aer_strat(:,:,band) ) /              &
+                                    MAX( piz_aero_sw_rrtm(:,:,1,band)*tau_aero_sw_rrtm(:,:,1,band) +                             &
+                                         piz_aer_strat(:,:,band)*tau_aer_strat(:,:,band), 1.e-15 )
+        piz_aero_sw_rrtm(:,:,1,band) = ( piz_aero_sw_rrtm(:,:,1,band)*tau_aero_sw_rrtm(:,:,1,band) +                             &
+                                         piz_aer_strat(:,:,band)*tau_aer_strat(:,:,band) ) /                                     &
+                                    MAX( tau_aero_sw_rrtm(:,:,1,band) + tau_aer_strat(:,:,band), 1.e-15 )
+        tau_aero_sw_rrtm(:,:,1,band)  = tau_aero_sw_rrtm(:,:,1,band) + tau_aer_strat(:,:,band)
+    ENDWHERE
+    ENDDO
+!
+    ELSE
+!
+!--this is the VOLMIP case
+!--stratospheric aerosols are only added to index 2 in this case 
+!--weighted average for cg, piz and tau, adding strat aerosols on top of tropospheric ones
+    DO band=1, config%n_bands_sw
+      WHERE (stratomask.GT.0.999999)
+!--strat aerosols are added to index 2 : natural and anthropogenic aerosols for bands 1 to config%n_bands_sw 
+        cg_aero_sw_rrtm(:,:,2,band)  = ( cg_aero_sw_rrtm(:,:,2,band)*piz_aero_sw_rrtm(:,:,2,band)*tau_aero_sw_rrtm(:,:,2,band) + &
+                                         cg_aer_strat(:,:,band)*piz_aer_strat(:,:,band)*tau_aer_strat(:,:,band) ) /              &
+                                    MAX( piz_aero_sw_rrtm(:,:,2,band)*tau_aero_sw_rrtm(:,:,2,band) +                             &
+                                         piz_aer_strat(:,:,band)*tau_aer_strat(:,:,band), 1.e-15 )
+        piz_aero_sw_rrtm(:,:,2,band) = ( piz_aero_sw_rrtm(:,:,2,band)*tau_aero_sw_rrtm(:,:,2,band) +                             &
+                                         piz_aer_strat(:,:,band)*tau_aer_strat(:,:,band) ) /                                     &
+                                    MAX( tau_aero_sw_rrtm(:,:,2,band) + tau_aer_strat(:,:,band), 1.e-15 )
+        tau_aero_sw_rrtm(:,:,2,band)  = tau_aero_sw_rrtm(:,:,2,band) + tau_aer_strat(:,:,band)
+     ENDWHERE
+  ENDDO
+  ENDIF
+
+!--total vertical aod at 10 um
+!--this is approximated from band 7 of ECRAD (9.73 µm)
+    band=7
+    DO i=1, klon
+    DO k=1, klev
+      IF (stratomask(i,k).GT.0.999999) THEN
+        DO wave=1, config%n_bands_lw
+          tausum_aero(i,config%n_bands_sw+wave,id_STRAT_phy)=tausum_aero(i,config%n_bands_sw+wave,id_STRAT_phy)+taulw_aer_strat(i,k,band)
+        ENDDO
+      ENDIF
+    ENDDO
+    ENDDO
+
+    IF (.NOT. ok_volcan) THEN
+!--this is the default case 
+!--stratospheric aerosols are added to both index 2 and 1
+    DO band=1, config%n_bands_lw
+      WHERE (stratomask.GT.0.999999)
+! add ThL
+        cg_aero_lw_rrtm(:,:,2,band)  = ( cg_aero_lw_rrtm(:,:,2,band)*piz_aero_lw_rrtm(:,:,2,band)*tau_aero_lw_rrtm(:,:,2,band) + &
+                                         cglw_aer_strat(:,:,band)*pizlw_aer_strat(:,:,band)*taulw_aer_strat(:,:,band) ) /        &
+                                    MAX( piz_aero_lw_rrtm(:,:,2,band)*tau_aero_lw_rrtm(:,:,2,band) +                             &
+                                         pizlw_aer_strat(:,:,band)*taulw_aer_strat(:,:,band), 1.e-15 )
+        piz_aero_lw_rrtm(:,:,2,band) = ( piz_aero_lw_rrtm(:,:,2,band)*tau_aero_lw_rrtm(:,:,2,band) +                             &
+                                         pizlw_aer_strat(:,:,band)*taulw_aer_strat(:,:,band) ) /                                 &
+                                    MAX( tau_aero_lw_rrtm(:,:,2,band) + taulw_aer_strat(:,:,band), 1.e-15 )
+        cg_aero_lw_rrtm(:,:,1,band)  = ( cg_aero_lw_rrtm(:,:,1,band)*piz_aero_lw_rrtm(:,:,1,band)*tau_aero_lw_rrtm(:,:,1,band) + &
+                                         cglw_aer_strat(:,:,band)*pizlw_aer_strat(:,:,band)*taulw_aer_strat(:,:,band) ) /        &
+                                    MAX( piz_aero_lw_rrtm(:,:,1,band)*tau_aero_lw_rrtm(:,:,1,band) +                             &
+                                         pizlw_aer_strat(:,:,band)*taulw_aer_strat(:,:,band), 1.e-15 )
+        piz_aero_lw_rrtm(:,:,1,band) = ( piz_aero_lw_rrtm(:,:,1,band)*tau_aero_lw_rrtm(:,:,1,band) +                             &
+                                         pizlw_aer_strat(:,:,band)*taulw_aer_strat(:,:,band) ) /                                 &
+                                    MAX( tau_aero_lw_rrtm(:,:,1,band) + taulw_aer_strat(:,:,band), 1.e-15 )
+! end add ThL
+        tau_aero_lw_rrtm(:,:,2,band)  = tau_aero_lw_rrtm(:,:,2,band) + taulw_aer_strat(:,:,band)
+        tau_aero_lw_rrtm(:,:,1,band)  = tau_aero_lw_rrtm(:,:,1,band) + taulw_aer_strat(:,:,band)
+      ENDWHERE
+    ENDDO
+!
+    ELSE
+!
+! mod ThL
+!--this is the VOLMIP case
+    DO band=1, config%n_bands_lw
+      WHERE (stratomask.GT.0.999999)
+!--stratospheric aerosols are not added to index 1 
+!--and we copy index 2 in index 1 because we want the same dust aerosol LW properties as above
+        cg_aero_lw_rrtm(:,:,1,band)  = cg_aero_lw_rrtm(:,:,2,band)
+        piz_aero_lw_rrtm(:,:,1,band) = piz_aero_lw_rrtm(:,:,2,band)
+        tau_aero_lw_rrtm(:,:,1,band) = tau_aero_lw_rrtm(:,:,2,band)
+
+!--stratospheric aerosols are only added to index 2
+        cg_aero_lw_rrtm(:,:,2,band)  = (cg_aero_lw_rrtm(:,:,2,band)*piz_aero_lw_rrtm(:,:,2,band)*tau_aero_lw_rrtm(:,:,2,band) + &
+                                        cglw_aer_strat(:,:,band)*pizlw_aer_strat(:,:,band)*taulw_aer_strat(:,:,band)) /         &
+                                        MAX( piz_aero_lw_rrtm(:,:,2,band)*tau_aero_lw_rrtm(:,:,2,band) +                        &
+                                        pizlw_aer_strat(:,:,band)*taulw_aer_strat(:,:,band), 1.e-15 )
+        piz_aero_lw_rrtm(:,:,2,band) = (piz_aero_lw_rrtm(:,:,2,band)*tau_aero_lw_rrtm(:,:,2,band) +                             &
+                                        pizlw_aer_strat(:,:,band)*taulw_aer_strat(:,:,band) ) /                                 &
+                                        MAX( tau_aero_lw_rrtm(:,:,2,band) + taulw_aer_strat(:,:,band), 1.e-15 )
+        tau_aero_lw_rrtm(:,:,2,band)  = tau_aero_lw_rrtm(:,:,2,band) + taulw_aer_strat(:,:,band)
+      ENDWHERE
+    ENDDO
+    ENDIF
+! end mod ThL
+
+!--default SSA value if there is no aerosol
+!--to avoid 0 values that seems to cause some problem to RRTM
+    WHERE (tau_aero_sw_rrtm.LT.1.e-14)
+      piz_aero_sw_rrtm = 1.0
+    ENDWHERE
+
+!--in principle this should not be necessary 
+!--as these variables have min values already but just in case
+!--put 1e-15 min value to both SW and LW AOD
+    tau_aero_sw_rrtm = MAX(tau_aero_sw_rrtm,1.e-15)
+    tau_aero_lw_rrtm = MAX(tau_aero_lw_rrtm,1.e-15)
+
+END SUBROUTINE readaerosolstrato_ecrad
Index: /LMDZ6/trunk/libf/phylmd/ecrad/lmdz/setup_aerosol_optics_lmdz_m.F90
===================================================================
--- /LMDZ6/trunk/libf/phylmd/ecrad/lmdz/setup_aerosol_optics_lmdz_m.F90	(revision 4853)
+++ /LMDZ6/trunk/libf/phylmd/ecrad/lmdz/setup_aerosol_optics_lmdz_m.F90	(revision 4853)
@@ -0,0 +1,124 @@
+module setup_aerosol_optics_lmdz_m
+
+  implicit none
+
+contains
+
+  subroutine setup_aerosol_optics_lmdz(ao, file_name)
+
+    ! Read aerosol optical properties. Note differences with
+    ! "radiation_aerosol_optics_data::setup_aerosol_optics":
+
+    ! -- The input NetCDF file is not flat, it contains NetCDF groups.
+
+    ! -- We do not define ao%ssa_mono_phobic, ao%g_mono_phobic,
+    ! ao%lidar_ratio_mono_phobic, ao%ssa_mono_philic,
+    ! ao%g_mono_philic, ao%lidar_ratio_mono_philic. They are not in
+    ! the input NetCDF file and they are not used by ECRad.
+
+    ! -- We do not define ao%description_phobic_str and
+    ! ao%description_philic_str. We just leave the initialization
+    ! value, which is a blank.
+
+    ! -- We have to cshift the shortwave fields because the the
+    ! shortwave bands are in ascending order in the NetCDF file while
+    ! they are not in ECRad.
+
+    use radiation_aerosol_optics_data, only: aerosol_optics_type, &
+         IAerosolClassUndefined
+    use netcdf95, only: nf95_open, nf95_inq_grp_full_ncid, nf95_close, &
+         nf95_inq_dimid, nf95_inq_varid, nf95_inquire_dimension, &
+         nf95_get_var, nf95_gw_var, nf95_nowrite
+
+    type(aerosol_optics_type), intent(out):: ao
+
+    character(len=*), intent(in):: file_name
+    ! NetCDF file containing the aerosol optics data
+
+    ! Local:
+    integer ncid, grpid, dimid, varid
+
+    !-----------------------------------------------------------------------
+
+    ao%use_hydrophilic = .true.
+    ao%use_monochromatic = .true.
+    call nf95_open(file_name, nf95_nowrite, ncid)
+    call nf95_inq_grp_full_ncid(ncid, "Hydrophilic", grpid)
+    call nf95_inq_dimid(grpid, "hur", dimid)
+    call nf95_inquire_dimension(grpid, dimid, nclen = ao%nrh)
+    allocate(ao%rh_lower(ao%nrh))
+    call nf95_inq_varid(grpid, "hur_bounds", varid)
+    call nf95_get_var(grpid, varid, ao%rh_lower, count_nc = [1, ao%nrh])
+
+    ! Hydrophilic/LW_bands:
+    call nf95_inq_grp_full_ncid(ncid, "Hydrophilic/LW_bands", grpid)
+    call nf95_inq_varid(grpid, "asymmetry", varid)
+    call nf95_gw_var(grpid, varid, ao%g_lw_philic)
+    call nf95_inq_varid(grpid, "single_scat_alb", varid)
+    call nf95_gw_var(grpid, varid, ao%ssa_lw_philic)
+    call nf95_inq_varid(grpid, "mass_ext", varid)
+    call nf95_gw_var(grpid, varid, ao%mass_ext_lw_philic)
+
+    ! Hydrophilic/SW_bands:
+    call nf95_inq_grp_full_ncid(ncid, "Hydrophilic/SW_bands", grpid)
+    call nf95_inq_varid(grpid, "asymmetry", varid)
+    call nf95_gw_var(grpid, varid, ao%g_sw_philic)
+    ao%g_sw_philic = cshift(ao%g_sw_philic, 1)
+    call nf95_inq_varid(grpid, "single_scat_alb", varid)
+    call nf95_gw_var(grpid, varid, ao%ssa_sw_philic)
+    ao%ssa_sw_philic = cshift(ao%ssa_sw_philic, 1)
+    call nf95_inq_varid(grpid, "mass_ext", varid)
+    call nf95_gw_var(grpid, varid, ao%mass_ext_sw_philic)
+    ao%mass_ext_sw_philic = cshift(ao%mass_ext_sw_philic, 1)
+
+    ! Hydrophilic/Monochromatic:
+    call nf95_inq_grp_full_ncid(ncid, "Hydrophilic/Monochromatic", grpid)
+    call nf95_inq_varid(grpid, "mass_ext", varid)
+    call nf95_gw_var(grpid, varid, ao%mass_ext_mono_philic)
+
+    ! Hydrophobic/LW_bands:
+    call nf95_inq_grp_full_ncid(ncid, "Hydrophobic/LW_bands", grpid)
+    call nf95_inq_varid(grpid, "asymmetry", varid)
+    call nf95_gw_var(grpid, varid, ao%g_lw_phobic)
+    call nf95_inq_varid(grpid, "single_scat_alb", varid)
+    call nf95_gw_var(grpid, varid, ao%ssa_lw_phobic)
+    call nf95_inq_varid(grpid, "mass_ext", varid)
+    call nf95_gw_var(grpid, varid, ao%mass_ext_lw_phobic)
+
+    ! Hydrophobic/SW_bands:
+    call nf95_inq_grp_full_ncid(ncid, "Hydrophobic/SW_bands", grpid)
+    call nf95_inq_varid(grpid, "asymmetry", varid)
+    call nf95_gw_var(grpid, varid, ao%g_sw_phobic)
+    ao%g_sw_phobic = cshift(ao%g_sw_phobic, 1)
+    call nf95_inq_varid(grpid, "single_scat_alb", varid)
+    call nf95_gw_var(grpid, varid, ao%ssa_sw_phobic)
+    ao%ssa_sw_phobic = cshift(ao%ssa_sw_phobic, 1)
+    call nf95_inq_varid(grpid, "mass_ext", varid)
+    call nf95_gw_var(grpid, varid, ao%mass_ext_sw_phobic)
+    ao%mass_ext_sw_phobic = cshift(ao%mass_ext_sw_phobic, 1)
+
+    ! Hydrophobic/Monochromatic:
+    call nf95_inq_grp_full_ncid(ncid, "Hydrophobic/Monochromatic", grpid)
+    call nf95_inq_varid(grpid, "mass_ext", varid)
+    call nf95_gw_var(grpid, varid, ao%mass_ext_mono_phobic)
+
+    call nf95_close(ncid)
+
+    ! Get array sizes
+    ao%n_bands_lw = size(ao%mass_ext_lw_phobic, 1)
+    ao%n_bands_sw = size(ao%mass_ext_sw_phobic, 1)
+    ao%n_mono_wl = size(ao%mass_ext_mono_phobic, 1)
+    ao%n_type_phobic = size(ao%mass_ext_lw_phobic, 2)
+    ao%n_type_philic = size(ao%mass_ext_lw_philic, 3)
+
+    ! Allocate memory for mapping arrays
+    ao%ntype = ao%n_type_phobic + ao%n_type_philic
+    allocate(ao%iclass(ao%ntype))
+    allocate(ao%itype(ao%ntype))
+
+    ao%iclass = IAerosolClassUndefined
+    ao%itype  = 0
+
+  end subroutine setup_aerosol_optics_lmdz
+
+end module setup_aerosol_optics_lmdz_m
Index: /LMDZ6/trunk/libf/phylmd/ecrad/lmdz/setup_config_from_lmdz.F90
===================================================================
--- /LMDZ6/trunk/libf/phylmd/ecrad/lmdz/setup_config_from_lmdz.F90	(revision 4853)
+++ /LMDZ6/trunk/libf/phylmd/ecrad/lmdz/setup_config_from_lmdz.F90	(revision 4853)
@@ -0,0 +1,104 @@
+module setup_config_from_lmdz
+
+  use parkind1, only : jprb
+
+  implicit none
+
+  public
+
+  type driver_config_type
+     logical    :: ok_effective_size  = .true.
+     logical    :: ok_separation = .false.   
+     real(jprb) :: high_inv_effective_size   = -1.0_jprb ! m-1
+     real(jprb) :: middle_inv_effective_size = -1.0_jprb ! m-1
+     real(jprb) :: low_inv_effective_size    = -1.0_jprb ! m-1
+     real(jprb) :: cloud_inhom_separation_factor  = -1.0_jprb
+     real(jprb) :: cloud_separation_scale_surface = -1.0_jprb
+     real(jprb) :: cloud_separation_scale_toa     = -1.0_jprb
+     real(jprb) :: cloud_separation_scale_power   = -1.0_jprb
+     real(jprb) :: frac_std = 0.75_jprb
+     real(jprb) :: overlap_decorr_length = 2000.0_jprb
+
+
+ contains
+ procedure :: read => read_config_from_namelist
+
+  end type driver_config_type
+
+contains
+
+  !---------------------------------------------------------------------
+  subroutine read_config_from_namelist(this, file_name, is_success)
+
+    use radiation_io, only : nulerr, radiation_abort       
+
+    class(driver_config_type), intent(inout) :: this
+    character(*), intent(in)          :: file_name
+    logical, intent(out), optional    :: is_success
+    logical    :: ok_effective_size, ok_separation
+    integer    :: iosopen ! Status after calling open
+    real(jprb) :: high_inv_effective_size 
+    real(jprb) :: middle_inv_effective_size
+    real(jprb) :: low_inv_effective_size
+    real(jprb) :: cloud_inhom_separation_factor 
+    real(jprb) :: cloud_separation_scale_surface
+    real(jprb) :: cloud_separation_scale_toa
+    real(jprb) :: cloud_separation_scale_power
+    real(jprb) :: frac_std
+    real(jprb) :: overlap_decorr_length
+
+    namelist /radiation_driver/ ok_effective_size, ok_separation, &
+         &  frac_std, overlap_decorr_length, &
+         &  high_inv_effective_size, middle_inv_effective_size, low_inv_effective_size, &
+         &  cloud_inhom_separation_factor, cloud_separation_scale_surface, &
+         &  cloud_separation_scale_toa, cloud_separation_scale_power 
+
+    ok_effective_size = .false.
+    ok_separation = .false.
+    high_inv_effective_size   = -1.0_jprb 
+    middle_inv_effective_size = -1.0_jprb 
+    low_inv_effective_size    = -1.0_jprb 
+    cloud_inhom_separation_factor  = -1.0_jprb
+    cloud_separation_scale_surface = -1.0_jprb
+    cloud_separation_scale_toa     = -1.0_jprb
+    cloud_separation_scale_power   = -1.0_jprb
+    frac_std = 0.75_jprb
+    overlap_decorr_length = 2000.0_jprb
+
+    ! Open the namelist file and read the radiation_driver namelist
+    open(unit=10, iostat=iosopen, file=trim(file_name))
+    if (iosopen /= 0) then
+      ! An error occurred
+      if (present(is_success)) then
+        is_success = .false.
+        ! We now continue the subroutine so that the default values
+        ! are placed in the config structure
+      else
+        write(nulerr,'(a,a,a)') '*** Error: namelist file "', &
+             &                trim(file_name), '" not found'
+        call radiation_abort('Driver configuration error')
+      end if
+    else
+      ! Read the radiation_driver namelist, noting that it is not an
+      ! error if this namelist is not present, provided all the required
+      ! variables are present in the NetCDF data file instead
+      read(unit=10, nml=radiation_driver)
+      close(unit=10)
+    end if
+
+    ! Copy namelist data into configuration object
+    this%ok_effective_size = ok_effective_size 
+    this%ok_separation = ok_separation
+    this%frac_std = frac_std
+    this%overlap_decorr_length = overlap_decorr_length
+    this%cloud_inhom_separation_factor = cloud_inhom_separation_factor
+    this%cloud_separation_scale_surface = cloud_separation_scale_surface
+    this%cloud_separation_scale_toa = cloud_separation_scale_toa
+    this%cloud_separation_scale_power = cloud_separation_scale_power
+    this%high_inv_effective_size = high_inv_effective_size
+    this%middle_inv_effective_size = middle_inv_effective_size
+    this%low_inv_effective_size = low_inv_effective_size
+
+  end subroutine read_config_from_namelist          
+
+end module setup_config_from_lmdz
Index: /LMDZ6/trunk/libf/phylmd/ecrad/radiation/Makefile
===================================================================
--- /LMDZ6/trunk/libf/phylmd/ecrad/radiation/Makefile	(revision 4852)
+++ /LMDZ6/trunk/libf/phylmd/ecrad/radiation/Makefile	(revision 4853)
@@ -111,2 +111,4 @@
 
 radiation_general_cloud_optics.o: radiation_config.o radiation_cloud.o radiation_thermodynamics.o radiation_constants.o
+
+*.o: ecrad_config.h
Index: DZ6/trunk/libf/phylmd/ecrad/radiation/aeropt_5wv_ecrad.F90
===================================================================
--- /LMDZ6/trunk/libf/phylmd/ecrad/radiation/aeropt_5wv_ecrad.F90	(revision 4852)
+++ 	(revision )
@@ -1,100 +1,0 @@
-!aeropt_5wv_ecrad.F90 2022-09-20 A. Idelkadi et O. Boucher 
-!
-     SUBROUTINE AEROPT_5WV_ECRAD(istartcol,iendcol,istartlev,iendlev, &
-                                 config,thermodynamics,aerosol)
-
-
-      USE DIMPHY
-      USE aero_mod
-      USE phys_local_var_mod, ONLY: od443aer,od550aer,od865aer
-!                                      dryod550aer, 
-!                                      ec550aer,od550lt1aer,abs550aer
-!        USE phys_output_var_mod, ONLY: dryaod_diag
-!        USE YOMCST, ONLY: RD,RG
-      USE phys_local_var_mod, ONLY: rhcl
-
-      use parkind1,                      only : jprb
-      use radiation_config,              only : config_type
-      use radiation_thermodynamics,      only : thermodynamics_type
-      use radiation_aerosol,             only : aerosol_type
-      use radiation_constants,           only : AccelDueToGravity
-      use radiation_aerosol_optics_data, only : aerosol_optics_type, &
-         &  IAerosolClassUndefined,   IAerosolClassIgnored, &
-         &  IAerosolClassHydrophobic, IAerosolClassHydrophilic
-
-      IMPLICIT NONE
-
-      !---ATTENTION n_mono est a redéfinir proprement
-
-      ! Range of levels over which aerosols are present
-      integer, intent(in) :: istartlev, iendlev, istartcol,iendcol
-      type(config_type), intent(in), target :: config
-      type(thermodynamics_type),intent(in)  :: thermodynamics
-      type(aerosol_type),       intent(in)  :: aerosol
-      type(aerosol_optics_type), pointer :: ao
-
-      ! Loop indices for column, level, g point, band and aerosol type, and relative humidity
-      integer :: jcol, jlev, jtype, irh
-      ! indice wavelength in aerosol_optics_lmdz.nc
-      INTEGER, PARAMETER :: la443 = 1
-      INTEGER, PARAMETER :: la550 = 2
-!      INTEGER, PARAMETER :: la670 = 3
-!      INTEGER, PARAMETER :: la765 = 4
-      INTEGER, PARAMETER :: la865 = 5
-      real(jprb) :: factor
-      ! n_bands_sw
-      real(jprb), dimension(config%aerosol_optics%n_mono_wl) :: od_aerosol_mono, local_od_mono
-
-      !--initialization
-      od443aer = 0.0_jprb
-      od550aer = 0.0_jprb
-      od865aer = 0.0_jprb
-
-      ao => config%aerosol_optics
-
-      ! Loop over level
-     do jlev = istartlev,iendlev
-
-        ! Loop over column
-        do jcol = istartcol,iendcol
-
-          ! Compute relative humidity with respect to liquid
-          ! saturation and the index to the relative-humidity index of
-          ! hydrophilic-aerosol data
-          irh = ao%calc_rh_index(rhcl(jcol,jlev))
-
-          factor = ( thermodynamics%pressure_hl(jcol,jlev+1) &
-               &    -thermodynamics%pressure_hl(jcol,jlev  )  ) &
-               &   / AccelDueToGravity
-
-          ! Reset temporary arrays
-          od_aerosol_mono = 0.0_jprb
-
-          do jtype = 1,config%n_aerosol_types
-            ! Add the optical depth for this aerosol type to the total for all aerosols.  
-            ! Note that the following expressions are array-wise
-            if (ao%iclass(jtype) == IAerosolClassHydrophobic) then
-              local_od_mono = factor * aerosol%mixing_ratio(jcol,jlev,jtype) &
-                   &  * ao%mass_ext_mono_phobic(:,ao%itype(jtype))
-              od_aerosol_mono = od_aerosol_mono + local_od_mono
-            else if (ao%iclass(jtype) == IAerosolClassHydrophilic) then
-              ! Hydrophilic aerosols require the look-up tables to
-              ! be indexed with irh
-              local_od_mono = factor * aerosol%mixing_ratio(jcol,jlev,jtype) &
-                   &  * ao%mass_ext_mono_philic(:,irh,ao%itype(jtype))
-              od_aerosol_mono = od_aerosol_mono + local_od_mono
-            end if
-
-          end do ! Loop over aerosol type
-
-          !--ATTENTION A BIEN FAIRE CORRESPONDRE LES INDICES
-          od443aer(jcol) = od443aer(jcol) + od_aerosol_mono(la443)
-          od550aer(jcol) = od550aer(jcol) + od_aerosol_mono(la550)
-          od865aer(jcol) = od865aer(jcol) + od_aerosol_mono(la865)
-
-        end do ! Loop over column
-
-      end do ! Loop over level
-
-     END SUBROUTINE AEROPT_5WV_ECRAD
-
Index: /LMDZ6/trunk/libf/phylmd/ecrad/radiation/radiation_aerosol_optics.F90
===================================================================
--- /LMDZ6/trunk/libf/phylmd/ecrad/radiation/radiation_aerosol_optics.F90	(revision 4852)
+++ /LMDZ6/trunk/libf/phylmd/ecrad/radiation/radiation_aerosol_optics.F90	(revision 4853)
@@ -19,4 +19,6 @@
 !   2022-11-22  P. Ukkonen / R. Hogan  Optimizations to enhance vectorization
 
+#include "ecrad_config.h"
+
 module radiation_aerosol_optics
 
@@ -96,5 +98,9 @@
     use parkind1,                      only : jprb
     use yomhook,                       only : lhook, dr_hook, jphook
+#ifdef EASY_NETCDF_READ_MPI
+    use easy_netcdf_read_mpi,          only : netcdf_file
+#else
     use easy_netcdf,                   only : netcdf_file
+#endif
     use radiation_config,              only : config_type
     use radiation_aerosol_optics_data, only : aerosol_optics_type
@@ -341,5 +347,9 @@
     use parkind1,                      only : jprb
     use yomhook,                       only : lhook, dr_hook, jphook
+#ifdef EASY_NETCDF_READ_MPI
+    use easy_netcdf_read_mpi,          only : netcdf_file
+#else
     use easy_netcdf,                   only : netcdf_file
+#endif
     use radiation_config,              only : config_type
     use radiation_aerosol_optics_data, only : aerosol_optics_type
Index: /LMDZ6/trunk/libf/phylmd/ecrad/radiation/radiation_aerosol_optics_data.F90
===================================================================
--- /LMDZ6/trunk/libf/phylmd/ecrad/radiation/radiation_aerosol_optics_data.F90	(revision 4852)
+++ /LMDZ6/trunk/libf/phylmd/ecrad/radiation/radiation_aerosol_optics_data.F90	(revision 4853)
@@ -17,4 +17,5 @@
 !   2018-04-20  A. Bozzo  Read optical properties at selected wavelengths
 
+#include "ecrad_config.h"
 
 module radiation_aerosol_optics_data
@@ -157,5 +158,9 @@
 
     use yomhook,              only : lhook, dr_hook, jphook
+#ifdef EASY_NETCDF_READ_MPI
+    use easy_netcdf_read_mpi, only : netcdf_file
+#else
     use easy_netcdf,          only : netcdf_file
+#endif
     use radiation_io,         only : nulerr, radiation_abort
 
@@ -401,6 +406,6 @@
   subroutine save_aerosol_optics(this, file_name, iverbose)
 
-    use yomhook,     only : lhook, dr_hook, jphook
-    use easy_netcdf, only : netcdf_file
+    use yomhook,              only : lhook, dr_hook, jphook
+    use easy_netcdf,          only : netcdf_file
 
     class(aerosol_optics_type), intent(inout) :: this
Index: /LMDZ6/trunk/libf/phylmd/ecrad/radiation/radiation_aerosol_optics_description.F90
===================================================================
--- /LMDZ6/trunk/libf/phylmd/ecrad/radiation/radiation_aerosol_optics_description.F90	(revision 4852)
+++ /LMDZ6/trunk/libf/phylmd/ecrad/radiation/radiation_aerosol_optics_description.F90	(revision 4853)
@@ -13,4 +13,6 @@
 ! Email:   r.j.hogan@ecmwf.int
 !
+
+#include "ecrad_config.h"
 
 module radiation_aerosol_optics_description
@@ -60,4 +62,7 @@
     logical, allocatable :: is_preferred_philic(:)
 
+    ! Verbosity level
+    integer :: iverbose
+    
   contains
     procedure :: read
@@ -75,5 +80,9 @@
 
     use yomhook,              only : lhook, dr_hook, jphook
+#ifdef EASY_NETCDF_READ_MPI
+    use easy_netcdf_read_mpi, only : netcdf_file
+#else
     use easy_netcdf,          only : netcdf_file
+#endif
 
     class(aerosol_optics_description_type), intent(inout) :: this
@@ -84,5 +93,5 @@
     type(netcdf_file)  :: file
 
-    real(jphook) :: hook_handle
+    real(jphook)       :: hook_handle
 
     if (lhook) call dr_hook('radiation_aerosol_optics_description:load',0,hook_handle)
@@ -108,4 +117,10 @@
     call file%close()
 
+    if (present(iverbose)) then
+      this%iverbose = iverbose
+    else
+      this%iverbose = 3
+    end if
+    
     if (lhook) call dr_hook('radiation_aerosol_optics_description:load',1,hook_handle)
 
@@ -124,5 +139,6 @@
 
     use yomhook,              only : lhook, dr_hook, jphook
-
+    use radiation_io,         only : nulout, nulerr, radiation_abort
+    
     class(aerosol_optics_description_type), intent(inout) :: this
     character(len=2), intent(in) :: code_str
@@ -132,5 +148,7 @@
     integer :: ja
 
-    real(jphook) :: hook_handle
+    logical :: is_found, is_philic, is_phobic
+
+    real(jphook)         :: hook_handle
 
     if (lhook) call dr_hook('radiation_aerosol_optics_description:preferred_optical_model',0,hook_handle)
@@ -138,6 +156,11 @@
     ! Check for empty string
     if (optical_model_str == ' ') then
+      if (lhook) call dr_hook('radiation_aerosol_optics_description:preferred_optical_model',1,hook_handle)
       return
     end if
+
+    is_found  = .false.
+    is_philic = .false.
+    is_phobic = .false.
     
     ! Loop over hydrophilic types
@@ -145,7 +168,9 @@
       ! Check if we have a match
       if (to_string(this%code_philic(:,ja)) == code_str &
-           &  .and. to_string(this%optical_model_philic(1:len(optical_model_str),ja)) &
+           &  .and. trim(to_string(this%optical_model_philic(:,ja))) &
            &          == optical_model_str) then
         this%is_preferred_philic(ja) = .true.
+        is_found  = .true.
+        is_philic = .true.
       end if
     end do
@@ -153,14 +178,33 @@
     do ja = 1,size(this%bin_phobic)
       if (to_string(this%code_phobic(:,ja)) == code_str &
-           &  .and. to_string(this%optical_model_phobic(1:len(optical_model_str),ja)) &
+           &  .and. trim(to_string(this%optical_model_phobic(:,ja))) &
            &          == optical_model_str) then
         this%is_preferred_phobic(ja) = .true.
+        is_found  = .true.
+        is_phobic = .true.
       end if
     end do
 
+    if (.not. is_found) then
+      write(nulerr,'(a,a2,a,a,a)') '*** Error: Preferred "', code_str ,'" aerosol optical model "', &
+           &  trim(optical_model_str), '" not found in file'
+      call radiation_abort()
+    else if (this%iverbose > 2) then
+      write(nulout,'(a,a2,a,a,a)',advance='no') 'Preferred "', code_str, '" aerosol optical model set to "', &
+           &  trim(optical_model_str), '" ('
+      if (is_phobic) then
+        write(nulout,'(a)',advance='no') ' hydrophobic'
+      end if
+      if (is_philic) then
+        write(nulout,'(a)',advance='no') ' hydrophilic'
+      end if
+      write(nulout,'(a)') ' )'
+    end if
+    
     if (lhook) call dr_hook('radiation_aerosol_optics_description:preferred_optical_model',1,hook_handle)
 
   end subroutine preferred_optical_model
 
+  
   !---------------------------------------------------------------------
   ! Return the index to the aerosol optical properties corresponding
@@ -179,5 +223,4 @@
     
     use yomhook,              only : lhook, dr_hook, jphook
-    use easy_netcdf,          only : netcdf_file
     use radiation_io,         only : nulout
 
@@ -234,5 +277,5 @@
           end if
           if (present(optical_model_str)) then
-            if (to_string(this%optical_model_philic(1:len(optical_model_str),ja)) &
+            if (trim(to_string(this%optical_model_philic(:,ja))) &
                  &  == optical_model_str) then
               ! Requested optical model matches
@@ -285,5 +328,5 @@
           end if
           if (present(optical_model_str)) then
-            if (to_string(this%optical_model_phobic(1:len(optical_model_str),ja)) &
+            if (trim(to_string(this%optical_model_phobic(:,ja))) &
                  &  == optical_model_str) then
               ! Requested optical model matches
@@ -315,8 +358,9 @@
 
     if (is_ambiguous) then
-      write(nulout,'(a,a2,a,l1,a)') 'Warning: get_index("', code_str, '",', lhydrophilic, &
+      write(nulout,'(a,a2,a,l,a)') 'Warning: radiation_aerosol_optics_description:get_index("', &
+           &  code_str, '",', lhydrophilic, &
            &  ',...) does not unambiguously identify an aerosol optical property index'
     end if
-
+    
     if (lhook) call dr_hook('radiation_aerosol_optics_description:get_index',1,hook_handle)
 
@@ -325,5 +369,7 @@
   !---------------------------------------------------------------------
   ! Utility function to convert an array of single characters to a
-  ! character string (yes Fortran's string handling is a bit rubbish)
+  ! character string (yes Fortran's string handling is a bit
+  ! rubbish). We set NULL characters (ASCII code 0) returned from the
+  ! NetCDF library to spaces, so that TRIM can remove them.
   pure function to_string(arr) result(str)
     character, intent(in)  :: arr(:)
@@ -331,5 +377,10 @@
     integer :: jc
     do jc = 1,size(arr)
-      str(jc:jc) = arr(jc)
+      if (ichar(arr(jc)) == 0) then
+        ! Replace NULL character with a space
+        str(jc:jc) = ' '
+      else
+        str(jc:jc) = arr(jc)
+      end if
     end do
   end function to_string
Index: /LMDZ6/trunk/libf/phylmd/ecrad/radiation/radiation_cloud.F90
===================================================================
--- /LMDZ6/trunk/libf/phylmd/ecrad/radiation/radiation_cloud.F90	(revision 4852)
+++ /LMDZ6/trunk/libf/phylmd/ecrad/radiation/radiation_cloud.F90	(revision 4853)
@@ -64,5 +64,5 @@
     ! gridbox area for use in representing 3D effects. This variable
     ! is dimensioned (ncol,nlev).
-    real(jprb), allocatable,  dimension(:,:) :: inv_cloud_effective_size ! m-1
+    real(jprb), allocatable, dimension(:,:) :: inv_cloud_effective_size ! m-1
 
     ! Similarly for the in-cloud heterogeneities, used to compute the
@@ -606,5 +606,4 @@
 
     use yomhook,                  only : lhook, dr_hook, jphook
-!    USE mod_phys_lmdz_para
 
     class(cloud_type), intent(inout) :: this
Index: /LMDZ6/trunk/libf/phylmd/ecrad/radiation/radiation_cloud_cover.F90
===================================================================
--- /LMDZ6/trunk/libf/phylmd/ecrad/radiation/radiation_cloud_cover.F90	(revision 4852)
+++ /LMDZ6/trunk/libf/phylmd/ecrad/radiation/radiation_cloud_cover.F90	(revision 4853)
@@ -19,4 +19,6 @@
 !   2020-10-07  R. Hogan  Ensure iobj1 initialized in case of alpha_obj==0
 
+#include "ecrad_config.h"
+
 module radiation_cloud_cover
 
@@ -254,5 +256,5 @@
            &  * (frac(jlev)+frac(jlev+1)-frac(jlev)*frac(jlev+1))
 ! Added for DWD (2020)
-#ifdef __SX__
+#ifdef DWD_VECTOR_OPTIMIZATIONS
     end do
     do jlev = 1,nlev-1
Index: /LMDZ6/trunk/libf/phylmd/ecrad/radiation/radiation_cloud_generator.F90
===================================================================
--- /LMDZ6/trunk/libf/phylmd/ecrad/radiation/radiation_cloud_generator.F90	(revision 4852)
+++ /LMDZ6/trunk/libf/phylmd/ecrad/radiation/radiation_cloud_generator.F90	(revision 4853)
@@ -540,9 +540,9 @@
     use radiation_pdf_sampler, only : pdf_sampler_type
     implicit none
-!#if defined(__GFORTRAN__) || defined(__PGI) || defined(__NEC__)
-!#else
-!    !$omp declare simd(sample_from_pdf_simd) uniform(this) &
-!    !$omp linear(ref(fsd)) linear(ref(cdf))
-!#endif
+#if defined(__GFORTRAN__) || defined(__PGI) || defined(__NEC__) || defined(__INTEL_LLVM_COMPILER)
+#else
+    !!$omp declare simd(sample_from_pdf_simd) uniform(this) &
+    !!$omp linear(ref(fsd)) linear(ref(cdf))
+#endif
     type(pdf_sampler_type), intent(in)  :: this
 
Index: /LMDZ6/trunk/libf/phylmd/ecrad/radiation/radiation_cloud_optics_data.F90
===================================================================
--- /LMDZ6/trunk/libf/phylmd/ecrad/radiation/radiation_cloud_optics_data.F90	(revision 4852)
+++ /LMDZ6/trunk/libf/phylmd/ecrad/radiation/radiation_cloud_optics_data.F90	(revision 4853)
@@ -13,4 +13,6 @@
 ! Email:   r.j.hogan@ecmwf.int
 !
+
+#include "ecrad_config.h"
 
 module radiation_cloud_optics_data
@@ -48,6 +50,10 @@
   subroutine setup_cloud_optics(this, liq_file_name, ice_file_name, iverbose)
     
-    use yomhook,  only : lhook, dr_hook, jphook
-    use easy_netcdf, only : netcdf_file
+    use yomhook,              only : lhook, dr_hook, jphook
+#ifdef EASY_NETCDF_READ_MPI
+    use easy_netcdf_read_mpi, only : netcdf_file
+#else
+    use easy_netcdf,          only : netcdf_file
+#endif
 
     class(cloud_optics_type), intent(inout) :: this
Index: /LMDZ6/trunk/libf/phylmd/ecrad/radiation/radiation_config.F90
===================================================================
--- /LMDZ6/trunk/libf/phylmd/ecrad/radiation/radiation_config.F90	(revision 4852)
+++ /LMDZ6/trunk/libf/phylmd/ecrad/radiation/radiation_config.F90	(revision 4853)
@@ -34,4 +34,6 @@
 !
 
+#include "ecrad_config.h"
+
 module radiation_config
 
@@ -202,5 +204,5 @@
     ! more random numbers being generated?  This is the default on NEC
     ! SX.
-#ifdef __SX__
+#ifdef DWD_VECTOR_OPTIMIZATIONS
     logical :: use_vectorizable_generator = .true.
 #else
@@ -276,5 +278,6 @@
 
     ! Codes describing the gas model
-    integer :: i_gas_model = IGasModelIFSRRTMG
+    integer :: i_gas_model_sw = IGasModelIFSRRTMG
+    integer :: i_gas_model_lw = IGasModelIFSRRTMG
 
     ! Optics if i_gas_model==IGasModelMonochromatic.
@@ -702,4 +705,5 @@
     character(511) :: ssi_override_file_name
     character(63)  :: liquid_model_name, ice_model_name, gas_model_name
+    character(63)  :: sw_gas_model_name, lw_gas_model_name
     character(63)  :: sw_solver_name, lw_solver_name, overlap_scheme_name
     character(63)  :: sw_entrapment_name, sw_encroachment_name, cloud_pdf_shape_name
@@ -709,5 +713,5 @@
          &     .false.,.false.,.false.,.false.,.false.,.false.]
     integer :: i_aerosol_type_map(NMaxAerosolTypes) ! More than 256 is an error
-
+    
     logical :: do_nearest_spectral_sw_albedo
     logical :: do_nearest_spectral_lw_emiss
@@ -716,4 +720,5 @@
     integer :: i_sw_albedo_index(NMaxAlbedoIntervals)
     integer :: i_lw_emiss_index (NMaxAlbedoIntervals)
+    integer :: i_gas_model
 
     integer :: iunit ! Unit number of namelist file
@@ -726,5 +731,5 @@
          &  do_surface_sw_spectral_flux, do_lw_derivatives, do_toa_spectral_flux, &
          &  do_lw_aerosol_scattering, do_lw_cloud_scattering, &
-         &  n_regions, directory_name, gas_model_name, &
+         &  n_regions, directory_name, gas_model_name, sw_gas_model_name, lw_gas_model_name, &
          &  ice_optics_override_file_name, liq_optics_override_file_name, &
          &  aerosol_optics_override_file_name, cloud_pdf_override_file_name, &
@@ -815,4 +820,6 @@
     encroachment_scaling = -1.0_jprb
     gas_model_name = '' !DefaultGasModelName
+    sw_gas_model_name = '' !DefaultGasModelName
+    lw_gas_model_name = '' !DefaultGasModelName
     liquid_model_name = '' !DefaultLiquidModelName
     ice_model_name = '' !DefaultIceModelName
@@ -1014,8 +1021,18 @@
          &            'ice_model_name', this%i_ice_model)
 
-    ! Determine gas optics model
+    ! Determine gas optics model(s) - firstly try the generic gas_model_name
+    i_gas_model = -1
     call get_enum_code(gas_model_name, GasModelName, &
-         &            'gas_model_name', this%i_gas_model)
-
+         &            'gas_model_name', i_gas_model)
+    if (i_gas_model > -1) then
+      this%i_gas_model_sw = i_gas_model
+      this%i_gas_model_lw = i_gas_model
+    end if
+    ! ...then the band-specific values
+    call get_enum_code(sw_gas_model_name, GasModelName, &
+         &            'sw_gas_model_name', this%i_gas_model_sw)
+    call get_enum_code(lw_gas_model_name, GasModelName, &
+         &            'lw_gas_model_name', this%i_gas_model_lw)
+   
     ! Determine solvers
     call get_enum_code(sw_solver_name, SolverName, &
@@ -1055,12 +1072,12 @@
     end if
 
-    if (this%i_gas_model == IGasModelIFSRRTMG &
-         & .and. (this%use_general_cloud_optics &
-         &        .or. this%use_general_aerosol_optics)) then
-      if (this%do_sw .and. this%do_cloud_aerosol_per_sw_g_point) then
+    if (this%use_general_cloud_optics .or. this%use_general_aerosol_optics) then
+      if (this%do_sw .and. this%do_cloud_aerosol_per_sw_g_point &
+           &  .and. this%i_gas_model_sw == IGasModelIFSRRTMG) then
         write(nulout,'(a)') 'Warning: RRTMG SW only supports cloud/aerosol/surface optical properties per band, not per g-point'
         this%do_cloud_aerosol_per_sw_g_point = .false.
       end if
-      if (this%do_lw .and. this%do_cloud_aerosol_per_lw_g_point) then
+      if (this%do_lw .and. this%do_cloud_aerosol_per_lw_g_point &
+           &  .and. this%i_gas_model_lw == IGasModelIFSRRTMG) then
         write(nulout,'(a)') 'Warning: RRTMG LW only supports cloud/aerosol/surface optical properties per band, not per g-point'
         this%do_cloud_aerosol_per_lw_g_point = .false.
@@ -1128,5 +1145,5 @@
 
     ! If ecCKD gas optics model is being used set relevant file names
-    if (this%i_gas_model == IGasModelECCKD) then
+    if (this%i_gas_model_sw == IGasModelECCKD .or. this%i_gas_model_lw == IGasModelECCKD) then
 
       ! This gas optics model usually used with general cloud and
@@ -1138,4 +1155,8 @@
         write(nulout,'(a)') 'Warning: ecCKD gas optics model usually used with general aerosol optics'
       end if
+
+    end if
+
+    if (this%i_gas_model_sw == IGasModelECCKD) then
 
       if (len_trim(this%gas_optics_sw_override_file_name) > 0) then
@@ -1153,4 +1174,8 @@
       end if
 
+    end if
+
+    if (this%i_gas_model_lw == IGasModelECCKD) then
+
       if (len_trim(this%gas_optics_lw_override_file_name) > 0) then
         if (this%gas_optics_lw_override_file_name(1:1) == '/') then
@@ -1170,5 +1195,5 @@
 
     if (this%use_spectral_solar_cycle) then
-      if (this%i_gas_model /= IGasModelECCKD) then
+      if (this%i_gas_model_sw /= IGasModelECCKD) then
         write(nulerr,'(a)') '*** Error: solar cycle only available with ecCKD gas optics model'
         call radiation_abort('Radiation configuration error')
@@ -1278,10 +1303,17 @@
     end if
 
-    ! In the monochromatic case we need to override the liquid, ice
-    ! and aerosol models to ensure compatibility
-    if (this%i_gas_model == IGasModelMonochromatic) then
+    if (this%i_gas_model_sw == IGasModelMonochromatic .or. this%i_gas_model_lw == IGasModelMonochromatic) then
+
+      if (this%i_gas_model_sw /= this%i_gas_model_lw) then
+        write(nulerr,'(a,i0)') '*** Error: Monochromatic gas optics model must be used in shortwave and longwave'
+        call radiation_abort('Radiation configuration error')
+      end if
+    
+      ! In the monochromatic case we need to override the liquid, ice
+      ! and aerosol models to ensure compatibility
       this%i_liq_model = ILiquidModelMonochromatic
       this%i_ice_model = IIceModelMonochromatic
       this%use_aerosols = .false.
+      
     end if
 
@@ -1392,6 +1424,8 @@
       call print_logical('  Saving spectral flux profiles', &
            &   'do_save_spectral_flux', this%do_save_spectral_flux)
-      call print_enum('  Gas model is', GasModelName, 'i_gas_model', &
-           &          this%i_gas_model)
+      call print_enum('  Shortwave gas model is', GasModelName, 'i_gas_model_sw', &
+           &          this%i_gas_model_sw)
+      call print_enum('  Longwave gas model is', GasModelName, 'i_gas_model_lw', &
+           &          this%i_gas_model_lw)
       call print_logical('  Aerosols are', 'use_aerosols', this%use_aerosols)
       if (this%use_aerosols) then
@@ -1481,5 +1515,5 @@
              &          'i_solver_sw', this%i_solver_sw)
         
-        if (this%i_gas_model == IGasModelMonochromatic) then
+        if (this%i_gas_model_sw == IGasModelMonochromatic) then
           call print_real('  Shortwave atmospheric optical depth', &
                &   'mono_sw_total_od', this%mono_sw_total_od)
@@ -1502,5 +1536,5 @@
              &          this%i_solver_lw)
 
-        if (this%i_gas_model == IGasModelMonochromatic) then
+        if (this%i_gas_model_lw == IGasModelMonochromatic) then
           if (this%mono_lw_wavelength > 0.0_jprb) then
             call print_real('  Longwave effective wavelength (m)', &
Index: /LMDZ6/trunk/libf/phylmd/ecrad/radiation/radiation_ecckd.F90
===================================================================
--- /LMDZ6/trunk/libf/phylmd/ecrad/radiation/radiation_ecckd.F90	(revision 4852)
+++ /LMDZ6/trunk/libf/phylmd/ecrad/radiation/radiation_ecckd.F90	(revision 4853)
@@ -15,4 +15,6 @@
 !
 
+#include "ecrad_config.h"
+
 module radiation_ecckd
 
@@ -105,5 +107,5 @@
 ! Vectorized version of the optical depth look-up performs better on
 ! NEC, but slower on x86
-#ifdef __SX__
+#ifdef DWD_VECTOR_OPTIMIZATIONS
     procedure :: calc_optical_depth => calc_optical_depth_ckd_model_vec
 #else
@@ -125,7 +127,11 @@
   subroutine read_ckd_model(this, filename, iverbose)
 
-    use easy_netcdf,  only : netcdf_file
+#ifdef EASY_NETCDF_READ_MPI
+    use easy_netcdf_read_mpi, only : netcdf_file
+#else
+    use easy_netcdf,          only : netcdf_file
+#endif
     !use radiation_io, only : nulerr, radiation_abort
-    use yomhook,      only : lhook, dr_hook, jphook
+    use yomhook,              only : lhook, dr_hook, jphook
 
     class(ckd_model_type), intent(inout) :: this
@@ -166,6 +172,4 @@
     this%d_log_pressure = log(pressure_lut(2)) - this%log_pressure1
     call file%get('temperature', temperature_full)
-    ! AI oct 2023 ajout pour le double appel de ecrad    
-    if (allocated(this%temperature1)) deallocate(this%temperature1)
     allocate(this%temperature1(this%npress));
     this%temperature1 = temperature_full(:,1)
@@ -200,5 +204,4 @@
     ! Read gases
     call file%get('n_gases', this%ngas)
-    if (allocated(this%single_gas)) deallocate(this%single_gas)
     allocate(this%single_gas(this%ngas))
     call file%get_global_attribute('constituent_id', constituent_id)
@@ -292,7 +295,11 @@
   subroutine read_spectral_solar_cycle(this, filename, iverbose, use_updated_solar_spectrum)
 
-    use easy_netcdf,  only : netcdf_file
-    use radiation_io, only : nulout, nulerr, radiation_abort
-    use yomhook,      only : lhook, dr_hook, jphook
+#ifdef EASY_NETCDF_READ_MPI
+    use easy_netcdf_read_mpi, only : netcdf_file
+#else
+    use easy_netcdf,          only : netcdf_file
+#endif
+    use radiation_io,         only : nulout, nulerr, radiation_abort
+    use yomhook,              only : lhook, dr_hook, jphook
 
     ! Reference total solar irradiance (W m-2)
@@ -450,5 +457,5 @@
   subroutine calc_optical_depth_ckd_model(this, ncol, nlev, istartcol, iendcol, nmaxgas, &
        &  pressure_hl, temperature_fl, mole_fraction_fl, &
-       &  optical_depth_fl, rayleigh_od_fl)
+       &  optical_depth_fl, rayleigh_od_fl, concentration_scaling)
 
     use yomhook,             only : lhook, dr_hook, jphook
@@ -466,4 +473,6 @@
     ! Gas mole fractions at full levels (mol mol-1), dimensioned (ncol,nlev,nmaxgas)
     real(jprb),            intent(in)  :: mole_fraction_fl(ncol,nlev,nmaxgas)
+    ! Optional concentration scaling of each gas
+    real(jprb), optional,  intent(in)  :: concentration_scaling(nmaxgas)
     
     ! Output variables
@@ -486,4 +495,5 @@
 
     real(jprb) :: multiplier(nlev), simple_multiplier(nlev), global_multiplier, temperature1
+    real(jprb) :: scaling
 
     ! Indices and weights in temperature, pressure and concentration interpolation
@@ -547,4 +557,8 @@
             multiplier = simple_multiplier * mole_fraction_fl(jcol,:,igascode)
 
+            if (present(concentration_scaling)) then
+              multiplier = multiplier * concentration_scaling(igascode)
+            end if
+            
             do jlev = 1,nlev
               optical_depth_fl(:,jlev,jcol) = optical_depth_fl(:,jlev,jcol) &
@@ -557,6 +571,14 @@
           case (IConcDependenceRelativeLinear)
             molar_abs => this%single_gas(jgas)%molar_abs
-            multiplier = simple_multiplier  * (mole_fraction_fl(jcol,:,igascode) &
-                 &                            - single_gas%reference_mole_frac)
+
+            if (present(concentration_scaling)) then
+              multiplier = simple_multiplier &
+                   &  * (mole_fraction_fl(jcol,:,igascode)*concentration_scaling(igascode) &
+                   &     - single_gas%reference_mole_frac)
+            else
+              multiplier = simple_multiplier  * (mole_fraction_fl(jcol,:,igascode) &
+                   &                            - single_gas%reference_mole_frac)
+            end if
+            
             do jlev = 1,nlev
               optical_depth_fl(:,jlev,jcol) = optical_depth_fl(:,jlev,jcol) &
@@ -579,4 +601,11 @@
 
           case (IConcDependenceLUT)
+
+            if (present(concentration_scaling)) then
+              scaling = concentration_scaling(igascode)
+            else
+              scaling = 1.0_jprb
+            end if
+            
             ! Logarithmic interpolation in concentration space
             molar_abs_conc => this%single_gas(jgas)%molar_abs_conc
@@ -584,5 +613,5 @@
             do jlev = 1,nlev
               ! Take care of mole_fraction == 0
-              log_conc = log(max(mole_fraction_fl(jcol,jlev,igascode), mole_frac1))
+              log_conc = log(max(mole_fraction_fl(jcol,jlev,igascode)*scaling, mole_frac1))
               cindex1  = (log_conc - single_gas%log_mole_frac1) / single_gas%d_log_mole_frac
               cindex1  = 1.0_jprb + max(0.0_jprb, min(cindex1, single_gas%n_mole_frac-1.0001_jprb))
@@ -601,5 +630,5 @@
             do jlev = 1,nlev
               optical_depth_fl(:,jlev,jcol) = optical_depth_fl(:,jlev,jcol) &
-                   &  + (simple_multiplier(jlev) * mole_fraction_fl(jcol,jlev,igascode)) * ( &
+                   &  + (simple_multiplier(jlev) * mole_fraction_fl(jcol,jlev,igascode) * scaling) * ( &
                    &      (cw1(jlev) * tw1(jlev) * pw1(jlev)) * molar_abs_conc(:,ip1(jlev),it1(jlev),ic1(jlev)) &
                    &     +(cw1(jlev) * tw1(jlev) * pw2(jlev)) * molar_abs_conc(:,ip1(jlev)+1,it1(jlev),ic1(jlev)) &
Index: /LMDZ6/trunk/libf/phylmd/ecrad/radiation/radiation_ecckd_gas.F90
===================================================================
--- /LMDZ6/trunk/libf/phylmd/ecrad/radiation/radiation_ecckd_gas.F90	(revision 4852)
+++ /LMDZ6/trunk/libf/phylmd/ecrad/radiation/radiation_ecckd_gas.F90	(revision 4853)
@@ -14,4 +14,6 @@
 ! License: see the COPYING file for details
 !
+
+#include "ecrad_config.h"
 
 module radiation_ecckd_gas
@@ -82,5 +84,9 @@
   subroutine read_ckd_gas(this, file, gas_name, i_gas_code)
 
-    use easy_netcdf, only : netcdf_file
+#ifdef EASY_NETCDF_READ_MPI
+    use easy_netcdf_read_mpi, only : netcdf_file
+#else
+    use easy_netcdf,          only : netcdf_file
+#endif
 
     class(ckd_gas_type), intent(inout) :: this
Index: /LMDZ6/trunk/libf/phylmd/ecrad/radiation/radiation_ecckd_interface.F90
===================================================================
--- /LMDZ6/trunk/libf/phylmd/ecrad/radiation/radiation_ecckd_interface.F90	(revision 4852)
+++ /LMDZ6/trunk/libf/phylmd/ecrad/radiation/radiation_ecckd_interface.F90	(revision 4853)
@@ -39,5 +39,5 @@
     if (lhook) call dr_hook('radiation_ecckd_interface:setup_gas_optics',0,hook_handle)
 
-    if (config%do_sw) then
+    if (config%do_sw .and. config%i_gas_model_sw == IGasModelECCKD) then
 
       ! Read shortwave ecCKD gas optics NetCDF file
@@ -57,16 +57,7 @@
       end if
 
-!      if (allocated(config%i_band_from_g_sw)) deallocate(config%i_band_from_g_sw)
-!      allocate(config%i_band_from_g_sw(config%n_g_sw))
-!      if (allocated(config%i_band_from_reordered_g_sw)) deallocate(config%i_band_from_reordered_g_sw)
-!      allocate(config%i_band_from_reordered_g_sw(config%n_g_sw))
-!      if (allocated(config%i_g_from_reordered_g_sw)) deallocate(config%i_g_from_reordered_g_sw)
-!      allocate(config%i_g_from_reordered_g_sw(config%n_g_sw))
-      if (.not.allocated(config%i_band_from_g_sw)) &
-              allocate(config%i_band_from_g_sw(config%n_g_sw))
-      if (.not.allocated(config%i_band_from_reordered_g_sw)) &
-              allocate(config%i_band_from_reordered_g_sw(config%n_g_sw))
-      if (.not.allocated(config%i_g_from_reordered_g_sw)) &
-              allocate(config%i_g_from_reordered_g_sw(config%n_g_sw))
+      allocate(config%i_band_from_g_sw          (config%n_g_sw))
+      allocate(config%i_band_from_reordered_g_sw(config%n_g_sw))
+      allocate(config%i_g_from_reordered_g_sw   (config%n_g_sw))
         
       if (config%do_cloud_aerosol_per_sw_g_point) then
@@ -93,5 +84,5 @@
     end if
 
-    if (config%do_lw) then
+    if (config%do_lw .and. config%i_gas_model_lw == IGasModelECCKD) then
 
       ! Read longwave ecCKD gas optics NetCDF file
@@ -111,17 +102,7 @@
       end if
 
-!      if (allocated(config%i_band_from_g_lw)) deallocate(config%i_band_from_g_lw)
-!      allocate(config%i_band_from_g_lw          (config%n_g_lw))
-!      if (allocated(config%i_band_from_reordered_g_lw)) deallocate(config%i_band_from_reordered_g_lw)
-!      allocate(config%i_band_from_reordered_g_lw(config%n_g_lw))
-!      if (allocated(config%i_g_from_reordered_g_lw)) deallocate(config%i_g_from_reordered_g_lw)
-!      allocate(config%i_g_from_reordered_g_lw   (config%n_g_lw))
-      if (.not.allocated(config%i_band_from_g_lw)) &
-         allocate(config%i_band_from_g_lw          (config%n_g_lw))
-      if (.not.allocated(config%i_band_from_reordered_g_lw)) &
-         allocate(config%i_band_from_reordered_g_lw(config%n_g_lw))
-      if (.not.allocated(config%i_g_from_reordered_g_lw)) &
-         allocate(config%i_g_from_reordered_g_lw   (config%n_g_lw))
-
+      allocate(config%i_band_from_g_lw          (config%n_g_lw))
+      allocate(config%i_band_from_reordered_g_lw(config%n_g_lw))
+      allocate(config%i_g_from_reordered_g_lw   (config%n_g_lw))
 
       if (config%do_cloud_aerosol_per_lw_g_point) then
@@ -199,5 +180,5 @@
     use yomhook,  only : lhook, dr_hook, jphook
 
-    use radiation_config,         only : config_type
+    use radiation_config,         only : config_type, IGasModelECCKD
     use radiation_thermodynamics, only : thermodynamics_type
     use radiation_single_level,   only : single_level_type
@@ -242,5 +223,9 @@
     real(jprb) :: temperature_fl(istartcol:iendcol,nlev)
 
-    integer :: jcol
+    real(jprb) :: concentration_scaling(NMaxGases)
+    
+    logical :: is_volume_mixing_ratio
+    
+    integer :: jcol, jlev, jg
 
     real(jphook) :: hook_handle
@@ -259,19 +244,40 @@
          &  / (thermodynamics%pressure_hl(istartcol:iendcol,1:nlev) &
          &    +thermodynamics%pressure_hl(istartcol:iendcol,2:nlev+1))
- 
-    if (config%do_sw) then
-
-      call config%gas_optics_sw%calc_optical_depth(ncol,nlev,istartcol,iendcol, &
-           &  NMaxGases, thermodynamics%pressure_hl, &
-           &  temperature_fl, &
-           &  gas%mixing_ratio, &
-!           &  reshape(gas%mixing_ratio(istartcol:iendcol,:,:), &
-!           &          [nlev,iendcol-istartcol+1,NMaxGases],order=[2,1,3]), &
-           &  od_sw, rayleigh_od_fl=ssa_sw)
+
+    ! Check that the gas concentrations are stored in volume mixing
+    ! ratio with no scaling; if not, return a vector of scalings
+    call gas%assert_units(IVolumeMixingRatio, scale_factor=1.0_jprb, &
+         &                istatus=is_volume_mixing_ratio)
+    if (.not. is_volume_mixing_ratio) then
+      call gas%get_scaling(IVolumeMixingRatio, concentration_scaling)
+    else
+      concentration_scaling = 1.0_jprb
+    end if
+    
+    if (config%do_sw .and. config%i_gas_model_sw == IGasModelECCKD) then
+
+      if (is_volume_mixing_ratio) then
+        call config%gas_optics_sw%calc_optical_depth(ncol,nlev,istartcol,iendcol, &
+             &  NMaxGases, thermodynamics%pressure_hl, &
+             &  temperature_fl, gas%mixing_ratio, &
+             &  od_sw, rayleigh_od_fl=ssa_sw)
+      else
+        call config%gas_optics_sw%calc_optical_depth(ncol,nlev,istartcol,iendcol, &
+             &  NMaxGases, thermodynamics%pressure_hl, &
+             &  temperature_fl, gas%mixing_ratio, &
+             &  od_sw, rayleigh_od_fl=ssa_sw, concentration_scaling=concentration_scaling)
+      end if
+      
       ! At this point od_sw = absorption optical depth and ssa_sw =
       ! rayleigh optical depth: convert to total optical depth and
       ! single-scattering albedo
-      od_sw = od_sw + ssa_sw
-      ssa_sw = ssa_sw / od_sw
+      do jcol = istartcol,iendcol
+        do jlev = 1, nlev
+          do jg = 1, config%n_g_sw
+            od_sw(jg,jlev,jcol)  = od_sw(jg,jlev,jcol) + ssa_sw(jg,jlev,jcol)
+            ssa_sw(jg,jlev,jcol) = ssa_sw(jg,jlev,jcol) / od_sw(jg,jlev,jcol)
+          end do
+        end do
+      end do
 
       if (present(incoming_sw)) then
@@ -287,13 +293,17 @@
     end if
 
-    if (config%do_lw) then
-
-      call config%gas_optics_lw%calc_optical_depth(ncol,nlev,istartcol,iendcol, &
-           &  NMaxGases, thermodynamics%pressure_hl, &
-           &  temperature_fl, &
-           &  gas%mixing_ratio, &
-!           &  reshape(gas%mixing_ratio(istartcol:iendcol,:,:), &
-!           &          [nlev,iendcol-istartcol+1,NMaxGases],order=[2,1,3]), &
-           &  od_lw)
+    if (config%do_lw .and. config%i_gas_model_lw == IGasModelECCKD) then
+
+      if (is_volume_mixing_ratio) then
+        call config%gas_optics_lw%calc_optical_depth(ncol,nlev,istartcol,iendcol, &
+             &  NMaxGases, thermodynamics%pressure_hl, &
+             &  temperature_fl, gas%mixing_ratio, &
+             &  od_lw)
+      else
+        call config%gas_optics_lw%calc_optical_depth(ncol,nlev,istartcol,iendcol, &
+             &  NMaxGases, thermodynamics%pressure_hl, &
+             &  temperature_fl, gas%mixing_ratio, &
+             &  od_lw, concentration_scaling=concentration_scaling)
+      end if
 
       ! Calculate the Planck function for each g point
@@ -305,4 +315,5 @@
            &  single_level%skin_temperature(istartcol:iendcol), &
            &  lw_emission(:,:))
+!NEC$ forced_collapse
       lw_emission = lw_emission * (1.0_jprb - lw_albedo)
 
Index: /LMDZ6/trunk/libf/phylmd/ecrad/radiation/radiation_flux.F90
===================================================================
--- /LMDZ6/trunk/libf/phylmd/ecrad/radiation/radiation_flux.F90	(revision 4852)
+++ /LMDZ6/trunk/libf/phylmd/ecrad/radiation/radiation_flux.F90	(revision 4853)
@@ -20,4 +20,6 @@
 !   2021-01-20  R. Hogan  Added heating_rate_out_of_physical_bounds function
 !   2022-12-07  R. Hogan  Added top-of-atmosphere spectral output
+
+#include "ecrad_config.h"
 
 module radiation_flux
@@ -117,5 +119,5 @@
 
 ! Added for DWD (2020)
-#ifdef __SX__
+#ifdef DWD_VECTOR_OPTIMIZATIONS
       logical, parameter :: use_indexed_sum_vec = .true.
 #else
Index: /LMDZ6/trunk/libf/phylmd/ecrad/radiation/radiation_gas.F90
===================================================================
--- /LMDZ6/trunk/libf/phylmd/ecrad/radiation/radiation_gas.F90	(revision 4852)
+++ /LMDZ6/trunk/libf/phylmd/ecrad/radiation/radiation_gas.F90	(revision 4853)
@@ -72,4 +72,5 @@
      procedure :: assert_units => assert_units_gas
      procedure :: get        => get_gas
+     procedure :: get_scaling
      procedure :: reverse    => reverse_gas
      procedure :: out_of_physical_bounds
@@ -355,5 +356,5 @@
     real(jprb), optional, intent(in)    :: scale_factor
 
-    integer :: ig
+    integer :: jg
 
     ! Scaling factor to convert from old to new
@@ -396,6 +397,6 @@
       end if
     else
-      do ig = 1,this%ntype
-        call this%set_units(iunits, igas=this%icode(ig), scale_factor=new_sf)
+      do jg = 1,this%ntype
+        call this%set_units(iunits, igas=this%icode(jg), scale_factor=new_sf)
       end do
     end if
@@ -403,21 +404,46 @@
   end subroutine set_units_gas
 
-
+  
+  !---------------------------------------------------------------------
+  ! Return a vector indicating the scaling that one would need to
+  ! apply to each gas in order to obtain the dimension units in
+  ! "iunits" (which can be IVolumeMixingRatio or IMassMixingRatio)
+  subroutine get_scaling(this, iunits, scaling)
+    class(gas_type), intent(in)  :: this
+    integer,         intent(in)  :: iunits
+    real(jprb),      intent(out) :: scaling(NMaxGases)
+    integer :: jg
+    
+    scaling = this%scale_factor
+    do jg = 1,NMaxGases
+      if (iunits == IMassMixingRatio .and. this%iunits(jg) == IVolumeMixingRatio) then
+        scaling(jg) = scaling(jg) * GasMolarMass(jg) / AirMolarMass
+      else if (iunits == IVolumeMixingRatio .and. this%iunits(jg) == IMassMixingRatio) then
+        scaling(jg) = scaling(jg) * AirMolarMass / GasMolarMass(jg)
+      end if
+    end do
+    
+  end subroutine get_scaling
+
+  
   !---------------------------------------------------------------------
   ! Assert that gas mixing ratio units are "iunits", applying to gas
   ! with ID "igas" if present, otherwise to all gases. Otherwise the
-  ! program will exit. Otional argument scale factor specifies any
-  ! subsequent multiplication to apply; for PPMV one would use
-  ! iunits=IVolumeMixingRatio and scale_factor=1.0e6.
-  recursive subroutine assert_units_gas(this, iunits, igas, scale_factor)
+  ! program will exit, except if the optional argument "istatus" is
+  ! provided in which case it will return true if the units are
+  ! correct and false if they are not. Optional argument scale factor
+  ! specifies any subsequent multiplication to apply; for PPMV one
+  ! would use iunits=IVolumeMixingRatio and scale_factor=1.0e6.
+  recursive subroutine assert_units_gas(this, iunits, igas, scale_factor, istatus)
 
     use radiation_io,   only : nulerr, radiation_abort
 
-    class(gas_type),      intent(in) :: this
-    integer,              intent(in) :: iunits
-    integer,    optional, intent(in) :: igas
-    real(jprb), optional, intent(in) :: scale_factor
-
-    integer :: ig
+    class(gas_type),      intent(in)  :: this
+    integer,              intent(in)  :: iunits
+    integer,    optional, intent(in)  :: igas
+    real(jprb), optional, intent(in)  :: scale_factor
+    logical,    optional, intent(out) :: istatus
+
+    integer :: jg
 
     real(jprb) :: sf
@@ -429,20 +455,32 @@
     end if
 
+    if (present(istatus)) then
+      istatus = .true.
+    end if
+    
     if (present(igas)) then
       if (this%is_present(igas)) then
         if (iunits /= this%iunits(igas)) then
-          write(nulerr,'(a,a,a)') '*** Error: ', trim(GasName(igas)), &
-               &  ' is not in the required units'
-          call radiation_abort()
+          if (present(istatus)) then
+            istatus = .false.
+          else
+            write(nulerr,'(a,a,a)') '*** Error: ', trim(GasName(igas)), &
+                 &  ' is not in the required units'
+            call radiation_abort()
+          end if
         else if (sf /= this%scale_factor(igas)) then
-          write(nulerr,'(a,a,a,e12.4,a,e12.4)') '*** Error: ', GasName(igas), &
-               &  ' scaling of ', this%scale_factor(igas), &
-               &  ' does not match required ', sf
-          call radiation_abort()
+          if (present(istatus)) then
+            istatus = .false.
+          else
+            write(nulerr,'(a,a,a,e12.4,a,e12.4)') '*** Error: ', GasName(igas), &
+                 &  ' scaling of ', this%scale_factor(igas), &
+                 &  ' does not match required ', sf
+            call radiation_abort()
+          end if
         end if
       end if
     else
-      do ig = 1,this%ntype
-        call this%assert_units(iunits, igas=this%icode(ig), scale_factor=sf)
+      do jg = 1,this%ntype
+        call this%assert_units(iunits, igas=this%icode(jg), scale_factor=sf, istatus=istatus)
       end do
     end if
Index: /LMDZ6/trunk/libf/phylmd/ecrad/radiation/radiation_general_cloud_optics.F90
===================================================================
--- /LMDZ6/trunk/libf/phylmd/ecrad/radiation/radiation_general_cloud_optics.F90	(revision 4852)
+++ /LMDZ6/trunk/libf/phylmd/ecrad/radiation/radiation_general_cloud_optics.F90	(revision 4853)
@@ -75,10 +75,8 @@
     ! Allocate structures
     if (config%do_sw) then
-      if (allocated(config%cloud_optics_sw)) deallocate(config%cloud_optics_sw)      
       allocate(config%cloud_optics_sw(config%n_cloud_types))
     end if
 
     if (config%do_lw) then
-      if (allocated(config%cloud_optics_lw)) deallocate(config%cloud_optics_lw)      
       allocate(config%cloud_optics_lw(config%n_cloud_types))
     end if
@@ -172,5 +170,5 @@
     real(jprb), dimension(istartcol:iendcol,nlev) :: water_path
 
-    integer :: jtype, jcol, jlev
+    integer :: jtype, jcol, jlev, jg
 
     real(jphook) :: hook_handle
@@ -275,8 +273,10 @@
           if (cloud%fraction(jcol,jlev) > 0.0_jprb) then
             ! Scale to get asymmetry factor and single scattering albedo
-            g_sw_cloud(:,jlev,jcol) = g_sw_cloud(:,jlev,jcol) &
-                 &  / max(ssa_sw_cloud(:,jlev,jcol), 1.0e-15_jprb)
-            ssa_sw_cloud(:,jlev,jcol) = ssa_sw_cloud(:,jlev,jcol) &
-                 &  / max(od_sw_cloud(:,jlev,jcol),  1.0e-15_jprb)
+            do jg = 1, config%n_bands_sw
+              g_sw_cloud(jg,jlev,jcol) = g_sw_cloud(jg,jlev,jcol) &
+                 &  / max(ssa_sw_cloud(jg,jlev,jcol), 1.0e-15_jprb)
+              ssa_sw_cloud(jg,jlev,jcol) = ssa_sw_cloud(jg,jlev,jcol) &
+                 &  / max(od_sw_cloud(jg,jlev,jcol),  1.0e-15_jprb)
+            end do
           end if
         end do
Index: /LMDZ6/trunk/libf/phylmd/ecrad/radiation/radiation_general_cloud_optics_data.F90
===================================================================
--- /LMDZ6/trunk/libf/phylmd/ecrad/radiation/radiation_general_cloud_optics_data.F90	(revision 4852)
+++ /LMDZ6/trunk/libf/phylmd/ecrad/radiation/radiation_general_cloud_optics_data.F90	(revision 4853)
@@ -15,4 +15,6 @@
 !
 
+#include "ecrad_config.h"
+
 module radiation_general_cloud_optics_data
 
@@ -73,5 +75,9 @@
 
     use yomhook,                       only : lhook, dr_hook, jphook
-    use easy_netcdf,                   only : netcdf_file
+#ifdef EASY_NETCDF_READ_MPI
+    use easy_netcdf_read_mpi, only : netcdf_file
+#else
+    use easy_netcdf,          only : netcdf_file
+#endif
     use radiation_spectral_definition, only : spectral_definition_type
     use radiation_io,                  only : nulout, nulerr, radiation_abort
@@ -181,8 +187,4 @@
 
     ! Thin averaging
-
-    ! Circumvent ifort bug (see https://github.com/ecmwf-ifs/ecrad/issues/13):
-    allocate(this%mass_ext(size(mapping, 1), nre))
-
     this%mass_ext  = matmul(mapping, mass_ext)
     this%ssa       = matmul(mapping, mass_ext*ssa) / this%mass_ext
@@ -267,10 +269,10 @@
          &     scat_asymmetry ! Scattering optical depth x asymmetry factor
 
-    real(jprb) :: od_local(ng)
+    real(jprb) :: od_local
 
     real(jprb) :: re_index, weight1, weight2
     integer :: ire
 
-    integer :: jcol, jlev
+    integer :: jcol, jlev, jg
 
     real(jphook) :: hook_handle
@@ -287,13 +289,16 @@
             weight2 = re_index - ire
             weight1 = 1.0_jprb - weight2
-            od_local = water_path(jcol, jlev) * (weight1*this%mass_ext(:,ire) &
-                 &                              +weight2*this%mass_ext(:,ire+1))
-            od(:,jlev,jcol) = od(:,jlev,jcol) + od_local
-            od_local = od_local * (weight1*this%ssa(:,ire) &
-                 &                +weight2*this%ssa(:,ire+1))
-            scat_od(:,jlev,jcol) = scat_od(:,jlev,jcol) + od_local
-            scat_asymmetry(:,jlev,jcol) = scat_asymmetry(:,jlev,jcol) &
-                 & + od_local * (weight1*this%asymmetry(:,ire) &
-                 &              +weight2*this%asymmetry(:,ire+1))
+            do jg = 1, ng
+              od_local = water_path(jcol, jlev) * (weight1*this%mass_ext(jg,ire) &
+                 &                                +weight2*this%mass_ext(jg,ire+1))
+              od(jg,jlev,jcol) = od(jg,jlev,jcol) + od_local
+              od_local = od_local * (weight1*this%ssa(jg,ire) &
+                 &                  +weight2*this%ssa(jg,ire+1))
+              scat_od(jg,jlev,jcol) = scat_od(jg,jlev,jcol) + od_local
+              scat_asymmetry(jg,jlev,jcol) = scat_asymmetry(jg,jlev,jcol) &
+                 & + od_local * (weight1*this%asymmetry(jg,ire) &
+                 &              +weight2*this%asymmetry(jg,ire+1))
+            end do
+
           end if
         end do
Index: /LMDZ6/trunk/libf/phylmd/ecrad/radiation/radiation_ifs_rrtm.F90
===================================================================
--- /LMDZ6/trunk/libf/phylmd/ecrad/radiation/radiation_ifs_rrtm.F90	(revision 4852)
+++ /LMDZ6/trunk/libf/phylmd/ecrad/radiation/radiation_ifs_rrtm.F90	(revision 4853)
@@ -41,4 +41,6 @@
 
     use radiation_config
+    use radiation_spectral_definition, only &
+         &  : SolarReferenceTemperature, TerrestrialReferenceTemperature
 
     type(config_type), intent(inout), target :: config
@@ -65,4 +67,6 @@
           &   44, 107, 94, 14, 108, 15, 16, 109, 17, 18, 110, 111, 112 &
           & /)
+
+    logical :: do_sw, do_lw
     
     real(jphook) :: hook_handle
@@ -77,4 +81,7 @@
     if (lhook) call dr_hook('radiation_ifs_rrtm:setup_gas_optics',0,hook_handle)
 
+    do_sw = (config%do_sw .and. config%i_gas_model_sw == IGasModelIFSRRTMG)
+    do_lw = (config%do_lw .and. config%i_gas_model_lw == IGasModelIFSRRTMG)
+    
     ! The IFS implementation of RRTMG uses many global variables.  In
     ! the IFS these will have been set up already; otherwise set them
@@ -85,88 +92,106 @@
       call SURRTPK
       call SURRTRF
-      call RRTM_INIT_140GP(directory)
-      call SRTM_INIT(directory)
+      if (do_lw) then
+        call RRTM_INIT_140GP(directory)
+      end if
+      if (do_sw) then
+        call SRTM_INIT(directory)
+      end if
     end if
 
-    ! Cloud and aerosol properties can only be defined per band
-    config%do_cloud_aerosol_per_sw_g_point = .false.
-    config%do_cloud_aerosol_per_lw_g_point = .false.
-
-    config%n_g_sw = jpgsw
-    config%n_g_lw = jpglw
-    config%n_bands_sw = 14
-    config%n_bands_lw = 16
-
-    ! Wavenumber ranges of each band may be needed so that the user
-    ! can compute UV and photosynthetically active radiation for a
-    ! particular wavelength range
-    call config%gas_optics_sw%spectral_def%allocate_bands_only( &
-         &  [2600.0_jprb, 3250.0_jprb, 4000.0_jprb, 4650.0_jprb, 5150.0_jprb, 6150.0_jprb, 7700.0_jprb, &
-         &   8050.0_jprb, 12850.0_jprb, 16000.0_jprb, 22650.0_jprb, 29000.0_jprb, 38000.0_jprb, 820.0_jprb], &
-         &  [3250.0_jprb, 4000.0_jprb, 4650.0_jprb, 5150.0_jprb, 6150.0_jprb, 7700.0_jprb, 8050.0_jprb, &
-         &   12850.0_jprb, 16000.0_jprb, 22650.0_jprb, 29000.0_jprb, 38000.0_jprb, 50000.0_jprb, 2600.0_jprb])
-    call config%gas_optics_lw%spectral_def%allocate_bands_only( &
-         &  [10.0_jprb, 350.0_jprb, 500.0_jprb, 630.0_jprb, 700.0_jprb, 820.0_jprb, 980.0_jprb, 1080.0_jprb, &
-         &   1180.0_jprb, 1390.0_jprb, 1480.0_jprb, 1800.0_jprb, 2080.0_jprb, 2250.0_jprb, 2380.0_jprb, 2600.0_jprb], &
-         &  [350.0_jprb, 500.0_jprb, 630.0_jprb, 700.0_jprb, 820.0_jprb, 980.0_jprb, 1080.0_jprb, 1180.0_jprb, &
-         &   1390.0_jprb, 1480.0_jprb, 1800.0_jprb, 2080.0_jprb, 2250.0_jprb, 2380.0_jprb, 2600.0_jprb, 3250.0_jprb])
-
-    allocate(config%i_band_from_g_sw          (config%n_g_sw))
-    allocate(config%i_band_from_g_lw          (config%n_g_lw))
-    allocate(config%i_band_from_reordered_g_sw(config%n_g_sw))
-    allocate(config%i_band_from_reordered_g_lw(config%n_g_lw))
-    allocate(config%i_g_from_reordered_g_sw(config%n_g_sw))
-    allocate(config%i_g_from_reordered_g_lw(config%n_g_lw))
-
-    ! Shortwave starts at 16: need to start at 1
-    config%i_band_from_g_sw = ngb_sw - ngb_sw(1)+1
-    config%i_band_from_g_lw = ngb_lw
-
-    if (config%i_solver_sw == ISolverSpartacus) then
-      ! SPARTACUS requires g points ordered in approximately
-      ! increasing order of optical depth
-      config%i_g_from_reordered_g_sw = RRTM_GPOINT_REORDERING_SW
-    else
-      ! Implied-do for no reordering
-!      config%i_g_from_reordered_g_sw = RRTM_GPOINT_REORDERING_SW
-      config%i_g_from_reordered_g_sw = (/ (irep, irep=1,config%n_g_sw) /)
+    if (do_sw) then
+      
+      ! Cloud and aerosol properties can only be defined per band
+      config%do_cloud_aerosol_per_sw_g_point = .false.
+      config%n_g_sw = jpgsw
+      config%n_bands_sw = 14
+      ! Wavenumber ranges of each band may be needed so that the user
+      ! can compute UV and photosynthetically active radiation for a
+      ! particular wavelength range
+      call config%gas_optics_sw%spectral_def%allocate_bands_only(SolarReferenceTemperature, &
+           &  [2600.0_jprb, 3250.0_jprb, 4000.0_jprb, 4650.0_jprb, 5150.0_jprb, 6150.0_jprb, 7700.0_jprb, &
+           &   8050.0_jprb, 12850.0_jprb, 16000.0_jprb, 22650.0_jprb, 29000.0_jprb, 38000.0_jprb, 820.0_jprb], &
+           &  [3250.0_jprb, 4000.0_jprb, 4650.0_jprb, 5150.0_jprb, 6150.0_jprb, 7700.0_jprb, 8050.0_jprb, &
+           &   12850.0_jprb, 16000.0_jprb, 22650.0_jprb, 29000.0_jprb, 38000.0_jprb, 50000.0_jprb, 2600.0_jprb])
+      allocate(config%i_band_from_g_sw          (config%n_g_sw))
+      allocate(config%i_band_from_reordered_g_sw(config%n_g_sw))
+      allocate(config%i_g_from_reordered_g_sw   (config%n_g_sw))
+      ! Shortwave starts at 16: need to start at 1
+      config%i_band_from_g_sw = ngb_sw - ngb_sw(1)+1
+
+      if (config%i_solver_sw == ISolverSpartacus) then
+        ! SPARTACUS requires g points ordered in approximately
+        ! increasing order of optical depth
+        config%i_g_from_reordered_g_sw = RRTM_GPOINT_REORDERING_SW
+      else
+        ! Implied-do for no reordering
+        !      config%i_g_from_reordered_g_sw = RRTM_GPOINT_REORDERING_SW
+        config%i_g_from_reordered_g_sw = (/ (irep, irep=1,config%n_g_sw) /)
+      end if
+
+      config%i_band_from_reordered_g_sw &
+           = config%i_band_from_g_sw(config%i_g_from_reordered_g_sw)
+
+      ! The i_spec_* variables are used solely for storing spectral
+      ! data, and this can either be by band or by g-point
+      if (config%do_save_spectral_flux .or. config%do_toa_spectral_flux) then
+        if (config%do_save_gpoint_flux) then
+          config%n_spec_sw = config%n_g_sw
+          config%i_spec_from_reordered_g_sw => config%i_g_from_reordered_g_sw
+        else
+          config%n_spec_sw = config%n_bands_sw
+          config%i_spec_from_reordered_g_sw => config%i_band_from_reordered_g_sw
+        end if
+      else
+        config%n_spec_sw = 0
+        nullify(config%i_spec_from_reordered_g_sw)
+      end if
+      
     end if
 
-    if (config%i_solver_lw == ISolverSpartacus) then
-      ! SPARTACUS requires g points ordered in approximately
-      ! increasing order of optical depth
-      config%i_g_from_reordered_g_lw = RRTM_GPOINT_REORDERING_LW
-    else
-      ! Implied-do for no reordering
-      config%i_g_from_reordered_g_lw = (/ (irep, irep=1,config%n_g_lw) /)
+    if (do_lw) then
+      ! Cloud and aerosol properties can only be defined per band
+      config%do_cloud_aerosol_per_lw_g_point = .false.
+      config%n_g_lw = jpglw
+      config%n_bands_lw = 16
+      call config%gas_optics_lw%spectral_def%allocate_bands_only(TerrestrialReferenceTemperature, &
+           &  [10.0_jprb, 350.0_jprb, 500.0_jprb, 630.0_jprb, 700.0_jprb, 820.0_jprb, 980.0_jprb, 1080.0_jprb, &
+           &   1180.0_jprb, 1390.0_jprb, 1480.0_jprb, 1800.0_jprb, 2080.0_jprb, 2250.0_jprb, 2380.0_jprb, 2600.0_jprb], &
+           &  [350.0_jprb, 500.0_jprb, 630.0_jprb, 700.0_jprb, 820.0_jprb, 980.0_jprb, 1080.0_jprb, 1180.0_jprb, &
+           &   1390.0_jprb, 1480.0_jprb, 1800.0_jprb, 2080.0_jprb, 2250.0_jprb, 2380.0_jprb, 2600.0_jprb, 3250.0_jprb])
+      allocate(config%i_band_from_g_lw          (config%n_g_lw))
+      allocate(config%i_band_from_reordered_g_lw(config%n_g_lw))
+      allocate(config%i_g_from_reordered_g_lw   (config%n_g_lw))
+      config%i_band_from_g_lw = ngb_lw
+
+      if (config%i_solver_lw == ISolverSpartacus) then
+        ! SPARTACUS requires g points ordered in approximately
+        ! increasing order of optical depth
+        config%i_g_from_reordered_g_lw = RRTM_GPOINT_REORDERING_LW
+      else
+        ! Implied-do for no reordering
+        config%i_g_from_reordered_g_lw = (/ (irep, irep=1,config%n_g_lw) /)
+      end if
+
+      config%i_band_from_reordered_g_lw &
+           = config%i_band_from_g_lw(config%i_g_from_reordered_g_lw)
+
+      ! The i_spec_* variables are used solely for storing spectral
+      ! data, and this can either be by band or by g-point
+      if (config%do_save_spectral_flux .or. config%do_toa_spectral_flux) then
+        if (config%do_save_gpoint_flux) then
+          config%n_spec_lw = config%n_g_lw
+          config%i_spec_from_reordered_g_lw => config%i_g_from_reordered_g_lw
+        else
+          config%n_spec_lw = config%n_bands_lw
+          config%i_spec_from_reordered_g_lw => config%i_band_from_reordered_g_lw
+        end if
+      else
+        config%n_spec_lw = 0
+        nullify(config%i_spec_from_reordered_g_lw)
+      end if
+
     end if
-
-    config%i_band_from_reordered_g_sw &
-         = config%i_band_from_g_sw(config%i_g_from_reordered_g_sw)
-
-    config%i_band_from_reordered_g_lw &
-         = config%i_band_from_g_lw(config%i_g_from_reordered_g_lw)
-
-    ! The i_spec_* variables are used solely for storing spectral
-    ! data, and this can either be by band or by g-point
-    if (config%do_save_spectral_flux .or. config%do_toa_spectral_flux) then
-      if (config%do_save_gpoint_flux) then
-        config%n_spec_sw = config%n_g_sw
-        config%n_spec_lw = config%n_g_lw
-        config%i_spec_from_reordered_g_sw => config%i_g_from_reordered_g_sw
-        config%i_spec_from_reordered_g_lw => config%i_g_from_reordered_g_lw
-      else
-        config%n_spec_sw = config%n_bands_sw
-        config%n_spec_lw = config%n_bands_lw
-        config%i_spec_from_reordered_g_sw => config%i_band_from_reordered_g_sw
-        config%i_spec_from_reordered_g_lw => config%i_band_from_reordered_g_lw
-      end if
-    else
-      config%n_spec_sw = 0
-      config%n_spec_lw = 0
-      nullify(config%i_spec_from_reordered_g_sw)
-      nullify(config%i_spec_from_reordered_g_lw)
-    end if
-
+    
     if (lhook) call dr_hook('radiation_ifs_rrtm:setup_gas_optics',1,hook_handle)
 
@@ -201,5 +226,5 @@
     use yomhook  , only : lhook, dr_hook, jphook
 
-    use radiation_config,         only : config_type, ISolverSpartacus
+    use radiation_config,         only : config_type, ISolverSpartacus, IGasModelIFSRRTMG
     use radiation_thermodynamics, only : thermodynamics_type
     use radiation_single_level,   only : single_level_type
@@ -334,4 +359,6 @@
     integer :: istartlev, iendlev
 
+    logical :: do_sw, do_lw
+    
     integer :: jlev, jgreorder, jg, ig, iband, jcol
 
@@ -345,4 +372,7 @@
 
     if (lhook) call dr_hook('radiation_ifs_rrtm:gas_optics',0,hook_handle)
+
+    do_sw = (config%do_sw .and. config%i_gas_model_sw == IGasModelIFSRRTMG)
+    do_lw = (config%do_lw .and. config%i_gas_model_lw == IGasModelIFSRRTMG)
 
     ! Compute start and end levels for indexing the gas mixing ratio
@@ -392,177 +422,185 @@
          &  ZPAVEL , ZTAVEL , ZPZ , ZTZ, IREFLECT)  
 
-    CALL RRTM_SETCOEF_140GP &
-         &( istartcol, iendcol, nlev , ZCOLDRY  , ZWBRODL , ZWKL , &
-         &  ZFAC00 , ZFAC01   , ZFAC10 , ZFAC11 , ZFORFAC,ZFORFRAC,INDFOR, JP, JT, JT1 , &
-         &  ZCOLH2O, ZCOLCO2  , ZCOLO3 , ZCOLN2O, ZCOLCH4, ZCOLO2,ZCO2MULT , ZCOLBRD, & 
-         &  ILAYTROP,ILAYSWTCH, ILAYLOW, ZPAVEL , ZTAVEL , ZSELFFAC, ZSELFFRAC, INDSELF, &
-         &  INDMINOR,ZSCALEMINOR,ZSCALEMINORN2,ZMINORFRAC,&
-         &  ZRAT_H2OCO2, ZRAT_H2OCO2_1, ZRAT_H2OO3, ZRAT_H2OO3_1, &
-         &  ZRAT_H2ON2O, ZRAT_H2ON2O_1, ZRAT_H2OCH4, ZRAT_H2OCH4_1, &
-         &  ZRAT_N2OCO2, ZRAT_N2OCO2_1, ZRAT_O3CO2, ZRAT_O3CO2_1)   
-
-    ZTAUAERL(istartcol:iendcol,:,:) = 0.0_jprb
-
-    CALL RRTM_GAS_OPTICAL_DEPTH &
-         &( istartcol, iendcol, nlev, ZOD_LW, ZPAVEL, ZCOLDRY, ZCOLBRD, ZWX ,&
-         &  ZTAUAERL, ZFAC00 , ZFAC01, ZFAC10 , ZFAC11 , ZFORFAC,ZFORFRAC,INDFOR, &
-         &  JP, JT, JT1, ZONEMINUS ,&
-         &  ZCOLH2O , ZCOLCO2, ZCOLO3, ZCOLN2O, ZCOLCH4, ZCOLO2,ZCO2MULT ,&
-         &  ILAYTROP, ILAYSWTCH,ILAYLOW, ZSELFFAC, ZSELFFRAC, INDSELF, ZPFRAC, &
-         &  INDMINOR,ZSCALEMINOR,ZSCALEMINORN2,ZMINORFRAC,&
-         &  ZRAT_H2OCO2, ZRAT_H2OCO2_1, ZRAT_H2OO3, ZRAT_H2OO3_1, &
-         &  ZRAT_H2ON2O, ZRAT_H2ON2O_1, ZRAT_H2OCH4, ZRAT_H2OCH4_1, &
-         &  ZRAT_N2OCO2, ZRAT_N2OCO2_1, ZRAT_O3CO2, ZRAT_O3CO2_1)      
-
-    if (present(lw_albedo)) then
-    
-      call planck_function_atmos(nlev, istartcol, iendcol, config, &
-           &                     thermodynamics, ZPFRAC, planck_hl)
-
-      if (single_level%is_simple_surface) then
-        call planck_function_surf(istartcol, iendcol, config, &
-             &                    single_level%skin_temperature, ZPFRAC(:,:,1), &
-             &                    lw_emission)
+    if (do_lw) then
+    
+      CALL RRTM_SETCOEF_140GP &
+           &( istartcol, iendcol, nlev , ZCOLDRY  , ZWBRODL , ZWKL , &
+           &  ZFAC00 , ZFAC01   , ZFAC10 , ZFAC11 , ZFORFAC,ZFORFRAC,INDFOR, JP, JT, JT1 , &
+           &  ZCOLH2O, ZCOLCO2  , ZCOLO3 , ZCOLN2O, ZCOLCH4, ZCOLO2,ZCO2MULT , ZCOLBRD, & 
+           &  ILAYTROP,ILAYSWTCH, ILAYLOW, ZPAVEL , ZTAVEL , ZSELFFAC, ZSELFFRAC, INDSELF, &
+           &  INDMINOR,ZSCALEMINOR,ZSCALEMINORN2,ZMINORFRAC,&
+           &  ZRAT_H2OCO2, ZRAT_H2OCO2_1, ZRAT_H2OO3, ZRAT_H2OO3_1, &
+           &  ZRAT_H2ON2O, ZRAT_H2ON2O_1, ZRAT_H2OCH4, ZRAT_H2OCH4_1, &
+           &  ZRAT_N2OCO2, ZRAT_N2OCO2_1, ZRAT_O3CO2, ZRAT_O3CO2_1)   
+
+      ZTAUAERL(istartcol:iendcol,:,:) = 0.0_jprb
+
+      CALL RRTM_GAS_OPTICAL_DEPTH &
+           &( istartcol, iendcol, nlev, ZOD_LW, ZPAVEL, ZCOLDRY, ZCOLBRD, ZWX ,&
+           &  ZTAUAERL, ZFAC00 , ZFAC01, ZFAC10 , ZFAC11 , ZFORFAC,ZFORFRAC,INDFOR, &
+           &  JP, JT, JT1, ZONEMINUS ,&
+           &  ZCOLH2O , ZCOLCO2, ZCOLO3, ZCOLN2O, ZCOLCH4, ZCOLO2,ZCO2MULT ,&
+           &  ILAYTROP, ILAYSWTCH,ILAYLOW, ZSELFFAC, ZSELFFRAC, INDSELF, ZPFRAC, &
+           &  INDMINOR,ZSCALEMINOR,ZSCALEMINORN2,ZMINORFRAC,&
+           &  ZRAT_H2OCO2, ZRAT_H2OCO2_1, ZRAT_H2OO3, ZRAT_H2OO3_1, &
+           &  ZRAT_H2ON2O, ZRAT_H2ON2O_1, ZRAT_H2OCH4, ZRAT_H2OCH4_1, &
+           &  ZRAT_N2OCO2, ZRAT_N2OCO2_1, ZRAT_O3CO2, ZRAT_O3CO2_1)      
+    
+      if (present(lw_albedo)) then
+    
+        call planck_function_atmos(nlev, istartcol, iendcol, config, &
+             &                     thermodynamics, ZPFRAC, planck_hl)
+
+        if (single_level%is_simple_surface) then
+          call planck_function_surf(istartcol, iendcol, config, &
+               &                    single_level%skin_temperature, ZPFRAC(:,:,1), &
+               &                    lw_emission)
+          
+          ! The following can be used to extract the parameters defined at
+          ! the top of the planck_function routine below:
+          !write(*,'(a,140(e12.5,","),a)') 'ZPFRAC_surf=[', &
+          !&  sum(ZPFRAC(istartcol:iendcol,:,1),1) / (iendcol+1-istartcol), ']'
         
-        ! The following can be used to extract the parameters defined at
-        ! the top of the planck_function routine below:
-        !write(*,'(a,140(e12.5,","),a)') 'ZPFRAC_surf=[', &
-        !&  sum(ZPFRAC(istartcol:iendcol,:,1),1) / (iendcol+1-istartcol), ']'
-        
-        ! lw_emission at this point is actually the planck function of
-        ! the surface
-        lw_emission = lw_emission * (1.0_jprb - lw_albedo)
+          ! lw_emission at this point is actually the planck function of
+          ! the surface
+          lw_emission = lw_emission * (1.0_jprb - lw_albedo)
+        else
+          ! Longwave emission has already been computed
+          if (config%use_canopy_full_spectrum_lw) then
+            lw_emission = transpose(single_level%lw_emission(istartcol:iendcol,:))
+          else
+            lw_emission = transpose(single_level%lw_emission(istartcol:iendcol, &
+                 & config%i_emiss_from_band_lw(config%i_band_from_reordered_g_lw)))
+          end if
+        end if
+
+      end if
+
+      if (config%i_solver_lw == ISolverSpartacus) then
+        ! We need to rearrange the gas optics info in memory: reordering
+        ! the g points in order of approximately increasing optical
+        ! depth (for efficient 3D processing on only the regions of the
+        ! spectrum that are optically thin for gases) and reorder in
+        ! pressure since the the functions above treat pressure
+        ! decreasing with increasing index.  Note that the output gas
+        ! arrays have dimensions in a different order to the inputs,
+        ! so there is some inefficiency here.
+        do jgreorder = 1,config%n_g_lw
+          iband = config%i_band_from_reordered_g_lw(jgreorder)
+          ig = config%i_g_from_reordered_g_lw(jgreorder)
+          
+          ! Top-of-atmosphere half level
+          do jlev = 1,nlev
+            do jcol = istartcol,iendcol
+              ! Some g points can return negative optical depths;
+              ! specifically original g points 54-56 which causes
+              ! unphysical single-scattering albedo when combined with
+              ! aerosol
+              od_lw(jgreorder,jlev,jcol) &
+                   &   = max(config%min_gas_od_lw, ZOD_LW(ig,nlev+1-jlev,jcol))
+            end do
+          end do
+        end do
       else
-        ! Longwave emission has already been computed
-        if (config%use_canopy_full_spectrum_lw) then
-          lw_emission = transpose(single_level%lw_emission(istartcol:iendcol,:))
-        else
-          lw_emission = transpose(single_level%lw_emission(istartcol:iendcol, &
-               & config%i_emiss_from_band_lw(config%i_band_from_reordered_g_lw)))
-        end if
+        ! G points have not been reordered 
+        do jcol = istartcol,iendcol
+          do jlev = 1,nlev
+            ! Check for negative optical depth
+            od_lw(:,jlev,jcol) = max(config%min_gas_od_lw, ZOD_LW(:,nlev+1-jlev,jcol))
+          end do
+        end do
       end if
 
     end if
 
-    if (config%i_solver_lw == ISolverSpartacus) then
-      ! We need to rearrange the gas optics info in memory: reordering
-      ! the g points in order of approximately increasing optical
-      ! depth (for efficient 3D processing on only the regions of the
-      ! spectrum that are optically thin for gases) and reorder in
-      ! pressure since the the functions above treat pressure
-      ! decreasing with increasing index.  Note that the output gas
-      ! arrays have dimensions in a different order to the inputs,
-      ! so there is some inefficiency here.
-      do jgreorder = 1,config%n_g_lw
-        iband = config%i_band_from_reordered_g_lw(jgreorder)
-        ig = config%i_g_from_reordered_g_lw(jgreorder)
-        
-        ! Top-of-atmosphere half level
-        do jlev = 1,nlev
-          do jcol = istartcol,iendcol
-            ! Some g points can return negative optical depths;
-            ! specifically original g points 54-56 which causes
-            ! unphysical single-scattering albedo when combined with
-            ! aerosol
-            od_lw(jgreorder,jlev,jcol) &
-                 &   = max(config%min_gas_od_lw, ZOD_LW(ig,nlev+1-jlev,jcol))
+    if (do_sw) then
+    
+      CALL SRTM_SETCOEF &
+           & ( istartcol, iendcol, nlev,&
+           & ZPAVEL  , ZTAVEL,&
+           & ZCOLDRY , ZWKL,&
+           & ILAYTROP,&
+           & ZCOLCH4  , ZCOLCO2 , ZCOLH2O , ZCOLMOL  , ZCOLO2 , ZCOLO3,&
+           & ZFORFAC , ZFORFRAC , INDFOR  , ZSELFFAC, ZSELFFRAC, INDSELF, &
+           & ZFAC00  , ZFAC01   , ZFAC10  , ZFAC11,&
+           & JP      , JT       , JT1     , single_level%cos_sza(istartcol:iendcol)  &
+           & )  
+    
+      ! SRTM_GAS_OPTICAL_DEPTH will not initialize profiles when the sun
+      ! is below the horizon, so we do it here
+      ZOD_SW(istartcol:iendcol,:,:)  = 0.0_jprb
+      ZSSA_SW(istartcol:iendcol,:,:) = 0.0_jprb
+      ZINCSOL(istartcol:iendcol,:)   = 0.0_jprb
+
+      CALL SRTM_GAS_OPTICAL_DEPTH &
+           &( istartcol, iendcol , nlev  , ZONEMINUS_ARRAY,&
+           & single_level%cos_sza(istartcol:iendcol), ILAYTROP,&
+           & ZCOLCH4 , ZCOLCO2  , ZCOLH2O, ZCOLMOL , ZCOLO2   , ZCOLO3,&
+           & ZFORFAC , ZFORFRAC , INDFOR , ZSELFFAC, ZSELFFRAC, INDSELF,&
+           & ZFAC00  , ZFAC01   , ZFAC10 , ZFAC11  ,&
+           & JP      , JT       , JT1    ,&
+           & ZOD_SW  , ZSSA_SW  , ZINCSOL )
+    
+      ! Scale the incoming solar per band, if requested
+      if (config%use_spectral_solar_scaling) then
+        do jg = 1,JPGPT_SW
+          do jcol = istartcol,iendcol 
+            ZINCSOL(jcol,jg) = ZINCSOL(jcol,jg) * &
+                 &   single_level%spectral_solar_scaling(config%i_band_from_reordered_g_sw(jg))
           end do
         end do
-      end do
-    else
-      ! G points have not been reordered 
-      do jcol = istartcol,iendcol
-        do jlev = 1,nlev
-          ! Check for negative optical depth
-          od_lw(:,jlev,jcol) = max(config%min_gas_od_lw, ZOD_LW(:,nlev+1-jlev,jcol))
-        end do
-      end do
-    end if
-    
-    CALL SRTM_SETCOEF &
-         & ( istartcol, iendcol, nlev,&
-         & ZPAVEL  , ZTAVEL,&
-         & ZCOLDRY , ZWKL,&
-         & ILAYTROP,&
-         & ZCOLCH4  , ZCOLCO2 , ZCOLH2O , ZCOLMOL  , ZCOLO2 , ZCOLO3,&
-         & ZFORFAC , ZFORFRAC , INDFOR  , ZSELFFAC, ZSELFFRAC, INDSELF, &
-         & ZFAC00  , ZFAC01   , ZFAC10  , ZFAC11,&
-         & JP      , JT       , JT1     , single_level%cos_sza(istartcol:iendcol)  &
-         & )  
-    
-    ! SRTM_GAS_OPTICAL_DEPTH will not initialize profiles when the sun
-    ! is below the horizon, so we do it here
-    ZOD_SW(istartcol:iendcol,:,:)  = 0.0_jprb
-    ZSSA_SW(istartcol:iendcol,:,:) = 0.0_jprb
-    ZINCSOL(istartcol:iendcol,:)   = 0.0_jprb
-
-    CALL SRTM_GAS_OPTICAL_DEPTH &
-         &( istartcol, iendcol , nlev  , ZONEMINUS_ARRAY,&
-         & single_level%cos_sza(istartcol:iendcol), ILAYTROP,&
-         & ZCOLCH4 , ZCOLCO2  , ZCOLH2O, ZCOLMOL , ZCOLO2   , ZCOLO3,&
-         & ZFORFAC , ZFORFRAC , INDFOR , ZSELFFAC, ZSELFFRAC, INDSELF,&
-         & ZFAC00  , ZFAC01   , ZFAC10 , ZFAC11  ,&
-         & JP      , JT       , JT1    ,&
-         & ZOD_SW  , ZSSA_SW  , ZINCSOL )
-    
-    ! Scale the incoming solar per band, if requested
-    if (config%use_spectral_solar_scaling) then
-      do jg = 1,JPGPT_SW
-        do jcol = istartcol,iendcol 
-          ZINCSOL(jcol,jg) = ZINCSOL(jcol,jg) * &
-            &   single_level%spectral_solar_scaling(config%i_band_from_reordered_g_sw(jg))
-        end do
-      end do
-    end if
-
-    ! Scaling factor to ensure that the total solar irradiance is as
-    ! requested.  Note that if the sun is below the horizon then
-    ! ZINCSOL will be zero.
-    if (present(incoming_sw)) then
-      do jcol = istartcol,iendcol
-        if (single_level%cos_sza(jcol) > 0.0_jprb) then
+      end if
+
+      ! Scaling factor to ensure that the total solar irradiance is as
+      ! requested.  Note that if the sun is below the horizon then
+      ! ZINCSOL will be zero.
+      if (present(incoming_sw)) then
+        do jcol = istartcol,iendcol
+          if (single_level%cos_sza(jcol) > 0.0_jprb) then
 ! Added for DWD (2020)
 !NEC$ nounroll
-          incoming_sw_scale(jcol) = single_level%solar_irradiance / sum(ZINCSOL(jcol,:))
-        else
-          incoming_sw_scale(jcol) = 1.0_jprb
-        end if
-      end do
-    end if
-
-    if (config%i_solver_sw == ISolverSpartacus) then
-!    if (.true.) then
-      ! Account for reordered g points
-      do jgreorder = 1,config%n_g_sw
-        ig = config%i_g_from_reordered_g_sw(jgreorder)
-        do jlev = 1,nlev
-          do jcol = istartcol,iendcol
-            ! Check for negative optical depth
-            od_sw (jgreorder,nlev+1-jlev,jcol) &
-                 &  = max(config%min_gas_od_sw, ZOD_SW (jcol,jlev,ig))
-            ssa_sw(jgreorder,nlev+1-jlev,jcol) = ZSSA_SW(jcol,jlev,ig)
-           end do
+            incoming_sw_scale(jcol) = single_level%solar_irradiance / sum(ZINCSOL(jcol,:))
+          else
+            incoming_sw_scale(jcol) = 1.0_jprb
+          end if
         end do
-        if (present(incoming_sw)) then
-          incoming_sw(jgreorder,:) &
-               &  = incoming_sw_scale(:) * ZINCSOL(:,ig)
-        end if
-      end do
-    else
-      ! G points have not been reordered
-      do jcol = istartcol,iendcol
-        do jlev = 1,nlev
-          do jg = 1,config%n_g_sw
-            ! Check for negative optical depth
-            od_sw (jg,nlev+1-jlev,jcol) = max(config%min_gas_od_sw, ZOD_SW(jcol,jlev,jg))
-            ssa_sw(jg,nlev+1-jlev,jcol) = ZSSA_SW(jcol,jlev,jg)
-          end do
+      end if
+
+      if (config%i_solver_sw == ISolverSpartacus) then
+!      if (.true.) then
+        ! Account for reordered g points
+        do jgreorder = 1,config%n_g_sw
+          ig = config%i_g_from_reordered_g_sw(jgreorder)
+          do jlev = 1,nlev
+            do jcol = istartcol,iendcol
+              ! Check for negative optical depth
+              od_sw (jgreorder,nlev+1-jlev,jcol) &
+                   &  = max(config%min_gas_od_sw, ZOD_SW (jcol,jlev,ig))
+              ssa_sw(jgreorder,nlev+1-jlev,jcol) = ZSSA_SW(jcol,jlev,ig)
+            end do
+          end do
+          if (present(incoming_sw)) then
+            incoming_sw(jgreorder,:) &
+                 &  = incoming_sw_scale(:) * ZINCSOL(:,ig)
+          end if
         end do
-        if (present(incoming_sw)) then
-          do jg = 1,config%n_g_sw
-            incoming_sw(jg,jcol) = incoming_sw_scale(jcol) * ZINCSOL(jcol,jg)
-          end do
-        end if
-      end do
+      else
+        ! G points have not been reordered
+        do jcol = istartcol,iendcol
+          do jlev = 1,nlev
+            do jg = 1,config%n_g_sw
+              ! Check for negative optical depth
+              od_sw (jg,nlev+1-jlev,jcol) = max(config%min_gas_od_sw, ZOD_SW(jcol,jlev,jg))
+              ssa_sw(jg,nlev+1-jlev,jcol) = ZSSA_SW(jcol,jlev,jg)
+            end do
+          end do
+          if (present(incoming_sw)) then
+            do jg = 1,config%n_g_sw
+              incoming_sw(jg,jcol) = incoming_sw_scale(jcol) * ZINCSOL(jcol,jg)
+            end do
+          end if
+        end do
+      end if
+
     end if
     
Index: /LMDZ6/trunk/libf/phylmd/ecrad/radiation/radiation_interface.F90
===================================================================
--- /LMDZ6/trunk/libf/phylmd/ecrad/radiation/radiation_interface.F90	(revision 4852)
+++ /LMDZ6/trunk/libf/phylmd/ecrad/radiation/radiation_interface.F90	(revision 4853)
@@ -68,10 +68,16 @@
 
     ! Load the look-up tables from files in the specified directory
-    if (config%i_gas_model == IGasModelMonochromatic) then
+    if (config%i_gas_model_sw == IGasModelMonochromatic) then
       call setup_gas_optics_mono(config, trim(config%directory_name))
-    else if (config%i_gas_model == IGasModelIFSRRTMG) then
-      call setup_gas_optics_rrtmg(config, trim(config%directory_name))
-    else if (config%i_gas_model == IGasModelECCKD) then
-      call setup_gas_optics_ecckd(config)
+    else
+      ! Note that we can run RRTMG and ECCKD for different parts of
+      ! the spectrum: the setup routines only configure the relevant
+      ! part.
+      if (config%i_gas_model_sw == IGasModelIFSRRTMG .or. config%i_gas_model_lw == IGasModelIFSRRTMG) then
+        call setup_gas_optics_rrtmg(config, trim(config%directory_name))
+      end if
+      if (config%i_gas_model_sw == IGasModelECCKD .or. config%i_gas_model_lw == IGasModelECCKD) then
+        call setup_gas_optics_ecckd(config)
+      end if
     end if
 
@@ -122,5 +128,5 @@
 
     if (config%do_clouds) then
-      if (config%i_gas_model == IGasModelMonochromatic) then
+      if (config%i_gas_model_sw == IGasModelMonochromatic) then
         !      call setup_cloud_optics_mono(config)
       elseif (config%use_general_cloud_optics) then
@@ -132,5 +138,5 @@
 
     if (config%use_aerosols) then
-      if (config%i_gas_model == IGasModelMonochromatic) then
+      if (config%i_gas_model_sw == IGasModelMonochromatic) then
 !        call setup_aerosol_optics_mono(config)
       else 
@@ -167,10 +173,14 @@
     type(gas_type),    intent(inout) :: gas
 
-    if (config%i_gas_model == IGasModelMonochromatic) then
+    if (config%i_gas_model_sw == IGasModelMonochromatic) then
       call set_gas_units_mono(gas)
-    elseif (config%i_gas_model == IGasModelECCKD) then
+    elseif (config%i_gas_model_sw == IGasModelIFSRRTMG &
+         &  .or. config%i_gas_model_lw == IGasModelIFSRRTMG) then
+      ! Convert to mass-mixing ratio for RRTMG; note that ecCKD can
+      ! work with this but performs an internal scaling
+      call set_gas_units_ifs(gas)
+    else
+      ! Use volume mixing ratio preferred by ecCKD
       call set_gas_units_ecckd(gas)
-    else
-      call set_gas_units_ifs(gas)
     end if
 
@@ -196,5 +206,5 @@
     use radiation_io,             only : nulout
     use radiation_config,         only : config_type, &
-         &   IGasModelMonochromatic, IGasModelIFSRRTMG, &
+         &   IGasModelMonochromatic, IGasModelIFSRRTMG, IGasModelECCKD, &
          &   ISolverMcICA, ISolverSpartacus, ISolverHomogeneous, &
          &   ISolverTripleclouds
@@ -227,6 +237,4 @@
     use radiation_general_cloud_optics, only : general_cloud_optics
     use radiation_aerosol_optics, only : add_aerosol_optics
-    USE mod_phys_lmdz_para
-
 
     ! Inputs
@@ -238,5 +246,5 @@
     type(thermodynamics_type),intent(in)   :: thermodynamics
     type(gas_type),           intent(in)   :: gas
-    type(cloud_type),        intent(inout):: cloud
+    type(cloud_type),         intent(inout):: cloud
     type(aerosol_type),       intent(in)   :: aerosol
     ! Output
@@ -297,22 +305,6 @@
 
     real(jphook) :: hook_handle
-    integer :: jcol, jlev
 
     if (lhook) call dr_hook('radiation_interface:radiation',0,hook_handle)
-
-    if (config%i_solver_sw == ISolverSPARTACUS) then
-         print*,'Dans radiation, mpi_rank, omp_rank, size, chape inv_cloud = ',&
-              mpi_rank, omp_rank, &
-              shape(cloud%inv_cloud_effective_size), &
-              size(cloud%inv_cloud_effective_size)   
-!         do jcol=istartcol, iendcol
-!              do jlev=1,nlev
-!              print*,'Entree radiation_interf, mpi_rank, omp_rank, jcol, jlev &
-!           &  cloud%inv_cloud_effective_size =',mpi_rank, omp_rank, jcol, jlev, &
-!           &  cloud%inv_cloud_effective_size(jcol,jlev)
-!              enddo
-!          enddo
-    endif
-!    cloud%inv_cloud_effective_size=0.05_jprb
 
     if (thermodynamics%pressure_hl(istartcol,2) &
@@ -339,21 +331,26 @@
       ! incoming shortwave flux at each g-point, for the specified
       ! range of atmospheric columns
-      if (config%i_gas_model == IGasModelMonochromatic) then
+      if (config%i_gas_model_sw == IGasModelMonochromatic) then
         call gas_optics_mono(ncol,nlev,istartcol,iendcol, config, &
              &  single_level, thermodynamics, gas, lw_albedo, &
              &  od_lw, od_sw, ssa_sw, &
              &  planck_hl, lw_emission, incoming_sw)
-      else if (config%i_gas_model == IGasModelIFSRRTMG) then
-        call gas_optics_rrtmg(ncol,nlev,istartcol,iendcol, config, &
-             &  single_level, thermodynamics, gas, &
-             &  od_lw, od_sw, ssa_sw, lw_albedo=lw_albedo, &
-             &  planck_hl=planck_hl, lw_emission=lw_emission, &
-             &  incoming_sw=incoming_sw)
       else
-        call gas_optics_ecckd(ncol,nlev,istartcol,iendcol, config, &
-             &  single_level, thermodynamics, gas, &
-             &  od_lw, od_sw, ssa_sw, lw_albedo=lw_albedo, &
-             &  planck_hl=planck_hl, lw_emission=lw_emission, &
-             &  incoming_sw=incoming_sw)
+        if (config%i_gas_model_sw == IGasModelIFSRRTMG &
+             &   .or. config%i_gas_model_lw == IGasModelIFSRRTMG) then
+          call gas_optics_rrtmg(ncol,nlev,istartcol,iendcol, config, &
+               &  single_level, thermodynamics, gas, &
+               &  od_lw, od_sw, ssa_sw, lw_albedo=lw_albedo, &
+               &  planck_hl=planck_hl, lw_emission=lw_emission, &
+               &  incoming_sw=incoming_sw)
+        end if
+        if (config%i_gas_model_sw == IGasModelECCKD &
+             &   .or. config%i_gas_model_lw == IGasModelECCKD) then
+          call gas_optics_ecckd(ncol,nlev,istartcol,iendcol, config, &
+               &  single_level, thermodynamics, gas, &
+               &  od_lw, od_sw, ssa_sw, lw_albedo=lw_albedo, &
+               &  planck_hl=planck_hl, lw_emission=lw_emission, &
+               &  incoming_sw=incoming_sw)
+        end if
       end if
 
@@ -368,5 +365,5 @@
         ! Compute hydrometeor absorption/scattering properties in each
         ! shortwave and longwave band
-        if (config%i_gas_model == IGasModelMonochromatic) then
+        if (config%i_gas_model_sw == IGasModelMonochromatic) then
           call cloud_optics_mono(nlev, istartcol, iendcol, &
                &  config, thermodynamics, cloud, &
@@ -387,5 +384,5 @@
 
       if (config%use_aerosols) then
-        if (config%i_gas_model == IGasModelMonochromatic) then
+        if (config%i_gas_model_sw == IGasModelMonochromatic) then
 !          call add_aerosol_optics_mono(nlev,istartcol,iendcol, &
 !               &  config, thermodynamics, gas, aerosol, & 
@@ -474,12 +471,4 @@
         else if (config%i_solver_sw == ISolverSPARTACUS) then
           ! Compute fluxes using the SPARTACUS shortwave solver
-!             cloud%inv_cloud_effective_size=0.05_jprb
-!             do jcol=istartcol, iendcol
-!              do jlev=1,nlev
-!              print*,'jcol, jlev, dans radiation_interf i &
-!               &       cloud%inv_cloud_effective_size =',jcol, jlev, &
-!               cloud%inv_cloud_effective_size(jcol,jlev)
-!              enddo
-!             enddo
           call solver_spartacus_sw(nlev,istartcol,iendcol, &
                &  config, single_level, thermodynamics, cloud, & 
Index: /LMDZ6/trunk/libf/phylmd/ecrad/radiation/radiation_mcica_lw.F90
===================================================================
--- /LMDZ6/trunk/libf/phylmd/ecrad/radiation/radiation_mcica_lw.F90	(revision 4852)
+++ /LMDZ6/trunk/libf/phylmd/ecrad/radiation/radiation_mcica_lw.F90	(revision 4853)
@@ -19,4 +19,6 @@
 !   2017-10-23  R. Hogan  Renamed single-character variables
 
+#include "ecrad_config.h"
+
 module radiation_mcica_lw
 
@@ -124,4 +126,11 @@
     ! Identify clear-sky layers
     logical :: is_clear_sky_layer(nlev)
+
+    ! Temporary storage for more efficient summation
+#ifdef DWD_REDUCTION_OPTIMIZATIONS
+    real(jprb), dimension(nlev+1,2) :: sum_aux
+#else
+    real(jprb) :: sum_up, sum_dn
+#endif
 
     ! Index of the highest cloudy layer
@@ -179,6 +188,28 @@
 
       ! Sum over g-points to compute broadband fluxes
-      flux%lw_up_clear(jcol,:) = sum(flux_up_clear,1)
-      flux%lw_dn_clear(jcol,:) = sum(flux_dn_clear,1)
+#ifdef DWD_REDUCTION_OPTIMIZATIONS
+      sum_aux(:,:) = 0.0_jprb
+      do jg = 1,ng
+        do jlev = 1,nlev+1
+          sum_aux(jlev,1) = sum_aux(jlev,1) + flux_up_clear(jg,jlev)
+          sum_aux(jlev,2) = sum_aux(jlev,2) + flux_dn_clear(jg,jlev)
+        end do
+      end do
+      flux%lw_up_clear(jcol,:) = sum_aux(:,1)
+      flux%lw_dn_clear(jcol,:) = sum_aux(:,2)
+#else
+      do jlev = 1,nlev+1
+        sum_up = 0.0_jprb
+        sum_dn = 0.0_jprb
+        !$omp simd reduction(+:sum_up, sum_dn)
+        do jg = 1,ng
+          sum_up = sum_up + flux_up_clear(jg,jlev)
+          sum_dn = sum_dn + flux_dn_clear(jg,jlev)
+        end do
+        flux%lw_up_clear(jcol,jlev) = sum_up
+        flux%lw_dn_clear(jcol,jlev) = sum_dn
+      end do
+#endif
+
       ! Store surface spectral downwelling fluxes
       flux%lw_dn_surf_clear_g(:,jcol) = flux_dn_clear(:,nlev+1)
@@ -279,8 +310,10 @@
           else
             ! Clear-sky layer: copy over clear-sky values
-            reflectance(:,jlev) = ref_clear(:,jlev)
-            transmittance(:,jlev) = trans_clear(:,jlev)
-            source_up(:,jlev) = source_up_clear(:,jlev)
-            source_dn(:,jlev) = source_dn_clear(:,jlev)
+            do jg = 1,ng
+              reflectance(jg,jlev) = ref_clear(jg,jlev)
+              transmittance(jg,jlev) = trans_clear(jg,jlev)
+              source_up(jg,jlev) = source_up_clear(jg,jlev)
+              source_dn(jg,jlev) = source_dn_clear(jg,jlev)
+            end do
           end if
         end do
@@ -307,13 +340,36 @@
         
         ! Store overcast broadband fluxes
-        flux%lw_up(jcol,:) = sum(flux_up,1)
-        flux%lw_dn(jcol,:) = sum(flux_dn,1)
+#ifdef DWD_REDUCTION_OPTIMIZATIONS
+        sum_aux(:,:) = 0._jprb
+        do jg = 1, ng
+          do jlev = 1, nlev+1
+            sum_aux(jlev,1) = sum_aux(jlev,1) + flux_up(jg,jlev)
+            sum_aux(jlev,2) = sum_aux(jlev,2) + flux_dn(jg,jlev)
+          end do
+        end do
+        flux%lw_up(jcol,:) = sum_aux(:,1)
+        flux%lw_dn(jcol,:) = sum_aux(:,2)
+#else
+        do jlev = 1,nlev+1
+          sum_up = 0.0_jprb
+          sum_dn = 0.0_jprb
+          !$omp simd reduction(+:sum_up, sum_dn)
+          do jg = 1,ng
+            sum_up = sum_up + flux_up(jg,jlev)
+            sum_dn = sum_dn + flux_dn(jg,jlev)
+          end do
+          flux%lw_up(jcol,jlev) = sum_up
+          flux%lw_dn(jcol,jlev) = sum_dn
+        end do
+#endif
 
         ! Cloudy flux profiles currently assume completely overcast
         ! skies; perform weighted average with clear-sky profile
-        flux%lw_up(jcol,:) =  total_cloud_cover *flux%lw_up(jcol,:) &
-             &  + (1.0_jprb - total_cloud_cover)*flux%lw_up_clear(jcol,:)
-        flux%lw_dn(jcol,:) =  total_cloud_cover *flux%lw_dn(jcol,:) &
-             &  + (1.0_jprb - total_cloud_cover)*flux%lw_dn_clear(jcol,:)
+        do jlev = 1,nlev+1
+          flux%lw_up(jcol,jlev) =  total_cloud_cover *flux%lw_up(jcol,jlev) &
+             &       + (1.0_jprb - total_cloud_cover)*flux%lw_up_clear(jcol,jlev)
+          flux%lw_dn(jcol,jlev) =  total_cloud_cover *flux%lw_dn(jcol,jlev) &
+             &       + (1.0_jprb - total_cloud_cover)*flux%lw_dn_clear(jcol,jlev)
+        end do
         ! Store surface spectral downwelling fluxes
         flux%lw_dn_surf_g(:,jcol) = total_cloud_cover*flux_dn(:,nlev+1) &
@@ -335,6 +391,8 @@
         ! No cloud in profile and clear-sky fluxes already
         ! calculated: copy them over
-        flux%lw_up(jcol,:) = flux%lw_up_clear(jcol,:)
-        flux%lw_dn(jcol,:) = flux%lw_dn_clear(jcol,:)
+        do jlev = 1,nlev+1
+          flux%lw_up(jcol,jlev) = flux%lw_up_clear(jcol,jlev)
+          flux%lw_dn(jcol,jlev) = flux%lw_dn_clear(jcol,jlev)
+        end do
         flux%lw_dn_surf_g(:,jcol) = flux%lw_dn_surf_clear_g(:,jcol)
         if (config%do_lw_derivatives) then
Index: /LMDZ6/trunk/libf/phylmd/ecrad/radiation/radiation_mcica_sw.F90
===================================================================
--- /LMDZ6/trunk/libf/phylmd/ecrad/radiation/radiation_mcica_sw.F90	(revision 4852)
+++ /LMDZ6/trunk/libf/phylmd/ecrad/radiation/radiation_mcica_sw.F90	(revision 4853)
@@ -18,4 +18,6 @@
 !   2017-10-23  R. Hogan  Renamed single-character variables
 
+#include "ecrad_config.h"
+
 module radiation_mcica_sw
 
@@ -119,4 +121,11 @@
     ! Total cloud cover output from the cloud generator
     real(jprb) :: total_cloud_cover
+
+    ! Temporary storage for more efficient summation
+#ifdef DWD_REDUCTION_OPTIMIZATIONS
+    real(jprb), dimension(nlev+1,3) :: sum_aux
+#else
+    real(jprb) :: sum_up, sum_dn_diff, sum_dn_dir
+#endif
 
     ! Number of g points
@@ -175,18 +184,47 @@
         
         ! Sum over g-points to compute and save clear-sky broadband
-        ! fluxes
-        flux%sw_up_clear(jcol,:) = sum(flux_up,1)
+        ! fluxes. Note that the built-in "sum" function is very slow,
+        ! and before being replaced by the alternatives below
+        ! accounted for around 40% of the total cost of this routine.
+#ifdef DWD_REDUCTION_OPTIMIZATIONS
+        ! Optimized summation for the NEC architecture
+        sum_aux(:,:) = 0.0_jprb
+        do jg = 1,ng
+          do jlev = 1,nlev+1
+            sum_aux(jlev,1) = sum_aux(jlev,1) + flux_up(jg,jlev)
+            sum_aux(jlev,2) = sum_aux(jlev,2) + flux_dn_direct(jg,jlev)
+            sum_aux(jlev,3) = sum_aux(jlev,3) + flux_dn_diffuse(jg,jlev)
+          end do
+        end do
+        flux%sw_up_clear(jcol,:) = sum_aux(:,1)
+        flux%sw_dn_clear(jcol,:) = sum_aux(:,2) + sum_aux(:,3)
         if (allocated(flux%sw_dn_direct_clear)) then
-          flux%sw_dn_direct_clear(jcol,:) &
-               &  = sum(flux_dn_direct,1)
-          flux%sw_dn_clear(jcol,:) = sum(flux_dn_diffuse,1) &
-               &  + flux%sw_dn_direct_clear(jcol,:)
-        else
-          flux%sw_dn_clear(jcol,:) = sum(flux_dn_diffuse,1) &
-               &  + sum(flux_dn_direct,1)
+          flux%sw_dn_direct_clear(jcol,:) = sum_aux(:,2)
         end if
+#else
+        ! Optimized summation for the x86-64 architecture
+        do jlev = 1,nlev+1
+          sum_up      = 0.0_jprb
+          sum_dn_diff = 0.0_jprb
+          sum_dn_dir  = 0.0_jprb
+          !$omp simd reduction(+:sum_up, sum_dn_diff, sum_dn_dir)
+          do jg = 1,ng
+            sum_up      = sum_up      + flux_up(jg,jlev)
+            sum_dn_diff = sum_dn_diff + flux_dn_diffuse(jg,jlev)
+            sum_dn_dir  = sum_dn_dir  + flux_dn_direct(jg,jlev)
+          end do
+          flux%sw_up_clear(jcol,jlev) = sum_up
+          flux%sw_dn_clear(jcol,jlev) = sum_dn_diff + sum_dn_dir
+          if (allocated(flux%sw_dn_direct_clear)) then
+            flux%sw_dn_direct_clear(jcol,jlev) = sum_dn_dir
+          end if
+        end do
+#endif
+        
         ! Store spectral downwelling fluxes at surface
-        flux%sw_dn_diffuse_surf_clear_g(:,jcol) = flux_dn_diffuse(:,nlev+1)
-        flux%sw_dn_direct_surf_clear_g(:,jcol)  = flux_dn_direct(:,nlev+1)
+        do jg = 1,ng
+          flux%sw_dn_diffuse_surf_clear_g(jg,jcol) = flux_dn_diffuse(jg,nlev+1)
+          flux%sw_dn_direct_surf_clear_g(jg,jcol)  = flux_dn_direct(jg,nlev+1)
+        end do
 
         ! Do cloudy-sky calculation
@@ -249,9 +287,11 @@
             else
               ! Clear-sky layer: copy over clear-sky values
-              reflectance(:,jlev) = ref_clear(:,jlev)
-              transmittance(:,jlev) = trans_clear(:,jlev)
-              ref_dir(:,jlev) = ref_dir_clear(:,jlev)
-              trans_dir_diff(:,jlev) = trans_dir_diff_clear(:,jlev)
-              trans_dir_dir(:,jlev) = trans_dir_dir_clear(:,jlev)
+              do jg = 1,ng
+                reflectance(jg,jlev) = ref_clear(jg,jlev)
+                transmittance(jg,jlev) = trans_clear(jg,jlev)
+                ref_dir(jg,jlev) = ref_dir_clear(jg,jlev)
+                trans_dir_diff(jg,jlev) = trans_dir_diff_clear(jg,jlev)
+                trans_dir_dir(jg,jlev) = trans_dir_dir_clear(jg,jlev)
+              end do
             end if
           end do
@@ -264,42 +304,73 @@
           
           ! Store overcast broadband fluxes
-          flux%sw_up(jcol,:) = sum(flux_up,1)
+#ifdef DWD_REDUCTION_OPTIMIZATIONS
+          sum_aux(:,:) = 0.0_jprb
+          do jg = 1,ng
+            do jlev = 1,nlev+1
+              sum_aux(jlev,1) = sum_aux(jlev,1) + flux_up(jg,jlev)
+              sum_aux(jlev,2) = sum_aux(jlev,2) + flux_dn_direct(jg,jlev)
+              sum_aux(jlev,3) = sum_aux(jlev,3) + flux_dn_diffuse(jg,jlev)
+            end do
+          end do
+          flux%sw_up(jcol,:) = sum_aux(:,1)
+          flux%sw_dn(jcol,:) = sum_aux(:,2) + sum_aux(:,3)
           if (allocated(flux%sw_dn_direct)) then
-            flux%sw_dn_direct(jcol,:) = sum(flux_dn_direct,1)
-            flux%sw_dn(jcol,:) = sum(flux_dn_diffuse,1) &
-                 &  + flux%sw_dn_direct(jcol,:)
-          else
-            flux%sw_dn(jcol,:) = sum(flux_dn_diffuse,1) &
-                 &  + sum(flux_dn_direct,1)
+            flux%sw_dn_direct(jcol,:) = sum_aux(:,2)
           end if
-
+#else
+          do jlev = 1,nlev+1
+            sum_up      = 0.0_jprb
+            sum_dn_diff = 0.0_jprb
+            sum_dn_dir  = 0.0_jprb
+            !$omp simd reduction(+:sum_up, sum_dn_diff, sum_dn_dir)
+            do jg = 1,ng
+              sum_up      = sum_up      + flux_up(jg,jlev)
+              sum_dn_diff = sum_dn_diff + flux_dn_diffuse(jg,jlev)
+              sum_dn_dir  = sum_dn_dir  + flux_dn_direct(jg,jlev)
+            end do
+            flux%sw_up(jcol,jlev) = sum_up
+            flux%sw_dn(jcol,jlev) = sum_dn_diff + sum_dn_dir
+            if (allocated(flux%sw_dn_direct)) then
+              flux%sw_dn_direct(jcol,jlev) = sum_dn_dir
+            end if
+          end do
+#endif
+          
           ! Cloudy flux profiles currently assume completely overcast
           ! skies; perform weighted average with clear-sky profile
-          flux%sw_up(jcol,:) =  total_cloud_cover *flux%sw_up(jcol,:) &
-               &  + (1.0_jprb - total_cloud_cover)*flux%sw_up_clear(jcol,:)
-          flux%sw_dn(jcol,:) =  total_cloud_cover *flux%sw_dn(jcol,:) &
-               &  + (1.0_jprb - total_cloud_cover)*flux%sw_dn_clear(jcol,:)
-          if (allocated(flux%sw_dn_direct)) then
-            flux%sw_dn_direct(jcol,:) = total_cloud_cover *flux%sw_dn_direct(jcol,:) &
-                 &  + (1.0_jprb - total_cloud_cover)*flux%sw_dn_direct_clear(jcol,:)
-          end if
+          do jlev = 1, nlev+1
+            flux%sw_up(jcol,jlev) =  total_cloud_cover *flux%sw_up(jcol,jlev) &
+                 &     + (1.0_jprb - total_cloud_cover)*flux%sw_up_clear(jcol,jlev)
+            flux%sw_dn(jcol,jlev) =  total_cloud_cover *flux%sw_dn(jcol,jlev) &
+                 &     + (1.0_jprb - total_cloud_cover)*flux%sw_dn_clear(jcol,jlev)
+            if (allocated(flux%sw_dn_direct)) then
+              flux%sw_dn_direct(jcol,jlev) = total_cloud_cover *flux%sw_dn_direct(jcol,jlev) &
+                   &  + (1.0_jprb - total_cloud_cover)*flux%sw_dn_direct_clear(jcol,jlev)
+            end if
+          end do
           ! Likewise for surface spectral fluxes
-          flux%sw_dn_diffuse_surf_g(:,jcol) = flux_dn_diffuse(:,nlev+1)
-          flux%sw_dn_direct_surf_g(:,jcol)  = flux_dn_direct(:,nlev+1)
-          flux%sw_dn_diffuse_surf_g(:,jcol) = total_cloud_cover *flux%sw_dn_diffuse_surf_g(:,jcol) &
-               &     + (1.0_jprb - total_cloud_cover)*flux%sw_dn_diffuse_surf_clear_g(:,jcol)
-          flux%sw_dn_direct_surf_g(:,jcol) = total_cloud_cover *flux%sw_dn_direct_surf_g(:,jcol) &
-               &     + (1.0_jprb - total_cloud_cover)*flux%sw_dn_direct_surf_clear_g(:,jcol)
-          
+          do jg = 1,ng
+            flux%sw_dn_diffuse_surf_g(jg,jcol) = flux_dn_diffuse(jg,nlev+1)
+            flux%sw_dn_direct_surf_g(jg,jcol)  = flux_dn_direct(jg,nlev+1)
+            flux%sw_dn_diffuse_surf_g(jg,jcol) = total_cloud_cover *flux%sw_dn_diffuse_surf_g(jg,jcol) &
+                 &                 + (1.0_jprb - total_cloud_cover)*flux%sw_dn_diffuse_surf_clear_g(jg,jcol)
+            flux%sw_dn_direct_surf_g(jg,jcol)  = total_cloud_cover *flux%sw_dn_direct_surf_g(jg,jcol) &
+                 &                 + (1.0_jprb - total_cloud_cover)*flux%sw_dn_direct_surf_clear_g(jg,jcol)
+          end do
+
         else
           ! No cloud in profile and clear-sky fluxes already
           ! calculated: copy them over
-          flux%sw_up(jcol,:) = flux%sw_up_clear(jcol,:)
-          flux%sw_dn(jcol,:) = flux%sw_dn_clear(jcol,:)
-          if (allocated(flux%sw_dn_direct)) then
-            flux%sw_dn_direct(jcol,:) = flux%sw_dn_direct_clear(jcol,:)
-          end if
-          flux%sw_dn_diffuse_surf_g(:,jcol) = flux%sw_dn_diffuse_surf_clear_g(:,jcol)
-          flux%sw_dn_direct_surf_g(:,jcol)  = flux%sw_dn_direct_surf_clear_g(:,jcol)
+          do jlev = 1, nlev+1
+            flux%sw_up(jcol,jlev) = flux%sw_up_clear(jcol,jlev)
+            flux%sw_dn(jcol,jlev) = flux%sw_dn_clear(jcol,jlev)
+            if (allocated(flux%sw_dn_direct)) then
+              flux%sw_dn_direct(jcol,jlev) = flux%sw_dn_direct_clear(jcol,jlev)
+            end if
+          end do
+          do jg = 1,ng
+            flux%sw_dn_diffuse_surf_g(jg,jcol) = flux%sw_dn_diffuse_surf_clear_g(jg,jcol)
+            flux%sw_dn_direct_surf_g(jg,jcol)  = flux%sw_dn_direct_surf_clear_g(jg,jcol)
+          end do
 
         end if ! Cloud is present in profile
@@ -307,18 +378,22 @@
       else
         ! Set fluxes to zero if sun is below the horizon
-        flux%sw_up(jcol,:) = 0.0_jprb
-        flux%sw_dn(jcol,:) = 0.0_jprb
-        if (allocated(flux%sw_dn_direct)) then
-          flux%sw_dn_direct(jcol,:) = 0.0_jprb
-        end if
-        flux%sw_up_clear(jcol,:) = 0.0_jprb
-        flux%sw_dn_clear(jcol,:) = 0.0_jprb
-        if (allocated(flux%sw_dn_direct_clear)) then
-          flux%sw_dn_direct_clear(jcol,:) = 0.0_jprb
-        end if
-        flux%sw_dn_diffuse_surf_g(:,jcol) = 0.0_jprb
-        flux%sw_dn_direct_surf_g(:,jcol)  = 0.0_jprb
-        flux%sw_dn_diffuse_surf_clear_g(:,jcol) = 0.0_jprb
-        flux%sw_dn_direct_surf_clear_g(:,jcol)  = 0.0_jprb
+        do jlev = 1, nlev+1
+          flux%sw_up(jcol,jlev) = 0.0_jprb
+          flux%sw_dn(jcol,jlev) = 0.0_jprb
+          if (allocated(flux%sw_dn_direct)) then
+            flux%sw_dn_direct(jcol,jlev) = 0.0_jprb
+          end if
+          flux%sw_up_clear(jcol,jlev) = 0.0_jprb
+          flux%sw_dn_clear(jcol,jlev) = 0.0_jprb
+          if (allocated(flux%sw_dn_direct_clear)) then
+            flux%sw_dn_direct_clear(jcol,jlev) = 0.0_jprb
+          end if
+        end do
+        do jg = 1,ng
+          flux%sw_dn_diffuse_surf_g(jg,jcol) = 0.0_jprb
+          flux%sw_dn_direct_surf_g(jg,jcol)  = 0.0_jprb
+          flux%sw_dn_diffuse_surf_clear_g(jg,jcol) = 0.0_jprb
+          flux%sw_dn_direct_surf_clear_g(jg,jcol)  = 0.0_jprb
+        end do
       end if ! Sun above horizon
 
Index: /LMDZ6/trunk/libf/phylmd/ecrad/radiation/radiation_save.F90
===================================================================
--- /LMDZ6/trunk/libf/phylmd/ecrad/radiation/radiation_save.F90	(revision 4852)
+++ /LMDZ6/trunk/libf/phylmd/ecrad/radiation/radiation_save.F90	(revision 4853)
@@ -86,5 +86,5 @@
     end if
 
-    if (config%i_gas_model == IGasModelMonochromatic &
+    if (config%i_gas_model_lw == IGasModelMonochromatic &
          .and. config%mono_lw_wavelength > 0.0_jprb) then
       lw_units_str = 'W m-3'
@@ -515,5 +515,5 @@
     end if
 
-    if (config%i_gas_model == IGasModelMonochromatic &
+    if (config%i_gas_model_lw == IGasModelMonochromatic &
          .and. config%mono_lw_wavelength > 0.0_jprb) then
       lw_units_str = 'W m-3'
Index: DZ6/trunk/libf/phylmd/ecrad/radiation/radiation_scheme.F90
===================================================================
--- /LMDZ6/trunk/libf/phylmd/ecrad/radiation/radiation_scheme.F90	(revision 4852)
+++ 	(revision )
@@ -1,691 +1,0 @@
-! AI mars 2021
-! ====================== Interface between ECRAD and LMDZ ====================
-! radiation_scheme.F90 appelee dans radlwsw_m.F90 si iflag_rttm = 2
-! revoir toutes les parties avec "AI ATTENTION" 
-! Mars 2021 :
-!             - Revoir toutes les parties commentees AI ATTENTION
-!             1. Traitement des aerosols
-!             2. Verifier les parametres times issus de LMDZ (calcul issed)
-!             3. Configuration a partir de namelist
-!             4. frac_std = 0.75      
-! Juillet 2023 :
-!             
-! ============================================================================
-module interface_lmdz_ecrad
-
-IMPLICIT NONE        
-
-contains
-
-SUBROUTINE RADIATION_SCHEME &
-! Inputs
-     & (KIDIA, KFDIA, KLON, KLEV, KAEROSOL, NSW, &
-     &  namelist_file, ok_3Deffect, &
-     &  debut, ok_volcan, flag_aerosol_strat, &
-     &  IDAY, TIME, &
-     &  PSOLAR_IRRADIANCE, &
-     &  PMU0, PTEMPERATURE_SKIN, &
-     &  PALBEDO_DIF, PALBEDO_DIR, &
-     &  PEMIS, PEMIS_WINDOW, &
-     &  PGELAM, PGEMU, &
-     &  PPRESSURE_H, PTEMPERATURE_H, PQ, PQSAT, &
-     &  PCO2, PCH4, PN2O, PNO2, PCFC11, PCFC12, PHCFC22, &
-     &  PCCL4, PO3, PO2, &
-     &  PCLOUD_FRAC, PQ_LIQUID, PQ_ICE, PQ_SNOW, &
-     &  ZRE_LIQUID_UM, ZRE_ICE_UM, &
-     &  PAEROSOL_OLD, PAEROSOL, &
-! Outputs
-     &  PFLUX_SW, PFLUX_LW, PFLUX_SW_CLEAR, PFLUX_LW_CLEAR, &
-     &  PFLUX_SW_DN, PFLUX_LW_DN, PFLUX_SW_DN_CLEAR, PFLUX_LW_DN_CLEAR, &
-     &  PFLUX_SW_UP, PFLUX_LW_UP, PFLUX_SW_UP_CLEAR, PFLUX_LW_UP_CLEAR, &
-     &  PFLUX_DIR, PFLUX_DIR_CLEAR, PFLUX_DIR_INTO_SUN, &
-     &  PFLUX_UV, PFLUX_PAR, PFLUX_PAR_CLEAR, &
-     &  PEMIS_OUT, PLWDERIVATIVE, &
-     &  PSWDIFFUSEBAND, PSWDIRECTBAND, &
-     &  ecrad_cloud_cover_sw)
-
-! RADIATION_SCHEME - Interface to modular radiation scheme
-!
-! (C) Copyright 2015- ECMWF.
-!
-! This software is licensed under the terms of the Apache Licence Version 2.0
-! which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
-!
-! In applying this licence, ECMWF does not waive the privileges and immunities
-! granted to it by virtue of its status as an intergovernmental organisation
-! nor does it submit to any jurisdiction.
-!
-! PURPOSE
-! -------
-!   The modular radiation scheme is contained in a separate
-!   library. This routine puts the the IFS arrays into appropriate
-!   objects, computing the additional data that is required, and sends
-!   it to the radiation scheme.  It returns net fluxes and surface
-!   flux components needed by the rest of the model. 
-!
-!   Lower case is used for variables and types taken from the
-!   radiation library
-!
-! INTERFACE
-! ---------
-!    RADIATION_SCHEME is called from RADLSWR. The
-!    SETUP_RADIATION_SCHEME routine (in the RADIATION_SETUP module)
-!    should have been run first.
-!
-! AUTHOR
-! ------
-!   Robin Hogan, ECMWF
-!   Original: 2015-09-16
-!
-! MODIFICATIONS
-! -------------
-!
-! TO DO
-! -----
-!
-!-----------------------------------------------------------------------
-
-! Modules from ifs or ifsaux libraries
-USE PARKIND1 , ONLY : JPIM, JPRB
-USE YOMHOOK  , ONLY : LHOOK, DR_HOOK
-USE RADIATION_SETUP
-USE YOMCST   , ONLY : RSIGMA ! Stefan-Boltzmann constant
-!USE RADIATION_SETUP, ONLY : SETUP_RADIATION_SCHEME, &
-!                         &  config_type, driver_config_type, &
-!                         &  NWEIGHT_UV,  IBAND_UV,  WEIGHT_UV, &
-!                         &  NWEIGHT_PAR, IBAND_PAR, WEIGHT_PAR, &
-!                         &  ITYPE_TROP_BG_AER,  TROP_BG_AER_MASS_EXT, &
-!                         &  ITYPE_STRAT_BG_AER, STRAT_BG_AER_MASS_EXT, &
-!                         &  ISolverSpartacus
-
-! Modules from radiation library
-USE radiation_single_level,   ONLY : single_level_type
-USE radiation_thermodynamics, ONLY : thermodynamics_type
-USE radiation_gas
-USE radiation_cloud,          ONLY : cloud_type
-USE radiation_aerosol,        ONLY : aerosol_type
-USE radiation_flux,           ONLY : flux_type
-USE radiation_interface,      ONLY : radiation, set_gas_units
-USE radiation_save,           ONLY : save_inputs
-
-USE mod_phys_lmdz_para
-
-IMPLICIT NONE
-
-! INPUT ARGUMENTS
-! *** Array dimensions and ranges
-INTEGER(KIND=JPIM),INTENT(IN) :: KIDIA    ! Start column to process
-INTEGER(KIND=JPIM),INTENT(IN) :: KFDIA    ! End column to process
-!INTEGER, INTENT(IN) :: KIDIA, KFDIA
-INTEGER(KIND=JPIM),INTENT(IN) :: KLON     ! Number of columns
-INTEGER(KIND=JPIM),INTENT(IN) :: KLEV     ! Number of levels
-!INTEGER, INTENT(IN) :: KLON, KLEV
-!INTEGER(KIND=JPIM),INTENT(IN) :: KAEROLMDZ ! Number of aerosol types
-INTEGER(KIND=JPIM),INTENT(IN) :: KAEROSOL
-INTEGER(KIND=JPIM),INTENT(IN) :: NSW ! Numbe of bands
-
-! AI ATTENTION
-!INTEGER, PARAMETER :: KAEROSOL = 12
-
-! *** Single-level fields
-REAL(KIND=JPRB),   INTENT(IN) :: PSOLAR_IRRADIANCE ! (W m-2)
-REAL(KIND=JPRB),   INTENT(IN) :: PMU0(KLON) ! Cosine of solar zenith ang
-REAL(KIND=JPRB),   INTENT(IN) :: PTEMPERATURE_SKIN(KLON) ! (K)
-! Diffuse and direct components of surface shortwave albedo
-!REAL(KIND=JPRB),   INTENT(IN) :: PALBEDO_DIF(KLON,YRERAD%NSW)
-!REAL(KIND=JPRB),   INTENT(IN) :: PALBEDO_DIR(KLON,YRERAD%NSW)
-REAL(KIND=JPRB),   INTENT(IN) :: PALBEDO_DIF(KLON,NSW)
-REAL(KIND=JPRB),   INTENT(IN) :: PALBEDO_DIR(KLON,NSW)
-! Longwave emissivity outside and inside the window region
-REAL(KIND=JPRB),   INTENT(IN) :: PEMIS(KLON)
-REAL(KIND=JPRB),   INTENT(IN) :: PEMIS_WINDOW(KLON)
-! Longitude (radians), sine of latitude
-REAL(KIND=JPRB),   INTENT(IN) :: PGELAM(KLON)
-REAL(KIND=JPRB),   INTENT(IN) :: PGEMU(KLON)
-! Land-sea mask
-!REAL(KIND=JPRB),   INTENT(IN) :: PLAND_SEA_MASK(KLON) 
-
-! *** Variables on half levels
-REAL(KIND=JPRB),   INTENT(IN) :: PPRESSURE_H(KLON,KLEV+1)    ! (Pa)
-REAL(KIND=JPRB),   INTENT(IN) :: PTEMPERATURE_H(KLON,KLEV+1) ! (K)
-
-! *** Gas mass mixing ratios on full levels
-REAL(KIND=JPRB),   INTENT(IN) :: PQ(KLON,KLEV) 
-! AI
-REAL(KIND=JPRB),   INTENT(IN) :: PQSAT(KLON,KLEV)
-REAL(KIND=JPRB),   INTENT(IN) :: PCO2
-REAL(KIND=JPRB),   INTENT(IN) :: PCH4 
-REAL(KIND=JPRB),   INTENT(IN) :: PN2O 
-REAL(KIND=JPRB),   INTENT(IN) :: PNO2 
-REAL(KIND=JPRB),   INTENT(IN) :: PCFC11
-REAL(KIND=JPRB),   INTENT(IN) :: PCFC12
-REAL(KIND=JPRB),   INTENT(IN) :: PHCFC22
-REAL(KIND=JPRB),   INTENT(IN) :: PCCL4
-REAL(KIND=JPRB),   INTENT(IN) :: PO3(KLON,KLEV) ! AI (kg/kg) ATTENTION (Pa*kg/kg) 
-REAL(KIND=JPRB),   INTENT(IN) :: PO2
-
-! *** Cloud fraction and hydrometeor mass mixing ratios
-REAL(KIND=JPRB),   INTENT(IN) :: PCLOUD_FRAC(KLON,KLEV)
-REAL(KIND=JPRB),   INTENT(IN) :: PQ_LIQUID(KLON,KLEV)
-REAL(KIND=JPRB),   INTENT(IN) :: PQ_ICE(KLON,KLEV)
-!REAL(KIND=JPRB),   INTENT(IN) :: PQ_RAIN(KLON,KLEV)
-REAL(KIND=JPRB),   INTENT(IN) :: PQ_SNOW(KLON,KLEV)
-
-! *** Aerosol mass mixing ratios
-REAL(KIND=JPRB),   INTENT(IN) :: PAEROSOL_OLD(KLON,6,KLEV)
-REAL(KIND=JPRB),   INTENT(IN) :: PAEROSOL(KLON,KLEV,KAEROSOL)
-
-!REAL(KIND=JPRB),   INTENT(IN) :: PCCN_LAND(KLON) 
-!REAL(KIND=JPRB),   INTENT(IN) :: PCCN_SEA(KLON) 
-
-!AI mars 2021
-INTEGER(KIND=JPIM), INTENT(IN) :: IDAY
-REAL(KIND=JPRB), INTENT(IN)    :: TIME
-
-! Name of file names specified on command line
-character(len=512), INTENT(IN) :: namelist_file
-logical, INTENT(IN)            :: ok_3Deffect, debut, ok_volcan
-INTEGER(KIND=JPIM), INTENT(IN) :: flag_aerosol_strat
-
-
-! OUTPUT ARGUMENTS
-
-! *** Net fluxes on half-levels (W m-2)
-REAL(KIND=JPRB),  INTENT(OUT) :: PFLUX_SW(KLON,KLEV+1) 
-REAL(KIND=JPRB),  INTENT(OUT) :: PFLUX_LW(KLON,KLEV+1) 
-REAL(KIND=JPRB),  INTENT(OUT) :: PFLUX_SW_CLEAR(KLON,KLEV+1) 
-REAL(KIND=JPRB),  INTENT(OUT) :: PFLUX_LW_CLEAR(KLON,KLEV+1) 
-
-!*** DN and UP flux on half-levels (W m-2)
-REAL(KIND=JPRB),  INTENT(OUT) :: PFLUX_SW_DN(KLON,KLEV+1)
-REAL(KIND=JPRB),  INTENT(OUT) :: PFLUX_LW_DN(KLON,KLEV+1)
-REAL(KIND=JPRB),  INTENT(OUT) :: PFLUX_SW_DN_CLEAR(KLON,KLEV+1)
-REAL(KIND=JPRB),  INTENT(OUT) :: PFLUX_LW_DN_CLEAR(KLON,KLEV+1)
-REAL(KIND=JPRB),  INTENT(OUT) :: PFLUX_SW_UP(KLON,KLEV+1)
-REAL(KIND=JPRB),  INTENT(OUT) :: PFLUX_LW_UP(KLON,KLEV+1)
-REAL(KIND=JPRB),  INTENT(OUT) :: PFLUX_SW_UP_CLEAR(KLON,KLEV+1)
-REAL(KIND=JPRB),  INTENT(OUT) :: PFLUX_LW_UP_CLEAR(KLON,KLEV+1)
-
-! Direct component of surface flux into horizontal plane
-REAL(KIND=JPRB),  INTENT(OUT) :: PFLUX_DIR(KLON)
-REAL(KIND=JPRB),  INTENT(OUT) :: PFLUX_DIR_CLEAR(KLON)
-! As PFLUX_DIR but into a plane perpendicular to the sun
-REAL(KIND=JPRB),  INTENT(OUT) :: PFLUX_DIR_INTO_SUN(KLON)
-
-! *** Ultraviolet and photosynthetically active radiation (W m-2)
-REAL(KIND=JPRB),  INTENT(OUT) :: PFLUX_UV(KLON)
-REAL(KIND=JPRB),  INTENT(OUT) :: PFLUX_PAR(KLON)
-REAL(KIND=JPRB),  INTENT(OUT) :: PFLUX_PAR_CLEAR(KLON)
-
-! Diagnosed longwave surface emissivity across the whole spectrum
-REAL(KIND=JPRB),  INTENT(OUT) :: PEMIS_OUT(KLON)   
-
-! Partial derivative of total-sky longwave upward flux at each level
-! with respect to upward flux at surface, used to correct heating
-! rates at gridpoints/timesteps between calls to the full radiation
-! scheme.  Note that this version uses the convention of level index
-! increasing downwards, unlike the local variable ZLwDerivative that
-! is returned from the LW radiation scheme.
-REAL(KIND=JPRB),  INTENT(OUT) :: PLWDERIVATIVE(KLON,KLEV+1)
-
-! Surface diffuse and direct downwelling shortwave flux in each
-! shortwave albedo band, used in RADINTG to update the surface fluxes
-! accounting for high-resolution albedo information
-REAL(KIND=JPRB),  INTENT(OUT) :: PSWDIFFUSEBAND(KLON,NSW)
-REAL(KIND=JPRB),  INTENT(OUT) :: PSWDIRECTBAND (KLON,NSW)
-
-!AI Nov 2023
-REAL(KIND=JPRB),  INTENT(OUT) :: ecrad_cloud_cover_sw(KLON)
-
-! LOCAL VARIABLES
-! AI ATTENTION
-type(config_type),save         :: rad_config
-!!$OMP THREADPRIVATE(rad_config)
-type(driver_config_type),save  :: driver_config
-!!$OMP THREADPRIVATE(driver_config)
-!type(config_type)        :: rad_config
-!type(driver_config_type)  :: driver_config
-TYPE(single_level_type)   :: single_level
-TYPE(thermodynamics_type) :: thermodynamics
-TYPE(gas_type)            :: gas
-TYPE(cloud_type)          :: cloud
-TYPE(aerosol_type)        :: aerosol
-TYPE(flux_type)           :: flux
-
-! Mass mixing ratio of ozone (kg/kg)
-REAL(KIND=JPRB)           :: ZO3(KLON,KLEV)
-
-! Cloud effective radii in microns
-REAL(KIND=JPRB)           :: ZRE_LIQUID_UM(KLON,KLEV)
-REAL(KIND=JPRB)           :: ZRE_ICE_UM(KLON,KLEV)
-
-! Cloud overlap decorrelation length for cloud boundaries in km
-REAL(KIND=JPRB)           :: ZDECORR_LEN_KM(KLON)
-
-! Ratio of cloud overlap decorrelation length for cloud water
-! inhomogeneities to that for cloud boundaries (typically 0.5)
-!REAL(KIND=JPRB)           :: ZDECORR_LEN_RATIO = 0.5_jprb
-
-! The surface net longwave flux if the surface was a black body, used
-! to compute the effective broadband surface emissivity
-REAL(KIND=JPRB)           :: ZBLACK_BODY_NET_LW(KIDIA:KFDIA)
-
-! Layer mass in kg m-2
-REAL(KIND=JPRB)           :: ZLAYER_MASS(KIDIA:KFDIA,KLEV)
-
-! Time integers
-INTEGER :: ITIM
-
-! Loop indices
-INTEGER :: JLON, JLEV, JBAND, JB_ALBEDO, JAER
-
-REAL(KIND=JPRB) :: ZHOOK_HANDLE
-
-! AI ATTENTION traitement aerosols
-INTEGER, PARAMETER :: NAERMACC = 1
-
-logical :: loutput=.true.
-logical :: lprint_input=.false.
-logical :: lprint_config=.false.
-logical, save :: debut_ecrad=.true.
-!$OMP THREADPRIVATE(debut_ecrad)
-integer, save :: itap_ecrad=0
-!$OMP THREADPRIVATE(itap_ecrad)
-
-REAL(KIND=JPRB) ::  inv_cloud_effective_size(KLON,KLEV)
-REAL(KIND=JPRB) ::  inv_inhom_effective_size(KLON,KLEV)
-
-integer :: irang
-
-
-IF (LHOOK) CALL DR_HOOK('RADIATION_SCHEME',0,ZHOOK_HANDLE)
-
-! A.I juillet 2023 : 
-! Initialisation dans radiation_setup au 1er passage dans Ecrad
-!$OMP MASTER
-if (.not.ok_3Deffect) then
-  if (debut_ecrad) then
-   call SETUP_RADIATION_SCHEME(loutput,namelist_file,rad_config,driver_config)
-   debut_ecrad=.false. 
-  endif 
-else
-   call SETUP_RADIATION_SCHEME(loutput,namelist_file,rad_config,driver_config)
-endif
-!$OMP END MASTER
-!$OMP BARRIER 
-! Fin partie initialisation et configuration 
-
-!AI print fichiers namelist utilise
-!if (is_omp_root) then
-! itap_ecrad=itap_ecrad+1
-! print*,'Dans radiation_scheme itap_ecrad, mpi_rank, omp_rank, namelist_file : ', &
-!         itap_ecrad, mpi_rank, omp_rank, namelist_file
-!else
-! print*,'mpi_rank omp_rank, namelist_file :', mpi_rank, omp_rank, namelist_file
-!endif
-
-! AI 11 23 Allocates depplaces au debut
-print*,'*********** ALLOCATES *******************************'
-! AI ATTENTION
-! Allocate memory in radiation objects
-! emissivite avec une seule bande
-CALL single_level%allocate(KLON, NSW, 1, &
-     &                     use_sw_albedo_direct=.TRUE.)
-CALL thermodynamics%allocate(KLON, KLEV, use_h2o_sat=.true.)
-CALL cloud%allocate(KLON, KLEV)
-CALL aerosol%allocate(KLON, 1, KLEV, KAEROSOL)
-CALL gas%allocate(KLON, KLEV)
-CALL flux%allocate(rad_config, 1, KLON, KLEV)
-
-print*,'************* THERMO (input) ************************************'
-! Set thermodynamic profiles: simply copy over the half-level
-! pressure and temperature
-! AI
-! pressure_hl > paprs
-! temperature_hl calculee dans radlsw de la meme facon que pour RRTM
-thermodynamics%pressure_hl   (KIDIA:KFDIA,:) = PPRESSURE_H   (KIDIA:KFDIA,:)
-thermodynamics%temperature_hl(KIDIA:KFDIA,:) = PTEMPERATURE_H(KIDIA:KFDIA,:)
-!print*,'Compute saturation specific humidity'
-! Compute saturation specific humidity, used to hydrate aerosols. The
-! "2" for the last argument indicates that the routine is not being
-! called from within the convection scheme.
-!CALL SATUR(KIDIA, KFDIA, KLON, 1, KLEV, &
-!     &  PPRESSURE, PTEMPERATURE, thermodynamics%h2o_sat_liq, 2)
-! Alternative approximate version using temperature and pressure from
-! the thermodynamics structure
-!CALL thermodynamics%calc_saturation_wrt_liquid(KIDIA, KFDIA)
-!AI ATTENTION
-thermodynamics%h2o_sat_liq = PQSAT
-
-print*,'********** SINGLE LEVEL VARS **********************************'
-!AI ATTENTION
-! Set single-level fileds
-single_level%solar_irradiance              = PSOLAR_IRRADIANCE
-single_level%cos_sza(KIDIA:KFDIA)          = PMU0(KIDIA:KFDIA)
-single_level%skin_temperature(KIDIA:KFDIA) = PTEMPERATURE_SKIN(KIDIA:KFDIA)
-single_level%sw_albedo(KIDIA:KFDIA,:)      = PALBEDO_DIF(KIDIA:KFDIA,:)
-single_level%sw_albedo_direct(KIDIA:KFDIA,:)=PALBEDO_DIR(KIDIA:KFDIA,:)
-single_level%lw_emissivity(KIDIA:KFDIA,1)  = PEMIS(KIDIA:KFDIA)
-!single_level%lw_emissivity(KIDIA:KFDIA,2)  = PEMIS_WINDOW(KIDIA:KFDIA)
-
-! Create the relevant seed from date and time get the starting day
-! and number of minutes since start
-!IDAY = NDD(NINDAT)
-!cur_day
-!ITIM = NINT(NSTEP * YRRIP%TSTEP / 60.0_JPRB)
-!ITIM = NINT(TIME / 60.0_JPRB)
-!current_time
-!allocate(single_level%iseed(KIDIA:KFDIA))
-!DO JLON = KIDIA, KFDIA
-  ! This method gives a unique value for roughly every 1-km square
-  ! on the globe and every minute.  ASIN(PGEMU)*60 gives rough
-  ! latitude in degrees, which we multiply by 100 to give a unique
-  ! value for roughly every km. PGELAM*60*100 gives a unique number
-  ! for roughly every km of longitude around the equator, which we
-  ! multiply by 180*100 so there is no overlap with the latitude
-  ! values.  The result can be contained in a 32-byte integer (but
-  ! since random numbers are generated with the help of integer
-  ! overflow, it should not matter if the number did overflow).
-!  single_level%iseed(JLON) = ITIM + IDAY & 
-!       &  +  NINT(PGELAM(JLON)*108000000.0_JPRB &
-!       &          + ASIN(PGEMU(JLON))*6000.0_JPRB)
-!ENDDO
-!AI Nov 23
-! Simple initialization of the seeds for the Monte Carlo scheme
-call single_level%init_seed_simple(kidia, kfdia)
-
-print*,'********** CLOUDS (allocate + input) *******************************************'
-!print*,'Appel Allocate clouds'
-! Set cloud fields
-cloud%q_liq(KIDIA:KFDIA,:)    = PQ_LIQUID(KIDIA:KFDIA,:)
-cloud%q_ice(KIDIA:KFDIA,:)    = PQ_ICE(KIDIA:KFDIA,:) + PQ_SNOW(KIDIA:KFDIA,:)
-cloud%fraction(KIDIA:KFDIA,:) = PCLOUD_FRAC(KIDIA:KFDIA,:)
-!!! ok AI ATTENTION a voir avec JL
-! Compute effective radi and convert to metres
-! AI. : on passe directement les champs de LMDZ
-cloud%re_liq(KIDIA:KFDIA,:) = ZRE_LIQUID_UM(KIDIA:KFDIA,:)
-cloud%re_ice(KIDIA:KFDIA,:) = ZRE_ICE_UM(KIDIA:KFDIA,:)
-! Get the cloud overlap decorrelation length (for cloud boundaries),
-! in km, according to the parameterization specified by NDECOLAT,
-! and insert into the "cloud" object. Also get the ratio of
-! decorrelation lengths for cloud water content inhomogeneities and
-! cloud boundaries, and set it in the "rad_config" object.
-! IFS :
-!CALL CLOUD_OVERLAP_DECORR_LEN(KIDIA, KFDIA, KLON, PGEMU, YRERAD%NDECOLAT, &
-!     &    ZDECORR_LEN_KM, PDECORR_LEN_RATIO=ZDECORR_LEN_RATIO)
-! AI valeur dans namelist
-! rad_config%cloud_inhom_decorr_scaling = ZDECORR_LEN_RATIO
-!AI ATTENTION meme valeur que dans offline
-! A mettre dans namelist
-ZDECORR_LEN_KM = driver_config%overlap_decorr_length
-DO JLON = KIDIA,KFDIA
-  CALL cloud%set_overlap_param(thermodynamics, &
-       &                 ZDECORR_LEN_KM(JLON), &
-       &                 istartcol=JLON, iendcol=JLON)
-ENDDO
-! IFS :
-! Cloud water content fractional standard deviation is configurable
-! from namelist NAERAD but must be globally constant. Before it was
-! hard coded at 1.0.
-!CALL cloud%create_fractional_std(KLON, KLEV, YRERAD%RCLOUD_FRAC_STD)
-! AI ATTENTION frac_std=0.75 meme valeur que dans la version offline
-CALL cloud%create_fractional_std(KLON, KLEV, driver_config%frac_std)
-
-if (ok_3Deffect) then
- if (driver_config%ok_effective_size) then
-     call cloud%create_inv_cloud_effective_size_eta(klon, klev, &
-               &  thermodynamics%pressure_hl, &
-               &  driver_config%low_inv_effective_size, &
-               &  driver_config%middle_inv_effective_size, &
-               &  driver_config%high_inv_effective_size, 0.8_jprb, 0.45_jprb, &
-               &  KIDIA, KFDIA)
-   else if (driver_config%ok_separation) then
-     call cloud%param_cloud_effective_separation_eta(klon, klev, &
-               &  thermodynamics%pressure_hl, &
-               &  driver_config%cloud_separation_scale_surface, &
-               &  driver_config%cloud_separation_scale_toa, &
-               &  driver_config%cloud_separation_scale_power, &
-               &  driver_config%cloud_inhom_separation_factor, &
-               &  KIDIA, KFDIA)
-   endif     
- else  
- if (rad_config%i_solver_sw == ISolverSPARTACUS &
-      & .or.   rad_config%i_solver_lw == ISolverSPARTACUS) then
-   ! AI ! Read cloud properties needed by SPARTACUS
-   if (driver_config%ok_effective_size) then
-     call cloud%create_inv_cloud_effective_size_eta(klon, klev, &
-               &  thermodynamics%pressure_hl, &
-               &  driver_config%low_inv_effective_size, &
-               &  driver_config%middle_inv_effective_size, &
-               &  driver_config%high_inv_effective_size, 0.8_jprb, 0.45_jprb, &
-               &  KIDIA, KFDIA)
-   else if (driver_config%ok_separation) then
-     call cloud%param_cloud_effective_separation_eta(klon, klev, &
-               &  thermodynamics%pressure_hl, &
-               &  driver_config%cloud_separation_scale_surface, &
-               &  driver_config%cloud_separation_scale_toa, &
-               &  driver_config%cloud_separation_scale_power, &
-               &  driver_config%cloud_inhom_separation_factor, &
-               &  KIDIA, KFDIA)
-   endif
- endif  
-endif
-
-print*,'******** AEROSOLS (input) **************************************'
-!IF (NAERMACC > 0) THEN
-!ELSE
-!  CALL aerosol%allocate(KLON, 1, KLEV, 6) ! Tegen climatology
-!ENDIF
-! Compute the dry mass of each layer neglecting humidity effects, in
-! kg m-2, needed to scale some of the aerosol inputs
-! AI commente ATTENTION
-!CALL thermodynamics%get_layer_mass(ZLAYER_MASS)
-
-! Copy over aerosol mass mixing ratio
-!IF (NAERMACC > 0) THEN
-
-  ! MACC aerosol climatology - this is already in mass mixing ratio
-  ! units with the required array orientation so we can copy it over
-  ! directly
-  aerosol%mixing_ratio(KIDIA:KFDIA,:,:) = PAEROSOL(KIDIA:KFDIA,:,:)
-
-  ! Add the tropospheric and stratospheric backgrounds contained in the
-  ! old Tegen arrays - this is very ugly!
-! AI ATTENTION
-!  IF (TROP_BG_AER_MASS_EXT > 0.0_JPRB) THEN
-!    aerosol%mixing_ratio(KIDIA:KFDIA,:,ITYPE_TROP_BG_AER) &
-!         &  = aerosol%mixing_ratio(KIDIA:KFDIA,:,ITYPE_TROP_BG_AER) &
-!         &  + PAEROSOL_OLD(KIDIA:KFDIA,1,:) &
-!         &  / (ZLAYER_MASS * TROP_BG_AER_MASS_EXT)
-!  ENDIF
-!  IF (STRAT_BG_AER_MASS_EXT > 0.0_JPRB) THEN
-!    aerosol%mixing_ratio(KIDIA:KFDIA,:,ITYPE_STRAT_BG_AER) &
-!         &  = aerosol%mixing_ratio(KIDIA:KFDIA,:,ITYPE_STRAT_BG_AER) &
-!         &  + PAEROSOL_OLD(KIDIA:KFDIA,6,:) &
-!         &  / (ZLAYER_MASS * STRAT_BG_AER_MASS_EXT)
-!  ENDIF
-
-!ELSE
-
-  ! Tegen aerosol climatology - the array PAEROSOL_OLD contains the
-  ! 550-nm optical depth in each layer. The optics data file
-  ! aerosol_ifs_rrtm_tegen.nc does not contain mass extinction
-  ! coefficient, but a scaling factor that the 550-nm optical depth
-  ! should be multiplied by to obtain the optical depth in each
-  ! spectral band.  Therefore, in order for the units to work out, we
-  ! need to divide by the layer mass (in kg m-2) to obtain the 550-nm
-  ! cross-section per unit mass of dry air (so in m2 kg-1).  We also
-  ! need to permute the array.
-!  DO JLEV = 1,KLEV
-!    DO JAER = 1,6
-!      aerosol%mixing_ratio(KIDIA:KFDIA,JLEV,JAER) &
-!         &  = PAEROSOL_OLD(KIDIA:KFDIA,JAER,JLEV) &
-!         &  / ZLAYER_MASS(KIDIA:KFDIA,JLEV)
-!    ENDDO
-!  ENDDO
-!ENDIF
-
-print*,'********** GAS (input) ************************************************'
-!print*,'Appel Allocate gas'
-! Convert ozone Pa*kg/kg to kg/kg
-! AI ATTENTION
-!DO JLEV = 1,KLEV
-!  DO JLON = KIDIA,KFDIA
-!    ZO3(JLON,JLEV) = PO3_DP(JLON,JLEV) &
-!         &         / (PPRESSURE_H(JLON,JLEV+1)-PPRESSURE_H(JLON,JLEV))
-!  ENDDO
-!ENDDO
-!  Insert gas mixing ratios
-!print*,'Insert gas mixing ratios'
-CALL gas%put(IH2O,    IMassMixingRatio, PQ)
-CALL gas%put(IO3,     IMassMixingRatio, PO3)
-CALL gas%put_well_mixed(ICO2,    IMAssMixingRatio, PCO2)
-CALL gas%put_well_mixed(ICH4,    IMassMixingRatio, PCH4)
-CALL gas%put_well_mixed(IN2O,    IMassMixingRatio, PN2O)
-CALL gas%put_well_mixed(ICFC11,  IMassMixingRatio, PCFC11)
-CALL gas%put_well_mixed(ICFC12,  IMassMixingRatio, PCFC12)
-CALL gas%put_well_mixed(IHCFC22, IMassMixingRatio, PHCFC22)
-CALL gas%put_well_mixed(ICCL4,   IMassMixingRatio, PCCL4)
-CALL gas%put_well_mixed(IO2,     IMassMixingRatio, PO2)
-! Ensure the units of the gas mixing ratios are what is required by
-! the gas absorption model
-call set_gas_units(rad_config, gas)
-
-! Call radiation scheme
-!print*,'*** Appel radiation *** namelist **** omp_rank ****', &
-!         omp_rank, namelist_file
-!   if (rad_config%i_solver_sw == ISolverSPARTACUS) then 
-!    if (driver_config%ok_separation) then
-!      print*,'Avant radiation, mpi_rank, omp_rank, size, chape inv_cloud = ',&
-!              mpi_rank, omp_rank, &
-!              shape(cloud%inv_cloud_effective_size), &
-!              size(cloud%inv_cloud_effective_size)      
-!      do jlon=KIDIA, KFDIA      
-!        do jlev=1,klev
-!         print*,' Avant radiation mpi_rank, omp_rank, jlon, jlev, &
-!            &     cloud%inv_cloud_effective_size =', mpi_rank, &
-!            &     omp_rank, jlon, jlev, &
-!            &     cloud%inv_cloud_effective_size(jlon,jlev)
-!        enddo
-!      enddo
-!       cloud%inv_cloud_effective_size=inv_cloud_effective_size
-!       cloud%inv_inhom_effective_size=inv_inhom_effective_size
-!    endif
-!   endif
-CALL radiation(KLON, KLEV, KIDIA, KFDIA, rad_config, &
-     &  single_level, thermodynamics, gas, cloud, aerosol, flux)
-
- if (rad_config%use_aerosols) then
-    if (rad_config%i_gas_model == IGasModelIFSRRTMG) then     
-       CALL aeropt_5wv_ecrad(kidia, kfdia, 1, klev, &
-                             rad_config,thermodynamics,aerosol)
-    endif                 
-    if (flag_aerosol_strat.eq.2) then
-       CALL readaerosolstrato_ecrad(rad_config, debut, ok_volcan)
-    endif
- endif               
-
-print*,'*********** Sortie flux ****************'
-! Cloud cover
-ecrad_cloud_cover_sw = flux%cloud_cover_sw
-! Compute required output fluxes
-! DN and UP flux
-PFLUX_SW_DN(KIDIA:KFDIA,:) = flux%sw_dn(KIDIA:KFDIA,:)
-PFLUX_SW_UP(KIDIA:KFDIA,:) = flux%sw_up(KIDIA:KFDIA,:)
-PFLUX_LW_DN(KIDIA:KFDIA,:) = flux%lw_dn(KIDIA:KFDIA,:)
-PFLUX_LW_UP(KIDIA:KFDIA,:) = flux%lw_up(KIDIA:KFDIA,:)
-PFLUX_SW_DN_CLEAR(KIDIA:KFDIA,:) = flux%sw_dn_clear(KIDIA:KFDIA,:)
-PFLUX_SW_UP_CLEAR(KIDIA:KFDIA,:) = flux%sw_up_clear(KIDIA:KFDIA,:)
-PFLUX_LW_DN_CLEAR(KIDIA:KFDIA,:) = flux%lw_dn_clear(KIDIA:KFDIA,:)
-PFLUX_LW_UP_CLEAR(KIDIA:KFDIA,:) = flux%lw_up_clear(KIDIA:KFDIA,:)
-! First the net fluxes
-PFLUX_SW(KIDIA:KFDIA,:) = flux%sw_dn(KIDIA:KFDIA,:) - flux%sw_up(KIDIA:KFDIA,:)
-PFLUX_LW(KIDIA:KFDIA,:) = flux%lw_dn(KIDIA:KFDIA,:) - flux%lw_up(KIDIA:KFDIA,:)
-PFLUX_SW_CLEAR(KIDIA:KFDIA,:) &
-     &  = flux%sw_dn_clear(KIDIA:KFDIA,:) - flux%sw_up_clear(KIDIA:KFDIA,:)
-PFLUX_LW_CLEAR(KIDIA:KFDIA,:) &
-     &  = flux%lw_dn_clear(KIDIA:KFDIA,:) - flux%lw_up_clear(KIDIA:KFDIA,:)
-! Now the surface fluxes
-!PFLUX_SW_DN_SURF(KIDIA:KFDIA) = flux%sw_dn(KIDIA:KFDIA,KLEV+1)
-!PFLUX_LW_DN_SURF(KIDIA:KFDIA) = flux%lw_dn(KIDIA:KFDIA,KLEV+1)
-!PFLUX_SW_UP_SURF(KIDIA:KFDIA) = flux%sw_up(KIDIA:KFDIA,KLEV+1)
-!PFLUX_LW_UP_SURF(KIDIA:KFDIA) = flux%lw_up(KIDIA:KFDIA,KLEV+1)
-!PFLUX_SW_DN_CLEAR_SURF(KIDIA:KFDIA) = flux%sw_dn_clear(KIDIA:KFDIA,KLEV+1)
-!PFLUX_LW_DN_CLEAR_SURF(KIDIA:KFDIA) = flux%lw_dn_clear(KIDIA:KFDIA,KLEV+1)
-!PFLUX_SW_UP_CLEAR_SURF(KIDIA:KFDIA) = flux%sw_up_clear(KIDIA:KFDIA,KLEV+1)
-!PFLUX_LW_UP_CLEAR_SURF(KIDIA:KFDIA) = flux%lw_up_clear(KIDIA:KFDIA,KLEV+1)
-PFLUX_DIR(KIDIA:KFDIA) = flux%sw_dn_direct(KIDIA:KFDIA,KLEV+1)
-PFLUX_DIR_CLEAR(KIDIA:KFDIA) = flux%sw_dn_direct_clear(KIDIA:KFDIA,KLEV+1)
-PFLUX_DIR_INTO_SUN(KIDIA:KFDIA) = 0.0_JPRB
-WHERE (PMU0(KIDIA:KFDIA) > EPSILON(1.0_JPRB))
-  PFLUX_DIR_INTO_SUN(KIDIA:KFDIA) = PFLUX_DIR(KIDIA:KFDIA) / PMU0(KIDIA:KFDIA)
-END WHERE
-! Top-of-atmosphere downwelling flux
-!PFLUX_SW_DN_TOA(KIDIA:KFDIA) = flux%sw_dn(KIDIA:KFDIA,1)
-!PFLUX_SW_UP_TOA(KIDIA:KFDIA) = flux%sw_up(KIDIA:KFDIA,1)
-!PFLUX_LW_DN_TOA(KIDIA:KFDIA) = flux%lw_dn(KIDIA:KFDIA,1)
-!PFLUX_LW_UP_TOA(KIDIA:KFDIA) = flux%lw_up(KIDIA:KFDIA,1)
-!AI ATTENTION
-if (0.eq.1) then
-PFLUX_UV       (KIDIA:KFDIA) = 0.0_JPRB
-DO JBAND = 1,NWEIGHT_UV
-  PFLUX_UV(KIDIA:KFDIA) = PFLUX_UV(KIDIA:KFDIA) + WEIGHT_UV(JBAND) &
-       &  * flux%sw_dn_surf_band(IBAND_UV(JBAND),KIDIA:KFDIA)
-ENDDO
-! Compute photosynthetically active radiation similarly
-PFLUX_PAR      (KIDIA:KFDIA) = 0.0_JPRB
-PFLUX_PAR_CLEAR(KIDIA:KFDIA) = 0.0_JPRB
-DO JBAND = 1,NWEIGHT_PAR
-  PFLUX_PAR(KIDIA:KFDIA) = PFLUX_PAR(KIDIA:KFDIA) + WEIGHT_PAR(JBAND) &
-       &  * flux%sw_dn_surf_band(IBAND_PAR(JBAND),KIDIA:KFDIA)
-  PFLUX_PAR_CLEAR(KIDIA:KFDIA) = PFLUX_PAR_CLEAR(KIDIA:KFDIA) &
-       &  + WEIGHT_PAR(JBAND) &
-       &  * flux%sw_dn_surf_clear_band(IBAND_PAR(JBAND),KIDIA:KFDIA)
-ENDDO
-endif
-! Compute effective broadband emissivity
-ZBLACK_BODY_NET_LW = flux%lw_dn(KIDIA:KFDIA,KLEV+1) &
-     &  - RSIGMA*PTEMPERATURE_SKIN(KIDIA:KFDIA)**4
-PEMIS_OUT(KIDIA:KFDIA) = PEMIS(KIDIA:KFDIA)
-WHERE (ABS(ZBLACK_BODY_NET_LW) > 1.0E-5) 
-  PEMIS_OUT(KIDIA:KFDIA) = PFLUX_LW(KIDIA:KFDIA,KLEV+1) / ZBLACK_BODY_NET_LW
-END WHERE
-! Copy longwave derivatives
-! AI ATTENTION
-!IF (YRERAD%LAPPROXLWUPDATE) THEN
-IF (rad_config%do_lw_derivatives) THEN
-  PLWDERIVATIVE(KIDIA:KFDIA,:) = flux%lw_derivatives(KIDIA:KFDIA,:)
-END IF
-! Store the shortwave downwelling fluxes in each albedo band
-!AI ATTENTION
-!IF (YRERAD%LAPPROXSWUPDATE) THEN
-if (0.eq.1) then
-IF (rad_config%do_surface_sw_spectral_flux) THEN
-  PSWDIFFUSEBAND(KIDIA:KFDIA,:) = 0.0_JPRB
-  PSWDIRECTBAND (KIDIA:KFDIA,:) = 0.0_JPRB
-  DO JBAND = 1,rad_config%n_bands_sw
-    JB_ALBEDO = rad_config%i_albedo_from_band_sw(JBAND)
-    DO JLON = KIDIA,KFDIA
-      PSWDIFFUSEBAND(JLON,JB_ALBEDO) = PSWDIFFUSEBAND(JLON,JB_ALBEDO) &
-           &  + flux%sw_dn_surf_band(JBAND,JLON) &
-           &  - flux%sw_dn_direct_surf_band(JBAND,JLON)
-      PSWDIRECTBAND(JLON,JB_ALBEDO)  = PSWDIRECTBAND(JLON,JB_ALBEDO) &
-           &  + flux%sw_dn_direct_surf_band(JBAND,JLON)
-    ENDDO
-  ENDDO
-ENDIF
-endif
-
-print*,'********** DEALLOCATIONS ************************'
-CALL single_level%deallocate
-CALL thermodynamics%deallocate
-CALL gas%deallocate
-CALL cloud%deallocate
-CALL aerosol%deallocate
-CALL flux%deallocate
-
-IF (LHOOK) CALL DR_HOOK('RADIATION_SCHEME',1,ZHOOK_HANDLE)
-
-END SUBROUTINE RADIATION_SCHEME
-
-end module interface_lmdz_ecrad
Index: DZ6/trunk/libf/phylmd/ecrad/radiation/radiation_setup.F90
===================================================================
--- /LMDZ6/trunk/libf/phylmd/ecrad/radiation/radiation_setup.F90	(revision 4852)
+++ 	(revision )
@@ -1,150 +1,0 @@
-MODULE RADIATION_SETUP
-
-! RADIATION_SETUP - Setting up modular radiation scheme
-!
-! AUTHOR
-! ------
-!   Robin Hogan, ECMWF
-!   Original: 2015-09-16
-!
-! MODIFICATIONS
-! -------------
-!   Abderrahmane Idelkadi LMD, juillet 2023
-!
-!-----------------------------------------------------------------------
-
-  USE PARKIND1,         ONLY : JPRB
-  USE radiation_config, ONLY : config_type, &
-       &                       ISolverMcICA, ISolverSpartacus, &
-       &                       ILiquidModelSlingo, ILiquidModelSOCRATES, &
-       &                       IIceModelFu, IIceModelBaran, IGasModelECCKD, &
-       &                       IGasModelIFSRRTMG, IOverlapExponentialRandom
-
-  USE radiation_interface,      ONLY : setup_radiation
-  USE setup_config_from_lmdz,   ONLY : driver_config_type
-
-  IMPLICIT NONE
-
-
-  ! Ultraviolet weightings
-  INTEGER         :: NWEIGHT_UV
-  INTEGER         :: IBAND_UV(100)
-  REAL(KIND=JPRB) :: WEIGHT_UV(100)
-  ! Photosynthetically active radiation weightings
-  INTEGER         :: NWEIGHT_PAR
-  INTEGER         :: IBAND_PAR(100)
-  REAL(KIND=JPRB) :: WEIGHT_PAR(100)
-
-  ! Background aerosol is specified in an ugly way: using the old
-  ! Tegen fields that are in terms of optical depth, and converted to
-  ! mass mixing ratio via the relevant mass-extinction coefficient
-  INTEGER, PARAMETER :: ITYPE_TROP_BG_AER = 8 ! hydrophobic organic
-  INTEGER, PARAMETER :: ITYPE_STRAT_BG_AER=12 ! non-absorbing sulphate
-  REAL(KIND=JPRB)    :: TROP_BG_AER_MASS_EXT
-  REAL(KIND=JPRB)    :: STRAT_BG_AER_MASS_EXT
-
-CONTAINS
-
-  ! This routine copies information between the LMDZ radiation
-  ! configuration (stored in global variables) and the radiation
-  ! configuration of the modular radiation scheme (stored in
-  ! rad_config).  The optional input logical LOUTPUT controls whether
-  ! to print lots of information during the setup stage (default is
-  ! no).
-! AI At the end of the routine, the parameters are read in namelist
-!    
-  SUBROUTINE SETUP_RADIATION_SCHEME(LOUTPUT,file_name,rad_config,driver_config)
-
-!    USE radiation_config, ONLY : config_type, &
-!        &                       ISolverMcICA, ISolverSpartacus, &
-!        &                       ILiquidModelSlingo, ILiquidModelSOCRATES, &
-!        &                       IIceModelFu, IIceModelBaran, &
-!        &                       IOverlapExponentialRandom
-    USE mod_phys_lmdz_para
-      
-    USE YOMHOOK,  ONLY : LHOOK, DR_HOOK
-    USE YOMLUN,   ONLY : NULOUT, NULERR
-    USE YOESRTWN, ONLY : NMPSRTM
-
- !   USE radiation_interface,      ONLY : setup_radiation
- !   USE setup_config_from_lmdz,   ONLY : driver_config_type
-
-    ! Whether or not to provide information on the radiation scheme
-    ! configuration
-    LOGICAL, INTENT(IN), OPTIONAL :: LOUTPUT
-
-    REAL(KIND=JPRB) :: ZHOOK_HANDLE
-
-    character(len=512) :: file_name
-
-    logical :: lprint_setp=.TRUE.
-
-    ! Store configuration information for the radiation scheme in a
-    ! global variable
-    type(config_type) :: rad_config
-    type(driver_config_type) :: driver_config
-
-    IF (LHOOK) CALL DR_HOOK('RADIATION_SETUP:SETUP_RADIATION_SCHEME',0,ZHOOK_HANDLE)
-
-    ! *** GENERAL SETUP ***
-
-    ! Configure verbosity of setup of radiation scheme
- 
-    print*,'********** Dans radiation_setup *****************'
-
-! AI ATTENTION (parameters read in namelist file)
-!    file_name="namelist_ecrad"
-    call rad_config%read(file_name=file_name)
-    call driver_config%read(file_name)
-
-    ! Use configuration data to set-up radiation scheme, including
-    ! reading scattering datafiles
-    CALL setup_radiation(rad_config)
-
-    ! Populate the mapping between the 14 RRTM shortwave bands and the
-    ! 6 albedo inputs. The mapping according to the stated wavelength
-    ! ranges of the 6-band model does not match the hard-wired mapping
-    ! in NMPSRTM, but only the hard-wired values produce sensible
-    ! results...
-    ! Note that NMPSRTM(:)=(/  6, 6, 5, 5, 5, 5, 5, 4, 4, 3, 2, 2, 1, 6 /)
-! AI (6 albedo SW bands) 
-    call rad_config%define_sw_albedo_intervals(6, &
-       &  [0.25e-6_jprb, 0.44e-6_jprb, 0.69e-6_jprb, &
-       &   1.19e-6_jprb, 2.38e-6_jprb], [1,2,3,4,5,6])
-    ! Likewise between the 16 RRTM longwave bands and the 2 emissivity
-    ! inputs (info taken from rrtm_ecrt_140gp_mcica.F90) representing
-    ! outside and inside the window region of the spectrum
-!     rad_config%i_emiss_from_band_lw = (/ 1,1,1,1,1,2,2,2,1,1,1,1,1,1,1,1 /)
-! AI ATTENTION ?????
-!!    call rad_config%define_lw_emiss_intervals(3, &
-!!         &  (/ 8.0e-6_jprb,13.0e-6_jprb /),  (/ 1,2,1 /))
-
-!    ! Get spectral weightings for UV and PAR
-    call rad_config%get_sw_weights(0.2e-6_jprb, 0.4415e-6_jprb, &
-         &  NWEIGHT_UV, IBAND_UV, WEIGHT_UV, 'ultraviolet')
-    call rad_config%get_sw_weights(0.4e-6_jprb, 0.7e-6_jprb, &
-         &  NWEIGHT_PAR, IBAND_PAR, WEIGHT_PAR, &
-         &  'photosynthetically active radiation, PAR')
-
-     rad_config%i_aerosol_type_map(1:13) = (/ &
-           &  -1, &  ! Sea salt, size bin 1 (OPAC)
-           &  -2, &  ! Sea salt, size bin 2 (OPAC)
-           &  -3, &  ! Sea salt, size bin 3 (OPAC)
-           &  -4, &  ! Hydrophilic organic matter (OPAC)
-           &  -5, &  ! Ammonium sulphate (OPAC)
-           &  -6, &
-           &  -7, &
-           &   1, &
-           &   2, &
-           &   3, &
-           &  -8, &
-           &  -9, &
-           &   4 /)  ! Stratospheric sulphate (hand edited from OPAC)
-   rad_config%aerosol_optics_override_file_name = 'aerosol_optics_lmdz.nc'
-
-
-    IF (LHOOK) CALL DR_HOOK('RADIATION_SETUP:SETUP_RADIATION_SCHEME',1,ZHOOK_HANDLE)
-
-  END SUBROUTINE SETUP_RADIATION_SCHEME
-
-END MODULE RADIATION_SETUP
Index: /LMDZ6/trunk/libf/phylmd/ecrad/radiation/radiation_spartacus_sw.F90
===================================================================
--- /LMDZ6/trunk/libf/phylmd/ecrad/radiation/radiation_spartacus_sw.F90	(revision 4852)
+++ /LMDZ6/trunk/libf/phylmd/ecrad/radiation/radiation_spartacus_sw.F90	(revision 4853)
@@ -87,5 +87,4 @@
     use radiation_constants, only      : Pi, GasConstantDryAir, &
          &                               AccelDueToGravity
-    USE mod_phys_lmdz_para
 
     implicit none
@@ -327,10 +326,4 @@
       write(nulout,'(a)',advance='no') '  Processing columns'
     end if
-
-      print*,'Dans radiation_spartacus, mpi_rank, omp_rank, &
-              size, chape inv_cloud = ',&
-              mpi_rank, omp_rank, &
-              shape(cloud%inv_cloud_effective_size), &
-              size(cloud%inv_cloud_effective_size)
 
     ! Main loop over columns
@@ -504,8 +497,4 @@
                &  .not. (nreg == 2 .and. cloud%fraction(jcol,jlev) &
                &  > 1.0-config%cloud_fraction_threshold)) then
-!           print*,' Dans radiation_spartacus mpi_rank, omp_rank, jcol, jlev, &
-!            &     cloud%inv_cloud_effective_size =', mpi_rank, &
-!            &     omp_rank, jcol, jlev, &
-!            &     cloud%inv_cloud_effective_size(jcol,jlev)
             if (cloud%inv_cloud_effective_size(jcol,jlev) > 0.0_jprb) then
               ! 3D effects are only simulated if
Index: /LMDZ6/trunk/libf/phylmd/ecrad/radiation/radiation_spectral_definition.F90
===================================================================
--- /LMDZ6/trunk/libf/phylmd/ecrad/radiation/radiation_spectral_definition.F90	(revision 4852)
+++ /LMDZ6/trunk/libf/phylmd/ecrad/radiation/radiation_spectral_definition.F90	(revision 4853)
@@ -15,4 +15,6 @@
 !
 
+#include "ecrad_config.h"
+
 module radiation_spectral_definition
 
@@ -23,5 +25,5 @@
   public
 
-  real(jprb), parameter :: SolarReferenceTemperature = 5777.0_jprb ! K
+  real(jprb), parameter :: SolarReferenceTemperature       = 5777.0_jprb ! K
   real(jprb), parameter :: TerrestrialReferenceTemperature = 273.15_jprb ! K
 
@@ -85,5 +87,9 @@
   subroutine read_spectral_definition(this, file)
 
-    use easy_netcdf, only : netcdf_file
+#ifdef EASY_NETCDF_READ_MPI
+    use easy_netcdf_read_mpi, only : netcdf_file
+#else
+    use easy_netcdf,          only : netcdf_file
+#endif
     use yomhook,     only : lhook, dr_hook, jphook
 
@@ -132,12 +138,13 @@
 
   !---------------------------------------------------------------------
-  ! Store a simple band description by copying over the lower and
-  ! upper wavenumbers of each band
-  subroutine allocate_bands_only(this, wavenumber1, wavenumber2)
+  ! Store a simple band description by copying over the reference
+  ! temperature and the lower and upper wavenumbers of each band
+  subroutine allocate_bands_only(this, reference_temperature, wavenumber1, wavenumber2)
 
     use yomhook,     only : lhook, dr_hook, jphook
 
     class(spectral_definition_type), intent(inout) :: this
-    real(jprb),        dimension(:), intent(in)    :: wavenumber1, wavenumber2
+    real(jprb),                      intent(in)    :: reference_temperature    ! K
+    real(jprb),        dimension(:), intent(in)    :: wavenumber1, wavenumber2 ! cm-1
 
     real(jphook) :: hook_handle
@@ -152,5 +159,6 @@
     this%wavenumber1_band = wavenumber1
     this%wavenumber2_band = wavenumber2
-
+    this%reference_temperature = reference_temperature
+    
     if (lhook) call dr_hook('radiation_spectral_definition:allocate_bands_only',1,hook_handle)
 
@@ -167,4 +175,5 @@
     this%ng    = 0
     this%nband = 0
+    this%reference_temperature = -1.0_jprb
 
     if (allocated(this%wavenumber1))      deallocate(this%wavenumber1)
Index: /LMDZ6/trunk/libf/phylmd/ecrad/radiation/radiation_tripleclouds_lw.F90
===================================================================
--- /LMDZ6/trunk/libf/phylmd/ecrad/radiation/radiation_tripleclouds_lw.F90	(revision 4852)
+++ /LMDZ6/trunk/libf/phylmd/ecrad/radiation/radiation_tripleclouds_lw.F90	(revision 4853)
@@ -170,4 +170,7 @@
     logical :: is_clear_sky_layer(0:nlev+1)
 
+    ! Temporaries to speed up summations
+    real(jprb) :: sum_dn, sum_up
+    
     ! Index of the highest cloudy layer
     integer :: i_cloud_top
@@ -261,9 +264,21 @@
       if (config%do_clear) then
         ! Sum over g-points to compute broadband fluxes
-        flux%lw_up_clear(jcol,:) = sum(flux_up_clear,1)
-        flux%lw_dn_clear(jcol,:) = sum(flux_dn_clear,1)
+        do jlev = 1,nlev+1
+          sum_up = 0.0_jprb
+          sum_dn = 0.0_jprb
+          !$omp simd reduction(+:sum_up, sum_dn)
+          do jg = 1,ng
+            sum_up = sum_up + flux_up_clear(jg,jlev)
+            sum_dn = sum_dn + flux_dn_clear(jg,jlev)
+          end do
+          flux%lw_up_clear(jcol,jlev) = sum_up
+          flux%lw_dn_clear(jcol,jlev) = sum_dn
+        end do
+
         ! Store surface spectral downwelling fluxes / TOA upwelling
-        flux%lw_dn_surf_clear_g(:,jcol) = flux_dn_clear(:,nlev+1)
-        flux%lw_up_toa_clear_g (:,jcol) = flux_up_clear(:,1)
+        do jg = 1,ng
+          flux%lw_dn_surf_clear_g(jg,jcol) = flux_dn_clear(jg,nlev+1)
+          flux%lw_up_toa_clear_g (jg,jcol) = flux_up_clear(jg,1)
+        end do
         ! Save the spectral fluxes if required
         if (config%do_save_spectral_flux) then
@@ -453,5 +468,10 @@
           end if
         else
-          flux%lw_dn(jcol,:) = sum(flux_dn_clear(:,jlev))
+          sum_dn = 0.0_jprb
+          !$omp simd reduction(+:sum_dn)
+          do jg = 1,ng
+            sum_dn = sum_dn + flux_dn_clear(jg,jlev)
+          end do
+          flux%lw_dn(jcol,jlev) = sum_dn
           if (config%do_save_spectral_flux) then
             call indexed_sum(flux_dn_clear(:,jlev), &
@@ -470,5 +490,12 @@
            &  + total_albedo(:,1,i_cloud_top)*flux_dn_clear(:,i_cloud_top)
       flux_up(:,2:) = 0.0_jprb
-      flux%lw_up(jcol,i_cloud_top) = sum(flux_up(:,1))
+
+      sum_up = 0.0_jprb
+      !$omp simd reduction(+:sum_up)
+      do jg = 1,ng
+        sum_up = sum_up + flux_up(jg,1)
+      end do
+      flux%lw_up(jcol,i_cloud_top) = sum_up
+
       if (config%do_save_spectral_flux) then
         call indexed_sum(flux_up(:,1), &
@@ -478,5 +505,10 @@
       do jlev = i_cloud_top-1,1,-1
         flux_up(:,1) = trans_clear(:,jlev)*flux_up(:,1) + source_up_clear(:,jlev)
-        flux%lw_up(jcol,jlev) = sum(flux_up(:,1))
+        sum_up = 0.0_jprb
+        !$omp simd reduction(+:sum_up)
+        do jg = 1,ng
+          sum_up = sum_up + flux_up(jg,1)
+        end do
+        flux%lw_up(jcol,jlev) = sum_up
         if (config%do_save_spectral_flux) then
           call indexed_sum(flux_up(:,1), &
@@ -528,6 +560,15 @@
 
         ! Store the broadband fluxes
-        flux%lw_up(jcol,jlev+1) = sum(sum(flux_up,1))
-        flux%lw_dn(jcol,jlev+1) = sum(sum(flux_dn,1))
+        sum_up = 0.0_jprb
+        sum_dn = 0.0_jprb
+        do jreg = 1,nregions
+          !$omp simd reduction(+:sum_up, sum_dn)
+          do jg = 1,ng
+            sum_up = sum_up + flux_up(jg,jreg)
+            sum_dn = sum_dn + flux_dn(jg,jreg)
+          end do
+        end do
+        flux%lw_up(jcol,jlev+1) = sum_up
+        flux%lw_dn(jcol,jlev+1) = sum_dn
 
         ! Save the spectral fluxes if required
Index: /LMDZ6/trunk/libf/phylmd/ecrad/radiation/radiation_tripleclouds_sw.F90
===================================================================
--- /LMDZ6/trunk/libf/phylmd/ecrad/radiation/radiation_tripleclouds_sw.F90	(revision 4852)
+++ /LMDZ6/trunk/libf/phylmd/ecrad/radiation/radiation_tripleclouds_sw.F90	(revision 4853)
@@ -74,12 +74,11 @@
     ! Gas and aerosol optical depth, single-scattering albedo and
     ! asymmetry factor at each shortwave g-point
-!    real(jprb), intent(in), dimension(istartcol:iendcol,nlev,config%n_g_sw) :: &
-    real(jprb), intent(in), dimension(config%n_g_sw,nlev,istartcol:iendcol) :: &
-         &  od, ssa, g
+    real(jprb), intent(in), dimension(config%n_g_sw,nlev,istartcol:iendcol) &
+         &  :: od, ssa, g
 
     ! Cloud and precipitation optical depth, single-scattering albedo and
     ! asymmetry factor in each shortwave band
-    real(jprb), intent(in), dimension(config%n_bands_sw,nlev,istartcol:iendcol) :: &
-         &  od_cloud, ssa_cloud, g_cloud
+    real(jprb), intent(in), dimension(config%n_bands_sw,nlev,istartcol:iendcol) &
+         &  :: od_cloud, ssa_cloud, g_cloud
 
     ! Optical depth, single scattering albedo and asymmetry factor in
@@ -92,6 +91,6 @@
     ! flux into a plane perpendicular to the incoming radiation at
     ! top-of-atmosphere in each of the shortwave g points
-    real(jprb), intent(in), dimension(config%n_g_sw,istartcol:iendcol) :: &
-         &  albedo_direct, albedo_diffuse, incoming_sw
+    real(jprb), intent(in), dimension(config%n_g_sw,istartcol:iendcol) &
+         &  :: albedo_direct, albedo_diffuse, incoming_sw
 
     ! Output
@@ -166,4 +165,8 @@
     real(jprb) :: scat_od, scat_od_cloud
 
+    ! Temporaries to speed up summations
+    real(jprb) :: sum_dn_diff, sum_dn_dir, sum_up
+
+    ! Local cosine of solar zenith angle
     real(jprb) :: mu0
 
@@ -444,13 +447,33 @@
       end if
       
-      ! Store the TOA broadband fluxes
-      flux%sw_up(jcol,1) = sum(sum(flux_up,1))
-      flux%sw_dn(jcol,1) = mu0 * sum(sum(direct_dn,1))
+      ! Store the TOA broadband fluxes, noting that there is no
+      ! diffuse downwelling at TOA. The intrinsic "sum" command has
+      ! been found to be very slow; better performance is found on
+      ! x86-64 architecture with explicit loops and the "omp simd
+      ! reduction" directive.
+      sum_up     = 0.0_jprb
+      sum_dn_dir = 0.0_jprb
+      do jreg = 1,nregions
+        !$omp simd reduction(+:sum_up, sum_dn_dir)
+        do jg = 1,ng
+          sum_up     = sum_up     + flux_up(jg,jreg)
+          sum_dn_dir = sum_dn_dir + direct_dn(jg,jreg)
+        end do
+      end do
+      flux%sw_up(jcol,1) = sum_up
+      flux%sw_dn(jcol,1) = mu0 * sum_dn_dir
       if (allocated(flux%sw_dn_direct)) then
         flux%sw_dn_direct(jcol,1) = flux%sw_dn(jcol,1)
       end if
       if (config%do_clear) then
-        flux%sw_up_clear(jcol,1) = sum(flux_up_clear)
-        flux%sw_dn_clear(jcol,1) = mu0 * sum(direct_dn_clear)
+        sum_up     = 0.0_jprb
+        sum_dn_dir = 0.0_jprb
+        !$omp simd reduction(+:sum_up, sum_dn_dir)
+        do jg = 1,ng
+          sum_up     = sum_up     + flux_up_clear(jg)
+          sum_dn_dir = sum_dn_dir + direct_dn_clear(jg)
+        end do
+        flux%sw_up_clear(jcol,1) = sum_up
+        flux%sw_dn_clear(jcol,1) = mu0 * sum_dn_dir
         if (allocated(flux%sw_dn_direct_clear)) then
           flux%sw_dn_direct_clear(jcol,1) = flux%sw_dn_clear(jcol,1)
@@ -467,6 +490,5 @@
              &           config%i_spec_from_reordered_g_sw, &
              &           flux%sw_dn_band(:,jcol,1))
-        flux%sw_dn_band(:,jcol,1) = &
-             &  mu0 * flux%sw_dn_band(:,jcol,1)
+        flux%sw_dn_band(:,jcol,1) = mu0 * flux%sw_dn_band(:,jcol,1)
         if (allocated(flux%sw_dn_direct_band)) then
           flux%sw_dn_direct_band(:,jcol,1) = flux%sw_dn_band(:,jcol,1)
@@ -549,22 +571,38 @@
                ! nothing to do
 
-        ! Store the broadband fluxes
-        flux%sw_up(jcol,jlev+1) = sum(sum(flux_up,1))
+        ! Store the broadband fluxes. The intrinsic "sum" command has
+        ! been found to be very slow; better performance is found on
+        ! x86-64 architecture with explicit loops and the "omp simd
+        ! reduction" directive.
+        sum_up      = 0.0_jprb
+        sum_dn_dir  = 0.0_jprb
+        sum_dn_diff = 0.0_jprb
+        do jreg = 1,nregions
+          !$omp simd reduction(+:sum_up, sum_dn_diff, sum_dn_dir)
+          do jg = 1,ng
+            sum_up      = sum_up      + flux_up(jg,jreg)
+            sum_dn_diff = sum_dn_diff + flux_dn(jg,jreg)
+            sum_dn_dir  = sum_dn_dir  + direct_dn(jg,jreg)
+          end do
+        end do
+        flux%sw_up(jcol,jlev+1) = sum_up
+        flux%sw_dn(jcol,jlev+1) = mu0 * sum_dn_dir + sum_dn_diff
         if (allocated(flux%sw_dn_direct)) then
-          flux%sw_dn_direct(jcol,jlev+1) = mu0 * sum(sum(direct_dn,1))
-          flux%sw_dn(jcol,jlev+1) &
-               &  = flux%sw_dn_direct(jcol,jlev+1) + sum(sum(flux_dn,1))
-        else
-          flux%sw_dn(jcol,jlev+1) = mu0 * sum(sum(direct_dn,1)) + sum(sum(flux_dn,1))   
+          flux%sw_dn_direct(jcol,jlev+1) = mu0 * sum_dn_dir
         end if
         if (config%do_clear) then
-          flux%sw_up_clear(jcol,jlev+1) = sum(flux_up_clear)
+          sum_up      = 0.0_jprb
+          sum_dn_dir  = 0.0_jprb
+          sum_dn_diff = 0.0_jprb
+          !$omp simd reduction(+:sum_up, sum_dn_diff, sum_dn_dir)
+          do jg = 1,ng
+            sum_up      = sum_up      + flux_up_clear(jg)
+            sum_dn_diff = sum_dn_diff + flux_dn_clear(jg)
+            sum_dn_dir  = sum_dn_dir  + direct_dn_clear(jg)
+          end do
+          flux%sw_up_clear(jcol,jlev+1) = sum_up
+          flux%sw_dn_clear(jcol,jlev+1) = mu0 * sum_dn_dir + sum_dn_diff
           if (allocated(flux%sw_dn_direct_clear)) then
-            flux%sw_dn_direct_clear(jcol,jlev+1) = mu0 * sum(direct_dn_clear)
-            flux%sw_dn_clear(jcol,jlev+1) &
-                 &  = flux%sw_dn_direct_clear(jcol,jlev+1) + sum(flux_dn_clear)
-          else
-            flux%sw_dn_clear(jcol,jlev+1) = mu0 * sum(direct_dn_clear) &
-                 &  + sum(flux_dn_clear)
+            flux%sw_dn_direct_clear(jcol,jlev+1) = mu0 * sum_dn_dir
           end if
         end if
@@ -605,5 +643,4 @@
           end if
         end if
-
       end do ! Final loop over levels
       
Index: /LMDZ6/trunk/libf/phylmd/ecrad/radiation/radiation_two_stream.F90
===================================================================
--- /LMDZ6/trunk/libf/phylmd/ecrad/radiation/radiation_two_stream.F90	(revision 4852)
+++ /LMDZ6/trunk/libf/phylmd/ecrad/radiation/radiation_two_stream.F90	(revision 4853)
@@ -22,4 +22,6 @@
 !   2023-09-28  R Hogan  Increased security for single-precision SW "k"
 
+#include "ecrad_config.h"
+
 module radiation_two_stream
 
@@ -43,21 +45,4 @@
 
 contains
-
-#ifdef FAST_EXPONENTIAL
-  !---------------------------------------------------------------------
-  ! Fast exponential for negative arguments: a Pade approximant that
-  ! doesn't go negative for negative arguments, applied to arg/8, and
-  ! the result is then squared three times
-  elemental function exp_fast(arg) result(ex)
-    real(jprd) :: arg, ex
-    ex = 1.0_jprd / (1.0_jprd + arg*(-0.125_jprd &
-         + arg*(0.0078125_jprd - 0.000325520833333333_jprd * arg)))
-    ex = ex*ex
-    ex = ex*ex
-    ex = ex*ex
-  end function exp_fast
-#else
-#define exp_fast exp
-#endif
 
   !---------------------------------------------------------------------
@@ -214,5 +199,5 @@
         k_exponent = sqrt(max((gamma1(jg) - gamma2(jg)) * (gamma1(jg) + gamma2(jg)), &
              1.0e-12_jprd)) ! Eq 18 of Meador & Weaver (1980)
-        exponential = exp_fast(-k_exponent*od(jg))
+        exponential = exp(-k_exponent*od(jg))
         exponential2 = exponential*exponential
         reftrans_factor = 1.0 / (k_exponent + gamma1(jg) + (k_exponent - gamma1(jg))*exponential2)
@@ -306,6 +291,4 @@
 #endif
 
-! Added for DWD (2020)
-!NEC$ shortloop
     do jg = 1, ng
       factor = (LwDiffusivityWP * 0.5_jprb) * ssa(jg)
@@ -315,5 +298,5 @@
            1.0e-12_jprb)) ! Eq 18 of Meador & Weaver (1980)
       if (od(jg) > 1.0e-3_jprb) then
-        exponential = exp_fast(-k_exponent*od(jg))
+        exponential = exp(-k_exponent*od(jg))
         exponential2 = exponential*exponential
         reftrans_factor = 1.0_jprb / (k_exponent + gamma1 + (k_exponent - gamma1)*exponential2)
@@ -392,8 +375,8 @@
 #endif
 
-    transmittance = exp_fast(-LwDiffusivityWP*od)
-
-! Added for DWD (2020)
-!NEC$ shortloop
+#ifndef DWD_TWO_STREAM_OPTIMIZATIONS
+    transmittance = exp(-LwDiffusivityWP*od)
+#endif
+
     do jg = 1, ng
       ! Compute upward and downward emission assuming the Planck
@@ -401,4 +384,7 @@
       ! (e.g. Wiscombe , JQSRT 1976).
       coeff = LwDiffusivityWP*od(jg)
+#ifdef DWD_TWO_STREAM_OPTIMIZATIONS
+      transmittance(jg) = exp(-coeff)
+#endif
       if (od(jg) > 1.0e-3_jprb) then
         ! Simplified from calc_reflectance_transmittance_lw above
@@ -516,7 +502,7 @@
         k_gamma4 = k_exponent*gamma4
         ! Check for mu0 <= 0!
-        exponential0 = exp_fast(-od_over_mu0)
+        exponential0 = exp(-od_over_mu0)
         trans_dir_dir(jg) = exponential0
-        exponential = exp_fast(-k_exponent*od(jg))
+        exponential = exp(-k_exponent*od(jg))
         
         exponential2 = exponential*exponential
@@ -609,7 +595,13 @@
     ! The three transfer coefficients from the two-stream
     ! differentiatial equations 
+#ifndef DWD_TWO_STREAM_OPTIMIZATIONS
     real(jprb), dimension(ng) :: gamma1, gamma2, gamma3, gamma4 
     real(jprb), dimension(ng) :: alpha1, alpha2, k_exponent
     real(jprb), dimension(ng) :: exponential ! = exp(-k_exponent*od)
+#else
+    real(jprb) :: gamma1, gamma2, gamma3, gamma4 
+    real(jprb) :: alpha1, alpha2, k_exponent
+    real(jprb) :: exponential ! = exp(-k_exponent*od)
+#endif
     
     real(jprb) :: reftrans_factor, factor
@@ -625,12 +617,11 @@
 #endif
 
+#ifndef DWD_TWO_STREAM_OPTIMIZATIONS
     ! GCC 9.3 strange error: intermediate values of ~ -8000 cause a
     ! FPE when vectorizing exp(), but not in non-vectorized loop, nor
     ! with larger negative values!
     trans_dir_dir = max(-max(od * (1.0_jprb/mu0), 0.0_jprb),-1000.0_jprb)
-    trans_dir_dir = exp_fast(trans_dir_dir)
-
-! Added for DWD (2020)
-!NEC$ shortloop
+    trans_dir_dir = exp(trans_dir_dir)
+
     do jg = 1, ng
 
@@ -659,7 +650,6 @@
     end do
 
-    exponential = exp_fast(-k_exponent*od)
-
-!NEC$ shortloop
+    exponential = exp(-k_exponent*od)
+
     do jg = 1, ng
       k_mu0 = k_exponent(jg)*mu0
@@ -705,5 +695,74 @@
       trans_dir_diff(jg) = max(0.0_jprb, min(trans_dir_diff(jg), mu0*(1.0_jprb-trans_dir_dir(jg))-ref_dir(jg)))
     end do
-    
+
+#else
+    ! GPU-capable and vector-optimized version for ICON
+    do jg = 1, ng
+
+      trans_dir_dir(jg) = max(-max(od(jg) * (1.0_jprb/mu0),0.0_jprb),-1000.0_jprb)
+      trans_dir_dir(jg) = exp(trans_dir_dir(jg))
+
+      ! Zdunkowski "PIFM" (Zdunkowski et al., 1980; Contributions to
+      ! Atmospheric Physics 53, 147-66)
+      factor = 0.75_jprb*asymmetry(jg)
+
+      gamma1 = 2.0_jprb  - ssa(jg) * (1.25_jprb + factor)
+      gamma2 = ssa(jg) * (0.75_jprb - factor)
+      gamma3 = 0.5_jprb  - mu0*factor
+      gamma4 = 1.0_jprb - gamma3
+
+      alpha1 = gamma1*gamma4 + gamma2*gamma3 ! Eq. 16
+      alpha2 = gamma1*gamma3 + gamma2*gamma4 ! Eq. 17
+#ifdef PARKIND1_SINGLE
+      k_exponent = sqrt(max((gamma1 - gamma2) * (gamma1 + gamma2), 1.0e-6_jprb))  ! Eq 18
+#else
+      k_exponent = sqrt(max((gamma1 - gamma2) * (gamma1 + gamma2), 1.0e-12_jprb)) ! Eq 18
+#endif
+
+      exponential = exp(-k_exponent*od(jg))
+
+      k_mu0 = k_exponent*mu0
+      one_minus_kmu0_sqr = 1.0_jprb - k_mu0*k_mu0
+      k_gamma3 = k_exponent*gamma3
+      k_gamma4 = k_exponent*gamma4
+      exponential2 = exponential*exponential
+      k_2_exponential = 2.0_jprb * k_exponent * exponential
+      reftrans_factor = 1.0_jprb / (k_exponent + gamma1 + (k_exponent - gamma1)*exponential2)
+        
+      ! Meador & Weaver (1980) Eq. 25
+      ref_diff(jg) = gamma2 * (1.0_jprb - exponential2) * reftrans_factor
+        
+      ! Meador & Weaver (1980) Eq. 26
+      trans_diff(jg) = k_2_exponential * reftrans_factor
+        
+      ! Here we need mu0 even though it wasn't in Meador and Weaver
+      ! because we are assuming the incoming direct flux is defined to
+      ! be the flux into a plane perpendicular to the direction of the
+      ! sun, not into a horizontal plane
+      reftrans_factor = mu0 * ssa(jg) * reftrans_factor &
+            &  / merge(one_minus_kmu0_sqr, epsilon(1.0_jprb), abs(one_minus_kmu0_sqr) > epsilon(1.0_jprb))
+      
+      ! Meador & Weaver (1980) Eq. 14, multiplying top & bottom by
+      ! exp(-k_exponent*od) in case of very high optical depths
+      ref_dir(jg) = reftrans_factor &
+           &  * ( (1.0_jprb - k_mu0) * (alpha2 + k_gamma3) &
+           &     -(1.0_jprb + k_mu0) * (alpha2 - k_gamma3)*exponential2 &
+           &     -k_2_exponential*(gamma3 - alpha2*mu0)*trans_dir_dir(jg) )
+        
+      ! Meador & Weaver (1980) Eq. 15, multiplying top & bottom by
+      ! exp(-k_exponent*od), minus the 1*exp(-od/mu0) term
+      ! representing direct unscattered transmittance.
+      trans_dir_diff(jg) = reftrans_factor * ( k_2_exponential*(gamma4 + alpha1*mu0) &
+           & - trans_dir_dir(jg) &
+           & * ( (1.0_jprb + k_mu0) * (alpha1 + k_gamma4) &
+           &    -(1.0_jprb - k_mu0) * (alpha1 - k_gamma4) * exponential2) )
+
+      ! Final check that ref_dir + trans_dir_diff <= 1
+      ref_dir(jg)        = max(0.0_jprb, min(ref_dir(jg), mu0*(1.0_jprb-trans_dir_dir(jg))))
+      trans_dir_diff(jg) = max(0.0_jprb, min(trans_dir_diff(jg), mu0*(1.0_jprb-trans_dir_dir(jg))-ref_dir(jg)))
+
+    end do
+#endif
+
 #ifdef DO_DR_HOOK_TWO_STREAM
     if (lhook) call dr_hook('radiation_two_stream:calc_ref_trans_sw',1,hook_handle)
@@ -757,5 +816,5 @@
       k_exponent = sqrt(max((gamma1(jg) - gamma2(jg)) * (gamma1(jg) + gamma2(jg)), &
            &       1.0e-12_jprd)) ! Eq 18
-      exponential = exp_fast(-k_exponent*od(jg))
+      exponential = exp(-k_exponent*od(jg))
       exponential2 = exponential*exponential
       k_2_exponential = 2.0_jprd * k_exponent * exponential
@@ -766,8 +825,8 @@
       ! Until 1.1.8, used LwDiffusivity instead of 2.0, although the
       ! effect is very small
-      !      frac_scat_diffuse(jg) = 1.0_jprb - min(1.0_jprb,exp_fast(-LwDiffusivity*od(jg)) &
+      !      frac_scat_diffuse(jg) = 1.0_jprb - min(1.0_jprb,exp(-LwDiffusivity*od(jg)) &
       !           &  / max(1.0e-8_jprb, k_2_exponential * reftrans_factor))
       frac_scat_diffuse(jg) = 1.0_jprb &
-           &  - min(1.0_jprb,exp_fast(-2.0_jprb*od(jg)) &
+           &  - min(1.0_jprb,exp(-2.0_jprb*od(jg)) &
            &  / max(1.0e-8_jprb, k_2_exponential * reftrans_factor))
     end do
Index: DZ6/trunk/libf/phylmd/ecrad/radiation/readaerosol_optic_ecrad.F90
===================================================================
--- /LMDZ6/trunk/libf/phylmd/ecrad/radiation/readaerosol_optic_ecrad.F90	(revision 4852)
+++ 	(revision )
@@ -1,311 +1,0 @@
-! $Id: readaerosol_optic_ecrad.F90
-!
-SUBROUTINE readaerosol_optic_ecrad(debut, aerosol_couple, ok_alw, ok_volcan, &
-     flag_aerosol, flag_bc_internal_mixture, itap, rjourvrai, &
-     pdtphys, pplay, paprs, t_seri, rhcl, presnivs, &
-     tr_seri, mass_solu_aero, mass_solu_aero_pi, &
-     tau_aero, piz_aero, cg_aero, &
-     tausum_aero, drytausum_aero, tau3d_aero )
-
-  ! This routine will :
-  ! 1) recevie the aerosols(already read and interpolated) corresponding to flag_aerosol
-  ! 2) calculate the optical properties for the aerosols
-  !
-
-  USE dimphy
-  USE aero_mod
-  USE phys_local_var_mod, only: sconcso4,sconcno3,sconcoa,sconcbc,sconcss,sconcdust, &
-       concso4,concno3,concoa,concbc,concss,concdust,loadso4,loadoa,loadbc,loadss,loaddust, &
-       loadno3,load_tmp1,load_tmp2,load_tmp3,load_tmp4,load_tmp5,load_tmp6,load_tmp7, & 
-       load_tmp8,load_tmp9,load_tmp10,m_allaer
-
-  USE infotrac_phy, ONLY: tracers, nqtot, nbtr
-  USE YOMCST
-
-  IMPLICIT NONE
-
-  include "clesphys.h"
-
-  ! Input arguments
-  !****************************************************************************************
-  LOGICAL, INTENT(IN)                      :: debut
-  LOGICAL, INTENT(IN)                      :: aerosol_couple
-  LOGICAL, INTENT(IN)                      :: ok_alw
-  LOGICAL, INTENT(IN)                      :: ok_volcan
-  INTEGER, INTENT(IN)                      :: flag_aerosol
-  LOGICAL, INTENT(IN)                      :: flag_bc_internal_mixture
-  INTEGER, INTENT(IN)                      :: itap
-  REAL, INTENT(IN)                         :: rjourvrai
-  REAL, INTENT(IN)                         :: pdtphys
-  REAL, DIMENSION(klon,klev), INTENT(IN)   :: pplay
-  REAL, DIMENSION(klon,klev+1), INTENT(IN) :: paprs
-  REAL, DIMENSION(klon,klev), INTENT(IN)   :: t_seri
-  REAL, DIMENSION(klon,klev), INTENT(IN)   :: rhcl   ! humidite relative ciel clair
-  REAL, DIMENSION(klev), INTENT(IN)        :: presnivs
-  REAL, DIMENSION(klon,klev,nbtr), INTENT(IN) :: tr_seri ! concentration tracer
-
-  ! Output arguments
-  !****************************************************************************************
-  REAL, DIMENSION(klon,klev), INTENT(OUT)     :: mass_solu_aero    ! Total mass for all soluble aerosols
-  REAL, DIMENSION(klon,klev), INTENT(OUT)     :: mass_solu_aero_pi !     -"-     preindustrial values
-  REAL, DIMENSION(klon,klev,2,NSW), INTENT(OUT) :: tau_aero    ! Aerosol optical thickness
-  REAL, DIMENSION(klon,klev,2,NSW), INTENT(OUT) :: piz_aero    ! Single scattering albedo aerosol
-  REAL, DIMENSION(klon,klev,2,NSW), INTENT(OUT) :: cg_aero     ! asymmetry parameter aerosol
-  REAL, DIMENSION(klon,nwave,naero_tot), INTENT(OUT)       :: tausum_aero
-  REAL, DIMENSION(klon,naero_tot), INTENT(OUT)             :: drytausum_aero
-  REAL, DIMENSION(klon,klev,nwave,naero_tot), INTENT(OUT)  :: tau3d_aero
-
-  ! Local variables
-  !****************************************************************************************
-  REAL, DIMENSION(klon)        :: aerindex      ! POLDER aerosol index 
-  REAL, DIMENSION(klon,klev)   :: sulfacc       ! SO4 accumulation concentration [ug/m3]
-  REAL, DIMENSION(klon,klev)   :: sulfcoarse    ! SO4 coarse concentration [ug/m3]
-  REAL, DIMENSION(klon,klev)   :: bcsol         ! BC soluble concentration [ug/m3]
-  REAL, DIMENSION(klon,klev)   :: bcins         ! BC insoluble concentration [ug/m3]
-  REAL, DIMENSION(klon,klev)   :: pomsol        ! POM soluble concentration [ug/m3]
-  REAL, DIMENSION(klon,klev)   :: pomins        ! POM insoluble concentration [ug/m3]
-  REAL, DIMENSION(klon,klev)   :: cidust        ! DUST aerosol concentration  [ug/m3]
-  REAL, DIMENSION(klon,klev)   :: sscoarse      ! SS Coarse concentration [ug/m3]
-  REAL, DIMENSION(klon,klev)   :: sssupco       ! SS Super Coarse concentration [ug/m3]
-  REAL, DIMENSION(klon,klev)   :: ssacu         ! SS Acumulation concentration [ug/m3]
-  REAL, DIMENSION(klon,klev)   :: nitracc       ! nitrate accumulation concentration [ug/m3]
-  REAL, DIMENSION(klon,klev)   :: nitrcoarse    ! nitrate coarse concentration [ug/m3]
-  REAL, DIMENSION(klon,klev)   :: nitrinscoarse ! nitrate insoluble coarse concentration [ug/m3]
-  REAL, DIMENSION(klon,klev)   :: sulfacc_pi
-  REAL, DIMENSION(klon,klev)   :: sulfcoarse_pi
-  REAL, DIMENSION(klon,klev)   :: bcsol_pi
-  REAL, DIMENSION(klon,klev)   :: bcins_pi
-  REAL, DIMENSION(klon,klev)   :: pomsol_pi
-  REAL, DIMENSION(klon,klev)   :: pomins_pi
-  REAL, DIMENSION(klon,klev)   :: cidust_pi
-  REAL, DIMENSION(klon,klev)   :: sscoarse_pi
-  REAL, DIMENSION(klon,klev)   :: sssupco_pi
-  REAL, DIMENSION(klon,klev)   :: ssacu_pi
-  REAL, DIMENSION(klon,klev)   :: nitracc_pi
-  REAL, DIMENSION(klon,klev)   :: nitrcoarse_pi
-  REAL, DIMENSION(klon,klev)   :: nitrinscoarse_pi
-  REAL, DIMENSION(klon,klev)   :: pdel, zrho
-!  REAL, DIMENSION(klon,klev,naero_tot) :: m_allaer
-  REAL, DIMENSION(klon,klev,naero_tot) :: m_allaer_pi !RAF  
-
-  integer :: id_ASBCM, id_ASPOMM, id_ASSO4M, id_ASMSAM, id_CSSO4M, id_CSMSAM, id_SSSSM
-  integer :: id_CSSSM, id_ASSSM, id_CIDUSTM, id_AIBCM, id_AIPOMM, id_ASNO3M, id_CSNO3M, id_CINO3M
-  INTEGER :: k, i, iq, itr
-
-  !--air density
-  zrho(:,:)=pplay(:,:)/t_seri(:,:)/RD                     !--kg/m3
-
-  !****************************************************************************************
-  ! 1) Get aerosol mass
-  !    
-  !****************************************************************************************
-  !
-  !
-  IF (aerosol_couple) THEN   !--we get aerosols from tr_seri array from INCA
-     !
-     !--copy fields from INCA tr_seri 
-     !--convert to ug m-3 unit for consistency with offline fields
-     !
-     itr = 0
-     DO iq = 1,nqtot
-        IF(.NOT. tracers(iq)%isInPhysics) CYCLE
-        itr = itr+1
-        SELECT CASE(trim(tracers(iq)%name))
-           CASE ("ASBCM");  id_ASBCM  = itr
-           CASE ("ASPOMM"); id_ASPOMM = itr
-           CASE ("ASSO4M"); id_ASSO4M = itr
-           CASE ("ASMSAM"); id_ASMSAM = itr
-           CASE ("CSSO4M"); id_CSSO4M = itr
-           CASE ("CSMSAM"); id_CSMSAM = itr
-           CASE ("SSSSM");  id_SSSSM  = itr
-           CASE ("CSSSM");  id_CSSSM  = itr
-           CASE ("ASSSM");  id_ASSSM  = itr
-           CASE ("CIDUSTM");id_CIDUSTM= itr
-           CASE ("AIBCM");  id_AIBCM  = itr
-           CASE ("AIPOMM"); id_AIPOMM = itr
-           CASE ("ASNO3M"); id_ASNO3M = itr
-           CASE ("CSNO3M"); id_CSNO3M = itr
-           CASE ("CINO3M"); id_CINO3M = itr
-        END SELECT
-     END DO
-
-     bcsol(:,:)        =   tr_seri(:,:,id_ASBCM)                         *zrho(:,:)*1.e9  ! ASBCM
-     pomsol(:,:)       =   tr_seri(:,:,id_ASPOMM)                        *zrho(:,:)*1.e9  ! ASPOMM
-     sulfacc(:,:)      =  (tr_seri(:,:,id_ASSO4M)+tr_seri(:,:,id_ASMSAM))*zrho(:,:)*1.e9  ! ASSO4M (=SO4) + ASMSAM (=MSA)
-     sulfcoarse(:,:)   =  (tr_seri(:,:,id_CSSO4M)+tr_seri(:,:,id_CSMSAM))*zrho(:,:)*1.e9  ! CSSO4M (=SO4) + CSMSAM (=MSA)
-     sssupco(:,:)      =   tr_seri(:,:,id_SSSSM)                         *zrho(:,:)*1.e9  ! SSSSM
-     sscoarse(:,:)     =   tr_seri(:,:,id_CSSSM)                         *zrho(:,:)*1.e9  ! CSSSM
-     ssacu(:,:)        =   tr_seri(:,:,id_ASSSM)                         *zrho(:,:)*1.e9  ! ASSSM
-     cidust(:,:)       =   tr_seri(:,:,id_CIDUSTM)                       *zrho(:,:)*1.e9  ! CIDUSTM
-     bcins(:,:)        =   tr_seri(:,:,id_AIBCM)                         *zrho(:,:)*1.e9  ! AIBCM
-     pomins(:,:)       =   tr_seri(:,:,id_AIPOMM)                        *zrho(:,:)*1.e9  ! AIPOMM
-     nitracc(:,:)      =   tr_seri(:,:,id_ASNO3M)                        *zrho(:,:)*1.e9  ! ASNO3M
-     nitrcoarse(:,:)   =   tr_seri(:,:,id_CSNO3M)                        *zrho(:,:)*1.e9  ! CSNO3M
-     nitrinscoarse(:,:)=   tr_seri(:,:,id_CINO3M)                        *zrho(:,:)*1.e9  ! CINO3M
-     !
-     bcsol_pi(:,:)        =   0.0 ! ASBCM pre-ind
-     pomsol_pi(:,:)       =   0.0 ! ASPOMM pre-ind
-     sulfacc_pi(:,:)      =   0.0 ! ASSO4M (=SO4) + ASMSAM (=MSA) pre-ind
-     sulfcoarse_pi(:,:)   =   0.0 ! CSSO4M (=SO4) + CSMSAM (=MSA) pre-ind
-     sssupco_pi(:,:)      =   0.0 ! SSSSM pre-ind
-     sscoarse_pi(:,:)     =   0.0 ! CSSSM pre-ind
-     ssacu_pi(:,:)        =   0.0 ! ASSSM pre-ind
-     cidust_pi(:,:)       =   0.0 ! CIDUSTM pre-ind
-     bcins_pi(:,:)        =   0.0 ! AIBCM pre-ind
-     pomins_pi(:,:)       =   0.0 ! AIPOMM pre-ind
-     nitracc_pi(:,:)      =   0.0 ! ASNO3M pre-ind
-     nitrcoarse_pi(:,:)   =   0.0 ! CSNO3M pre-ind
-     nitrinscoarse_pi(:,:)=   0.0 ! CINO3M
-     !
-  ELSE !--not aerosol_couple
-     !
-     ! Read and interpolate sulfate
-     IF ( flag_aerosol .EQ. 1 .OR. flag_aerosol .EQ. 6 .OR. flag_aerosol .EQ. 7 ) THEN 
-
-        CALL readaerosol_interp(id_ASSO4M_phy, itap, pdtphys, rjourvrai, debut, pplay, paprs, t_seri, sulfacc, sulfacc_pi,loadso4)
-     ELSE
-        sulfacc(:,:) = 0. ; sulfacc_pi(:,:) = 0.
-        loadso4=0.
-     ENDIF
-
-     ! Read and interpolate bcsol and bcins
-     IF ( flag_aerosol .EQ. 2 .OR. flag_aerosol .EQ. 6 .OR. flag_aerosol .EQ. 7 ) THEN 
-
-        ! Get bc aerosol distribution 
-        CALL readaerosol_interp(id_ASBCM_phy, itap, pdtphys, rjourvrai, debut, pplay, paprs, t_seri, bcsol, bcsol_pi, load_tmp1 )
-        CALL readaerosol_interp(id_AIBCM_phy, itap, pdtphys, rjourvrai, debut, pplay, paprs, t_seri, bcins, bcins_pi, load_tmp2 )
-        loadbc(:)=load_tmp1(:)+load_tmp2(:)
-     ELSE
-        bcsol(:,:) = 0. ; bcsol_pi(:,:) = 0.
-        bcins(:,:) = 0. ; bcins_pi(:,:) = 0.
-        loadbc=0.
-     ENDIF
-
-     ! Read and interpolate pomsol and pomins
-     IF ( flag_aerosol .EQ. 3 .OR. flag_aerosol .EQ. 6 .OR. flag_aerosol .EQ. 7 ) THEN
-
-        CALL readaerosol_interp(id_ASPOMM_phy, itap, pdtphys, rjourvrai, debut, pplay, paprs, t_seri, pomsol, pomsol_pi, load_tmp3)
-        CALL readaerosol_interp(id_AIPOMM_phy, itap, pdtphys, rjourvrai, debut, pplay, paprs, t_seri, pomins, pomins_pi, load_tmp4)
-        loadoa(:)=load_tmp3(:)+load_tmp4(:)
-     ELSE
-        pomsol(:,:) = 0. ; pomsol_pi(:,:) = 0.
-        pomins(:,:) = 0. ; pomins_pi(:,:) = 0.
-        loadoa=0.
-     ENDIF
-
-     ! Read and interpolate csssm, ssssm, assssm
-     IF (flag_aerosol .EQ. 4 .OR. flag_aerosol .EQ. 6 .OR. flag_aerosol .EQ. 7 ) THEN 
-
-        CALL readaerosol_interp(id_SSSSM_phy ,itap, pdtphys,rjourvrai, &
-        debut, pplay, paprs, t_seri, sssupco, sssupco_pi, load_tmp5) 
-        CALL readaerosol_interp(id_CSSSM_phy ,itap, pdtphys,rjourvrai, &
-        debut, pplay, paprs, t_seri, sscoarse,sscoarse_pi, load_tmp6) 
-        CALL readaerosol_interp(id_ASSSM_phy ,itap, pdtphys,rjourvrai, &
-        debut, pplay, paprs, t_seri, ssacu, ssacu_pi, load_tmp7) 
-        loadss(:)=load_tmp5(:)+load_tmp6(:)+load_tmp7(:)
-     ELSE
-        sscoarse(:,:) = 0. ; sscoarse_pi(:,:) = 0. 
-        ssacu(:,:)    = 0. ; ssacu_pi(:,:) = 0. 
-        sssupco(:,:)  = 0. ; sssupco_pi = 0. 
-        loadss=0.
-     ENDIF
-
-     ! Read and interpolate cidustm
-     IF (flag_aerosol .EQ. 5 .OR. flag_aerosol .EQ. 6 .OR. flag_aerosol .EQ. 7 ) THEN 
-
-        CALL readaerosol_interp(id_CIDUSTM_phy, itap, pdtphys, rjourvrai, debut, pplay, paprs, t_seri, cidust, cidust_pi, loaddust) 
-
-     ELSE
-        cidust(:,:) = 0. ; cidust_pi(:,:) = 0. 
-        loaddust=0.
-     ENDIF
-     !
-     ! Read and interpolate asno3m, csno3m, cino3m
-     IF (flag_aerosol .EQ. 6 .OR. flag_aerosol .EQ. 7 ) THEN 
-
-        CALL readaerosol_interp(id_ASNO3M_phy, itap, pdtphys, rjourvrai, & 
-        debut, pplay, paprs, t_seri, nitracc, nitracc_pi, load_tmp8) 
-        CALL readaerosol_interp(id_CSNO3M_phy, itap, pdtphys, rjourvrai, & 
-        debut, pplay, paprs, t_seri, nitrcoarse, nitrcoarse_pi, load_tmp9) 
-        CALL readaerosol_interp(id_CINO3M_phy, itap, pdtphys, rjourvrai, & 
-        debut, pplay, paprs, t_seri, nitrinscoarse, nitrinscoarse_pi, load_tmp10) 
-        loadno3(:)=load_tmp8(:)+load_tmp9(:)+load_tmp10(:)
-
-     ELSE
-        nitracc(:,:)         =   0.0 ; nitracc_pi(:,:)      =   0.0 
-        nitrcoarse(:,:)      =   0.0 ; nitrcoarse_pi(:,:)   =   0.0
-        nitrinscoarse(:,:)   =   0.0 ; nitrinscoarse_pi(:,:)=   0.0
-        loadno3(:)=0.0
-     ENDIF
-     !
-     ! CSSO4M is set to 0 as not reliable
-     sulfcoarse(:,:)      =   0.0 ! CSSO4M (=SO4) + CSMSAM (=MSA) 
-     sulfcoarse_pi(:,:)   =   0.0 ! CSSO4M (=SO4) + CSMSAM (=MSA) pre-ind
-
-  ENDIF !--not aerosol_couple
-
-  !
-  ! Store all aerosols mixing ratios in one variable for radiation scheme (unit kg/kg for ECRAD)
-  ! present-day values
-  m_allaer(:,:,id_ASBCM_phy)  = bcsol(:,:)        /1.e9/zrho(:,:) ! ASBCM
-  m_allaer(:,:,id_ASPOMM_phy) = pomsol(:,:)       /1.e9/zrho(:,:) ! ASPOMM
-  m_allaer(:,:,id_ASSO4M_phy) = sulfacc(:,:)      /1.e9/zrho(:,:) ! ASSO4M (= SO4) 
-  m_allaer(:,:,id_CSSO4M_phy) = sulfcoarse(:,:)   /1.e9/zrho(:,:) ! CSSO4M 
-  m_allaer(:,:,id_SSSSM_phy)  = sssupco(:,:)      /1.e9/zrho(:,:) ! SSSSM
-  m_allaer(:,:,id_CSSSM_phy)  = sscoarse(:,:)     /1.e9/zrho(:,:) ! CSSSM
-  m_allaer(:,:,id_ASSSM_phy)  = ssacu(:,:)        /1.e9/zrho(:,:) ! ASSSM
-  m_allaer(:,:,id_CIDUSTM_phy)= cidust(:,:)       /1.e9/zrho(:,:) ! CIDUSTM
-  m_allaer(:,:,id_AIBCM_phy)  = bcins(:,:)        /1.e9/zrho(:,:) ! AIBCM
-  m_allaer(:,:,id_ASNO3M_phy) = nitracc(:,:)      /1.e9/zrho(:,:) ! ASNO3M
-  m_allaer(:,:,id_CSNO3M_phy) = nitrcoarse(:,:)   /1.e9/zrho(:,:) ! CSNO3M
-  m_allaer(:,:,id_CINO3M_phy) = nitrinscoarse(:,:)/1.e9/zrho(:,:) ! CINO3M
-  m_allaer(:,:,id_AIPOMM_phy) = pomins(:,:)       /1.e9/zrho(:,:) ! AIPOMM
-  m_allaer(:,:,id_STRAT_phy)  = 0.0
-
-  !  pre-industrial (pi) values
-  m_allaer_pi(:,:,id_ASBCM_phy)  = bcsol_pi(:,:)        /1.e9/zrho(:,:) ! ASBCM pre-ind
-  m_allaer_pi(:,:,id_ASPOMM_phy) = pomsol_pi(:,:)       /1.e9/zrho(:,:) ! ASPOMM pre-ind
-  m_allaer_pi(:,:,id_ASSO4M_phy) = sulfacc_pi(:,:)      /1.e9/zrho(:,:) ! ASSO4M (= SO4) pre-ind
-  m_allaer_pi(:,:,id_CSSO4M_phy) = sulfcoarse_pi(:,:)   /1.e9/zrho(:,:) ! CSSO4M pre-ind
-  m_allaer_pi(:,:,id_SSSSM_phy)  = sssupco_pi(:,:)      /1.e9/zrho(:,:) ! SSSSM pre-ind
-  m_allaer_pi(:,:,id_CSSSM_phy)  = sscoarse_pi(:,:)     /1.e9/zrho(:,:) ! CSSSM pre-ind
-  m_allaer_pi(:,:,id_ASSSM_phy)  = ssacu_pi(:,:)        /1.e9/zrho(:,:) ! ASSSM pre-ind
-  m_allaer_pi(:,:,id_CIDUSTM_phy)= cidust_pi(:,:)       /1.e9/zrho(:,:) ! CIDUSTM pre-ind
-  m_allaer_pi(:,:,id_AIBCM_phy)  = bcins_pi(:,:)        /1.e9/zrho(:,:) ! AIBCM pre-ind
-  m_allaer_pi(:,:,id_ASNO3M_phy) = nitracc_pi(:,:)      /1.e9/zrho(:,:) ! ASNO3M pre-ind
-  m_allaer_pi(:,:,id_CSNO3M_phy) = nitrcoarse_pi(:,:)   /1.e9/zrho(:,:) ! CSNO3M pre-ind
-  m_allaer_pi(:,:,id_CINO3M_phy) = nitrinscoarse_pi(:,:)/1.e9/zrho(:,:) ! CINO3M pre-ind
-  m_allaer_pi(:,:,id_AIPOMM_phy) = pomins_pi(:,:)       /1.e9/zrho(:,:) ! AIPOMM pre-ind
-  m_allaer_pi(:,:,id_STRAT_phy)  = 0.0
-
-  !
-  ! Calculate the total mass of all soluble aersosols (in unit ug /m3)
-  ! to be revisited for AR6
-  mass_solu_aero(:,:)    = sulfacc(:,:)    + bcsol(:,:)    + pomsol(:,:)    + nitracc(:,:)    + ssacu(:,:)
-  mass_solu_aero_pi(:,:) = sulfacc_pi(:,:) + bcsol_pi(:,:) + pomsol_pi(:,:) + nitracc_pi(:,:) + ssacu_pi(:,:)
-
-  !****************************************************************************************
-  ! 2) Calculate optical properties for the aerosols
-  !
-  !****************************************************************************************
-  DO k = 1, klev
-     DO i = 1, klon
-        pdel(i,k) = paprs(i,k) - paprs (i,k+1)
-     ENDDO
-  ENDDO
-
-  ! Diagnostics calculation for CMIP5 protocol unit (in unit kg/m3)
-  sconcso4(:)  =m_allaer(:,1,id_ASSO4M_phy)*1.e-9
-  sconcno3(:)  =(m_allaer(:,1,id_ASNO3M_phy)+m_allaer(:,1,id_CSNO3M_phy)+m_allaer(:,1,id_CINO3M_phy))*1.e-9
-  sconcoa(:)   =(m_allaer(:,1,id_ASPOMM_phy)+m_allaer(:,1,id_AIPOMM_phy))*1.e-9
-  sconcbc(:)   =(m_allaer(:,1,id_ASBCM_phy)+m_allaer(:,1,id_AIBCM_phy))*1.e-9
-  sconcss(:)   =(m_allaer(:,1,id_ASSSM_phy)+m_allaer(:,1,id_CSSSM_phy)+m_allaer(:,1,id_SSSSM_phy))*1.e-9
-  sconcdust(:) =m_allaer(:,1,id_CIDUSTM_phy)*1.e-9
-  concso4(:,:) =m_allaer(:,:,id_ASSO4M_phy)*1.e-9
-  concno3(:,:) =(m_allaer(:,:,id_ASNO3M_phy)+m_allaer(:,:,id_CSNO3M_phy)+m_allaer(:,:,id_CINO3M_phy))*1.e-9
-  concoa(:,:)  =(m_allaer(:,:,id_ASPOMM_phy)+m_allaer(:,:,id_AIPOMM_phy))*1.e-9
-  concbc(:,:)  =(m_allaer(:,:,id_ASBCM_phy)+m_allaer(:,:,id_AIBCM_phy))*1.e-9
-  concss(:,:)  =(m_allaer(:,:,id_ASSSM_phy)+m_allaer(:,:,id_CSSSM_phy)+m_allaer(:,:,id_SSSSM_phy))*1.e-9
-  concdust(:,:)=m_allaer(:,:,id_CIDUSTM_phy)*1.e-9
-
-END SUBROUTINE readaerosol_optic_ecrad
Index: DZ6/trunk/libf/phylmd/ecrad/radiation/readaerosolstrato_ecrad.F90
===================================================================
--- /LMDZ6/trunk/libf/phylmd/ecrad/radiation/readaerosolstrato_ecrad.F90	(revision 4852)
+++ 	(revision )
@@ -1,564 +1,0 @@
-!
-! $Id: readaerosolstrato_ecrad.F90 tlurton $
-!
-SUBROUTINE readaerosolstrato_ecrad(config, debut, ok_volcan)
-
-    USE netcdf95, ONLY: nf95_close, nf95_gw_var, nf95_inq_dimid, & 
-                        nf95_inq_varid, nf95_open
-    USE netcdf, ONLY: nf90_get_var, nf90_noerr, nf90_nowrite
-
-    USE phys_cal_mod, ONLY : mth_cur
-    USE mod_grid_phy_lmdz, ONLY: nbp_lon, nbp_lat, klon_glo, grid2dTo1d_glo, grid_type, unstructured
-    USE mod_phys_lmdz_mpi_data
-    USE mod_phys_lmdz_omp_data
-    USE mod_phys_lmdz_para 
-    USE phys_state_var_mod
-    USE phys_local_var_mod
-!    USE physiq_mod, ONLY : ok_volcan
-    USE aero_mod
-    USE dimphy
-!    USE YOERAD
-    USE radiation_config, ONLY : config_type
-    USE YOMCST
-#ifdef CPP_XIOS
-    USE xios
-#endif
-
-    IMPLICIT NONE
-
-    INCLUDE "clesphys.h"
-
-    CHARACTER (len = 80) :: abort_message
-    CHARACTER (LEN=20) :: modname = 'readaerosolstrato_ecrad'
-
-! Variable input
-    LOGICAL, INTENT(IN) ::  debut
-    LOGICAL, INTENT(IN) ::  ok_volcan !activate volcanic diags
-
-! Variables locales
-    INTEGER n_lat   ! number of latitudes in the input data
-    INTEGER n_lon   ! number of longitudes
-    INTEGER n_lev   ! number of levels in the input data
-    INTEGER n_month ! number of months in the input data
-    INTEGER n_wav   ! number of wavelengths in the input data
-    REAL, ALLOCATABLE:: latitude(:)
-    REAL, ALLOCATABLE:: time(:)
-    REAL, ALLOCATABLE:: lev(:)
-    REAL, ALLOCATABLE:: wav(:)
-    INTEGER i,k,wave,band
-    INTEGER, SAVE :: mth_pre=1
-!$OMP THREADPRIVATE(mth_pre)
-
-    REAL, ALLOCATABLE, DIMENSION(:,:,:), SAVE :: tau_aer_strat
-    REAL, ALLOCATABLE, DIMENSION(:,:,:), SAVE :: piz_aer_strat
-    REAL, ALLOCATABLE, DIMENSION(:,:,:), SAVE :: cg_aer_strat
-    REAL, ALLOCATABLE, DIMENSION(:,:,:), SAVE :: taulw_aer_strat
-! add ThL
-    REAL, ALLOCATABLE, DIMENSION(:,:,:), SAVE :: pizlw_aer_strat
-    REAL, ALLOCATABLE, DIMENSION(:,:,:), SAVE :: cglw_aer_strat
-! end add ThL
-! mod ThL
-!$OMP THREADPRIVATE(tau_aer_strat,piz_aer_strat,cg_aer_strat,taulw_aer_strat,pizlw_aer_strat,cglw_aer_strat)
-! end mod ThL
-
-! Champs reconstitues
-    REAL, ALLOCATABLE:: tauaerstrat(:, :, :, :)
-    REAL, ALLOCATABLE:: pizaerstrat(:, :, :, :)
-    REAL, ALLOCATABLE:: cgaerstrat(:, :, :, :)
-    REAL, ALLOCATABLE:: taulwaerstrat(:, :, :, :)
-! add ThL
-    REAL, ALLOCATABLE:: pizlwaerstrat(:, :, :, :)
-    REAL, ALLOCATABLE:: cglwaerstrat(:, :, :, :)
-! end add ThL
-
-    REAL, ALLOCATABLE:: tauaerstrat_mois(:, :, :, :)
-    REAL, ALLOCATABLE:: pizaerstrat_mois(:, :, :, :)
-    REAL, ALLOCATABLE:: cgaerstrat_mois(:, :, :, :)
-    REAL, ALLOCATABLE:: taulwaerstrat_mois(:, :, :, :)
-! add ThL
-    REAL, ALLOCATABLE:: pizlwaerstrat_mois(:, :, :, :)
-    REAL, ALLOCATABLE:: cglwaerstrat_mois(:, :, :, :)
-! end add ThL
-
-    REAL, ALLOCATABLE:: tauaerstrat_mois_glo(:, :, :)
-    REAL, ALLOCATABLE:: pizaerstrat_mois_glo(:, :, :)
-    REAL, ALLOCATABLE:: cgaerstrat_mois_glo(:, :, :)
-    REAL, ALLOCATABLE:: taulwaerstrat_mois_glo(:, :, :)
-! add ThL
-    REAL, ALLOCATABLE:: pizlwaerstrat_mois_glo(:, :, :)
-    REAL, ALLOCATABLE:: cglwaerstrat_mois_glo(:, :, :) 
-! end add ThL
-    REAL, ALLOCATABLE:: tauaerstrat_mpi(:, :, :)
-    REAL, ALLOCATABLE:: pizaerstrat_mpi(:, :, :)
-    REAL, ALLOCATABLE:: cgaerstrat_mpi(:, :, :)
-    REAL, ALLOCATABLE:: taulwaerstrat_mpi(:, :, :)
-! add ThL
-    REAL, ALLOCATABLE:: pizlwaerstrat_mpi(:, :, :)
-    REAL, ALLOCATABLE:: cglwaerstrat_mpi(:, :, :)
-! end add ThL
-
-! For NetCDF:
-    INTEGER ncid_in  ! IDs for input files
-    INTEGER varid, ncerr
-
-    TYPE(config_type), INTENT(IN) :: config
-
-!--------------------------------------------------------
-
-    IF (.not.ALLOCATED(tau_aer_strat)) ALLOCATE(tau_aer_strat(klon,klev,config%n_bands_sw))
-    IF (.not.ALLOCATED(piz_aer_strat)) ALLOCATE(piz_aer_strat(klon,klev,config%n_bands_sw))
-    IF (.not.ALLOCATED(cg_aer_strat))  ALLOCATE(cg_aer_strat(klon,klev,config%n_bands_sw))
-
-    IF (.not.ALLOCATED(taulw_aer_strat)) ALLOCATE(taulw_aer_strat(klon,klev,config%n_bands_lw))
-! add ThL    
-    IF (.not.ALLOCATED(pizlw_aer_strat)) ALLOCATE(pizlw_aer_strat(klon,klev,config%n_bands_lw))
-    IF (.not.ALLOCATED(cglw_aer_strat)) ALLOCATE(cglw_aer_strat(klon,klev,config%n_bands_lw))
-! end add ThL
-
-!--we only read monthly strat aerosol data
-    IF (debut.OR.mth_cur.NE.mth_pre) THEN
-
-!--only root reads the data
-      IF (is_mpi_root.AND.is_omp_root) THEN
-
-!--check mth_cur
-        IF (mth_cur.LT.1.OR.mth_cur.GT.12) THEN
-          print *,'probleme avec le mois dans readaerosolstrat =', mth_cur
-        ENDIF
-
-!--initialize n_lon as input data is 2D (lat-alt) only
-        n_lon = nbp_lon
-
-!--Starts with SW optical properties
-
-        CALL nf95_open("tauswstrat.2D.nc", nf90_nowrite, ncid_in)
-
-        CALL nf95_inq_varid(ncid_in, "LEV", varid)
-        CALL nf95_gw_var(ncid_in, varid, lev)
-        n_lev = size(lev)
-        IF (n_lev.NE.klev) THEN 
-           abort_message='Le nombre de niveaux n est pas egal a klev'
-           CALL abort_physic(modname,abort_message,1)
-        ENDIF
-
-        CALL nf95_inq_varid(ncid_in, "LAT", varid)
-        CALL nf95_gw_var(ncid_in, varid, latitude)
-        n_lat = size(latitude)
-
-        IF (grid_type/=unstructured) THEN
-           IF (n_lat.NE.nbp_lat) THEN 
-             print *, 'latitude=', n_lat, nbp_lat
-             abort_message='Le nombre de lat n est pas egal a nbp_lat'
-             CALL abort_physic(modname,abort_message,1)
-           ENDIF
-        ENDIF
-
-        CALL nf95_inq_varid(ncid_in, "TIME", varid)
-        CALL nf95_gw_var(ncid_in, varid, time)
-        n_month = size(time)
-        IF (n_month.NE.12) THEN 
-           abort_message='Le nombre de month n est pas egal a 12'
-           CALL abort_physic(modname,abort_message,1)
-        ENDIF
-
-        CALL nf95_inq_varid(ncid_in, "WAV", varid)
-        CALL nf95_gw_var(ncid_in, varid, wav)
-        n_wav = size(wav)
-        print *, 'WAV aerosol strato=', n_wav, wav
-!        IF (n_wav.NE.config%n_bands_sw) THEN 
-!           abort_message='Le nombre de wav n est pas egal a config%n_bands_sw'
-!           CALL abort_physic(modname,abort_message,1)
-!        ENDIF
-
-        ALLOCATE(tauaerstrat(n_lat, n_lev, n_wav, n_month))
-        ALLOCATE(pizaerstrat(n_lat, n_lev, n_wav, n_month))
-        ALLOCATE(cgaerstrat(n_lat, n_lev, n_wav, n_month))
-
-!--reading stratospheric aerosol tau per layer
-        CALL nf95_inq_varid(ncid_in, "TAU_SUN", varid)
-        ncerr = nf90_get_var(ncid_in, varid, tauaerstrat)
-        print *,'code erreur readaerosolstrato=', ncerr, varid
-
-!--reading stratospheric aerosol omega per layer
-        CALL nf95_inq_varid(ncid_in, "OME_SUN", varid)
-        ncerr = nf90_get_var(ncid_in, varid, pizaerstrat)
-        print *,'code erreur readaerosolstrato=', ncerr, varid
-
-!--reading stratospheric aerosol g per layer
-        CALL nf95_inq_varid(ncid_in, "GGG_SUN", varid)
-        ncerr = nf90_get_var(ncid_in, varid, cgaerstrat)
-        print *,'code erreur readaerosolstrato sw=', ncerr, varid
-
-        CALL nf95_close(ncid_in)
-
-       
-        IF (grid_type/=unstructured) THEN
-          ALLOCATE(tauaerstrat_mois(n_lon, n_lat, n_lev, n_wav))
-          ALLOCATE(pizaerstrat_mois(n_lon, n_lat, n_lev, n_wav))
-          ALLOCATE(cgaerstrat_mois(n_lon, n_lat, n_lev, n_wav))
-
-          ALLOCATE(tauaerstrat_mois_glo(klon_glo, n_lev, n_wav))
-          ALLOCATE(pizaerstrat_mois_glo(klon_glo, n_lev, n_wav))
-          ALLOCATE(cgaerstrat_mois_glo(klon_glo, n_lev, n_wav))
-!--select the correct month
-!--and copy into 1st longitude
-          tauaerstrat_mois(1,:,:,:) = tauaerstrat(:,:,:,mth_cur)
-          pizaerstrat_mois(1,:,:,:) = pizaerstrat(:,:,:,mth_cur)
-          cgaerstrat_mois(1,:,:,:)  = cgaerstrat(:,:,:,mth_cur)
-
-!--copy longitudes
-          DO i=2, n_lon
-           tauaerstrat_mois(i,:,:,:) = tauaerstrat_mois(1,:,:,:)
-           pizaerstrat_mois(i,:,:,:) = pizaerstrat_mois(1,:,:,:)
-           cgaerstrat_mois(i,:,:,:)  = cgaerstrat_mois(1,:,:,:)
-          ENDDO
-
-!---reduce to a klon_glo grid 
-          DO band=1, config%n_bands_sw
-            CALL grid2dTo1d_glo(tauaerstrat_mois(:,:,:,band),tauaerstrat_mois_glo(:,:,band))
-            CALL grid2dTo1d_glo(pizaerstrat_mois(:,:,:,band),pizaerstrat_mois_glo(:,:,band))
-            CALL grid2dTo1d_glo(cgaerstrat_mois(:,:,:,band),cgaerstrat_mois_glo(:,:,band))
-          ENDDO
-        ENDIF
-!--Now LW optical properties
-!
-
-        CALL nf95_open("taulwstrat.2D.nc", nf90_nowrite, ncid_in)
-
-        CALL nf95_inq_varid(ncid_in, "LEV", varid)
-        CALL nf95_gw_var(ncid_in, varid, lev)
-        n_lev = size(lev)
-        IF (n_lev.NE.klev) THEN 
-           abort_message='Le nombre de niveaux n est pas egal a klev'
-           CALL abort_physic(modname,abort_message,1)
-        ENDIF
-
-        CALL nf95_inq_varid(ncid_in, "LAT", varid)
-        CALL nf95_gw_var(ncid_in, varid, latitude)
-        n_lat = size(latitude)
-
-        IF (grid_type/=unstructured) THEN
-          IF (n_lat.NE.nbp_lat) THEN 
-             abort_message='Le nombre de lat n est pas egal a nbp_lat'
-             CALL abort_physic(modname,abort_message,1)
-          ENDIF
-        ENDIF
-        
-        CALL nf95_inq_varid(ncid_in, "TIME", varid)
-        CALL nf95_gw_var(ncid_in, varid, time)
-        n_month = size(time)
-        IF (n_month.NE.12) THEN 
-           abort_message='Le nombre de month n est pas egal a 12'
-           CALL abort_physic(modname,abort_message,1)
-        ENDIF
-
-        CALL nf95_inq_varid(ncid_in, "WAV", varid)
-        CALL nf95_gw_var(ncid_in, varid, wav)
-        n_wav = size(wav)
-        print *, 'WAV aerosol strato=', n_wav, wav
-!        IF (n_wav.NE.config%n_bands_lw) THEN 
-!           abort_message='Le nombre de wav n est pas egal a config%n_bands_lw'
-!           CALL abort_physic(modname,abort_message,1)
-!        ENDIF
-
-        ALLOCATE(taulwaerstrat(n_lat, n_lev, n_wav, n_month))
-! add ThL
-        ALLOCATE(pizlwaerstrat(n_lat, n_lev, n_wav, n_month))
-        ALLOCATE(cglwaerstrat(n_lat, n_lev, n_wav, n_month))
-! end add ThL
-
-!--reading stratospheric aerosol lw tau per layer
-        CALL nf95_inq_varid(ncid_in, "TAU_EAR", varid)
-        ncerr = nf90_get_var(ncid_in, varid, taulwaerstrat)
-        print *,'code erreur readaerosolstrato lw=', ncerr, varid
-
-! add/mod ThL
-!--with ECRAd, we also read omega and g:
-       !--reading stratospheric aerosol omega per layer
-        CALL nf95_inq_varid(ncid_in, "OME_EAR", varid)
-        ncerr = nf90_get_var(ncid_in, varid, pizlwaerstrat)
-        print *,'code erreur readaerosolstrato lw=', ncerr, varid
-
-!--reading stratospheric aerosol g per layer
-        CALL nf95_inq_varid(ncid_in, "GGG_EAR", varid)
-        ncerr = nf90_get_var(ncid_in, varid, cglwaerstrat)
-        print *,'code erreur readaerosolstrato lw=', ncerr, varid
-
-        CALL nf95_close(ncid_in)
-
-        IF (grid_type/=unstructured) THEN
-
-          ALLOCATE(taulwaerstrat_mois(n_lon, n_lat, n_lev, n_wav))
-          ALLOCATE(pizlwaerstrat_mois(n_lon, n_lat, n_lev, n_wav))
-          ALLOCATE(cglwaerstrat_mois(n_lon, n_lat, n_lev, n_wav))
-
-          ALLOCATE(taulwaerstrat_mois_glo(klon_glo, n_lev, n_wav))
-          ALLOCATE(pizlwaerstrat_mois_glo(klon_glo, n_lev, n_wav))
-          ALLOCATE(cglwaerstrat_mois_glo(klon_glo, n_lev, n_wav))
-!--select the correct month
-!--and copy into 1st longitude
-          taulwaerstrat_mois(1,:,:,:) = taulwaerstrat(:,:,:,mth_cur)
-          pizlwaerstrat_mois(1,:,:,:) = pizlwaerstrat(:,:,:,mth_cur)
-          cglwaerstrat_mois(1,:,:,:) = cglwaerstrat(:,:,:,mth_cur)
-!--copy longitudes
-          DO i=2, n_lon
-            taulwaerstrat_mois(i,:,:,:) = taulwaerstrat_mois(1,:,:,:)
-            pizlwaerstrat_mois(i,:,:,:) = pizlwaerstrat_mois(1,:,:,:)
-            cglwaerstrat_mois(i,:,:,:) = cglwaerstrat_mois(1,:,:,:)
-          ENDDO
-
-!---reduce to a klon_glo grid 
-          DO band=1, config%n_bands_lw
-            CALL grid2dTo1d_glo(taulwaerstrat_mois(:,:,:,band),taulwaerstrat_mois_glo(:,:,band))
-            CALL grid2dTo1d_glo(pizlwaerstrat_mois(:,:,:,band),pizlwaerstrat_mois_glo(:,:,band))
-            CALL grid2dTo1d_glo(cglwaerstrat_mois(:,:,:,band),cglwaerstrat_mois_glo(:,:,band))
-          ENDDO
-        ENDIF
-      
-      ELSE !--proc other than mpi_root and omp_root
-           !--dummy allocation needed for debug mode
-
-        ALLOCATE(tauaerstrat_mois_glo(1,1,1))
-        ALLOCATE(pizaerstrat_mois_glo(1,1,1))
-        ALLOCATE(cgaerstrat_mois_glo(1,1,1))
-        ALLOCATE(taulwaerstrat_mois_glo(1,1,1))
-        ALLOCATE(pizlwaerstrat_mois_glo(1,1,1))
-        ALLOCATE(cglwaerstrat_mois_glo(1,1,1))
-
-        ALLOCATE(tauaerstrat(0,0,0,12))
-        ALLOCATE(pizaerstrat(0,0,0,12))
-        ALLOCATE(cgaerstrat(0,0,0,12))
-        ALLOCATE(taulwaerstrat(0,0,0,12))
-        ALLOCATE(pizlwaerstrat(0,0,0,12))
-        ALLOCATE(cglwaerstrat(0,0,0,12))
-! end add/mod ThL
-
-      ENDIF !--is_mpi_root and is_omp_root
-
-!$OMP BARRIER
-
-!--keep memory of previous month
-      mth_pre=mth_cur
-
-      IF (grid_type==unstructured) THEN
-
-#ifdef CPP_XIOS
-
-        IF (is_omp_master) THEN
-          ALLOCATE(tauaerstrat_mpi(klon_mpi, klev, config%n_bands_sw))
-          ALLOCATE(pizaerstrat_mpi(klon_mpi, klev, config%n_bands_sw))
-          ALLOCATE(cgaerstrat_mpi(klon_mpi, klev, config%n_bands_sw))        
-          ALLOCATE(taulwaerstrat_mpi(klon_mpi, klev, config%n_bands_lw))
-! add ThL
-          ALLOCATE(pizlwaerstrat_mpi(klon_mpi, klev, config%n_bands_lw))
-          ALLOCATE(cglwaerstrat_mpi(klon_mpi, klev, config%n_bands_lw))
-! end add ThL
-
-          CALL xios_send_field("tauaerstrat_in",SPREAD(tauaerstrat(:,:,:,mth_cur),1,8))
-          CALL xios_recv_field("tauaerstrat_out",tauaerstrat_mpi)
-          CALL xios_send_field("pizaerstrat_in",SPREAD(pizaerstrat(:,:,:,mth_cur),1,8))
-          CALL xios_recv_field("pizaerstrat_out",pizaerstrat_mpi)
-          CALL xios_send_field("cgaerstrat_in",SPREAD(cgaerstrat(:,:,:,mth_cur),1,8))
-          CALL xios_recv_field("cgaerstrat_out",cgaerstrat_mpi)
-          CALL xios_send_field("taulwaerstrat_in",SPREAD(taulwaerstrat(:,:,:,mth_cur),1,8))
-          CALL xios_recv_field("taulwaerstrat_out",taulwaerstrat_mpi)
-! add ThL
-          CALL xios_send_field("pizlwaerstrat_in",SPREAD(pizlwaerstrat(:,:,:,mth_cur),1,8))
-          CALL xios_recv_field("pizlwaerstrat_out",pizlwaerstrat_mpi)
-          CALL xios_send_field("cglwaerstrat_in",SPREAD(cglwaerstrat(:,:,:,mth_cur),1,8))
-          CALL xios_recv_field("cglwaerstrat_out",cglwaerstrat_mpi)
-! end add ThL
-        ELSE
-          ALLOCATE(tauaerstrat_mpi(0, 0, 0))
-          ALLOCATE(pizaerstrat_mpi(0, 0, 0))
-          ALLOCATE(cgaerstrat_mpi(0, 0, 0))        
-          ALLOCATE(taulwaerstrat_mpi(0, 0, 0))
-! add ThL
-          ALLOCATE(pizlwaerstrat_mpi(0, 0, 0))
-          ALLOCATE(cglwaerstrat_mpi(0, 0, 0))
-! end add ThL
-        ENDIF  
-        
-        CALL scatter_omp(tauaerstrat_mpi,tau_aer_strat)
-        CALL scatter_omp(pizaerstrat_mpi,piz_aer_strat)
-        CALL scatter_omp(cgaerstrat_mpi,cg_aer_strat)
-        CALL scatter_omp(taulwaerstrat_mpi,taulw_aer_strat)
-! add ThL
-        CALL scatter_omp(pizlwaerstrat_mpi,pizlw_aer_strat)
-        CALL scatter_omp(cglwaerstrat_mpi,cglw_aer_strat)
-! end add ThL
-#endif
-      ELSE  
-        
-!--scatter on all proc
-        CALL scatter(tauaerstrat_mois_glo,tau_aer_strat)
-        CALL scatter(pizaerstrat_mois_glo,piz_aer_strat)
-        CALL scatter(cgaerstrat_mois_glo,cg_aer_strat)
-        CALL scatter(taulwaerstrat_mois_glo,taulw_aer_strat)
-! add ThL
-        CALL scatter(pizlwaerstrat_mois_glo,pizlw_aer_strat)
-        CALL scatter(cglwaerstrat_mois_glo,cglw_aer_strat) 
-! end add ThL
-        IF (is_mpi_root.AND.is_omp_root)  DEALLOCATE(tauaerstrat_mois, pizaerstrat_mois, cgaerstrat_mois, taulwaerstrat_mois, pizlwaerstrat_mois, cglwaerstrat_mois) ! mod ThL
-
-      ENDIF 
-
-      IF (is_mpi_root.AND.is_omp_root) THEN
-        DEALLOCATE(tauaerstrat, pizaerstrat, cgaerstrat, taulwaerstrat, pizlwaerstrat, cglwaerstrat) ! mod ThL
-      ENDIF
-      
-
-!$OMP BARRIER
-
-    ENDIF !--debut ou nouveau mois
-
-!--total vertical aod at the SW wavelengths
-!--for now use ECRAD band #10 AOD into all wavelengths
-!--it is only a reasonable approximation for 550 nm
-!--WAV(10)=0.53 µm
-!--<!!!> This is considering that wavebands are in their original order,
-!--and have NOT been re-ordered monotonously, i.e. with
-!--WAV(1) = 3.46 µm
-!--WAV(2) = 2.79 µm
-!--(...)
-!--WAV(last-1) = 0.23 µm
-!--WAV(last)= 8.02 µm
-!--If bands were to be re-ordered, i.e. last band be put in 1st position,
-!--then we should consider band=11 to fetch WAV=0.53 µm.
-    band=10
-    DO i=1, klon
-    DO k=1, klev
-      IF (stratomask(i,k).GT.0.999999) THEN
-        DO wave=1, config%n_bands_sw
-          tausum_aero(i,wave,id_STRAT_phy)=tausum_aero(i,wave,id_STRAT_phy)+tau_aer_strat(i,k,band)
-        ENDDO
-      ENDIF
-    ENDDO
-    ENDDO
-
-    IF (.NOT. ok_volcan) THEN
-!
-!--this is the default case 
-!--stratospheric aerosols are added to both index 2 and 1 for double radiation calls
-!--weighted average for cg, piz and tau, adding strat aerosols on top of tropospheric ones
-    DO band=1, config%n_bands_sw
-      WHERE (stratomask.GT.0.999999)
-!--strat aerosols are added to index 2: natural and anthropogenic aerosols for bands 1 to config%n_bands_sw 
-        cg_aero_sw_rrtm(:,:,2,band)  = ( cg_aero_sw_rrtm(:,:,2,band)*piz_aero_sw_rrtm(:,:,2,band)*tau_aero_sw_rrtm(:,:,2,band) + &
-                                         cg_aer_strat(:,:,band)*piz_aer_strat(:,:,band)*tau_aer_strat(:,:,band) ) /              &
-                                    MAX( piz_aero_sw_rrtm(:,:,2,band)*tau_aero_sw_rrtm(:,:,2,band) +                             &
-                                         piz_aer_strat(:,:,band)*tau_aer_strat(:,:,band), 1.e-15 )
-        piz_aero_sw_rrtm(:,:,2,band) = ( piz_aero_sw_rrtm(:,:,2,band)*tau_aero_sw_rrtm(:,:,2,band) +                             &
-                                         piz_aer_strat(:,:,band)*tau_aer_strat(:,:,band) ) /                                     &
-                                    MAX( tau_aero_sw_rrtm(:,:,2,band) + tau_aer_strat(:,:,band), 1.e-15 )
-        tau_aero_sw_rrtm(:,:,2,band)  = tau_aero_sw_rrtm(:,:,2,band) + tau_aer_strat(:,:,band)
-!--strat aerosols are added to index 1: natural aerosols only for bands 1 to config%n_bands_sw
-        cg_aero_sw_rrtm(:,:,1,band)  = ( cg_aero_sw_rrtm(:,:,1,band)*piz_aero_sw_rrtm(:,:,1,band)*tau_aero_sw_rrtm(:,:,1,band) + &
-                                         cg_aer_strat(:,:,band)*piz_aer_strat(:,:,band)*tau_aer_strat(:,:,band) ) /              &
-                                    MAX( piz_aero_sw_rrtm(:,:,1,band)*tau_aero_sw_rrtm(:,:,1,band) +                             &
-                                         piz_aer_strat(:,:,band)*tau_aer_strat(:,:,band), 1.e-15 )
-        piz_aero_sw_rrtm(:,:,1,band) = ( piz_aero_sw_rrtm(:,:,1,band)*tau_aero_sw_rrtm(:,:,1,band) +                             &
-                                         piz_aer_strat(:,:,band)*tau_aer_strat(:,:,band) ) /                                     &
-                                    MAX( tau_aero_sw_rrtm(:,:,1,band) + tau_aer_strat(:,:,band), 1.e-15 )
-        tau_aero_sw_rrtm(:,:,1,band)  = tau_aero_sw_rrtm(:,:,1,band) + tau_aer_strat(:,:,band)
-    ENDWHERE
-    ENDDO
-!
-    ELSE
-!
-!--this is the VOLMIP case
-!--stratospheric aerosols are only added to index 2 in this case 
-!--weighted average for cg, piz and tau, adding strat aerosols on top of tropospheric ones
-    DO band=1, config%n_bands_sw
-      WHERE (stratomask.GT.0.999999)
-!--strat aerosols are added to index 2 : natural and anthropogenic aerosols for bands 1 to config%n_bands_sw 
-        cg_aero_sw_rrtm(:,:,2,band)  = ( cg_aero_sw_rrtm(:,:,2,band)*piz_aero_sw_rrtm(:,:,2,band)*tau_aero_sw_rrtm(:,:,2,band) + &
-                                         cg_aer_strat(:,:,band)*piz_aer_strat(:,:,band)*tau_aer_strat(:,:,band) ) /              &
-                                    MAX( piz_aero_sw_rrtm(:,:,2,band)*tau_aero_sw_rrtm(:,:,2,band) +                             &
-                                         piz_aer_strat(:,:,band)*tau_aer_strat(:,:,band), 1.e-15 )
-        piz_aero_sw_rrtm(:,:,2,band) = ( piz_aero_sw_rrtm(:,:,2,band)*tau_aero_sw_rrtm(:,:,2,band) +                             &
-                                         piz_aer_strat(:,:,band)*tau_aer_strat(:,:,band) ) /                                     &
-                                    MAX( tau_aero_sw_rrtm(:,:,2,band) + tau_aer_strat(:,:,band), 1.e-15 )
-        tau_aero_sw_rrtm(:,:,2,band)  = tau_aero_sw_rrtm(:,:,2,band) + tau_aer_strat(:,:,band)
-     ENDWHERE
-  ENDDO
-  ENDIF
-
-!--total vertical aod at 10 um
-!--this is approximated from band 7 of ECRAD (9.73 µm)
-    band=7
-    DO i=1, klon
-    DO k=1, klev
-      IF (stratomask(i,k).GT.0.999999) THEN
-        DO wave=1, config%n_bands_lw
-          tausum_aero(i,config%n_bands_sw+wave,id_STRAT_phy)=tausum_aero(i,config%n_bands_sw+wave,id_STRAT_phy)+taulw_aer_strat(i,k,band)
-        ENDDO
-      ENDIF
-    ENDDO
-    ENDDO
-
-    IF (.NOT. ok_volcan) THEN
-!--this is the default case 
-!--stratospheric aerosols are added to both index 2 and 1
-    DO band=1, config%n_bands_lw
-      WHERE (stratomask.GT.0.999999)
-! add ThL
-        cg_aero_lw_rrtm(:,:,2,band)  = ( cg_aero_lw_rrtm(:,:,2,band)*piz_aero_lw_rrtm(:,:,2,band)*tau_aero_lw_rrtm(:,:,2,band) + &
-                                         cglw_aer_strat(:,:,band)*pizlw_aer_strat(:,:,band)*taulw_aer_strat(:,:,band) ) /        &
-                                    MAX( piz_aero_lw_rrtm(:,:,2,band)*tau_aero_lw_rrtm(:,:,2,band) +                             &
-                                         pizlw_aer_strat(:,:,band)*taulw_aer_strat(:,:,band), 1.e-15 )
-        piz_aero_lw_rrtm(:,:,2,band) = ( piz_aero_lw_rrtm(:,:,2,band)*tau_aero_lw_rrtm(:,:,2,band) +                             &
-                                         pizlw_aer_strat(:,:,band)*taulw_aer_strat(:,:,band) ) /                                 &
-                                    MAX( tau_aero_lw_rrtm(:,:,2,band) + taulw_aer_strat(:,:,band), 1.e-15 )
-        cg_aero_lw_rrtm(:,:,1,band)  = ( cg_aero_lw_rrtm(:,:,1,band)*piz_aero_lw_rrtm(:,:,1,band)*tau_aero_lw_rrtm(:,:,1,band) + &
-                                         cglw_aer_strat(:,:,band)*pizlw_aer_strat(:,:,band)*taulw_aer_strat(:,:,band) ) /        &
-                                    MAX( piz_aero_lw_rrtm(:,:,1,band)*tau_aero_lw_rrtm(:,:,1,band) +                             &
-                                         pizlw_aer_strat(:,:,band)*taulw_aer_strat(:,:,band), 1.e-15 )
-        piz_aero_lw_rrtm(:,:,1,band) = ( piz_aero_lw_rrtm(:,:,1,band)*tau_aero_lw_rrtm(:,:,1,band) +                             &
-                                         pizlw_aer_strat(:,:,band)*taulw_aer_strat(:,:,band) ) /                                 &
-                                    MAX( tau_aero_lw_rrtm(:,:,1,band) + taulw_aer_strat(:,:,band), 1.e-15 )
-! end add ThL
-        tau_aero_lw_rrtm(:,:,2,band)  = tau_aero_lw_rrtm(:,:,2,band) + taulw_aer_strat(:,:,band)
-        tau_aero_lw_rrtm(:,:,1,band)  = tau_aero_lw_rrtm(:,:,1,band) + taulw_aer_strat(:,:,band)
-      ENDWHERE
-    ENDDO
-!
-    ELSE
-!
-! mod ThL
-!--this is the VOLMIP case
-    DO band=1, config%n_bands_lw
-      WHERE (stratomask.GT.0.999999)
-!--stratospheric aerosols are not added to index 1 
-!--and we copy index 2 in index 1 because we want the same dust aerosol LW properties as above
-        cg_aero_lw_rrtm(:,:,1,band)  = cg_aero_lw_rrtm(:,:,2,band)
-        piz_aero_lw_rrtm(:,:,1,band) = piz_aero_lw_rrtm(:,:,2,band)
-        tau_aero_lw_rrtm(:,:,1,band) = tau_aero_lw_rrtm(:,:,2,band)
-
-!--stratospheric aerosols are only added to index 2
-        cg_aero_lw_rrtm(:,:,2,band)  = (cg_aero_lw_rrtm(:,:,2,band)*piz_aero_lw_rrtm(:,:,2,band)*tau_aero_lw_rrtm(:,:,2,band) + &
-                                        cglw_aer_strat(:,:,band)*pizlw_aer_strat(:,:,band)*taulw_aer_strat(:,:,band)) /         &
-                                        MAX( piz_aero_lw_rrtm(:,:,2,band)*tau_aero_lw_rrtm(:,:,2,band) +                        &
-                                        pizlw_aer_strat(:,:,band)*taulw_aer_strat(:,:,band), 1.e-15 )
-        piz_aero_lw_rrtm(:,:,2,band) = (piz_aero_lw_rrtm(:,:,2,band)*tau_aero_lw_rrtm(:,:,2,band) +                             &
-                                        pizlw_aer_strat(:,:,band)*taulw_aer_strat(:,:,band) ) /                                 &
-                                        MAX( tau_aero_lw_rrtm(:,:,2,band) + taulw_aer_strat(:,:,band), 1.e-15 )
-        tau_aero_lw_rrtm(:,:,2,band)  = tau_aero_lw_rrtm(:,:,2,band) + taulw_aer_strat(:,:,band)
-      ENDWHERE
-    ENDDO
-    ENDIF
-! end mod ThL
-
-!--default SSA value if there is no aerosol
-!--to avoid 0 values that seems to cause some problem to RRTM
-    WHERE (tau_aero_sw_rrtm.LT.1.e-14)
-      piz_aero_sw_rrtm = 1.0
-    ENDWHERE
-
-!--in principle this should not be necessary 
-!--as these variables have min values already but just in case
-!--put 1e-15 min value to both SW and LW AOD
-    tau_aero_sw_rrtm = MAX(tau_aero_sw_rrtm,1.e-15)
-    tau_aero_lw_rrtm = MAX(tau_aero_lw_rrtm,1.e-15)
-
-END SUBROUTINE readaerosolstrato_ecrad
Index: DZ6/trunk/libf/phylmd/ecrad/radiation/setup_aerosol_optics_lmdz_m.F90
===================================================================
--- /LMDZ6/trunk/libf/phylmd/ecrad/radiation/setup_aerosol_optics_lmdz_m.F90	(revision 4852)
+++ 	(revision )
@@ -1,124 +1,0 @@
-module setup_aerosol_optics_lmdz_m
-
-  implicit none
-
-contains
-
-  subroutine setup_aerosol_optics_lmdz(ao, file_name)
-
-    ! Read aerosol optical properties. Note differences with
-    ! "radiation_aerosol_optics_data::setup_aerosol_optics":
-
-    ! -- The input NetCDF file is not flat, it contains NetCDF groups.
-
-    ! -- We do not define ao%ssa_mono_phobic, ao%g_mono_phobic,
-    ! ao%lidar_ratio_mono_phobic, ao%ssa_mono_philic,
-    ! ao%g_mono_philic, ao%lidar_ratio_mono_philic. They are not in
-    ! the input NetCDF file and they are not used by ECRad.
-
-    ! -- We do not define ao%description_phobic_str and
-    ! ao%description_philic_str. We just leave the initialization
-    ! value, which is a blank.
-
-    ! -- We have to cshift the shortwave fields because the the
-    ! shortwave bands are in ascending order in the NetCDF file while
-    ! they are not in ECRad.
-
-    use radiation_aerosol_optics_data, only: aerosol_optics_type, &
-         IAerosolClassUndefined
-    use netcdf95, only: nf95_open, nf95_inq_grp_full_ncid, nf95_close, &
-         nf95_inq_dimid, nf95_inq_varid, nf95_inquire_dimension, &
-         nf95_get_var, nf95_gw_var, nf95_nowrite
-
-    type(aerosol_optics_type), intent(out):: ao
-
-    character(len=*), intent(in):: file_name
-    ! NetCDF file containing the aerosol optics data
-
-    ! Local:
-    integer ncid, grpid, dimid, varid
-
-    !-----------------------------------------------------------------------
-
-    ao%use_hydrophilic = .true.
-    ao%use_monochromatic = .true.
-    call nf95_open(file_name, nf95_nowrite, ncid)
-    call nf95_inq_grp_full_ncid(ncid, "Hydrophilic", grpid)
-    call nf95_inq_dimid(grpid, "hur", dimid)
-    call nf95_inquire_dimension(grpid, dimid, nclen = ao%nrh)
-    allocate(ao%rh_lower(ao%nrh))
-    call nf95_inq_varid(grpid, "hur_bounds", varid)
-    call nf95_get_var(grpid, varid, ao%rh_lower, count_nc = [1, ao%nrh])
-
-    ! Hydrophilic/LW_bands:
-    call nf95_inq_grp_full_ncid(ncid, "Hydrophilic/LW_bands", grpid)
-    call nf95_inq_varid(grpid, "asymmetry", varid)
-    call nf95_gw_var(grpid, varid, ao%g_lw_philic)
-    call nf95_inq_varid(grpid, "single_scat_alb", varid)
-    call nf95_gw_var(grpid, varid, ao%ssa_lw_philic)
-    call nf95_inq_varid(grpid, "mass_ext", varid)
-    call nf95_gw_var(grpid, varid, ao%mass_ext_lw_philic)
-
-    ! Hydrophilic/SW_bands:
-    call nf95_inq_grp_full_ncid(ncid, "Hydrophilic/SW_bands", grpid)
-    call nf95_inq_varid(grpid, "asymmetry", varid)
-    call nf95_gw_var(grpid, varid, ao%g_sw_philic)
-    ao%g_sw_philic = cshift(ao%g_sw_philic, 1)
-    call nf95_inq_varid(grpid, "single_scat_alb", varid)
-    call nf95_gw_var(grpid, varid, ao%ssa_sw_philic)
-    ao%ssa_sw_philic = cshift(ao%ssa_sw_philic, 1)
-    call nf95_inq_varid(grpid, "mass_ext", varid)
-    call nf95_gw_var(grpid, varid, ao%mass_ext_sw_philic)
-    ao%mass_ext_sw_philic = cshift(ao%mass_ext_sw_philic, 1)
-
-    ! Hydrophilic/Monochromatic:
-    call nf95_inq_grp_full_ncid(ncid, "Hydrophilic/Monochromatic", grpid)
-    call nf95_inq_varid(grpid, "mass_ext", varid)
-    call nf95_gw_var(grpid, varid, ao%mass_ext_mono_philic)
-
-    ! Hydrophobic/LW_bands:
-    call nf95_inq_grp_full_ncid(ncid, "Hydrophobic/LW_bands", grpid)
-    call nf95_inq_varid(grpid, "asymmetry", varid)
-    call nf95_gw_var(grpid, varid, ao%g_lw_phobic)
-    call nf95_inq_varid(grpid, "single_scat_alb", varid)
-    call nf95_gw_var(grpid, varid, ao%ssa_lw_phobic)
-    call nf95_inq_varid(grpid, "mass_ext", varid)
-    call nf95_gw_var(grpid, varid, ao%mass_ext_lw_phobic)
-
-    ! Hydrophobic/SW_bands:
-    call nf95_inq_grp_full_ncid(ncid, "Hydrophobic/SW_bands", grpid)
-    call nf95_inq_varid(grpid, "asymmetry", varid)
-    call nf95_gw_var(grpid, varid, ao%g_sw_phobic)
-    ao%g_sw_phobic = cshift(ao%g_sw_phobic, 1)
-    call nf95_inq_varid(grpid, "single_scat_alb", varid)
-    call nf95_gw_var(grpid, varid, ao%ssa_sw_phobic)
-    ao%ssa_sw_phobic = cshift(ao%ssa_sw_phobic, 1)
-    call nf95_inq_varid(grpid, "mass_ext", varid)
-    call nf95_gw_var(grpid, varid, ao%mass_ext_sw_phobic)
-    ao%mass_ext_sw_phobic = cshift(ao%mass_ext_sw_phobic, 1)
-
-    ! Hydrophobic/Monochromatic:
-    call nf95_inq_grp_full_ncid(ncid, "Hydrophobic/Monochromatic", grpid)
-    call nf95_inq_varid(grpid, "mass_ext", varid)
-    call nf95_gw_var(grpid, varid, ao%mass_ext_mono_phobic)
-
-    call nf95_close(ncid)
-
-    ! Get array sizes
-    ao%n_bands_lw = size(ao%mass_ext_lw_phobic, 1)
-    ao%n_bands_sw = size(ao%mass_ext_sw_phobic, 1)
-    ao%n_mono_wl = size(ao%mass_ext_mono_phobic, 1)
-    ao%n_type_phobic = size(ao%mass_ext_lw_phobic, 2)
-    ao%n_type_philic = size(ao%mass_ext_lw_philic, 3)
-
-    ! Allocate memory for mapping arrays
-    ao%ntype = ao%n_type_phobic + ao%n_type_philic
-    allocate(ao%iclass(ao%ntype))
-    allocate(ao%itype(ao%ntype))
-
-    ao%iclass = IAerosolClassUndefined
-    ao%itype  = 0
-
-  end subroutine setup_aerosol_optics_lmdz
-
-end module setup_aerosol_optics_lmdz_m
Index: DZ6/trunk/libf/phylmd/ecrad/radiation/setup_config_from_lmdz.F90
===================================================================
--- /LMDZ6/trunk/libf/phylmd/ecrad/radiation/setup_config_from_lmdz.F90	(revision 4852)
+++ 	(revision )
@@ -1,104 +1,0 @@
-module setup_config_from_lmdz
-
-  use parkind1, only : jprb
-
-  implicit none
-
-  public
-
-  type driver_config_type
-     logical    :: ok_effective_size  = .true.
-     logical    :: ok_separation = .false.   
-     real(jprb) :: high_inv_effective_size   = -1.0_jprb ! m-1
-     real(jprb) :: middle_inv_effective_size = -1.0_jprb ! m-1
-     real(jprb) :: low_inv_effective_size    = -1.0_jprb ! m-1
-     real(jprb) :: cloud_inhom_separation_factor  = -1.0_jprb
-     real(jprb) :: cloud_separation_scale_surface = -1.0_jprb
-     real(jprb) :: cloud_separation_scale_toa     = -1.0_jprb
-     real(jprb) :: cloud_separation_scale_power   = -1.0_jprb
-     real(jprb) :: frac_std = 0.75_jprb
-     real(jprb) :: overlap_decorr_length = 2000.0_jprb
-
-
- contains
- procedure :: read => read_config_from_namelist
-
-  end type driver_config_type
-
-contains
-
-  !---------------------------------------------------------------------
-  subroutine read_config_from_namelist(this, file_name, is_success)
-
-    use radiation_io, only : nulerr, radiation_abort       
-
-    class(driver_config_type), intent(inout) :: this
-    character(*), intent(in)          :: file_name
-    logical, intent(out), optional    :: is_success
-    logical    :: ok_effective_size, ok_separation
-    integer    :: iosopen ! Status after calling open
-    real(jprb) :: high_inv_effective_size 
-    real(jprb) :: middle_inv_effective_size
-    real(jprb) :: low_inv_effective_size
-    real(jprb) :: cloud_inhom_separation_factor 
-    real(jprb) :: cloud_separation_scale_surface
-    real(jprb) :: cloud_separation_scale_toa
-    real(jprb) :: cloud_separation_scale_power
-    real(jprb) :: frac_std
-    real(jprb) :: overlap_decorr_length
-
-    namelist /radiation_driver/ ok_effective_size, ok_separation, &
-         &  frac_std, overlap_decorr_length, &
-         &  high_inv_effective_size, middle_inv_effective_size, low_inv_effective_size, &
-         &  cloud_inhom_separation_factor, cloud_separation_scale_surface, &
-         &  cloud_separation_scale_toa, cloud_separation_scale_power 
-
-    ok_effective_size = .false.
-    ok_separation = .false.
-    high_inv_effective_size   = -1.0_jprb 
-    middle_inv_effective_size = -1.0_jprb 
-    low_inv_effective_size    = -1.0_jprb 
-    cloud_inhom_separation_factor  = -1.0_jprb
-    cloud_separation_scale_surface = -1.0_jprb
-    cloud_separation_scale_toa     = -1.0_jprb
-    cloud_separation_scale_power   = -1.0_jprb
-    frac_std = 0.75_jprb
-    overlap_decorr_length = 2000.0_jprb
-
-    ! Open the namelist file and read the radiation_driver namelist
-    open(unit=10, iostat=iosopen, file=trim(file_name))
-    if (iosopen /= 0) then
-      ! An error occurred
-      if (present(is_success)) then
-        is_success = .false.
-        ! We now continue the subroutine so that the default values
-        ! are placed in the config structure
-      else
-        write(nulerr,'(a,a,a)') '*** Error: namelist file "', &
-             &                trim(file_name), '" not found'
-        call radiation_abort('Driver configuration error')
-      end if
-    else
-      ! Read the radiation_driver namelist, noting that it is not an
-      ! error if this namelist is not present, provided all the required
-      ! variables are present in the NetCDF data file instead
-      read(unit=10, nml=radiation_driver)
-      close(unit=10)
-    end if
-
-    ! Copy namelist data into configuration object
-    this%ok_effective_size = ok_effective_size 
-    this%ok_separation = ok_separation
-    this%frac_std = frac_std
-    this%overlap_decorr_length = overlap_decorr_length
-    this%cloud_inhom_separation_factor = cloud_inhom_separation_factor
-    this%cloud_separation_scale_surface = cloud_separation_scale_surface
-    this%cloud_separation_scale_toa = cloud_separation_scale_toa
-    this%cloud_separation_scale_power = cloud_separation_scale_power
-    this%high_inv_effective_size = high_inv_effective_size
-    this%middle_inv_effective_size = middle_inv_effective_size
-    this%low_inv_effective_size = low_inv_effective_size
-
-  end subroutine read_config_from_namelist          
-
-end module setup_config_from_lmdz
Index: /LMDZ6/trunk/libf/phylmd/ecrad/test/ifs/Makefile
===================================================================
--- /LMDZ6/trunk/libf/phylmd/ecrad/test/ifs/Makefile	(revision 4852)
+++ /LMDZ6/trunk/libf/phylmd/ecrad/test/ifs/Makefile	(revision 4853)
@@ -15,4 +15,5 @@
 CONFIG = configCY49R1.nam
 CONFIG_ECCKD = configCY49R1_ecckd.nam
+CONFIG_MIXED = configCY49R1_mixed.nam
 
 # Typing "make" will run radiation scheme on IFS profiles
@@ -111,4 +112,13 @@
 test_ecckd_tc:
 	$(DRIVER) $(CONFIG_ECCKD) $(INPUT).nc $(INPUT)_ecckd_tc_out.nc
+
+test_mixed_gas:
+	$(DRIVER) $(CONFIG_MIXED) $(INPUT).nc $(INPUT)_sw_ecckd_lw_ecckd_out.nc
+	$(CHANGENAM) $(CONFIG_MIXED) config_mix.nam lw_gas_model_name='"RRTMG-IFS"' do_cloud_aerosol_per_lw_g_point=false
+	$(DRIVER) config_mix.nam $(INPUT).nc $(INPUT)_sw_ecckd_lw_rrtmg_out.nc
+	$(CHANGENAM) $(CONFIG_MIXED) config_mix.nam sw_gas_model_name='"RRTMG-IFS"' do_cloud_aerosol_per_sw_g_point=false
+	$(DRIVER) config_mix.nam $(INPUT).nc $(INPUT)_sw_rrtmg_lw_ecckd_out.nc
+	$(CHANGENAM) $(CONFIG_MIXED) config_mix.nam sw_gas_model_name='"RRTMG-IFS"' lw_gas_model_name='"RRTMG-IFS"' do_cloud_aerosol_per_lw_g_point=false do_cloud_aerosol_per_sw_g_point=false
+	$(DRIVER) config_mix.nam $(INPUT).nc $(INPUT)_sw_rrtmg_lw_rrtmg_out.nc
 
 # ecCKD with no aerosols
Index: /LMDZ6/trunk/libf/phylmd/physiq_mod.F90
===================================================================
--- /LMDZ6/trunk/libf/phylmd/physiq_mod.F90	(revision 4852)
+++ /LMDZ6/trunk/libf/phylmd/physiq_mod.F90	(revision 4853)
@@ -4364,7 +4364,5 @@
                   flag_aerosol, flag_bc_internal_mixture, itap, jD_cur-jD_ref, &
                   pdtphys, pplay, paprs, t_seri, rhcl, presnivs,  &
-                  tr_seri, mass_solu_aero, mass_solu_aero_pi,  &
-                  tau_aero_sw_rrtm, piz_aero_sw_rrtm, cg_aero_sw_rrtm,  &
-                  tausum_aero, drytausum_aero, tau3d_aero)
+                  tr_seri, mass_solu_aero, mass_solu_aero_pi)  
 #else
                 abort_message='You should compile with -rad ecrad if running with iflag_rrtm=2'
Index: /LMDZ6/trunk/libf/phylmd/radlwsw_m.F90
===================================================================
--- /LMDZ6/trunk/libf/phylmd/radlwsw_m.F90	(revision 4852)
+++ /LMDZ6/trunk/libf/phylmd/radlwsw_m.F90	(revision 4853)
@@ -1354,5 +1354,8 @@
       endif
 ! lldebug_for_offline
- 
+
+  if (namelist_ecrad_file.eq.'namelist_ecrad') then 
+      print*,' 1er apell Ecrad : ok_3Deffect, namelist_ecrad_file = ', &
+          ok_3Deffect, namelist_ecrad_file    
       CALL RADIATION_SCHEME &
       & (ist, iend, klon, klev, naero_grp, NSW, &
@@ -1396,4 +1399,50 @@
       & PSFSWDIF, PSFSWDIR, &
       & cloud_cover_sw)
+  else
+   print*,' 2e apell Ecrad : ok_3Deffect, namelist_ecrad_file = ', &
+          ok_3Deffect, namelist_ecrad_file       
+   CALL RADIATION_SCHEME_S2 &
+      & (ist, iend, klon, klev, naero_grp, NSW, &
+      & namelist_ecrad_file, ok_3Deffect, &
+      & debut, ok_volcan, flag_aerosol_strat, &
+      & day_cur, current_time, &
+!       Cste solaire/(d_Terre-Soleil)**2
+      & SOLARIRAD, &
+!       Cos(angle zin), temp sol              
+      & rmu0, tsol, &
+!       Albedo diffuse et directe
+      & PALBD_NEW,PALBP_NEW, &
+!       Emessivite : PEMIS_WINDOW (???), &
+      & ZEMIS, ZEMISW, &
+!       longitude(rad), sin(latitude), PMASQ_ ???
+      & ZGELAM, ZGEMU, &
+!       Temp et pres aux interf, vapeur eau, Satur spec humid 
+      & paprs_i, ZTH_i, q_i, qsat_i, & 
+!       Gas
+       & ZCO2, ZCH4, ZN2O, ZNO2, ZCFC11, ZCFC12, ZHCFC22, &
+       & ZCCL4, POZON_i(:,:,1), ZO2, &
+!       nuages :
+      & cldfra_i, flwc_i, fiwc_i, ZQ_SNOW, &
+!       rayons effectifs des gouttelettes              
+      & ref_liq_i, ref_ice_i, &
+!       aerosols
+     & ZAEROSOL_OLD, ZAEROSOL, &
+! Outputs
+!       Net flux :
+      & ZSWFT_i, ZLWFT_i, ZSWFT0_ii, ZLWFT0_ii, &
+!       DWN flux :
+      & ZFSDWN_i, ZFLUX_i(:,2,:), ZFCDWN_i, ZFLUC_i(:,2,:), &
+!       UP flux :
+      & ZFSUP_i, ZFLUX_i(:,1,:), ZFCUP_i, ZFLUC_i(:,1,:), &
+!       Surf Direct flux : ATTENTION
+      & ZFLUX_DIR, ZFLUX_DIR_CLEAR, ZFLUX_DIR_INTO_SUN, &
+!       UV and para flux
+      & ZFLUX_UV, ZFLUX_PAR, ZFLUX_PAR_CLEAR, &
+!      & ZFLUX_SW_DN_TOA,
+      & ZEMIS_OUT, ZLWDERIVATIVE, &
+      & PSFSWDIF, PSFSWDIR, &
+      & cloud_cover_sw)
+  endif
+
 
       print *,'========= RADLWSW: apres RADIATION_SCHEME ==================== '
