source: BOL/LMDZ_Setup/setup.sh @ 5723

Last change on this file since 5723 was 5723, checked in by idelkadi, 5 months ago

Added the "-install" option to control the installation and compilation of the model.
In setup.sh, set install=n to avoid reinstalling and recompiling the model if it's not necessary (default: install=y).

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#---------------------------------------------------------------------------
8function define_expert_options() { # Expert-level choices
9#---------------------------------------------------------------------------
10
11  # optim: either "" or "-debug" to compile in debug mode
12  #       (slower but better diagnosis of segfaults)
13  optim=""
14
15  # "n" or "y". If testmode="y", then simulations run for a single day
16  # per period.
17  # NOTE: you must set mthend accordingly !
18  testmode="n"
19
20  # instll : either "y" or "n"
21  # default : y if n LMDZ will not be installed and compiled
22  install="y"
23
24  # Radiative code: "oldrad" / "rrtm" / "ecrad"
25  rad="rrtm"
26
27  #   !!! STRONG recommendation : experiments with DIFFERENT Orchidee or
28  #   aerosol options should be performed in DIFFERENT LMDZ_Setup folders
29  #   !!! (especially as they may need different initial files)
30
31  # AEROSOLS : "n" (=no)/"clim" (=average 1995-2014) / "spla" (interactive)
32  # (WARNING : if you first run the scripts with aerosols=n, then you want
33  # to change to =clim, you must remove the INIT and LIMIT folders and
34  # rerun main.sh with init=1 in order to create aerosol files
35
36  aerosols="clim"
37
38  # SURFACE/VEGETATION SCHEME
39  # - "none" : bucket scheme
40  #   CMIP6 : orchidee CMIP6 version
41  #   7983/7994 : orchidee svn release 7983 (orch2.2) and 7994 (last tested)
42  #   If you need other orch versions, and also require XIOS, you'll need
43  #                    to create the appropriate files in DEF/XMLfilesOR...
44  veget="CMIP6"
45
46  # New snow scheme INLANDSIS! "y" / "n"
47  # Activates INLANDSIS compilation
48  #  to be done : treatment of specific restart and def file
49  inlandsis="n"
50
51  # netcdf: 0 (use existing library) / 1 (recompile netcdf, slow)
52  netcdf=0
53
54  # --->>> ALSO PAY ATTENTION TO OUTPUT files, frequency, level ------------
55  #   With IOIPSL : Choose your config.def among versions available in DEF,
56  #     copy it as config.def (the copy is done automatically for "iso"),
57  #     edit it and set up output files, frequencies and levels.
58  #     NB : For aerosols=spla, output level minimum 4 is required to outpu
59  #     the specific variables.
60  #     For aerosols=n, aerosol flags will automatically be set to "n".
61  #   With XIOS : adjust DEF/XMLfiles*/file*xml
62
63  save_pub=0
64
65}
66
67
68#---------------------------------------------------------------------------
69function enable_platform() {  # Sed platform-specific headers
70#---------------------------------------------------------------------------
71  local file="$1"
72  local platform
73
74  case ${hostname:0:5} in
75    jean-) platform="JZ";;
76    spiri) platform="SP";;
77    adast) platform="ADS";;
78    *) echo "Warning: $hostname is not a known job platform (ignore if running locally)"; return 0;;
79  esac
80
81  sed -i'' -e "s/^#@$platform//" "$file"
82}
83
84#---------------------------------------------------------------------------
85function load_install_lib() { #Fetch and source install_lmdz.sh to get myget
86#---------------------------------------------------------------------------
87  if [[ ! -f "install_lmdz.sh" ]]; then
88    wget --no-cache "http://svn.lmd.jussieu.fr/LMDZ/BOL/script_install/install_lmdz.sh"
89  fi
90  # shellcheck disable=SC1090
91  source <(sed 's/function \(.*\) {/function installlmdz_\1 {/g' install_lmdz.sh)  # source with a namespace for functions
92  function myget { installlmdz_myget "$@"; }
93}
94
95#---------------------------------------------------------------------------
96function set_default_params() { # Default value of script parameters
97#---------------------------------------------------------------------------
98
99  SIM=$(basename "$local_d")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
125#---------------------------------------------------------------------------
126function read_cmdline_args() {
127#---------------------------------------------------------------------------
128  while (($# > 0)); do
129    case $1 in
130      "-h") cat <<........fin
131       setup.sh can be launched/driven by main.sh
132             setup.sh [-v version] [-r svn_release] [-init INIT] [-d 96x95x79] [-f mo] [-nudging]
133             -v "version" like 20150828.trunk; see https://lmdz.lmd.jussieu.fr/Distrib/LISMOI.trunk (default <$version>)
134             -r "svn_release"        either the svn release number or "last" (default <$svn>)
135             -d IMxJMxLM             to run in resolution IM x JM x LM (default <$resol>)
136             -install y/n            pour installer et compiler le modele
137             -f mo/yr                pour tourner en mensuel ou annuel (default <$freq>)
138             -rad RAD                Radiation
139             -netcdf  0/1/DIR        Netcdf installation
140             -aerosols n/clim/spla   Aerosols : none / climatological / interactive with SPLA
141             -veget CMIP6            CMIP6 version of rchidee
142                    7983             orch2.2
143                    7994             trunk
144             "INIT"                  1: creates INIT and LIMIT
145                                     0: reads from INIT and LIMIT
146                                     SIMU: reads from preexisting simulation SIMU and LIMIT (default <$init>)
147             -nudging                to run with nudging. Nudging files must be created independently
148             -p                      the physics to use (default <$phylmd>)
149             -save_pub               To files downlaoded with wget (default <$SIM>)
150             -name                   install folder name (default <$SIM>)
151             Other options available (see "options" section in the script)
152........fin
153        exit;;
154      "-v") version="$2"; shift 2;;
155      "-r") svn=$2; shift 2;;
156      "-d") resol=$2; shift 2;;
157      "-f") freq=$2; shift 2;;
158      "-p") phylmd=$2; shift 2;;
159      "-name") SIM=$2; shift 2;;
160      "-save_pub") save_pub=$2 ; shift 2 ;;
161      "-install") install=$2; shift 2;;
162      "-rad") rad=$2; shift 2;;
163      "-netcdf") netcdf=$2; shift 2;;
164      "-aerosols") aerosols=$2; shift 2;;
165      "-veget") veget=$2; shift 2;;
166      "-cosp") cosp=y; shift;;
167      "-xios") xios=y; shift;;
168      "-init") init=$2; shift 2;;
169      "-nudging") ok_guide=y; shift;;
170      "-climato") climato=$2; shift 2;;
171      "-mthini") mthini=$2; shift 2;;
172      "-mthend") mthend=$2; shift 2;;
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  case $rad in
185    oldrad) iflag_rrtm=0; NSW=2;;
186    rrtm)   iflag_rrtm=1; NSW=6;;
187    ecrad)  iflag_rrtm=2; NSW=6;;
188  esac
189
190  im=$(echo "$resol" | cut -dx -f1)
191  jm=$(echo "$resol" | cut -dx -f2)
192  lm=$(echo "$resol" | cut -dx -f3)
193
194  case $save_pub in
195     0) save_pub_opt=0 ;;
196     1) save_pub_opt="-save_pub" ;;
197     *) save_pub_opt="-save_pub -save_pub_dir $save_pub"
198          mkdir -p $save_pub
199          if [ $? != 0 ] ; then echo Cannot create directory $save_pub
200                           exit 1 ; fi
201  esac
202
203  yearini=$(echo "$mthini" | cut -c-4)
204  if [[ $freq = yr ]]; then stopsim=$(echo "$mthend" | cut -c-4); else stopsim=$mthend; fi
205
206  if [[ -d $SIM ]]; then
207     echo "La simulation $SIM existe deja. Il est conseillé d'arrêter et de vérifier."
208     echo "Si vous êtes sûr de vous, vous pouvez la prolonger. Voulez vous la prolonger ? (y/n)"
209     read -r ans
210     if [[ $ans != y ]]; then exit 1; fi
211  fi
212
213  ######################################################################
214  # Choix du nombre de processeurs
215  # NOTES :
216  # omp=8 by default (for Jean-Zay must be a divisor of 40 procs/node)
217  # omp=1 : required for SPLA (omp parallelism not ready)
218  # omp=2 for veget=CMIP6+XIOS beacause of a bug in ORCHIDEE/src_xml/xios_orchidee.f90
219  ######################################################################
220  (( mpi = jm / 2 ))
221  omp=8
222  if [[ $aerosols = "spla" ]]; then omp=1; fi
223  if [[ $veget = "CMIP6" && $xios = "y" ]]; then omp=2; fi
224  if [[ $mpi -gt $NB_MPI_MAX ]]; then mpi=$NB_MPI_MAX; fi
225  if [[ $omp -gt $NB_OMP_MAX ]]; then omp=$NB_OMP_MAX; fi
226
227  # Compute how many mpi per node (required e.g. for Adastra)
228  mpi_per_node=0
229  if [[ $NB_CORE_PER_NODE_MAX -gt 0 ]]; then
230    local N_omp_mt=1
231    if [[ $omp -gt 1 ]]; then (( N_omp_mt = omp / N_HYPERTHREADING )); fi  # take into account hyperthreading
232    (( mpi_per_node = NB_CORE_PER_NODE_MAX / N_omp_mt ))
233    if [[ mpi_per_node -gt mpi ]]; then mpi_per_node=$mpi; fi
234  fi
235
236  echo "Total MPI=$mpi (PER NODE=$mpi_per_node), OMP=$omp"
237}
238
239#---------------------------------------------------------------------------
240function ensure_correct_option_combinations() {
241  # AVOID COMBINATIONS OF OPTIONS THAT DON'T WORK in user choices
242#---------------------------------------------------------------------------
243  if [[ $ok_guide = y && $climato = 1 ]]; then
244     echo "STOP: Running nudged simulations with climatological SSTs is not planned. Change <climato> to <0> or modify the setup (experts)"; exit 1
245  fi
246
247  if [[ $climato = 0 && $freq = "yr" ]]; then
248     echo "STOP: Running simulations with interannual SSTs is possible only month by month and a true calendar."
249     echo "Change <climato> to <1> or <freq> to <mo> or modify setup.sh (experts)"; exit 1
250  fi
251
252
253  # (Temporary) Constraints for aerosols=spla :
254  # --> resolution 128x88x79 and rad=rrtm
255  if [[ $aerosols = "spla" && ( ${im}x${jm} != "128x88" || $freq != mo ) ]]; then
256    echo 'STOP: For now, <aerosols=spla> requires <resol=128x88x79>,'
257    echo 'and uses the zoomed grid from gcm.def_zNAfrica_BiJe,'
258    echo 'for which forcing & initial files are available'
259    echo "Right now resol=<$resol>"
260    echo 'Should be run in monthly mode'
261    exit 1
262  fi
263
264  if [[ $rad = "ecrad" && $phylmd != "lmd" ]]; then
265    echo "<rad=ecrad> is only supported for <phy=phylmd> here"  # (Amaury) I added this check because we fetch ecrad data from libf/phylmd/ecrad/data only.
266  fi
267}
268
269#---------------------------------------------------------------------------
270function install_model() {
271#---------------------------------------------------------------------------
272  mkdir -p "$LMDZD"
273
274  local ins_xios ins_cosp ins_aero ins_inlandsis
275  if [[ $xios = "y" ]]; then ins_xios="-xios"; else ins_xios=""; fi
276  if [[ $cosp = "y" ]]; then ins_cosp="-cosp v1"; else ins_cosp=""; fi
277  if [[ $aerosols = "spla" ]]; then ins_aero="-spla"; else ins_aero=""; fi
278  if [[ $inlandsis = "y" ]]; then ins_inlandsis="-inlandsis"; else ins_inlandsis=""; fi
279  if [[ -n $svn ]]; then svnopt="-r $svn"; else svnopt=""; fi
280
281  if [[ $PARALLEL == 0 ]] ; then parallel= ; parsuf=seq ; else parallel="-parallel mpi_omp" ; parsuf= ; fi
282  version_name=LMDZ$(echo "$version" | sed -e 's/-v//g' -e 's/-unstable//' -e 's/-r/r/' -e 's/ //g')
283  LMDZname="${version_name}${svn}OR$veget${ins_xios}${parsuf}$( echo $optim | sed -e 's/[\ -]//g' )"
284  MODEL="$LMDZD/$LMDZname/modipsl/modeles/LMDZ"
285
286  if [[ -d $MODEL ]]; then echo "Found existing install at MODEL=$MODEL"; fi
287  if [[ $install = "y" ]]; then
288     echo "Installing model"
289     cd "$LMDZD"
290     cp "$local_d/install_lmdz.sh" .
291     chmod +x install_lmdz.sh
292     local make_j=8
293     # We launch using $MPICMD, except if it's using mpirun (no srun equivalent for bash script) => if supported, the compilation runs in a cluster job
294     jobcmd="\"$RUNBASHCMD $make_j\""
295     if [[ ${hostname:0:5} = "jean-" ]]; then jobcmd="\"$RUNBASHCMD $make_j --partition=compil\""; fi  # On JeanZay: compile on the <compil> partition
296     if [[ $(echo "$RUNBASHCMD" | cut -c -4) = "bash" ]]; then
297        jobcmd="bash"
298     fi
299     echo "./install_lmdz.sh -noclean $optim -v $version $svnopt -d $resol -rad $rad -bench compile_only $parallel $ins_cosp $ins_xios $ins_aero $ins_inlandsis -name $LMDZname -veget $veget -netcdf $netcdf -arch $ARCH -make_j $make_j -jobcmd $jobcmd" $save_pub_opt >> install_lmdz_options.$$.sh
300     chmod +x install_lmdz_options.$$.sh
301     echo "Running install_lmdz_options.$$.sh"
302     set -o pipefail
303       ./install_lmdz_options.$$.sh
304       #gcm=$MODEL/$(./install_lmdz_options.$$.sh | tee /dev/tty | tail -n 1 | sed -n "s:.* executable is \(.*\.e\).*:\1:p")
305       gcm=$MODEL/bin/gcm.e
306     set +o pipefail
307     mv install_lmdz.sh install_lmdz.$$.sh
308  else 
309    echo "install=n no need to install and recompile the model (already done)"
310    gcm=$MODEL/bin/gcm.e
311  fi 
312  cd "$local_d"
313}
314
315#---------------------------------------------------------------------------
316function setup_def() {  # modify various .def in ./DEF (+ xios xml )
317#---------------------------------------------------------------------------
318  cd "$local_d"
319
320  # Utilisation des .def_iso pour LMDZ-ISOtopes
321  if [[ $phylmd = "lmdiso" ]]; then
322    for file_iso in $(ls DEF | grep _iso); do
323      cp DEF/"$file_iso" DEF/"${file_iso%%_iso}"
324    done
325  fi
326
327  ######################################################################
328  # Choix de la grille verticale
329  ######################################################################
330  if [ ! -f "DEF/DYN/L$lm.def" ]; then
331    echo "STOP: Résolution verticale non prévue - créer un fichier DEF/DYN/L$lm.def"; exit 1
332  else
333    sed -i'' -e "s/INCLUDEDEF=L.*.def/INCLUDEDEF=L$lm.def/" DEF/run.def
334    cp DEF/DYN/L$lm.def DEF/
335  fi
336
337  ######################################################################
338  # Changements dans les fichiers DEF/*def
339  # (ils vont se repercuter dans les repertoires de simulation $local_d/$SIM et de run $SIMRUNDIR)
340  ######################################################################
341
342  # Choix du fichier tracer.def coherent avec l'option "aerosols"
343  #  NOTE : Le nouveau tracer.def_nospla par defaut n'inclut pas Rn-Pb;
344  #  si on les veut, il faut utiliser ci-dessous; a la place, tracer_RN_PB.def
345  #---------------------------------------------------------------------
346  # NB : Les traceurs absents de start* files sont initialises=0 dans le code
347  if [[ $aerosols = "spla" ]]; then
348    # nouveau tracer.def (remplace "traceur.def")
349    cp DEF/CONFIG/traceur.def_spla DEF/traceur.def
350    \rm -f DEF/tracer.def
351  elif [[ $phylmd = "lmdiso" ]]; then
352    # déjà copié si 'y'
353    cp DEF/CONFIG/tracer.def_nospla DEF/tracer.def
354  fi
355
356  # TEMPORAIREMENT pour spla on force l'utilisation de gcm.def_zNAfrica_BiJe (avec resolution 128x88x79)
357  #----------------------------------------------------------------------
358  if [[ $aerosols = "spla" ]]; then
359      cp DEF/DYN/gcm.def_zNAfrica_BiJe DEF/gcm.def; fi
360
361  # Inscription du choix ok_guide dans DEF/guide.def
362  #---------------------------------------------------------------------
363  sed -i'' -e 's/ok_guide=.*.$/ok_guide='$ok_guide'/' DEF/guide.def
364
365  # Inscription du type de calendrier (qui est fonction de $climato) dans DEF/run.def
366  #---------------------------------------------------------------------
367  # NB Contrairement a ce qui est ecrit dans les fichiers run.def standard,
368  # dans ce tutorial le choix earth_365d n'est pas disponible, et earth_366d s'appelle gregorian
369  if [[ $climato = 0 ]]; then calend="gregorian"; else calend="earth_360d"; fi
370  sed -i'' -e 's/calend=.*.$/calend='$calend'/' DEF/run.def
371
372  # Changements dans config.def (pre-choisi, et regle pour output si utilisation avec IOIPSL)
373  #   cf options veget, aerosols, cosp, xios
374  #---------------------------------------------------------------------
375  if [[ $veget = "none" ]]; then  VEGET="n"; else VEGET="y"; fi
376  sed -i'' -e 's/VEGET=.*.$/VEGET='$VEGET'/' DEF/config.def
377
378  ok_cdnc=y ; ok_ade=y ; ok_aie=y ; ok_alw=y
379  case $aerosols in
380    clim) flag_aerosol=6 ;;
381    spla) flag_aerosol=1 ;;
382    n)    flag_aerosol=0 ; ok_cdnc=n ; ok_ade=n ; ok_aie=n ; ok_alw=n ;;
383    *)    echo Option aerosols=$aerosols not available ; exit 1
384  esac
385  sed -i'' -e 's/^ok_cdnc=.*.$/ok_cdnc='$ok_cdnc'/' \
386           -e 's/^ok_ade=.*.$/ok_ade='$ok_ade'/' \
387           -e 's/^ok_aie=.*.$/ok_aie='$ok_aie'/' \
388           -e 's/^ok_alw=.*.$/ok_alw='$ok_alw'/' \
389           -e 's/^flag_aerosol=.*.$/flag_aerosol='$flag_aerosol'/' DEF/config.def
390  pwd
391
392  # COSP : ok_cosp desactive COSP si on a compile avec; il ne l'active pas si on a compile sans
393  sed -i'' -e 's/ok_cosp.*.$/ok_cosp='$cosp'/' DEF/config.def
394  if [[ $cosp = "y" ]]; then \cp -f "$MODEL"/DefLists/cosp*.txt "$local_d"/DEF/; fi
395
396  # Sorties LMDZ en fonction de l'option "xios"
397  sed -i'' -e 's/ok_all_xml=.*.$/ok_all_xml='$xios'/' DEF/config.def
398
399  # Ajuster physiq.def en fonction de radiative code (default: values for rad=rrtm)
400  #   Pour isotopes=y , mettre iflag_ice_thermo=0 au lieu de 1
401  #---------------------------------------------------------------------
402  sed -i'' -e "s/iflag_rrtm=.*.$/iflag_rrtm=$iflag_rrtm/" -e "s/NSW=.*.$/NSW=$NSW/" DEF/physiq.def
403  sed -i"" -e "s:directory_name.*$:directory_name=\"$MODEL/libf/phylmd/ecrad/data\",:" DEF/namelist_ecrad
404
405  if [[ $phylmd = "lmdiso" ]]; then iflag_ice_thermo=0; else iflag_ice_thermo=1; fi
406  sed -i -e 's/iflag_ice_thermo=.*.$/iflag_ice_thermo='$iflag_ice_thermo'/' DEF/physiq.def
407
408  # Choix de orchidee.def en fonction de orchidee_rev; modification pour xios
409  #  NOTE separate orchidee_pft.def file for ORCHIDEE trunk post-CMIP6
410  #---------------------------------------------------------------------
411  orchidee_def=orchidee.def_6.1
412  orchidee_pft_def=""
413  if [[ $veget = "7983" ]]; then
414    orchidee_def=orchidee.def_6.2work
415  elif [[ $veget = "8758" ]]; then
416    orchidee_def=orchidee.def_6.4work
417    orchidee_pft_def=orchidee_pft.def_6.4work
418    if ! grep "INCLUDEDEF=orchidee_pft.def" DEF/run.def; then
419      sed -i'' -e 's/INCLUDEDEF=orchidee.def/INCLUDEDEF=orchidee.def\nINCLUDEDEF=orchidee_pft.def/' DEF/run.def; fi
420  fi
421  cp -f DEF/CONFIG/$orchidee_def DEF/orchidee.def
422  if [[ $orchidee_pft_def != "" ]]; then cp -f DEF/CONFIG/$orchidee_pft_def DEF/orchidee_pft.def; fi
423
424  # Only for veget=CMIP6 it is still possible to use IOIPSL; newer versions of orchidee.def have XIOS_ORCHIDEE_OK = y
425  sed -i'' -e 's/XIOS_ORCHIDEE_OK =.*.$/XIOS_ORCHIDEE_OK = '$xios'/' DEF/orchidee.def
426
427  ######################################################################
428  # Si on tourne avec XIOS, mise a jour des fichiers context et field* dans XMLfilesLMDZ
429  # (ils vont se repercuter dans les repertoires de simulation $local_d/$SIM et de run $SIMRUNDIR)
430  ######################################################################
431  if [[ $xios = y ]]; then
432    cp -f "$MODEL"/DefLists/context_lmdz.xml "$local_d"/DEF/XMLfilesLMDZ/.
433    cp -f "$MODEL"/DefLists/field_def_lmdz.xml "$local_d"/DEF/XMLfilesLMDZ/.
434    if [[ $cosp = y ]]; then cp -f "$MODEL"/DefLists/field_def_cosp1.xml "$local_d"/DEF/XMLfilesLMDZ/.; fi
435  fi
436}
437
438#---------------------------------------------------------------------------
439function setup_ce0l() { # Verification de l'existance de l'état initial, compilation eventuelle pour sa creation
440#---------------------------------------------------------------------------
441  if [[ ! -d $INIT ]]; then
442    if [[ $init = 0 ]]; then
443      echo "STOP: Récuperer les repertoires $INIT ou lancer avec option -init"; exit 1
444    else
445      # Compile ce0l
446      cd "$MODEL"
447      sed -e 's/gcm/ce0l/g' compile.sh > compile_ce0l.sh; chmod +x compile_ce0l.sh
448      echo "Compiling ce0l"
449      if ! ./compile_ce0l.sh &> ce0l.log; then echo "STOP: ce0l compilation failed, see $MODEL/ce0l.log"; exit 1; fi
450      echo "Compiled ce0l"
451      ce0l=${gcm/gcm/ce0l}
452
453      cd "$local_d"
454    fi
455  elif [[ $init = 1 ]]; then
456    echo "STOP: Vous essayez d initialiser le modele mais $INIT existe deja"; exit 1
457  fi
458}
459
460#---------------------------------------------------------------------------
461function setup_simu() {
462#---------------------------------------------------------------------------
463  #SIMRUNTOPDIR="$SIMRUNBASEDIR/$(basename "$local_d")"
464  SIMRUNTOPDIR="$SIMRUNBASEDIR"
465  SIMRUNDIR=$SIMRUNTOPDIR
466  mkdir -p "$SIMRUNDIR"
467  cd "$SIMRUNDIR"
468  echo "La simulation s'exécutera sur $SIMRUNDIR"
469
470  #####################################################################
471  # Creation du repertoire $SIM s'il n'existe pas deja
472  #####################################################################
473  if [[ ! -d $local_d/$SIM ]]; then
474    mkdir "$local_d/$SIM"
475    cd "$local_d"
476
477    # Edit reb.sh
478    cp reb.sh "$local_d/$SIM/reb.sh"; chmod +x "$local_d/$SIM/reb.sh"
479    sed -i'' -e "s:^rebuild=.*.$:rebuild=$LMDZD/$LMDZname/modipsl/bin/rebuild:" "$local_d/$SIM/reb.sh"
480    enable_platform "$local_d/$SIM/reb.sh"
481
482    # Copy .def
483    cp lmdz_env.sh "$local_d/$SIM/"
484    mkdir "$local_d/$SIM/DEF"; cp DEF/*def DEF/namelis* "$local_d/$SIM/DEF/"
485    #Pour XIOS, respectivement COSP, copier aussi les fichiers *xml / *txt
486    if [[ $cosp = "y" ]]; then cp DEF/cosp*txt "$local_d/$SIM/DEF/"; fi
487    if [[ $xios = "y" ]]; then
488       cp DEF/XMLfilesLMDZ/*xml "$local_d/$SIM/DEF/"
489       if [[ $veget != 'none' ]]; then cp DEF/XMLfilesOR$veget/*xml "$local_d/$SIM/DEF/"; fi
490    fi
491    chmod u+w "$local_d/$SIM"/DEF/*
492
493    # Gestion du calendrier
494    #######################
495    cd "$SIM"
496    sed -i'' -e "s/anneeref=.*.$/anneeref=$yearini/" DEF/run.def
497    if [[ $freq = "yr" ]]; then date=$yearini; else date=$mthini; fi
498    echo "$date a faire" >| etat
499
500    # Recuperation des fichiers : executable initiaux et forcages
501    #############################################################
502    echo "date: $date"
503    for f in start startphy; do
504      inf=../$INIT/$f.$date.nc
505      if [[ -f $inf || $init = 1 ]]; then ln -s "$inf" ./; else echo "STOP: $inf missing"; exit ; fi;
506    done
507    for f in sechiba stomate; do
508      if [[ -f ../$INIT/start_$f.$date.nc ]]; then ln -sf "../$INIT/start_$f.$date.nc" .; fi
509    done
510    cp "$gcm" gcm.e
511  fi
512  cd "$local_d"/..
513
514  #####################################################################
515  echo "Modification du script de lancement"
516  #####################################################################
517  local cput
518  if [[ $freq = "yr" ]]; then cput="04:00:00"; else cput="01:00:00"; fi
519  local isotopes="n"
520  if [[ $phylmd = "lmdiso" ]]; then isotopes="y"; fi
521  sed -e "s/NOM_SIMU/$SIM/" \
522  -e "s/time=.*.$/time=$cput/" \
523  -e "s/ntasks=.*.$/ntasks=$mpi/" \
524  -e "s/ntasks-per-node=.*.$/ntasks-per-node=$mpi_per_node/" \
525  -e "s/cpus-per-task=.*.$/cpus-per-task=$omp/" \
526  -e "s/nthreads=.*./nthreads=$omp/" \
527  -e "s/MAINDIR=.*.$/MAINDIR=$(basename "$local_d")/" \
528  -e "s:STORED=.*.*:STORED=$(dirname "$local_d"):" \
529  -e "s:SCRATCHD=.*.*:SCRATCHD=$SIMRUNBASEDIR:" \
530  -e "s/stopsim=.*.$/stopsim=$stopsim/" \
531  -e "s/^veget=.*.$/veget=$veget/" \
532  -e "s/^aerosols=.*.$/aerosols=$aerosols/" \
533  -e "s/^isotopes=.*.$/isotopes=$isotopes/" \
534  -e "s/^climato=.*.$/climato=$climato/" \
535  -e "s/^ok_guide=.*.$/ok_guide=$ok_guide/" \
536  "$local_d/script_SIMU" >| "$SIMRUNDIR/tmp_$SIM"
537
538  enable_platform "$SIMRUNDIR/tmp_$SIM"
539
540  if [[ $testmode = "y" ]]; then
541    sed -i'' -e "s/time=.*.$/time=00:10:00/" -e "s/#nday=1/nday=1/" -e "s/#@TESTQ//" "$SIMRUNTOPDIR/tmp_$SIM"
542  fi
543}
544
545#----------------------------------------------------------------------
546function list_yrmth() {
547#----------------------------------------------------------------------
548    local liste=""
549    local mthini=$1
550    local mthend=$2
551    local mo_=$mthini
552    while [[ $mo_ != $mthend ]] ; do
553        liste="$liste $mo_"
554        yr__=$( echo $mo_ | cut -c 1-4 )
555        mo__=$( echo $mo_ | cut -c 5-6 )
556        echo YM $yr__ $mo__
557        if [ $(( $mo__ +1 )) == 12 ] ; then
558           yr__=$(( $yr__ + 1 )) ; mo_=$yr__$mo__
559        else
560           mo_=$(( $mo_ + 1 ))
561        fi
562    done
563    echo $liste
564   
565}
566
567#----------------------------------------------------------------------
568increment_month() {
569#----------------------------------------------------------------------
570  local year=$( echo $1 | cut -c 1-4 )
571  local month=$(( $1 - ${year}00 ))
572  if [ $(( $month - 12 )) -eq 0 ]; then
573    year=$((year + 1))
574    month=1
575  else
576    month=$((month + 1))
577  fi
578  if [[ $month -le 9 ]] ; then month=0$month ; fi
579  echo $year$month
580}
581
582#----------------------------------------------------------------------
583function fetch_simu_init_files() {
584#----------------------------------------------------------------------
585  #####################################################################
586  echo "Recuperation eventuelle de certains fichiers sur http:lmdz.lmd.jussieu.fr/pub"
587  #####################################################################
588
589  #  ORCHIDEE input files
590  get_input_files wget_pub Orchidee
591
592  # Files for aerosols and chemistry
593  if [[ $aerosols = "clim" ]]; then
594       get_input_files wget_pub AerChem ; fi
595
596  # Files for SPLA
597  if [[ $aerosols = "spla" ]]; then
598       get_input_files wget_pub SPLA_WA/emissions
599       mo_=$mthini
600       while [[ $mo_ != $mthend ]] ; do
601       # Code horrible duplique a cause de 08 (FH)
602           local yr__=$( echo $mo_ | cut -c 1-4 )
603           local mo__=$(( $mo_ - ${yr__}00 ))
604           if [[ $mo__ -le 9 ]] ; then mo__=0$mo__ ; fi
605           for var in u10m v10m u v ; do
606               echo wget_pub 3DInputData/SPLA_WA/ERA5/$yr__/$mo__ $var.nc
607               wget_pub 3DInputData/SPLA_WA/ERA5/$yr__/$mo__ $var.nc
608           done
609           mo_=$( increment_month $mo_ )
610       done
611       cd $local_d ; ln -sf $LMDZ_INIT/3DInputData/SPLA_WA/ERA5 GUIDE
612  fi
613}
614
615#----------------------------------------------------------------------
616function run_sim_or_init() {
617#----------------------------------------------------------------------
618  cd "$local_d"
619
620  if [[ $init = 1 ]]; then
621    #####################################################################
622    echo "Creation de l etat initial"
623    #####################################################################
624
625    # Creation du repertoire INIT et mise en place de liens logiques vers les starts
626    # en anticipation de leur création :
627    mkdir "$local_d/$INIT"; cd "$local_d/$INIT"
628    for an in $mthini $yearini; do for f in start startphy; do ln -s "$f.nc" "$f.$an.nc"; done; done
629
630    # Creation du repertoire INIT temporaire et rapatriement des fichiers necessaires
631    if [[ -d $SIMRUNDIR/$INIT ]]; then mv "$SIMRUNDIR/$INIT" "$SIMRUNDIR/$INIT$$"; fi
632    mkdir "$SIMRUNDIR/$INIT"; cp -r "$local_d/DEF" "$SIMRUNDIR/$INIT/"
633    cd "$SIMRUNDIR/$INIT"; cp DEF/*.def .; cp "$local_d/lmdz_env.sh" .
634    if [[ $xios = "y" ]]; then
635      cp DEF/XMLfilesLMDZ/*xml .
636      if [[ $veget != 'none' ]]; then cp DEF/XMLfilesOR$veget/*xml .; fi
637    fi
638    sed -e "s/anneeref=.*.$/anneeref=$yearini/" DEF/run.def >| run.def
639
640    #-------------------------------------------------------------------
641    # Fichiers Limit
642    #-------------------------------------------------------------------
643    local yrs suf
644    if [[ $climato = 0 ]]; then
645      # calend est choisi plus haut dans "Changements dans les fichiers DEF/*def" et ecrit dans $MAINDIR/DEF/run.def
646      yrini=$(echo "$mthini" | cut -c-4)
647      yrend=$(echo "$mthend" | cut -c-4)
648      yrs=""; yr=$yrini
649      while [[ $yr -le $yrend ]]; do yrs="$yrs $yr"; (( yr = yr + 1 )); done
650      suf="360x180_"
651    else
652      yrs=2000
653      suf="1x1_clim"
654    fi
655
656    liste_get="Albedo.nc Relief.nc Rugos.nc landiceref.nc"
657    for yr in $yrs; do
658       if [[ $climato = 0 ]]; then sufyr=$suf$yr; else sufyr=$suf; fi
659       liste_get="$liste_get amipbc_sic_$sufyr.nc amipbc_sst_$sufyr.nc"
660    done
661    echo LISTEGET "$liste_get"
662    for file in $liste_get; do
663       wget_pub 3DInputData/Limit $file
664       ln_from_pub  3DInputData/Limit $file
665    done
666    #-------------------------------------------------------------------
667    # Initial state ECDYN
668    #-------------------------------------------------------------------
669    wget_pub 3DInputData/Init ECDYN.nc
670    ln_from_pub 3DInputData/Init ECDYN.nc
671    ln -sf ECDYN.nc ECPHY.nc
672
673    # Creation du script d'initialisation
674  if [ "$MPICMD" = "" ] ; then mpicmd='' ; else mpicmd='OMP_NUM_THREADS=1 '"$MPICMD"' 1' ; fi
675    cat << ...eod >| tmp
676#!/bin/bash
677#@JZ#JeanZay
678#@JZ#SBATCH --job-name=Init         # nom du job
679#@JZ#SBATCH --ntasks=1              # Nombre de processus MPI
680#@JZ#SBATCH --cpus-per-task=1      # nombre de threads OpenMP
681#@JZ# /!\ Attention, la ligne suivante est trompeuse mais dans le vocabulaire
682#@JZ# de Slurm "multithread" fait bien référence à l'hyperthreading.
683#@JZ#SBATCH --hint=nomultithread    # 1 thread par coeur physique (pas d'hyperthreading)
684#@JZ#SBATCH --time=00:10:00         # Temps d'exécution maximum demandé (HH:MM:SS)
685#@JZ#SBATCH --output=Init%j.out     # Nom du fichier de sortie
686#@JZ#SBATCH --error=Init%j.out      # Nom du fichier d'erreur (ici commun avec la sortie)
687#@JZ# To submit to dev queue; "time" (above) must be max 2h
688#@JZ#TESTQ#SBATCH --qos=qos_cpu-dev
689#@SP#Spirit
690#@SP#SBATCH --job-name=Init
691#@SP#SBATCH --ntasks=1
692#@SP#SBATCH --cpus-per-task=1
693#@SP#SBATCH --hint=nomultithread
694#@SP#SBATCH --time=00:10:00
695#@SP#SBATCH --output=Init%j.out
696#@SP#SBATCH --error=Init%j.out
697#@ADS#Adastra
698#@ADS#SBATCH --job-name=Init
699#@ADS#SBATCH --ntasks=1
700#@ADS#SBATCH --cpus-per-task=1
701#@ADS#SBATCH --nodes=1
702#@ADS#SBATCH --hint=nomultithread
703#@ADS#SBATCH --time=00:10:00
704#@ADS#SBATCH --output=Init%j.out
705#@ADS#SBATCH --error=Init%j.out
706
707set -eu
708
709# ANCIEN MULTI STEP  case \${LOADL_STEP_NAME} in
710
711# ANCIEN MULTI STEP   init )
712
713if [ ! -f lmdz_env.sh ]; then echo "manque fichier lmdz_env.sh"; ls; exit 1; fi
714. lmdz_env.sh
715ulimit -s unlimited
716cd $SIMRUNDIR/$INIT
717echo "Executable : $ce0l"
718for yr in $yrs; do
719  if [ $climato = 0 ]; then sufyr=$suf\$yr; else sufyr=$suf; fi
720  ln -sf amipbc_sic_\$sufyr.nc amipbc_sic_1x1.nc
721  ln -sf amipbc_sst_\$sufyr.nc amipbc_sst_1x1.nc
722  sed -e 's/anneeref=.*.$/anneeref='\$yr'/' DEF/run.def >| run.def
723  echo Starting initialisation
724  # Runing ce0l.e
725  $mpicmd $ce0l  # ce0l requires MPI=OMP=1
726  if [ $climato = 0 ]; then mv limit.nc limit.\$yr.nc; fi
727done
728# ANCIEN MULTI STEP   ;;
729
730# ANCIEN MULTI STEP   interp )
731if [[ $aerosols = clim ]]; then
732  cp $local_d/interp_aerosols.sh .; chmod +x interp_aerosols.sh
733  # Les aerosols de l'annee 2000 ont été remplacés par "9999" qui pointe vers un fichier moyen sur 1995-2014
734  #for year in 2000 1850; do  ./interp_aerosols.sh \$year; done
735  #mv aerosols.2000.nc aerosols.clim.nc; mv aerosols.1850.nc aerosols.nat.nc
736  for year in 9999 1850; do ./interp_aerosols.sh \$year; done
737  mv aerosols.9999.nc aerosols.clim.nc; mv aerosols.1850.nc aerosols.nat.nc
738fi
739
740for f in sta* gri*nc; do cp \$f $local_d/$INIT/\$f; done
741if [[ $climato = 1 ]]; then cp limit.nc $local_d/$INIT/limit.nc; fi
742mkdir -p $local_d/$LIMIT
743for f in limit*.nc ; do cp \$f $local_d/$LIMIT/\$f; done
744if [ $aerosols = clim ]; then  for f in aerosols[.0-9]*nc; do cp \$f $local_d/$LIMIT/\$f; done; fi
745#
746cd $SIMRUNDIR
747...eod
748    if [[ $ok_guide != "y" ]]; then # Running first simulation automatically except for nudging
749      cat << ...eod >> tmp
750      echo "Submitting job tmp_$SIM"
751      #echo "\$SUBMITCMD tmp_$SIM"
752      #\$SUBMITCMD tmp_$SIM
753      echo submitcmd tmp_$SIM
754      submitcmd tmp_$SIM
755...eod
756    fi
757    cat << ...eod >> tmp
758  # ANCIEN MULTI STEP   esac
759...eod
760    enable_platform tmp
761    echo "#################################################################"
762    #echo "Submitting initialisation job <$SUBMITCMD tmp> from $(pwd)"
763    echo "Submitting initialisation job <submitcmd tmp> from $(pwd)"
764    chmod +x tmp
765    #$SUBMITCMD tmp
766    submitcmd tmp
767    echo "#################################################################"
768
769  else #case [ $init != 1 ]
770     cd "$SIMRUNDIR"
771     echo "################################################################"
772     echo "Submitting job tmp_$SIM"
773     #echo "$SUBMITCMD tmp_$SIM"
774     #$SUBMITCMD "tmp_$SIM"
775     echo "submitcmd tmp_$SIM"
776     submitcmd "tmp_$SIM"
777     echo '################################################################'
778  fi
779}
780
781#---------------------------------------------------------------------------
782function message_post_submit() {
783#---------------------------------------------------------------------------
784  if [[ $ok_guide = "y" && $init = 1 ]]; then
785    cd "$local_d"
786    enable_platform era2gcm_tuto.sh
787    echo "Once initialisation is finished, you have to create nudging files"
788    echo "Edit era2gcm_tuto.sh and set the desired parameters in section <User choices>"
789    echo "Make sure you have acces to the chosen ERA files, and the required modules are loaded, then run : ./era2gcm_tuto.sh"
790    if [[ $aerosols = "spla" ]]; then
791      echo "Your aerosol choice is <spla>, so you need ERA 10m-winds interpolated on LMDZ grid. Use script era2gcm_uv10m.sh"
792    fi
793  else
794    echo "Si tout se passe bien, vous avez initialisé et lancé automatiquement la simulation."
795    echo "Le job qui a été lancé se trouve sur $SIMRUNTOPDIR/tmp_$SIM"
796  fi
797}
798
799#---------------------------------------------------------------------------
800function setup_and_load_lmdz_env() {
801#---------------------------------------------------------------------------
802  if [[ ! -f .lmdz_setup_root_dir ]]; then echo "STOP: setup.sh is not located in the root dir ??!!"; exit 1; fi
803  # sed root_dir in lmdz_env.sh
804  sed -i'' "s<root_dir=.*<root_dir=$local_d<" lmdz_env.sh
805
806  # Set up the appropriate environment
807  source lmdz_env.sh
808}
809
810local_d=$(pwd)
811
812setup_and_load_lmdz_env
813load_install_lib
814define_expert_options
815set_default_params
816read_cmdline_args "$@"
817ensure_correct_option_combinations
818install_model
819setup_def
820setup_ce0l
821setup_simu
822fetch_simu_init_files
823run_sim_or_init
824message_post_submit
Note: See TracBrowser for help on using the repository browser.