source: BOL/LMDZ_Setup_amaury/setup.sh @ 4955

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

(WIP) continue refactoring setup.sh

File size: 32.9 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  SIMRUNDIR=$SIMRUNTOPDIR
377  mkdir -p "$SIMRUNDIR"
378  cd "$SIMRUNDIR"
379  echo "La simulation s'exécutera sur $SIMRUNDIR"
380
381  #####################################################################
382  # Creation du repertoire $SIM s'il n'existe pas deja
383  #####################################################################
384  if [[ ! -d $local/$SIM ]]; then
385    mkdir "$local/$SIM"
386    cd "$local"
387
388    # Edit reb.sh
389    cp reb.sh "$local/$SIM/reb.sh"; chmod +x "$local/$SIM/reb.sh"
390    sed -i'' -e "s:^rebuild=.*.$:rebuild=$LMDZD/$LMDZname/modipsl/bin/rebuild:" \
391    -e "s/@@groupe/$GROUPE/" "$local/$SIM/reb.sh"
392    enable_groupe "$local/$SIM/reb.sh"
393
394    # Copy .def
395    cp lmdz_env.sh "$local/$SIM/"
396    mkdir "$local/$SIM/DEF"; cp DEF/*def DEF/namelis* "$local/$SIM/DEF/"
397    #Pour XIOS, respectivement COSP, copier aussi les fichiers *xml / *txt
398    if [[ $cosp = "y" ]]; then cp DEF/cosp*txt "$local/$SIM/DEF/"; fi
399    if [[ $xios = "y" ]]; then
400       cp DEF/XMLfilesLMDZ/*xml "$local/$SIM/DEF/"
401       if [[ $veget != 'none' ]]; then cp DEF/XMLfilesOR$veget/*xml "$local/$SIM/DEF/"; fi
402    fi
403    chmod u+w "$local/$SIM"/DEF/*
404
405    # Gestion du calendrier
406    #######################
407    cd "$SIM"
408    sed -i'' -e "s/anneeref=.*.$/anneeref=$yearini/" DEF/run.def
409    if [[ $freq = "yr" ]]; then date=$yearini; else date=$mthini; fi
410    echo "$date a faire" >| etat
411
412    # Recuperation des fichiers : executable initiaux et forcages
413    #############################################################
414    echo "date: $date"
415    for f in start startphy; do
416      inf=../$INIT/$f.$date.nc
417      if [[ -f $inf || $init = 1 ]]; then ln -s "$inf" ./; else echo "STOP: $inf missing"; exit ; fi;
418    done
419    for f in sechiba stomate; do
420      if [[ -f ../$INIT/start_$f.$date.nc ]]; then ln -sf "../$INIT/start_$f.$date.nc" .; fi
421    done
422    cp "$gcm" gcm.e
423  fi
424  cd "$local"/..
425
426  #####################################################################
427  echo "Modification du script de lancement"
428  #####################################################################
429  local cput
430  if [[ $freq = "yr" ]]; then cput="04:00:00"; else cput="01:00:00"; fi
431  local isotopes="n"
432  if [[ $phylmd = "lmdiso" ]]; then isotopes="y"; fi
433  sed -e "s/@@groupe/$GROUPE/" \
434  -e "s/NOM_SIMU/$SIM/" \
435  -e "s/time=.*.$/time=$cput/" \
436  -e "s/ntasks=.*.$/ntasks=$mpi/" \
437  -e "s/cpus-per-task=.*.$/cpus-per-task=$omp/" \
438  -e "s/nthreads=.*./nthreads=$omp/" \
439  -e "s/MAINDIR=.*.$/MAINDIR=$(basename "$SIMRUNTOPDIR")/" \
440  -e "s:STORED=.*.*:STORED=$SIMRESDIR:" \
441  -e "s:SCRATCHD=.*.*:SCRATCHD=$(dirname "$SIMRUNTOPDIR"):" \
442  -e "s/stopsim=.*.$/stopsim=$stopsim/" \
443  -e "s/^veget=.*.$/veget=$veget/" \
444  -e "s/^aerosols=.*.$/aerosols=$aerosols/" \
445  -e "s/^isotopes=.*.$/isotopes=$isotopes/" \
446  -e "s/^climato=.*.$/climato=$climato/" \
447  -e "s/^ok_guide=.*.$/ok_guide=$ok_guide/" \
448  "$local/script_SIMU" >| "$SIMRUNDIR/tmp_$SIM"
449
450  enable_groupe "$SIMRUNDIR/tmp_$SIM"
451
452  if [[ $testmode = "y" ]]; then
453    sed -i'' -e "s/time=.*.$/time=00:30:00/" -e "s/#nday=1/nday=1/" -e "s/#@TESTQ//" "$SIMRUNTOPDIR/tmp_$SIM"
454  fi
455}
456
457function fetch_simu_init_files {
458  #####################################################################
459  echo "Recuperation eventuelle de certains fichiers sur $LMDZ_INIT"
460  #####################################################################
461  mkdir -p "$LMDZ_INIT"
462
463  #-------------------------------------------------------------------
464  # Fichiers ORCHIDEE
465  #-------------------------------------------------------------------
466  get="myget 3DInputData/Orchidee/"
467  cd "$LMDZ_INIT";
468  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
469    if [[ ! -f $file ]]; then ${get}$file; fi
470  done
471  cd - > /dev/null
472  # Additionnal files needed for ORCHIDEE trunk post-CMIP6
473  if [[ $veget = 7994 && ! -f $LMDZ_INIT/soil_bulk_and_ph.nc ]]; then
474    cd "$LMDZ_INIT"
475    ${get}soil_bulk_and_ph.nc; ${get}NITROGEN_for_ORtrunk.tar
476    tar -xvf NITROGEN_for_ORtrunk.tar; cd - > /dev/null
477  fi
478  #-------------------------------------------------------------------
479  # Fichiers aerosols/chimie
480  #-------------------------------------------------------------------
481  if [[ $aerosols = "clim" ]]; then
482    get="myget 3DInputData/AerChem/"
483    #liste_get="aerosols1850_from_inca.nc aerosols2000_from_inca.nc"
484    #aerosols9999_from_inca.nc est un lien vers aerosols1995_2014_ensavg_from_inca.nc
485    cd "$LMDZ_INIT"
486    for file in "aerosols1850_from_inca.nc" "aerosols9999_from_inca.nc"; do
487      if [[ ! -f $file ]]; then ${get}$file; fi
488    done
489    cd - > /dev/null
490  fi
491  # For SPLA
492  #-------------------
493  # Dans ${LMDZ_INIT} on cree folder SPLA_Init et dedans le INITIAL
494  # Pour l'instant on copie là-dedans de chez Binta les fichiers a la res zoomNaf;
495  # plus tard on y recupererea des fichiers a haute resolution reguliere depuis http:/LMDZ,
496  # a regrider ensuite par un script interp_fichiers_spla.sh (comme pour aerosols="clim")
497  # Les fichiers (regrides, sauf SOILSPEC.data utilise tel quel) seront mis dans $MAINDIR/INPUT_SPLA (equivalent de INPUT_DUST)
498  if [[ $aerosols = "spla" ]]; then
499    mkdir -p "${LMDZ_INIT}/SPLA_Init"; mkdir -p "$LMDZ_INIT/SPLA_Init/INITIAL"
500    get="cp -p /gpfsstore/rech/gzi/rgzi027/ergon/BIBIAERO/INPUTS_DUST/INITIAL/"
501    liste_get="wth.dat cly.dat donnees_lisa.nc SOILSPEC.data \
502                 carbon_emissions.nc sulphur_emissions_antro.nc  \
503                 sulphur_emissions_nat.nc  sulphur_emissions_volc.nc"
504
505    cd "$LMDZ_INIT/SPLA_Init/INITIAL"
506    for file in $liste_get; do
507      if [[ ! -f $file ]]; then ${get}$file .; fi
508    done
509    cd - > /dev/null
510    ###
511    #Cas particulier des fichiers mensuels dust.nc :A DECIDER :
512    #C'est entre le cas des aerosols.clim= 1 seul fichier, annuel,
513    # et le cas des vents guidage, pré-interpolés avec era2gcm pour toute la periode, dans MAINDIR/GUIDE.
514    # 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.
515    # 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
516    #ICI pour l'instant je copie les fichiers de chez Binta (repositoire==http...) dans LMDZ_INIT/SPLA_Init, avec test sur mois 01
517
518    if [[ ! -d ${LMDZ_INIT}/SPLA_Init/PERIOD0001 ]]; then
519      if [[ ${hostname:0:5} != "jean-" ]]; then echo "PERIOD001 (aerosols=spla) IS ONLY AVAILABLE ON JEANZAY FOR NOW, CONTACT SUPPORT"; exit 1; fi
520      cp -pr /gpfsstore/rech/gzi/rgzi027/ergon/BIBIAERO/INPUTS_DUST/PERIOD* "$LMDZ_INIT/SPLA_Init/.";
521    fi
522   #A la fin on doit avoir dans SPLA_Init les fichiers initiaux dans INITIAL plus les repertoires PERIOD00MM contenant dust.nc
523   #Cela doit se retrouver dans script_SIMU qui les copie dans le repertoire de run sur $SCRATCH
524  fi
525  #-------------------------------------------------------------------
526  # Fichiers Init
527  #-------------------------------------------------------------------
528  get="myget 3DInputData/Init/"
529  liste_get="alb_bg_modisopt_2D_ESA_v2.nc reftemp.nc"
530  cd "$LMDZ_INIT"
531  for file in $liste_get; do
532    if [[ ! -f $LMDZ_INIT/$file ]]; then ${get}$file; fi
533  done
534  cd - > /dev/null
535}
536
537function run_sim_or_init {
538  cd "$local"
539  if [[ $init = 1 ]]; then
540    #####################################################################
541    echo "Creation de l etat initial"
542    #####################################################################
543
544    # Creation du repertoire INIT et mise en place de liens logiques vers les starts
545    # en anticipation de leur création :
546    mkdir "$local/$INIT"; cd "$local/$INIT"
547    for an in $mthini $yearini; do for f in start startphy; do ln -s "$f.nc" "$f.$an.nc"; done; done
548
549    # Creation du repertoire INIT temporaire et rapatriement des fichiers necessaires
550    if [[ -d $SIMRUNDIR/$INIT ]]; then mv "$SIMRUNDIR/$INIT" "$SIMRUNDIR/$INIT$$"; fi
551    mkdir "$SIMRUNDIR/$INIT"; cp -r "$local/DEF" "$SIMRUNDIR/$INIT/"
552    cd "$SIMRUNDIR/$INIT"; cp DEF/*.def .; cp "$local/lmdz_env.sh" .
553    if [[ $xios = "y" ]]; then
554      cp DEF/XMLfilesLMDZ/*xml .
555      if [[ $veget != 'none' ]]; then cp DEF/XMLfilesOR$veget/*xml .; fi
556    fi
557    sed -e "s/anneeref=.*.$/anneeref=$yearini/" DEF/run.def >| run.def
558
559    #-------------------------------------------------------------------
560    # Fichiers Limit
561    #-------------------------------------------------------------------
562    local yrs suf
563    if [[ $climato = 0 ]]; then
564      # calend est choisi plus haut dans "Changements dans les fichiers DEF/*def" et ecrit dans $MAINDIR/DEF/run.def
565      yrini=$(echo "$mthini" | cut -c-4)
566      yrend=$(echo "$mthend" | cut -c-4)
567      yrs=""; yr=$yrini
568      while [[ $yr -le $yrend ]]; do yrs="$yrs $yr"; (( yr = yr + 1 )); done
569      suf="360x180_"
570    else
571      yrs=2000
572      suf="1x1_clim"
573    fi
574
575    get="myget 3DInputData/Limit/"
576    liste_get="Albedo.nc Relief.nc Rugos.nc landiceref.nc"
577    for yr in $yrs; do
578       if [[ $climato = 0 ]]; then sufyr=$suf$yr; else sufyr=$suf; fi
579       liste_get="$liste_get amipbc_sic_$sufyr.nc amipbc_sst_$sufyr.nc"
580    done
581    echo LISTEGET "$liste_get"
582    for file in $liste_get; do
583      cd "$LMDZ_INIT"
584      if [[ ! -f $LMDZ_INIT/$file ]]; then ${get}$file; fi
585      cd - > /dev/null
586      ln -s "$LMDZ_INIT/$file" .
587    done
588    #-------------------------------------------------------------------
589    # ECDYN
590    #-------------------------------------------------------------------
591    get="myget 3DInputData/Init/"
592    if [[ ! -f $LMDZ_INIT/ECDYN.nc ]]; then cd "$LMDZ_INIT"; ${get}ECDYN.nc; cd - > /dev/null; fi
593    ln -s "$LMDZ_INIT"/ECDYN.nc .
594    ln -sf ECDYN.nc ECPHY.nc
595
596    # Creation du script d'initialisation
597    cat << ...eod >| tmp
598#!/bin/bash
599#@JZ#JeanZay
600#@JZ#SBATCH --job-name=Init         # nom du job
601#@JZ#SBATCH -A "$GROUPE"@cpu
602#@JZ#SBATCH --ntasks=1             # Nombre de processus MPI
603#@JZ#SBATCH --cpus-per-task=16     # nombre de threads OpenMP
604#@JZ# /!\ Attention, la ligne suivante est trompeuse mais dans le vocabulaire
605#@JZ# de Slurm "multithread" fait bien référence à l'hyperthreading.
606#@JZ#SBATCH --hint=nomultithread   # 1 thread par coeur physique (pas d'hyperthreading)
607#@JZ#SBATCH --time=00:10:00            # Temps d’exécution maximum demandé (HH:MM:SS)
608#@JZ#SBATCH --output=Init%j.out     # Nom du fichier de sortie
609#@JZ#SBATCH --error=Init%j.out      # Nom du fichier d'erreur (ici commun avec la sortie)
610#@JZ# To submit to dev queue; "time" (above) must be max 2h
611#@JZ# #SBATCH --qos=qos_cpu-dev
612
613# ANCIEN MULTI STEP  case \${LOADL_STEP_NAME} in
614
615# ANCIEN MULTI STEP   init )
616
617if [ ! -f lmdz_env.sh ]; then echo "manque fichier lmdz_env.sh"; ls; exit 1; fi
618. lmdz_env.sh
619ulimit -s unlimited
620export OMP_STACKSIZE=800M
621export OMP_NUM_THREADS=1
622cd $SIMRUNDIR/$INIT
623echo "Executable : $ce0l"
624for yr in $yrs; do
625  if [ $climato = 0 ]; then sufyr=$suf\$yr; else sufyr=$suf; fi
626  ln -sf amipbc_sic_\$sufyr.nc amipbc_sic_1x1.nc
627  ln -sf amipbc_sst_\$sufyr.nc amipbc_sst_1x1.nc
628  sed -e 's/anneeref=.*.$/anneeref='\$yr'/' DEF/run.def >| run.def
629  echo Starting initialisation
630  $RUNCMD 1 $ce0l
631  if [ $climato = 0 ]; then mv limit.nc limit.\$yr.nc; fi
632done
633# ANCIEN MULTI STEP   ;;
634
635# ANCIEN MULTI STEP   interp )
636if [ $aerosols = clim ]; then
637cp $local/interp_aerosols.sh .; chmod +x interp_aerosols.sh
638# Les aerosols de l'annee 2000 ont ete remplaces par "9999" qui pointe vers un fichier moyen sur 1995-2014
639#for year in 2000 1850; do  ./interp_aerosols.sh \$year; done
640#mv aerosols.2000.nc aerosols.clim.nc; mv aerosols.1850.nc aerosols.nat.nc
641for year in 9999 1850; do ./interp_aerosols.sh \$year; done
642mv aerosols.9999.nc aerosols.clim.nc; mv aerosols.1850.nc aerosols.nat.nc
643fi
644
645# AS : S'il etait possible d'automatiser l'interpolation de l'input SPLA, ce serait a lancer ici
646#en attendant, on passe au paragraphe suivant où on copie les fichiers à la res ZoomNaf depuis $LMDZ_INIT/SPLA_Init
647#if [ $aerosols = spla ]; then
648#cp $local/futur script interp_aerosols_SPLA.sh .; chmod +x interp_aerosols_SPLA.sh
649#for file in...; do  ./interp_aerosols_SPLA.sh \$year; done
650#etc etc etc ...
651#fi
652
653# Copy initial and forcing files in $local/$INIT and $local/$LIMIT; also in $local/INPUT_SPLA if $aerosols=spla
654for f in sta* limit.nc gri*nc; do cp \$f $local/$INIT/\$f; done
655mkdir -p $local/$LIMIT
656for f in limit*.nc ; do cp \$f $local/$LIMIT/\$f; done
657if [ $aerosols = clim ]; then  for f in aerosols[.0-9]*nc; do cp \$f $local/$LIMIT/\$f; done; fi
658#
659if [ $aerosols = spla ]; then
660 #mkdir -p $local/INPUT_SPLA; pour l'instant on copie $LMDZ_INIT/SPLA_Init en block
661 if [ ! -d $local/INPUT_SPLA ]; then cp -pr $LMDZ_INIT/SPLA_Init $local/INPUT_SPLA; fi
662fi
663cd $SIMRUNDIR
664...eod
665    if [[ $ok_guide != "y" ]]; then # Running first simulation automatically except for nudging
666      cat << ...eod >> tmp
667       $SUBMITCMD tmp_$SIM
668...eod
669    fi
670    cat << ...eod >> tmp
671  # ANCIEN MULTI STEP   esac
672...eod
673    enable_groupe tmp
674    echo "###############################################################################"
675    echo "Submitting initialisation job <$SUBMITCMD tmp> from $(pwd)"
676    chmod +x tmp
677    $SUBMITCMD tmp
678    echo "###############################################################################"
679
680  else #case [ $init != 1 ]
681     cd "$SIMRUNDIR"
682     echo "###############################################################################"
683     echo "Submitting job tmp_$SIM"
684     echo "$SUBMITCMD tmp_$SIM"
685     $SUBMITCMD "tmp_$SIM"
686     echo '###############################################################################'
687  fi
688}
689
690# Set up the appropriate environment
691source lmdz_env.sh
692
693# TODO Amaury: commented-out for now // /!\ check w/ Adriana: "groupe@cpu" never appears in seasonal.sh...
694## Pour les post-traitements
695#sed -i'' -e "s/groupe@cpu/$groupe@cpu/" seasonal.sh
696local=$(pwd)
697
698load_install_lib
699define_expert_options
700set_default_params
701read_cmdline_args "$@"
702ensure_correct_option_combinations
703install_model
704setup_def
705setup_ce0l
706setup_simu
707fetch_simu_init_files
708run_sim_or_init
709
710exit 1
711
712
713# COMPILATION OPTIONS depending on the user choices and LMDZ revision number $mysvn
714#-------------------------------------------------------
715if [[ $rad = "ecrad" && ! -d ecrad_data ]]; then
716    cd "$local"; wget https://lmdz.lmd.jussieu.fr/pub/3DInputData/ecrad/ecrad_data.tar; tar xvf ecrad_data.tar; cd - > /dev/null
717fi
718
719if [[ $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
720
721# EXIT after (install and) compilation if we are on jean-zay-pp instead of jean-zay !
722hostname=`hostname`
723if [ ${hostname:0:11} = "jean-zay-pp" ]; then
724 echo "You are on jean-zay-pp, here you only can install and compile the model, not run it"
725 echo "If you want to run a simulation, log in to jean-zay and launch main.sh again, without install"
726 echo `date`
727 exit
728fi
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745if [ $ok_guide = y -a $init = 1 ]; then
746   echo Once initialisation is finished, you have to create nudging files
747   echo Edit era2gcm.sh and set the desired parameters in section "User choices"
748   echo Make sure you have acces to the chosen ERA files, and the required modules are load
749   echo Then run : ./era2gcm.sh
750   if [ "$aerosols" = "spla" ]; then
751     echo Your aerosol choice is "spla", so you need ERA 10m-winds interpolated on LMDZ grid
752     echo Use script era2gcm_uv10m.sh 
753   fi
754else
755   echo Si tout se passe bien, vous avez initialise et lance automatiquement
756   echo la simulation.
757   echo Si vous voulez modifier les caracteristiques du job, comme le temps
758   echo max ou le nombre de proc, il se trouve sur
759   echo $SIMRUNTOPDIR/$MAINDIR/tmp_$SIM
760fi
761
762###############################################################################
763# At the end, print on screen the compilation command, and also in a "compile.sh" script
764
765echo "To recompile the model :"
766echo "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.