Index: /trunk/LMDZ.COMMON/libf/evolution/changelog.txt
===================================================================
--- /trunk/LMDZ.COMMON/libf/evolution/changelog.txt	(revision 3385)
+++ /trunk/LMDZ.COMMON/libf/evolution/changelog.txt	(revision 3386)
@@ -375,2 +375,8 @@
 == 18/06/2024 == JBC
 Correction related to r3330 for the initialization of the global average pressure taken from the PCM: it has to be done before the call of "pemetat0".
+
+== 19/06/2024 == JBC
+- Correction for the initialization in 1D due to the change of 'ecritphy' into 'outputs_per_sol' in r3369.
+- Correction in the condition to check the normal end of a PCM/PEM run in "jobP*M.slurm" files.
+- Correction of files cleaning in the launching script.
+- Improvement of the launching script to take into account the modification of parameters for a relaunch.
Index: /trunk/LMDZ.COMMON/libf/evolution/deftank/jobPCM.slurm
===================================================================
--- /trunk/LMDZ.COMMON/libf/evolution/deftank/jobPCM.slurm	(revision 3385)
+++ /trunk/LMDZ.COMMON/libf/evolution/deftank/jobPCM.slurm	(revision 3386)
@@ -30,5 +30,5 @@
 cp run_PCM.def run.def
 srun --cpu-bind=threads --label -c${OMP_NUM_THREADS:=1} $exePCM > out_runPCM${iPCM} 2>&1
-if [ ! -f "restartfi.nc" ] || [ ! tail -n 1 out_runPCM${iPCM} | grep -iq "everything is cool!" ]; then # Check if it ended abnormally
+if [ ! -f "restartfi.nc" ] || ! (tail -n 1 out_runPCM${iPCM} | grep -iq "everything is cool!"); then # Check if it ended abnormally
     echo "Error: the run PCM $iPCM crashed!"
     echo "Be careful: there may be dependent jobs remaining in the SLURM queue with status 'DependencyNeverSatisfied'! You can cancel them by executing the script \"kill_launchPEM.sh\"."
@@ -38,5 +38,7 @@
 # Copy data files and prepare the next run
 mv out_runPCM${iPCM} out_PCM/run${iPCM}
-mv diagfi.nc diags/diagfi${iPCM}.nc
+if [ -f "diagfi.nc" ]; then
+    mv diagfi.nc diags/diagfi${iPCM}.nc
+fi
 if [ -f "diagsoil.nc" ]; then
     mv diagsoil.nc diags/diagsoil${iPCM}.nc
Index: /trunk/LMDZ.COMMON/libf/evolution/deftank/jobPEM.slurm
===================================================================
--- /trunk/LMDZ.COMMON/libf/evolution/deftank/jobPEM.slurm	(revision 3385)
+++ /trunk/LMDZ.COMMON/libf/evolution/deftank/jobPEM.slurm	(revision 3386)
@@ -38,5 +38,5 @@
 cp run_PEM.def run.def
 ./$exePEM > out_runPEM${iPEM} 2>&1
-if [ ! -f "restartfi.nc" ] || [ ! tail -n 1 out_runPEM${iPEM} | grep -iq "so far, so good!" ]; then # Check if it ended abnormally
+if [ ! -f "restartfi.nc" ] || ! (tail -n 1 out_runPEM${iPEM} | grep -iq "so far, so good!"); then # Check if it ended abnormally
     echo "Error: the run PEM $iPEM crashed!"
     exit 1
@@ -45,5 +45,7 @@
 # Copy data files and prepare the next run
 mv out_runPEM${iPEM} out_PEM/run${iPEM}
-mv diagpem.nc diags/diagpem${iPEM}.nc
+if [ -f "diagpem.nc" ]; then
+    mv diagpem.nc diags/diagpem${iPEM}.nc
+fi
 if [ -f "diagsoilpem.nc" ]; then
     mv diagsoilpem.nc diags/diagsoilpem${iPEM}.nc
Index: /trunk/LMDZ.COMMON/libf/evolution/deftank/launchPEM.sh
===================================================================
--- /trunk/LMDZ.COMMON/libf/evolution/deftank/launchPEM.sh	(revision 3385)
+++ /trunk/LMDZ.COMMON/libf/evolution/deftank/launchPEM.sh	(revision 3386)
@@ -74,5 +74,5 @@
             fi
         done
-        read i_myear n_myear convert_years iPCM iPEM nPCM nPCM_ini < info_PEM.txt
+        read i_myear n_myear_old convert_years iPCM iPEM nPCM_old nPCM_ini_old < info_PEM.txt
         while true; do
             if [ $relaunch = "PCM" ]; then
@@ -101,4 +101,15 @@
         date
         checklaunch
+        convertyears
+        if [ $nPCM_ini -ne $nPCM_ini_old ]; then
+            echo "The number of initial PCM runs has been modified from $nPCM_ini_old to $nPCM_ini."
+        fi
+        if [ $nPCM -ne $nPCM_old ]; then
+            echo "The number of PCM runs between each PEM run has been modified from $nPCM_old to $nPCM."
+        fi
+        if [ $n_myear -ne $n_myear_old ]; then
+            echo "The number of initial PCM runs has been modified from $n_myear_old to $n_myear."
+        fi
+        sed -i "1s/.*/$i_myear $n_myear $convert_years $iPCM $iPEM $nPCM $nPCM_ini/" info_PEM.txt
         if [ $relaunch = "PCM" ]; then
             relaunchPCM
Index: /trunk/LMDZ.COMMON/libf/evolution/deftank/lib_launchPEM.sh
===================================================================
--- /trunk/LMDZ.COMMON/libf/evolution/deftank/lib_launchPEM.sh	(revision 3385)
+++ /trunk/LMDZ.COMMON/libf/evolution/deftank/lib_launchPEM.sh	(revision 3386)
@@ -108,7 +108,6 @@
 }
 
-# To initialize the launching script
-initlaunch() {
-    echo "This is a chained simulation for PEM and PCM runs in $dir on $machine by $user."
+# To convert Earth years into Mars years
+convertyears() {
     myear=686.9725      # Number of Earth days in Martian year
     eyear=365.256363004 # Number of days in Earth year
@@ -122,4 +121,10 @@
         echo "Number of years to be simulated: $n_earth_years Earth years = $n_myear Martian years."
     fi
+}
+
+# To initialize the launching script
+initlaunch() {
+    echo "This is a chained simulation for PEM and PCM runs in $dir on $machine by $user."
+    convertyears
     i_myear=0
     iPEM=1
@@ -137,4 +142,6 @@
 
 # To submit the PCM runs
+# arg1: number of PCM runs to launch
+# arg2: local number of the PCM run from which to start (optional)
 submitPCM() {
     find . -type f -name "jobPCM*.slurm" ! -name "jobPCM.slurm" -delete
@@ -191,4 +198,6 @@
 
 # To make one cycle of PCM and PEM runs
+# arg1: number of PCM runs to launch
+# arg2: local number of the PCM run from which to start (optional)
 cyclelaunch() {
     # PCM runs
@@ -207,4 +216,7 @@
 
 # To clean files after the starting run of the relaunch
+# arg1: file name prefix to clean
+# arg2: file name extension to clean
+# arg3: file number from which to clean
 cleanfiles() {
     prefix=$1
@@ -232,4 +244,5 @@
     iPCM=$(($irelaunch + 1))
     cleanfiles diags/diagfi .nc $irelaunch
+    cleanfiles diags/data2reshape .nc $irelaunch
     cleanfiles "out_PCM/run" "" $irelaunch
     cleanfiles starts/restart1D .txt $irelaunch
@@ -256,13 +269,10 @@
         if [ $irelaunch -eq $(($nPCM_ini - 1)) ]; then
             cp diags/data2reshape${irelaunch}.nc data2reshape_Y1.nc
-            cleanfiles diags/data2reshape .nc $irelaunch
             cyclelaunch $nPCM_ini $irelaunch
         elif [ $irelaunch -eq $nPCM_ini ]; then
             cp diags/data2reshape$(($irelaunch - 1)).nc data2reshape_Y1.nc
             cp diags/data2reshape${irelaunch}.nc data2reshape_Y2.nc
-            cleanfiles diags/data2reshape .nc $(($irelaunch - 1))
             submitPEM # The next job is a PEM run
         else
-            cleanfiles diags/data2reshape .nc 0
             cyclelaunch $nPCM_ini $iPCM
         fi
@@ -282,5 +292,4 @@
             sed -i "1s/.*/$i_myear $n_myear $convert_years $iPCM $iPEM $nPCM $nPCM_ini/" info_PEM.txt
             cp diags/data2reshape${irelaunch}.nc data2reshape_Y1.nc
-            cleanfiles diags/data2reshape .nc $irelaunch
             cyclelaunch $nPCM $il
         elif [ $il -eq 0 ]; then
@@ -289,10 +298,8 @@
             cp diags/data2reshape$(($irelaunch - 1)).nc data2reshape_Y1.nc
             cp diags/data2reshape${irelaunch}.nc data2reshape_Y2.nc
-            cleanfiles diags/data2reshape .nc $(($irelaunch - 1))
             submitPEM # The next job is a PEM run
         else
             i_myear=$(($(awk "NR==$iPEM {print \$1}" "info_PEM.txt") + $il))
             sed -i "1s/.*/$i_myear $n_myear $convert_years $iPCM $iPEM $nPCM $nPCM_ini/" info_PEM.txt
-            cleanfiles diags/data2reshape .nc $irelaunch
             cyclelaunch $nPCM $il
         fi
Index: /trunk/LMDZ.COMMON/libf/evolution/pem.F90
===================================================================
--- /trunk/LMDZ.COMMON/libf/evolution/pem.F90	(revision 3385)
+++ /trunk/LMDZ.COMMON/libf/evolution/pem.F90	(revision 3386)
@@ -99,5 +99,5 @@
     use control_mod,              only: iphysiq, day_step, nsplit_phys
 #else
-    use time_phylmdz_mod,         only: iphysiq, day_step
+    use time_phylmdz_mod,         only: iphysiq, steps_per_sol
     use regular_lonlat_mod,       only: init_regular_lonlat
     use physics_distribution_mod, only: init_physics_distribution
@@ -263,4 +263,5 @@
     integer            :: nsplit_phys
     integer, parameter :: jjm_value = jjm - 1
+    integer            :: day_step
 
     ! Dummy variables to use the subroutine 'init_testphys1d'
@@ -342,4 +343,5 @@
 #ifndef CPP_1D
     dtphys = daysec/48. ! Dummy value (overwritten in phyetat0)
+    day_step = steps_per_sol
     call conf_gcm(99,.true.)
     call infotrac_init
