source: BOL/LMDZ_Setup_amaury/setup.sh @ 4980

Last change on this file since 4980 was 4980, checked in by abarral, 3 weeks ago

(WIP) update spirit arch
update script_SIMU env
fix setup.sh, add netcdf option
fix aerosols detection

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