1 | #!/bin/bash |
---|
2 | # This script sets up and launches a (series of) simulation(s). |
---|
3 | # RECOMMENDATION: use main.sh to drive it (do not run it directly) |
---|
4 | |
---|
5 | set -eu |
---|
6 | |
---|
7 | #--------------------------------------------------------------------------- |
---|
8 | function define_expert_options() { # Expert-level choices |
---|
9 | #--------------------------------------------------------------------------- |
---|
10 | |
---|
11 | # optim: either "" or "-debug" to compile in debug mode |
---|
12 | # (slower but better diagnosis of segfaults) |
---|
13 | optim="" |
---|
14 | |
---|
15 | # "n" or "y". If testmode="y", then simulations run for a single day |
---|
16 | # per period. |
---|
17 | # NOTE: you must set mthend accordingly ! |
---|
18 | testmode="n" |
---|
19 | |
---|
20 | # Radiative code: "oldrad" / "rrtm" / "ecrad" |
---|
21 | rad="rrtm" |
---|
22 | |
---|
23 | # !!! STRONG recommendation : experiments with DIFFERENT Orchidee or |
---|
24 | # aerosol options should be performed in DIFFERENT LMDZ_Setup folders |
---|
25 | # !!! (especially as they may need different initial files) |
---|
26 | |
---|
27 | # AEROSOLS : "n" (=no)/"clim" (=average 1995-2014) / "spla" (interactive) |
---|
28 | # (WARNING : if you first run the scripts with aerosols=n, then you want |
---|
29 | # to change to =clim, you must remove the INIT and LIMIT folders and |
---|
30 | # rerun main.sh with init=1 in order to create aerosol files |
---|
31 | |
---|
32 | aerosols="clim" |
---|
33 | |
---|
34 | # SURFACE/VEGETATION SCHEME |
---|
35 | # - "none" : bucket scheme |
---|
36 | # CMIP6 : orchidee CMIP6 version |
---|
37 | # 7983/7994 : orchidee svn release 7983 (orch2.2) and 7994 (last tested) |
---|
38 | # If you need other orch versions, and also require XIOS, you'll need |
---|
39 | # to create the appropriate files in DEF/XMLfilesOR... |
---|
40 | veget="CMIP6" |
---|
41 | |
---|
42 | # New snow scheme INLANDSIS! "y" / "n" |
---|
43 | # Activates INLANDSIS compilation |
---|
44 | # to be done : treatment of specific restart and def file |
---|
45 | inlandsis="n" |
---|
46 | |
---|
47 | # netcdf: 0 (use existing library) / 1 (recompile netcdf, slow) |
---|
48 | netcdf=0 |
---|
49 | |
---|
50 | # --->>> ALSO PAY ATTENTION TO OUTPUT files, frequency, level ------------ |
---|
51 | # With IOIPSL : Choose your config.def among versions available in DEF, |
---|
52 | # copy it as config.def (the copy is done automatically for "iso"), |
---|
53 | # edit it and set up output files, frequencies and levels. |
---|
54 | # NB : For aerosols=spla, output level minimum 4 is required to outpu |
---|
55 | # the specific variables. |
---|
56 | # For aerosols=n, aerosol flags will automatically be set to "n". |
---|
57 | # With XIOS : adjust DEF/XMLfiles*/file*xml |
---|
58 | } |
---|
59 | |
---|
60 | |
---|
61 | #--------------------------------------------------------------------------- |
---|
62 | function enable_platform() { # Sed platform-specific headers |
---|
63 | #--------------------------------------------------------------------------- |
---|
64 | local file="$1" |
---|
65 | local platform |
---|
66 | |
---|
67 | case ${hostname:0:5} in |
---|
68 | jean-) platform="JZ";; |
---|
69 | spiri) platform="SP";; |
---|
70 | adast) platform="ADS";; |
---|
71 | *) echo "Warning: $hostname is not a known job platform (ignore if running locally)"; return 0;; |
---|
72 | esac |
---|
73 | |
---|
74 | sed -i'' -e "s/^#@$platform//" "$file" |
---|
75 | } |
---|
76 | |
---|
77 | #--------------------------------------------------------------------------- |
---|
78 | function load_install_lib() { #Fetch and source install_lmdz.sh to get myget |
---|
79 | #--------------------------------------------------------------------------- |
---|
80 | if [[ ! -f "install_lmdz.sh" ]]; then |
---|
81 | wget --no-cache "http://svn.lmd.jussieu.fr/LMDZ/BOL/script_install/install_lmdz.sh" |
---|
82 | fi |
---|
83 | # shellcheck disable=SC1090 |
---|
84 | source <(sed 's/function \(.*\) {/function installlmdz_\1 {/g' install_lmdz.sh) # source with a namespace for functions |
---|
85 | function myget { installlmdz_myget "$@"; } |
---|
86 | } |
---|
87 | |
---|
88 | #--------------------------------------------------------------------------- |
---|
89 | function set_default_params() { # Default value of script parameters |
---|
90 | #--------------------------------------------------------------------------- |
---|
91 | |
---|
92 | SIM=$(basename "$local")CTL # name |
---|
93 | phylmd="lmd" #option -p $phylmd for makelmdz |
---|
94 | |
---|
95 | cosp="n" # COSP |
---|
96 | xios="n" #XIOS |
---|
97 | |
---|
98 | # Nudging : |
---|
99 | ok_guide="n" |
---|
100 | # With nudging, use real calendar (climato=0) and monthly integrations |
---|
101 | climato=1 |
---|
102 | freq="mo" # frequence mensuelle mo ou annuelle yr |
---|
103 | |
---|
104 | # NB : the run stops in the BEGINNING of mthend (test "next=stopsim") |
---|
105 | mthini=200001 |
---|
106 | mthend=200501 |
---|
107 | resol="144x142x79" |
---|
108 | |
---|
109 | version="20230412.trunk" |
---|
110 | svn="" |
---|
111 | |
---|
112 | init=1 |
---|
113 | |
---|
114 | LIMIT="LIMIT" |
---|
115 | |
---|
116 | } |
---|
117 | |
---|
118 | #--------------------------------------------------------------------------- |
---|
119 | function read_cmdline_args() { |
---|
120 | #--------------------------------------------------------------------------- |
---|
121 | while (($# > 0)); do |
---|
122 | case $1 in |
---|
123 | "-h") cat <<........fin |
---|
124 | setup.sh can be launched/driven by main.sh |
---|
125 | setup.sh [-v version] [-r svn_release] [-init INIT] [-d 96x95x79] [-f mo] [-nudging] |
---|
126 | -v "version" like 20150828.trunk; see https://lmdz.lmd.jussieu.fr/Distrib/LISMOI.trunk (default <$version>) |
---|
127 | -r "svn_release" either the svn release number or "last" (default <$svn>) |
---|
128 | -d IMxJMxLM to run in resolution IM x JM x LM (default <$resol>) |
---|
129 | -install pour installer et compiler le modele |
---|
130 | -f mo/yr pour tourner en mensuel ou annuel (default <$freq>) |
---|
131 | -rad RAD Radiation |
---|
132 | -netcdf 0/1/DIR Netcdf installation |
---|
133 | -aerosols n/clim/spla Aerosols : none / climatological / interactive with SPLA |
---|
134 | -veget CMIP6 CMIP6 version of rchidee |
---|
135 | 7983 orch2.2 |
---|
136 | 7994 trunk |
---|
137 | "INIT" 1: creates INIT and LIMIT |
---|
138 | 0: reads from INIT and LIMIT |
---|
139 | SIMU: reads from preexisting simulation SIMU and LIMIT (default <$init>) |
---|
140 | -nudging to run with nudging. Nudging files must be created independently |
---|
141 | -p the physics to use (default <$phylmd>) |
---|
142 | -name install folder name (default <$SIM>) |
---|
143 | Other options available (see "options" section in the script) |
---|
144 | ........fin |
---|
145 | exit;; |
---|
146 | "-v") version="$2"; shift; shift;; |
---|
147 | "-r") svn=$2; shift; shift;; |
---|
148 | "-d") resol=$2; shift; shift;; |
---|
149 | "-f") freq=$2; shift; shift;; |
---|
150 | "-p") phylmd=$2; shift; shift;; |
---|
151 | "-name") SIM=$2; shift; shift;; |
---|
152 | "-rad") rad=$2; shift; shift;; |
---|
153 | "-netcdf") netcdf=$2; shift; shift;; |
---|
154 | "-aerosols") aerosols=$2; shift; shift;; |
---|
155 | "-veget") veget=$2; shift; shift;; |
---|
156 | "-cosp") cosp=y; shift;; |
---|
157 | "-xios") xios=y; shift;; |
---|
158 | "-init") init=$2; shift; shift;; |
---|
159 | "-nudging") ok_guide=y; shift;; |
---|
160 | "-climato") climato=$2; shift; shift;; |
---|
161 | "-mthini") mthini=$2; shift; shift;; |
---|
162 | "-mthend") mthend=$2; shift; shift;; |
---|
163 | *) echo "unexpected $1"; $0 -h; exit |
---|
164 | esac |
---|
165 | done |
---|
166 | |
---|
167 | # Initialisation |
---|
168 | if [[ $init = 1 || $init = 0 ]]; then |
---|
169 | INIT="INIT" |
---|
170 | else |
---|
171 | INIT=$init |
---|
172 | fi |
---|
173 | |
---|
174 | case $rad in |
---|
175 | oldrad) iflag_rrtm=0; NSW=2;; |
---|
176 | rrtm) iflag_rrtm=1; NSW=6;; |
---|
177 | ecrad) iflag_rrtm=2; NSW=6;; |
---|
178 | esac |
---|
179 | |
---|
180 | im=$(echo "$resol" | cut -dx -f1) |
---|
181 | jm=$(echo "$resol" | cut -dx -f2) |
---|
182 | lm=$(echo "$resol" | cut -dx -f3) |
---|
183 | |
---|
184 | yearini=$(echo "$mthini" | cut -c-4) |
---|
185 | if [[ $freq = yr ]]; then stopsim=$(echo "$mthend" | cut -c-4); else stopsim=$mthend; fi |
---|
186 | |
---|
187 | if [[ -d $SIM ]]; then |
---|
188 | echo "La simulation $SIM existe deja. Il est conseillé d'arrêter et de vérifier." |
---|
189 | echo "Si vous êtes sûr de vous, vous pouvez la prolonger. Voulez vous la prolonger ? (y/n)" |
---|
190 | read -r ans |
---|
191 | if [[ $ans != y ]]; then exit 1; fi |
---|
192 | fi |
---|
193 | |
---|
194 | ###################################################################### |
---|
195 | # Choix du nombre de processeurs |
---|
196 | # NOTES : |
---|
197 | # omp=8 by default (for Jean-Zay must be a divisor of 40 procs/node) |
---|
198 | # omp=1 : required for SPLA (omp parallelism not ready) |
---|
199 | # omp=2 for veget=CMIP6+XIOS beacause of a bug in ORCHIDEE/src_xml/xios_orchidee.f90 |
---|
200 | ###################################################################### |
---|
201 | (( mpi = ( jm + 1 ) / 2 )) |
---|
202 | omp=8 |
---|
203 | if [[ $aerosols = "spla" ]]; then omp=1; fi |
---|
204 | if [[ $veget = "CMIP6" && $xios = "y" ]]; then omp=2; fi |
---|
205 | if [[ $mpi -gt $NB_MPI_MAX ]]; then mpi=$NB_MPI_MAX; fi |
---|
206 | if [[ $omp -gt $NB_OMP_MAX ]]; then omp=$NB_OMP_MAX; fi |
---|
207 | |
---|
208 | # Compute how many mpi per node (required e.g. for Adastra) |
---|
209 | mpi_per_node=0 |
---|
210 | if [[ $NB_CORE_PER_NODE_MAX -gt 0 ]]; then |
---|
211 | local N_omp_mt=1 |
---|
212 | if [[ $omp -gt 1 ]]; then (( N_omp_mt = omp / N_HYPERTHREADING )); fi # take into account hyperthreading |
---|
213 | (( mpi_per_node = NB_CORE_PER_NODE_MAX / N_omp_mt )) |
---|
214 | if [[ mpi_per_node -gt mpi ]]; then mpi_per_node=$mpi; fi |
---|
215 | fi |
---|
216 | |
---|
217 | echo "Total MPI=$mpi (PER NODE=$mpi_per_node), OMP=$omp" |
---|
218 | } |
---|
219 | |
---|
220 | #--------------------------------------------------------------------------- |
---|
221 | function ensure_correct_option_combinations() { |
---|
222 | # AVOID COMBINATIONS OF OPTIONS THAT DON'T WORK in user choices |
---|
223 | #--------------------------------------------------------------------------- |
---|
224 | if [[ $ok_guide = y && $climato = 1 ]]; then |
---|
225 | echo "STOP: Running nudged simulations with climatological SSTs is not planned. Change <climato> to <0> or modify the setup (experts)"; exit 1 |
---|
226 | fi |
---|
227 | |
---|
228 | if [[ $climato = 0 && $freq = "yr" ]]; then |
---|
229 | echo "STOP: Running simulations with interannual SSTs is possible only month by month and a true calendar." |
---|
230 | echo "Change <climato> to <1> or <freq> to <mo> or modify setup.sh (experts)"; exit 1 |
---|
231 | fi |
---|
232 | |
---|
233 | |
---|
234 | # (Temporary) Constraints for aerosols=spla : |
---|
235 | # --> resolution 128x88x79 and rad=rrtm |
---|
236 | if [[ $aerosols = "spla" && ( ${im}x${jm} != "128x88" || $freq != mo ) ]]; then |
---|
237 | echo 'STOP: For now, <aerosols=spla> requires <resol=128x88x79>,' |
---|
238 | echo 'and uses the zoomed grid from gcm.def_zNAfrica_BiJe,' |
---|
239 | echo 'for which forcing & initial files are available' |
---|
240 | echo "Right now resol=<$resol>" |
---|
241 | echo 'Should be run in monthly mode' |
---|
242 | exit 1 |
---|
243 | fi |
---|
244 | |
---|
245 | if [[ $rad = "ecrad" && $phylmd != "lmd" ]]; then |
---|
246 | echo "<rad=ecrad> is only supported for <phy=phylmd> here" # (Amaury) I added this check because we fetch ecrad data from libf/phylmd/ecrad/data only. |
---|
247 | fi |
---|
248 | } |
---|
249 | |
---|
250 | #--------------------------------------------------------------------------- |
---|
251 | function install_model() { |
---|
252 | #--------------------------------------------------------------------------- |
---|
253 | mkdir -p "$LMDZD" |
---|
254 | |
---|
255 | local ins_xios ins_cosp ins_aero ins_inlandsis |
---|
256 | if [[ $xios = "y" ]]; then ins_xios="-xios"; else ins_xios=""; fi |
---|
257 | if [[ $cosp = "y" ]]; then ins_cosp="-cosp v1"; else ins_cosp=""; fi |
---|
258 | if [[ $aerosols = "spla" ]]; then ins_aero="-spla"; else ins_aero=""; fi |
---|
259 | if [[ $inlandsis = "y" ]]; then ins_inlandsis="-inlandsis"; else ins_inlandsis=""; fi |
---|
260 | if [[ -n $svn ]]; then svnopt="-r $svn"; else svnopt=""; fi |
---|
261 | |
---|
262 | version_name=LMDZ$(echo "$version" | sed -e 's/-v//g' -e 's/-unstable//' -e 's/-r/r/' -e 's/ //g') |
---|
263 | LMDZname="${version_name}${svn}OR$veget${ins_xios}" |
---|
264 | MODEL="$LMDZD/$LMDZname/modipsl/modeles/LMDZ" |
---|
265 | |
---|
266 | if [[ -d $MODEL ]]; then echo "Found existing install at MODEL=$MODEL"; fi |
---|
267 | echo "Installing model" |
---|
268 | cd "$LMDZD" |
---|
269 | cp "$local/install_lmdz.sh" . |
---|
270 | chmod +x install_lmdz.sh |
---|
271 | local make_j=8 |
---|
272 | # We launch using $MPICMD, except if it's using mpirun (no srun equivalent for bash script) => if supported, the compilation runs in a cluster job |
---|
273 | jobcmd="\"$RUNBASHCMD $make_j\"" |
---|
274 | if [[ ${hostname:0:5} = "jean-" ]]; then jobcmd="\"$RUNBASHCMD $make_j --partition=compil\""; fi # On JeanZay: compile on the <compil> partition |
---|
275 | if [[ $(echo "$RUNBASHCMD" | cut -c -4) = "bash" ]]; then |
---|
276 | jobcmd="bash" |
---|
277 | fi |
---|
278 | echo "./install_lmdz.sh -noclean $optim -v $version $svnopt -d $resol -rad $rad -bench 0 -parallel mpi_omp $ins_cosp $ins_xios $ins_aero $ins_inlandsis -name $LMDZname -veget $veget -netcdf $netcdf -arch $ARCH -make_j $make_j -jobcmd $jobcmd" >> install_lmdz_options.$$.sh |
---|
279 | chmod +x install_lmdz_options.$$.sh |
---|
280 | echo "Running install_lmdz_options.$$.sh" |
---|
281 | set -o pipefail |
---|
282 | gcm=$MODEL/$(./install_lmdz_options.$$.sh | tee /dev/tty | tail -n 1 | sed -n "s:.* executable is \(.*\.e\).*:\1:p") |
---|
283 | set +o pipefail |
---|
284 | mv install_lmdz.sh install_lmdz.$$.sh |
---|
285 | cd "$local" |
---|
286 | } |
---|
287 | |
---|
288 | #--------------------------------------------------------------------------- |
---|
289 | function setup_def() { # modify various .def in ./DEF (+ xios xml ) |
---|
290 | #--------------------------------------------------------------------------- |
---|
291 | cd "$local" |
---|
292 | |
---|
293 | # Utilisation des .def_iso pour LMDZ-ISOtopes |
---|
294 | if [[ $phylmd = "lmdiso" ]]; then |
---|
295 | for file_iso in $(ls DEF | grep _iso); do |
---|
296 | cp DEF/"$file_iso" DEF/"${file_iso%%_iso}" |
---|
297 | done |
---|
298 | fi |
---|
299 | |
---|
300 | ###################################################################### |
---|
301 | # Choix de la grille verticale |
---|
302 | ###################################################################### |
---|
303 | if [ ! -f "DEF/L$lm.def" ]; then |
---|
304 | echo "STOP: Résolution verticale non prévue - créer un fichier DEF/L$lm.def"; exit 1 |
---|
305 | else |
---|
306 | sed -i'' -e "s/INCLUDEDEF=L.*.def/INCLUDEDEF=L$lm.def/" DEF/run.def |
---|
307 | fi |
---|
308 | |
---|
309 | ###################################################################### |
---|
310 | # Changements dans les fichiers DEF/*def |
---|
311 | # (ils vont se repercuter dans les repertoires de simulation $local/$SIM et de run $SIMRUNDIR) |
---|
312 | ###################################################################### |
---|
313 | |
---|
314 | # Choix du fichier tracer.def coherent avec l'option "aerosols" |
---|
315 | # NOTE : Le nouveau tracer.def_nospla par defaut n'inclut pas Rn-Pb; |
---|
316 | # si on les veut, il faut utiliser ci-dessous; a la place, tracer_RN_PB.def |
---|
317 | #--------------------------------------------------------------------- |
---|
318 | # NB : Les traceurs absents de start* files sont initialises=0 dans le code |
---|
319 | if [[ $aerosols = "spla" ]]; then |
---|
320 | # nouveau tracer.def (remplace "traceur.def") |
---|
321 | cp DEF/tracer.def_spla DEF/tracer.def |
---|
322 | elif [[ $phylmd = "lmdiso" ]]; then |
---|
323 | # déjà copié si 'y' |
---|
324 | cp DEF/tracer.def_nospla DEF/tracer.def |
---|
325 | fi |
---|
326 | |
---|
327 | # TEMPORAIREMENT pour spla on force l'utilisation de gcm.def_zNAfrica_BiJe (avec resolution 128x88x79) |
---|
328 | #---------------------------------------------------------------------- |
---|
329 | if [[ $aerosols = "spla" ]]; then |
---|
330 | cp DEF/gcm.def_zNAfrica_BiJe DEF/gcm.def; fi |
---|
331 | |
---|
332 | # Inscription du choix ok_guide dans DEF/guide.def |
---|
333 | #--------------------------------------------------------------------- |
---|
334 | sed -i'' -e 's/ok_guide=.*.$/ok_guide='$ok_guide'/' DEF/guide.def |
---|
335 | |
---|
336 | # Inscription du type de calendrier (qui est fonction de $climato) dans DEF/run.def |
---|
337 | #--------------------------------------------------------------------- |
---|
338 | # NB Contrairement a ce qui est ecrit dans les fichiers run.def standard, |
---|
339 | # dans ce tutorial le choix earth_365d n'est pas disponible, et earth_366d s'appelle gregorian |
---|
340 | if [[ $climato = 0 ]]; then calend="gregorian"; else calend="earth_360d"; fi |
---|
341 | sed -i'' -e 's/calend=.*.$/calend='$calend'/' DEF/run.def |
---|
342 | |
---|
343 | # Changements dans config.def (pre-choisi, et regle pour output si utilisation avec IOIPSL) |
---|
344 | # cf options veget, aerosols, cosp, xios |
---|
345 | #--------------------------------------------------------------------- |
---|
346 | if [[ $veget = "none" ]]; then VEGET="n"; else VEGET="y"; fi |
---|
347 | sed -i'' -e 's/VEGET=.*.$/VEGET='$VEGET'/' DEF/config.def |
---|
348 | |
---|
349 | ok_cdnc=y ; ok_ade=y ; ok_aie=y ; ok_alw=y |
---|
350 | case $aerosols in |
---|
351 | clim) flag_aerosol=6 ;; |
---|
352 | spla) flag_aerosol=1 ;; |
---|
353 | n) flag_aerosol=0 ; ok_cdnc=n ; ok_ade=n ; ok_aie=n ; ok_alw=n ;; |
---|
354 | *) echo Option aerosols=$aerosols not available ; exit 1 |
---|
355 | esac |
---|
356 | sed -i'' -e 's/^ok_cdnc=.*.$/ok_cdnc='$ok_cdnc'/' \ |
---|
357 | -e 's/^ok_ade=.*.$/ok_ade='$ok_ade'/' \ |
---|
358 | -e 's/^ok_aie=.*.$/ok_aie='$ok_aie'/' \ |
---|
359 | -e 's/^ok_alw=.*.$/ok_alw='$ok_alw'/' \ |
---|
360 | -e 's/^flag_aerosol=.*.$/flag_aerosol='$flag_aerosol'/' DEF/config.def |
---|
361 | pwd |
---|
362 | |
---|
363 | # COSP : ok_cosp desactive COSP si on a compile avec; il ne l'active pas si on a compile sans |
---|
364 | sed -i'' -e 's/ok_cosp.*.$/ok_cosp='$cosp'/' DEF/config.def |
---|
365 | if [[ $cosp = "y" ]]; then \cp -f "$MODEL"/DefLists/cosp*.txt "$local"/DEF/; fi |
---|
366 | |
---|
367 | # Sorties LMDZ en fonction de l'option "xios" |
---|
368 | sed -i'' -e 's/ok_all_xml=.*.$/ok_all_xml='$xios'/' DEF/config.def |
---|
369 | |
---|
370 | # Ajuster physiq.def en fonction de radiative code (default: values for rad=rrtm) |
---|
371 | # Pour isotopes=y , mettre iflag_ice_thermo=0 au lieu de 1 |
---|
372 | #--------------------------------------------------------------------- |
---|
373 | sed -i'' -e "s/iflag_rrtm=.*.$/iflag_rrtm=$iflag_rrtm/" -e "s/NSW=.*.$/NSW=$NSW/" DEF/physiq.def |
---|
374 | sed -i"" -e "s:directory_name.*$:directory_name=\"$MODEL/libf/phylmd/ecrad/data\",:" DEF/namelist_ecrad |
---|
375 | |
---|
376 | if [[ $phylmd = "lmdiso" ]]; then iflag_ice_thermo=0; else iflag_ice_thermo=1; fi |
---|
377 | sed -i -e 's/iflag_ice_thermo=.*.$/iflag_ice_thermo='$iflag_ice_thermo'/' DEF/physiq.def |
---|
378 | |
---|
379 | # Choix de orchidee.def en fonction de orchidee_rev; modification pour xios |
---|
380 | # NOTE separate orchidee_pft.def file for ORCHIDEE trunk post-CMIP6 |
---|
381 | #--------------------------------------------------------------------- |
---|
382 | orchidee_def=orchidee.def_6.1 |
---|
383 | orchidee_pft_def="" |
---|
384 | if [[ $veget = "7983" ]]; then |
---|
385 | orchidee_def=orchidee.def_6.2work |
---|
386 | elif [[ $veget = "7994" ]]; then |
---|
387 | orchidee_def=orchidee.def_6.4work |
---|
388 | orchidee_pft_def=orchidee_pft.def_6.4work |
---|
389 | if ! grep "INCLUDEDEF=orchidee_pft.def" DEF/run.def; then |
---|
390 | sed -i'' -e 's/INCLUDEDEF=orchidee.def/INCLUDEDEF=orchidee.def\nINCLUDEDEF=orchidee_pft.def/' DEF/run.def; fi |
---|
391 | fi |
---|
392 | cp -f DEF/$orchidee_def DEF/orchidee.def |
---|
393 | if [[ $orchidee_pft_def != "" ]]; then cp -f DEF/$orchidee_pft_def DEF/orchidee_pft.def; fi |
---|
394 | |
---|
395 | # Only for veget=CMIP6 it is still possible to use IOIPSL; newer versions of orchidee.def have XIOS_ORCHIDEE_OK = y |
---|
396 | sed -i'' -e 's/XIOS_ORCHIDEE_OK =.*.$/XIOS_ORCHIDEE_OK = '$xios'/' DEF/orchidee.def |
---|
397 | |
---|
398 | ###################################################################### |
---|
399 | # Si on tourne avec XIOS, mise a jour des fichiers context et field* dans XMLfilesLMDZ |
---|
400 | # (ils vont se repercuter dans les repertoires de simulation $local/$SIM et de run $SIMRUNDIR) |
---|
401 | ###################################################################### |
---|
402 | if [[ $xios = y ]]; then |
---|
403 | cp -f "$MODEL"/DefLists/context_lmdz.xml "$local"/DEF/XMLfilesLMDZ/. |
---|
404 | cp -f "$MODEL"/DefLists/field_def_lmdz.xml "$local"/DEF/XMLfilesLMDZ/. |
---|
405 | if [[ $cosp = y ]]; then cp -f "$MODEL"/DefLists/field_def_cosp1.xml "$local"/DEF/XMLfilesLMDZ/.; fi |
---|
406 | fi |
---|
407 | } |
---|
408 | |
---|
409 | #--------------------------------------------------------------------------- |
---|
410 | function setup_ce0l() { # Verification de l'existance de l'état initial, compilation eventuelle pour sa creation |
---|
411 | #--------------------------------------------------------------------------- |
---|
412 | if [[ ! -d $INIT ]]; then |
---|
413 | if [[ $init = 0 ]]; then |
---|
414 | echo "STOP: Récuperer les repertoires $INIT ou lancer avec option -init"; exit 1 |
---|
415 | else |
---|
416 | # Compile ce0l |
---|
417 | cd "$MODEL" |
---|
418 | sed -e 's/gcm$/ce0l/' compile.sh > compile_ce0l.sh; chmod +x compile_ce0l.sh |
---|
419 | echo "Compiling ce0l" |
---|
420 | if ! ./compile_ce0l.sh &> ce0l.log; then echo "STOP: ce0l compilation failed, see $MODEL/ce0l.log"; exit 1; fi |
---|
421 | echo "Compiled ce0l" |
---|
422 | ce0l=${gcm/gcm/ce0l} |
---|
423 | |
---|
424 | cd "$local" |
---|
425 | fi |
---|
426 | elif [[ $init = 1 ]]; then |
---|
427 | echo "STOP: Vous essayez d initialiser le modele mais $INIT existe deja"; exit 1 |
---|
428 | fi |
---|
429 | } |
---|
430 | |
---|
431 | #--------------------------------------------------------------------------- |
---|
432 | function setup_simu() { |
---|
433 | #--------------------------------------------------------------------------- |
---|
434 | #SIMRUNTOPDIR="$SIMRUNBASEDIR/$(basename "$local")" |
---|
435 | SIMRUNTOPDIR="$SIMRUNBASEDIR" |
---|
436 | SIMRUNDIR=$SIMRUNTOPDIR |
---|
437 | mkdir -p "$SIMRUNDIR" |
---|
438 | cd "$SIMRUNDIR" |
---|
439 | echo "La simulation s'exécutera sur $SIMRUNDIR" |
---|
440 | |
---|
441 | ##################################################################### |
---|
442 | # Creation du repertoire $SIM s'il n'existe pas deja |
---|
443 | ##################################################################### |
---|
444 | if [[ ! -d $local/$SIM ]]; then |
---|
445 | mkdir "$local/$SIM" |
---|
446 | cd "$local" |
---|
447 | |
---|
448 | # Edit reb.sh |
---|
449 | cp reb.sh "$local/$SIM/reb.sh"; chmod +x "$local/$SIM/reb.sh" |
---|
450 | sed -i'' -e "s:^rebuild=.*.$:rebuild=$LMDZD/$LMDZname/modipsl/bin/rebuild:" "$local/$SIM/reb.sh" |
---|
451 | enable_platform "$local/$SIM/reb.sh" |
---|
452 | |
---|
453 | # Copy .def |
---|
454 | cp lmdz_env.sh "$local/$SIM/" |
---|
455 | mkdir "$local/$SIM/DEF"; cp DEF/*def DEF/namelis* "$local/$SIM/DEF/" |
---|
456 | #Pour XIOS, respectivement COSP, copier aussi les fichiers *xml / *txt |
---|
457 | if [[ $cosp = "y" ]]; then cp DEF/cosp*txt "$local/$SIM/DEF/"; fi |
---|
458 | if [[ $xios = "y" ]]; then |
---|
459 | cp DEF/XMLfilesLMDZ/*xml "$local/$SIM/DEF/" |
---|
460 | if [[ $veget != 'none' ]]; then cp DEF/XMLfilesOR$veget/*xml "$local/$SIM/DEF/"; fi |
---|
461 | fi |
---|
462 | chmod u+w "$local/$SIM"/DEF/* |
---|
463 | |
---|
464 | # Gestion du calendrier |
---|
465 | ####################### |
---|
466 | cd "$SIM" |
---|
467 | sed -i'' -e "s/anneeref=.*.$/anneeref=$yearini/" DEF/run.def |
---|
468 | if [[ $freq = "yr" ]]; then date=$yearini; else date=$mthini; fi |
---|
469 | echo "$date a faire" >| etat |
---|
470 | |
---|
471 | # Recuperation des fichiers : executable initiaux et forcages |
---|
472 | ############################################################# |
---|
473 | echo "date: $date" |
---|
474 | for f in start startphy; do |
---|
475 | inf=../$INIT/$f.$date.nc |
---|
476 | if [[ -f $inf || $init = 1 ]]; then ln -s "$inf" ./; else echo "STOP: $inf missing"; exit ; fi; |
---|
477 | done |
---|
478 | for f in sechiba stomate; do |
---|
479 | if [[ -f ../$INIT/start_$f.$date.nc ]]; then ln -sf "../$INIT/start_$f.$date.nc" .; fi |
---|
480 | done |
---|
481 | cp "$gcm" gcm.e |
---|
482 | fi |
---|
483 | cd "$local"/.. |
---|
484 | |
---|
485 | ##################################################################### |
---|
486 | echo "Modification du script de lancement" |
---|
487 | ##################################################################### |
---|
488 | local cput |
---|
489 | if [[ $freq = "yr" ]]; then cput="04:00:00"; else cput="01:00:00"; fi |
---|
490 | local isotopes="n" |
---|
491 | if [[ $phylmd = "lmdiso" ]]; then isotopes="y"; fi |
---|
492 | sed -e "s/NOM_SIMU/$SIM/" \ |
---|
493 | -e "s/time=.*.$/time=$cput/" \ |
---|
494 | -e "s/ntasks=.*.$/ntasks=$mpi/" \ |
---|
495 | -e "s/ntasks-per-node=.*.$/ntasks-per-node=$mpi_per_node/" \ |
---|
496 | -e "s/cpus-per-task=.*.$/cpus-per-task=$omp/" \ |
---|
497 | -e "s/nthreads=.*./nthreads=$omp/" \ |
---|
498 | -e "s/MAINDIR=.*.$/MAINDIR=$(basename "$local")/" \ |
---|
499 | -e "s:STORED=.*.*:STORED=$(dirname "$local"):" \ |
---|
500 | -e "s:SCRATCHD=.*.*:SCRATCHD=$SIMRUNBASEDIR:" \ |
---|
501 | -e "s/stopsim=.*.$/stopsim=$stopsim/" \ |
---|
502 | -e "s/^veget=.*.$/veget=$veget/" \ |
---|
503 | -e "s/^aerosols=.*.$/aerosols=$aerosols/" \ |
---|
504 | -e "s/^isotopes=.*.$/isotopes=$isotopes/" \ |
---|
505 | -e "s/^climato=.*.$/climato=$climato/" \ |
---|
506 | -e "s/^ok_guide=.*.$/ok_guide=$ok_guide/" \ |
---|
507 | "$local/script_SIMU" >| "$SIMRUNDIR/tmp_$SIM" |
---|
508 | |
---|
509 | enable_platform "$SIMRUNDIR/tmp_$SIM" |
---|
510 | |
---|
511 | if [[ $testmode = "y" ]]; then |
---|
512 | sed -i'' -e "s/time=.*.$/time=00:10:00/" -e "s/#nday=1/nday=1/" -e "s/#@TESTQ//" "$SIMRUNTOPDIR/tmp_$SIM" |
---|
513 | fi |
---|
514 | } |
---|
515 | |
---|
516 | #---------------------------------------------------------------------- |
---|
517 | function fetch_simu_init_files() { |
---|
518 | #---------------------------------------------------------------------- |
---|
519 | ##################################################################### |
---|
520 | echo "Recuperation eventuelle de certains fichiers sur http:lmdz.lmd.jussieu.fr/pub" |
---|
521 | ##################################################################### |
---|
522 | |
---|
523 | # ORCHIDEE input files |
---|
524 | get_input_files wget_pub Orchidee |
---|
525 | |
---|
526 | # Files for aerosols and chemistry |
---|
527 | if [[ $aerosols = "clim" ]]; then |
---|
528 | get_input_files wget_pub AerChem ; fi |
---|
529 | |
---|
530 | # Files for SPLA |
---|
531 | if [[ $aerosols = "spla" ]]; then |
---|
532 | get_input_files wget_pub SPLA_WA/emissions |
---|
533 | for mo_ in $( seq $mthini $mthend ) ; do |
---|
534 | for var in u10m v10m u v ; do |
---|
535 | yr__=$( echo $mo_ | cut -c 1-4 ) |
---|
536 | mo__=$( echo $mo_ | cut -c 5-6 ) |
---|
537 | echo wget_pub 3DInputData/SPLA_WA/ERA5/$yr__/$mo__ $var.nc |
---|
538 | wget_pub 3DInputData/SPLA_WA/ERA5/$yr__/$mo__ $var.nc |
---|
539 | done |
---|
540 | done |
---|
541 | fi |
---|
542 | } |
---|
543 | |
---|
544 | #---------------------------------------------------------------------- |
---|
545 | function run_sim_or_init() { |
---|
546 | #---------------------------------------------------------------------- |
---|
547 | cd "$local" |
---|
548 | |
---|
549 | if [[ $init = 1 ]]; then |
---|
550 | ##################################################################### |
---|
551 | echo "Creation de l etat initial" |
---|
552 | ##################################################################### |
---|
553 | |
---|
554 | # Creation du repertoire INIT et mise en place de liens logiques vers les starts |
---|
555 | # en anticipation de leur création : |
---|
556 | mkdir "$local/$INIT"; cd "$local/$INIT" |
---|
557 | for an in $mthini $yearini; do for f in start startphy; do ln -s "$f.nc" "$f.$an.nc"; done; done |
---|
558 | |
---|
559 | # Creation du repertoire INIT temporaire et rapatriement des fichiers necessaires |
---|
560 | if [[ -d $SIMRUNDIR/$INIT ]]; then mv "$SIMRUNDIR/$INIT" "$SIMRUNDIR/$INIT$$"; fi |
---|
561 | mkdir "$SIMRUNDIR/$INIT"; cp -r "$local/DEF" "$SIMRUNDIR/$INIT/" |
---|
562 | cd "$SIMRUNDIR/$INIT"; cp DEF/*.def .; cp "$local/lmdz_env.sh" . |
---|
563 | if [[ $xios = "y" ]]; then |
---|
564 | cp DEF/XMLfilesLMDZ/*xml . |
---|
565 | if [[ $veget != 'none' ]]; then cp DEF/XMLfilesOR$veget/*xml .; fi |
---|
566 | fi |
---|
567 | sed -e "s/anneeref=.*.$/anneeref=$yearini/" DEF/run.def >| run.def |
---|
568 | |
---|
569 | #------------------------------------------------------------------- |
---|
570 | # Fichiers Limit |
---|
571 | #------------------------------------------------------------------- |
---|
572 | local yrs suf |
---|
573 | if [[ $climato = 0 ]]; then |
---|
574 | # calend est choisi plus haut dans "Changements dans les fichiers DEF/*def" et ecrit dans $MAINDIR/DEF/run.def |
---|
575 | yrini=$(echo "$mthini" | cut -c-4) |
---|
576 | yrend=$(echo "$mthend" | cut -c-4) |
---|
577 | yrs=""; yr=$yrini |
---|
578 | while [[ $yr -le $yrend ]]; do yrs="$yrs $yr"; (( yr = yr + 1 )); done |
---|
579 | suf="360x180_" |
---|
580 | else |
---|
581 | yrs=2000 |
---|
582 | suf="1x1_clim" |
---|
583 | fi |
---|
584 | |
---|
585 | liste_get="Albedo.nc Relief.nc Rugos.nc landiceref.nc" |
---|
586 | for yr in $yrs; do |
---|
587 | if [[ $climato = 0 ]]; then sufyr=$suf$yr; else sufyr=$suf; fi |
---|
588 | liste_get="$liste_get amipbc_sic_$sufyr.nc amipbc_sst_$sufyr.nc" |
---|
589 | done |
---|
590 | echo LISTEGET "$liste_get" |
---|
591 | for file in $liste_get; do |
---|
592 | wget_pub 3DInputData/Limit $file |
---|
593 | ln_from_pub 3DInputData/Limit $file |
---|
594 | done |
---|
595 | #------------------------------------------------------------------- |
---|
596 | # Initial state ECDYN |
---|
597 | #------------------------------------------------------------------- |
---|
598 | wget_pub 3DInputData/Init ECDYN.nc |
---|
599 | ln_from_pub 3DInputData/Init ECDYN.nc |
---|
600 | ln -sf ECDYN.nc ECPHY.nc |
---|
601 | |
---|
602 | # Creation du script d'initialisation |
---|
603 | cat << ...eod >| tmp |
---|
604 | #!/bin/bash |
---|
605 | #@JZ#JeanZay |
---|
606 | #@JZ#SBATCH --job-name=Init # nom du job |
---|
607 | #@JZ#SBATCH --ntasks=1 # Nombre de processus MPI |
---|
608 | #@JZ#SBATCH --cpus-per-task=1 # nombre de threads OpenMP |
---|
609 | #@JZ# /!\ Attention, la ligne suivante est trompeuse mais dans le vocabulaire |
---|
610 | #@JZ# de Slurm "multithread" fait bien référence à l'hyperthreading. |
---|
611 | #@JZ#SBATCH --hint=nomultithread # 1 thread par coeur physique (pas d'hyperthreading) |
---|
612 | #@JZ#SBATCH --time=00:10:00 # Temps d'exécution maximum demandé (HH:MM:SS) |
---|
613 | #@JZ#SBATCH --output=Init%j.out # Nom du fichier de sortie |
---|
614 | #@JZ#SBATCH --error=Init%j.out # Nom du fichier d'erreur (ici commun avec la sortie) |
---|
615 | #@JZ# To submit to dev queue; "time" (above) must be max 2h |
---|
616 | #@JZ#TESTQ#SBATCH --qos=qos_cpu-dev |
---|
617 | #@SP#Spirit |
---|
618 | #@SP#SBATCH --job-name=Init |
---|
619 | #@SP#SBATCH --ntasks=1 |
---|
620 | #@SP#SBATCH --cpus-per-task=1 |
---|
621 | #@SP#SBATCH --hint=nomultithread |
---|
622 | #@SP#SBATCH --time=00:10:00 |
---|
623 | #@SP#SBATCH --output=Init%j.out |
---|
624 | #@SP#SBATCH --error=Init%j.out |
---|
625 | #@ADS#Adastra |
---|
626 | #@ADS#SBATCH --job-name=Init |
---|
627 | #@ADS#SBATCH --ntasks=1 |
---|
628 | #@ADS#SBATCH --cpus-per-task=1 |
---|
629 | #@ADS#SBATCH --nodes=1 |
---|
630 | #@ADS#SBATCH --hint=nomultithread |
---|
631 | #@ADS#SBATCH --time=00:10:00 |
---|
632 | #@ADS#SBATCH --output=Init%j.out |
---|
633 | #@ADS#SBATCH --error=Init%j.out |
---|
634 | |
---|
635 | set -eu |
---|
636 | |
---|
637 | # ANCIEN MULTI STEP case \${LOADL_STEP_NAME} in |
---|
638 | |
---|
639 | # ANCIEN MULTI STEP init ) |
---|
640 | |
---|
641 | if [ ! -f lmdz_env.sh ]; then echo "manque fichier lmdz_env.sh"; ls; exit 1; fi |
---|
642 | . lmdz_env.sh |
---|
643 | ulimit -s unlimited |
---|
644 | cd $SIMRUNDIR/$INIT |
---|
645 | echo "Executable : $ce0l" |
---|
646 | for yr in $yrs; do |
---|
647 | if [ $climato = 0 ]; then sufyr=$suf\$yr; else sufyr=$suf; fi |
---|
648 | ln -sf amipbc_sic_\$sufyr.nc amipbc_sic_1x1.nc |
---|
649 | ln -sf amipbc_sst_\$sufyr.nc amipbc_sst_1x1.nc |
---|
650 | sed -e 's/anneeref=.*.$/anneeref='\$yr'/' DEF/run.def >| run.def |
---|
651 | echo Starting initialisation |
---|
652 | # Runing ce0l.e |
---|
653 | OMP_NUM_THREADS=1 $MPICMD 1 $ce0l # ce0l requires MPI=OMP=1 |
---|
654 | if [ $climato = 0 ]; then mv limit.nc limit.\$yr.nc; fi |
---|
655 | done |
---|
656 | # ANCIEN MULTI STEP ;; |
---|
657 | |
---|
658 | # ANCIEN MULTI STEP interp ) |
---|
659 | if [[ $aerosols = clim ]]; then |
---|
660 | cp $local/interp_aerosols.sh .; chmod +x interp_aerosols.sh |
---|
661 | # Les aerosols de l'annee 2000 ont été remplacés par "9999" qui pointe vers un fichier moyen sur 1995-2014 |
---|
662 | #for year in 2000 1850; do ./interp_aerosols.sh \$year; done |
---|
663 | #mv aerosols.2000.nc aerosols.clim.nc; mv aerosols.1850.nc aerosols.nat.nc |
---|
664 | for year in 9999 1850; do ./interp_aerosols.sh \$year; done |
---|
665 | mv aerosols.9999.nc aerosols.clim.nc; mv aerosols.1850.nc aerosols.nat.nc |
---|
666 | fi |
---|
667 | |
---|
668 | for f in sta* gri*nc; do cp \$f $local/$INIT/\$f; done |
---|
669 | if [[ $climato = 1 ]]; then cp limit.nc $local/$INIT/limit.nc; fi |
---|
670 | mkdir -p $local/$LIMIT |
---|
671 | for f in limit*.nc ; do cp \$f $local/$LIMIT/\$f; done |
---|
672 | if [ $aerosols = clim ]; then for f in aerosols[.0-9]*nc; do cp \$f $local/$LIMIT/\$f; done; fi |
---|
673 | # |
---|
674 | cd $SIMRUNDIR |
---|
675 | ...eod |
---|
676 | if [[ $ok_guide != "y" ]]; then # Running first simulation automatically except for nudging |
---|
677 | cat << ...eod >> tmp |
---|
678 | echo "Submitting job tmp_$SIM" |
---|
679 | #echo "\$SUBMITCMD tmp_$SIM" |
---|
680 | #\$SUBMITCMD tmp_$SIM |
---|
681 | echo submitcmd tmp_$SIM |
---|
682 | submitcmd tmp_$SIM |
---|
683 | ...eod |
---|
684 | fi |
---|
685 | cat << ...eod >> tmp |
---|
686 | # ANCIEN MULTI STEP esac |
---|
687 | ...eod |
---|
688 | enable_platform tmp |
---|
689 | echo "#################################################################" |
---|
690 | #echo "Submitting initialisation job <$SUBMITCMD tmp> from $(pwd)" |
---|
691 | echo "Submitting initialisation job <submitcmd tmp> from $(pwd)" |
---|
692 | chmod +x tmp |
---|
693 | #$SUBMITCMD tmp |
---|
694 | submitcmd tmp |
---|
695 | echo "#################################################################" |
---|
696 | |
---|
697 | else #case [ $init != 1 ] |
---|
698 | cd "$SIMRUNDIR" |
---|
699 | echo "################################################################" |
---|
700 | echo "Submitting job tmp_$SIM" |
---|
701 | #echo "$SUBMITCMD tmp_$SIM" |
---|
702 | #$SUBMITCMD "tmp_$SIM" |
---|
703 | echo "submitcmd tmp_$SIM" |
---|
704 | submitcmd "tmp_$SIM" |
---|
705 | echo '################################################################' |
---|
706 | fi |
---|
707 | } |
---|
708 | |
---|
709 | #--------------------------------------------------------------------------- |
---|
710 | function message_post_submit() { |
---|
711 | #--------------------------------------------------------------------------- |
---|
712 | if [[ $ok_guide = "y" && $init = 1 ]]; then |
---|
713 | cd "$local" |
---|
714 | enable_platform era2gcm_tuto.sh |
---|
715 | echo "Once initialisation is finished, you have to create nudging files" |
---|
716 | echo "Edit era2gcm_tuto.sh and set the desired parameters in section <User choices>" |
---|
717 | echo "Make sure you have acces to the chosen ERA files, and the required modules are loaded, then run : ./era2gcm_tuto.sh" |
---|
718 | if [[ $aerosols = "spla" ]]; then |
---|
719 | echo "Your aerosol choice is <spla>, so you need ERA 10m-winds interpolated on LMDZ grid. Use script era2gcm_uv10m.sh" |
---|
720 | fi |
---|
721 | else |
---|
722 | echo "Si tout se passe bien, vous avez initialisé et lancé automatiquement la simulation." |
---|
723 | echo "Le job qui a été lancé se trouve sur $SIMRUNTOPDIR/tmp_$SIM" |
---|
724 | fi |
---|
725 | } |
---|
726 | |
---|
727 | #--------------------------------------------------------------------------- |
---|
728 | function setup_and_load_lmdz_env() { |
---|
729 | #--------------------------------------------------------------------------- |
---|
730 | if [[ ! -f .lmdz_setup_root_dir ]]; then echo "STOP: setup.sh is not located in the root dir ??!!"; exit 1; fi |
---|
731 | # sed root_dir in lmdz_env.sh |
---|
732 | sed -i'' "s<root_dir=.*<root_dir=$local<" lmdz_env.sh |
---|
733 | |
---|
734 | # Set up the appropriate environment |
---|
735 | source lmdz_env.sh |
---|
736 | } |
---|
737 | |
---|
738 | local=$(pwd) |
---|
739 | |
---|
740 | setup_and_load_lmdz_env |
---|
741 | load_install_lib |
---|
742 | define_expert_options |
---|
743 | set_default_params |
---|
744 | read_cmdline_args "$@" |
---|
745 | ensure_correct_option_combinations |
---|
746 | install_model |
---|
747 | setup_def |
---|
748 | setup_ce0l |
---|
749 | setup_simu |
---|
750 | fetch_simu_init_files |
---|
751 | run_sim_or_init |
---|
752 | message_post_submit |
---|