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