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