Index: /LMDZ6/branches/LMDZ_ECRad/libf/phylmd/clesphys.h
===================================================================
--- /LMDZ6/branches/LMDZ_ECRad/libf/phylmd/clesphys.h	(revision 4757)
+++ /LMDZ6/branches/LMDZ_ECRad/libf/phylmd/clesphys.h	(revision 4758)
@@ -109,5 +109,4 @@
 !AI flags pour ECRAD       
        LOGICAL :: ok_3Deffect
-       CHARACTER(len=512) :: namelist_ecrad_file
 
        COMMON/clesphys/                                                 &
@@ -162,5 +161,5 @@
      &     , iflag_phytrac, ok_new_lscp, ok_bs, ok_rad_bs               &
      &     ,  iflag_thermals,nsplit_thermals, tau_thermals              &
-     &     , iflag_physiq, ok_3Deffect, namelist_ecrad_file
+     &     , iflag_physiq, ok_3Deffect
        save /clesphys/
 !$OMP THREADPRIVATE(/clesphys/)
Index: /LMDZ6/branches/LMDZ_ECRad/libf/phylmd/ecrad/CHANGELOG
===================================================================
--- /LMDZ6/branches/LMDZ_ECRad/libf/phylmd/ecrad/CHANGELOG	(revision 4757)
+++ /LMDZ6/branches/LMDZ_ECRad/libf/phylmd/ecrad/CHANGELOG	(revision 4758)
@@ -13,4 +13,6 @@
 	  saves look-up table averaged to the bands of the radiation scheme
 	  (general cloud optics only)
+	- Increased security value in single-precision SW
+	  reflectance-transmittance calculation from 1e-12 to 1e-6
 
 version 1.6.0 (27 April 2023)
Index: /LMDZ6/branches/LMDZ_ECRad/libf/phylmd/ecrad/radiation/radiation_aerosol_optics.F90
===================================================================
--- /LMDZ6/branches/LMDZ_ECRad/libf/phylmd/ecrad/radiation/radiation_aerosol_optics.F90	(revision 4757)
+++ /LMDZ6/branches/LMDZ_ECRad/libf/phylmd/ecrad/radiation/radiation_aerosol_optics.F90	(revision 4758)
@@ -37,6 +37,5 @@
     use yomhook,                       only : lhook, dr_hook, jphook
     use radiation_config,              only : config_type
-    use radiation_aerosol_optics_data, only : aerosol_optics_type, &
-         data_setup_aerosol_optics => setup_aerosol_optics
+    use radiation_aerosol_optics_data, only : aerosol_optics_type
     use radiation_io,                  only : nulerr, radiation_abort
 
@@ -58,6 +57,4 @@
         ! Read file containing optical properties already in the bands
         ! of the gas-optics scheme
-         if (.not. associated(config%aerosol_optics%setup)) &
-              config%aerosol_optics%setup => data_setup_aerosol_optics
         call config%aerosol_optics%setup(trim(config%aerosol_optics_file_name), &
              &                           iverbose=config%iverbosesetup)
@@ -346,6 +343,5 @@
     use easy_netcdf,                   only : netcdf_file
     use radiation_config,              only : config_type
-    use radiation_aerosol_optics_data, only : aerosol_optics_type, &
-         data_setup_aerosol_optics => setup_aerosol_optics
+    use radiation_aerosol_optics_data, only : aerosol_optics_type
     use radiation_spectral_definition, only : SolarReferenceTemperature, &
          &                                    TerrestrialReferenceTemperature
@@ -374,5 +370,4 @@
     if (lhook) call dr_hook('radiation_aerosol_optics:setup_general_aerosol_optics_legacy',0,hook_handle)
     ao => config%aerosol_optics
-    ao_legacy%setup => data_setup_aerosol_optics
 
     ! Load file into a local structure
Index: /LMDZ6/branches/LMDZ_ECRad/libf/phylmd/ecrad/radiation/radiation_aerosol_optics_data.F90
===================================================================
--- /LMDZ6/branches/LMDZ_ECRad/libf/phylmd/ecrad/radiation/radiation_aerosol_optics_data.F90	(revision 4757)
+++ /LMDZ6/branches/LMDZ_ECRad/libf/phylmd/ecrad/radiation/radiation_aerosol_optics_data.F90	(revision 4758)
@@ -135,7 +135,6 @@
      logical :: use_monochromatic = .false.
 
-     procedure(setup_aerosol_optics), pointer:: setup => null()
-
    contains
+     procedure :: setup => setup_aerosol_optics
      procedure :: save  => save_aerosol_optics
      procedure :: allocate
Index: /LMDZ6/branches/LMDZ_ECRad/libf/phylmd/ecrad/radiation/radiation_cloud.F90
===================================================================
--- /LMDZ6/branches/LMDZ_ECRad/libf/phylmd/ecrad/radiation/radiation_cloud.F90	(revision 4757)
+++ /LMDZ6/branches/LMDZ_ECRad/libf/phylmd/ecrad/radiation/radiation_cloud.F90	(revision 4758)
@@ -64,5 +64,5 @@
     ! gridbox area for use in representing 3D effects. This variable
     ! is dimensioned (ncol,nlev).
-    real(jprb), allocatable, dimension(:,:) :: inv_cloud_effective_size ! m-1
+    real(jprb), allocatable,  dimension(:,:) :: inv_cloud_effective_size ! m-1
 
     ! Similarly for the in-cloud heterogeneities, used to compute the
@@ -606,4 +606,5 @@
 
     use yomhook,                  only : lhook, dr_hook, jphook
+!    USE mod_phys_lmdz_para
 
     class(cloud_type), intent(inout) :: this
Index: /LMDZ6/branches/LMDZ_ECRad/libf/phylmd/ecrad/radiation/radiation_cloud_generator.F90
===================================================================
--- /LMDZ6/branches/LMDZ_ECRad/libf/phylmd/ecrad/radiation/radiation_cloud_generator.F90	(revision 4757)
+++ /LMDZ6/branches/LMDZ_ECRad/libf/phylmd/ecrad/radiation/radiation_cloud_generator.F90	(revision 4758)
@@ -540,9 +540,9 @@
     use radiation_pdf_sampler, only : pdf_sampler_type
     implicit none
-#if defined(__GFORTRAN__) || defined(__PGI) || defined(__NEC__)
-#else
-    !$omp declare simd(sample_from_pdf_simd) uniform(this) &
-    !$omp linear(ref(fsd)) linear(ref(cdf))
-#endif
+!#if defined(__GFORTRAN__) || defined(__PGI) || defined(__NEC__)
+!#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/radiation_ecckd_interface.F90
===================================================================
--- /LMDZ6/branches/LMDZ_ECRad/libf/phylmd/ecrad/radiation/radiation_ecckd_interface.F90	(revision 4757)
+++ /LMDZ6/branches/LMDZ_ECRad/libf/phylmd/ecrad/radiation/radiation_ecckd_interface.F90	(revision 4758)
@@ -57,10 +57,16 @@
       end if
 
-      if (allocated(config%i_band_from_g_sw)) deallocate(config%i_band_from_g_sw)
-       allocate(config%i_band_from_g_sw          (config%n_g_sw))
-      if (allocated(config%i_band_from_reordered_g_sw)) deallocate(config%i_band_from_reordered_g_sw)
-       allocate(config%i_band_from_reordered_g_sw(config%n_g_sw))
-      if (allocated(config%i_g_from_reordered_g_sw)) deallocate(config%i_g_from_reordered_g_sw) 
-       allocate(config%i_g_from_reordered_g_sw   (config%n_g_sw))
+!      if (allocated(config%i_band_from_g_sw)) deallocate(config%i_band_from_g_sw)
+!      allocate(config%i_band_from_g_sw(config%n_g_sw))
+!      if (allocated(config%i_band_from_reordered_g_sw)) deallocate(config%i_band_from_reordered_g_sw)
+!      allocate(config%i_band_from_reordered_g_sw(config%n_g_sw))
+!      if (allocated(config%i_g_from_reordered_g_sw)) deallocate(config%i_g_from_reordered_g_sw)
+!      allocate(config%i_g_from_reordered_g_sw(config%n_g_sw))
+      if (.not.allocated(config%i_band_from_g_sw)) &
+              allocate(config%i_band_from_g_sw(config%n_g_sw))
+      if (.not.allocated(config%i_band_from_reordered_g_sw)) &
+              allocate(config%i_band_from_reordered_g_sw(config%n_g_sw))
+      if (.not.allocated(config%i_g_from_reordered_g_sw)) &
+              allocate(config%i_g_from_reordered_g_sw(config%n_g_sw))
         
       if (config%do_cloud_aerosol_per_sw_g_point) then
@@ -105,10 +111,17 @@
       end if
 
-      if (allocated(config%i_band_from_g_lw)) deallocate(config%i_band_from_g_lw)
-       allocate(config%i_band_from_g_lw          (config%n_g_lw))
-      if (allocated(config%i_band_from_reordered_g_lw)) deallocate(config%i_band_from_reordered_g_lw) 
-       allocate(config%i_band_from_reordered_g_lw(config%n_g_lw))
-      if (allocated(config%i_g_from_reordered_g_lw)) deallocate(config%i_g_from_reordered_g_lw) 
-       allocate(config%i_g_from_reordered_g_lw   (config%n_g_lw))
+!      if (allocated(config%i_band_from_g_lw)) deallocate(config%i_band_from_g_lw)
+!      allocate(config%i_band_from_g_lw          (config%n_g_lw))
+!      if (allocated(config%i_band_from_reordered_g_lw)) deallocate(config%i_band_from_reordered_g_lw)
+!      allocate(config%i_band_from_reordered_g_lw(config%n_g_lw))
+!      if (allocated(config%i_g_from_reordered_g_lw)) deallocate(config%i_g_from_reordered_g_lw)
+!      allocate(config%i_g_from_reordered_g_lw   (config%n_g_lw))
+      if (.not.allocated(config%i_band_from_g_lw)) &
+         allocate(config%i_band_from_g_lw          (config%n_g_lw))
+      if (.not.allocated(config%i_band_from_reordered_g_lw)) &
+         allocate(config%i_band_from_reordered_g_lw(config%n_g_lw))
+      if (.not.allocated(config%i_g_from_reordered_g_lw)) &
+         allocate(config%i_g_from_reordered_g_lw   (config%n_g_lw))
+
 
       if (config%do_cloud_aerosol_per_lw_g_point) then
Index: /LMDZ6/branches/LMDZ_ECRad/libf/phylmd/ecrad/radiation/radiation_general_cloud_optics.F90
===================================================================
--- /LMDZ6/branches/LMDZ_ECRad/libf/phylmd/ecrad/radiation/radiation_general_cloud_optics.F90	(revision 4757)
+++ /LMDZ6/branches/LMDZ_ECRad/libf/phylmd/ecrad/radiation/radiation_general_cloud_optics.F90	(revision 4758)
@@ -75,10 +75,10 @@
     ! Allocate structures
     if (config%do_sw) then
-     if (allocated(config%cloud_optics_sw)) deallocate(config%cloud_optics_sw)       
+      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)       
+      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/radiation_interface.F90
===================================================================
--- /LMDZ6/branches/LMDZ_ECRad/libf/phylmd/ecrad/radiation/radiation_interface.F90	(revision 4757)
+++ /LMDZ6/branches/LMDZ_ECRad/libf/phylmd/ecrad/radiation/radiation_interface.F90	(revision 4758)
@@ -227,4 +227,6 @@
     use radiation_general_cloud_optics, only : general_cloud_optics
     use radiation_aerosol_optics, only : add_aerosol_optics
+    USE mod_phys_lmdz_para
+
 
     ! Inputs
@@ -236,5 +238,5 @@
     type(thermodynamics_type),intent(in)   :: thermodynamics
     type(gas_type),           intent(in)   :: gas
-    type(cloud_type),         intent(inout):: cloud
+    type(cloud_type),        intent(inout):: cloud
     type(aerosol_type),       intent(in)   :: aerosol
     ! Output
@@ -295,6 +297,22 @@
 
     real(jphook) :: hook_handle
+    integer :: jcol, jlev
 
     if (lhook) call dr_hook('radiation_interface:radiation',0,hook_handle)
+
+    if (config%i_solver_sw == ISolverSPARTACUS) then
+         print*,'Dans radiation, mpi_rank, omp_rank, size, chape inv_cloud = ',&
+              mpi_rank, omp_rank, &
+              shape(cloud%inv_cloud_effective_size), &
+              size(cloud%inv_cloud_effective_size)   
+!         do jcol=istartcol, iendcol
+!              do jlev=1,nlev
+!              print*,'Entree radiation_interf, mpi_rank, omp_rank, jcol, jlev &
+!           &  cloud%inv_cloud_effective_size =',mpi_rank, omp_rank, jcol, jlev, &
+!           &  cloud%inv_cloud_effective_size(jcol,jlev)
+!              enddo
+!          enddo
+    endif
+!    cloud%inv_cloud_effective_size=0.05_jprb
 
     if (thermodynamics%pressure_hl(istartcol,2) &
@@ -456,4 +474,12 @@
         else if (config%i_solver_sw == ISolverSPARTACUS) then
           ! Compute fluxes using the SPARTACUS shortwave solver
+!             cloud%inv_cloud_effective_size=0.05_jprb
+!             do jcol=istartcol, iendcol
+!              do jlev=1,nlev
+!              print*,'jcol, jlev, dans radiation_interf i &
+!               &       cloud%inv_cloud_effective_size =',jcol, jlev, &
+!               cloud%inv_cloud_effective_size(jcol,jlev)
+!              enddo
+!             enddo
           call solver_spartacus_sw(nlev,istartcol,iendcol, &
                &  config, single_level, thermodynamics, cloud, & 
Index: /LMDZ6/branches/LMDZ_ECRad/libf/phylmd/ecrad/radiation/radiation_spartacus_sw.F90
===================================================================
--- /LMDZ6/branches/LMDZ_ECRad/libf/phylmd/ecrad/radiation/radiation_spartacus_sw.F90	(revision 4757)
+++ /LMDZ6/branches/LMDZ_ECRad/libf/phylmd/ecrad/radiation/radiation_spartacus_sw.F90	(revision 4758)
@@ -87,4 +87,5 @@
     use radiation_constants, only      : Pi, GasConstantDryAir, &
          &                               AccelDueToGravity
+    USE mod_phys_lmdz_para
 
     implicit none
@@ -326,4 +327,10 @@
       write(nulout,'(a)',advance='no') '  Processing columns'
     end if
+
+      print*,'Dans radiation_spartacus, mpi_rank, omp_rank, &
+              size, chape inv_cloud = ',&
+              mpi_rank, omp_rank, &
+              shape(cloud%inv_cloud_effective_size), &
+              size(cloud%inv_cloud_effective_size)
 
     ! Main loop over columns
@@ -497,4 +504,8 @@
                &  .not. (nreg == 2 .and. cloud%fraction(jcol,jlev) &
                &  > 1.0-config%cloud_fraction_threshold)) then
+!           print*,' Dans radiation_spartacus mpi_rank, omp_rank, jcol, jlev, &
+!            &     cloud%inv_cloud_effective_size =', mpi_rank, &
+!            &     omp_rank, jcol, jlev, &
+!            &     cloud%inv_cloud_effective_size(jcol,jlev)
             if (cloud%inv_cloud_effective_size(jcol,jlev) > 0.0_jprb) then
               ! 3D effects are only simulated if
Index: /LMDZ6/branches/LMDZ_ECRad/libf/phylmd/ecrad/radiation/radiation_two_stream.F90
===================================================================
--- /LMDZ6/branches/LMDZ_ECRad/libf/phylmd/ecrad/radiation/radiation_two_stream.F90	(revision 4757)
+++ /LMDZ6/branches/LMDZ_ECRad/libf/phylmd/ecrad/radiation/radiation_two_stream.F90	(revision 4758)
@@ -20,4 +20,5 @@
 !   2021-02-19  R Hogan  Security for shortwave singularity
 !   2022-11-22  P Ukkonen/R Hogan  Single precision uses no double precision
+!   2023-09-28  R Hogan  Increased security for single-precision SW "k"
 
 module radiation_two_stream
@@ -212,5 +213,5 @@
       if (od(jg) > 1.0e-3_jprd) then
         k_exponent = sqrt(max((gamma1(jg) - gamma2(jg)) * (gamma1(jg) + gamma2(jg)), &
-             1.E-12_jprd)) ! Eq 18 of Meador & Weaver (1980)
+             1.0e-12_jprd)) ! Eq 18 of Meador & Weaver (1980)
         exponential = exp_fast(-k_exponent*od(jg))
         exponential2 = exponential*exponential
@@ -235,5 +236,5 @@
       else
         k_exponent = sqrt(max((gamma1(jg) - gamma2(jg)) * (gamma1(jg) + gamma2(jg)), &
-             1.E-12_jprd)) ! Eq 18 of Meador & Weaver (1980)
+             1.0e-12_jprd)) ! Eq 18 of Meador & Weaver (1980)
         reflectance(jg) = gamma2(jg) * od(jg)
         transmittance(jg) = (1.0_jprb - k_exponent*od(jg)) / (1.0_jprb + od(jg)*(gamma1(jg)-k_exponent))
@@ -312,5 +313,5 @@
       gamma2 = factor * (1.0_jprb - asymmetry(jg))
       k_exponent = sqrt(max((gamma1 - gamma2) * (gamma1 + gamma2), &
-           1.E-12_jprb)) ! Eq 18 of Meador & Weaver (1980)
+           1.0e-12_jprb)) ! Eq 18 of Meador & Weaver (1980)
       if (od(jg) > 1.0e-3_jprb) then
         exponential = exp_fast(-k_exponent*od(jg))
@@ -646,7 +647,14 @@
       alpha2(jg) = gamma1(jg)*gamma3(jg) + gamma2(jg)*gamma4(jg) ! Eq. 17
       ! The following line crashes inexplicably with gfortran 8.5.0 in
-      ! single precision - try a later version
+      ! single precision - try a later version. Note that the minimum
+      ! value is needed to produce correct results for single
+      ! scattering albedos very close to or equal to one.
+#ifdef PARKIND1_SINGLE
+      k_exponent(jg) = sqrt(max((gamma1(jg) - gamma2(jg)) * (gamma1(jg) + gamma2(jg)), &
+           &       1.0e-6_jprb)) ! Eq 18
+#else
       k_exponent(jg) = sqrt(max((gamma1(jg) - gamma2(jg)) * (gamma1(jg) + gamma2(jg)), &
            &       1.0e-12_jprb)) ! Eq 18
+#endif
     end do
 
@@ -665,8 +673,10 @@
       ! Meador & Weaver (1980) Eq. 25
       ref_diff(jg) = gamma2(jg) * (1.0_jprb - exponential2) * reftrans_factor
-        
-      ! Meador & Weaver (1980) Eq. 26
-      trans_diff(jg) = k_2_exponential * reftrans_factor
-        
+      !ref_diff(jg)       = max(0.0_jprb, min(ref_diff(jg)), 1.0_jprb)
+
+      ! Meador & Weaver (1980) Eq. 26, with security (which is
+      ! sometimes needed, but apparently not on ref_diff)
+      trans_diff(jg) = max(0.0_jprb, min(k_2_exponential * reftrans_factor, 1.0_jprb-ref_diff(jg)))
+
       ! Here we need mu0 even though it wasn't in Meador and Weaver
       ! because we are assuming the incoming direct flux is defined to
@@ -694,5 +704,4 @@
       ref_dir(jg)        = max(0.0_jprb, min(ref_dir(jg), mu0*(1.0_jprb-trans_dir_dir(jg))))
       trans_dir_diff(jg) = max(0.0_jprb, min(trans_dir_diff(jg), mu0*(1.0_jprb-trans_dir_dir(jg))-ref_dir(jg)))
-
     end do
     
Index: /LMDZ6/branches/LMDZ_ECRad/libf/phylmd/phys_output_ctrlout_mod.F90
===================================================================
--- /LMDZ6/branches/LMDZ_ECRad/libf/phylmd/phys_output_ctrlout_mod.F90	(revision 4757)
+++ /LMDZ6/branches/LMDZ_ECRad/libf/phylmd/phys_output_ctrlout_mod.F90	(revision 4758)
@@ -539,4 +539,8 @@
 !AI Ecrad 3Deffect
 #ifdef CPP_ECRAD
+  TYPE(ctrl_out), SAVE :: o_cloud_cover_sw = ctrl_out((/ 11, 11, 10, 10, 10, 10, 11, 11, 11, 11/), &
+    'cloud_cover_sw', 'Ecrad SW cloud cover', '-', (/ ('', i=1, 10) /))
+  TYPE(ctrl_out), SAVE :: o_cloud_cover_sw_s2 = ctrl_out((/ 11, 11, 10, 10, 10, 10, 11, 11, 11, 11/), &
+    'cloud_cover_sw_s2', 'Ecrad SW cloud cover 2 call', '-', (/ ('', i=1, 10) /))
   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) /))
Index: /LMDZ6/branches/LMDZ_ECRad/libf/phylmd/phys_output_var_mod.F90
===================================================================
--- /LMDZ6/branches/LMDZ_ECRad/libf/phylmd/phys_output_var_mod.F90	(revision 4757)
+++ /LMDZ6/branches/LMDZ_ECRad/libf/phylmd/phys_output_var_mod.F90	(revision 4758)
@@ -174,10 +174,13 @@
   REAL, SAVE, ALLOCATABLE:: sss(:) ! (klon)
   ! bulk salinity of the surface layer of the ocean, in ppt
-  
   !$OMP THREADPRIVATE(tkt, tks, taur, sss)
 
+  !AI. cloud_cover_sw, cloud_cover_sw_s2 from Ecrad (1rt and 2 call)
+  REAL, SAVE, ALLOCATABLE:: cloud_cover_sw(:), cloud_cover_sw_s2(:)
+  !$OMP THREADPRIVATE(cloud_cover_sw, cloud_cover_sw_s2)
+
 CONTAINS
 
-  !======================================================================
+  !=====================================================taur=================
   SUBROUTINE phys_output_var_init
     use dimphy
@@ -253,4 +256,8 @@
     ALLOCATE(icc3dstra(klon, klev))
 
+! cloud_cover_sw, cloud_cover_sw_s2 from Ecrad
+   ALLOCATE(cloud_cover_sw(klon))
+   ALLOCATE(cloud_cover_sw_s2(klon))
+
   END SUBROUTINE phys_output_var_init
 
@@ -304,4 +311,7 @@
     DEALLOCATE(icc3dstra)
 
+!AI cloud_cover_sw, cloud_cover_sw_s2 from Ecrad    
+    DEALLOCATE(cloud_cover_sw, cloud_cover_sw_s2)
+
   END SUBROUTINE phys_output_var_end
 
Index: /LMDZ6/branches/LMDZ_ECRad/libf/phylmd/phys_output_write_mod.F90
===================================================================
--- /LMDZ6/branches/LMDZ_ECRad/libf/phylmd/phys_output_write_mod.F90	(revision 4757)
+++ /LMDZ6/branches/LMDZ_ECRad/libf/phylmd/phys_output_write_mod.F90	(revision 4758)
@@ -231,5 +231,10 @@
     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   
+         o_topl0_s2,o_topl_s2,o_tops0_s2,o_tops_s2, &
+         o_SWupTOA_s2,o_SWupTOAclr_s2,o_cloud_cover_sw, &
+         o_cloud_cover_sw_s2,o_SWdnTOA_s2,o_SWdnTOAclr_s2, &
+         o_LWupSFCclr_s2, o_LWdnSFCclr_s2, o_SWupSFC_s2, &
+         o_SWupSFCclr_s2, o_SWdnSFC_s2, o_SWdnSFCclr_s2, &
+         o_LWupSFC_s2, o_LWdnSFC_s2
 #endif
 
@@ -290,6 +295,11 @@
     USE phys_state_var_mod, ONLY: &
         sollw0_s2,sollw_s2,solsw0_s2,solsw_s2, &
-        toplw0_s2,toplw_s2,topsw0_s2,topsw_s2
+        toplw0_s2,toplw_s2,topsw0_s2,topsw_s2, &
+        swup0_s2,swup_s2,swdn_s2,swdn0_s2,sollwdownclr_s2, &
+        sollwdown_s2,lwdn0_s2
+    USE phys_output_var_mod, ONLY: cloud_cover_sw, &
+        cloud_cover_sw_s2
 #endif
+
 
 
@@ -1068,4 +1078,5 @@
 !AI 08 2023 Ecrad 3Deffect
 #ifdef CPP_ECRAD
+     CALL histwrite_phy(o_cloud_cover_sw, cloud_cover_sw)
      if (ok_3Deffect) then
         IF (vars_defined) THEN
@@ -1091,4 +1102,58 @@
        CALL histwrite_phy(o_topl_s2, toplw_s2)
        CALL histwrite_phy(o_topl0_s2, toplw0_s2)
+
+       IF (vars_defined) THEN
+          zx_tmp_fi2d(:) = swup_s2(:,klevp1)*swradcorr(:)
+       ENDIF
+       CALL histwrite_phy(o_SWupTOA_s2, zx_tmp_fi2d)
+
+       IF (vars_defined) THEN
+          zx_tmp_fi2d(:) = swup0_s2(:,klevp1)*swradcorr(:)
+       ENDIF
+       CALL histwrite_phy(o_SWupTOAclr_s2, zx_tmp_fi2d)
+
+       IF (vars_defined) THEN
+          zx_tmp_fi2d(:) = swdn_s2(:,klevp1)*swradcorr(:)
+       ENDIF
+       CALL histwrite_phy(o_SWdnTOA_s2, zx_tmp_fi2d)
+
+       IF (vars_defined) THEN
+          zx_tmp_fi2d(:) = swdn0_s2(:,klevp1)*swradcorr(:)
+       ENDIF
+       CALL histwrite_phy(o_SWdnTOAclr_s2, zx_tmp_fi2d)
+
+       IF (vars_defined) THEN
+          zx_tmp_fi2d(:)=sollwdown_s2(:)-sollw_s2(:)
+       ENDIF
+       CALL histwrite_phy(o_LWupSFC_s2, zx_tmp_fi2d)
+       CALL histwrite_phy(o_LWdnSFC_s2, sollwdown_s2)
+
+       IF (vars_defined) THEN
+          sollwdownclr_s2(1:klon) = -1.*lwdn0_s2(1:klon,1)
+          zx_tmp_fi2d(1:klon)=sollwdownclr_s2(1:klon)-sollw0_s2(1:klon)
+       ENDIF
+       CALL histwrite_phy(o_LWupSFCclr_s2, zx_tmp_fi2d)
+       CALL histwrite_phy(o_LWdnSFCclr_s2, sollwdownclr_s2)
+
+       IF (vars_defined) THEN
+          zx_tmp_fi2d(:) = swup_s2(:,1)*swradcorr(:)
+       ENDIF
+       CALL histwrite_phy(o_SWupSFC_s2, zx_tmp_fi2d)
+
+       IF (vars_defined) THEN
+          zx_tmp_fi2d(:) = swup0_s2(:,1)*swradcorr(:)
+       ENDIF
+       CALL histwrite_phy(o_SWupSFCclr_s2, zx_tmp_fi2d)
+
+       IF (vars_defined) THEN
+          zx_tmp_fi2d(:) = swdn_s2(:,1)*swradcorr(:)
+       ENDIF
+       CALL histwrite_phy(o_SWdnSFC_s2, zx_tmp_fi2d)
+
+       IF (vars_defined) THEN
+          zx_tmp_fi2d(:) = swdn0_s2(:,1)*swradcorr(:)
+       ENDIF
+       CALL histwrite_phy(o_SWdnSFCclr_s2, zx_tmp_fi2d)
+
      endif
 #endif       
Index: /LMDZ6/branches/LMDZ_ECRad/libf/phylmd/phys_state_var_mod.F90
===================================================================
--- /LMDZ6/branches/LMDZ_ECRad/libf/phylmd/phys_state_var_mod.F90	(revision 4757)
+++ /LMDZ6/branches/LMDZ_ECRad/libf/phylmd/phys_state_var_mod.F90	(revision 4758)
@@ -410,6 +410,6 @@
       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 :: sollwdown_s2(:), sollwdownclr_s2(:)
+!$OMP THREADPRIVATE(sollwdown_s2, sollwdownclr_s2)
       REAL,ALLOCATABLE,SAVE :: topsw0_s2(:),toplw0_s2(:)
       REAL,ALLOCATABLE,SAVE :: solsw0_s2(:),sollw0_s2(:)
@@ -727,5 +727,5 @@
       ALLOCATE(albpla_s2(klon))
       ALLOCATE(solsw_s2(klon), solswfdiff_s2(klon), sollw_s2(klon))
-      ALLOCATE(sollwdown_s2(klon))
+      ALLOCATE(sollwdown_s2(klon),sollwdownclr_s2(klon))
       ALLOCATE(topsw0_s2(klon),toplw0_s2(klon))
       ALLOCATE(solsw0_s2(klon),sollw0_s2(klon))
@@ -900,5 +900,5 @@
       DEALLOCATE(albpla_s2)
       DEALLOCATE(solsw_s2, solswfdiff_s2, sollw_s2)
-      DEALLOCATE(sollwdown_s2)
+      DEALLOCATE(sollwdown_s2, sollwdownclr_s2)
       DEALLOCATE(topsw0_s2,toplw0_s2)
       DEALLOCATE(solsw0_s2,sollw0_s2)
Index: /LMDZ6/branches/LMDZ_ECRad/libf/phylmd/physiq_mod.F90
===================================================================
--- /LMDZ6/branches/LMDZ_ECRad/libf/phylmd/physiq_mod.F90	(revision 4757)
+++ /LMDZ6/branches/LMDZ_ECRad/libf/phylmd/physiq_mod.F90	(revision 4758)
@@ -92,4 +92,5 @@
     USE lmdz_cloud_optics_prop_ini, ONLY : cloud_optics_prop_ini
     USE phys_output_var_mod, ONLY :      cloudth_sth,cloudth_senv,cloudth_sigmath,cloudth_sigmaenv
+    USE phys_output_var_mod, ONLY : cloud_cover_sw, cloud_cover_sw_s2
 
 
@@ -1266,4 +1267,6 @@
     REAL pi
     INTEGER ieru
+
+    CHARACTER(len=512) :: namelist_ecrad_file
 
     !======================================================================!
@@ -4579,4 +4582,6 @@
           ENDIF
           !
+           namelist_ecrad_file='namelist_ecrad'
+          !
           CALL radlwsw &
                (dist, rmu0, fract,  &
@@ -4597,4 +4602,5 @@
                zqsat, flwc, fiwc, &
                ref_liq, ref_ice, ref_liq_pi, ref_ice_pi, &
+               namelist_ecrad_file, &
                heat,heat0,cool,cool0,albpla, &
                heat_volc,cool_volc, &
@@ -4616,5 +4622,6 @@
                                 !-end
                ZLWFT0_i, ZFLDN0, ZFLUP0, &
-               ZSWFT0_i, ZFSDN0, ZFSUP0)
+               ZSWFT0_i, ZFSDN0, ZFSUP0, &
+               cloud_cover_sw)
 
           !lwoff=y, betalwoff=1. : offset LW CRE for radiation code and other
@@ -4653,4 +4660,6 @@
                 ENDIF
                 !
+                 namelist_ecrad_file='namelist_ecrad'
+                ! 
                 CALL radlwsw &
                      (dist, rmu0, fract,  &
@@ -4671,4 +4680,5 @@
                      zqsat, flwc, fiwc, &
                      ref_liq, ref_ice, ref_liq_pi, ref_ice_pi, &
+                     namelist_ecrad_file, &
                      heatp,heat0p,coolp,cool0p,albplap, &
                      heat_volc,cool_volc, &
@@ -4690,5 +4700,6 @@
                                 !-end
                      ZLWFT0_i, ZFLDN0, ZFLUP0, &
-                     ZSWFT0_i, ZFSDN0, ZFSUP0)
+                     ZSWFT0_i, ZFSDN0, ZFSUP0, &
+                     cloud_cover_sw)
           ENDIF !ok_4xCO2atm
 
@@ -4714,4 +4725,5 @@
                      zqsat, flwc, fiwc, &
                      ref_liq, ref_ice, ref_liq_pi, ref_ice_pi, &
+                     namelist_ecrad_file, &
 ! A modifier              
                      heat_s2,heat0_s2,cool_s2,cool0_s2,albpla_s2, &
@@ -4734,6 +4746,6 @@
                                 !-end
                      ZLWFT0_i, ZFLDN0, ZFLUP0, &
-                     ZSWFT0_i, ZFSDN0, ZFSUP0)
-             namelist_ecrad_file='namelist_ecrad'
+                     ZSWFT0_i, ZFSDN0, ZFSUP0, &
+                     cloud_cover_sw_s2)
           ENDIF ! ok_3Deffect
 #endif
Index: /LMDZ6/branches/LMDZ_ECRad/libf/phylmd/radiation_scheme.F90
===================================================================
--- /LMDZ6/branches/LMDZ_ECRad/libf/phylmd/radiation_scheme.F90	(revision 4757)
+++ /LMDZ6/branches/LMDZ_ECRad/libf/phylmd/radiation_scheme.F90	(revision 4758)
@@ -12,4 +12,9 @@
 !             
 ! ============================================================================
+module interface_lmdz_ecrad
+
+IMPLICIT NONE        
+
+contains
 
 SUBROUTINE RADIATION_SCHEME &
@@ -35,6 +40,6 @@
      &  PFLUX_UV, PFLUX_PAR, PFLUX_PAR_CLEAR, &
      &  PEMIS_OUT, PLWDERIVATIVE, &
-     &  PSWDIFFUSEBAND, PSWDIRECTBAND)
-
+     &  PSWDIFFUSEBAND, PSWDIRECTBAND, &
+     &  ecrad_cloud_cover_sw)
 
 ! RADIATION_SCHEME - Interface to modular radiation scheme
@@ -84,11 +89,11 @@
 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
+!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
@@ -176,4 +181,7 @@
 REAL(KIND=JPRB), INTENT(IN)    :: TIME
 
+! Name of file names specified on command line
+character(len=512), INTENT(IN) :: namelist_file
+logical, INTENT(IN)            :: ok_3Deffect
 
 ! OUTPUT ARGUMENTS
@@ -222,4 +230,7 @@
 REAL(KIND=JPRB),  INTENT(OUT) :: PSWDIFFUSEBAND(KLON,NSW)
 REAL(KIND=JPRB),  INTENT(OUT) :: PSWDIRECTBAND (KLON,NSW)
+
+!AI Nov 2023
+REAL(KIND=JPRB),  INTENT(OUT) :: ecrad_cloud_cover_sw(KLON)
 
 ! LOCAL VARIABLES
@@ -270,14 +281,17 @@
 INTEGER, PARAMETER :: NAERMACC = 1
 
-! Name of file names specified on command line
-character(len=512) :: namelist_file
-
 logical :: loutput=.true.
 logical :: lprint_input=.false.
-logical :: lprint_config=.true.
+logical :: lprint_config=.false.
 logical, save :: debut_ecrad=.true.
 !$OMP THREADPRIVATE(debut_ecrad)
-integer, save :: itap_ecrad=1
-logical :: ok_3Deffect
+integer, save :: itap_ecrad=0
+!$OMP THREADPRIVATE(itap_ecrad)
+
+REAL(KIND=JPRB) ::  inv_cloud_effective_size(KLON,KLEV)
+REAL(KIND=JPRB) ::  inv_inhom_effective_size(KLON,KLEV)
+
+integer :: irang
+
 
 IF (LHOOK) CALL DR_HOOK('RADIATION_SCHEME',0,ZHOOK_HANDLE)
@@ -298,89 +312,15 @@
 ! Fin partie initialisation et configuration 
 
-!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 print fichiers namelist utilise
+!if (is_omp_root) then
+! itap_ecrad=itap_ecrad+1
+! print*,'Dans radiation_scheme itap_ecrad, mpi_rank, omp_rank, namelist_file : ', &
+!         itap_ecrad, mpi_rank, omp_rank, namelist_file
+!else
+! print*,'mpi_rank omp_rank, namelist_file :', mpi_rank, omp_rank, namelist_file
+!endif
+
+! AI 11 23 Allocates depplaces au debut
+print*,'*********** ALLOCATES *******************************'
 ! AI ATTENTION
 ! Allocate memory in radiation objects
@@ -388,11 +328,13 @@
 CALL single_level%allocate(KLON, NSW, 1, &
      &                     use_sw_albedo_direct=.TRUE.)
-
-print*,'************* THERMO (allocate + input) ************************************'
+CALL thermodynamics%allocate(KLON, KLEV, use_h2o_sat=.true.)
+CALL cloud%allocate(KLON, KLEV)
+CALL aerosol%allocate(KLON, 1, KLEV, KAEROSOL)
+CALL gas%allocate(KLON, KLEV)
+CALL flux%allocate(rad_config, 1, KLON, KLEV)
+
+print*,'************* THERMO (input) ************************************'
 ! Set thermodynamic profiles: simply copy over the half-level
 ! pressure and temperature
-!print*,'Appel allocate thermo'
-CALL thermodynamics%allocate(KLON, KLEV, use_h2o_sat=.true.)
-!print*,'Definir les champs thermo'
 ! AI
 ! pressure_hl > paprs
@@ -400,5 +342,4 @@
 thermodynamics%pressure_hl   (KIDIA:KFDIA,:) = PPRESSURE_H   (KIDIA:KFDIA,:)
 thermodynamics%temperature_hl(KIDIA:KFDIA,:) = PTEMPERATURE_H(KIDIA:KFDIA,:)
-
 !print*,'Compute saturation specific humidity'
 ! Compute saturation specific humidity, used to hydrate aerosols. The
@@ -429,8 +370,8 @@
 !cur_day
 !ITIM = NINT(NSTEP * YRRIP%TSTEP / 60.0_JPRB)
-ITIM = NINT(TIME / 60.0_JPRB)
+!ITIM = NINT(TIME / 60.0_JPRB)
 !current_time
 !allocate(single_level%iseed(KIDIA:KFDIA))
-DO JLON = KIDIA, KFDIA
+!DO JLON = KIDIA, KFDIA
   ! This method gives a unique value for roughly every 1-km square
   ! on the globe and every minute.  ASIN(PGEMU)*60 gives rough
@@ -442,17 +383,18 @@
   ! since random numbers are generated with the help of integer
   ! overflow, it should not matter if the number did overflow).
-  single_level%iseed(JLON) = ITIM + IDAY & 
-       &  +  NINT(PGELAM(JLON)*108000000.0_JPRB &
-       &          + ASIN(PGEMU(JLON))*6000.0_JPRB)
-ENDDO
+!  single_level%iseed(JLON) = ITIM + IDAY & 
+!       &  +  NINT(PGELAM(JLON)*108000000.0_JPRB &
+!       &          + ASIN(PGEMU(JLON))*6000.0_JPRB)
+!ENDDO
+!AI Nov 23
+! Simple initialization of the seeds for the Monte Carlo scheme
+call single_level%init_seed_simple(kidia, kfdia)
 
 print*,'********** CLOUDS (allocate + input) *******************************************'
 !print*,'Appel Allocate clouds'
-CALL cloud%allocate(KLON, KLEV)
 ! Set cloud fields
 cloud%q_liq(KIDIA:KFDIA,:)    = PQ_LIQUID(KIDIA:KFDIA,:)
 cloud%q_ice(KIDIA:KFDIA,:)    = PQ_ICE(KIDIA:KFDIA,:) + PQ_SNOW(KIDIA:KFDIA,:)
 cloud%fraction(KIDIA:KFDIA,:) = PCLOUD_FRAC(KIDIA:KFDIA,:)
-
 !!! ok AI ATTENTION a voir avec JL
 ! Compute effective radi and convert to metres
@@ -460,5 +402,4 @@
 cloud%re_liq(KIDIA:KFDIA,:) = ZRE_LIQUID_UM(KIDIA:KFDIA,:)
 cloud%re_ice(KIDIA:KFDIA,:) = ZRE_ICE_UM(KIDIA:KFDIA,:)
-
 ! Get the cloud overlap decorrelation length (for cloud boundaries),
 ! in km, according to the parameterization specified by NDECOLAT,
@@ -471,5 +412,4 @@
 ! AI valeur dans namelist
 ! rad_config%cloud_inhom_decorr_scaling = ZDECORR_LEN_RATIO
-
 !AI ATTENTION meme valeur que dans offline
 ! A mettre dans namelist
@@ -480,5 +420,4 @@
        &                 istartcol=JLON, iendcol=JLON)
 ENDDO
-
 ! IFS :
 ! Cloud water content fractional standard deviation is configurable
@@ -489,36 +428,46 @@
 CALL cloud%create_fractional_std(KLON, KLEV, driver_config%frac_std)
 
-if (rad_config%i_solver_sw == ISolverSPARTACUS &
-      & .or.   rad_config%i_solver_lw == ISolverSPARTACUS) then
-! AI ! Read cloud properties needed by SPARTACUS
-!AI ATTENTION meme traitement dans le version offline
-
-! By default mid and high cloud effective size is 10 km
-!CALL cloud%create_inv_cloud_effective_size(KLON,KLEV,1.0_JPRB/10000.0_JPRB)
-
-!  if (driver_config%low_inv_effective_size >= 0.0_jprb &
-!     & .or. driver_config%middle_inv_effective_size >= 0.0_jprb &
-!     & .or. driver_config%high_inv_effective_size >= 0.0_jprb) then
-  if (driver_config%ok_effective_size) then
+if (ok_3Deffect) then
+ if (driver_config%ok_effective_size) then
      call cloud%create_inv_cloud_effective_size_eta(klon, klev, &
                &  thermodynamics%pressure_hl, &
                &  driver_config%low_inv_effective_size, &
                &  driver_config%middle_inv_effective_size, &
-               &  driver_config%high_inv_effective_size, 0.8_jprb, 0.45_jprb)
-!  else if (driver_config%cloud_separation_scale_surface > 0.0_jprb &
-!         .and. driver_config%cloud_separation_scale_toa > 0.0_jprb) then
-  else if (driver_config%ok_separation) then
-      call cloud%param_cloud_effective_separation_eta(klon, klev, &
+               &  driver_config%high_inv_effective_size, 0.8_jprb, 0.45_jprb, &
+               &  KIDIA, KFDIA)
+   else if (driver_config%ok_separation) then
+     call cloud%param_cloud_effective_separation_eta(klon, klev, &
                &  thermodynamics%pressure_hl, &
                &  driver_config%cloud_separation_scale_surface, &
                &  driver_config%cloud_separation_scale_toa, &
                &  driver_config%cloud_separation_scale_power, &
-               &  driver_config%cloud_inhom_separation_factor)
-  endif
-endif  
-
-print*,'******** AEROSOLS (allocate + input) **************************************'
+               &  driver_config%cloud_inhom_separation_factor, &
+               &  KIDIA, KFDIA)
+   endif     
+ else  
+ if (rad_config%i_solver_sw == ISolverSPARTACUS &
+      & .or.   rad_config%i_solver_lw == ISolverSPARTACUS) then
+   ! AI ! Read cloud properties needed by SPARTACUS
+   if (driver_config%ok_effective_size) then
+     call cloud%create_inv_cloud_effective_size_eta(klon, klev, &
+               &  thermodynamics%pressure_hl, &
+               &  driver_config%low_inv_effective_size, &
+               &  driver_config%middle_inv_effective_size, &
+               &  driver_config%high_inv_effective_size, 0.8_jprb, 0.45_jprb, &
+               &  KIDIA, KFDIA)
+   else if (driver_config%ok_separation) then
+     call cloud%param_cloud_effective_separation_eta(klon, klev, &
+               &  thermodynamics%pressure_hl, &
+               &  driver_config%cloud_separation_scale_surface, &
+               &  driver_config%cloud_separation_scale_toa, &
+               &  driver_config%cloud_separation_scale_power, &
+               &  driver_config%cloud_inhom_separation_factor, &
+               &  KIDIA, KFDIA)
+   endif
+ endif  
+endif
+
+print*,'******** AEROSOLS (input) **************************************'
 !IF (NAERMACC > 0) THEN
-  CALL aerosol%allocate(KLON, 1, KLEV, KAEROSOL) ! MACC climatology
 !ELSE
 !  CALL aerosol%allocate(KLON, 1, KLEV, 6) ! Tegen climatology
@@ -571,11 +520,8 @@
 !    ENDDO
 !  ENDDO
-
 !ENDIF
 
-print*,'********** GAS (allocate + input) ************************************************'
+print*,'********** GAS (input) ************************************************'
 !print*,'Appel Allocate gas'
-CALL gas%allocate(KLON, KLEV)
-
 ! Convert ozone Pa*kg/kg to kg/kg
 ! AI ATTENTION
@@ -586,5 +532,4 @@
 !  ENDDO
 !ENDDO
-
 !  Insert gas mixing ratios
 !print*,'Insert gas mixing ratios'
@@ -603,12 +548,32 @@
 call set_gas_units(rad_config, gas)
 
-print*,'************** FLUX (allocate) ***********************'
-CALL flux%allocate(rad_config, 1, KLON, KLEV)
-
 ! Call radiation scheme
-print*,'******** Appel radiation scheme **************************'
+!print*,'*** Appel radiation *** namelist **** omp_rank ****', &
+!         omp_rank, namelist_file
+!   if (rad_config%i_solver_sw == ISolverSPARTACUS) then 
+!    if (driver_config%ok_separation) then
+!      print*,'Avant radiation, mpi_rank, omp_rank, size, chape inv_cloud = ',&
+!              mpi_rank, omp_rank, &
+!              shape(cloud%inv_cloud_effective_size), &
+!              size(cloud%inv_cloud_effective_size)      
+!      do jlon=KIDIA, KFDIA      
+!        do jlev=1,klev
+!         print*,' Avant radiation mpi_rank, omp_rank, jlon, jlev, &
+!            &     cloud%inv_cloud_effective_size =', mpi_rank, &
+!            &     omp_rank, jlon, jlev, &
+!            &     cloud%inv_cloud_effective_size(jlon,jlev)
+!        enddo
+!      enddo
+!       cloud%inv_cloud_effective_size=inv_cloud_effective_size
+!       cloud%inv_inhom_effective_size=inv_inhom_effective_size
+!    endif
+!   endif
 CALL radiation(KLON, KLEV, KIDIA, KFDIA, rad_config, &
      &  single_level, thermodynamics, gas, cloud, aerosol, flux)
 
+print*,'*********** Sortie flux ****************'
+
+! Cloud cover
+ecrad_cloud_cover_sw = flux%cloud_cover_sw
 ! Compute required output fluxes
 ! DN and UP flux
@@ -621,5 +586,4 @@
 PFLUX_LW_DN_CLEAR(KIDIA:KFDIA,:) = flux%lw_dn_clear(KIDIA:KFDIA,:)
 PFLUX_LW_UP_CLEAR(KIDIA:KFDIA,:) = flux%lw_up_clear(KIDIA:KFDIA,:)
-
 ! First the net fluxes
 PFLUX_SW(KIDIA:KFDIA,:) = flux%sw_dn(KIDIA:KFDIA,:) - flux%sw_up(KIDIA:KFDIA,:)
@@ -629,5 +593,4 @@
 PFLUX_LW_CLEAR(KIDIA:KFDIA,:) &
      &  = flux%lw_dn_clear(KIDIA:KFDIA,:) - flux%lw_up_clear(KIDIA:KFDIA,:)
-
 ! Now the surface fluxes
 !PFLUX_SW_DN_SURF(KIDIA:KFDIA) = flux%sw_dn(KIDIA:KFDIA,KLEV+1)
@@ -645,5 +608,4 @@
   PFLUX_DIR_INTO_SUN(KIDIA:KFDIA) = PFLUX_DIR(KIDIA:KFDIA) / PMU0(KIDIA:KFDIA)
 END WHERE
-
 ! Top-of-atmosphere downwelling flux
 !PFLUX_SW_DN_TOA(KIDIA:KFDIA) = flux%sw_dn(KIDIA:KFDIA,1)
@@ -651,6 +613,4 @@
 !PFLUX_LW_DN_TOA(KIDIA:KFDIA) = flux%lw_dn(KIDIA:KFDIA,1)
 !PFLUX_LW_UP_TOA(KIDIA:KFDIA) = flux%lw_up(KIDIA:KFDIA,1)
-
-! Compute UV fluxes as weighted sum of appropriate shortwave bands
 !AI ATTENTION
 if (0.eq.1) then
@@ -660,5 +620,4 @@
        &  * flux%sw_dn_surf_band(IBAND_UV(JBAND),KIDIA:KFDIA)
 ENDDO
-
 ! Compute photosynthetically active radiation similarly
 PFLUX_PAR      (KIDIA:KFDIA) = 0.0_JPRB
@@ -679,5 +638,4 @@
   PEMIS_OUT(KIDIA:KFDIA) = PFLUX_LW(KIDIA:KFDIA,KLEV+1) / ZBLACK_BODY_NET_LW
 END WHERE
-
 ! Copy longwave derivatives
 ! AI ATTENTION
@@ -686,5 +644,4 @@
   PLWDERIVATIVE(KIDIA:KFDIA,:) = flux%lw_derivatives(KIDIA:KFDIA,:)
 END IF
-
 ! Store the shortwave downwelling fluxes in each albedo band
 !AI ATTENTION
@@ -706,4 +663,6 @@
 ENDIF
 endif
+
+print*,'********** DEALLOCATIONS ************************'
 CALL single_level%deallocate
 CALL thermodynamics%deallocate
@@ -716,2 +675,4 @@
 
 END SUBROUTINE RADIATION_SCHEME
+
+end module interface_lmdz_ecrad
Index: /LMDZ6/branches/LMDZ_ECRad/libf/phylmd/radlwsw_m.F90
===================================================================
--- /LMDZ6/branches/LMDZ_ECRad/libf/phylmd/radlwsw_m.F90	(revision 4757)
+++ /LMDZ6/branches/LMDZ_ECRad/libf/phylmd/radlwsw_m.F90	(revision 4758)
@@ -24,4 +24,5 @@
    qsat, flwc, fiwc, &
    ref_liq, ref_ice, ref_liq_pi, ref_ice_pi, &
+   namelist_ecrad_file, &
    heat,heat0,cool,cool0,albpla,&
    heat_volc, cool_volc,&
@@ -43,5 +44,6 @@
 !-end
    ZLWFT0_i, ZFLDN0, ZFLUP0,&
-   ZSWFT0_i, ZFSDN0, ZFSUP0)
+   ZSWFT0_i, ZFSDN0, ZFSUP0,&
+   cloud_cover_sw)
 
 ! Modules necessaires
@@ -84,4 +86,5 @@
       USE time_phylmdz_mod, only: current_time
       USE phys_cal_mod, only: day_cur
+      USE interface_lmdz_ecrad
 #endif
 
@@ -245,4 +248,6 @@
   REAL,    INTENT(in)  :: ref_ice_pi(klon,klev) ! ice crystal radius   pre-industrial from newmicro
 
+  CHARACTER(len=512), INTENT(in) :: namelist_ecrad_file
+
 ! Output arguments
   REAL,    INTENT(out) :: heat(KLON,KLEV), cool(KLON,KLEV)
@@ -333,5 +338,7 @@
                ZFLUX_PAR_CLEAR(klon), &     ! CS photosynthetically 
                ZFLUX_SW_DN_TOA(klon), &     ! DN SW flux at TOA
-               ZEMIS_OUT(klon)              ! effective broadband emissivity
+               ZEMIS_OUT(klon), &              ! effective broadband emissivity
+               cloud_cover_sw(klon)
+
   REAL(KIND=8) ZLWDERIVATIVE(klon,klev+1)   ! LW derivatives
   REAL(KIND=8) ZSWDIFFUSEBAND(klon,NSW), &  ! SW DN flux in diffuse albedo band 
@@ -1384,5 +1391,6 @@
 !      & ZFLUX_SW_DN_TOA, 
       & ZEMIS_OUT, ZLWDERIVATIVE, &
-      & PSFSWDIF, PSFSWDIR)
+      & PSFSWDIF, PSFSWDIR, &
+      & cloud_cover_sw)
 
       print *,'========= RADLWSW: apres RADIATION_SCHEME ==================== '
