Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion pygmt/clib/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -1971,20 +1971,36 @@ def inquire_virtualfile(self, vfname: str) -> int:
family
The integer value for the family of the virtual file.

Raises
------
GMTCLibError
If the virtual file is not found, i.e., ``vfname`` is not a valid virtual
file name.

Examples
--------
>>> from pygmt.clib import Session
>>> with Session() as lib:
... with lib.virtualfile_out(kind="dataset") as vfile:
... family = lib.inquire_virtualfile(vfile)
... assert family == lib["GMT_IS_DATASET"]
>>> with Session() as lib:
... lib.inquire_virtualfile("not-a-virtual-file")
Traceback (most recent call last):
...
pygmt.exceptions.GMTCLibError: Failed to inquire the family of virtual file ...
"""
c_inquire_virtualfile = self.get_libgmt_func(
"GMT_Inquire_VirtualFile",
argtypes=[ctp.c_void_p, ctp.c_char_p],
restype=ctp.c_int,
)
return c_inquire_virtualfile(self.session_pointer, vfname.encode())
family = c_inquire_virtualfile(self.session_pointer, vfname.encode())

if family not in {self[name] for name in FAMILIES}:
msg = f"Failed to inquire the family of virtual file {vfname!r}."
raise GMTCLibError(msg)
return family

def read_virtualfile(
self,
Expand Down
Loading