source: BOL/LMDZ_Setup_amaury/setup.sh @ 4978

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

(WIP) update spirit and adastra-specific params
detect gcm.e compile fail

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