Skip to content

Commit 2aae7bf

Browse files
authored
Merge pull request #43 from NCAR/feature_41_iofields_filename
2 parents 16301e4 + fd471c2 commit 2aae7bf

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

run_wrf.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,34 @@ def main(cycle_dt_beg, sim_hrs, wrf_dir, run_dir, tmp_dir, icbc_model, exp_name,
198198
return success
199199
sys.exit(1)
200200

201+
# If the WRF namelist has a line "iofields_filename", look for the name(s) of that file(s)
202+
# If that file(s) exists in the templates directory, then copy it/them over to the WRF run directory
203+
is_iofields = False
204+
with open('namelist.input') as nml:
205+
for line in nml:
206+
if line.strip()[0:17] == 'iofields_filename':
207+
# If the user didn't add an ending comma, that might be a problem...
208+
iofields_fnames = line.split('=')[1].strip().split(',')
209+
is_iofields = True
210+
break
211+
if is_iofields:
212+
# How many file names were listed?
213+
n_io_files = len(iofields_fnames)
214+
# Loop over the file(s)
215+
for ff in range(n_io_files):
216+
# Strip any spaces and get rid of any quotes around the file name that are the first/last character
217+
io_fname = iofields_fnames[ff].strip()[1:-1]
218+
# If this is blank or a newline, then we're at the end of the list.
219+
if io_fname == '' or io_fname == '\n':
220+
break
221+
io_file = tmp_dir.joinpath(io_fname)
222+
if io_file.is_file():
223+
ret, output = exec_command(['cp', io_file, '.'], log, False, False)
224+
else:
225+
log.warning(f'WARNING: WRF namelist expects to find {io_fname} to control WRF variable I/O.')
226+
log.warning(f' That file was not found in {tmp_dir},')
227+
log.warning(' so cannot be copied to the run directory.')
228+
201229
## Clean up any rsl.out, rsl.error, and wrf log files
202230
files = glob.glob('rsl.*')
203231
for file in files:

0 commit comments

Comments
 (0)