source: BOL/LMDZ_Setup/script_SIMU @ 4752

Last change on this file since 4752 was 4752, checked in by asima, 7 months ago

The log file for Orchidee, out_orchidee.0000.0000, will be only saved on $STORE if $VEGET=y, and if the line is uncommented on purpose

File size: 14.4 KB
Line 
1#!/bin/bash
2#
3#SBATCH --job-name=NOM_SIMU         # nom du job
4#SBATCH -A groupe@cpu
5# Nombre de processus MPI :
6#SBATCH --ntasks=8
7# number of MPI processes per node :
8#SBATCH --ntasks-per-node=5
9# nombre de threads OpenMP
10#SBATCH --cpus-per-task=5
11# de Slurm "multithread" fait bien reference a l'hyperthreading.
12#SBATCH --hint=nomultithread       # 1 thread par coeur physique (pas d'hyperthreading)
13#SBATCH --time=00:30:00            # Temps d execution maximum demande (HH:MM:SS)
14#SBATCH --output=outNOM_SIMU%j     # Nom du fichier de sortie
15#SBATCH --error=outNOM_SIMU%j      # Nom du fichier d'erreur (ici commun avec la sortie)
16#
17# To submit to test queue ; "time" (above) must be max 30 min
18# #SBATCH --qos=qos_cpu-dev
19
20set -ex
21
22
23ntasks=8
24nthreads=4
25# number of OpenMP threads:
26export OMP_NUM_THREADS=$nthreads
27# private memory for each thread
28export OMP_STACKSIZE=800M
29# Binding
30export OMP_PLACES=cores
31
32simul=NOM_SIMU
33ulimit -s unlimited
34#### reste ada  : export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/smplocal/pub/NetCDF/4.1.3/lib:/smplocal/pub/HDF5/1.8.9/seq/lib
35
36
37reseau_local=0
38#veget=y
39veget=CMIP6
40if [ $veget = NONE ] ; then VEGET=n ; else VEGET=y ; fi 
41
42isotopes=n
43# If isotopes=y, initialisation_iso will be changed to 0 in iso.def after the 1st run period, to read isotopes in restart files
44
45# Choice of aerosols : n / clim / spla
46aerosols=clim
47stopsim=201101
48ok_guide=y   # y/n guidage ou non
49climato=1
50orchidee_rev=5004
51
52echo '##############################################################'
53echo '# Gestion des repertoires de lancement                                 '
54echo '##############################################################'
55
56# Repertoires de la simulation
57SCRATCHD=$SCRATCH
58STORED=$STORE
59MAINDIR=LMDZOR96x95x79
60SIMU_dir=$MAINDIR/$simul
61SIMUDIR=$STORED/$SIMU_dir
62
63# Repertoires de travail
64WWORKD=$SCRATCHD/$SIMU_dir$$
65mkdir -p $WWORKD
66cd $WWORKD
67SCRIPTDIR=$SCRATCHD/$MAINDIR
68
69cp $STORED/$MAINDIR/lmdz_env.sh . ; . lmdz_env.sh
70ERADIR=$STORED/$MAINDIR/GUIDE
71if [ "$aerosols" = "spla" ] ; then ERA10mDIR=$STORED/$MAINDIR/ERA10m ; fi
72LIMITDIR=$STORED/$MAINDIR/LIMIT
73SPLADIR=$STORED/$MAINDIR/INPUT_SPLA
74DEFDIR=$SIMUDIR/DEF
75
76GET='ln -s'
77PUT='mv '
78
79
80echo '##################################################################'
81echo 'Gestion des mois et annees'
82echo '##################################################################'
83
84$GET $SIMUDIR/etat
85year=`tail -1 etat | awk ' { print $1 } ' | cut -c1-4`
86month=`tail -1 etat | awk ' { print $1 } ' | cut -c5-`
87echo year $year month $month
88
89if [ "$month" = "" ] ; then
90   paran=1
91   ym=$year
92   next=`expr $ym + 1`
93else
94   paran=0
95   if [ $month = 12 ] ; then
96      nextmonth=1
97      nextyear=`expr $year + 1`
98   else
99      nextmonth=`expr $month + 1`
100      nextyear=$year
101   fi
102   if [ `echo $nextmonth | wc -m` = 2  ] ; then
103      nextmonth=0$nextmonth
104   fi
105   ym=$year$month
106   next=$nextyear$nextmonth
107fi
108
109
110echo ym $ym
111echo mois ancien  : $ym
112echo mois nouveau : $next
113
114INI=${SPLADIR}/INITIAL
115PERIOD=${SPLADIR}/PERIOD00${month}/SUB
116
117echo '#################################################################'
118echo 'Modification de run.def et gcm.def pour prendre en compte la duree du'
119echo 'du mois en question.'
120echo 'le dayref est modifie pour tricher avec le calendrier (ecrit pour'
121echo 'une annee de 260 jours dans le modele).'
122echo 'On passe donc comme jour de reference le numero du jour du mois dans'
123echo 'une annee en 360 jours.'
124echo '#################################################################'
125
126# Choix du calendrier
127#AS: La condition if "$climato" = "0" suffit, car "$ok_guide" = "y" est interdit avec $climato" = "1" dans setup.sh (exit ligne 160)
128##calend=earth_360d
129##if [ "$ok_guide" = "y" -o "$climato" = "0" ] ; then calend=gregorian ; fi
130if [ "$climato" = "0" ] ; then calend=gregorian ; else calend=earth_360d ; fi
131bisextile=0
132if [ $(( $year % 4 )) = 0 -a $calend = gregorian ] ; then bisextile=1 ; fi
133if [ $paran = 0 ] ; then
134   if [ "$calend" = "gregorian" ] ; then
135      ndays=( 31 28 31 30 31 30 31 31 30 31 30 31 )
136      if [ $bisextile = 1 ] ; then ndays[1]=29 ; fi
137   else
138      ndays=( 30 30 30 30 30 30 30 30 30 30 30 30 )
139   fi
140   #Constants with a leading 0 are interpreted as octal numbers.
141   # You can remove the leading zero by parameter expansion: hour=${hour#0}
142
143   nday=${ndays[(( ${month#0} - 1 ))]}
144   ndayh=$nday
145   dayref=1 ; mm=1 ; while [ $mm -lt ${month#0} ] ; do
146    (( dayref = $dayref + ${ndays[(( $mm - 1 ))]} )) ; (( mm = $mm + 1 )) ; done
147else
148   dayref=1
149   if [ "$calend" = "gregorian" ] ; then
150      if [ $bisextile = 0 ] ; then nday=365 ; else nday=366 ; fi
151   else
152      nday=360 ; ndayh=30
153   fi
154fi
155
156echo CALENDRIER $calend : longueur du mois vrai $year $month $nday dayref=$dayref
157
158
159echo '####################################################################'
160echo '# On va chercher les fichiers necessaires a la simulation'
161echo '####################################################################'
162#Reminder : we are in $WWORKD = $SCRATCHD/$SIMU_dir = $SCRATCHD/$MAINDIR/$simul
163
164echo DEFDIR $DEFDIR
165echo SIMUDIR $SIMUDIR
166echo simul $simul
167
168if [ $reseau_local = 0 ] ; then mkdir DEF ; cd DEF ; $GET $DEFDIR/* . ; cd .. ; fi
169
170cp -f DEF/* .
171#---The following changes in .def files will only be visible in the running directory (on SCRATCH if $reseau_local = 0)
172# They concern variables that change during runtime : nday, dayref, anneeref, ndayh
173# The other "sed" were totally or partially moved in setup.sh, to be done in $MAINDIR/DEF/*.def, before creating $MAINDIR/$SIMU (more transparent)
174#sed -e 's/ok_guide=.*.$/ok_guide='$ok_guide'/' DEF/guide.def >| guide.def
175#sed -e 's/nday=.*.$/nday='$nday'/' -e 's/dayref=.*.$/dayref='${dayref}'/' -e 's/calend=.*.$/calend='$calend'/' -e 's/anneeref=.*.$/anneeref='$year'/' DEF/run.def >| run.def
176
177#=====!!!!!!!!====!!!!!!====!!!!+++====!!!!!!====!!!!!!!=====!!!!!!====z!!!====!!!!========!!!!!========!!!
178##POUR que des TESTS soyent tres RAPIDES (pour ex, verifier fichiers input), ON FORCE nday=1 jour  !!!
179#nday=1
180#=====!!!!!!!!====!!!!!!====!!!!+++====!!!!!!====!!!!!!!=====!!!!!!====z!!!====!!!!========!!!!!========!!!
181
182sed -e 's/nday=.*.$/nday='$nday'/' -e 's/dayref=.*.$/dayref='${dayref}'/' -e 's/anneeref=.*.$/anneeref='$year'/' DEF/run.def >| run.def
183sed -e 's/phys_out_filetimesteps=[[:space:]]*[0-9][0-9]day/phys_out_filetimesteps=  '$ndayh'day/'  DEF/config.def >| config.def
184#--- End of *.def changes in the $WWORKD only
185
186${GET} $SIMUDIR/start.$ym.nc start.nc
187${GET} $SIMUDIR/startphy.$ym.nc startphy.nc
188if [ $climato = 1 ] ; then
189   ${GET} $LIMITDIR/limit.nc limit.nc
190else
191   ${GET} $LIMITDIR/limit.$year.nc limit.nc
192fi
193
194
195echo '####################################################################'
196echo '# Imports des fichiers aerosols si flag_aerosol>0 dans config.def, '
197echo '# et si dans setup.sh on a "aerosols=clim" ou "aerosols=spla". '
198echo '# NOTE: Si "aerosols=n" dans setup.sh, script_SIMU met flag_aerosol=0 et on tourne SANS aerosols' 
199echo '####################################################################'
200if [ "`grep 'flag_aerosol=' config.def | head -1 | cut -d= -f2`" != 0 ] ; then
201  if [ $aerosols = clim ] ; then
202    # if [ $climato = 1 ] ; then suf=clim ; else suf=$year ; fi
203    suf=clim
204    # Le script pourrait être sophistique pour prendre des aerosols interannuels
205    ${GET} $LIMITDIR/aerosols.$suf.nc aerosols$year.nc
206    if [ ! -f aerosols1980.nc ] ; then ${GET} $LIMITDIR/aerosols.$suf.nc aerosols1980.nc ; fi
207    ${GET} $LIMITDIR/aerosols.nat.nc aerosols.nat.nc
208  fi
209
210  ## Ca doit etre la meme liste de fichiers rapatriee par setup.sh dans $LMDZ_Init/SPLA_Init
211  ## et interpolee (setup.sh aussi) dans $SPLADIR
212  if [ $aerosols = spla ] ; then 
213    inputf="wth.dat cly.dat donnees_lisa.nc SOILSPEC.data \
214                carbon_emissions.nc sulphur_emissions_antro.nc  \
215                sulphur_emissions_nat.nc  sulphur_emissions_volc.nc"
216    for file in $inputf ; do ${GET} $INI/$file . ; done
217
218    change="dust.nc "
219    for file in $change ; do ${GET} $PERIOD/$file . ; done
220
221    # Le calcul d'emissions de sels marins utilise les vents ERA-10m interpoles sur grille_s (lonv,latu) avec le script era2gcm_uv10m.sh
222    # NB : GET=ln -s ; ERA10mDIR contient lui-meme le lien ERA10m vers le repertoire des vents interpoles $REA_uv10m (REA=ERA5, ERAI ou OPERA)
223    ventl="u10m.nc v10m.nc"
224    for file in $ventl ; do ${GET} $ERA10mDIR/${year}/${month}/$file . ; done
225  fi
226fi
227
228#----------------------------------------
229# Noveaux forcages a activer a l'avenir
230#   (commentes en attendant) :
231#----------------------------------------
232#for file in climoz_LMDZ.nc solarforcing.nc  taulwstrat.2D.nc  tauswstrat.2D.nc ; do
233#   ${GET} $LIMITDIR/$file $file
234#done
235#----------------------------------------
236
237${GET} $SIMUDIR/gcm.e gcm.e ; chmod  +x gcm.e
238
239
240if [ $VEGET = y ] ; then
241    set +e ; for t in stomate sechiba ; do cp $SIMUDIR/start_$t.$ym.nc ${t}_rest_in.nc ; done ; set -e
242    if [ "`grep RIVER_ROUTING orchidee.def |grep -i y`" ] ; then
243      set +e ; ln -s $LMDZ_Init/routing_simple.nc . ; ln -s $LMDZ_Init/routing.nc .
244               cp $SIMUDIR/start_routing.$ym.nc routing_start.nc ; set -e
245    fi
246
247#For Orchidee trunk (post-CMIP6), orchidee_pft.def must be copied in addition to orchidee.def
248    \cp -f DEF/orchidee*.def .
249
250# Test sur sechiba_rest_in.nc,
251#  supposant que les restarts pour sechiba, stomate, et routing le cas echeant,
252#  sont soit tous dispo, soit tous absents
253    if [ ! -f sechiba_rest_in.nc ] ; then
254       echo '#########################################################'
255       echo Autoinitialisation d orchidee au besoin
256       echo '#########################################################'
257       get="ln -s $LMDZ_Init/"
258       for file in cartepente2d_15min.nc \
259          lai2D.nc soils_param.nc soil_bulk_and_ph.nc alb_bg_modisopt_2D_ESA_v2.nc reftemp.nc ; do ${get}$file ; done
260
261       ln -sf alb_bg_modisopt_2D_ESA_v2.nc alb_bg.nc
262
263       echo ATTENTION : ON UTILISE LES FICHIERS DE L ANNEE 2000
264       ${get}PFTmap_15PFT.v1_2000.nc PFTmap.nc
265       ${get}woodharvest_2000.nc woodharvest.nc
266
267       sed -e 's/^SECHIBA_restart_in.*./SECHIBA_restart_in=NONE/' \
268           -e 's/^STOMATE_RESTART_FILEIN.*./STOMATE_RESTART_FILEIN=NONE/' \
269           -i orchidee.def
270
271      if [ $veget = 7994 ] ; then
272         get="ln -s $LMDZ_Init/"
273         for file in ndep_nhx.nc ndep_noy.nc nfert_cropland.nc nfert_pasture.nc nmanure_cropland.nc nmanure_pasture.nc bnf.nc ; do ${get}$file ; done
274      fi
275
276    fi
277
278fi
279
280
281echo '#################################################################'
282echo    'Repertoire contenant les fichiers de reanalyses'
283echo '#################################################################'
284
285if [ "$ok_guide" = "y" ] ; then
286   \rm -f u.nc v.nc T.nc hur.nc
287   if [ -f u.nc ] ; then
288      echo PROBLEME D EFFACEMENT DES FICHIERS DE REANALYSES
289      exit
290   fi
291   for var in u v T hur ; do $GET $ERADIR/$year/$month/$var.nc $var.nc ; done
292   echo Fin du rapatriement des fichiers de guidage
293fi
294
295echo '##################################################################'
296echo    'liste des fichiers avant le lancement de la simulation'
297echo '##################################################################'
298ls -lrt
299#diff DEF ./
300
301echo '##################################################################'
302echo    'Lancement de la simulation'
303echo '##################################################################'
304
305time $run $ntasks ./gcm.e > listing
306if [ ! -f restartphy.nc ] ; then
307echo PROBLEME PAS DE FICHIER RESTARTPHY
308exit
309fi
310
311echo '##################################################################'
312echo     'sauvegarde des fichiers de sortie'
313echo '##################################################################'
314
315# listing
316${PUT} listing ${SIMUDIR}/list$ym
317# if the listing for Orchidee is also needed, then uncomment the following line :
318#if [ $VEGET = y ] ; then ${PUT} out_orchidee_0000.0000 ${SIMUDIR}/out_orchidee$ym ; fi
319
320# restart(s)
321${PUT} restart.nc ${SIMUDIR}/start.$next.nc
322${PUT} restartphy.nc ${SIMUDIR}/startphy.$next.nc
323if [ $VEGET = y ] ; then for t in sechiba stomate ; do
324    f=${t}_rest_out.nc ; if [ -f $f ] ; then ${PUT} $f ${SIMUDIR}/start_$t.$next.nc ; fi ; done 
325    f=routing_restart.nc ; if [ -f $f ] ; then ${PUT} $f ${SIMUDIR}/start_routing.$next.nc ; fi
326fi
327
328# fichiers "histoires"
329# Si on tourne avec xios (et type="one_file") au lieu de ioipsl, on n'a pas besoin de rebuild, on doit juste copier les fichiers
330liste_out="histmth histday histhf histmthCOSP Xhistins XhistLES sechiba_history sechiba_history_4dim sechiba_out_2 stomate_history stomate_ipcc_history diag_routing dynzon"
331xios_used=0
332
333for fileout in $liste_out ; do
334  if [ -f  $fileout.nc ] ; then 
335     ${PUT} $fileout.nc ${SIMUDIR}/$fileout.$ym.nc
336     xios_used=1
337  fi
338done
339
340if [ $xios_used = 0 ] ; then
341  $GET $SIMUDIR/reb.sh
342  chmod +x reb.sh
343  ./reb.sh $ym $SIMUDIR $liste_out
344fi
345
346if [ -f guide_ins.nc ] ; then ${PUT} guide_ins.nc ${SIMUDIR}/guide_ins.$ym.nc ; fi
347
348echo '##################################################################'
349echo     'preparation et lancement de la simulation suivante'
350echo '##################################################################'
351
352# Gestion du fichier etat de controle de la simulation
353echo $ym OK >> etat
354echo $next a faire >> etat
355# ${PUT} etat $SIMUDIR/etat # Pas necessaire car etat est un lien vers $SIMUDIR/etat
356
357# set initialisation_iso to 0 for next run to read isotopes from restart files
358if [ $isotopes = y ] ; then
359   sed -i 's/^initialisation_iso=.*.$/initialisation_iso=0/' $SIMUDIR/DEF/iso.def
360fi
361set +e ; \rm out* sec* sta* list* rest* gcm.e aer* ; set -e
362
363# Arret si on est arrive au bout
364if [ $next =  $stopsim ] ; then
365   echo 'On arrive au bout, simulation next:'$next', stopsim:'$stopsim
366   # Cas particulier ou on veut chainer plusieurs simulations multi annuelles.
367   # pour le tuning automatique.
368   # Ici on passe de SCM_1-019 a SCM_1-029
369   if [ "${simul:0:3}" = "SCM" ] ; then
370      pre="SCM_1-"
371      num=`echo $simul | sed -e 's/'$pre'//'`
372      # (( num = $num + 10 )) change a cause d un probleme avec 008
373      num=`echo $num | awk ' { print $1 + 10 } '`
374      num=`printf "%03d\n" $num`
375      simul_new=$pre$num
376      cd $SCRIPTDIR
377      if [ $num -le 250 ] ; then
378         sed -e 's/^simul=.*.$/simul='$simul_new'/' -e 's/^\# @ job_nam.*.=.*.$/\# @ job_name = '$simul_new'/' tmp_$simul >| tmp_$simul_new
379         sbatch tmp_$simul_new
380      fi
381   fi
382   exit
383fi
384
385
386echo '##################################################################'
387echo      'lancement de la simulation suivante tmp_'$simul' depuis :'
388echo '##################################################################'
389pwd
390
391
392cd $SCRIPTDIR
393sbatch tmp_$simul
Note: See TracBrowser for help on using the repository browser.