Repository navigation
Closed
Description
The bug was first reported in PyGMT GenericMappingTools/pygmt#255. After tracking it down, I realize that it actually is a GMT bug.
The minimal example to reproduce the bug is:
import pygmt
fig = pygmt.Figure()
fig.plot(x=[1.0, 3.0], y=[2, 4], pen="1p,gray,-", region='0/10/0/10', frame=True)
fig.savefig("map.png")I can't reproduce the bug using GMT command line or GMT.jl, possibly because they read data in different ways.
Here is the output of the above Python script. Obviously, it's wrong.

The buggy codes are shown below:
Lines 4017 to 4025 in 3f11b48
| for (col = 1, diff_types = false; !diff_types && col < V_obj->n_columns; col++) if (V_obj->type[col] != V_obj->type[col-1]) diff_types = true; | |
| api_get_val = gmtapi_select_get_function (API, V_obj->type[0]); | |
| for (row = seg = n_records = 0; row < V_obj->n_rows; row++) { /* This loop may include NaN-records and data records */ | |
| n_use = gmtapi_n_cols_needed_for_gaps (GMT, V_obj->n_columns); | |
| gmtapi_update_prev_rec (GMT, n_use); | |
| for (col = 0; col < V_obj->n_columns; col++) { /* Process a single record into curr_rec */ | |
| if (diff_types && col) api_get_val = gmtapi_select_get_function (API, V_obj->type[col]); | |
| api_get_val (&(V_obj->data[col]), row, &(GMT->current.io.curr_rec[col])); | |
| } |
In the example above, the two columns have different types (GMT_DOUBLE and GMT_LONG), thus diff_types is true. At L4018, api_get_val is set to gmtapi_get_val_double.
- row=0, col=0, L4023 isn't executed, api_get_val=gmtapi_get_val_double
- row=0, col=1, L4023 is executed, api_get_val=gmtapi_get_val_long
- row=1, col=0, L4023 isn't executed, api_get_val=gmtapi_get_val_long [BUG HERE]
- row=1, col=1, L4023 is executed, api_get_val=gmtapi_get_val_long
Metadata
Metadata
Assignees
Labels
No labels
Activity
Fix functino selection bug in API for vector input
Fix functino selection bug in API for vector input (#3331)