source: trunk/LMDZ.COMMON/libf/evolution/deftank/launch_pem.sh @ 3210

Last change on this file since 3210 was 3210, checked in by jbclement, 22 months ago

PEM:

  • Addition in the deftank of a bash script "modify_startfi_var.sh" to modify the value of a variable in a "startfi.nc".
  • Small corrections due to r3206.

JBC

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