source: BOL/LMDZ_Setup_amaury/setup.sh @ 4942

Last change on this file since 4942 was 4940, checked in by abarral, 7 weeks ago

(WIP)
move compile-relevant args to install_lmdz

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