Skip to content

Commit 23fddf2

Browse files
committed
implement parser for conf/ini files
1 parent c9f6dbc commit 23fddf2

File tree

6 files changed

+212
-95
lines changed

6 files changed

+212
-95
lines changed

ctl/control_tsmp2.sh

Lines changed: 18 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -8,80 +8,41 @@
88
set -aeo pipefail
99

1010
###########################################
11+
12+
echo "#####"
13+
echo "## Start TSMP WFE"
14+
echo "#####"
15+
16+
# set control directory
17+
ctl_dir=$(dirname $(realpath ${BASH_SOURCE:-$0}))
18+
19+
# Import function
20+
source ${ctl_dir}/utils_tsmp2.sh
21+
1122
###
12-
# Settings
23+
# Master-settings
1324
###
1425

15-
# main settings
16-
MODEL_ID=ICON-eCLM-ParFlow #ParFlow #ICON-eCLM #ICON-eCLM-ParFlow #ICON
17-
EXP_ID="eur-11u"
18-
CASE_ID="" # identifier for cases
26+
# load master conf
27+
parse_config_file "master.conf"
1928

20-
# main switches (PREprocessing, SIMulations, POSt-processing, VISualisation)
21-
lpre=( false false false ) # config, run, cleanup
22-
lsim=( true true true ) # config, run, cleanup
23-
lpos=( false false false ) # config, run, cleanup
24-
lvis=( false false false ) # config, run, cleanup
29+
# config file
30+
conf_file=${conf_file:-${ctl_dir}/expid.conf}
2531

26-
# time information
27-
cpltsp_atmsfc=900 # coupling time step, atm-sfc, eCLM timestep [sec]
28-
cpltsp_sfcss=900 # coupling time step, sfc-ss, ParFlow timestep [sec]
29-
simlength="1 day" #"23 hours"
30-
startdate="2017-07-01T00:00Z" # ISO norm 8601
31-
numsimstep=1 # number of simulation steps, simulation period = numsimstep * simlength
32-
33-
# restart
34-
lrestart=false
35-
36-
# mail notification for slurm jobs
37-
mailtype=NONE # NONE, BEGIN, END, FAIL, REQUEUE, ALL
38-
mailaddress=""
39-
40-
# user setting, leave empty for jsc machine defaults
41-
prevjobid="" # previous job-id, default leave empty
42-
npnode="" # number of cores per node
43-
partition="" # compute partition
44-
account="" # SET compute account. $BUDGET_ACCOUNTS / slts is used, if not set.
45-
46-
# wallclock
47-
pre_wallclock=00:35:00
48-
sim_wallclock=00:25:00 # needs to be format hh:mm:ss
49-
pos_wallclock=00:05:00
50-
vis_wallclock=00:05:00
51-
52-
# file/directory pathes
53-
tsmp2_dir=$TSMP2_DIR
54-
tsmp2_install_dir="" # leave empty to use default
55-
tsmp2_env="" # leave empty to use default
56-
57-
# number of nodes per component (<comp>_node will be set to zero, if not indicated in MODEL_ID)
58-
ico_node=3
59-
clm_node=1
60-
pfl_node=2
61-
62-
# DebugMode: No job submission. Just config
63-
debugmode=false
64-
65-
# log job status
66-
joblog=true
32+
echo "Conf_file: ${conf_file}"
6733

6834
###########################################
6935

7036
###
7137
# Start of script
7238
###
7339

74-
echo "#####"
75-
echo "## Start TSMP WFE"
76-
echo "#####"
77-
7840
# set modelid, caseid and expid
7941
modelid=$(echo ${MODEL_ID//"-"/} | tr '[:upper:]' '[:lower:]')
8042
if [ -n "${CASE_ID}" ]; then caseid+=${CASE_ID,,}"_"; fi
8143
expid=${EXP_ID,,}
8244

8345
# set path (not run-dir)
84-
ctl_dir=$(dirname $(realpath ${BASH_SOURCE:-$0}))
8546
nml_dir=$(realpath ${ctl_dir}/../nml/)
8647
geo_dir=$(realpath ${ctl_dir}/../dta/geo/)
8748
frc_dir=$(realpath ${ctl_dir}/../dta/forcing/)
@@ -92,9 +53,6 @@ echo "ctl_dir: "${ctl_dir}
9253
echo "nml_dir: "${nml_dir}
9354
echo "geo_dir: "${geo_dir}
9455

95-
# Import function
96-
source ${ctl_dir}/utils_tsmp2.sh
97-
9856
# select machine defaults, if not set by user
9957
if [ "${SYSTEMNAME}" == "juwels" ]; then
10058
check_var_def npnode 48 "Taking user setting for npnode "
@@ -111,7 +69,7 @@ account_def=${BUDGET_ACCOUNTS:-slts}
11169
check_var_def account ${account_def} "WARNING: No account is set. Using account="
11270
check_var_def tsmp2_dir $(realpath ${ctl_dir}/../src/TSMP2) "Taking TSMP2 default dir at "
11371
check_var_def tsmp2_install_dir ${tsmp2_dir}/bin/${SYSTEMNAME^^}_${MODEL_ID} \
114-
"Taking TSMP2 component binaries from default dir at"
72+
"Taking TSMP2 component binaries from default dir at "
11573
check_var_def tsmp2_env $(find ${tsmp2_install_dir}/ -type f -name "*mpi") "Using environment file "
11674

11775
# generic sbatch string

ctl/expid.conf

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#####
2+
## exp-id conf
3+
#####
4+
5+
###
6+
# PRE
7+
###
8+
9+
[pre_config_clm]
10+
11+
###
12+
# SIM
13+
###
14+
[sim_config_general]
15+
16+
[sim_config_icon]
17+
fname_dwdFG=dwdFG_R13B05_DOM01.nc
18+
fname_icondomain=europe011_DOM01.nc
19+
fname_iconextpar=external_parameter_icon_europe011_DOM01_tiles.nc
20+
fname_iconghgforc=bc_greenhouse_rcp45_1765-2500.nc
21+
22+
[sim_config_clm]
23+
domainfile_clm=domain.lnd.ICON-11_ICON-11.230302_landlake_halo.nc
24+
surffile_clm=surfdata_ICON-11_hist_16pfts_Irrig_CMIP6_simyr2000_c230302_gcvurb-pfsoil_halo.nc
25+
clmoutvar='TWS','H2OSOI','TSOI','TG','EFLX_LH_TOT','FSH','FSA','FSR','FIRA','Rnet','EFLX_SOIL_GRND'
26+
27+
[sim_config_parflow]
28+
pfl_ngx=444
29+
pfl_ngy=432
30+
pfl_mask=PfbMask4SolidFile_eCLM.pfsol
31+
32+
[sim_config_oas]
33+
icon_ncg=189976
34+
clm_ngx=189976
35+
clm_ngy=1
36+
37+
###
38+
# POS
39+
###
40+
41+
42+
###
43+
# VIS
44+
###

ctl/master.conf

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
######
2+
## Master config file for general settings
3+
######
4+
5+
# main settings
6+
MODEL_ID=ICON-eCLM-ParFlow #ParFlow #ICON-eCLM #ICON-eCLM-ParFlow #ICON
7+
EXP_ID="eur-11u"
8+
CASE_ID="" # identifier for cases
9+
conf_file="" # configure file for cases, also possible ${EXP_ID}.conf
10+
11+
# main switches (PREprocessing, SIMulations, POSt-processing, VISualisation)
12+
lpre=( false false false ) # config, run, cleanup
13+
lsim=( true true true ) # config, run, cleanup
14+
lpos=( false false false ) # config, run, cleanup
15+
lvis=( false false false ) # config, run, cleanup
16+
17+
# time information
18+
cpltsp_atmsfc=900 # coupling time step, atm-sfc, eCLM timestep [sec]
19+
cpltsp_sfcss=900 # coupling time step, sfc-ss, ParFlow timestep [sec]
20+
simlength="1 day" #"23 hours"
21+
startdate="2017-07-01T00:00Z" # ISO norm 8601
22+
numsimstep=1 # number of simulation steps, simulation period = numsimstep * simlength
23+
24+
# restart
25+
lrestart=false
26+
27+
# mail notification for slurm jobs
28+
mailtype=NONE # NONE, BEGIN, END, FAIL, REQUEUE, ALL
29+
mailaddress=""
30+
31+
# user setting, leave empty for jsc machine defaults
32+
prevjobid="" # previous job-id, default leave empty
33+
npnode="" # number of cores per node
34+
partition="" # compute partition
35+
account="" # SET compute account. $BUDGET_ACCOUNTS / slts is used, if not set.
36+
37+
# wallclock
38+
pre_wallclock=00:35:00
39+
sim_wallclock=00:25:00 # needs to be format hh:mm:ss
40+
pos_wallclock=00:05:00
41+
vis_wallclock=00:05:00
42+
43+
# file/directory pathes
44+
tsmp2_dir=$TSMP2_DIR
45+
tsmp2_install_dir="" # leave empty to use default
46+
tsmp2_env="" # leave empty to use default
47+
48+
# number of nodes per component (<comp>_node will be set to zero, if not indicated in MODEL_ID)
49+
ico_node=3
50+
clm_node=1
51+
pfl_node=2
52+
53+
# DebugMode: No job submission. Just config
54+
debugmode=false
55+
56+
# log job status
57+
joblog=true

ctl/pre_ctl/pre_config.sh

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,12 @@ if [[ "${modelid}" == *clm* ]]; then
2727

2828
echo "start create clm forcing"
2929

30+
parse_config_file ${conf_file} "pre_config_clm"
31+
3032
# directories
31-
lsmforcgensrc_dir=${ctl_dir}/../src/eCLM_atmforcing/mkforcing
32-
eclmfrc_dir=${frc_dir}/eclm/forcing/
33-
cdsapi_dtadir=${ctl_dir}/../src/eCLM_atmforcing/mkforcing/cdsapidwn
33+
lsmforcgensrc_dir=${lsmforcgensrc_dir:-${ctl_dir}/../src/eCLM_atmforcing/mkforcing}
34+
eclmfrc_dir=${eclmfrc_dir:-${frc_dir}/eclm/forcing/}
35+
cdsapi_dtadir=${cdsapi_dtadir:-${ctl_dir}/../src/eCLM_atmforcing/mkforcing/cdsapidwn}
3436

3537
# check if forcing files already exists
3638
unset listfrcfile

ctl/sim_ctl/sim_config.sh

Lines changed: 41 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,18 @@ sed -i "s/__pfl_pe__/$(($ico_proc+$clm_proc+$pfl_proc-1))/" ${sim_dir}/slm_multi
4242
# change to run directory
4343
cd ${sim_dir}
4444

45-
simrstm1_dir=${rst_dir}/${caseid}$(date -u -d "${datem1}" +%Y%m%d)
45+
parse_config_file ${conf_file} "sim_config_general"
46+
47+
simrstm1_dir=${simrstm1_dir:-${rst_dir}/${caseid}$(date -u -d "${datem1}" +%Y%m%d)}
4648

4749
####################
4850
# ICON
4951
####################
5052
if [[ "${modelid}" == *icon* ]]; then
5153

52-
icon_latbc_dir=${frc_dir}/icon/latbc/$(date -u -d "${startdate}" +%Y%m)
54+
parse_config_file ${conf_file} "sim_config_icon"
55+
56+
icon_latbc_dir=${icon_latbc_dir:-${frc_dir}/icon/latbc/$(date -u -d "${startdate}" +%Y%m)}
5357

5458
# link executeable (will be replaced with copy in production)
5559
# ln -sf $tsmp2_install_dir/bin/icon icon
@@ -76,11 +80,11 @@ if [[ "${modelid}" == *icon* ]]; then
7680
sed -i "s/\(lrestart =\).*/\1 $lrestart/" icon_master.namelist
7781

7882
# link needed files
79-
ln -sf ${icon_latbc_dir}/igaf$(date -u -d "${startdate}" +%Y%m%d%H).nc dwdFG_R13B05_DOM01.nc
80-
ln -sf ${geo_dir}/icon/static/europe011_DOM01.nc
81-
ln -sf ${geo_dir}/icon/static/external_parameter_icon_europe011_DOM01_tiles.nc
82-
ln -sf ${geo_dir}/icon/static/bc_greenhouse_rcp45_1765-2500.nc
83-
ln -sf ${geo_dir}/icon/static/ecraddata
83+
ln -sf ${icon_latbc_dir}/igaf$(date -u -d "${startdate}" +%Y%m%d%H).nc ${fname_dwdFG}
84+
ln -sf ${geo_dir}/icon/static/${fname_icondomain}
85+
ln -sf ${geo_dir}/icon/static/${fname_iconextpar}
86+
ln -sf ${geo_dir}/icon/static/${fname_iconghgforc}
87+
ln -sf ${geo_dir}/icon/static/${ecraddata:-ecraddata}
8488

8589
fi # if modelid == ICON
8690

@@ -89,16 +93,20 @@ fi # if modelid == ICON
8993
####################
9094
if [[ "${modelid}" == *clm* ]]; then
9195

92-
#
93-
geo_dir_clm=${geo_dir}/eclm/static
94-
clm_tsp=${cpltsp_atmsfc}
95-
clmoutfrq=-1 # in hr
96-
clmoutmfilt=24 # number of tsp in out
96+
parse_config_file ${conf_file} "sim_config_clm"
97+
98+
# set defaults
99+
geo_dir_clm=${geo_dir_clm:-${geo_dir}/eclm/static}
100+
clm_tsp=${clm_tsp:-${cpltsp_atmsfc}}
101+
clmoutfrq=${clmoutfrq:--1} # in hr
102+
clmoutmfilt=${clmoutmfilt:-24} # number of tsp in out
103+
clmoutvar=${clmoutvar:-'TG'}
97104
#
98-
domainfile_clm=domain.lnd.ICON-11_ICON-11.230302_landlake_halo.nc
99-
surffile_clm=surfdata_ICON-11_hist_16pfts_Irrig_CMIP6_simyr2000_c230302_gcvurb-pfsoil_halo.nc
105+
# domainfile_clm=domain.lnd.ICON-11_ICON-11.230302_landlake_halo.nc
106+
# surffile_clm=surfdata_ICON-11_hist_16pfts_Irrig_CMIP6_simyr2000_c230302_gcvurb-pfsoil_halo.nc
100107
# fini_clm=${rst_dir}/$(date -u -d "${datem1}" +%Y%m%d)/eclm/eCLM_eur-11u.clm2.r.$(date -u -d "${startdate}" +%Y-%m-%d)-00000.nc
101-
fini_clm=${simrstm1_dir}/eclm/eCLM_eur-11u.clm2.r.$(date -u -d "${startdate}" +%Y-%m-%d)-$(printf "%05d" $(( $(date -d "${startdate}" +%s) % 86400 ))).nc
108+
# fini_clm=${simrstm1_dir}/eclm/eCLM_eur-11u.clm2.r.$(date -u -d "${startdate}" +%Y-%m-%d)-$(printf "%05d" $(( $(date -d "${startdate}" +%s) % 86400 ))).nc
109+
fini_clm=${fini_clm:-${simrstm1_dir}/eclm/eCLM_eur-11u.clm2.r.$(date -u -d "${startdate}" +%Y-%m-%d)-$(printf "%05d" $(( $(date -d "${startdate}" +%s) % 86400 ))).nc}
102110

103111

104112
# link executeable
@@ -144,12 +152,10 @@ if [[ "${modelid}" == *clm* ]]; then
144152
sed -i "s#__surffile_clm__#$surffile_clm#" lnd_in
145153
if [[ "${modelid}" != *parflow* ]]; then
146154
sed -i "s/__swmm__/1/" lnd_in # soilwater_movement_method
147-
sed -i "s/__clmoutvar__/'TWS','H2OSOI','TSOI','TG','EFLX_LH_TOT','FSH','FSA','FSR','FIRA','Rnet','EFLX_SOIL_GRND'/" lnd_in
155+
sed -i "s/__clmoutvar__/$clmoutvar/" lnd_in
148156
else
149157
sed -i "s/__swmm__/4/" lnd_in # soilwater_movement_method
150-
sed -i "s/__clmoutvar__/'TWS','H2OSOI','TSOI','TG','EFLX_LH_TOT','FSH','FSA','FSR','FIRA','Rnet','EFLX_SOIL_GRND'/" lnd_in
151-
# sed -i "s/__clmoutvar__/'TWS','H2OSOI','QFLX_EVAP_TOT','TG','TSOI','FSH','FSR'/" lnd_in
152-
# sed -i "s/__clmoutvar__/'PFL_PSI', 'PFL_PSI_GRC', 'PFL_SOILLIQ', 'PFL_SOILLIQ_GRC', 'RAIN', 'SNOW', 'SOILPSI', 'SMP', 'QPARFLOW', 'FH2OSFC', 'FH2OSFC_NOSNOW', 'FRAC_ICEOLD', 'FSAT', 'H2OCAN', 'H2OSFC', 'H2OSNO', 'H2OSNO_ICE', 'H2OSOI', 'LIQCAN', 'LIQUID_WATER_TEMP1', 'OFFSET_SWI', 'ONSET_SWI', 'QH2OSFC', 'QH2OSFC_TO_ICE', 'QROOTSINK', 'QTOPSOIL', 'SNOLIQFL', 'SNOWLIQ', 'SNOWLIQ_ICE', 'SNOW_SINKS', 'SNOW_SOURCES', 'SNO_BW', 'SNO_BW_ICE', 'SNO_LIQH2O', 'SOILLIQ', 'SOILPSI', 'SOILWATER_10CM', 'TH2OSFC', 'TOTSOILLIQ', 'TWS', 'VEGWP', 'VOLR', 'VOLRMCH', 'WF', 'ZWT', 'ZWT_CH4_UNSAT', 'ZWT_PERCH', 'watfc', 'watsat', 'QINFL', 'Qstor', 'QOVER', 'QRUNOFF', 'EFF_POROSITY', 'TSOI', 'TSKIN', 'QDRAI'/" lnd_in
158+
sed -i "s/__clmoutvar__/$clmoutvar/" lnd_in
153159
fi
154160
sed -i "s#__geo_dir_clm__#$geo_dir_clm#" datm_in
155161
sed -i "s/__simystart__/$(date -u -d "${startdate}" +%Y)/g" datm_in
@@ -170,18 +176,19 @@ fi # if modelid == CLM
170176
####################
171177
if [[ "${modelid}" == *parflow* ]]; then
172178

179+
parse_config_file ${conf_file} "sim_config_parflow"
173180
#
174-
fini_pfl=${simrstm1_dir}/parflow/${EXP_ID}.out.${dateshort}.nc
181+
fini_pfl=${fini_pfl:-${simrstm1_dir}/parflow/${EXP_ID}.out.${dateshort}.nc}
175182

176183
# link executeable
177184
# ln -sf $tsmp2_install_dir/bin/parflow parflow
178185
cp $tsmp2_install_dir/bin/parflow parflow
179186

180-
#
181-
parflow_tsp=$(echo "$cpltsp_sfcss / 3600" | bc -l)
182-
parflow_base=0.0025
187+
# set defaults
188+
parflow_tsp=${parflow_tsp:-$(echo "$cpltsp_sfcss / 3600" | bc -l)}
189+
parflow_base=${parflow_base:-0.0025}
183190
# parflow_inifile=${frc_dir}/parflow/ini/ic_press.pfb
184-
pfloutfrq=1.0
191+
pfloutfrq=${pfloutfrq:-1.0}
185192

186193
# copy namelist
187194
cp ${nml_dir}/parflow/ascii2pfb_slopes.tcl ascii2pfb_slopes.tcl
@@ -191,7 +198,7 @@ if [[ "${modelid}" == *parflow* ]]; then
191198

192199
# copy sa and pfsol files
193200
cp ${geo_dir}/parflow/static/*sa .
194-
cp ${geo_dir}/parflow/static/PfbMask4SolidFile_eCLM.pfsol PfbMask4SolidFile_eCLM.pfsol
201+
cp ${geo_dir}/parflow/static/${pfl_mask} ${pfl_mask}
195202

196203
# PFL NML
197204
sed -i "s/__nprocx_pfl_bldsva__/$pfl_procX/" ascii2pfb_slopes.tcl
@@ -200,8 +207,8 @@ if [[ "${modelid}" == *parflow* ]]; then
200207
sed -i "s/__nprocy_pfl_bldsva__/$pfl_procY/" ascii2pfb_SoilInd.tcl
201208
sed -i "s/__nprocx_pfl_bldsva__/$pfl_procX/" coup_oas.tcl
202209
sed -i "s/__nprocy_pfl_bldsva__/$pfl_procY/" coup_oas.tcl
203-
sed -i "s/__ngpflx_bldsva__/444/" coup_oas.tcl
204-
sed -i "s/__ngpfly_bldsva__/432/" coup_oas.tcl
210+
sed -i "s/__ngpflx_bldsva__/$pfl_ngx/" coup_oas.tcl
211+
sed -i "s/__ngpfly_bldsva__/$pfl_ngy/" coup_oas.tcl
205212
sed -i "s/__base_pfl__/$parflow_base/" coup_oas.tcl
206213
sed -i "s/__start_cnt_pfl__/0/" coup_oas.tcl
207214
sed -i "s/__stop_pfl_bldsva__/$(echo "${simlenhr} + ${parflow_base}" | bc -l)/" coup_oas.tcl
@@ -225,6 +232,8 @@ fi # if modelid == parflow
225232

226233
if [[ "${run_oasis}" == true ]]; then
227234

235+
parse_config_file ${conf_file} "sim_config_oas"
236+
228237
# copy namelist
229238
cp ${nml_dir}/oasis/namcouple_${modelid} namcouple
230239

@@ -233,11 +242,11 @@ if [[ "${run_oasis}" == true ]]; then
233242
sed -i "s/__cpltsp_as__/$cpltsp_atmsfc/" namcouple
234243
sed -i "s/__cpltsp_ss__/$cpltsp_sfcss/" namcouple
235244
sed -i "s/__simlen__/$(( $simlensec + $cpltsp_atmsfc ))/" namcouple
236-
sed -i "s/__icongp__/189976/" namcouple
237-
sed -i "s/__eclmgpx__/189976/" namcouple
238-
sed -i "s/__eclmgpy__/1/" namcouple
239-
sed -i "s/__parflowgpx__/444/" namcouple
240-
sed -i "s/__parflowgpy__/432/" namcouple
245+
sed -i "s/__icongp__/$icon_ncg/" namcouple
246+
sed -i "s/__eclmgpx__/$clm_ngx/" namcouple
247+
sed -i "s/__eclmgpy__/$clm_ngy/" namcouple
248+
sed -i "s/__parflowgpx__/$pfl_ngx/" namcouple
249+
sed -i "s/__parflowgpy__/$pfl_ngy/" namcouple
241250

242251
# copy remap-files
243252
cp ${geo_dir}/oasis/static/masks.nc .

0 commit comments

Comments
 (0)