Index: LMDZ6/trunk/libf/phylmd/clesphys.h
===================================================================
--- LMDZ6/trunk/libf/phylmd/clesphys.h	(revision 4675)
+++ LMDZ6/trunk/libf/phylmd/clesphys.h	(revision 4677)
@@ -105,4 +105,8 @@
        INTEGER :: iflag_phytrac
 
+!AI flags pour ECRAD       
+       LOGICAL :: ok_3Deffect
+       CHARACTER(len=512) :: namelist_ecrad_file
+
        COMMON/clesphys/                                                 &
 ! REAL FIRST
@@ -154,5 +158,5 @@
      &     , iflag_phytrac, ok_new_lscp, ok_bs, ok_rad_bs               &
      &     ,  iflag_thermals,nsplit_thermals, tau_thermals              &
-     &     , iflag_physiq
+     &     , iflag_physiq, ok_3Deffect, namelist_ecrad_file
        save /clesphys/
 !$OMP THREADPRIVATE(/clesphys/)
Index: LMDZ6/trunk/libf/phylmd/ecrad/radiation_ecckd.F90
===================================================================
--- LMDZ6/trunk/libf/phylmd/ecrad/radiation_ecckd.F90	(revision 4675)
+++ LMDZ6/trunk/libf/phylmd/ecrad/radiation_ecckd.F90	(revision 4677)
@@ -147,4 +147,5 @@
     this%d_log_pressure = log(pressure_lut(2)) - this%log_pressure1
     call file%get('temperature', temperature_full)
+    if (allocated(this%temperature1)) deallocate(this%temperature1)
     allocate(this%temperature1(this%npress));
     this%temperature1 = temperature_full(:,1)
@@ -179,4 +180,5 @@
     ! 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)
Index: LMDZ6/trunk/libf/phylmd/ecrad/radiation_ecckd_interface.F90
===================================================================
--- LMDZ6/trunk/libf/phylmd/ecrad/radiation_ecckd_interface.F90	(revision 4675)
+++ LMDZ6/trunk/libf/phylmd/ecrad/radiation_ecckd_interface.F90	(revision 4677)
@@ -52,7 +52,10 @@
       end if
 
-      allocate(config%i_band_from_g_sw          (config%n_g_sw))
+      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))
-      allocate(config%i_g_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 (config%do_cloud_aerosol_per_sw_g_point) then
@@ -91,6 +94,9 @@
       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))
 
Index: LMDZ6/trunk/libf/phylmd/ecrad/radiation_general_cloud_optics.F90
===================================================================
--- LMDZ6/trunk/libf/phylmd/ecrad/radiation_general_cloud_optics.F90	(revision 4675)
+++ LMDZ6/trunk/libf/phylmd/ecrad/radiation_general_cloud_optics.F90	(revision 4677)
@@ -75,8 +75,10 @@
     ! 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
Index: LMDZ6/trunk/libf/phylmd/ecrad/radiation_general_cloud_optics_data.F90
===================================================================
--- LMDZ6/trunk/libf/phylmd/ecrad/radiation_general_cloud_optics_data.F90	(revision 4675)
+++ LMDZ6/trunk/libf/phylmd/ecrad/radiation_general_cloud_optics_data.F90	(revision 4677)
@@ -185,5 +185,8 @@
     call delta_eddington(mass_ext, ssa, asymmetry)
 
+
     ! Thin averaging
+   ! AI juillet 2023 
+    allocate(this%mass_ext(nre,nwav))
     this%mass_ext  = matmul(mapping, mass_ext)
     this%ssa       = matmul(mapping, mass_ext*ssa) / this%mass_ext
Index: LMDZ6/trunk/libf/phylmd/ecrad/radiation_scheme.F90
===================================================================
--- LMDZ6/trunk/libf/phylmd/ecrad/radiation_scheme.F90	(revision 4675)
+++ LMDZ6/trunk/libf/phylmd/ecrad/radiation_scheme.F90	(revision 4677)
@@ -9,4 +9,6 @@
 !             3. Configuration a partir de namelist
 !             4. frac_std = 0.75      
+! Juillet 2023 :
+!             
 ! ============================================================================
 
@@ -14,5 +16,5 @@
 ! Inputs
      & (KIDIA, KFDIA, KLON, KLEV, KAEROSOL, NSW, &
-     &  IDAY, TIME, &
+     &  namelist_file, ok_3Deffect, IDAY, TIME, &
      &  PSOLAR_IRRADIANCE, &
      &  PMU0, PTEMPERATURE_SKIN, &
@@ -80,17 +82,13 @@
 USE PARKIND1 , ONLY : JPIM, JPRB
 USE YOMHOOK  , ONLY : LHOOK, DR_HOOK
-! AI ATTENTION module propre a ifs commentes
-!USE YOERAD   , ONLY : YRERAD
-USE RADIATION_SETUP, ONLY : SETUP_RADIATION_SCHEME, rad_config, &
-!USE RADIATION_SETUP, ONLY : &
-     &  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
-! Commentes : jour, date de la simulation 
-!USE YOMRIP0  , ONLY : NINDAT
-!USE YOMCT3   , ONLY : NSTEP
-!USE YOMRIP   , ONLY : YRRIP
+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
@@ -105,5 +103,4 @@
 
 USE mod_phys_lmdz_para
-USE setup_config_from_lmdz,   ONLY : driver_config_type
 
 IMPLICIT NONE
@@ -142,7 +139,4 @@
 !REAL(KIND=JPRB),   INTENT(IN) :: PLAND_SEA_MASK(KLON) 
 
-! *** Variables on full levels
-!REAL(KIND=JPRB),   INTENT(IN) :: PPRESSURE(KLON,KLEV)    ! (Pa)
-!REAL(KIND=JPRB),   INTENT(IN) :: PTEMPERATURE(KLON,KLEV) ! (K)
 ! *** Variables on half levels
 REAL(KIND=JPRB),   INTENT(IN) :: PPRESSURE_H(KLON,KLEV+1)    ! (Pa)
@@ -201,15 +195,4 @@
 REAL(KIND=JPRB),  INTENT(OUT) :: PFLUX_LW_UP_CLEAR(KLON,KLEV+1)
 
-! *** Surface flux components (W m-2)
-! AI ATTENTION
-!REAL(KIND=JPRB),  INTENT(OUT) :: PFLUX_SW_DN_SURF(KLON) 
-!REAL(KIND=JPRB),  INTENT(OUT) :: PFLUX_LW_DN_SURF(KLON) 
-!REAL(KIND=JPRB),  INTENT(OUT) :: PFLUX_SW_DN_CLEAR_SURF(KLON)
-!REAL(KIND=JPRB),  INTENT(OUT) :: PFLUX_LW_DN_CLEAR_SURF(KLON)
-!REAL(KIND=JPRB),  INTENT(OUT) :: PFLUX_SW_UP_SURF(KLON)
-!REAL(KIND=JPRB),  INTENT(OUT) :: PFLUX_LW_UP_SURF(KLON)
-!REAL(KIND=JPRB),  INTENT(OUT) :: PFLUX_SW_UP_CLEAR_SURF(KLON)
-!REAL(KIND=JPRB),  INTENT(OUT) :: PFLUX_LW_UP_CLEAR_SURF(KLON)
-
 ! Direct component of surface flux into horizontal plane
 REAL(KIND=JPRB),  INTENT(OUT) :: PFLUX_DIR(KLON)
@@ -222,12 +205,4 @@
 REAL(KIND=JPRB),  INTENT(OUT) :: PFLUX_PAR(KLON)
 REAL(KIND=JPRB),  INTENT(OUT) :: PFLUX_PAR_CLEAR(KLON)
-
-! *** Other single-level diagnostics
-! Top-of-atmosphere incident solar flux (W m-2)
-! AI ATTENTION
-!REAL(KIND=JPRB),  INTENT(OUT) :: PFLUX_SW_DN_TOA(KLON)
-!REAL(KIND=JPRB),  INTENT(OUT) :: PFLUX_SW_UP_TOA(KLON)
-!REAL(KIND=JPRB),  INTENT(OUT) :: PFLUX_LW_DN_TOA(KLON)
-!REAL(KIND=JPRB),  INTENT(OUT) :: PFLUX_LW_UP_TOA(KLON)
 
 ! Diagnosed longwave surface emissivity across the whole spectrum
@@ -250,5 +225,10 @@
 ! LOCAL VARIABLES
 ! AI ATTENTION
-!type(config_type)         :: rad_config
+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
@@ -272,15 +252,4 @@
 !REAL(KIND=JPRB)           :: ZDECORR_LEN_RATIO = 0.5_jprb
 
-!AI mai 2023
-! A mettre dans namelist
-!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
-
 ! The surface net longwave flux if the surface was a black body, used
 ! to compute the effective broadband surface emissivity
@@ -301,114 +270,117 @@
 INTEGER, PARAMETER :: NAERMACC = 1
 
-! AI ATTENTION
-! A mettre dans namelist
-!real(jprb), parameter    :: frac_std = 0.75
-
 ! Name of file names specified on command line
-character(len=512) :: file_name
+character(len=512) :: namelist_file
 
 logical :: loutput=.true.
 logical :: lprint_input=.false.
-logical :: lprint_config=.false.
+logical :: lprint_config=.true.
 logical, save :: debut_ecrad=.true.
 !$OMP THREADPRIVATE(debut_ecrad)
-
-type(driver_config_type) :: driver_config
-! Import time functions for iseed calculation
-! AI ATTENTION propre a ifs
-!#include "fcttim.func.h"
-!#include "liquid_effective_radius.intfb.h"
-!#include "ice_effective_radius.intfb.h"
-!#include "cloud_overlap_decorr_len.intfb.h"
-!#include "satur.intfb.h"
-
-! Verifier les inputs
-print*,'=============== dans radiation_scheme : ==================='
-if (lprint_input) then
-  print*,'********** Verification des entrees *************'
-  print*,'KIDIA, KFDIA, KLON, KLEV, KAEROSOL, NSW =', &
-        KIDIA, KFDIA, KLON, KLEV, KAEROSOL, NSW
-  print*,'IDAY, TIME =', IDAY, TIME
-  print*,'PSOLAR_IRRADIANCE =', PSOLAR_IRRADIANCE
-  print*,'PMU0 =', PMU0
-  print*,'PTEMPERATURE_SKIN =',PTEMPERATURE_SKIN
-  print*,'PEMIS, PEMIS_WINDOW =', PEMIS, PEMIS_WINDOW
-  print*,'PGELAM, PGEMU =', PGELAM, PGEMU
-  print*,'PPRESSURE_H =', PPRESSURE_H
-  print*,'PTEMPERATURE_H =', PTEMPERATURE_H
-  print*,'PQ =', PQ
-  print*,'PQSAT=',PQSAT
-  print*,'PCO2, PCH4, PN2O, PNO2, PCFC11, PCFC12, PHCFC22, PCCL4 =', &
-        PCO2, PCH4, PN2O, PNO2, PCFC11, PCFC12, PHCFC22, PCCL4
-  print*,'PO3 =',PO3
-  print*,'PCLOUD_FRAC, PQ_LIQUID, PQ_ICE, PQ_SNOW =', &
-        PCLOUD_FRAC, PQ_LIQUID, PQ_ICE, PQ_SNOW
-  print*,'ZRE_LIQUID_UM, ZRE_ICE_UM =', &
-        ZRE_LIQUID_UM, ZRE_ICE_UM
-  print*,'PAEROSOL_OLD, PAEROSOL =', PAEROSOL_OLD, PAEROSOL
+integer, save :: itap_ecrad=1
+logical :: ok_3Deffect
+
+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
-
-IF (LHOOK) CALL DR_HOOK('RADIATION_SCHEME',0,ZHOOK_HANDLE)
-print*,'Entree dans radiation_scheme'
-
-!$OMP MASTER
-if (debut_ecrad) then
-! AI appel radiation_setup
-call SETUP_RADIATION_SCHEME(loutput)
-! Read "radiation_driver" namelist into radiation driver config type
-  file_name="namelist_ecrad"
-call driver_config%read(file_name)
-
-if (rad_config%i_solver_sw == ISolverSPARTACUS &
-      & .or.   rad_config%i_solver_lw == ISolverSPARTACUS) then
-       print*,'Solveur SW: ', rad_config%i_solver_sw
-       print*,'Solveur LW: ', rad_config%i_solver_lw
-   if (driver_config%ok_effective_size) then
-       print*,'low_inv_effective_size = ',driver_config%low_inv_effective_size
-       print*,'middle_inv_effective_size = ',driver_config%middle_inv_effective_size
-       print*,'high_inv_effective_size = ',driver_config%high_inv_effective_size
-   else if (driver_config%ok_separation) then   
-       print*,'cloud_separation_scale_surface =',driver_config%cloud_separation_scale_surface
-       print*,'cloud_separation_scale_toa =',driver_config%cloud_separation_scale_toa
-       print*,'cloud_separation_scale_power =',driver_config%cloud_separation_scale_power
-       print*,'cloud_inhom_separation_factor =',driver_config%cloud_inhom_separation_factor
-   endif   
-endif   
-
- if (lprint_config) then
-  print*,'************* Parametres de configuration  ********************'
-  print*,'rad_config%iverbosesetup = ',rad_config%iverbosesetup 
-  print*,'rad_config%iverbose = ',rad_config%iverbose
-  print*,'rad_config%directory_name =', rad_config%directory_name
-  print*,'rad_config%do_lw_derivatives =',rad_config%do_lw_derivatives
-  print*,'rad_config%do_surface_sw_spectral_flux =', &
-        rad_config%do_surface_sw_spectral_flux
-  print*,'rad_config%do_setup_ifsrrtm =', rad_config%do_setup_ifsrrtm
-  print*,'rad_config%i_liq_model =',rad_config%i_liq_model
-  print*,'rad_config%i_ice_model =',rad_config%i_ice_model
-  print*,'rad_config%i_overlap_scheme =', rad_config%i_overlap_scheme
-  print*,'rad_config%use_aerosols = ', rad_config%use_aerosols
-  print*,'rad_config%n_aerosol_types = ', rad_config%n_aerosol_types
-  print*,'rad_config%i_solver_lw =',rad_config%i_solver_lw
-  print*,'rad_config%i_solver_sw =',rad_config%i_solver_sw
-  print*,'rad_config%do_3d_effects =', rad_config%do_3d_effects
-  print*,'rad_config%do_sw_delta_scaling_with_gases =', &
-       rad_config%do_sw_delta_scaling_with_gases
-  print*,'rad_config%do_lw_aerosol_scattering =', &
-       rad_config%do_lw_aerosol_scattering
-  print*,'rad_config%i_albedo_from_band_sw = ', &
-       rad_config%i_albedo_from_band_sw
-  print*,'n_bands_lw =', rad_config%n_bands_lw
-  print*,'rad_config%i_emiss_from_band_lw =', rad_config%i_emiss_from_band_lw
- endif
- debut_ecrad=.false. 
-endif 
 !$OMP END MASTER
 !$OMP BARRIER 
 ! Fin partie initialisation et configuration 
 
-! AI : allocation des tableaux pour chaque partie (thermo, ...)
-!      passage des champs LMDZ aux structures Ecrad
-!      calculs Ecrad
+!AI juillet 2023 : verif des param de config :
+if (lprint_config) then
+! IF (is_master) THEN       
+   print*,'Parametres de configuration de ecrad, etape ',itap_ecrad     
+   print*,'Entree dans radiation_scheme'
+   print*,'ok_3Deffect = ',ok_3Deffect
+   print*,'Fichier namelist = ',namelist_file
+
+   print*,'do_sw, do_lw, do_sw_direct, do_3d_effects = ', &
+           rad_config%do_sw, rad_config%do_lw, rad_config%do_sw_direct, rad_config%do_3d_effects
+   print*,'do_lw_side_emissivity, do_clear, do_save_radiative_properties = ', &
+           rad_config%do_lw_side_emissivity, rad_config%do_clear, rad_config%do_save_radiative_properties
+!   print*,'sw_entrapment_name, sw_encroachment_name = ', &
+!           rad_config%sw_entrapment_name, rad_config%sw_encroachment_name
+   print*,'do_3d_lw_multilayer_effects, do_fu_lw_ice_optics_bug = ', &
+           rad_config%do_3d_lw_multilayer_effects, rad_config%do_fu_lw_ice_optics_bug
+   print*,'do_save_spectral_flux, do_save_gpoint_flux = ', &
+           rad_config%do_save_spectral_flux, rad_config%do_save_gpoint_flux
+   print*,'do_surface_sw_spectral_flux, do_lw_derivatives = ', &
+           rad_config%do_surface_sw_spectral_flux, rad_config%do_lw_derivatives
+   print*,'do_lw_aerosol_scattering, do_lw_cloud_scattering = ', &
+           rad_config%do_lw_aerosol_scattering, rad_config%do_lw_cloud_scattering
+   print*, 'nregions, i_gas_model = ', &
+           rad_config%nregions, rad_config%i_gas_model 
+!   print*, 'ice_optics_override_file_name, liq_optics_override_file_name = ', &
+!           rad_config%ice_optics_override_file_name, rad_config%liq_optics_override_file_name
+!   print*, 'aerosol_optics_override_file_name, cloud_pdf_override_file_name = ', &
+!           rad_config%aerosol_optics_override_file_name, rad_config%cloud_pdf_override_file_name
+!   print*, 'gas_optics_sw_override_file_name, gas_optics_lw_override_file_name = ', &
+!           rad_config%gas_optics_sw_override_file_name, rad_config%gas_optics_lw_override_file_name
+   print*, 'i_liq_model, i_ice_model, max_3d_transfer_rate = ', &
+           rad_config%i_liq_model, rad_config%i_ice_model, rad_config%max_3d_transfer_rate
+   print*, 'min_cloud_effective_size, overhang_factor = ', &
+           rad_config%min_cloud_effective_size, rad_config%overhang_factor
+   print*, 'use_canopy_full_spectrum_sw, use_canopy_full_spectrum_lw = ', &
+           rad_config%use_canopy_full_spectrum_sw, rad_config%use_canopy_full_spectrum_lw
+   print*, 'do_canopy_fluxes_sw, do_canopy_fluxes_lw = ', &
+           rad_config%do_canopy_fluxes_sw, rad_config%do_canopy_fluxes_lw
+   print*, 'do_canopy_gases_sw, do_canopy_gases_lw = ', &
+           rad_config%do_canopy_gases_sw, rad_config%do_canopy_gases_lw 
+   print*, 'use_general_cloud_optics, use_general_aerosol_optics = ', &
+           rad_config%use_general_cloud_optics, rad_config%use_general_aerosol_optics
+   print*, 'do_sw_delta_scaling_with_gases, i_overlap_scheme = ', &
+           rad_config%do_sw_delta_scaling_with_gases, rad_config%i_overlap_scheme
+   print*, 'i_solver_sw, i_solver_sw, use_beta_overlap, use_vectorizable_generator = ', &
+           rad_config%i_solver_sw, rad_config%i_solver_lw, &
+           rad_config%use_beta_overlap, rad_config%use_vectorizable_generator
+   print*, 'use_expm_everywhere, iverbose, iverbosesetup = ', &
+           rad_config%use_expm_everywhere, rad_config%iverbose, rad_config%iverbosesetup
+   print*, 'cloud_inhom_decorr_scaling, cloud_fraction_threshold = ', &
+           rad_config%cloud_inhom_decorr_scaling, rad_config%cloud_fraction_threshold
+   print*, 'clear_to_thick_fraction, max_gas_od_3d, max_cloud_od = ', &
+           rad_config%clear_to_thick_fraction, rad_config%max_gas_od_3d, rad_config%max_cloud_od
+   print*, 'cloud_mixing_ratio_threshold, overhead_sun_factor =', &
+           rad_config%cloud_mixing_ratio_threshold, rad_config%overhead_sun_factor
+   print*, 'n_aerosol_types, i_aerosol_type_map, use_aerosols = ', &
+           rad_config%n_aerosol_types, rad_config%i_aerosol_type_map, rad_config%use_aerosols
+   print*, 'mono_lw_wavelength, mono_lw_total_od, mono_sw_total_od = ', &
+           rad_config%mono_lw_wavelength, rad_config%mono_lw_total_od,rad_config% mono_sw_total_od
+   print*, 'mono_lw_single_scattering_albedo, mono_sw_single_scattering_albedo = ', &
+           rad_config%mono_lw_single_scattering_albedo, rad_config%mono_sw_single_scattering_albedo
+   print*, 'mono_lw_asymmetry_factor, mono_sw_asymmetry_factor = ', &
+           rad_config%mono_lw_asymmetry_factor, rad_config%mono_sw_asymmetry_factor
+   print*, 'i_cloud_pdf_shape = ', & 
+           rad_config%i_cloud_pdf_shape
+!           cloud_type_name, use_thick_cloud_spectral_averaging = ', &
+!           rad_config%i_cloud_pdf_shape, rad_config%cloud_type_name, &
+!           rad_config%use_thick_cloud_spectral_averaging
+   print*, 'do_nearest_spectral_sw_albedo, do_nearest_spectral_lw_emiss = ', &
+           rad_config%do_nearest_spectral_sw_albedo, rad_config%do_nearest_spectral_lw_emiss
+   print*, 'sw_albedo_wavelength_bound, lw_emiss_wavelength_bound = ', &
+           rad_config%sw_albedo_wavelength_bound, rad_config%lw_emiss_wavelength_bound
+   print*, 'i_sw_albedo_index, i_lw_emiss_index = ', &
+           rad_config%i_sw_albedo_index, rad_config%i_lw_emiss_index
+   print*, 'do_cloud_aerosol_per_lw_g_point = ', &
+           rad_config%do_cloud_aerosol_per_lw_g_point
+   print*, 'do_cloud_aerosol_per_sw_g_point, do_weighted_surface_mapping = ', &
+           rad_config%do_cloud_aerosol_per_sw_g_point, rad_config%do_weighted_surface_mapping
+   print*, 'n_bands_sw, n_bands_lw, n_g_sw, n_g_lw = ', &
+           rad_config%n_bands_sw, rad_config%n_bands_lw, rad_config%n_g_sw, rad_config%n_g_lw
+
+           itap_ecrad=itap_ecrad+1
+!   ENDIF          
+endif           
+
 ! AI ATTENTION
 ! Allocate memory in radiation objects
Index: LMDZ6/trunk/libf/phylmd/ecrad/radiation_setup.F90
===================================================================
--- LMDZ6/trunk/libf/phylmd/ecrad/radiation_setup.F90	(revision 4675)
+++ LMDZ6/trunk/libf/phylmd/ecrad/radiation_setup.F90	(revision 4677)
@@ -2,28 +2,4 @@
 
 ! RADIATION_SETUP - Setting up 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. SETUP_RADIATION_SCHEME in this module sets up a small
-!   number of global variables needed to store the information for it.
-!
-!   Lower case is used for variables and types taken from the
-!   radiation library
-!
-! INTERFACE
-! ---------
-!   SETUP_RADIATION_SCHEME is called from SUECRAD.  The radiation
-!   scheme is actually run using the RADIATION_SCHEME routine (not in
-!   this module).
 !
 ! AUTHOR
@@ -34,4 +10,5 @@
 ! MODIFICATIONS
 ! -------------
+!   Abderrahmane Idelkadi LMD, juillet 2023
 !
 !-----------------------------------------------------------------------
@@ -44,9 +21,9 @@
        &                       IOverlapExponentialRandom
 
+  USE radiation_interface,      ONLY : setup_radiation
+  USE setup_config_from_lmdz,   ONLY : driver_config_type
+
   IMPLICIT NONE
 
-  ! Store configuration information for the radiation scheme in a
-  ! global variable
-  type(config_type) :: rad_config
 
   ! Ultraviolet weightings
@@ -77,28 +54,23 @@
 ! AI At the end of the routine, the parameters are read in namelist
 !    
-  SUBROUTINE SETUP_RADIATION_SCHEME(LOUTPUT)
+  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
-! AI (propre a IFS)    
-!    USE YOMLUN,   ONLY : NULNAM, NULOUT, NULERR
     USE YOMLUN,   ONLY : NULOUT, NULERR
     USE YOESRTWN, ONLY : NMPSRTM
-! AI ATTENTION (propre a IFS)
-!    USE YOERAD,   ONLY : YRERAD
 
-    USE radiation_interface,      ONLY : setup_radiation
-!    USE radiation_aerosol_optics, ONLY : dry_aerosol_sw_mass_extinction
-
-! AI (propre a IFS)    
-!#include "posname.intfb.h"
+ !   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
-
-    ! Verbosity of configuration information 0=none, 1=warning,
-    ! 2=info, 3=progress, 4=detailed, 5=debug
-    INTEGER :: IVERBOSESETUP
-    INTEGER :: ISTAT
 
     REAL(KIND=JPRB) :: ZHOOK_HANDLE
@@ -107,4 +79,9 @@
 
     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)
@@ -116,155 +93,8 @@
     print*,'********** Dans radiation_setup *****************'
 
-    IVERBOSESETUP = 4 ! Provide plenty of information
-    IF (PRESENT(LOUTPUT)) THEN
-      IF (.NOT. LOUTPUT) THEN
-        IVERBOSESETUP = 1 ! Warnings and errors only
-      ENDIF
-    ENDIF
-    rad_config%iverbosesetup = IVERBOSESETUP
-    if (lprint_setp) then
-      print*,'Dans radiation_setup '
-      print*,'rad_config%iverbosesetup =', rad_config%iverbosesetup
-    endif
-
-    IF (IVERBOSESETUP > 1) THEN
-      WRITE(NULOUT,'(a)') '-------------------------------------------------------------------------------'
-      WRITE(NULOUT,'(a)') 'RADIATION_SETUP'
-    ENDIF
-
-    ! Normal operation of the radiation scheme displays only errors
-    ! and warnings
-    rad_config%iverbose = 5
-    if (lprint_setp) then
-      print*,'rad_config%iverbose =', rad_config%iverbose
-    endif
-    ! For the time being, ensure a valid default directory name
-    rad_config%directory_name = 'data'
-    if (lprint_setp) then
-      print*,'rad_config%directory_name =', rad_config%directory_name
-    endif
-
-    ! Do we do Hogan and Bozzo (2014) approximate longwave updates?
-! AI ATTENTION (ifs : )
-     ! AI (propre a IFS)
-!    rad_config%do_lw_derivatives = YRERAD%LAPPROXLWUPDATE
-    rad_config%do_lw_derivatives = .false.
-    if (lprint_setp) then
-      print*,'rad_config%do_lw_derivatives =', rad_config%do_lw_derivatives    
-    endif
-
-    ! Surface spectral fluxes are needed for spectral shortwave albedo
-    ! calculation
-! AI ATTENTION test (ifs : T)
-!    rad_config%do_save_spectral_flux = .FALSE.
-    rad_config%do_surface_sw_spectral_flux = .TRUE.
-    if (lprint_setp) then
-      print*,'rad_config%do_surface_sw_spectral_flux =', &
-            rad_config%do_surface_sw_spectral_flux
-    endif
-
-    ! *** SETUP GAS OPTICS ***
-
-! routine below does not have to (ifs : F)
-    print*,'i_gas_model =',rad_config%i_gas_model
-    rad_config%do_setup_ifsrrtm = .TRUE.
-    if (lprint_setp) then
-      print*,'rad_config%do_setup_ifsrrtm =', rad_config%do_setup_ifsrrtm
-    endif
-
-    ! *** SETUP CLOUD OPTICS ***
-
-    ! Setup liquid optics
-! AI ATTENTION
-! Choix offline : liquid_model_name = "SOCRATES"
-      rad_config%i_liq_model = ILiquidModelSOCRATES
-      if (lprint_setp) then
-        print*,'rad_config%i_liq_model =',rad_config%i_liq_model
-      endif
-
-    ! Setup ice optics
-! Choix offline : ice_model_name    = "Fu-IFS"
-      rad_config%i_ice_model = IIceModelFu
-      if (lprint_setp) then
-        print*,'rad_config%i_ice_model =', rad_config%i_ice_model
-      endif
-
-! AI (propre a IFS)      
-    ! For consistency with earlier versions of the IFS radiation
-    ! scheme, we perform shortwave delta-Eddington scaling *after* the
-    ! merge of the cloud, aerosol and gas optical properties.  Set
-    ! this to "false" to do the scaling on the cloud and aerosol
-    ! properties separately before merging with gases. Note that this
-    ! is not compatible with the SPARTACUS solver.
-    rad_config%do_sw_delta_scaling_with_gases = .FALSE.
-    if (lprint_setp) then
-      print*,'rad_config%do_sw_delta_scaling_with_gases =', &
-            rad_config%do_sw_delta_scaling_with_gases
-    endif
-
-! AI (propre a IFS)    
-    ! Use Exponential-Exponential cloud overlap to match original IFS
-    ! implementation of Raisanen cloud generator
-    rad_config%i_overlap_scheme = IOverlapExponentialRandom
-    if (lprint_setp) then
-      print*,'rad_config%i_overlap_scheme =', rad_config%i_overlap_scheme
-    endif
-
-    ! *** SETUP AEROSOLS ***
-! AI ATTENTION 
-!    rad_config%use_aerosols = .TRUE. !(ifs)
-    rad_config%use_aerosols = .FALSE.
-    if (lprint_setp) then
-      print*,'rad_config%use_aerosols =', rad_config%use_aerosols
-    endif
-
-! *** SETUP SOLVER ***
-
-    ! 3D effects are off by default (ifs)
-    rad_config%do_3d_effects = .TRUE.
-    if (lprint_setp) then
-      print*,'rad_config%do_3d_effects=', rad_config%do_3d_effects
-    endif
-
-    ! Select longwave solver
-! AI ATTENTION
-      rad_config%i_solver_lw = ISolverSpartacus
-      if (lprint_setp) then
-        print*,'rad_config%i_solver_lw =', rad_config%i_solver_lw
-      endif
-
-      rad_config%i_solver_sw = ISolverSpartacus
-      if (lprint_setp) then
-        print*,'rad_config%i_solver_sw =', rad_config%i_solver_sw
-      endif
-
-    ! SPARTACUS solver requires delta scaling to be done separately
-    ! for clouds & aerosols
-    IF (rad_config%i_solver_sw == ISolverSpartacus) THEN
-      rad_config%do_sw_delta_scaling_with_gases = .FALSE.
-    ENDIF
-
-    ! Do we represent longwave scattering?
-    rad_config%do_lw_cloud_scattering = .TRUE.
-    rad_config%do_lw_aerosol_scattering = .TRUE.
-    if (lprint_setp) then
-      print*,'rad_config%do_lw_cloud_scattering =', &
-           rad_config%do_lw_cloud_scattering
-      print*,'rad_config%do_lw_aerosol_scattering =', &
-           rad_config%do_lw_aerosol_scattering
-    endif
-
-    ! *** IMPLEMENT SETTINGS ***
-
-    ! For advanced configuration, the configuration data for the
-    ! "radiation" project can specified directly in the namelist.
-    ! However, the variable naming convention is not consistent with
-    ! the rest of the IFS.  For basic configuration there are specific
-    ! variables in the NAERAD namelist available in the YRERAD
-    ! structure.
-
 ! AI ATTENTION (parameters read in namelist file)
-    file_name="namelist_ecrad"
+!    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
@@ -313,24 +143,4 @@
    rad_config%aerosol_optics_override_file_name = 'aerosol_optics_lmdz.nc'
 
-!    IF (YRERAD%NAERMACC > 0) THEN
-      ! With the MACC aerosol climatology we need to add in the
-      ! background aerosol afterwards using the Tegen arrays.  In this
-      ! case we first configure the background aerosol mass-extinction
-      ! coefficient at 550 nm, which corresponds to the 10th RRTMG
-      ! shortwave band.
-!      TROP_BG_AER_MASS_EXT  = dry_aerosol_sw_mass_extinction(rad_config, &
-!           &                                   ITYPE_TROP_BG_AER, 10)
-!      STRAT_BG_AER_MASS_EXT = dry_aerosol_sw_mass_extinction(rad_config, &
-!           &                                   ITYPE_STRAT_BG_AER, 10)
-      
-!      WRITE(NULOUT,'(a,i0)') 'Tropospheric bacground uses aerosol type ', &
-!           &                 ITYPE_TROP_BG_AER
-!      WRITE(NULOUT,'(a,i0)') 'Stratospheric bacground uses aerosol type ', &
-!           &                 ITYPE_STRAT_BG_AER
-!    ENDIF     
-      
-    IF (IVERBOSESETUP > 1) THEN
-      WRITE(NULOUT,'(a)') '-------------------------------------------------------------------------------'
-    ENDIF
 
     IF (LHOOK) CALL DR_HOOK('RADIATION_SETUP:SETUP_RADIATION_SCHEME',1,ZHOOK_HANDLE)
Index: LMDZ6/trunk/libf/phylmd/phys_local_var_mod.F90
===================================================================
--- LMDZ6/trunk/libf/phylmd/phys_local_var_mod.F90	(revision 4675)
+++ LMDZ6/trunk/libf/phylmd/phys_local_var_mod.F90	(revision 4677)
@@ -272,4 +272,25 @@
 !$OMP THREADPRIVATE(toplwad0_aerop, sollwad0_aerop)
 
+!AI 08 2023 ajout pour Ecrad
+      REAL,ALLOCATABLE,SAVE :: topswad_aero_s2(:), solswad_aero_s2(:)
+!$OMP THREADPRIVATE(topswad_aero_s2, solswad_aero_s2)
+      REAL,ALLOCATABLE,SAVE :: topswai_aero_s2(:), solswai_aero_s2(:)
+!$OMP THREADPRIVATE(topswai_aero_s2, solswai_aero_s2)
+      REAL,ALLOCATABLE,SAVE :: topswad0_aero_s2(:), solswad0_aero_s2(:)
+!$OMP THREADPRIVATE(topswad0_aero_s2, solswad0_aero_s2)
+      REAL,ALLOCATABLE,SAVE :: topsw_aero_s2(:,:), topsw0_aero_s2(:,:)
+!$OMP THREADPRIVATE(topsw_aero_s2, topsw0_aero_s2)
+      REAL,ALLOCATABLE,SAVE :: solsw_aero_s2(:,:), solsw0_aero_s2(:,:)
+!$OMP THREADPRIVATE(solsw_aero_s2, solsw0_aero_s2)
+      REAL,ALLOCATABLE,SAVE :: topswcf_aero_s2(:,:), solswcf_aero_s2(:,:)
+!$OMP THREADPRIVATE(topswcf_aero_s2, solswcf_aero_s2)
+! additional LW variables CK
+      REAL,ALLOCATABLE,SAVE :: toplwad_aero_s2(:), sollwad_aero_s2(:)
+!$OMP THREADPRIVATE(toplwad_aero_s2, sollwad_aero_s2)
+      REAL,ALLOCATABLE,SAVE :: toplwai_aero_s2(:), sollwai_aero_s2(:)
+!$OMP THREADPRIVATE(toplwai_aero_s2, sollwai_aero_s2)
+      REAL,ALLOCATABLE,SAVE :: toplwad0_aero_s2(:), sollwad0_aero_s2(:)
+!$OMP THREADPRIVATE(toplwad0_aero_s2, sollwad0_aero_s2)
+
 !Ajout de celles n??cessaires au phys_output_write_mod
       REAL, SAVE, ALLOCATABLE :: tal1(:), pal1(:), pab1(:), pab2(:)
@@ -538,5 +559,5 @@
       !$OMP THREADPRIVATE(distcltop)
       REAL, SAVE, ALLOCATABLE :: temp_cltop(:,:)
-      !$OMP THREADPRIVATE(temp_cltop)      
+      !$OMP THREADPRIVATE(temp_cltop)
 
 
@@ -617,8 +638,4 @@
       REAL, ALLOCATABLE, SAVE, DIMENSION(:) :: budg_sed_part
 !$OMP THREADPRIVATE(budg_sed_part)
-#endif
-#ifdef REPROBUS
-      REAL,SAVE,ALLOCATABLE    :: d_q_emiss(:,:)
-!$OMP THREADPRIVATE(d_q_emiss)
 #endif
 
@@ -774,4 +791,17 @@
       ALLOCATE(toplwad0_aerop(klon), sollwad0_aerop(klon))
 
+!AI Ajout Ecrad (3Deffect)
+      ALLOCATE(topswad_aero_s2(klon), solswad_aero_s2(klon))
+      ALLOCATE(topswai_aero_s2(klon), solswai_aero_s2(klon))
+      ALLOCATE(topswad0_aero_s2(klon), solswad0_aero_s2(klon))
+      ALLOCATE(topsw_aero_s2(klon,naero_grp), topsw0_aero_s2(klon,naero_grp))
+      ALLOCATE(solsw_aero_s2(klon,naero_grp), solsw0_aero_s2(klon,naero_grp))
+      ALLOCATE(topswcf_aero_s2(klon,naero_grp), solswcf_aero_s2(klon,naero_grp))
+! additional LW variables CK
+      ALLOCATE(toplwad_aero_s2(klon), sollwad_aero_s2(klon))
+      ALLOCATE(toplwai_aero_s2(klon), sollwai_aero_s2(klon))
+      ALLOCATE(toplwad0_aero_s2(klon), sollwad0_aero_s2(klon))
+
+
 ! FH Ajout de celles necessaires au phys_output_write_mod
 
@@ -911,4 +941,5 @@
       ALLOCATE(distcltop(klon,klev))
       ALLOCATE(temp_cltop(klon,klev))
+
 
       ALLOCATE (zxsnow(klon),snowhgt(klon),qsnow(klon),to_ice(klon))
@@ -1104,4 +1135,16 @@
       DEALLOCATE(toplwad0_aerop, sollwad0_aerop)
 
+!AI Ajout pour Ecrad (3Deffect)
+      DEALLOCATE(topswad_aero_s2, solswad_aero_s2)
+      DEALLOCATE(topswai_aero_s2, solswai_aero_s2)
+      DEALLOCATE(topswad0_aero_s2, solswad0_aero_s2)
+      DEALLOCATE(topsw_aero_s2, topsw0_aero_s2)
+      DEALLOCATE(solsw_aero_s2, solsw0_aero_s2)
+      DEALLOCATE(topswcf_aero_s2, solswcf_aero_s2)
+!CK LW diagnostics
+      DEALLOCATE(toplwad_aero_s2, sollwad_aero_s2)
+      DEALLOCATE(toplwai_aero_s2, sollwai_aero_s2)
+      DEALLOCATE(toplwad0_aero_s2, sollwad0_aero_s2)      
+
 ! FH Ajout de celles necessaires au phys_output_write_mod
       DEALLOCATE(tal1, pal1, pab1, pab2)
Index: LMDZ6/trunk/libf/phylmd/phys_output_ctrlout_mod.F90
===================================================================
--- LMDZ6/trunk/libf/phylmd/phys_output_ctrlout_mod.F90	(revision 4675)
+++ LMDZ6/trunk/libf/phylmd/phys_output_ctrlout_mod.F90	(revision 4677)
@@ -536,4 +536,79 @@
   TYPE(ctrl_out), SAVE :: o_tauy = ctrl_out((/ 1, 10, 10, 10, 10, 10, 11, 11, 11, 11/), &
     'tauy', 'Meridional wind stress', 'Pa', (/ ('', i=1, 10) /))
+
+!AI Ecrad 3Deffect
+#ifdef CPP_ECRAD
+  TYPE(ctrl_out), SAVE :: o_sols_s2 = ctrl_out((/ 11, 11, 10, 10, 10, 10, 11, 11, 11, 11/), &
+    'sols_s2', 'Solar rad. at surf.', 'W/m2', (/ ('', i=1, 10) /))
+  TYPE(ctrl_out), SAVE :: o_sols0_s2 = ctrl_out((/ 11, 11, 10, 10, 10, 10, 11, 11, 11, 11/), &
+    'sols0_s2', 'Solar rad. at surf.', 'W/m2', (/ ('', i=1, 10) /))
+  TYPE(ctrl_out), SAVE :: o_soll_s2 = ctrl_out((/ 11, 11, 10, 10, 10, 10, 11, 11, 11, 11/), &
+    'soll_s2', 'IR rad. at surface', 'W/m2', (/ ('', i=1, 10) /))
+  TYPE(ctrl_out), SAVE :: o_soll0_s2 = ctrl_out((/ 11, 11, 10, 10, 10, 10, 11, 11, 11, 11/), &
+    'soll0_s2', 'IR rad. at surface', 'W/m2', (/ ('', i=1, 10) /))
+  TYPE(ctrl_out), SAVE :: o_tops_s2 = ctrl_out((/ 11, 11, 10, 10, 10, 10, 11, 11, 11, 11/), &
+    'tops_s2', 'Solar rad. at TOA', 'W/m2', (/ ('', i=1, 10) /))
+  TYPE(ctrl_out), SAVE :: o_tops0_s2 = ctrl_out((/ 11, 11, 10, 10, 10, 10, 11, 11, 11, 11/), &
+    'tops0_s2', 'CS Solar rad. at TOA', 'W/m2', (/ ('', i=1, 10) /))
+  TYPE(ctrl_out), SAVE :: o_topl_s2 = ctrl_out((/ 11, 11, 10, 11, 10, 10, 11, 11, 11, 11/), &
+    'topl_s2', 'IR rad. at TOA', 'W/m2', (/ ('', i=1, 10) /))
+  TYPE(ctrl_out), SAVE :: o_topl0_s2 = ctrl_out((/ 11, 11, 10, 10, 10, 10, 11, 11, 11, 11/), &
+    'topl0_s2', 'IR rad. at TOA', 'W/m2', (/ ('', i=1, 10) /))
+  TYPE(ctrl_out), SAVE :: o_SWupTOA_s2 = ctrl_out((/ 11, 11, 10, 10, 10, 10, 11, 11, 11, 11/), &
+    'SWupTOA_s2', 'SWup at TOA', 'W/m2', (/ ('', i=1, 10) /))
+  TYPE(ctrl_out), SAVE :: o_SWupTOAclr_s2 = ctrl_out((/ 11, 11, 10, 10, 10, 10, 11, 11, 11, 11/), &
+    'SWupTOAclr_s2', 'SWup clear sky at TOA', 'W/m2', (/ ('', i=1, 10) /))
+  TYPE(ctrl_out), SAVE :: o_SWupTOAcleanclr_s2 = ctrl_out((/ 11, 11, 11, 11, 11, 11, 11, 11, 11, 11/), &
+    'SWupTOAcleanclr_s2', 'SWup clear sky clean (no aerosol) at TOA', 'W/m2', (/ ('', i=1, 10) /))
+  TYPE(ctrl_out), SAVE :: o_SWdnTOA_s2 = ctrl_out((/ 11, 11, 10, 10, 10, 10, 11, 11, 11, 11/), &
+    'SWdnTOA_s2', 'SWdn at TOA', 'W/m2', (/ ('', i=1, 10) /))
+  TYPE(ctrl_out), SAVE :: o_SWdnTOAclr_s2 = ctrl_out((/ 11, 11, 10, 10, 10, 10, 11, 11, 11, 11/), &
+    'SWdnTOAclr_s2', 'SWdn clear sky at TOA', 'W/m2', (/ ('', i=1, 10) /))
+  TYPE(ctrl_out), SAVE :: o_nettop_s2 = ctrl_out((/ 11, 11, 10, 10, 10, 10, 11, 11, 11, 11/), &
+    'nettop_s2', 'Net dn radiatif flux at TOA', 'W/m2', (/ ('', i=1, 10) /))
+  TYPE(ctrl_out), SAVE :: o_LWdnSFC_s2 = ctrl_out((/ 11, 11, 10, 10, 11, 10, 11, 11, 11, 11/), &
+    'LWdnSFC_s2', 'Down. IR rad. at surface', 'W/m2', (/ ('', i=1, 10) /))
+  TYPE(ctrl_out), SAVE :: o_LWdnSFCclr_s2 = ctrl_out((/ 11, 11, 10, 10, 11, 10, 11, 11, 11, 11/), &
+    'LWdnSFCclr_s2', 'Down. CS IR rad. at surface', 'W/m2', (/ ('', i=1, 10) /))
+  TYPE(ctrl_out), SAVE :: o_SWupSFC_s2 = ctrl_out((/ 11, 11, 10, 10, 11, 10, 11, 11, 11, 11/), &
+    'SWupSFC_s2', 'SWup at surface', 'W/m2', (/ ('', i=1, 10) /))
+  TYPE(ctrl_out), SAVE :: o_SWupSFCclr_s2 = ctrl_out((/ 11, 11, 10, 10, 11, 10, 11, 11, 11, 11/), &
+    'SWupSFCclr_s2', 'SWup clear sky at surface', 'W/m2', (/ ('', i=1, 10) /))
+  TYPE(ctrl_out), SAVE :: o_SWupSFCcleanclr_s2 = ctrl_out((/ 11, 11, 11, 11, 11, 11, 11, 11, 11, 11/), &
+    'SWupSFCcleanclr_s2', 'SWup clear sky clean (no aerosol) at surface', 'W/m2', (/ ('', i=1, 10) /))
+  TYPE(ctrl_out), SAVE :: o_fdiffSWdnSFC_s2 = ctrl_out((/ 11, 11, 11, 11, 11, 11, 11, 11, 11, 11/), &
+    'fdiffSWdnSFC_s2', 'Fraction of diffuse SWdn at surface', 'W/m2', (/ ('', i=1, 10) /))
+  TYPE(ctrl_out), SAVE :: o_SWdnSFC_s2 = ctrl_out((/ 11, 11, 11, 10, 11, 10, 11, 11, 11, 11/), &
+    'SWdnSFC_s2', 'SWdn at surface', 'W/m2', (/ ('', i=1, 10) /))
+  TYPE(ctrl_out), SAVE :: o_SWdnSFCclr_s2 = ctrl_out((/ 11, 11, 10, 10, 11, 10, 11, 11, 11, 11/), &
+    'SWdnSFCclr_s2', 'SWdn clear sky at surface', 'W/m2', (/ ('', i=1, 10) /))
+  TYPE(ctrl_out), SAVE :: o_SWdnSFCcleanclr_s2 = ctrl_out((/ 11, 11, 11, 11, 11, 11, 11, 11, 11, 11/), &
+    'SWdnSFCcleanclr_s2', 'SWdn clear sky clean (no aerosol) at surface', 'W/m2', (/ ('', i=1, 10) /))
+  TYPE(ctrl_out), SAVE :: o_LWupSFC_s2 = ctrl_out((/ 11, 11, 10, 10, 11, 10, 11, 11, 11, 11/), &
+    'LWupSFC_s2', 'Upwd. IR rad. at surface', 'W/m2', (/ ('', i=1, 10) /))
+  TYPE(ctrl_out), SAVE :: o_LWupSFCclr_s2 = ctrl_out((/ 11, 11, 10, 10, 10, 10, 11, 11, 11, 11/), &
+    'LWupSFCclr_s2', 'CS Upwd. IR rad. at surface', 'W/m2', (/ ('', i=1, 10) /))
+  TYPE(ctrl_out), SAVE :: o_LWupTOAcleanclr_s2 = ctrl_out((/ 11, 11, 11, 11, 11, 11, 11, 11, 11, 11/), &
+    'LWupTOAcleanclr_s2', 'Upward CS clean (no aerosol) IR rad. at TOA', 'W/m2', (/ ('', i=1, 10) /))
+  TYPE(ctrl_out), SAVE :: o_LWdnSFCcleanclr_s2 = ctrl_out((/ 11, 11, 11, 11, 11, 11, 11, 11, 11, 11/), &
+    'LWdnSFCcleanclr_s2', 'Downward CS clean (no aerosol) IR rad. at surface', 'W/m2', (/ ('', i=1, 10) /))
+  TYPE(ctrl_out), SAVE :: o_rsu_s2 = ctrl_out((/ 11, 10, 10, 10, 10, 10, 11, 11, 11, 11/), &
+    'rsu_s2', 'SW upward radiation', 'W m-2', (/ ('', i=1, 10) /))
+  TYPE(ctrl_out), SAVE :: o_rsd_s2 = ctrl_out((/ 11, 10, 10, 10, 10, 10, 11, 11, 11, 11/), &
+    'rsd_s2', 'SW downward radiation', 'W m-2', (/ ('', i=1, 10) /))
+  TYPE(ctrl_out), SAVE :: o_rlu_s2 = ctrl_out((/ 11, 11, 11, 11, 11, 11, 11, 11, 11, 11/), &
+    'rlu_s2', 'LW upward radiation', 'W m-2', (/ ('', i=1, 10) /))
+  TYPE(ctrl_out), SAVE :: o_rld_s2 = ctrl_out((/ 11, 11, 11, 11, 11, 11, 11, 11, 11, 11/), &
+    'rld_s2', 'LW downward radiation', 'W m-2', (/ ('', i=1, 10) /))
+  TYPE(ctrl_out), SAVE :: o_rsucs_s2 = ctrl_out((/ 11, 11, 11, 11, 11, 11, 11, 11, 11, 11/), &
+    'rsucs_s2', 'SW CS upward radiation', 'W m-2', (/ ('', i=1, 10) /))
+  TYPE(ctrl_out), SAVE :: o_rsdcs_s2 = ctrl_out((/ 11, 11, 11, 11, 11, 11, 11, 11, 11, 11/), &
+    'rsdcs_s2', 'SW CS downward radiation', 'W m-2', (/ ('', i=1, 10) /))
+  TYPE(ctrl_out), SAVE :: o_rlucs_s2 = ctrl_out((/ 11, 11, 11, 11, 11, 11, 11, 11, 11, 11/), &
+    'rlucs_s2', 'LW CS upward radiation', 'W m-2', (/ ('', i=1, 10) /))
+  TYPE(ctrl_out), SAVE :: o_rldcs_s2 = ctrl_out((/ 11, 11, 11, 11, 11, 11, 11, 11, 11, 11/), &
+    'rldcs_s2', 'LW CS downward radiation', 'W m-2', (/ ('', i=1, 10) /))
+#endif
+
 
   TYPE(ctrl_out), SAVE, DIMENSION(4) :: o_taux_srf = (/           &
Index: LMDZ6/trunk/libf/phylmd/phys_output_write_mod.F90
===================================================================
--- LMDZ6/trunk/libf/phylmd/phys_output_write_mod.F90	(revision 4675)
+++ LMDZ6/trunk/libf/phylmd/phys_output_write_mod.F90	(revision 4677)
@@ -228,4 +228,10 @@
          o_zxfluxt,o_zxfluxq
 
+#ifdef CPP_ECRAD
+    USE phys_output_ctrlout_mod, ONLY:  &
+         o_soll0_s2,o_soll_s2,o_sols0_s2,o_sols_s2, &
+         o_topl0_s2,o_topl_s2,o_tops0_s2,o_tops_s2   
+#endif
+
 #ifdef CPP_StratAer
     USE phys_output_ctrlout_mod, ONLY:  & 
@@ -279,4 +285,12 @@
 #endif
          dt_ns, delta_sst, dter, dser
+         
+! AI 08 2023 pour ECRAD 3Deffect
+#ifdef CPP_ECRAD
+    USE phys_state_var_mod, ONLY: &
+        sollw0_s2,sollw_s2,solsw0_s2,solsw_s2, &
+        toplw0_s2,toplw_s2,topsw0_s2,topsw_s2
+#endif
+
 
     USE phys_local_var_mod, ONLY: zxfluxlat, slp, ptstar, pt0, zxtsol, zt2m, &
@@ -1051,4 +1065,32 @@
        ENDIF
 
+!AI 08 2023 Ecrad 3Deffect
+#ifdef CPP_ECRAD
+     if (ok_3Deffect) then
+        IF (vars_defined) THEN
+          zx_tmp_fi2d = solsw_s2*swradcorr
+       ENDIF
+       CALL histwrite_phy(o_sols_s2, zx_tmp_fi2d)
+       IF (vars_defined) THEN
+          zx_tmp_fi2d = solsw0_s2*swradcorr
+       ENDIF
+       CALL histwrite_phy(o_sols0_s2, zx_tmp_fi2d)
+       CALL histwrite_phy(o_soll_s2, sollw_s2)
+       CALL histwrite_phy(o_soll0_s2, sollw0_s2)
+       IF (vars_defined) THEN
+         zx_tmp_fi2d = topsw_s2*swradcorr
+       ENDIF
+       CALL histwrite_phy(o_tops_s2, zx_tmp_fi2d)
+
+       IF (vars_defined) THEN
+         zx_tmp_fi2d = topsw0_s2*swradcorr
+       ENDIF
+       CALL histwrite_phy(o_tops0_s2, zx_tmp_fi2d)
+
+       CALL histwrite_phy(o_topl_s2, toplw_s2)
+       CALL histwrite_phy(o_topl0_s2, toplw0_s2)
+     endif
+#endif       
+
        CALL histwrite_phy(o_bils, bils)
        CALL histwrite_phy(o_bils_diss, bils_diss)
Index: LMDZ6/trunk/libf/phylmd/phys_state_var_mod.F90
===================================================================
--- LMDZ6/trunk/libf/phylmd/phys_state_var_mod.F90	(revision 4675)
+++ LMDZ6/trunk/libf/phylmd/phys_state_var_mod.F90	(revision 4677)
@@ -399,4 +399,27 @@
 !$OMP THREADPRIVATE(swdnc0p, swdn0p, swdnp, swupc0p, swup0p, swupp)
 
+!AI ajout variables double appel Ecrad (3Deffect)
+      REAL,ALLOCATABLE,SAVE :: heat_s2(:,:), cool_s2(:,:)
+!$OMP THREADPRIVATE(heat_s2, cool_s2)
+      REAL,ALLOCATABLE,SAVE :: heat0_s2(:,:), cool0_s2(:,:)
+!$OMP THREADPRIVATE(heat0_s2, cool0_s2)
+      REAL,ALLOCATABLE,SAVE :: radsol_s2(:), topsw_s2(:), toplw_s2(:)
+!$OMP THREADPRIVATE(radsol_s2, topsw_s2, toplw_s2)
+      REAL,ALLOCATABLE,SAVE :: albpla_s2(:)
+!$OMP THREADPRIVATE(albpla_s2)
+      REAL,ALLOCATABLE,SAVE :: solsw_s2(:), solswfdiff_s2(:), sollw_s2(:)
+!$OMP THREADPRIVATE(solsw_s2, solswfdiff_s2, sollw_s2)
+      REAL,ALLOCATABLE,SAVE :: sollwdown_s2(:)
+!$OMP THREADPRIVATE(sollwdown_s2)
+      REAL,ALLOCATABLE,SAVE :: topsw0_s2(:),toplw0_s2(:)
+      REAL,ALLOCATABLE,SAVE :: solsw0_s2(:),sollw0_s2(:)
+!$OMP THREADPRIVATE(topsw0_s2,toplw0_s2,solsw0_s2,sollw0_s2)
+      REAL,ALLOCATABLE,SAVE :: lwdnc0_s2(:,:), lwdn0_s2(:,:), lwdn_s2(:,:)
+      REAL,ALLOCATABLE,SAVE :: lwupc0_s2(:,:), lwup0_s2(:,:), lwup_s2(:,:)
+!$OMP THREADPRIVATE(lwdnc0_s2,lwdn0_s2,lwdn_s2,lwupc0_s2,lwup0_s2,lwup_s2)       
+      REAL,ALLOCATABLE,SAVE :: swdnc0_s2(:,:), swdn0_s2(:,:), swdn_s2(:,:)
+      REAL,ALLOCATABLE,SAVE :: swupc0_s2(:,:), swup0_s2(:,:), swup_s2(:,:)
+!$OMP THREADPRIVATE(swdnc0_s2, swdn0_s2, swdn_s2, swupc0_s2, swup0_s2, swup_s2)
+
 ! pbase : cloud base pressure
 ! bbase : cloud base buoyancy
@@ -697,4 +720,18 @@
       ALLOCATE(swdnc0p(klon,klevp1), swdn0p(klon,klevp1), swdnp(klon,klevp1))
       ALLOCATE(swupc0p(klon,klevp1), swup0p(klon,klevp1), swupp(klon,klevp1))
+
+!AI Ajout pour Ecrad (3Deffect)       
+      ALLOCATE(heat_s2(klon,klev), cool_s2(klon,klev))
+      ALLOCATE(heat0_s2(klon,klev), cool0_s2(klon,klev))
+      ALLOCATE(radsol_s2(klon), topsw_s2(klon), toplw_s2(klon))
+      ALLOCATE(albpla_s2(klon))
+      ALLOCATE(solsw_s2(klon), solswfdiff_s2(klon), sollw_s2(klon))
+      ALLOCATE(sollwdown_s2(klon))
+      ALLOCATE(topsw0_s2(klon),toplw0_s2(klon))
+      ALLOCATE(solsw0_s2(klon),sollw0_s2(klon))
+      ALLOCATE(lwdnc0_s2(klon,klevp1), lwdn0_s2(klon,klevp1), lwdn_s2(klon,klevp1))
+      ALLOCATE(lwupc0_s2(klon,klevp1), lwup0_s2(klon,klevp1), lwup_s2(klon,klevp1))
+      ALLOCATE(swdnc0_s2(klon,klevp1), swdn0_s2(klon,klevp1), swdn_s2(klon,klevp1))
+      ALLOCATE(swupc0_s2(klon,klevp1), swup0_s2(klon,klevp1), swup_s2(klon,klevp1))
 
       ALLOCATE(cape(klon))
@@ -856,4 +893,19 @@
       DEALLOCATE(topsw0,toplw0,solsw0,sollw0)
       DEALLOCATE(albpla)
+
+!AI Ajout pour Ecrad (3Deffect)
+      DEALLOCATE(heat_s2, cool_s2)
+      DEALLOCATE(heat0_s2, cool0_s2)
+      DEALLOCATE(radsol_s2, topsw_s2, toplw_s2)
+      DEALLOCATE(albpla_s2)
+      DEALLOCATE(solsw_s2, solswfdiff_s2, sollw_s2)
+      DEALLOCATE(sollwdown_s2)
+      DEALLOCATE(topsw0_s2,toplw0_s2)
+      DEALLOCATE(solsw0_s2,sollw0_s2)
+      DEALLOCATE(lwdnc0_s2, lwdn0_s2, lwdn_s2)
+      DEALLOCATE(lwupc0_s2, lwup0_s2, lwup_s2)
+      DEALLOCATE(swdnc0_s2, swdn0_s2, swdn_s2)
+      DEALLOCATE(swupc0_s2, swup0_s2, swup_s2)
+
 !IM ajout variables CFMIP2/CMIP5
       DEALLOCATE(heatp, coolp)
Index: LMDZ6/trunk/libf/phylmd/physiq_mod.F90
===================================================================
--- LMDZ6/trunk/libf/phylmd/physiq_mod.F90	(revision 4675)
+++ LMDZ6/trunk/libf/phylmd/physiq_mod.F90	(revision 4677)
@@ -203,4 +203,15 @@
        toplwai_aero,sollwai_aero,   &
        toplwad0_aero,sollwad0_aero, &
+       !pour Ecrad
+       topswad_aero_s2, solswad_aero_s2,   &
+       topswai_aero_s2, solswai_aero_s2,   &
+       topswad0_aero_s2, solswad0_aero_s2, &
+       topsw_aero_s2, topsw0_aero_s2,      &
+       solsw_aero_s2, solsw0_aero_s2,      &
+       topswcf_aero_s2, solswcf_aero_s2,   &
+       !LW diagnostics
+       toplwad_aero_s2, sollwad_aero_s2,   &
+       toplwai_aero_s2, sollwai_aero_s2,   &
+       toplwad0_aero_s2, sollwad0_aero_s2, &
        !
        topsw_aero,solsw_aero,       &
@@ -221,4 +232,15 @@
        toplwai_aerop, sollwai_aerop,   &
        toplwad0_aerop, sollwad0_aerop, &
+       !pour Ecrad
+       topswad_aero_s2, solswad_aero_s2,   &
+       topswai_aero_s2, solswai_aero_s2,   &
+       topswad0_aero_s2, solswad0_aero_s2, &
+       topsw_aero_s2, topsw0_aero_s2,      &
+       solsw_aero_s2, solsw0_aero_s2,      &
+       topswcf_aero_s2, solswcf_aero_s2,   &
+       !LW diagnostics
+       toplwad_aero_s2, sollwad_aero_s2,   &
+       toplwai_aero_s2, sollwai_aero_s2,   &
+       toplwad0_aero_s2, sollwad0_aero_s2, &
        !
        ptstar, pt0, slp, &
@@ -1497,4 +1519,11 @@
        WRITE(lunout,*) 'Call to infocfields from physiq'
        CALL infocfields_init
+
+       !AI 08 2023
+#ifdef CPP_ECRAD
+       ok_3Deffect=.false.
+       CALL getin_p('ok_3Deffect',ok_3Deffect)
+       namelist_ecrad_file='namelist_ecrad'
+#endif
 
     ENDIF
@@ -4581,4 +4610,51 @@
                      ZSWFT0_i, ZFSDN0, ZFSUP0)
           ENDIF !ok_4xCO2atm
+
+! A.I aout 2023
+! Effet 3D des nuages Ecrad
+! a passer : nom du ficher namelist et cles ok_3Deffect
+! a declarer comme iflag_rrtm et a lire dans physiq.def
+#ifdef CPP_ECRAD
+          IF (ok_3Deffect) then
+!                print*,'ok_3Deffect = ',ok_3Deffect  
+                namelist_ecrad_file='namelist_ecrad_s2'
+                CALL radlwsw &
+                     (dist, rmu0, fract,  &
+                     paprs, pplay,zxtsol,SFRWL,albsol_dir, albsol_dif, &
+                     t_seri,q_seri,wo, &
+                     cldfrarad, cldemirad, cldtaurad, &
+                     ok_ade.OR.flag_aerosol_strat.GT.0, ok_aie,  ok_volcan, flag_volc_surfstrat, &
+                     flag_aerosol, flag_aerosol_strat, flag_aer_feedback, &
+                     tau_aero, piz_aero, cg_aero, &
+                     tau_aero_sw_rrtm, piz_aero_sw_rrtm, cg_aero_sw_rrtm, &
+                     tau_aero_lw_rrtm, &
+                     cldtaupi, &
+                     zqsat, flwc, fiwc, &
+                     ref_liq, ref_ice, ref_liq_pi, ref_ice_pi, &
+! A modifier              
+                     heat_s2,heat0_s2,cool_s2,cool0_s2,albpla_s2, &
+                     heat_volc,cool_volc, &
+                     topsw_s2,toplw_s2,solsw_s2,solswfdiff_s2,sollw_s2, &
+                     sollwdown_s2, &
+                     topsw0_s2,toplw0_s2,solsw0_s2,sollw0_s2, &
+                     lwdnc0_s2, lwdn0_s2, lwdn_s2, lwupc0_s2, lwup0_s2, lwup_s2,  &
+                     swdnc0_s2, swdn0_s2, swdn_s2, swupc0_s2, swup0_s2, swup_s2, &
+                     topswad_aero_s2, solswad_aero_s2, &
+                     topswai_aero_s2, solswai_aero_s2, &
+                     topswad0_aero_s2, solswad0_aero_s2, &
+                     topsw_aero_s2, topsw0_aero_s2, &
+                     solsw_aero_s2, solsw0_aero_s2, &
+                     topswcf_aero_s2, solswcf_aero_s2, &
+                                !-C. Kleinschmitt for LW diagnostics
+                     toplwad_aero_s2, sollwad_aero_s2,&
+                     toplwai_aero_s2, sollwai_aero_s2, &
+                     toplwad0_aero_s2, sollwad0_aero_s2,&
+                                !-end
+                     ZLWFT0_i, ZFLDN0, ZFLUP0, &
+                     ZSWFT0_i, ZFSDN0, ZFSUP0)
+             namelist_ecrad_file='namelist_ecrad'
+          ENDIF ! ok_3Deffect
+#endif
+
        ENDIF ! aerosol_couple
        itaprad = 0
Index: LMDZ6/trunk/libf/phylmd/radlwsw_m.F90
===================================================================
--- LMDZ6/trunk/libf/phylmd/radlwsw_m.F90	(revision 4675)
+++ LMDZ6/trunk/libf/phylmd/radlwsw_m.F90	(revision 4677)
@@ -1348,4 +1348,5 @@
       CALL RADIATION_SCHEME &
       & (ist, iend, klon, klev, naero_grp, NSW, &
+      & namelist_ecrad_file, ok_3Deffect, &
       & day_cur, current_time, & 
 !       Cste solaire/(d_Terre-Soleil)**2
