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