Index: trunk/LMDZ.COMMON/libf/evolution/changelog.txt
===================================================================
--- trunk/LMDZ.COMMON/libf/evolution/changelog.txt	(revision 3489)
+++ trunk/LMDZ.COMMON/libf/evolution/changelog.txt	(revision 3490)
@@ -449,5 +449,10 @@
 Update and correction for the visualization of the layerings over time.
 
-== 24,29/10/2024 == EV
+24/10/2024 == EV
+adding the NS dynamic subsurface ice module in the PEM
+
+== 24,29,30/10/2024 == EV
 we added the option to use NS dynamical subsurface ice in the model to more realisticly calculate the amount of ice in the subsurface and therfore the subsurface thermal inertia
 
+== 04/11/2024 == JBC
+Correction of initialization of 'icetable_dynamic' and the management of the flag.
Index: trunk/LMDZ.COMMON/libf/evolution/conf_pem.F90
===================================================================
--- trunk/LMDZ.COMMON/libf/evolution/conf_pem.F90	(revision 3489)
+++ trunk/LMDZ.COMMON/libf/evolution/conf_pem.F90	(revision 3490)
@@ -103,5 +103,5 @@
 reg_thprop_dependp = .false.
 call getin('reg_thprop_dependp',reg_thprop_dependp)
-write(*,*)  'Thermal properties of the regolith vary with pressure ?', reg_thprop_dependp
+write(*,*) 'Thermal properties of the regolith vary with pressure ?', reg_thprop_dependp
 
 fluxgeo = 0.
@@ -119,12 +119,12 @@
 icetable_equilibrium = .true.
 call getin('icetable_equilibrium',icetable_equilibrium)
-write(*,*)  'Is the ice table computed at equilibrium?', icetable_equilibrium
+write(*,*) 'Is the ice table computed at equilibrium?', icetable_equilibrium
 
 icetable_dynamic = .false.
 call getin('icetable_dynamic',icetable_dynamic)
-write(*,*)  'Is the ice table computed with the dynamic method?', icetable_dynamic
-if ((.not. soil_pem) .and. ((icetable_equilibrium) .or. (icetable_dynamic))) then
-    write(*,*) 'Ice table  must be used when soil_pem = T'
-    call abort_physic(modname,"Ice table  must be used when soil_pem = T",1)
+write(*,*) 'Is the ice table computed with the dynamic method?', icetable_dynamic
+if ((.not. soil_pem) .and. (icetable_equilibrium .or. icetable_dynamic)) then
+    write(*,*) 'Ice table (equilibrium or dynamic method) must be used when soil_pem = T'
+    call abort_physic(modname,"Ice table must be used when soil_pem = T",1)
 endif
 
@@ -145,6 +145,6 @@
 
 if (evol_orbit_pem .and. year_bp_ini == 0.) then
-    write(*,*)  'You want to follow the file obl_ecc_lsp.asc for changing orb parameters,'
-    write(*,*)  'but you did not specify from which year to start.'
+    write(*,*) 'You want to follow the file obl_ecc_lsp.asc for changing orb parameters,'
+    write(*,*) 'but you did not specify from which year to start.'
     call abort_physic(modname,"evol_orbit_pem=.true. but year_bp_ini=0",1)
 endif
Index: trunk/LMDZ.COMMON/libf/evolution/ice_table_mod.F90
===================================================================
--- trunk/LMDZ.COMMON/libf/evolution/ice_table_mod.F90	(revision 3489)
+++ trunk/LMDZ.COMMON/libf/evolution/ice_table_mod.F90	(revision 3490)
@@ -10,6 +10,6 @@
 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 
-logical, save                           :: icetable_equilibrium     ! Boolean to say if the PEM needs to recompute the icetable depth when at  equilibrium
-logical, save                           :: icetable_dynamic         ! Boolean to say if the PEM needs to recompute the icetable depth (dynamic method)
+logical, save                           :: icetable_equilibrium     ! Boolean to say if the PEM needs to recompute the icetable depth when at equilibrium
+logical, save                           :: icetable_dynamic         ! Boolean to say if the PEM needs to recompute the icetable depth with the dynamic method
 real, allocatable, dimension(:,:), save :: porefillingice_depth     ! ngrid x nslope: Depth of the ice table [m]
 real, allocatable, dimension(:,:), save :: porefillingice_thickness ! ngrid x nslope: Thickness of the ice table [m]
Index: trunk/LMDZ.COMMON/libf/evolution/pem.F90
===================================================================
--- trunk/LMDZ.COMMON/libf/evolution/pem.F90	(revision 3489)
+++ trunk/LMDZ.COMMON/libf/evolution/pem.F90	(revision 3490)
@@ -932,7 +932,5 @@
             call computeice_table_equilibrium(ngrid,nslope,nsoilmx_PEM,watercaptag,watersurf_density_avg,watersoil_density_PEM_avg,TI_PEM(:,1,:),porefillingice_depth,porefillingice_thickness)
             call compute_massh2o_exchange_ssi(ngrid,nslope,nsoilmx_PEM,porefillingice_thickness_prev_iter,porefillingice_thickness,porefillingice_depth,tsurf_avg, tsoil_PEM,delta_h2o_icetablesublim) ! Mass of H2O exchange between the ssi and the atmosphere
-        endif
-        ! II_d.3 Update the ice table
-        if (icetable_dynamic) then
+        else if (icetable_dynamic) then
             write(*,*) "Compute ice table"
             porefillingice_thickness_prev_iter = porefillingice_thickness
@@ -991,6 +989,5 @@
             call writediagpem(ngrid,'ssi_depth_slope'//str2,'ice table depth','m',2,porefillingice_depth(:,islope))
             call writediagpem(ngrid,'ssi_thick_slope'//str2,'ice table depth','m',2,porefillingice_thickness(:,islope))
-        endif
-        if (icetable_dynamic) then
+        else if (icetable_dynamic) then
             call writediagpem(ngrid,'ssi_depth_slope'//str2,'ice table depth','m',2,porefillingice_depth(:,islope))
             call writediagpem(ngrid,'ssi_thick_slope'//str2,'ice table depth','m',2,porefillingice_thickness(:,islope))
Index: trunk/LMDZ.COMMON/libf/evolution/pemetat0.F90
===================================================================
--- trunk/LMDZ.COMMON/libf/evolution/pemetat0.F90	(revision 3489)
+++ trunk/LMDZ.COMMON/libf/evolution/pemetat0.F90	(revision 3490)
@@ -16,5 +16,5 @@
 use comsoil_h,                  only: volcapa, inertiedat
 use adsorption_mod,             only: regolith_adsorption, adsorption_pem
-use ice_table_mod,              only: computeice_table_equilibrium, icetable_equilibrium
+use ice_table_mod,              only: computeice_table_equilibrium, icetable_equilibrium, icetable_dynamic
 use constants_marspem_mod,      only: alpha_clap_h2o, beta_clap_h2o, TI_breccia, TI_bedrock
 use soil_thermalproperties_mod, only: update_soil_thermalproperties
@@ -308,5 +308,5 @@
 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 !3. Ice Table
-        if(icetable_equilibrium) then
+        if (icetable_equilibrium .or. icetable_dynamic) then
             call get_field("ice_table",ice_table,found)
             if (.not. found) then
@@ -484,5 +484,5 @@
 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 !c) Ice table
-        if(icetable_equilibrium) then
+        if (icetable_equilibrium .or. icetable_dynamic) then
             call computeice_table_equilibrium(ngrid,nslope,nsoil_PEM,watercaptag,watersurf_avg,watersoil_avg,TI_PEM(:,1,:),ice_table,ice_table_thickness)
             call update_soil_thermalproperties(ngrid,nslope,nsoil_PEM,tend_h2o_ice,h2o_ice,global_avg_pressure,ice_table,ice_table_thickness,TI_PEM)
Index: trunk/LMDZ.MARS/changelog.txt
===================================================================
--- trunk/LMDZ.MARS/changelog.txt	(revision 3489)
+++ trunk/LMDZ.MARS/changelog.txt	(revision 3490)
@@ -4731,6 +4731,2 @@
 Remove obsolete/depreciated lwrite flag (which would trigger some very specific
 extra text outputs), in code and in reference callphys.def files.
-
-
-24/10/2024 == EV adding the NS dynamic subsurface ice module in the PEM
-
