@@ -1625,18 +1625,23 @@ def virtualfile_from_data(
1625
1625
1626
1626
return file_context
1627
1627
1628
- def read_virtualfile (self , vfname ):
1628
+ def read_virtualfile (self , vfname , kind = None ):
1629
1629
"""
1630
- Read data from a virtual file.
1630
+ Read data from a virtual file and cast it into a GMT data container if requested .
1631
1631
1632
1632
Parameters
1633
1633
----------
1634
1634
vfname : str
1635
1635
Name of the virtual file to read.
1636
1636
1637
+ kind : str
1638
+ Cast the data into a GMT data container. Choose from "grid" or
1639
+ "dataset". If None, will return a ctypes void pointer.
1640
+
1637
1641
Returns
1638
1642
-------
1639
- Pointer to the data, which can be casted into GMT data types.
1643
+ Pointer to the GMT data container. If ``kind`` is None, returns a
1644
+ ctypes void pointer instead.
1640
1645
"""
1641
1646
c_read_virtualfile = self .get_libgmt_func (
1642
1647
"GMT_Read_VirtualFile" ,
@@ -1646,29 +1651,18 @@ def read_virtualfile(self, vfname):
1646
1651
],
1647
1652
restype = ctp .c_void_p ,
1648
1653
)
1649
- return c_read_virtualfile (self .session_pointer , vfname .encode ())
1650
-
1651
- def read_virtualfile_to_data (self , vfname , kind ):
1652
- """
1653
- Read a virtual file and convert to a GMT data container.
1654
+ pointer = c_read_virtualfile (self .session_pointer , vfname .encode ())
1655
+ if kind is None : # Return the ctypes void pointer
1656
+ return pointer
1654
1657
1655
- Parameters
1656
- ----------
1657
- vfname : str
1658
- Name of the virtual file to read.
1659
- kind : str
1660
- The kind of data container to create. Choose from "grid" or
1661
- "dataset".
1662
-
1663
- Returns
1664
- -------
1665
- Pointer to the GMT_GRID or GMT_DATASET data container.
1666
- """
1658
+ # The GMT C API function GMT_Read_VirtualFile returns a void pointer.
1659
+ # It usually needs to be cast to a pointer to GMT data container (e.g.,
1660
+ # GMT_GRID or GMT_DATASET).
1667
1661
type = {
1668
1662
"grid" : GMT_GRID ,
1669
- # "dataset": GMT_DATASET, # implemented in PR #2729
1663
+ # "dataset": GMT_DATASET, # implemented in PR #2729
1670
1664
}[kind ]
1671
- return ctp .cast (self . read_virtualfile ( vfname ) , ctp .POINTER (type ))
1665
+ return ctp .cast (pointer , ctp .POINTER (type ))
1672
1666
1673
1667
@contextmanager
1674
1668
def virtualfile_to_data (self , kind ):
0 commit comments