source: BOL/LMDZ_Setup_amaury/setup.sh @ 4956

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

(WIP) continue refactoring setup.sh
fix env vars

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