source: BOL/LMDZ_Setup_amaury/setup.sh @ 4991

Last change on this file since 4991 was 4991, checked in by abarral, 3 months ago

Improve docs
Fix bug on sequential sim when running locally
Fix crash when running init without slurm (ce0l w/o OMP_NUM_THREADS=1)
Fix crash for climato=0 due to missing limit.nc

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