source: BOL/LMDZ_Setup_amaury/setup.sh @ 5177

Last change on this file since 5177 was 5175, checked in by abarral, 10 days ago

Automatically set root_dir via setup.sh

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