diff --git a/src/gmt_api.c b/src/gmt_api.c index 7a929776e56..1a3fb2536d5 100644 --- a/src/gmt_api.c +++ b/src/gmt_api.c @@ -3980,9 +3980,11 @@ GMT_LOCAL struct GMT_DATASET * gmtapi_import_dataset (struct GMTAPI_CTRL *API, i if ((V_obj = S_obj->resource) == NULL) { gmt_M_free (GMT, D_obj); return_null (API, GMT_PTR_IS_NULL); } - if (V_obj->type[0] != GMT_DOUBLE) { - GMT_Report (API, GMT_MSG_ERROR, "Only double-precision vectors can be passed via reference to datasets\n"); - gmt_M_free (GMT, D_obj); return_null (API, GMT_NOT_A_VALID_TYPE); + for (col = 0; col < V_obj->n_columns; col++) { + if (V_obj->type[col] != GMT_DOUBLE) { + GMT_Report (API, GMT_MSG_ERROR, "Only double-precision vectors can be passed via reference to datasets\n"); + gmt_M_free (GMT, D_obj); return_null (API, GMT_NOT_A_VALID_TYPE); + } } VH = gmt_get_V_hidden (V_obj); if (GMT->common.q.mode == GMT_RANGE_ROW_IN || GMT->common.q.mode == GMT_RANGE_DATA_IN) @@ -4009,7 +4011,7 @@ GMT_LOCAL struct GMT_DATASET * gmtapi_import_dataset (struct GMTAPI_CTRL *API, i else col_pos = col_pos_out = col; /* Just goto that column */ S->data[col_pos_out] = V_obj->data[col_pos].f8; - SH->alloc_mode[col_pos_out] = VH->alloc_mode[col]; /* Inherit from what we got */ + SH->alloc_mode[col_pos_out] = GMT_ALLOC_EXTERNALLY; /* Not this objects job to free what was passed in by reference */ } DH = gmt_get_DD_hidden (D_obj); if (smode) S->text = V_obj->text; @@ -7646,7 +7648,7 @@ GMT_LOCAL int gmtapi_init_import (struct GMTAPI_CTRL *API, enum GMT_enum_family return_value (API, API->error, GMT_NOTSET); /* Failure to register */ } n_reg++; /* Count of new items registered */ - gmt_M_free (API->GMT, wesn); + if (API->GMT->common.R.active[RSET]) gmt_M_free (API->GMT, wesn); if (first_ID == GMT_NOTSET) first_ID = object_ID; /* Found our first ID */ if ((item = gmtlib_validate_id (API, family, object_ID, GMT_IN, GMTAPI_MODULE_INPUT)) == GMT_NOTSET) return_value (API, API->error, GMT_NOTSET); /* Some internal error... */ diff --git a/src/testapi_vector_times.c b/src/testapi_vector_times.c new file mode 100644 index 00000000000..d97c8e14607 --- /dev/null +++ b/src/testapi_vector_times.c @@ -0,0 +1,28 @@ +#include "gmt.h" +int main () { + void *API = NULL; /* The API control structure */ + struct GMT_VECTOR *V = NULL; /* Structure to hold input dataset as vectors */ + char input[GMT_VF_LEN] = {""}; /* String to hold virtual input filename */ + char args[128] = {""}; /* String to hold module command arguments */ + + uint64_t dim[4] = {2, 4, 1, 0}; + char *x[4] = {"2021-03-01", "2021-03-02", "2021-03-03", "2021-03-04"}; + double y[4] = {0.0, 1.0, 2.0, 3.0}; + + /* Initialize the GMT session */ + API = GMT_Create_Session ("test", 2U, GMT_SESSION_EXTERNAL, NULL); + /* Create a dataset */ + if ((V = GMT_Create_Data (API, GMT_IS_DATASET|GMT_VIA_VECTOR, GMT_IS_POINT, GMT_CONTAINER_ONLY, dim, NULL, NULL, 0, 0, NULL)) == NULL) return (EXIT_FAILURE); + /**/ + GMT_Put_Vector(API, V, 0, GMT_TEXT, x); + GMT_Put_Vector(API, V, 1, GMT_DOUBLE, y); + /* Associate our data table with a virtual file */ + GMT_Open_VirtualFile (API, GMT_IS_DATASET|GMT_VIA_VECTOR, GMT_IS_POINT, GMT_IN|GMT_IS_REFERENCE, V, input); + /* Prepare the module arguments */ + sprintf (args, "%s -JX10c/5c -R2021-03-01/2021-03-04/-0.1/30 -Baf -BWSen -P", input); + /* Call the psxy module */ + GMT_Call_Module (API, "psxy", GMT_MODULE_CMD, args); + GMT_Close_VirtualFile (API, input); + /* Destroy the GMT session */ + if (GMT_Destroy_Session (API)) return EXIT_FAILURE; +}; diff --git a/test/api/apivectortimes.sh b/test/api/apivectortimes.sh new file mode 100755 index 00000000000..9f05fa58398 --- /dev/null +++ b/test/api/apivectortimes.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash +# +# Test the C API for plotting datetimes +# See https://github.com/GenericMappingTools/gmt/pull/6521 +ps=apivectortimes.ps +testapi_vector_times > $ps diff --git a/test/baseline/api.dvc b/test/baseline/api.dvc index 8aa20efe4a3..31a11242be3 100644 --- a/test/baseline/api.dvc +++ b/test/baseline/api.dvc @@ -1,5 +1,5 @@ outs: -- md5: 5bd99a34dd32a31bbfeb4336a9e445b7.dir - size: 3017982 - nfiles: 15 +- md5: b985dda50abc7f6dcceb4a8848e0a83a.dir + size: 3041741 + nfiles: 16 path: api diff --git a/test/gmtest.in b/test/gmtest.in index a7e62df6839..f8ed2dab03c 100755 --- a/test/gmtest.in +++ b/test/gmtest.in @@ -123,6 +123,7 @@ for apiprog in \ testapi_matrix_as_grid \ testapi_vector_strings \ testapi_vector_plot \ + testapi_vector_times \ testapi_vector_io \ testapi_matrix_io \ testapi_matrix_360 \