From 6aa8a770a59f83a6b4f429863f57b481b8a6c0b0 Mon Sep 17 00:00:00 2001 From: James McCreight Date: Fri, 27 Jun 2025 12:58:49 -0600 Subject: [PATCH] draft control to not set missing variables to defaults --- pyPRMS/control/ControlFile.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/pyPRMS/control/ControlFile.py b/pyPRMS/control/ControlFile.py index 0ff05cd..b7b9958 100644 --- a/pyPRMS/control/ControlFile.py +++ b/pyPRMS/control/ControlFile.py @@ -23,6 +23,7 @@ class ControlFile(Control): def __init__(self, filename: Union[str, Path], metadata, + missing_as_default: bool=True, verbose: Optional[bool] = False): super(ControlFile, self).__init__(metadata=metadata, verbose=verbose) @@ -31,6 +32,7 @@ def __init__(self, filename: Union[str, Path], self.__verbose = verbose self.__isloaded = False + self.__missing_as_default = missing_as_default if isinstance(filename, str): filename = Path(filename) @@ -61,6 +63,7 @@ def _read(self): Reads the contents of a control file into the class. """ + vars_in_file = [] if self.__verbose: chk_vars = [] @@ -79,6 +82,7 @@ def _read(self): # We're dealing with a control parameter/variable # We're in a parameter section varname = line.split(' ')[0] + vars_in_file += [varname] if self.__verbose: if varname in chk_vars: @@ -142,6 +146,12 @@ def _read(self): # Hit the end of the file continue + if not self.__missing_as_default: + ctl_vars = list(self.control_variables.keys()) + for vv in ctl_vars: + if vv not in vars_in_file: + self.remove(vv) + self.header = header_tmp self.__isloaded = True