source: BOL/LMDZ_Setup_amaury/setup.sh @ 4986

Last change on this file since 4986 was 4986, checked in by abarral, 4 months ago

(WIP) various minor fixes
add spirit header in reb.sh, fix run cmd
fix auto number of procs in setup.sh

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