From fab4ee6d6072e39bcaf1c9b8e3af9ef79eb1b3bd Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Mon, 8 Jul 2024 13:30:14 +0800 Subject: [PATCH] Wrap GMT_Read_Data --- pygmt/clib/session.py | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/pygmt/clib/session.py b/pygmt/clib/session.py index b0aaff44ec3..77546c9560f 100644 --- a/pygmt/clib/session.py +++ b/pygmt/clib/session.py @@ -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( + "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) + + pointer = c_read_data( + 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 + def write_data(self, family, geometry, mode, wesn, output, data): """ Write a GMT data container to a file.