Index: trunk/LMDZ.COMMON/libf/evolution/changelog.txt
===================================================================
--- trunk/LMDZ.COMMON/libf/evolution/changelog.txt	(revision 3704)
+++ trunk/LMDZ.COMMON/libf/evolution/changelog.txt	(revision 3705)
@@ -627,2 +627,6 @@
 == 1/4/2025 == EV
 updating paramaters to work with the layering
+
+== 2/4/2025 == EV
+updating the h2o and co2 ice values that will be used by the PCM according to the top layer in the stratum
+
Index: trunk/LMDZ.COMMON/libf/evolution/pem.F90
===================================================================
--- trunk/LMDZ.COMMON/libf/evolution/pem.F90	(revision 3704)
+++ trunk/LMDZ.COMMON/libf/evolution/pem.F90	(revision 3705)
@@ -111,4 +111,5 @@
     use comvert_mod,              only: ap, bp
     use writerestart1D_mod,       only: writerestart1D
+   ! use layering_mod,             only: layering, array2stratif, nb_str_max, layering_algo
 #endif
 
@@ -1082,28 +1083,32 @@
 write(*,*) '> Reconstructing perennial ice and frost for the PCM'
 watercap = 0.
-perennial_co2ice = co2_ice
+perennial_co2ice =sum(stratif(ig,islope)%top%co2ice_volfrac*stratif(ig,islope)%top%thickness*subslope_dist(ig,:)/cos(pi*def_slope_mean(:)/180.))
 do ig = 1,ngrid
     ! H2O ice metamorphism
-    if (metam_h2oice .and. sum(qsurf(ig,igcm_h2o_ice,:)*subslope_dist(ig,:)/cos(pi*def_slope_mean(:)/180.)) > metam_h2oice_threshold) then
-        h2o_ice(ig,:) = h2o_ice(ig,:) + qsurf(ig,igcm_h2o_ice,:) - metam_h2oice_threshold
-        qsurf(ig,igcm_h2o_ice,:) = metam_h2oice_threshold
-    endif
+    !if (metam_h2oice .and. sum(qsurf(ig,igcm_h2o_ice,:)*subslope_dist(ig,:)/cos(pi*def_slope_mean(:)/180.)) > metam_h2oice_threshold) then
+    !    h2o_ice(ig,:) = h2o_ice(ig,:) + qsurf(ig,igcm_h2o_ice,:) - metam_h2oice_threshold
+    !    qsurf(ig,igcm_h2o_ice,:) = metam_h2oice_threshold
+    !endif
 
     ! Is H2O ice still considered as an infinite reservoir for the PCM?
-    if (sum(h2o_ice(ig,:)*subslope_dist(ig,:)/cos(pi*def_slope_mean(:)/180.)) > inf_h2oice_threshold) then
-        ! There is enough ice to be considered as an infinite reservoir
+    !if (sum(h2o_ice(ig,:)*subslope_dist(ig,:)/cos(pi*def_slope_mean(:)/180.)) > inf_h2oice_threshold) then
+    if (sum(stratif(ig,islope)%top%h2oice_volfrac*stratif(ig,islope)%top%thickness*subslope_dist(ig,:)/cos(pi*def_slope_mean(:)/180.)) > inf_h2oice_threshold) then   
+       ! There is enough ice to be considered as an infinite reservoir
         watercaptag(ig) = .true.
     else
         ! There too little ice to be considered as an infinite reservoir so ice is transferred to the frost
         watercaptag(ig) = .false.
-        qsurf(ig,igcm_h2o_ice,:) = qsurf(ig,igcm_h2o_ice,:) + h2o_ice(ig,:)
+
+       ! qsurf(ig,igcm_h2o_ice,:) = qsurf(ig,igcm_h2o_ice,:) + h2o_ice(ig,:)
+
+       qsurf(ig,igcm_h2o_ice,:) = qsurf(ig,igcm_h2o_ice,:) + sum(stratif(ig,islope)%top%h2oice_volfrac*stratif(ig,islope)%top%thickness*subslope_dist(ig,:)/cos(pi*def_slope_mean(:)/180.))
         h2o_ice(ig,:) = 0.
     endif
 
     ! CO2 ice metamorphism
-    if (metam_co2ice .and. sum(qsurf(ig,igcm_co2,:)*subslope_dist(ig,:)/cos(pi*def_slope_mean(:)/180.)) > metam_co2ice_threshold) then
-        perennial_co2ice(ig,:) = perennial_co2ice(ig,:) + qsurf(ig,igcm_co2,:) - metam_co2ice_threshold
-        qsurf(ig,igcm_co2,:) = metam_co2ice_threshold
-    endif
+    !if (metam_co2ice .and. sum(qsurf(ig,igcm_co2,:)*subslope_dist(ig,:)/cos(pi*def_slope_mean(:)/180.)) > metam_co2ice_threshold) then
+    !    perennial_co2ice(ig,:) = perennial_co2ice(ig,:) + qsurf(ig,igcm_co2,:) - metam_co2ice_threshold
+    !    qsurf(ig,igcm_co2,:) = metam_co2ice_threshold
+    !endif
 enddo
 
