Skip to content

Commit

Permalink
Update GMT constant GMT_STR16 to GMT_VF_LEN for GMT API change in 6.1…
Browse files Browse the repository at this point in the history
….0 (GenericMappingTools#397)

PyGMT fails with the latest GMT master branch with the following error message:
```
GMTCLibError: Constant 'GMT_STR16' doesn't exits in libgmt.
```

To reproduce the issue, you can run:
```
import pygmt
fig = pygmt.Figure()
fig.basemap(region='0/10/0/10', projection='X10c', frame=True)
fig.plot(x=5, y=5, style='c0.2c')
```

The error is caused by the recent change of the length of virtual file names
from `GMT_STR16` to `GMT_VF_LEN` in the core GMT
(see GenericMappingTools#2861).

Changing `GMT_STR16` to `GMT_VF_LEN` is the easiest fix.
To keep compatibility with both GMT 6.0.0 and the upcomming 6.1.0,
this PR checks GMT version and use `GMT_STR16` for 6.0.0, otherwise
use `GMT_VF_LEN`.
  • Loading branch information
seisman committed Mar 18, 2020
1 parent 320a728 commit 56dfd85
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion pygmt/clib/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -987,7 +987,12 @@ def open_virtual_file(self, family, geometry, direction, data):
valid_modifiers=["GMT_IS_REFERENCE", "GMT_IS_DUPLICATE"],
)

buff = ctp.create_string_buffer(self["GMT_STR16"])
# The core GMT changes GMT_STR16 to GMT_VF_LEN in 6.1.0
# See https://github.com/GenericMappingTools/gmt/pull/2861
if Version(self.info["version"]) < Version("6.1.0"):
buff = ctp.create_string_buffer(self["GMT_STR16"])
else:
buff = ctp.create_string_buffer(self["GMT_VF_LEN"])

status = c_open_virtualfile(
self.session_pointer, family_int, geometry_int, direction_int, data, buff
Expand Down

0 comments on commit 56dfd85

Please sign in to comment.