source: BOL/LMDZ_Setup_amaury/setup.sh @ 4995

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

(WIP) update JEANZAY lmdz_env
fix ecrad data path
run model compilation in a dedicated job
fix Adastra missing --ntasks-per-node

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