source: trunk/LMDZ.MARS/deftank/pem/launch_pem.sh @ 3136

Last change on this file since 3136 was 3136, checked in by jbclement, 15 months ago

PEM:
Update of files in the deftank: addition of variables in the xml definition files, inclusion of "callphys.def" into "run_PEM.def" and minor typo in "launch_pem.sh".
JBC

  • Property svn:executable set to *
File size: 6.6 KB
Line 
1#!/bin/bash
2#####################################################################
3### Launching script for a chained simulation of PEM and PCM runs ###
4#####################################################################
5
6echo "The launching script is starting!"
7echo "The output file is \"loglaunch.txt\"."
8if [ "$1" = "bg" ]; then
9    date
10else
11    nohup "$0" bg > loglaunch.txt 2>&1 &
12    exit 1
13fi
14
15# A few parameters that might need be changed depending on your setup:
16# Path to the arch.env to source:
17source ../trunk/LMDZ.COMMON/arch.env
18
19# Save the current value of LC_NUMERIC and set it to a locale that uses a dot as the decimal separator
20OLD_LC_NUMERIC=$LC_NUMERIC
21LC_NUMERIC=en_US.UTF-8
22
23#---------- Modify here the number of years to be simulated ------------
24## set the number of years, either Martian or Earth years:
25n_mars_years=1000000
26#n_earth_years=1000000
27
28#---------------- Modify here the number of PCM calls ------------------
29## set the number of PCM calls between each PEM call:
30nPCM=2
31
32#------------------ Modify here the name of PEM exe --------------------
33## fill in the name of executable for PEM:
34exePEM=pem_29_phymars_seq.e
35
36#-------------- Modify here the name of reshape XIOS exe ---------------
37## fill in the name of executable for reshape XIOS:
38exeReshape=reshape_XIOS_output_64x48x29_phymars_seq.e
39
40#------------------------------ Parameters -----------------------------
41myear=686.9725      # Number of Earth days in Martian year
42eyear=365.256363004 # Number of days in Earth year
43
44#------ Check if files/directories necessary for the script exist ------
45dir=`pwd`
46machine=`hostname`
47address=`whoami`
48if [ ! -f "exePCM.sh" ]; then
49    echo "Error: file \"exePCM.sh\" does not exist in $dir!"
50    exit 1
51fi
52if [ ! -f "run_PEM.def" ]; then
53    echo "Error: file \"run_PEM.def\" does not exist in $dir!"
54    exit 1
55fi
56if [ ! -f "run_PCM.def" ]; then
57    echo "Error: file \"run_PCM.def\" does not exist in $dir!"
58    exit 1
59fi
60if [ ! -f "context_lmdz_physics.xml" ]; then
61    echo "Error: file \"context_lmdz_physics.xml\" does not exist in $dir!"
62    exit 1
63fi
64if [ ! -f "field_def_physics_mars.xml" ]; then
65    echo "Error: file \"field_def_physics_mars.xml\" does not exist in $dir!"
66    exit 1
67fi
68if [ ! -f "file_def_physics_mars.xml" ]; then
69    echo "Error: file \"file_def_physics_mars.xml\" does not exist in $dir!"
70    exit 1
71fi
72if [ ! -f "iodef.xml" ]; then
73    echo "Error: file \"iodef.xml\" does not exist in $dir!"
74    exit 1
75fi
76if [ ! -d "out_PCM" ]; then
77    mkdir out_PCM
78fi
79if [ ! -d "out_PEM" ]; then
80    mkdir out_PEM
81fi
82if [ ! -d "starts" ]; then
83    mkdir starts
84fi
85if [ ! -d "diags" ]; then
86    mkdir diags
87fi
88
89#---------------------------- Initialization ---------------------------
90dir=`pwd`
91machine=`hostname`
92address=`whoami`
93echo "This is a chained simulation for PEM and PCM runs in $dir on $machine."
94convert_years=$(echo "$myear/$eyear" | bc -l)
95convert_years=$(printf "%.4f" $convert_years) # Rounding to the 4th decimal to respect the precision of Martian year
96if [ -v n_mars_years ] && [ ! -z "$n_mars_years" ]; then
97    n_myear=$n_mars_years
98    echo "Number of years to be simulated: $n_myear Martian years."
99elif [ -v n_earth_years ] && [ ! -z "$n_earth_years" ]; then
100    n_myear=$(echo "($n_earth_years/$convert_years + 0.999999)/1" | bc) # Ceiling of n_earth_years/convert_years
101    echo "Number of years to be simulated: $n_earth_years Earth years = $n_myear Martian years."
102else
103    echo "No number of years to be simulated has been set!"
104    exit 1
105fi
106i_myear=0
107iPEM=1
108((iPCM = ($iPEM - 1)*$nPCM + 1))
109cp startfi.nc starts/
110if [ -f "start.nc" ]; then
111    cp start.nc starts/
112fi
113
114# Create a file to manage years of the chained simulation and store some info from the PEM runs
115if [ -f "info_PEM.txt" ]; then
116    rm info_PEM.txt
117fi
118echo $i_myear $n_myear $convert_years > info_PEM.txt
119
120#---------------------- Main loop to call PEM/PCM ----------------------
121while [ $i_myear -lt $n_myear ]; do
122    #--- Loop to run PCM year by year
123    cp run_PCM.def run.def
124    for ((i = 1; i <= $nPCM; i++)); do
125        echo "Run PCM $iPCM: call $i/$nPCM..."
126        sed -i "s/#SBATCH --job-name=runPCM.*/#SBATCH --job-name=runPCM${iPCM}/" exePCM.sh
127        sed -i "s/out_runPCM[0-9]\+/out_runPCM${iPCM}/" exePCM.sh
128        sbatch -W exePCM.sh
129        if [ ! -f "restartfi.nc" ]; then # Check if run ended abnormally
130            echo "Error: the run PCM $iPCM has crashed!"
131            exit 1
132        fi
133        # Copy data files and prepare the next run
134        mv out_runPCM${iPCM} out_PCM/run${iPCM}
135        mv diagfi.nc diags/diagfi${iPCM}.nc
136        if [ -f "diagsoil.nc" ]; then
137            mv diagsoil.nc diags/diagsoil${iPCM}.nc
138        fi
139        if [ -f "stats.nc" ]; then
140            mv stats.nc diags/stats${iPCM}.nc
141        fi
142        cp Xdiurnalave.nc diags/data2reshape${iPCM}.nc
143        mv Xdiurnalave.nc data2reshape${i}.nc
144        cp restartfi.nc starts/startfi${iPCM}.nc
145        mv restartfi.nc startfi.nc
146        if [ -f "restart.nc" ]; then
147            cp restart.nc starts/restart${iPCM}.nc
148            mv restart.nc start.nc
149        elif [ -f "restart1D.txt" ]; then
150            cp restart1D.txt starts/restart1D${iPCM}.txt
151            mv restart1D.txt start1D.txt
152        fi
153        ((iPCM++))
154        ((i_myear++))
155        echo "Done!"
156    done
157    sed -i "1s/.*/$i_myear $n_myear $convert_years/" info_PEM.txt
158
159    #--- Reshaping PCM data with XIOS
160    echo "Reshaping PCM data with XIOS..."
161    ./$exeReshape
162    echo "Done!"
163
164    #--- Running PEM
165    echo "Run PEM $iPEM..."
166    cp run_PEM.def run.def
167    mv startfi.nc startfi_evol.nc
168    if [ -f "start.nc" ]; then
169        mv start.nc start_evol.nc
170    elif [ -f "start1D.txt" ]; then
171        mv start1D.txt start1D_evol.txt
172    fi
173    ./$exePEM > out_runPEM${iPEM} 2>&1
174    if [ ! -f "restartfi_evol.nc" ]; then # Check if run ended abnormally
175        echo "Error: the run PEM $iPEM has crashed!"
176        exit 1
177    fi
178    # Copy data files and prepare the next run
179    mv out_runPEM${iPEM} out_PEM/run${iPEM}
180    mv diagpem.nc diags/diagpem${iPEM}.nc
181    cp restartpem.nc starts/startpem${iPEM}.nc
182    mv restartpem.nc startpem.nc
183    cp restartfi_evol.nc starts/startfi_postPEM${iPEM}.nc
184    mv restartfi_evol.nc startfi.nc
185    if [ -f "restart_evol.nc" ]; then
186        cp restart_evol.nc starts/restart_postPEM${iPEM}.nc
187        mv restart_evol.nc start.nc
188    elif [ -f "restart1D_evol.txt" ]; then
189        cp restart1D_evol.txt starts/restart1D_postPEM${iPEM}.txt
190        mv restart1D_evol.txt start1D.txt
191    fi
192    ((iPEM++))
193    read i_myear n_myear convert_years < info_PEM.txt
194    echo "Done!"
195done
196
197# Restore the previous value of LC_NUMERIC
198LC_NUMERIC=$OLD_LC_NUMERIC
199
200date
201echo "The launching script has terminated."
Note: See TracBrowser for help on using the repository browser.