source: BOL/LMDZ_Setup_amaury/setup.sh @ 5075

Last change on this file since 5075 was 5034, checked in by abarral, 2 months ago

fix Adastra max cpu/node
fix Adastra sbatch env inheritance
remove Adastra nomultithread
fix ini script SUBMITCMD

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