From 6fe8a341c3205ea21f170b33d21070ce138916f0 Mon Sep 17 00:00:00 2001 From: Jorn Bruggeman Date: Wed, 3 Jul 2024 18:05:41 +0200 Subject: [PATCH] pyfabm: fix output_name for coupled diagnostics (#77) --- src/c/variable.F90 | 14 -------------- src/pyfabm/__init__.py | 23 ++++------------------- 2 files changed, 4 insertions(+), 33 deletions(-) diff --git a/src/c/variable.F90 b/src/c/variable.F90 index fff745a4..750e70be 100644 --- a/src/c/variable.F90 +++ b/src/c/variable.F90 @@ -28,20 +28,6 @@ subroutine variable_get_metadata(pvariable, length, name, units, long_name) bind call copy_to_c_string(variable%long_name, long_name) end subroutine variable_get_metadata - subroutine variable_get_output_name(pvariable, length, name) bind(c) - !DIR$ ATTRIBUTES DLLEXPORT :: variable_get_output_name - type (c_ptr), intent(in), value :: pvariable - integer(c_int), intent(in), value :: length - character(kind=c_char), intent(out), dimension(length) :: name - - type (type_internal_variable), pointer :: variable - character(len=attribute_length) :: name_ - - call c_f_pointer(pvariable, variable) - name_ = get_safe_name(variable%name) - call copy_to_c_string(name_, name) - end subroutine variable_get_output_name - subroutine variable_get_long_path(pvariable, length, long_name) bind(c) !DIR$ ATTRIBUTES DLLEXPORT :: variable_get_long_path type (c_ptr), intent(in), value :: pvariable diff --git a/src/pyfabm/__init__.py b/src/pyfabm/__init__.py index b0ed040b..36522218 100644 --- a/src/pyfabm/__init__.py +++ b/src/pyfabm/__init__.py @@ -247,12 +247,6 @@ def get_lib(name: str) -> ctypes.CDLL: ctypes.c_char_p, ] lib.variable_get_long_path.restype = None - lib.variable_get_output_name.argtypes = [ - ctypes.c_void_p, - ctypes.c_int, - ctypes.c_char_p, - ] - lib.variable_get_output_name.restype = None lib.variable_get_suitable_masters.argtypes = [ctypes.c_void_p, ctypes.c_void_p] lib.variable_get_suitable_masters.restype = ctypes.c_void_p lib.variable_get_output.argtypes = [ctypes.c_void_p] @@ -628,13 +622,7 @@ def long_path(self) -> str: @property def output_name(self) -> str: - if self.variable_pointer is None: - return self.name - stroutput_name = ctypes.create_string_buffer(ATTRIBUTE_LENGTH) - self.model.fabm.variable_get_output_name( - self.variable_pointer, ATTRIBUTE_LENGTH, stroutput_name - ) - return stroutput_name.value.decode("ascii") + return re.sub("\W", "_", self.name) @property def missing_value(self): @@ -736,13 +724,12 @@ def __init__( name: str, units: str, long_name: str, - path: str, variable_pointer: ctypes.c_void_p, index: int, horizontal: bool, ): Variable.__init__( - self, model, name, units, long_name, path, variable_pointer=variable_pointer + self, model, name, units, long_name, variable_pointer=variable_pointer ) self.data = None self.horizontal = horizontal @@ -1308,10 +1295,9 @@ def updateConfiguration(self, settings=None): self.interior_diagnostic_variables._data.append( DiagnosticVariable( self, - strname.value.decode("ascii"), + strpath.value.decode("ascii"), strunits.value.decode("ascii"), strlong_name.value.decode("ascii"), - strpath.value.decode("ascii"), ptr, i + 1, False, @@ -1334,10 +1320,9 @@ def updateConfiguration(self, settings=None): self.horizontal_diagnostic_variables._data.append( DiagnosticVariable( self, - strname.value.decode("ascii"), + strpath.value.decode("ascii"), strunits.value.decode("ascii"), strlong_name.value.decode("ascii"), - strpath.value.decode("ascii"), ptr, i + 1, True,