Skip to content

Commit

Permalink
SAS plugin modifications to handle MFUEL output.
Browse files Browse the repository at this point in the history
  • Loading branch information
danieletimpano committed May 30, 2024
1 parent 9560bfc commit 97a01f9
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/watts/plugin_sas.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ class PluginSAS(PluginGeneric):
List of command-line arguments used to call the executable
conv_channel
Path to CHANNELtoCSV utility executable
conv_mfuel (Timpano - May 2024: modifications to work with MFUEL output)
Path to MFUELPeaktoCSV utility executable
conv_primar4
Path to PRIMAR4toCSV utility executable
Expand All @@ -118,6 +120,7 @@ def __init__(
# Set other executables based on the main SAS executable
suffix = executable.suffix
self._conv_channel = executable.with_name(f"CHANNELtoCSV{suffix}")
self._conv_mfuel = executable.with_name(f"MFUELtoCSV{suffix}") # Timpano - May 2024: modifications to work with MFUEL output
self._conv_primar4 = executable.with_name(f"PRIMAR4toCSV{suffix}")

@property
Expand All @@ -128,6 +131,10 @@ def conv_channel(self) -> Path:
def conv_primar4(self) -> Path:
return self._conv_primar4

@property
def conv_mfuel(self) -> Path: # Timpano - May 2024: modifications to work with MFUEL output
return self._conv_mfuel

@conv_channel.setter
def conv_channel(self, exe: PathLike):
if shutil.which(exe) is None:
Expand All @@ -140,6 +147,12 @@ def conv_primar4(self, exe: PathLike):
raise RuntimeError(f"PRIMAR4toCSV utility executable '{exe}' is missing.")
self._conv_primar4 = Path(exe)

@conv_mfuel.setter
def conv_mfuel(self, exe: PathLike): # Timpano - May 2024: modifications to work with MFUEL output
if shutil.which(exe) is None:
raise RuntimeError(f"MFUELtoCSV utility executable '{exe}' is missing.")
self._conv_mfuel = Path(exe)

@property
def execute_command(self):
return [str(self.executable), "-i", self.input_name, "-o", "out.txt"]
Expand All @@ -159,9 +172,10 @@ def postrun(self, params: Parameters, exec_info: ExecInfo) -> ResultsSAS:
SAS results object
"""

# Convert CHANNEl.dat and PRIMER4.dat to csv files
# Convert CHANNEl.dat and PRIMAR4.dat and MFUELss.dat to csv files
# using SAS utilities. Check if files exist because
# they may not be outputted per user's choice.

if Path("CHANNEL.dat").is_file():
with open("CHANNEL.dat", "r") as file_in, open("CHANNEL.csv", "w") as file_out:
subprocess.run(str(self.conv_channel), stdin=file_in, stdout=file_out)
Expand All @@ -170,4 +184,8 @@ def postrun(self, params: Parameters, exec_info: ExecInfo) -> ResultsSAS:
with open("PRIMAR4.dat", "r") as file_in, open("PRIMAR4.csv", "w") as file_out:
subprocess.run(str(self.conv_primar4), stdin=file_in, stdout=file_out)

if Path("MFUELss_C000001.dat").is_file(): # Timpano - May 2024: modifications to work with MFUEL output
with open("MFUELss_C000001.dat", "r") as file_in:
subprocess.run(str(self.conv_mfuel), stdin=file_in)

return super().postrun(params, exec_info)

0 comments on commit 97a01f9

Please sign in to comment.