Skip to content

Commit

Permalink
Per #1289, added support for explicitly setting file list file path f…
Browse files Browse the repository at this point in the history
…or TCMRW wrapper -- updated logic to write a file list file since the tc_rmw tool now supports reading a ascii file containing a list of input files
  • Loading branch information
georgemccabe committed Jan 31, 2022
1 parent f9fdecb commit 7676c50
Showing 1 changed file with 35 additions and 29 deletions.
64 changes: 35 additions & 29 deletions metplus/wrappers/tcrmw_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,19 +65,22 @@ def create_c_dict(self):
c_dict['CONFIG_FILE'] = self.get_config_file('TCRMWConfig_wrapped')

c_dict['INPUT_DIR'] = self.config.getdir('TC_RMW_INPUT_DIR', '')
c_dict['INPUT_TEMPLATE'] = self.config.getraw('filename_templates',
c_dict['INPUT_TEMPLATE'] = self.config.getraw('config',
'TC_RMW_INPUT_TEMPLATE')
c_dict['INPUT_FILE_LIST'] = self.config.getraw(
'config', 'TC_RMW_INPUT_FILE_LIST'
)

c_dict['OUTPUT_DIR'] = self.config.getdir('TC_RMW_OUTPUT_DIR', '')
c_dict['OUTPUT_TEMPLATE'] = (
self.config.getraw('filename_templates',
self.config.getraw('config',
'TC_RMW_OUTPUT_TEMPLATE')
)

c_dict['DECK_INPUT_DIR'] = self.config.getdir('TC_RMW_DECK_INPUT_DIR',
'')
c_dict['DECK_INPUT_TEMPLATE'] = (
self.config.getraw('filename_templates',
self.config.getraw('config',
'TC_RMW_DECK_TEMPLATE')
)

Expand Down Expand Up @@ -291,46 +294,49 @@ def find_input_files(self, time_info):
@param time_info time dictionary to use for string substitution
@returns Input file list if all files were found, None if not.
"""

# tc_rmw currently doesn't support an ascii file that contains a list of input files
# setting this to False will list each file in the command, which can be difficult to read
# when the tool supports reading a file list file, we should use the logic when
# use_file_list = True
use_file_list = False

# get deck file
deck_file = self.find_data(time_info, data_type='DECK')
if not deck_file:
return None

self.c_dict['DECK_FILE'] = deck_file

all_input_files = []

lead_seq = util.get_lead_sequence(self.config, time_info)
for lead in lead_seq:
self.clear()
time_info['lead'] = lead

time_info = time_util.ti_calculate(time_info)
# get input files
if self.c_dict['INPUT_FILE_LIST']:
self.logger.debug("Explicit file list file: "
f"{self.c_dict['INPUT_FILE_LIST']}")
list_file = do_string_sub(self.c_dict['INPUT_FILE_LIST'],
**time_info)
if not os.path.exists(list_file):
self.log_error(f'Could not find file list: {list_file}')
return None
else:
all_input_files = []

# get a list of the input data files, write to an ascii file if there are more than one
input_files = self.find_data(time_info, return_list=True)
if not input_files:
continue
for lead in lead_seq:
self.clear()
time_info['lead'] = lead

all_input_files.extend(input_files)
time_info = time_util.ti_calculate(time_info)

if not all_input_files:
return None
# get a list of the input data files,
# write to an ascii file if there are more than one
input_files = self.find_data(time_info, return_list=True)
if not input_files:
continue

all_input_files.extend(input_files)

if not all_input_files:
return None

if use_file_list:
# create an ascii file with a list of the input files
list_file = self.write_list_file(f"{os.path.basename(adeck_file)}_data_files.txt",
all_input_files)
self.infiles.append(list_file)
else:
self.infiles.extend(all_input_files)
list_file = f"{os.path.basename(deck_file)}_data_files.txt"
list_file = self.write_list_file(list_file, all_input_files)

self.infiles.append(list_file)

# set LEAD_LIST to list of forecast leads used
if lead_seq != [0]:
Expand Down

0 comments on commit 7676c50

Please sign in to comment.