1818 -r, --rundir DIR Run directory containing the base namelists (default: .)
1919 -n, --num_ensemble INT Number of ensemble members (default: 96)
2020 -b, --backend BACKEND Namelist backend: 're' (default) or 'f90nml'
21+ -f, --forcings-dir DIR Forcings directory in stream files (default: ./forcings)
2122 --suffix-fsurdat Add ensemble suffix to clm_inparm:fsurdat in lnd_in
2223"""
2324import argparse
@@ -129,16 +130,16 @@ def adapt_lnd_in(iens, suffix_fsurdat=False, backend="re"):
129130 fh .write (content )
130131
131132
132- def adapt_stream_files (iens , backend = "re" ):
133+ def adapt_stream_files (iens , forcings_dir = "./forcings" , backend = "re" ):
133134 """Write per-ensemble XML stream description files.
134135
135136 Must be called after adapt_datm_in, which determines the ensemble
136137 stream filenames.
137138
138139 For each stream file listed in datm_in, reads the original XML and
139140 writes an ensemble-specific copy (named as in datm_in_NNNN), with
140- the fieldInfo/filePath entries under './forcings' redirected to
141- './forcings /real_NNNNN'.
141+ the fieldInfo/filePath entries under forcings_dir redirected to
142+ '<forcings_dir> /real_NNNNN'.
142143
143144 """
144145 # Must be called after datm update
@@ -167,9 +168,9 @@ def adapt_stream_files(iens, backend="re"):
167168 # Check parent
168169 if filePath .getparent ().tag == "fieldInfo" :
169170 # print(filePath.getparent().tag, filePath.tag)
170- if filePath .text .find ("./forcings" ) > - 1 :
171+ if filePath .text .find (forcings_dir ) > - 1 :
171172 filePath .text = filePath .text .replace (
172- "./forcings" , "./forcings /real_" + str (iens ).zfill (5 )
173+ forcings_dir , forcings_dir + " /real_" + str (iens ).zfill (5 )
173174 )
174175
175176 # Write XML streamfile
@@ -189,7 +190,7 @@ def adapt_stream_files(iens, backend="re"):
189190 f .write (fstr )
190191
191192
192- def create_ensemble_namelists (iens , suffix_fsurdat = False , backend = "re" ):
193+ def create_ensemble_namelists (iens , suffix_fsurdat = False , forcings_dir = "./forcings" , backend = "re" ):
193194 """Create all per-ensemble namelist files for ensemble member iens.
194195
195196 Calls:
@@ -210,7 +211,7 @@ def create_ensemble_namelists(iens, suffix_fsurdat=False, backend="re"):
210211
211212 adapt_mosart_in (iens , backend = backend )
212213
213- adapt_stream_files (iens , backend = backend )
214+ adapt_stream_files (iens , forcings_dir = forcings_dir , backend = backend )
214215
215216
216217if __name__ == "__main__" :
@@ -234,6 +235,11 @@ def create_ensemble_namelists(iens, suffix_fsurdat=False, backend="re"):
234235 default = "re" ,
235236 help = "Backend for reading/writing namelists: 're' (default, regexp) or 'f90nml'" ,
236237 )
238+ parser .add_argument (
239+ "-f" , "--forcings-dir" ,
240+ default = "./forcings" ,
241+ help = "Forcings directory used in stream file filePath entries (default: ./forcings)" ,
242+ )
237243 parser .add_argument (
238244 "--suffix-fsurdat" ,
239245 action = "store_true" ,
@@ -246,7 +252,8 @@ def create_ensemble_namelists(iens, suffix_fsurdat=False, backend="re"):
246252 os .chdir (args .rundir )
247253
248254 for ens in range (1 , args .num_ensemble + 1 ):
249- create_ensemble_namelists (ens , suffix_fsurdat = args .suffix_fsurdat , backend = args .backend )
255+ create_ensemble_namelists (ens , suffix_fsurdat = args .suffix_fsurdat ,
256+ forcings_dir = args .forcings_dir , backend = args .backend )
250257 sys .stdout .write ("\r [%s] " % ("Done with ensemble member: " + str (ens )))
251258 sys .stdout .flush ()
252259
0 commit comments