Index: /trunk/LMDZ.COMMON/libf/evolution/recomp_orb_param_mod.F90
===================================================================
--- /trunk/LMDZ.COMMON/libf/evolution/recomp_orb_param_mod.F90	(revision 3022)
+++ /trunk/LMDZ.COMMON/libf/evolution/recomp_orb_param_mod.F90	(revision 3023)
@@ -41,8 +41,8 @@
 !--------------------------------------------------------
 
-      real :: Year	                ! Year of the simulation
-      real :: Lsp	        ! time of peri in ls
-      integer ilask			! Loop variable
-      real :: halfaxe                   ! Million of km
+      real :: Year     ! Year of the simulation
+      real :: Lsp      ! time of peri in ls
+      integer ilask    ! Loop variable
+      real :: halfaxe  ! Million of km
       real :: unitastr
 
Index: /trunk/LMDZ.MARS/changelog.txt
===================================================================
--- /trunk/LMDZ.MARS/changelog.txt	(revision 3022)
+++ /trunk/LMDZ.MARS/changelog.txt	(revision 3023)
@@ -4160,2 +4160,5 @@
 == 1/08/2023 == JBC
 Rework and correction of computation of the maximum number of iterations for PEM according to orbital parameters.
+
+== 1/08/2023 == JBC
+Complete rewriting (much simpler) of script "run_pem1d_1" in deftank/pem/ to launch chained simulations of 1D PCM/PEM. To be adapted to 3D in the future.
Index: /trunk/LMDZ.MARS/deftank/pem/run_pem1d_1
===================================================================
--- /trunk/LMDZ.MARS/deftank/pem/run_pem1d_1	(revision 3022)
+++ /trunk/LMDZ.MARS/deftank/pem/run_pem1d_1	(revision 3023)
@@ -25,105 +25,144 @@
 
 # A few parameters that might need be changed depending on your setup:
-# Path to the arch.env to source
+# Path to the arch.env to source:
 source ../trunk/LMDZ.COMMON/arch.env
-# Number of threads to use (must be the same as "#MSUB -c" above) 
-export OMP_NUM_THREADS=1
-export OMP_STACKSIZE=400M
 
-#------------------Modify here the number of PEM call----------------------
+#------------------ Modify here the name of PEM exe --------------------
+## fill in the name of executable for PEM:
+exePEM=pem_29_phymars_seq.e
 
-## set starting PEM first and last number call: 
-num_PEM_now=1
-num_PEM_end=20
-(( num_PEM_previous = $num_PEM_now - 1 ))
+#------------------ Modify here the name of GCM exe --------------------
+## fill in the name of executable for GCM:
+exeGCM=testphys1d_29_phymars_para.e
 
-#-----------------Modify here the number of GCM call between each PEM ---------
+#-------------- Modify here the name of reshape XIOS exe ---------------
+## fill in the name of executable for reshape XIOS:
+exeReshape=reshape_XIOS_output_64x48x29_phymars_seq.e
 
-## set number of GCM call between each PEM call: 
-nb_GCM_call=2
+#---------------- Modify here the number of PEM calls ------------------
+## set the number of PEM calls:
+nPEM=1000
 
-#----------------Here we launch GCM call year by year ---------
+#---------------- Modify here the number of GCM calls ------------------
+## set the number of GCM calls between each PEM call:
+nGCM=2
 
-(( num_GCM_now = ($num_PEM_now - 1)* $nb_GCM_call + 1 ))
-(( num_GCM_previous = $num_GCM_now - 1 ))
-(( num_GCM_end = $num_GCM_previous + $nb_GCM_call ))
 
-echo "num_GCM_now $num_GCM_now"
-echo "num_GCM_previous $num_GCM_previous"
-echo "num_GCM_end $num_GCM_end"
 
-echo "$num_GCM_previous" > num_run
-
-  \cp -f startfi$num_GCM_previous.nc startfi.nc
-  ./testphys1d_29_phymars_seq.e > lrun$num_GCM_now 2>&1
-  \cp -f diagfi.nc diagfi$num_GCM_now.nc
-  \cp -f diagfi.nc data2reshape1.nc
-  \cp -f restartfi.nc startfi${num_GCM_now}.nc
-  \cp -f restartfi.nc startfi.nc
-
-  ./testphys1d_29_phymars_seq.e > lrun$num_GCM_end 2>&1
-  \cp -f diagfi.nc diagfi$num_GCM_end.nc
-  \cp -f diagfi.nc data2reshape2.nc
-  \cp -f restartfi.nc startfi${num_GCM_end}_GCM.nc
-  \cp -f restartfi.nc startfi_evol.nc
-
-#--------------- We reshape the GCM data from XIOS-------------------
-
-rm -rf datareshaped1.nc
-rm -rf datareshaped2.nc
-
-./reshape_XIOS_output_32x24x27_phymars_seq.e
-
-#---------------- We rename files for the PEM call----------------
-
-cp datareshaped1.nc data_GCM_Y1.nc
-echo "y"
-cp datareshaped2.nc data_GCM_Y2.nc
-echo "y"
-
-#--------------- We run the PEM ------------------
-
-if [[ -r run.def_PEM ]] ; then
-  cp run.def_PEM run.def
-  echo "y"
+#--------- Check if files/directories exist to be able to run ----------
+echo Starting script to call PEM with GCM!
+if [ ! -d "profiles" ]; then
+    mkdir profiles
+else
+    rm profiles/*
 fi
-if [[ -r diagfi.def_PEM ]] ; then
-  cp diagfi.def_PEM diagfi.def
-  echo "y"
+if [ ! -d "diagfis" ]; then
+    mkdir diagfis
+else
+    rm diagfis/*
+fi
+if [ ! -d "startfis" ]; then
+    mkdir startfis
+else
+    rm startfis/*
+fi
+if [ ! -r "context_lmdz_physics.xml" ]; then
+    echo File context_lmdz_physics.xml does not exist!
+    exit 0
+fi
+if [ ! -r "field_def_physics_mars.xml" ]; then
+    echo File field_def_physics_mars.xml does not exist!
+    exit 0
+fi
+if [ ! -r "file_def_physics_mars.xml" ]; then
+    echo File file_def_physics_mars.xml does not exist!
+    exit 0
+fi
+if [ ! -r "iodef.xml" ]; then
+    echo File iodef.xml does not exist!
+    exit 0
+fi
+if [ ! -r "run_PEM.def" ]; then
+    echo File diagfi_PEM.def does not exist!
+    exit 0
+fi
+if [ ! -r "run_GCM.def" ]; then
+    echo File diagfi_GCM.def does not exist!
+    exit 0
+fi
+if [ ! -r "run_PEM.def" ]; then
+    echo File diagfi_PEM.def does not exist!
+    exit 0
+fi
+if [ ! -r "run_GCM.def" ]; then
+    echo File diagfi_GCM.def does not exist!
+    exit 0
 fi
 
-./pem_29_phymars_seq.e > PEMrun${num_PEM_now} 2>&1
+#---------------------------- Initialization ---------------------------
+iPEM=1
+((iGCM = ($iPEM - 1)*$nGCM + 1))
+cp startfi.nc startfis/
+cp startfi_PEM.nc startfis/
+for file in profile_*; do
+    cp $file profiles/${file}_0
+done
 
-if [[ -r run.def_GCM ]] ; then
-  cp run.def_GCM run.def
-  echo "y"
-fi
-if [[ -r diagfi.def_GCM ]] ; then
-  cp diagfi.def_GCM diagfi.def
-  echo "y"
-fi
+#---------------------- Main loop to call PEM/GCM ----------------------
+while [ $iPEM -le $nPEM ]; do
+    #--- Loop to run GCM year by year
+    cp run_GCM.def run.def
+    cp diagfi_GCM.def diagfi.def
+    for ((i = 1; i <= $nGCM; i++)); do
+        echo Run GCM $iGCM: call $i out of $nGCM...
+        ./$exeGCM > lrun${iGCM} 2>&1
+        mv diagfi.nc diagfis/diagfi${iGCM}.nc
+	cp Xdiurnalave.nc diagfis/Xdiurnalave${iGCM}.nc
+        mv Xdiurnalave.nc data2reshape${i}.nc
+        cp restartfi.nc startfis/startfi${iGCM}.nc
+        mv restartfi.nc startfi.nc
+        for file in profile_out_*; do
+            cp $file profiles/${file/_out/}_${iGCM}
+            mv $file ${file/_out/}
+        done
+        ((iGCM++))
+        echo Done!
+    done
+    #--- Reshaping GCM data with XIOS
+    echo Reshaping GCM data with XIOS...
+    for i in $(ls datareshaped*); do
+        rm $i
+    done
+    ./$exeReshape
+    for file in datareshaped*; do
+        mv $file ${file/reshaped/_GCM_Y}
+    done
+    echo Done!
+     #--- Running PEM
+    echo Run PEM $iPEM...
+    cp run_PEM.def run.def
+    cp diagfi_PEM.def diagfi.def
+    mv startfi.nc startfi_evol.nc
+    ./$exePEM > mrun${iPEM} 2>&1
+    mv diagfi.nc diagfis/diagfi_PEM${iPEM}.nc
+    cp restartfi_evol.nc startfis/startfi_postPEM${iPEM}.nc
+    mv restartfi_evol.nc startfi.nc
+    cp restartfi_PEM.nc startfis/startfi_PEM${iPEM}.nc
+    mv restartfi_PEM.nc startfi_PEM.nc
+    for file in profile_out_*; do
+        cp $file profiles/${file/_out/}PEM_${iPEM}
+        mv $file ${file/_out/}
+    done
+    mv info_run_PEM.txt info_run_PEM${iPEM}.txt
+    ((iPEM++))
+    echo Done!
+done
 
-#--------------- We rename PEM output ------------------
+#---------------------- Preparation for relaunch  ----------------------
+echo Reinitializing starting files...
+cp startfis/startfi.nc .
+for file in profiles/*_0; do
+    cp $file ${file/_0/}
+done
 
-cp restartfi_evol.nc startfi${num_GCM_end}_post_PEM.nc
-echo "y"
-cp restartfi_evol.nc startfi${num_GCM_end}.nc
-echo "y"
-
-(( num_PEM_next = $num_PEM_now + 1 ))
-
-if [[ -r diagfi.nc ]] ; then
-  \mv -f diagfi.nc diagfi${num_PEM_now}_PEM.nc
-fi
-
-#------------------- Launch the next PEM call------------------
-
-# launch job for next month
-if (( $num_PEM_next <= $num_PEM_end )) ; then
-  cp -f run_pem1d_$num_PEM_now tmp
-  sed -e "s@run_pem1d_${num_PEM_now}@run_pem1d_${num_PEM_next}@" \
-      -e "s@num_PEM_now=${num_PEM_now}@num_PEM_now=${num_PEM_next}@" tmp > run_pem1d_$num_PEM_next
-  rm tmp
-  
-  ccc_msub run_pem1d_$num_PEM_next
-fi
+echo Script finished.
