Index: LMDZ6/branches/LMDZ_ECRad/libf/phylmd/clesphys.h
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/phylmd/clesphys.h	(revision 4646)
+++ LMDZ6/branches/LMDZ_ECRad/libf/phylmd/clesphys.h	(revision 4647)
@@ -103,4 +103,8 @@
        INTEGER :: iflag_phytrac
 
+!AI flags pour ECRAD
+       LOGICAL :: ok_3Deffect
+       CHARACTER(len=512) :: namelist_ecrad_file
+
        COMMON/clesphys/                                                 &
 ! REAL FIRST
@@ -151,5 +155,6 @@
      &     , ok_daily_climoz, ok_all_xml, ok_lwoff                      &
      &     , iflag_phytrac, ok_new_lscp                                 &
-     &     ,  iflag_thermals,nsplit_thermals, tau_thermals    
+     &     , iflag_thermals,nsplit_thermals, tau_thermals               &
+     &     , ok_3Deffect, namelist_ecrad_file    
        save /clesphys/
 !$OMP THREADPRIVATE(/clesphys/)
Index: LMDZ6/branches/LMDZ_ECRad/libf/phylmd/ecrad/radiation_aerosol_optics.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/phylmd/ecrad/radiation_aerosol_optics.F90	(revision 4646)
+++ LMDZ6/branches/LMDZ_ECRad/libf/phylmd/ecrad/radiation_aerosol_optics.F90	(revision 4647)
@@ -53,6 +53,5 @@
         ! properties and average to the spectral intervals of the
         ! current gas-optics scheme
-!        call setup_general_aerosol_optics(config)
-        call setup_general_aerosol_optics_lmdz(config,trim(config%aerosol_optics_file_name))
+        call setup_general_aerosol_optics(config)
       else
         ! Read file containing optical properties already in the bands
@@ -334,311 +333,4 @@
 
   end subroutine setup_general_aerosol_optics
-
-    !---------------------------------------------------------------------
-  ! Read LMDZ file containing high spectral resolution optical properties
-  ! and average to the spectral intervals of the current gas-optics
-  ! scheme
-  subroutine setup_general_aerosol_optics_lmdz(config,file_name)
-
-    use parkind1,                      only : jprb
-    use yomhook,                       only : lhook, dr_hook
-!    use easy_netcdf,                   only : netcdf_file
-    use radiation_config,              only : config_type
-    use radiation_aerosol_optics_data, only : aerosol_optics_type
-    use radiation_spectral_definition, only : SolarReferenceTemperature, &
-         &                                    TerrestrialReferenceTemperature
-    use radiation_io,                  only : nulout
-    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
-    use netcdf, only: nf90_nowrite
-
-
-    type(config_type), intent(inout), target :: config
-
-!    ! The NetCDF file containing the aerosol optics data
-!    type(netcdf_file)  :: file
-
-    character(len=*), intent(in):: file_name
-    ! NetCDF file containing the aerosol optics data
-
-    ! Wavenumber points in NetCDF file
-    real(jprb), allocatable :: wavenumber(:) ! cm-1
-
-    ! Hydrophilic aerosol properties
-    real(jprb), allocatable :: mass_ext_philic(:,:,:)    ! Mass-ext coefficient (m2 kg-1)
-    real(jprb), allocatable :: ssa_philic(:,:,:)         ! Single-scattering albedo
-    real(jprb), allocatable :: g_philic(:,:,:)           ! Asymmetry factor
-    real(jprb), allocatable :: lidar_ratio_philic(:,:,:) ! Lidar ratio (sr)
-
-    ! Hydrophobic aerosol properties
-    real(jprb), allocatable :: mass_ext_phobic(:,:)      ! Mass-ext coefficient (m2 kg-1)
-    real(jprb), allocatable :: ssa_phobic(:,:)           ! Single-scattering albedo
-    real(jprb), allocatable :: g_phobic(:,:)             ! Asymmetry factor
-    real(jprb), allocatable :: lidar_ratio_phobic(:,:)   ! Lidar ratio (sr)
-
-    ! Mapping matrix between optical properties at the wavenumbers in
-    ! the file, and spectral intervals used by the gas-optics scheme
-    real(jprb), allocatable :: mapping(:,:)
-
-    ! Pointer to the aerosol optics coefficients for brevity of access
-    type(aerosol_optics_type), pointer :: ao
-
-    ! Target monochromatic wavenumber for interpolation (cm-1)
-    real(jprb) :: wavenumber_target
-
-    ! Number of spectral points describing aerosol properties in the
-    ! shortwave and longwave
-    integer    :: nspecsw, nspeclw
-
-    ! Number of monochromatic wavelengths required
-    integer    :: nmono
-
-    integer    :: n_type_philic, n_type_phobic, nrh, nwn
-    integer    :: jtype, jwl, iwn
-
-    ! Weight of first point in interpolation
-    real(jprb) :: weight1
-
-    real(jprb) :: hook_handle
-
-    ! Local:
-    integer ncid, grpid, dimid, varid
-
-    if (lhook) call dr_hook('radiation_aerosol_optics:setup_general_aerosol_optics',0,hook_handle)
-
-    ao => config%aerosol_optics
-
-    ao%use_hydrophilic = .true.
-    ao%use_monochromatic = .true.
-    print*,'file_name= ',file_name
-    call nf95_open(file_name, nf90_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%g_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%g_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%g_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%g_sw_phobic = cshift(ao%mass_ext_sw_phobic, 1)
-! AI ATTENTION    
-    call nf95_inq_varid(grpid, "wavenumber", varid)
-    call nf95_gw_var(grpid, varid, wavenumber)
-
-    ! 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 file%get('wavenumber', wavenumber)
-!    nwn = size(wavenumber)
-
-!    call file%get_global_attribute('description_hydrophobic', &
-!         &                         ao%description_phobic_str)
-
-
-!      call file%get('relative_humidity1',      ao%rh_lower)
-
-!      call file%get_global_attribute('description_hydrophilic', &
-!           &                         ao%description_philic_str)
-
-    ! Close aerosol scattering file
-!    call file%close()
-
-    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
-
-    n_type_phobic = size(mass_ext_phobic, 2)
-    if (ao%use_hydrophilic) then
-      n_type_philic = size(mass_ext_philic, 3)
-      nrh = size(ao%rh_lower)
-    else
-      n_type_philic = 0
-      nrh = 0
-    end if
-
-    if (config%do_cloud_aerosol_per_sw_g_point) then
-      nspecsw = config%gas_optics_sw%spectral_def%ng
-    else
-      nspecsw = config%gas_optics_sw%spectral_def%nband
-    end if
-
-    if (config%do_cloud_aerosol_per_lw_g_point) then
-      nspeclw = config%gas_optics_lw%spectral_def%ng
-    else
-      nspeclw = config%gas_optics_lw%spectral_def%nband
-    end if
-
-    if (allocated(ao%wavelength_mono)) then
-      ! Monochromatic wavelengths also required
-      nmono = size(ao%wavelength_mono)
-    else
-      nmono = 0
-    end if
-
-    call ao%allocate(n_type_phobic, n_type_philic, nrh, nspeclw, nspecsw, nmono)
-
-    if (config%do_sw) then
-      call config%gas_optics_sw%spectral_def%calc_mapping(SolarReferenceTemperature, &
-           &  wavenumber, mapping, use_bands=(.not. config%do_cloud_aerosol_per_sw_g_point))
-
-      ao%mass_ext_sw_phobic = matmul(mapping, mass_ext_phobic)
-      ao%ssa_sw_phobic = matmul(mapping, mass_ext_phobic*ssa_phobic) &
-           &           / ao%mass_ext_sw_phobic
-      ao%g_sw_phobic = matmul(mapping, mass_ext_phobic*ssa_phobic*g_phobic) &
-           &         / (ao%mass_ext_sw_phobic*ao%ssa_sw_phobic)
-
-      if (ao%use_hydrophilic) then
-        do jtype = 1,n_type_philic
-          ao%mass_ext_sw_philic(:,:,jtype) = matmul(mapping, mass_ext_philic(:,:,jtype))
-          ao%ssa_sw_philic(:,:,jtype) = matmul(mapping, mass_ext_philic(:,:,jtype) &
-               &                                        *ssa_philic(:,:,jtype)) &
-               &           / ao%mass_ext_sw_philic(:,:,jtype)
-          ao%g_sw_philic(:,:,jtype) = matmul(mapping, mass_ext_philic(:,:,jtype) &
-               &                       *ssa_philic(:,:,jtype)*g_philic(:,:,jtype)) &
-               &         / (ao%mass_ext_sw_philic(:,:,jtype)*ao%ssa_sw_philic(:,:,jtype))
-        end do
-      end if
-    end if
-    if (config%do_lw) then
-      call config%gas_optics_lw%spectral_def%calc_mapping(TerrestrialReferenceTemperature, &
-           &  wavenumber, mapping, use_bands=(.not. config%do_cloud_aerosol_per_lw_g_point))
-
-      ao%mass_ext_lw_phobic = matmul(mapping, mass_ext_phobic)
-      ao%ssa_lw_phobic = matmul(mapping, mass_ext_phobic*ssa_phobic) &
-           &           / ao%mass_ext_lw_phobic
-      ao%g_lw_phobic = matmul(mapping, mass_ext_phobic*ssa_phobic*g_phobic) &
-           &         / (ao%mass_ext_lw_phobic*ao%ssa_lw_phobic)
-
-      if (ao%use_hydrophilic) then
-        do jtype = 1,n_type_philic
-          ao%mass_ext_lw_philic(:,:,jtype) = matmul(mapping, mass_ext_philic(:,:,jtype))
-          ao%ssa_lw_philic(:,:,jtype) = matmul(mapping, mass_ext_philic(:,:,jtype) &
-               &                                        *ssa_philic(:,:,jtype)) &
-               &           / ao%mass_ext_lw_philic(:,:,jtype)
-          ao%g_lw_philic(:,:,jtype) = matmul(mapping, mass_ext_philic(:,:,jtype) &
-               &                       *ssa_philic(:,:,jtype)*g_philic(:,:,jtype)) &
-               &         / (ao%mass_ext_lw_philic(:,:,jtype)*ao%ssa_lw_philic(:,:,jtype))
-        end do
-      end if
-    end if
-
-    if (allocated(ao%wavelength_mono)) then
-      ! Monochromatic wavelengths also required
-      do jwl = 1,nmono
-        ! Wavelength (m) to wavenumber (cm-1)
-        wavenumber_target = 0.01_jprb / ao%wavelength_mono(jwl)
-        ! Find index to first interpolation point, and its weight
-        if (wavenumber_target <= wavenumber(1)) then
-          weight1 = 1.0_jprb
-          iwn = 1
-        else if (wavenumber_target >= wavenumber(nwn)) then
-          iwn = nwn-1
-          weight1 = 0.0_jprb
-        else
-          iwn = 1
-          do while (wavenumber(iwn+1) < wavenumber_target .and. iwn < nwn-1)
-            iwn = iwn + 1
-          end do
-          weight1 = (wavenumber(iwn+1)-wavenumber_target) &
-               &  / (wavenumber(iwn+1)-wavenumber(iwn))
-        end if
-        ! Linear interpolation
-        ao%mass_ext_mono_phobic(jwl,:) = weight1 * mass_ext_phobic(iwn,:) &
-             &             + (1.0_jprb - weight1)* mass_ext_phobic(iwn+1,:)
-        ao%ssa_mono_phobic(jwl,:)      = weight1 * ssa_phobic(iwn,:) &
-             &             + (1.0_jprb - weight1)* ssa_phobic(iwn+1,:)
-        ao%g_mono_phobic(jwl,:)        = weight1 * g_phobic(iwn,:) &
-             &             + (1.0_jprb - weight1)* g_phobic(iwn+1,:)
-        ao%lidar_ratio_mono_phobic(jwl,:) = weight1 * lidar_ratio_phobic(iwn,:) &
-             &                + (1.0_jprb - weight1)* lidar_ratio_phobic(iwn+1,:)
-        if (ao%use_hydrophilic) then
-          ao%mass_ext_mono_philic(jwl,:,:) = weight1 * mass_ext_philic(iwn,:,:) &
-               &               + (1.0_jprb - weight1)* mass_ext_philic(iwn+1,:,:)
-          ao%ssa_mono_philic(jwl,:,:)      = weight1 * ssa_philic(iwn,:,:) &
-               &               + (1.0_jprb - weight1)* ssa_philic(iwn+1,:,:)
-          ao%g_mono_philic(jwl,:,:)        = weight1 * g_philic(iwn,:,:) &
-               &               + (1.0_jprb - weight1)* g_philic(iwn+1,:,:)
-          ao%lidar_ratio_mono_philic(jwl,:,:) = weight1 * lidar_ratio_philic(iwn,:,:) &
-               &                  + (1.0_jprb - weight1)* lidar_ratio_philic(iwn+1,:,:)
-        end if
-      end do
-    end if
-
-    ! Deallocate memory local to this routine
-    deallocate(mass_ext_phobic)
-    deallocate(ssa_phobic)
-    deallocate(g_phobic)
-    deallocate(lidar_ratio_phobic)
-    if (ao%use_hydrophilic) then
-      deallocate(mass_ext_philic)
-      deallocate(ssa_philic)
-      deallocate(g_philic)
-      deallocate(lidar_ratio_philic)
-    end if
-
-    if (lhook) call dr_hook('radiation_aerosol_optics:setup_general_aerosol_optics',1,hook_handle)
-
-  end subroutine setup_general_aerosol_optics_lmdz
-    
 
   !---------------------------------------------------------------------
Index: LMDZ6/branches/LMDZ_ECRad/libf/phylmd/ecrad/radiation_cloud_generator.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/phylmd/ecrad/radiation_cloud_generator.F90	(revision 4646)
+++ LMDZ6/branches/LMDZ_ECRad/libf/phylmd/ecrad/radiation_cloud_generator.F90	(revision 4647)
@@ -541,9 +541,4 @@
     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
     type(pdf_sampler_type), intent(in)  :: this
 
Index: LMDZ6/branches/LMDZ_ECRad/libf/phylmd/ecrad/radiation_ecckd.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/phylmd/ecrad/radiation_ecckd.F90	(revision 4646)
+++ LMDZ6/branches/LMDZ_ECRad/libf/phylmd/ecrad/radiation_ecckd.F90	(revision 4647)
@@ -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/branches/LMDZ_ECRad/libf/phylmd/ecrad/radiation_ecckd_interface.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/phylmd/ecrad/radiation_ecckd_interface.F90	(revision 4646)
+++ LMDZ6/branches/LMDZ_ECRad/libf/phylmd/ecrad/radiation_ecckd_interface.F90	(revision 4647)
@@ -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/branches/LMDZ_ECRad/libf/phylmd/ecrad/radiation_general_cloud_optics.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/phylmd/ecrad/radiation_general_cloud_optics.F90	(revision 4646)
+++ LMDZ6/branches/LMDZ_ECRad/libf/phylmd/ecrad/radiation_general_cloud_optics.F90	(revision 4647)
@@ -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/branches/LMDZ_ECRad/libf/phylmd/ecrad/radiation_general_cloud_optics_data.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/phylmd/ecrad/radiation_general_cloud_optics_data.F90	(revision 4646)
+++ LMDZ6/branches/LMDZ_ECRad/libf/phylmd/ecrad/radiation_general_cloud_optics_data.F90	(revision 4647)
@@ -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/branches/LMDZ_ECRad/libf/phylmd/ecrad/radiation_scheme.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/phylmd/ecrad/radiation_scheme.F90	(revision 4646)
+++ LMDZ6/branches/LMDZ_ECRad/libf/phylmd/ecrad/radiation_scheme.F90	(revision 4647)
@@ -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, &
@@ -97,4 +99,5 @@
 USE mod_phys_lmdz_para
 USE setup_config_from_lmdz,   ONLY : driver_config_type
+!USE RADIATION_SETUP, ONLY : config_type, driver_config_type
 
 IMPLICIT NONE
@@ -220,5 +223,9 @@
 ! 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
@@ -261,5 +268,5 @@
 
 ! Name of file names specified on command line
-character(len=512) :: file_name
+character(len=512) :: namelist_file
 
 logical :: loutput=.true.
@@ -269,16 +276,19 @@
 !$OMP THREADPRIVATE(debut_ecrad)
 integer, save :: itap_ecrad=1
+logical :: ok_3Deffect
 
 IF (LHOOK) CALL DR_HOOK('RADIATION_SCHEME',0,ZHOOK_HANDLE)
-print*,'Entree dans radiation_scheme'
 
 ! A.I juillet 2023 : 
 ! Initialisation dans radiation_setup au 1er passage dans Ecrad
 !$OMP MASTER
-if (debut_ecrad) then
-! AI appel radiation_setup
- call SETUP_RADIATION_SCHEME(loutput,rad_config,driver_config)
- debut_ecrad=.false. 
-endif 
+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 
@@ -287,5 +297,10 @@
 !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
@@ -362,4 +377,5 @@
 
            itap_ecrad=itap_ecrad+1
+   ENDIF          
 endif           
 
Index: LMDZ6/branches/LMDZ_ECRad/libf/phylmd/ecrad/radiation_setup.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/phylmd/ecrad/radiation_setup.F90	(revision 4646)
+++ LMDZ6/branches/LMDZ_ECRad/libf/phylmd/ecrad/radiation_setup.F90	(revision 4647)
@@ -46,5 +46,5 @@
 ! AI At the end of the routine, the parameters are read in namelist
 !    
-  SUBROUTINE SETUP_RADIATION_SCHEME(LOUTPUT,rad_config,driver_config)
+  SUBROUTINE SETUP_RADIATION_SCHEME(LOUTPUT,file_name,rad_config,driver_config)
 
     USE radiation_config, ONLY : config_type, &
@@ -86,5 +86,5 @@
 
 ! 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)
Index: LMDZ6/branches/LMDZ_ECRad/libf/phylmd/ecrad/setup_aerosol_optics_lmdz_m.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/phylmd/ecrad/setup_aerosol_optics_lmdz_m.F90	(revision 4646)
+++ LMDZ6/branches/LMDZ_ECRad/libf/phylmd/ecrad/setup_aerosol_optics_lmdz_m.F90	(revision 4647)
@@ -29,6 +29,5 @@
     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
-    use netcdf, only: nf90_nowrite
+         nf95_get_var, nf95_gw_var, nf95_nowrite
 
     type(aerosol_optics_type), intent(out):: ao
@@ -44,6 +43,5 @@
     ao%use_hydrophilic = .true.
     ao%use_monochromatic = .true.
-    print*,'file_name= ',file_name
-    call nf95_open(file_name, nf90_nowrite, ncid)
+    call nf95_open(file_name, nf95_nowrite, ncid)
     call nf95_inq_grp_full_ncid(ncid, "Hydrophilic", grpid)
     call nf95_inq_dimid(grpid, "hur", dimid)
@@ -69,8 +67,8 @@
     call nf95_inq_varid(grpid, "single_scat_alb", varid)
     call nf95_gw_var(grpid, varid, ao%ssa_sw_philic)
-    ao%g_sw_philic = cshift(ao%ssa_sw_philic, 1)
+    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%g_sw_philic = cshift(ao%mass_ext_sw_philic, 1)
+    ao%mass_ext_sw_philic = cshift(ao%mass_ext_sw_philic, 1)
 
     ! Hydrophilic/Monochromatic:
@@ -95,8 +93,8 @@
     call nf95_inq_varid(grpid, "single_scat_alb", varid)
     call nf95_gw_var(grpid, varid, ao%ssa_sw_phobic)
-    ao%g_sw_phobic = cshift(ao%ssa_sw_phobic, 1)
+    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%g_sw_phobic = cshift(ao%mass_ext_sw_phobic, 1)
+    ao%mass_ext_sw_phobic = cshift(ao%mass_ext_sw_phobic, 1)
 
     ! Hydrophobic/Monochromatic:
Index: LMDZ6/branches/LMDZ_ECRad/libf/phylmd/phys_local_var_mod.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/phylmd/phys_local_var_mod.F90	(revision 4646)
+++ LMDZ6/branches/LMDZ_ECRad/libf/phylmd/phys_local_var_mod.F90	(revision 4647)
@@ -141,4 +141,26 @@
       REAL, SAVE, ALLOCATABLE :: toplwad0_aero(:), sollwad0_aero(:)     ! diag
       !$OMP THREADPRIVATE(toplwad0_aero,sollwad0_aero)
+
+!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)
+      
 ! Special RRTM
       REAL, SAVE, ALLOCATABLE :: ZLWFT0_i(:,:),  ZSWFT0_i(:,:)      ! diag
@@ -740,4 +762,16 @@
       ALLOCATE(solsw_aerop(klon,naero_grp), solsw0_aerop(klon,naero_grp))
       ALLOCATE(topswcf_aerop(klon,naero_grp), solswcf_aerop(klon,naero_grp))
+
+!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))
 
 ! additional LW variables CK
@@ -1056,4 +1090,17 @@
       DEALLOCATE(solsw_aerop, solsw0_aerop)
       DEALLOCATE(topswcf_aerop, solswcf_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)
+      
 !AI Aerosols
       DEALLOCATE(m_allaer)
Index: LMDZ6/branches/LMDZ_ECRad/libf/phylmd/phys_output_ctrlout_mod.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/phylmd/phys_output_ctrlout_mod.F90	(revision 4646)
+++ LMDZ6/branches/LMDZ_ECRad/libf/phylmd/phys_output_ctrlout_mod.F90	(revision 4647)
@@ -529,4 +529,78 @@
   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/branches/LMDZ_ECRad/libf/phylmd/phys_output_write_mod.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/phylmd/phys_output_write_mod.F90	(revision 4646)
+++ LMDZ6/branches/LMDZ_ECRad/libf/phylmd/phys_output_write_mod.F90	(revision 4647)
@@ -236,4 +236,10 @@
 #endif
 
+#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
+
     USE ice_sursat_mod, ONLY: flight_m, flight_h2o
     
@@ -272,4 +278,11 @@
 #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, &
@@ -1068,4 +1081,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/branches/LMDZ_ECRad/libf/phylmd/phys_state_var_mod.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/phylmd/phys_state_var_mod.F90	(revision 4646)
+++ LMDZ6/branches/LMDZ_ECRad/libf/phylmd/phys_state_var_mod.F90	(revision 4647)
@@ -397,4 +397,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
@@ -693,4 +716,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))
@@ -851,4 +888,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/branches/LMDZ_ECRad/libf/phylmd/physiq_mod.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/phylmd/physiq_mod.F90	(revision 4646)
+++ LMDZ6/branches/LMDZ_ECRad/libf/phylmd/physiq_mod.F90	(revision 4647)
@@ -209,5 +209,17 @@
        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, &
        !
@@ -1435,4 +1447,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
@@ -4450,4 +4469,47 @@
                      ZSWFT0_i, ZFSDN0, ZFSUP0)
           ENDIF !ok_4xCO2atm
+
+! A.I aout 2023
+! Effet 3D des nuages Ecrad
+#ifdef CPP_ECRAD
+          IF (ok_3Deffect) then
+                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, &
+                     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/branches/LMDZ_ECRad/libf/phylmd/radlwsw_m.F90
===================================================================
--- LMDZ6/branches/LMDZ_ECRad/libf/phylmd/radlwsw_m.F90	(revision 4646)
+++ LMDZ6/branches/LMDZ_ECRad/libf/phylmd/radlwsw_m.F90	(revision 4647)
@@ -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
