Skip to content

Commit

Permalink
pyfabm: fix output_name for coupled diagnostics (#77)
Browse files Browse the repository at this point in the history
  • Loading branch information
jornbr authored Jul 3, 2024
1 parent 1e94bf9 commit 6fe8a34
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 33 deletions.
14 changes: 0 additions & 14 deletions src/c/variable.F90
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 4 additions & 19 deletions src/pyfabm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down

0 comments on commit 6fe8a34

Please sign in to comment.