Skip to content

Commit

Permalink
Wrap GMT_Read_Data
Browse files Browse the repository at this point in the history
  • Loading branch information
seisman committed Jul 8, 2024
1 parent 41a0fe0 commit fab4ee6
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions pygmt/clib/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -1068,6 +1068,49 @@ def put_matrix(self, dataset, matrix, pad=0):
if status != 0:
raise GMTCLibError(f"Failed to put matrix of type {matrix.dtype}.")

def read_data(self, family: str, method, geometry, mode, wesn, input, data):
"""
Read a data file into a GMT data container.
Wraps ``GMT_Read_Data`` but only allows reading from a file.
Parameters
----------
family
A valid GMT data family name (e.g., ``'GMT_IS_DATASET'``). See the
``FAMILIES`` attribute for valid names.
"""
c_read_data = self.get_libgmt_func(

Check warning on line 1084 in pygmt/clib/session.py

View check run for this annotation

Codecov / codecov/patch

pygmt/clib/session.py#L1084

Added line #L1084 was not covered by tests
"GMT_Read_Data",
argtypes=[
ctp.c_void_p,
ctp.c_uint,
ctp.c_uint,
ctp.c_uint,
ctp.c_uint,
ctp.POINTER(ctp.c_double),
ctp.c_char_p,
ctp.c_void_p,
],
restype=ctp.c_void_p,
)
family_int = self._parse_constant(family, valid=FAMILIES, valid_modifiers=VIAS)
geometry_int = self._parse_constant(geometry, valid=GEOMETRIES)

Check warning on line 1099 in pygmt/clib/session.py

View check run for this annotation

Codecov / codecov/patch

pygmt/clib/session.py#L1098-L1099

Added lines #L1098 - L1099 were not covered by tests

pointer = c_read_data(

Check warning on line 1101 in pygmt/clib/session.py

View check run for this annotation

Codecov / codecov/patch

pygmt/clib/session.py#L1101

Added line #L1101 was not covered by tests
self.session_pointer,
family_int,
self["GMT_IS_FILE"],
geometry_int,
self[mode],
None,
# sequence_to_ctypes_array(wesn, ctp.c_double, 6),
input.encode(),
data,
)
return pointer

Check warning on line 1112 in pygmt/clib/session.py

View check run for this annotation

Codecov / codecov/patch

pygmt/clib/session.py#L1112

Added line #L1112 was not covered by tests

def write_data(self, family, geometry, mode, wesn, output, data):
"""
Write a GMT data container to a file.
Expand Down

0 comments on commit fab4ee6

Please sign in to comment.