source: BOL/LMDZ_Setup/script_SIMU @ 4990

Last change on this file since 4990 was 4990, checked in by asima, 3 weeks ago

Cleaning a few lines in script_SIMU

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