diff --git a/doc/rst/source/api.rst b/doc/rst/source/api.rst index 6f8f673efe8..cca81451bac 100644 --- a/doc/rst/source/api.rst +++ b/doc/rst/source/api.rst @@ -602,8 +602,8 @@ this program: void *API; /* The API control structure */ struct GMT_DATASET *D = NULL; /* Structure to hold input dataset */ struct GMT_GRID *G = NULL; /* Structure to hold output grid */ - char input[GMT_STR16] = {""}; /* String to hold virtual input filename */ - char output[GMT_STR16] = {""}; /* String to hold virtual output filename */ + char input[GMT_VF_LEN] = {""}; /* String to hold virtual input filename */ + char output[GMT_VF_LEN] = {""}; /* String to hold virtual output filename */ char args[128] = {""}; /* String to hold module command arguments */ /* Initialize the GMT session */ @@ -1644,7 +1644,7 @@ The full syntax is unsigned int direction, void *data, char *filename); Here, ``data`` is the pointer to your memory object. The function returns the -desired filename via ``filename``. This string must be at least ``GMT_STR16`` bytes (16). +desired filename via ``filename``. This string must be at least ``GMT_VF_LEN`` bytes (16). The other arguments have been discussed earlier. Specifically for direction, use GMT_IN for reading and GMT_OUT for writing. Simply pass this filename in the calling sequence to the module you want to use to indicate which file should diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 9f780101a02..55fae029efa 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -298,7 +298,7 @@ endif (DO_EXAMPLES OR DO_TESTS AND NOT DCW_FOUND) if (DO_API_TESTS) # These lines are temporarily here for the beta release - comment to avoid in the build - set (GMT_DEMOS_SRCS testapi.c testpsl.c testgmt.c testgmtshell.c testgmtio.c testgrdio.c testio.c + set (GMT_DEMOS_SRCS testpsl.c testgmtshell.c testgmtio.c testgrdio.c testapiconv.c example1.c testapi_matrix.c testapi_matrix_plot.c testapi_vector.c test_JL.c testapi_mixmatrix.c test_walter.c testapi_usergrid.c testapi_userdataset.c testapi_uservectors.c) endif (DO_API_TESTS) diff --git a/src/blockmean.c b/src/blockmean.c index 043bc6911c7..b549cd3cf47 100644 --- a/src/blockmean.c +++ b/src/blockmean.c @@ -282,11 +282,12 @@ GMT_LOCAL int parse (struct GMT_CTRL *GMT, struct BLOCKMEAN_CTRL *Ctrl, struct G int GMT_blockmean (void *V_API, int mode, void *args) { uint64_t node, n_cells_filled, n_read, n_lost, n_pitched, w_col, *np = NULL; - unsigned int row, col, n_input, k, NF = 0, fcol[BLK_N_FIELDS] = {2,3,4,5,6,0,0,0}, field[BLK_N_FIELDS]; + unsigned int row, col, n_input, k, kk, NF = 0, fcol[BLK_N_FIELDS] = {2,3,4,5,6,0,0,0}, field[BLK_N_FIELDS]; int error; - bool use_xy, use_weight, duplicate_col; + bool use_xy, use_weight, duplicate_col, bail = false; double weight, weight_s2 = 0, weight_pos, weighted_z, iw, half_dx, wesn[4], out[7], *in = NULL; char format[GMT_LEN512] = {""}, *fcode[BLK_N_FIELDS] = {"z", "s", "l", "h", "w", "", "", ""}, *code[BLK_N_FIELDS]; + char file[PATH_MAX] = {""}; struct GMT_OPTION *options = NULL; struct GMT_GRID *Grid = NULL, *G = NULL, *GridOut[BLK_N_FIELDS]; @@ -451,22 +452,27 @@ int GMT_blockmean (void *V_API, int mode, void *args) { if (n_read == 0) { /* Blank/empty input files */ GMT_Report (API, GMT_MSG_WARNING, "No data records found; no output produced\n"); - Return (GMT_NOERROR); + if (!(API->external && Ctrl->G.active)) + bail = true; } - if (n_pitched == 0) { /* No points inside region */ + else if (n_pitched == 0) { /* No points inside region */ GMT_Report (API, GMT_MSG_WARNING, "No data points found inside the region; no output produced\n"); + if (!(API->external && Ctrl->G.active)) + bail = true; + } + + if (bail) { /* Time to quit */ Return (GMT_NOERROR); } w_col = gmt_get_cols (GMT, GMT_OUT) - 1; /* Index of weight column (the last output column) */ n_cells_filled = 0; /* Number of blocks with values */ fcol[4] = (unsigned int)w_col; /* Since we don't know what it is until parsed */ - GMT_Report (API, GMT_MSG_INFORMATION, "Calculating block means\n"); if (Ctrl->G.active) { /* Create the grid(s) */ char *remarks[BLK_N_FIELDS] = {"Mean value per bin", "Standard deviation per bin", "Lowest value per bin", "Highest value per bin", "Weight per bin"}; - for (k = 0; k < BLK_N_FIELDS; k++) { + for (k = kk = 0; k < BLK_N_FIELDS; k++) { if (!Ctrl->A.selected[k]) continue; field[NF] = fcol[k]; /* Just keep record of which fields we are actually using */ code[NF] = fcode[k]; @@ -477,9 +483,22 @@ int GMT_blockmean (void *V_API, int mode, void *args) { if (GMT_Set_Comment (API, GMT_IS_GRID, GMT_COMMENT_IS_REMARK, remarks[k], GridOut[NF])) Return (API->error); if (G == NULL) G = GridOut[NF]; /* First grid header used to get node later */ for (node = 0; node < G->header->size; node++) - GridOut[NF]->data[node] = GMT->session.f_NaN; + GridOut[NF]->data[node] = GMT->session.f_NaN; /* Initialize with NaNs */ + if (API->external && n_read == 0) { /* Write the empty grids back to the external caller */ + if (strstr (Ctrl->G.file[kk], "%s")) + sprintf (file, Ctrl->G.file[kk], code[k]); + else + strncpy (file, Ctrl->G.file[kk], PATH_MAX-1); + if (GMT_Write_Data (API, GMT_IS_GRID, GMT_IS_FILE, GMT_IS_SURFACE, GMT_CONTAINER_AND_DATA, NULL, file, GridOut[k]) != GMT_NOERROR) { + Return (API->error); + } + } + if (Ctrl->G.n > 1) kk++; /* Only true for APIs */ NF++; /* Number of actual field grids */ } + if (API->external && n_read == 0) { /* Delayed return */ + Return (GMT_NOERROR); + } } else { /* Get ready for rec-by-rec output */ if (GMT->common.h.add_colnames) { /* Create meaningful column header */ @@ -503,6 +522,7 @@ int GMT_blockmean (void *V_API, int mode, void *args) { } } + GMT_Report (API, GMT_MSG_INFORMATION, "Calculating block means\n"); Out = gmt_new_record (GMT, out, NULL); /* Since we only need to worry about numerics in this module */ for (node = 0; node < Grid->header->size; node++) { /* Visit all possible blocks to see if they were visited */ @@ -558,8 +578,6 @@ int GMT_blockmean (void *V_API, int mode, void *args) { GMT_Put_Record (API, GMT_WRITE_DATA, Out); /* Write this to output */ } if (Ctrl->G.active) { /* Writes the grid(s) */ - unsigned int kk; - char file[PATH_MAX] = {""}; for (k = kk = 0; k < NF; k++) { if (strstr (Ctrl->G.file[kk], "%s")) sprintf (file, Ctrl->G.file[kk], code[k]); diff --git a/src/blockmedian.c b/src/blockmedian.c index 69f0c87d075..118fb86f6d9 100644 --- a/src/blockmedian.c +++ b/src/blockmedian.c @@ -368,14 +368,15 @@ GMT_LOCAL void median_output (struct GMT_CTRL *GMT, struct GMT_GRID_HEADER *h, u int GMT_blockmedian (void *V_API, int mode, void *args) { int error = 0; - bool do_extra = false, duplicate_col; + bool do_extra = false, duplicate_col, bail = false; uint64_t n_lost, node, first_in_cell, first_in_new_cell; uint64_t n_read, nz, n_pitched, n_cells_filled, w_col, i_col = 0, sid_col; size_t n_alloc = 0, nz_alloc = 0; unsigned int row, col, emode = 0, n_input, n_output, n_quantiles = 1, go_quickly = 0; - unsigned int k, NF = 0, fcol[BLK_N_FIELDS] = {2,3,4,5,6,7,0,0}, field[BLK_N_FIELDS]; + unsigned int k, kk, NF = 0, fcol[BLK_N_FIELDS] = {2,3,4,5,6,7,0,0}, field[BLK_N_FIELDS]; double out[8], wesn[4], quantile[3] = {0.25, 0.5, 0.75}, extra[8], weight, half_dx, *in = NULL, *z_tmp = NULL; char format[GMT_LEN512] = {""}, *old_format = NULL, *fcode[BLK_N_FIELDS] = {"z", "s", "l", "q25", "q75", "h", "w", ""}, *code[BLK_N_FIELDS]; + char file[PATH_MAX] = {""}; struct GMT_OPTION *options = NULL; struct GMT_GRID *Grid = NULL, *G = NULL, *GridOut[BLK_N_FIELDS]; @@ -527,10 +528,15 @@ int GMT_blockmedian (void *V_API, int mode, void *args) { if (n_read == 0) { /* Blank/empty input files */ GMT_Report (API, GMT_MSG_WARNING, "No data records found; no output produced\n"); - Return (GMT_NOERROR); + if (!(API->external && Ctrl->G.active)) + bail = true; } - if (n_pitched == 0) { /* No points inside region */ + else if (n_pitched == 0) { /* No points inside region */ GMT_Report (API, GMT_MSG_WARNING, "No data points found inside the region; no output produced\n"); + if (!(API->external && Ctrl->G.active)) + bail = true; + } + if (bail) { /* Time to quit */ Return (GMT_NOERROR); } @@ -545,7 +551,7 @@ int GMT_blockmedian (void *V_API, int mode, void *args) { if (Ctrl->G.active) { /* Create the grid(s) */ char *remarks[BLK_N_FIELDS] = {"Median value per bin", "L1 scale per bin", "Lowest value per bin", "25% quartile", "75% quartile", "Highest value per bin", "Weight per bin"}; - for (k = NF = 0; k < BLK_N_FIELDS; k++) { + for (k = kk = 0; k < BLK_N_FIELDS; k++) { if (!Ctrl->A.selected[k]) continue; field[NF] = fcol[k]; /* Just keep record of which fields we are actually using */ code[NF] = fcode[k]; @@ -557,8 +563,21 @@ int GMT_blockmedian (void *V_API, int mode, void *args) { if (G == NULL) G = GridOut[NF]; /* First grid header used to get node later */ for (node = 0; node < G->header->size; node++) GridOut[NF]->data[node] = GMT->session.f_NaN; + if (API->external && n_read == 0) { /* Write the empty grids back to the external caller */ + if (strstr (Ctrl->G.file[kk], "%s")) + sprintf (file, Ctrl->G.file[kk], code[k]); + else + strncpy (file, Ctrl->G.file[kk], PATH_MAX-1); + if (GMT_Write_Data (API, GMT_IS_GRID, GMT_IS_FILE, GMT_IS_SURFACE, GMT_CONTAINER_AND_DATA, NULL, file, GridOut[k]) != GMT_NOERROR) { + Return (API->error); + } + } + if (Ctrl->G.n > 1) kk++; /* Only true for APIs */ NF++; /* Number of actual field grids */ } + if (API->external && n_read == 0) { /* Delayed return */ + Return (GMT_NOERROR); + } } else { /* Get ready for rec-by-rec output */ if (GMT_Begin_IO (API, GMT_IS_DATASET, GMT_OUT, GMT_HEADER_ON) != GMT_NOERROR) { /* Enables data output and sets access mode */ @@ -571,6 +590,8 @@ int GMT_blockmedian (void *V_API, int mode, void *args) { } } + GMT_Report (API, GMT_MSG_INFORMATION, "Calculating block medians\n"); + if (emode) { /* Index column last, with weight col just before */ i_col = w_col--; old_format = GMT->current.io.o_format[i_col]; /* Need to restore this at end */ @@ -648,8 +669,6 @@ int GMT_blockmedian (void *V_API, int mode, void *args) { if (do_extra) gmt_M_free (GMT, z_tmp); if (Ctrl->G.active) { /* Writes the grid(s) */ - unsigned int kk; - char file[PATH_MAX] = {""}; for (k = kk = 0; k < NF; k++) { if (strstr (Ctrl->G.file[kk], "%s")) sprintf (file, Ctrl->G.file[kk], code[k]); diff --git a/src/blockmode.c b/src/blockmode.c index 75fc3b18a04..0e657e59e66 100644 --- a/src/blockmode.c +++ b/src/blockmode.c @@ -483,12 +483,12 @@ GMT_LOCAL double weighted_mode (struct BLK_DATA *d, double wsum, unsigned int em #define Return(code) {GMT_Destroy_Data (API, &Grid); gmt_M_free (GMT, Out); gmt_M_free (GMT, data); Free_Ctrl (GMT, Ctrl); gmt_end_module (GMT, GMT_cpy); bailout (code);} int GMT_blockmode (void *V_API, int mode, void *args) { - bool mode_xy, do_extra = false, is_integer, duplicate_col; + bool mode_xy, do_extra = false, is_integer, duplicate_col, bail = false; int way, error = 0; unsigned int row, col, emode = 0, n_input, n_output; - unsigned int k, NF = 0, fcol[BLK_N_FIELDS] = {2,3,4,5,6,7,0,0}, field[BLK_N_FIELDS]; + unsigned int k, kk, NF = 0, fcol[BLK_N_FIELDS] = {2,3,4,5,6,7,0,0}, field[BLK_N_FIELDS]; uint64_t node, first_in_cell, first_in_new_cell, n_lost, n_read; uint64_t n_cells_filled, n_in_cell, nz, n_pitched, src_id = 0; @@ -500,6 +500,7 @@ int GMT_blockmode (void *V_API, int mode, void *args) { double z_min = DBL_MAX, z_max = -DBL_MAX; char format[GMT_LEN512] = {""}, *old_format = NULL, *fcode[BLK_N_FIELDS] = {"z", "s", "l", "h", "w", "", "", ""}, *code[BLK_N_FIELDS]; + char file[PATH_MAX] = {""}; struct GMT_OPTION *options = NULL; struct GMT_GRID *Grid = NULL, *G = NULL, *GridOut[BLK_N_FIELDS]; @@ -650,17 +651,23 @@ int GMT_blockmode (void *V_API, int mode, void *args) { Return (API->error); } + if (Ctrl->D.active && Ctrl->D.width == 0.0 && !is_integer) { + GMT_Report (API, GMT_MSG_ERROR, "Option -D: No bin width specified and data are not integers\n"); + Return (GMT_PARSE_ERROR); + } + if (n_read == 0) { /* Blank/empty input files */ GMT_Report (API, GMT_MSG_WARNING, "No data records found; no output produced\n"); - Return (GMT_NOERROR); + if (!(API->external && Ctrl->G.active)) + bail = true; } - if (n_pitched == 0) { /* No points inside region */ + else if (n_pitched == 0) { /* No points inside region */ GMT_Report (API, GMT_MSG_WARNING, "No data points found inside the region; no output produced\n"); - Return (GMT_NOERROR); + if (!(API->external && Ctrl->G.active)) + bail = true; } - if (Ctrl->D.active && Ctrl->D.width == 0.0 && !is_integer) { - GMT_Report (API, GMT_MSG_ERROR, "Option -D: No bin width specified and data are not integers\n"); - Return (GMT_PARSE_ERROR); + if (bail) { /* Time to quit */ + Return (GMT_NOERROR); } if (n_pitched < n_alloc) { n_alloc = n_pitched; @@ -673,7 +680,7 @@ int GMT_blockmode (void *V_API, int mode, void *args) { if (Ctrl->G.active) { /* Create the grid(s) */ char *remarks[BLK_N_FIELDS] = {"Median value per bin", "L1 scale per bin", "Lowest value per bin", "Highest value per bin", "Weight per bin"}; - for (k = 0; k < BLK_N_FIELDS; k++) { + for (k = kk = 0; k < BLK_N_FIELDS; k++) { if (!Ctrl->A.selected[k]) continue; field[NF] = fcol[k]; /* Just keep record of which fields we are actually using */ code[NF] = fcode[k]; @@ -685,8 +692,21 @@ int GMT_blockmode (void *V_API, int mode, void *args) { if (G == NULL) G = GridOut[NF]; /* First grid header used to get node later */ for (node = 0; node < G->header->size; node++) GridOut[NF]->data[node] = GMT->session.f_NaN; + if (API->external && n_read == 0) { /* Write the empty grids back to the external caller */ + if (strstr (Ctrl->G.file[kk], "%s")) + sprintf (file, Ctrl->G.file[kk], code[k]); + else + strncpy (file, Ctrl->G.file[kk], PATH_MAX-1); + if (GMT_Write_Data (API, GMT_IS_GRID, GMT_IS_FILE, GMT_IS_SURFACE, GMT_CONTAINER_AND_DATA, NULL, file, GridOut[k]) != GMT_NOERROR) { + Return (API->error); + } + } + if (Ctrl->G.n > 1) kk++; /* Only true for APIs */ NF++; /* Number of actual field grids */ } + if (API->external && n_read == 0) { /* Delayed return */ + Return (GMT_NOERROR); + } } else { /* Get ready for rec-by-rec output */ if (GMT_Begin_IO (API, GMT_IS_DATASET, GMT_OUT, GMT_HEADER_ON) != GMT_NOERROR) { /* Enables data output and sets access mode */ @@ -697,6 +717,8 @@ int GMT_blockmode (void *V_API, int mode, void *args) { } } + GMT_Report (API, GMT_MSG_INFORMATION, "Calculating block modes\n"); + if (emode) { /* Index column last, with weight col just before */ i_col = w_col--; old_format = GMT->current.io.o_format[i_col]; /* Need to restore this at end */ diff --git a/src/example1.c b/src/example1.c index ea18c30ec72..09df80374e2 100644 --- a/src/example1.c +++ b/src/example1.c @@ -3,8 +3,8 @@ int main () { void *API; /* The API control structure */ struct GMT_DATASET *D = NULL; /* Structure to hold input dataset */ struct GMT_GRID *G = NULL; /* Structure to hold output grid */ - char input[GMT_STR16] = {""}; /* String to hold virtual input filename */ - char output[GMT_STR16] = {""}; /* String to hold virtual output filename */ + char input[GMT_VF_LEN] = {""}; /* String to hold virtual input filename */ + char output[GMT_VF_LEN] = {""}; /* String to hold virtual output filename */ char args[128] = {""}; /* String to hold module command arguments */ /* Initialize the GMT session */ diff --git a/src/gmt.h b/src/gmt.h index 2bd36cbecaf..40bddb42f56 100644 --- a/src/gmt.h +++ b/src/gmt.h @@ -174,16 +174,6 @@ EXTERN_MSC int GMT_Extract_Region (void *API, char *file, double wesn[]); EXTERN_MSC float GMT_Get_Version (void *API, unsigned int *major, unsigned int *minor, unsigned int *patch); EXTERN_MSC void *GMT_Get_Ctrl (void *API); -/* These 8 functions are provided for backwards compatibility but are considered obsolete as of 6 */ -EXTERN_MSC void *GMT_Get_Data (void *API, int object_ID, unsigned int mode, void *data); -EXTERN_MSC int GMT_Put_Data (void *API, int object_ID, unsigned int mode, void *data); -EXTERN_MSC void *GMT_Retrieve_Data (void *API, int object_ID); -EXTERN_MSC int GMT_Encode_ID (void *API, char *string, int object_ID); -EXTERN_MSC int GMT_Get_ID (void *API, unsigned int family, unsigned int direction, void *resource); -EXTERN_MSC int GMT_Get_Value (void *API, const char *arg, double *par); -EXTERN_MSC int GMT_Get_Family (void *API, unsigned int direction, struct GMT_OPTION *head); -EXTERN_MSC int GMT_Status_IO (void *API, unsigned int mode); - #ifdef __cplusplus } #endif diff --git a/src/gmt_api.c b/src/gmt_api.c index 8a91d0f7965..4dfa5199d4c 100644 --- a/src/gmt_api.c +++ b/src/gmt_api.c @@ -249,6 +249,7 @@ static const char *GMT_status[] = {"Unused", "In-use", "Used"}; static const char *GMT_geometry[] = {"Not Set", "Point", "Line", "Polygon", "Point|Line|Poly", "Line|Poly", "Surface", "Non-Geographical", "Text"}; static const char *GMT_class[] = {"QUIET", "ERROR", "WARNING", "TIMING", "INFORMATION", "COMPATIBILITY", "DEBUG"}; static unsigned int GMT_no_pad[4] = {0, 0, 0, 0}; +static const char *GMT_family_abbrev[] = {"D", "G", "I", "C", "X", "M", "V", "-"}; /*! Two different i/o mode: GMT_Put|Get_Data vs GMT_Put|Get_Record */ enum GMT_enum_iomode { @@ -354,6 +355,11 @@ GMT_LOCAL bool valid_input_family (unsigned int family) { || family == GMT_IS_IMAGE || family == GMT_IS_PALETTE || family == GMT_IS_POSTSCRIPT); } +GMT_LOCAL bool valid_actual_family (unsigned int family) { + /* Return true for the main actual family types */ + return (family >= GMT_IS_DATASET && family < GMT_N_FAMILIES); +} + GMT_LOCAL bool valid_output_family (unsigned int family) { if (family == GMT_IS_VECTOR || family == GMT_IS_MATRIX || family == GMT_IS_POSTSCRIPT) return true; return valid_input_family (family); @@ -2421,7 +2427,7 @@ GMT_LOCAL int api_decode_id (const char *filename) { int object_ID = GMT_NOTSET; if (gmt_M_file_is_memory (filename)) { /* Passing ID of a registered object */ - if (sscanf (&filename[9], "%d", &object_ID) != 1) return (GMT_NOTSET); /* Get the object ID unless we fail scanning */ + if (sscanf (&filename[GMTAPI_OBJECT_ID_START], "%d", &object_ID) != 1) return (GMT_NOTSET); /* Get the object ID unless we fail scanning */ } return (object_ID); /* Returns GMT_NOTSET if no embedded ID was found */ } @@ -2704,11 +2710,7 @@ GMT_LOCAL struct GMT_PALETTE * api_import_palette (struct GMTAPI_CTRL *API, int break; } S_obj->status = GMT_IS_USED; /* Mark as read */ -#ifdef GMT_BACKWARDS_API - P_obj->range = P_obj->data; - P_obj->patch = P_obj->bfn; - P_obj->cpt_flags = P_obj->mode; -#endif + return (P_obj); /* Pass back the palette */ } @@ -3885,10 +3887,6 @@ GMT_LOCAL struct GMT_DATASET *api_import_dataset (struct GMTAPI_CTRL *API, int o D_obj->table = gmt_M_memory (GMT, D_obj->table, n_alloc, struct GMT_DATATABLE *); gmt_M_memset (&(D_obj->table[old_n_alloc]), n_alloc - old_n_alloc, struct GMT_DATATABLE *); /* Set new memory to NULL */ } -#ifdef GMT_BACKWARDS_API - for (seg = 0; seg < D_obj->table[D_obj->n_tables-1]->n_segments; seg++) - D_obj->table[D_obj->n_tables-1]->segment[seg]->coord = D_obj->table[D_obj->n_tables-1]->segment[seg]->data; -#endif } S_obj->alloc_mode = DH->alloc_mode; /* Clarify allocation mode for this object */ #if 0 @@ -4476,11 +4474,6 @@ GMT_LOCAL struct GMT_IMAGE *api_import_image (struct GMTAPI_CTRL *API, int objec if (done) S_obj->status = GMT_IS_USED; /* Mark as read (unless we just got the header) */ if (!via) S_obj->resource = I_obj; /* Retain pointer to the allocated data so we use garbage collection later */ -#ifdef GMT_BACKWARDS_API - I_obj->ColorMap = I_obj->colormap; - I_obj->nIndexedColors = I_obj->n_indexed_colors; -#endif - return ((mode & GMT_DATA_ONLY) ? NULL : I_obj); /* Pass back out what we have so far */ } @@ -4921,10 +4914,6 @@ GMT_LOCAL struct GMT_GRID *api_import_grid (struct GMTAPI_CTRL *API, int object_ if (done) S_obj->status = GMT_IS_USED; /* Mark as read (unless we just got the header) */ -#ifdef GMT_BACKWARDS_API - G_obj->header->nx = G_obj->header->n_columns; - G_obj->header->ny = G_obj->header->n_rows; -#endif return (G_obj); /* Pass back out what we have so far */ } @@ -6167,17 +6156,50 @@ int GMT_Destroy_Session_ () { #endif /*! . */ -GMT_LOCAL int api_encode_id (void *V_API, char *filename, int object_ID) { - /* Creates a filename with the embedded GMTAPI Object ID. Space must exist. +GMT_LOCAL char api_debug_geometry_code (unsigned int geometry) { + char c; + switch (geometry) { + case GMT_IS_POINT: c = 'T'; break; + case GMT_IS_LINE: c = 'L'; break; + case GMT_IS_POLY: c = 'P'; break; + case GMT_IS_LP: c = 'C'; break; + case GMT_IS_PLP: c = 'A'; break; + case GMT_IS_SURFACE: c = 'G'; break; + case GMT_IS_NONE: c = 'N'; break; + case GMT_IS_TEXT: c = 'X'; break; + default: c = 'U'; break; + } + return c; +} + +/*! . */ +GMT_LOCAL int api_encode_id (struct GMTAPI_CTRL *API, unsigned int module_input, unsigned int direction, unsigned int family, unsigned int actual_family, unsigned int geometry, unsigned int messenger, int object_ID, char *filename) { + /* Creates a virtual filename with the embedded object information . Space for up to GMT_VF_LEN characters in filename must exist. + * Name template: @GMTAPI@-S-D-F-A-G-M-###### where # is the 6-digit integer object code. + * S stands for P(rimary) or S(econdary) input or output object (command line is primary, files via options are secondary). + * D stands for Direction and is either I(n) or O(ut). + * F stands for Family and is one of D(ataset), G(rid), I(mage), C(PT), X(PostScript), M(atrix), V(ector), U(ndefined). + * A stands for Actual Family and is one of D, G, I, C, X, M, V, and U as well. + * Actual family may differ from family if a Dataset is actually passed as a Matrix, for instance. + * G stands for Geometry and is one of (poin)T, L(ine), P(olygon), C(Line|Polygon), A(POint|Line|Polygon), G(rid), N(one), X(text), or U(ndefined). + * M stands for Messenger and is either Y(es) or N(o). * Limitation: object_ID must be <= GMTAPI_MAX_ID */ - if (V_API == NULL) return_error (V_API, GMT_NOT_A_SESSION); /* GMT_Create_Session has not been called */ - if (!filename) return_error (V_API, GMT_MEMORY_ERROR); /* Oops, cannot write to that variable */ - if (object_ID == GMT_NOTSET) return_error (V_API, GMT_NOT_A_VALID_ID); /* ID is not set yet */ - if (object_ID > GMTAPI_MAX_ID) return_error (V_API, GMT_ID_TOO_LARGE); /* ID is too large to fit in %06d format below */ + if (API == NULL) return_error (API, GMT_NOT_A_SESSION); /* GMT_Create_Session has not been called */ + if (!filename) return_error (API, GMT_MEMORY_ERROR); /* Oops, cannot write to that variable */ + if (object_ID <= GMT_NOTSET) return_error (API, GMT_NOT_A_VALID_ID); /* ID is not set yet */ + if (object_ID > GMTAPI_MAX_ID) return_error (API, GMT_ID_TOO_LARGE); /* ID is too large to fit in %06d format below */ + if (!(direction == GMT_IN || direction == GMT_OUT)) return_error (API, GMT_NOT_A_VALID_DIRECTION); + if (!valid_input_family (family)) return_error (API, GMT_NOT_A_VALID_FAMILY); + if (!valid_actual_family (actual_family)) return_error (API, GMT_NOT_A_VALID_FAMILY); + if (api_validate_geometry (API, family, geometry)) return_error (API, GMT_BAD_GEOMETRY); + if (!(messenger == 0 || messenger == 1)) return_error (API, GMT_RUNTIME_ERROR); + if (module_input) module_input = 1; /* It may be GMT_VIA_MODULE_INPUT but here we want just 0 or 1 */ - sprintf (filename, "@GMTAPI@-%06d", object_ID); /* Place the object ID in the special GMT API format */ - return_error (V_API, GMT_NOERROR); /* No error encountered */ + sprintf (filename, "@GMTAPI@-%c-%c-%s-%s-%c-%c-%06d", (module_input) ? 'P' : 'S', (direction == GMT_IN) ? 'I' : 'O', GMT_family_abbrev[family], GMT_family_abbrev[actual_family], api_debug_geometry_code (geometry), (messenger) ? 'Y' : 'N', object_ID); + GMT_Report (API, GMT_MSG_DEBUG, "VirtualFile name created: %s\n", filename); + + return_error (API, GMT_NOERROR); /* No error encountered */ } /* Data registration: The main reason for data registration is the following: @@ -6822,11 +6844,13 @@ int GMT_Open_VirtualFile (void *V_API, unsigned int family, unsigned int geometr * beforehand or it is NULL and we create an expanding output resource. * name is the name given to the virtual file and is returned. */ int object_ID = GMT_NOTSET, item_s = 0; - unsigned int item, orig_family, actual_family = 0, via_type = 0; + unsigned int item, orig_family, actual_family = 0, via_type = 0, messenger = 0, module_input; bool readonly = false; struct GMTAPI_DATA_OBJECT *S_obj = NULL; struct GMTAPI_CTRL *API = NULL; if (V_API == NULL) return_error (V_API, GMT_NOT_A_SESSION); + module_input = (family & GMT_VIA_MODULE_INPUT); /* Are we registering a resource that is a module input? */ + family -= module_input; if (direction & GMT_IS_REFERENCE) { /* Treat this memory as read-only */ readonly = true; direction -= GMT_IS_REFERENCE; @@ -6913,12 +6937,13 @@ int GMT_Open_VirtualFile (void *V_API, unsigned int family, unsigned int geometr S_obj = API->object[item_s]; /* Short-hand for later */ S_obj->type = (via_type) ? via_type - 1 : API->GMT->current.setting.export_type; /* Remember what output type we want */ S_obj->method = GMT_IS_REFERENCE; /* Now a memory resource */ + messenger = 1; } /* If the output is a matrix masquerading as grid then it must be GMT_FLOAT, otherwise change to DUPLICATE */ maybe_change_method_to_duplicate (API, S_obj, readonly); } /* Obtain the unique VirtualFile name */ - if (api_encode_id (API, name, object_ID) != GMT_NOERROR) + if (api_encode_id (API, module_input, direction, family, actual_family, geometry, messenger, object_ID, name) != GMT_NOERROR) return (API->error); return GMT_NOERROR; } @@ -12508,90 +12533,6 @@ int GMT_Get_Enum_ (char *arg, int len) { } #endif -/* Backwards compatibility for old API functions from 5.1-2 no longer in favor - * as the Virtual File concept is much easier to understand and use. */ - -/*! . */ -int GMT_Get_Value (void *V_API, const char *arg, double *par) { - - return (GMT_Get_Values (V_API, arg, par, 999)); -} -#ifdef FORTRAN_API -int GMT_Get_Value_ (char *arg, double par[], int len) { - /* Fortran version: We pass the global GMT_FORTRAN structure */ - return (GMT_Get_Values (GMT_FORTRAN, arg, par, len)); -} -#endif - -/*! . */ -void *GMT_Retrieve_Data (void *API, int object_ID) { - return api_retrieve_data (API, object_ID); -} - -#ifdef FORTRAN_API -void *GMT_Retrieve_Data_ (int *object_ID) { - /* Fortran version: We pass the global GMT_FORTRAN structure */ - return (api_retrieve_data (GMT_FORTRAN, *object_ID)); -} -#endif - -void *GMT_Get_Data (void *API, int object_ID, unsigned int mode, void *data) { - return api_get_data (API, object_ID, mode, data); -} - -#ifdef FORTRAN_API -void *GMT_Get_Data_ (int *ID, int *mode, void *data) { - /* Fortran version: We pass the global GMT_FORTRAN structure */ - return (api_get_data (GMT_FORTRAN, *ID, *mode, data)); -} -#endif - -int GMT_Put_Data (void *API, int object_ID, unsigned int mode, void *data) { - return api_put_data (API, object_ID, mode, data); -} - -#ifdef FORTRAN_API -int GMT_Put_Data_ (int *object_ID, unsigned int *mode, void *data) { - /* Fortran version: We pass the global GMT_FORTRAN structure */ - return (api_put_data (GMT_FORTRAN, *object_ID, *mode, data)); -} -#endif - -int GMT_Encode_ID (void *API, char *filename, int object_ID) { - return (api_encode_id (API, filename, object_ID)); -} - -#ifdef FORTRAN_API -int GMT_Encode_ID_ (char *filename, int *object_ID, int len) { - /* Fortran version: We pass the global GMT_FORTRAN structure */ - return (GMT_Encode_ID (GMT_FORTRAN, filename, *object_ID)); -} -#endif - -int GMT_Get_ID (void *API, unsigned int family, unsigned int direction, void *resource) { - return (api_get_id (API, family, direction, resource)); -} - -#ifdef FORTRAN_API -int GMT_Get_ID_ (unsigned int *family, unsigned int *direction, void *resource) { - /* Fortran version: We pass the global GMT_FORTRAN structure */ - return (GMT_Get_ID (GMT_FORTRAN, *family, *direction, resource)); -} -#endif - -/* Changed name to always have a verb */ - -int GMT_Status_IO (void *V_API, unsigned int mode) { - return (GMT_Get_Status (V_API, mode)); -} - -#ifdef FORTRAN_API -int GMT_Status_IO_ (unsigned int *mode) { - /* Fortran version: We pass the global GMT_FORTRAN structure */ - return (GMT_Get_Status (GMT_FORTRAN, *mode)); -} -#endif - /* A few more FORTRAN bindings moved from gmt_fft.c: */ #ifdef FORTRAN_API diff --git a/src/gmt_enum_dict.h b/src/gmt_enum_dict.h index 0ea5862aec8..b020655a157 100644 --- a/src/gmt_enum_dict.h +++ b/src/gmt_enum_dict.h @@ -28,7 +28,7 @@ struct GMT_API_DICT { int value; }; -#define GMT_N_API_ENUMS 230 +#define GMT_N_API_ENUMS 231 GMT_LOCAL struct GMT_API_DICT gmt_api_enums[GMT_N_API_ENUMS] = { {"GMT_ADD_DEFAULT", 6}, @@ -135,6 +135,7 @@ GMT_LOCAL struct GMT_API_DICT gmt_api_enums[GMT_N_API_ENUMS] = { {"GMT_IS_GRID", 1}, {"GMT_IS_HOLE", 1}, {"GMT_IS_LINE", 2}, + {"GMT_IS_LP", 6}, {"GMT_IS_MATRIX", 5}, {"GMT_IS_NONE", 16}, {"GMT_IS_OUTPUT", 1024}, @@ -208,7 +209,6 @@ GMT_LOCAL struct GMT_API_DICT gmt_api_enums[GMT_N_API_ENUMS] = { {"GMT_SESSION_NORMAL", 0}, {"GMT_SESSION_RUNMODE", 16}, {"GMT_SHORT", 2}, - {"GMT_STR16", 16}, {"GMT_STRICT_CONVERSION", 1024}, {"GMT_SYNOPSIS", 1}, {"GMT_TBL", 0}, @@ -222,6 +222,7 @@ GMT_LOCAL struct GMT_API_DICT gmt_api_enums[GMT_N_API_ENUMS] = { {"GMT_ULONG", 7}, {"GMT_USAGE", 0}, {"GMT_USHORT", 3}, + {"GMT_VF_LEN", 32}, {"GMT_VIA_CHAR", 100}, {"GMT_VIA_DOUBLE", 1000}, {"GMT_VIA_FLOAT", 900}, diff --git a/src/gmt_grdio.c b/src/gmt_grdio.c index 9530d38eebf..6b2ee6a28fd 100644 --- a/src/gmt_grdio.c +++ b/src/gmt_grdio.c @@ -1415,10 +1415,6 @@ int gmtlib_read_grd_info (struct GMT_CTRL *GMT, char *file, struct GMT_GRID_HEAD /* unpack z-range: */ header->z_min = header->z_min * header->z_scale_factor + header->z_add_offset; header->z_max = header->z_max * header->z_scale_factor + header->z_add_offset; -#ifdef GMT_BACKWARDS_API - header->nx = header->n_columns; - header->ny = header->n_rows; -#endif return (GMT_NOERROR); } @@ -1928,10 +1924,6 @@ void gmt_set_grddim (struct GMT_CTRL *GMT, struct GMT_GRID_HEADER *h) { h->size = gmt_grd_get_size (h); /* Sets the number of items (not bytes!) needed to hold this array, which includes the padding (size >= nm) */ h->xy_off = 0.5 * h->registration; gmt_set_grdinc (GMT, h); -#ifdef GMT_BACKWARDS_API - h->nx = h->n_columns; - h->ny = h->n_rows; -#endif } void gmt_grd_init (struct GMT_CTRL *GMT, struct GMT_GRID_HEADER *header, struct GMT_OPTION *options, bool update) { diff --git a/src/gmt_hidden.h b/src/gmt_hidden.h index a4fbfe0d2cd..4e49367e68a 100644 --- a/src/gmt_hidden.h +++ b/src/gmt_hidden.h @@ -80,9 +80,6 @@ struct GMT_DATASEGMENT_HIDDEN { /* Supporting information hidden from the API struct GMT_DATASEGMENT *next; /* NULL unless polygon and has holes and pointing to next hole */ enum GMT_enum_alloc alloc_mode; /* Allocation mode [GMT_ALLOC_INTERNALLY] */ char *file[2]; /* Name of file or source [0 = in, 1 = out] */ -#ifdef GMT_BACKWARDS_API - double **coord; -#endif }; struct GMT_DATATABLE_HIDDEN { /* Supporting information hidden from the API */ diff --git a/src/gmt_init.c b/src/gmt_init.c index 1f209d08e69..a4e625e8fd1 100644 --- a/src/gmt_init.c +++ b/src/gmt_init.c @@ -828,7 +828,7 @@ GMT_LOCAL int gmtinit_rectR_to_geoR (struct GMT_CTRL *GMT, char unit, double rec uint64_t dim[GMT_DIM_SIZE] = {1, 1, 2, 2}; /* Just a single data table with one segment with two 2-column records */ bool was_R, was_J; double wesn[4]; - char buffer[GMT_LEN256] = {""}, in_string[GMT_STR16] = {""}, out_string[GMT_STR16] = {""}; + char buffer[GMT_LEN256] = {""}, in_string[GMT_VF_LEN] = {""}, out_string[GMT_VF_LEN] = {""}; struct GMT_DATASET *In = NULL, *Out = NULL; GMT_Report (GMT->parent, GMT_MSG_DEBUG, "Call gmtinit_rectR_to_geoR to convert projected -R to geo -R\n"); @@ -12768,7 +12768,7 @@ GMT_LOCAL int gmtlib_get_region_from_data (struct GMTAPI_CTRL *API, int family, struct GMT_GRID *G = NULL; struct GMT_OPTION *opt = NULL, *head = NULL, *tmp = NULL; struct GMT_DATASET *Out = NULL; - char virt_file[GMT_STR16] = {""}, tmpfile[PATH_MAX] = {""}, *list = "bfi:"; + char virt_file[GMT_VF_LEN] = {""}, tmpfile[PATH_MAX] = {""}, *list = "bfi:"; struct GMT_GRID_HEADER_HIDDEN *HH = NULL; switch (family) { diff --git a/src/gmt_io.c b/src/gmt_io.c index 2702bab56a0..2827f118970 100644 --- a/src/gmt_io.c +++ b/src/gmt_io.c @@ -2760,7 +2760,7 @@ GMT_LOCAL int gmtio_prep_ogr_output (struct GMT_CTRL *GMT, struct GMT_DATASET *D int object_ID, col, stop, n_reg, item; uint64_t row, seg, seg1, seg2, k; - char buffer[GMT_BUFSIZ] = {""}, in_string[GMT_STR16] = {""}, out_string[GMT_STR16] = {""}; + char buffer[GMT_BUFSIZ] = {""}, in_string[GMT_VF_LEN] = {""}, out_string[GMT_VF_LEN] = {""}; struct GMT_DATATABLE *T = NULL; struct GMT_DATASET *M = NULL; struct GMT_DATASEGMENT *S = NULL; @@ -2768,7 +2768,7 @@ GMT_LOCAL int gmtio_prep_ogr_output (struct GMT_CTRL *GMT, struct GMT_DATASET *D struct GMT_DATASEGMENT_HIDDEN *SH = NULL, *SH1 = NULL, *SH2 = NULL; struct GMTAPI_DATA_OBJECT O; - /* When this functions is called we have already registered the output destination. This will normally + /* When this function is called we have already registered the output destination. This will normally * prevent us from register the data set separately in order to call GMT_gmtinfo. We must temporarily * unregister the output, do our thing, then reregister again. */ @@ -2786,27 +2786,22 @@ GMT_LOCAL int gmtio_prep_ogr_output (struct GMT_CTRL *GMT, struct GMT_DATASET *D /* Determine w/e/s/n via GMT_gmtinfo */ - /* Create option list, register D as input source via ref */ - if ((object_ID = GMT_Register_IO (GMT->parent, GMT_IS_DATASET, GMT_IS_REFERENCE, GMT_IS_POINT, GMT_IN, NULL, D)) == GMT_NOTSET) { - return (GMT->parent->error); - } - if (GMT_Encode_ID (GMT->parent, in_string, object_ID) != GMT_OK) { - return (GMT->parent->error); /* Make filename with embedded object ID */ + if (GMT_Open_VirtualFile (GMT->parent, GMT_IS_DATASET, GMT_IS_POINT, GMT_IN, D, in_string) == GMT_NOTSET) { + return (GMT->parent->error); } - if ((object_ID = GMT_Register_IO (GMT->parent, GMT_IS_DATASET, GMT_IS_DUPLICATE, GMT_IS_POINT, GMT_OUT, NULL, NULL)) == GMT_NOTSET) { - return (GMT->parent->error); - } - if (GMT_Encode_ID (GMT->parent, out_string, object_ID)) { - return (GMT->parent->error); /* Make filename with embedded object ID */ + if (GMT_Open_VirtualFile (GMT->parent, GMT_IS_DATASET, GMT_IS_POINT, GMT_OUT, NULL, out_string) == GMT_NOTSET) { + return (GMT->parent->error); } snprintf (buffer, GMT_BUFSIZ, "-C -fg -<%s ->%s --GMT_HISTORY=false", in_string, out_string); GMT_Report (GMT->parent, GMT_MSG_INFORMATION, "Calling gmtinfo with args %s\n", buffer); if (GMT_Call_Module (GMT->parent, "gmtinfo", GMT_MODULE_CMD, buffer) != GMT_OK) { /* Get the extent via gmtinfo */ return (GMT->parent->error); } - if ((M = GMT_Retrieve_Data (GMT->parent, object_ID)) == NULL) { + GMT_Close_VirtualFile (GMT->parent, in_string); + if ((M = GMT_Read_VirtualFile (GMT->parent, out_string)) == NULL) { return (GMT->parent->error); } + GMT_Close_VirtualFile (GMT->parent, out_string); /* Time to reregister the original destination */ @@ -7293,9 +7288,6 @@ int gmt_alloc_segment (struct GMT_CTRL *GMT, struct GMT_DATASEGMENT *S, uint64_t uint64_t col; if (first && n_columns) { /* First time we allocate the number of columns needed */ S->data = gmt_M_memory (GMT, NULL, n_columns, double *); -#ifdef GMT_BACKWARDS_API - S->coord = S->data; -#endif S->min = gmt_M_memory (GMT, NULL, n_columns, double); S->max = gmt_M_memory (GMT, NULL, n_columns, double); for (col = 0; col < n_columns; col++) { /* Initialize the min/max array */ diff --git a/src/gmt_plot.c b/src/gmt_plot.c index 8d91c6c705f..d3c2c03e94c 100644 --- a/src/gmt_plot.c +++ b/src/gmt_plot.c @@ -7361,7 +7361,7 @@ struct PSL_CTRL *gmt_plotinit (struct GMT_CTRL *GMT, struct GMT_OPTION *options) if (gmt_M_file_is_memory (&(Out->arg[k]))) { write_to_mem = 2; GMT->current.ps.memory = true; - strncpy (GMT->current.ps.memname, &(Out->arg[k]), GMT_STR16-1); + strncpy (GMT->current.ps.memname, &(Out->arg[k]), GMT_VF_LEN-1); } else { if ((fp = PSL_fopen (PSL, &(Out->arg[k]), mode[k])) == NULL) { /* Must open inside PSL DLL */ diff --git a/src/gmt_private.h b/src/gmt_private.h index 5a2308a8499..39e1d2b56ae 100644 --- a/src/gmt_private.h +++ b/src/gmt_private.h @@ -201,7 +201,9 @@ struct GMTAPI_CTRL { /* Macro to test if filename is a special name indicating memory location */ -#define gmt_M_file_is_memory(file) (file && !strncmp (file, "@GMTAPI@-", 9U)) +#define GMTAPI_PREFIX_LEN 9U /* The length of the unique leading prefix of virtual filenames */ +#define GMTAPI_OBJECT_ID_START 21U /* Start position of the encoded object ID in the virtual filename */ +#define gmt_M_file_is_memory(file) (file && !strncmp (file, "@GMTAPI@-", GMTAPI_PREFIX_LEN)) #ifdef __cplusplus } diff --git a/src/gmt_psl.h b/src/gmt_psl.h index c3a40082762..92ca97b88b5 100644 --- a/src/gmt_psl.h +++ b/src/gmt_psl.h @@ -68,7 +68,7 @@ struct GMT_PSL { bool logo_cmd; /* True if we need to use command line as logo label */ char map_logo_label[GMT_LEN256]; /* Label added to GMT time stamp generated by -U */ char title[GMT_LEN256]; /* Title of this plot */ - char memname[GMT_LEN16]; /* Memory object ID */ + char memname[GMT_VF_LEN]; /* Memory object ID */ char filename[GMT_LEN256]; /* Filename for hidden PS file */ char origin[2]; /* Defines the origin of the map offset ('r', 'a', 'c', or 'f') */ FILE *fp; /* Pointer to open but hidden PS file for RUNMODE = modern */ diff --git a/src/gmt_remote.c b/src/gmt_remote.c index e5203199bee..dbb896508d7 100644 --- a/src/gmt_remote.c +++ b/src/gmt_remote.c @@ -834,7 +834,7 @@ char *gmtlib_get_srtmlist (struct GMTAPI_CTRL *API, double wesn[], unsigned int uint64_t dim[GMT_DIM_SIZE] = {1, 1, 2, 2}; /* Just a single data table with one segment with two 2-column records */ uint64_t row, col, n = 0; double inc[2], lon, lat; - char output[GMT_STR16], input[GMT_STR16], cmd[GMT_LEN128] = {""}; + char output[GMT_VF_LEN], input[GMT_VF_LEN], cmd[GMT_LEN128] = {""}; struct GMT_GRID *G = NULL; struct GMT_DATASET *Din = NULL, *Dout = NULL; struct GMT_DATASEGMENT *S = NULL; @@ -927,7 +927,7 @@ struct GMT_GRID * gmtlib_assemble_srtm (struct GMTAPI_CTRL *API, double *region, char res = file[strlen(file)-8]; struct GMT_GRID *G = NULL; double *wesn = (region) ? region : API->GMT->common.R.wesn; /* Default to -R */ - char grid[GMT_STR16] = {""}, cmd[GMT_LEN256] = {""}, tag[4] = {"01s"}; + char grid[GMT_VF_LEN] = {""}, cmd[GMT_LEN256] = {""}, tag[4] = {"01s"}; struct GMT_GRID_HEADER_HIDDEN *HH = NULL; tag[1] = res; diff --git a/src/gmt_resources.h b/src/gmt_resources.h index e6fb3c8b1d4..591fa820a72 100644 --- a/src/gmt_resources.h +++ b/src/gmt_resources.h @@ -33,8 +33,6 @@ #ifndef GMT_RESOURCES_H #define GMT_RESOURCES_H -#define GMT_BACKWARDS_API /* Try to be backwards compatible with API naming for now */ - #ifdef DOUBLE_PRECISION_GRID /* Build GMT using double-precicion for grids. Untested and caveat emptor */ typedef double gmt_grdfloat; @@ -80,7 +78,7 @@ enum GMT_enum_api { GMT_USAGE = 0, /* Want to report full program usage message */ GMT_SYNOPSIS = 1, /* Just want the synopsis of usage */ GMT_PAD_DEFAULT = 2, /* Default is 2 rows and 2 cols for grid padding */ - GMT_STR16 = 16 /* Bytes needed to hold the @GMTAPI@-###### resource names */ + GMT_VF_LEN = 32 /* Bytes needed to hold the @GMTAPI@-* virtual file names */ }; /*! These data primitive identifiers are as follows: */ @@ -412,10 +410,6 @@ struct GMT_GRID_HEADER { char *ProjRefWKT; /* To store a referencing system string in WKT format */ int ProjRefEPSG; /* To store a referencing system EPSG code */ void *hidden; /* Lower-level information for GMT use only */ -#ifdef GMT_BACKWARDS_API - uint32_t nx; - uint32_t ny; -#endif }; /* grd is stored in rows going from west (xmin) to east (xmax) @@ -455,6 +449,7 @@ enum GMT_enum_geometry { GMT_IS_POINT = 1U, GMT_IS_LINE = 2U, GMT_IS_POLY = 4U, + GMT_IS_LP = 6U, /* Could be any one of LINE or POLY */ GMT_IS_PLP = 7U, /* Could be any one of POINT, LINE, POLY */ GMT_IS_SURFACE = 8U, GMT_IS_NONE = 16U, /* Non-geographical items like color palettes */ @@ -505,9 +500,6 @@ struct GMT_DATASEGMENT { /* For holding segment lines in memory */ char *header; /* Segment header (if applicable) */ char **text; /* text beyond the data */ void *hidden; /* Book-keeping variables "hidden" from the API */ -#ifdef GMT_BACKWARDS_API - double **coord; -#endif }; struct GMT_DATATABLE { /* To hold an array of line segment structures and header information in one container */ @@ -619,11 +611,6 @@ struct GMT_PALETTE { /* Holds all pen, color, and fill-related parameters */ double wrap_length; /* z-length of active CPT */ char **header; /* Array with all CPT header records, if any) */ /* Content not counted by sizeof (struct) */ void *hidden; /* Book-keeping variables "hidden" from the API */ -#ifdef GMT_BACKWARDS_API - struct GMT_LUT *range; - struct GMT_BFN *patch; - unsigned int cpt_flags; -#endif }; /*============================================================ */ @@ -643,10 +630,6 @@ struct GMT_IMAGE { /* Single container for a user image of data */ const char *color_interp; double *x, *y; /* Vector of coordinates */ void *hidden; /* Book-keeping variables "hidden" from the API */ -#ifdef GMT_BACKWARDS_API - int *ColorMap; - int nIndexedColors; -#endif }; /*==================================================================== */ @@ -779,7 +762,7 @@ struct GMT_RESOURCE { /* Information related to passing resources between GMT an enum GMT_enum_geometry geometry;/* One of the recognized GMT geometries */ enum GMT_enum_std direction; /* Either GMT_IN or GMT_OUT */ struct GMT_OPTION *option; /* Pointer to the corresponding module option */ - char name[GMT_STR16]; /* Virtual file name for resource */ + char name[GMT_VF_LEN]; /* Virtual file name for resource */ int pos; /* Corresponding index into external object in|out arrays */ int mode; /* Either primary (0) or secondary (1) resource */ void *object; /* Pointer to the actual GMT object */ diff --git a/src/gmt_support.c b/src/gmt_support.c index 15a3608d785..c7c45151fbf 100644 --- a/src/gmt_support.c +++ b/src/gmt_support.c @@ -4722,7 +4722,7 @@ GMT_LOCAL int support_init_custom_symbol (struct GMT_CTRL *GMT, char *in_name, s } for (bb = 0; bb < 2; bb++) { /* Check for both flavors of BoundingBox unless found */ if (!got_BB[bb] && (strstr (buffer, BB_string[bb]))) { - char c1[GMT_STR16] = {""}, c2[GMT_STR16] = {""}, c3[GMT_STR16] = {""}, c4[GMT_STR16] = {""}; + char c1[GMT_VF_LEN] = {""}, c2[GMT_VF_LEN] = {""}, c3[GMT_VF_LEN] = {""}, c4[GMT_VF_LEN] = {""}; sscanf (&buffer[strlen(BB_string[bb])], "%s %s %s %s", c1, c2, c3, c4); head->PS_BB[0] = atof (c1); head->PS_BB[2] = atof (c2); head->PS_BB[1] = atof (c3); head->PS_BB[3] = atof (c4); @@ -7112,9 +7112,6 @@ struct GMT_PALETTE * gmtlib_create_palette (struct GMT_CTRL *GMT, uint64_t n_col PH->alloc_mode = GMT_ALLOC_INTERNALLY; /* Memory can be freed by GMT. */ PH->alloc_level = GMT->hidden.func_level; /* Must be freed at this level. */ PH->id = GMT->parent->unique_var_ID++; /* Give unique identifier */ -#ifdef GMT_BACKWARDS_API - P->range = P->data; -#endif return (P); } @@ -8585,11 +8582,6 @@ void gmtlib_init_cpt (struct GMT_CTRL *GMT, struct GMT_PALETTE *P) { GMT->current.setting.color_model = (P->model | GMT_COLORINT); /* So color interpolation will happen in the color system */ /* We leave BNF as we got them from the external API */ -#ifdef GMT_BACKWARDS_API - P->range = P->data; - P->patch = P->bfn; - P->cpt_flags = P->mode; -#endif } /*! . */ diff --git a/src/gmtlogo.c b/src/gmtlogo.c index 40061cf1107..4505362ff0b 100644 --- a/src/gmtlogo.c +++ b/src/gmtlogo.c @@ -315,7 +315,7 @@ int GMT_gmtlogo (void *V_API, int mode, void *args) { double wesn[4] = {0.0, 0.0, 0.0, 0.0}; /* Dimensions in inches */ double scale, y, dim[2]; - char cmd[GMT_LEN256] = {""}, pars[GMT_LEN128] = {""}, file[GMT_STR16] = {""}; + char cmd[GMT_LEN256] = {""}, pars[GMT_LEN128] = {""}, file[GMT_VF_LEN] = {""}; struct GMT_FONT F; struct GMT_MATRIX *M = NULL; @@ -420,7 +420,7 @@ int GMT_gmtlogo (void *V_API, int mode, void *args) { /* Allocate a matrix container for holding the GMT-matrix coordinates */ par[0] = 2; par[1] = GMT_N_LETTERS; - if ((M = GMT_Create_Data (API, GMT_IS_DATASET|GMT_VIA_MATRIX, GMT_IS_POINT, GMT_CONTAINER_ONLY, par, NULL, NULL, 0, GMT_IS_ROW_FORMAT, NULL)) == NULL) + if ((M = GMT_Create_Data (API, GMT_IS_DATASET|GMT_VIA_MATRIX, GMT_IS_POLY, GMT_CONTAINER_ONLY, par, NULL, NULL, 0, GMT_IS_ROW_FORMAT, NULL)) == NULL) exit (EXIT_FAILURE); GMT_Put_Matrix (API, M, GMT_FLOAT, 0, gmt_letters); /* Hook in our static float matrix */ GMT_Open_VirtualFile (API, GMT_IS_DATASET|GMT_VIA_MATRIX, GMT_IS_POLY, GMT_IN, M, file); /* Open matrix for reading */ diff --git a/src/gmtmath.c b/src/gmtmath.c index b83b08623ac..291f0fbda26 100644 --- a/src/gmtmath.c +++ b/src/gmtmath.c @@ -6281,6 +6281,7 @@ int GMT_gmtmath (void *V_API, int mode, void *args) { if (op == GMTMATH_ARG_IS_BAD) Return (GMT_RUNTIME_ERROR); /* Horrible */ if (op != GMTMATH_ARG_IS_FILE) continue; /* Skip operators and numbers */ if (!got_t_from_file) { + /* Passing GMT_VIA_MODULE_INPUT since these are command line file arguments but processed here instead of by GMT_Init_IO */ if (!strcmp (opt->arg, "STDIN")) { /* Special stdin name. We store this input in a special struct since we may need it again and it can only be read once! */ if ((D_stdin = GMT_Read_Data (API, GMT_IS_DATASET|GMT_VIA_MODULE_INPUT, GMT_IS_STREAM, GMT_IS_NONE, GMT_READ_NORMAL, NULL, NULL, NULL)) == NULL) { Return (API->error); @@ -6611,6 +6612,7 @@ int GMT_gmtmath (void *V_API, int mode, void *args) { } else { if (gmt_M_is_verbose (GMT, GMT_MSG_INFORMATION)) GMT_Message (API, GMT_TIME_NONE, "%s ", opt->arg); + /* Passing GMT_VIA_MODULE_INPUT since these are command line file arguments but processed here instead of by GMT_Init_IO */ if ((F = GMT_Read_Data (API, GMT_IS_DATASET|GMT_VIA_MODULE_INPUT, GMT_IS_FILE, GMT_IS_NONE, GMT_READ_NORMAL, NULL, opt->arg, NULL)) == NULL) { GMT_Report (API, GMT_MSG_ERROR, "Failure while reading file %s\n", opt->arg); Return (API->error); diff --git a/src/grd2kml.c b/src/grd2kml.c index e75da08eaac..41c8cc6f5fb 100644 --- a/src/grd2kml.c +++ b/src/grd2kml.c @@ -394,7 +394,7 @@ int GMT_grd2kml (void *V_API, int mode, void *args) { char cmd[GMT_BUFSIZ] = {""}, level_dir[PATH_MAX] = {""}, Zgrid[PATH_MAX] = {""}, Igrid[PATH_MAX] = {""}; char W[GMT_LEN16] = {""}, E[GMT_LEN16] = {""}, S[GMT_LEN16] = {""}, N[GMT_LEN16] = {""}, file[PATH_MAX] = {""}; char DataGrid[PATH_MAX] = {""}, IntensGrid[PATH_MAX] = {""}, path[PATH_MAX] = {""}, im_arg[16] = {""}; - char region[GMT_LEN128] = {""}, ps_cmd[GMT_LEN128] = {""}, cfile[GMT_STR16] = {""}, K[4] = {""}, *cmd_args = NULL; + char region[GMT_LEN128] = {""}, ps_cmd[GMT_LEN128] = {""}, cfile[GMT_VF_LEN] = {""}, K[4] = {""}, *cmd_args = NULL; FILE *fp = NULL; struct GMT_DATASET *C = NULL; @@ -694,7 +694,7 @@ int GMT_grd2kml (void *V_API, int mode, void *args) { if (use_tile) { /* Found data inside this tile, make plot and rasterize */ /* Build the grdimage command to make the PostScript plot */ - char z_data[GMT_STR16] = {""}, psfile[PATH_MAX] = {""}; + char z_data[GMT_VF_LEN] = {""}, psfile[PATH_MAX] = {""}; /* Open the grid subset as a virtual file we can pass to grdimage */ if (GMT_Open_VirtualFile (API, GMT_IS_GRID, GMT_IS_SURFACE, GMT_IN, T, z_data) == GMT_NOTSET) { GMT_Report (API, GMT_MSG_ERROR, "Unable to open grid tile as virtual file!\n"); diff --git a/src/grdfill.c b/src/grdfill.c index 5e476d6571e..2d2aec4c261 100644 --- a/src/grdfill.c +++ b/src/grdfill.c @@ -203,7 +203,7 @@ GMT_LOCAL int do_constant_fill (struct GMT_GRID *G, unsigned int limit[], gmt_gr #if 1 GMT_LOCAL int do_splinefill (struct GMTAPI_CTRL *API, struct GMT_GRID *G, double wesn[], unsigned int limit[], unsigned int n_in_hole, double value) { /* Algorithm 2: Replace NaNs with a spline */ - char input[GMT_STR16] = {""}, output[GMT_STR16] = {""}, args[GMT_LEN256] = {""}, method[GMT_LEN32] = {""}; + char input[GMT_VF_LEN] = {""}, output[GMT_VF_LEN] = {""}, args[GMT_LEN256] = {""}, method[GMT_LEN32] = {""}; unsigned int row, col, row_hole, col_hole, mode, d_limit[4], n_constraints; uint64_t node, node_hole, k = 0, dim[GMT_DIM_SIZE] = {0, 0, 0, 0}; double *x = NULL, *y = NULL; diff --git a/src/grdfilter.c b/src/grdfilter.c index f1eee2b1fe0..d1ce6a4ca96 100644 --- a/src/grdfilter.c +++ b/src/grdfilter.c @@ -1324,7 +1324,7 @@ int GMT_grdfilter (void *V_API, int mode, void *args) { if (Ctrl->F.highpass) { if (GMT->common.R.active[RSET] || GMT->common.R.active[ISET] || GMT->common.R.active[GSET]) { /* Must resample result so grids are coregistered */ - char in_string[GMT_STR16], out_string[GMT_STR16], cmd[GMT_LEN256]; + char in_string[GMT_VF_LEN], out_string[GMT_VF_LEN], cmd[GMT_LEN256]; static char *V_level = "qntcvld"; /* Here we low-passed filtered onto a coarse grid but to get high-pass we must sample the low-pass result at the original resolution */ diff --git a/src/grdfilter_mt.c b/src/grdfilter_mt.c index f1d13fff987..7c4eb50fa54 100644 --- a/src/grdfilter_mt.c +++ b/src/grdfilter_mt.c @@ -1009,7 +1009,7 @@ int GMT_grdfilter_mt (void *V_API, int mode, void *args) if (Ctrl->F.highpass) { if (GMT->common.R.active[RSET] || GMT->common.R.active[ISET] || GMT->common.R.active[GSET]) { /* Must resample result so grids are coregistered */ - char in_string[GMT_STR16], out_string[GMT_STR16], cmd[GMT_LEN256]; + char in_string[GMT_VF_LEN], out_string[GMT_VF_LEN], cmd[GMT_LEN256]; /* Here we low-passed filtered onto a coarse grid but to get high-pass we must sample the low-pass result at the original resolution */ /* Create a virtual file for the low-pass filtered grid */ if (GMT_Open_VirtualFile (API, GMT_IS_GRID, GMT_IS_SURFACE, GMT_IN, Gout, in_string) == GMT_NOTSET) { diff --git a/src/grdimage.c b/src/grdimage.c index 751d7ae7f90..85841b0a3f0 100644 --- a/src/grdimage.c +++ b/src/grdimage.c @@ -900,7 +900,7 @@ int GMT_grdimage (void *V_API, int mode, void *args) { if (Ctrl->D.active && (I->header->n_columns != Intens_orig->header->n_columns || I->header->n_rows != Intens_orig->header->n_rows)) { /* Resize illumination grid to match the dimensions of the image */ - char in_string[GMT_STR16] = {""}, out_string[GMT_STR16] = {""}; + char in_string[GMT_VF_LEN] = {""}, out_string[GMT_VF_LEN] = {""}; /* Associate the intensity grid with an open virtual file - in_string will then hold the name of this input "file" */ GMT_Open_VirtualFile (API, GMT_IS_GRID, GMT_IS_SURFACE, GMT_IN, Intens_orig, in_string); /* Create a virtual file to hold the resampled grid - out_string then holds the name of this output "file" */ diff --git a/src/grdinterpolate.c b/src/grdinterpolate.c index e00043ba990..3eb70d2c487 100644 --- a/src/grdinterpolate.c +++ b/src/grdinterpolate.c @@ -497,7 +497,7 @@ int GMT_grdinterpolate (void *V_API, int mode, void *args) { unsigned int io_mode = GMT_WRITE_NORMAL; uint64_t seg, row, rec, col; uint64_t dim[4] = {1, 1, 1, 2}; /* Dataset dimension for one point */ - char i_file[GMT_STR16] = {""}, o_file[GMT_STR16] = {""}, grid[GMT_LEN128] = {""}, header[GMT_LEN256] = {""}, cmd[GMT_LEN128] = {""}; + char i_file[GMT_VF_LEN] = {""}, o_file[GMT_VF_LEN] = {""}, grid[GMT_LEN128] = {""}, header[GMT_LEN256] = {""}, cmd[GMT_LEN128] = {""}; struct GMT_DATASET *D = NULL; struct GMT_DATASEGMENT *Si = NULL, *So = NULL; diff --git a/src/grdmath.c b/src/grdmath.c index 6d47510b3bd..c3c87fd801f 100644 --- a/src/grdmath.c +++ b/src/grdmath.c @@ -2628,7 +2628,8 @@ GMT_LOCAL void grd_INSIDE (struct GMT_CTRL *GMT, struct GRDMATH_INFO *info, stru return; } gmt_skip_xy_duplicates (GMT, true); /* Avoid repeating x/y points in polygons */ - if ((D = GMT_Read_Data (GMT->parent, GMT_IS_DATASET, GMT_IS_FILE, GMT_IS_POLY, GMT_READ_NORMAL|GMT_IO_RESET, NULL, info->ASCII_file, NULL)) == NULL) { + /* Passing GMT_VIA_MODULE_INPUT since these are command line file arguments but processed here instead of by GMT_Init_IO */ + if ((D = GMT_Read_Data (GMT->parent, GMT_IS_DATASET|GMT_VIA_MODULE_INPUT, GMT_IS_FILE, GMT_IS_POLY, GMT_READ_NORMAL|GMT_IO_RESET, NULL, info->ASCII_file, NULL)) == NULL) { GMT_Report (GMT->parent, GMT_MSG_ERROR, "Failure in operator INSIDE reading file %s!\n", info->ASCII_file); info->error = GMT->parent->error; return; @@ -2883,7 +2884,8 @@ GMT_LOCAL struct GMT_DATASET *ASCII_read (struct GMT_CTRL *GMT, struct GRDMATH_I info->error = GMT->parent->error; return NULL; } - if ((D = GMT_Read_Data (GMT->parent, GMT_IS_DATASET, GMT_IS_FILE, geometry, GMT_READ_NORMAL|GMT_IO_RESET, NULL, info->ASCII_file, NULL)) == NULL) { + /* Passing GMT_VIA_MODULE_INPUT since these are command line file arguments but processed here instead of by GMT_Init_IO */ + if ((D = GMT_Read_Data (GMT->parent, GMT_IS_DATASET|GMT_VIA_MODULE_INPUT, GMT_IS_FILE, geometry, GMT_READ_NORMAL|GMT_IO_RESET, NULL, info->ASCII_file, NULL)) == NULL) { GMT_Report (GMT->parent, GMT_MSG_ERROR, "Failure in operator %s reading file %s!\n", op, info->ASCII_file); info->error = GMT->parent->error; return NULL; @@ -6247,7 +6249,8 @@ int GMT_grdmath (void *V_API, int mode, void *args) { if (status != GRDMATH_ARG_IS_FILE) continue; /* Skip operators and numbers */ in_file = opt->arg; /* Read but request IO reset since the file (which may be a memory reference) will be read again later */ - if ((G_in = GMT_Read_Data (API, GMT_IS_GRID, GMT_IS_FILE, GMT_IS_SURFACE, GMT_CONTAINER_ONLY | GMT_IO_RESET, NULL, in_file, NULL)) == NULL) { /* Get header only */ + /* Passing GMT_VIA_MODULE_INPUT since these are command line file arguments but processed here instead of by GMT_Init_IO */ + if ((G_in = GMT_Read_Data (API, GMT_IS_GRID|GMT_VIA_MODULE_INPUT, GMT_IS_FILE, GMT_IS_SURFACE, GMT_CONTAINER_ONLY | GMT_IO_RESET, NULL, in_file, NULL)) == NULL) { /* Get header only */ Return (API->error); } } @@ -6268,7 +6271,8 @@ int GMT_grdmath (void *V_API, int mode, void *args) { } if (subset) { /* Gave -R and files: Read the subset to set the header properly */ gmt_M_memcpy (wesn, GMT->common.R.wesn, 4, double); - if (GMT_Read_Data (API, GMT_IS_GRID, GMT_IS_FILE, GMT_IS_SURFACE, GMT_DATA_ONLY, wesn, in_file, G_in) == NULL) { /* Get subset only */ + /* Passing GMT_VIA_MODULE_INPUT since these are command line file arguments but processed here instead of by GMT_Init_IO */ + if (GMT_Read_Data (API, GMT_IS_GRID|GMT_VIA_MODULE_INPUT, GMT_IS_FILE, GMT_IS_SURFACE, GMT_DATA_ONLY, wesn, in_file, G_in) == NULL) { /* Get subset only */ Return (API->error); } } @@ -6559,7 +6563,8 @@ int GMT_grdmath (void *V_API, int mode, void *args) { } else if (op == GRDMATH_ARG_IS_FILE) { /* Filename given */ if (gmt_M_is_verbose (GMT, GMT_MSG_INFORMATION)) GMT_Message (API, GMT_TIME_NONE, "%s ", opt->arg); - if ((stack[nstack]->G = GMT_Read_Data (API, GMT_IS_GRID, GMT_IS_FILE, GMT_IS_SURFACE, GMT_CONTAINER_ONLY, wesn, opt->arg, NULL)) == NULL) { /* Get header only */ + /* Passing GMT_VIA_MODULE_INPUT since these are command line file arguments but processed here instead of by GMT_Init_IO */ + if ((stack[nstack]->G = GMT_Read_Data (API, GMT_IS_GRID|GMT_VIA_MODULE_INPUT, GMT_IS_FILE, GMT_IS_SURFACE, GMT_CONTAINER_ONLY, wesn, opt->arg, NULL)) == NULL) { /* Get header only */ Return (API->error); } if (!subset && !gmt_M_grd_same_shape (GMT, stack[nstack]->G, info.G)) { @@ -6571,7 +6576,8 @@ int GMT_grdmath (void *V_API, int mode, void *args) { GMT_Report (API, GMT_MSG_ERROR, "grid files do not cover the same area!\n"); Return (GMT_RUNTIME_ERROR); } - if (GMT_Read_Data (API, GMT_IS_GRID, GMT_IS_FILE, GMT_IS_SURFACE, GMT_DATA_ONLY, wesn, opt->arg, stack[nstack]->G) == NULL) { /* Get data */ + /* Passing GMT_VIA_MODULE_INPUT since these are command line file arguments but processed here instead of by GMT_Init_IO */ + if (GMT_Read_Data (API, GMT_IS_GRID|GMT_VIA_MODULE_INPUT, GMT_IS_FILE, GMT_IS_SURFACE, GMT_DATA_ONLY, wesn, opt->arg, stack[nstack]->G) == NULL) { /* Get data */ Return (API->error); } } diff --git a/src/img/img2grd.c b/src/img/img2grd.c index c7d9e72656f..e5c354e01be 100644 --- a/src/img/img2grd.c +++ b/src/img/img2grd.c @@ -407,7 +407,7 @@ int GMT_img2grd (void *V_API, int mode, void *args) { int16_t *row = NULL; uint16_t *u2 = NULL; - char infile[PATH_MAX] = {""}, cmd[GMT_BUFSIZ] = {""}, input[GMT_STR16] = {""}, output[PATH_MAX] = {""}; + char infile[PATH_MAX] = {""}, cmd[GMT_BUFSIZ] = {""}, input[GMT_VF_LEN] = {""}, output[PATH_MAX] = {""}; char z_units[GMT_GRID_UNIT_LEN80] = {""}, exact_R[GMT_LEN256] = {""}; FILE *fp = NULL; diff --git a/src/movie.c b/src/movie.c index 0b797b8a598..6f02f31c8f3 100644 --- a/src/movie.c +++ b/src/movie.c @@ -1512,7 +1512,7 @@ int GMT_movie (void *V_API, int mode, void *args) { has_text = (D && D->table[0]->segment[0]->text); /* Trailing text present */ } else if (gmt_count_char (GMT, Ctrl->T.file, '/') == 2) { /* Give a vector specification -Tmin/max/inc, call gmtmath */ - char output[GMT_STR16] = {""}, cmd[GMT_LEN128] = {""}; + char output[GMT_VF_LEN] = {""}, cmd[GMT_LEN128] = {""}; unsigned int V = GMT->current.setting.verbose; if (GMT_Open_VirtualFile (API, GMT_IS_DATASET, GMT_IS_NONE, GMT_OUT, NULL, output) == GMT_NOTSET) { Return (API->error); diff --git a/src/pslegend.c b/src/pslegend.c index 430c2376c55..f0632470fe0 100644 --- a/src/pslegend.c +++ b/src/pslegend.c @@ -457,7 +457,7 @@ int GMT_pslegend (void *V_API, int mode, void *args) { char txtcolor[GMT_LEN256] = {""}, def_txtcolor[GMT_LEN256] = {""}, buffer[GMT_BUFSIZ] = {""}, A[GMT_LEN32] = {""}, legend_file[PATH_MAX] = {""}; char path[PATH_MAX] = {""}, B[GMT_LEN32] = {""}, C[GMT_LEN32] = {""}, p[GMT_LEN256] = {""}; char *plot_points[2] = {"psxy", "plot"}, *plot_text[2] = {"pstext", "text"}; - char *line = NULL, string[GMT_STR16] = {""}, *c = NULL, *fill[PSLEGEND_MAX_COLS]; + char *line = NULL, string[GMT_VF_LEN] = {""}, *c = NULL, *fill[PSLEGEND_MAX_COLS]; #ifdef DEBUG char *dname[N_DAT] = {"symbol", "front", "qline", "textline", "partext"}; #endif diff --git a/src/psternary.c b/src/psternary.c index c7a8df0eb61..a2873a3ae4b 100644 --- a/src/psternary.c +++ b/src/psternary.c @@ -534,7 +534,7 @@ int GMT_psternary (void *V_API, int mode, void *args) { } } if (Ctrl->S.active) { /* Plot symbols */ - char vfile[GMT_STR16] = {""}; + char vfile[GMT_VF_LEN] = {""}; if (GMT_Open_VirtualFile (API, GMT_IS_DATASET, GMT_IS_POINT, GMT_IN, D, vfile) == GMT_NOTSET) { GMT_Report (API, GMT_MSG_ERROR, "Unable to create a virtual data set\n"); Return (API->error); diff --git a/src/psxy.c b/src/psxy.c index fb6199cef6b..e855e9a1488 100644 --- a/src/psxy.c +++ b/src/psxy.c @@ -284,7 +284,7 @@ GMT_LOCAL int plot_decorations (struct GMT_CTRL *GMT, struct GMT_DATASET *D) { /* Accept the dataset D with records of {x, y, size, angle, symbol} and plot rotated symbols at those locations. * Note: The x,y are projected coordinates in inches, hence our -R -J choice below. */ size_t len; - char string[GMT_LEN16] = {""}, buffer[GMT_BUFSIZ] = {""}, tmp_file[PATH_MAX] = {""}; + char string[GMT_VF_LEN] = {""}, buffer[GMT_BUFSIZ] = {""}, tmp_file[PATH_MAX] = {""}; FILE *fp = NULL; gmt_set_dataset_minmax (GMT, D); /* Determine min/max for each column and add up total records */ if (D->n_records == 0) /* No symbols to plot */ diff --git a/src/subplot.c b/src/subplot.c index 4f7e81e2268..ac6974e5434 100644 --- a/src/subplot.c +++ b/src/subplot.c @@ -715,7 +715,7 @@ int GMT_subplot (void *V_API, int mode, void *args) { double x, y, width = 0.0, height = 0.0, tick_height, annot_height, label_height, title_height, y_header_off = 0.0; double *cx = NULL, *cy = NULL, *px = NULL, *py = NULL, y_heading, fluff[2] = {0.0, 0.0}, off[2] = {0.0, 0.0}, GMT_LETTER_HEIGHT = 0.736; char **Bx = NULL, **By = NULL, *cmd = NULL, axes[3] = {""}, Bopt[GMT_LEN256] = {""}; - char vfile[GMT_STR16] = {""}, xymode = 'r'; + char vfile[GMT_VF_LEN] = {""}, xymode = 'r'; bool add_annot, no_frame = false; FILE *fp = NULL; @@ -1248,7 +1248,7 @@ int GMT_subplot (void *V_API, int mode, void *args) { } else { /* SUBPLOT_END */ int k, id; - char *wmode[2] = {"w","a"}, vfile[GMT_STR16] = {""}, Rtxt[GMT_LEN64] = {""}, tag[GMT_LEN16] = {""}; + char *wmode[2] = {"w","a"}, vfile[GMT_VF_LEN] = {""}, Rtxt[GMT_LEN64] = {""}, tag[GMT_LEN16] = {""}; char legend_justification[4] = {""}, Jstr[3] = {"J"}; double legend_width = 0.0, legend_scale = 1.0; FILE *fp = NULL; diff --git a/src/surface.c b/src/surface.c index 25f5fdb6265..99d73ba78e7 100644 --- a/src/surface.c +++ b/src/surface.c @@ -2077,7 +2077,7 @@ int GMT_surface (void *V_API, int mode, void *args) { } if (Ctrl->M.active) { /* Want to mask the grid first */ - char input[GMT_STR16] = {""}, mask[GMT_STR16] = {""}, cmd[GMT_LEN256] = {""}; + char input[GMT_VF_LEN] = {""}, mask[GMT_VF_LEN] = {""}, cmd[GMT_LEN256] = {""}; static char *V_level = "qntcvld"; struct GMT_GRID *Gmask = NULL; struct GMT_VECTOR *V = NULL; diff --git a/src/surface_experimental.c b/src/surface_experimental.c index 5eb58ba5be2..313efc45fff 100644 --- a/src/surface_experimental.c +++ b/src/surface_experimental.c @@ -2430,7 +2430,7 @@ int GMT_surface_mt (void *V_API, int mode, void *args) { } if (Ctrl->M.active) { /* Want to mask the grid first */ - char input[GMT_STR16] = {""}, mask[GMT_STR16] = {""}, cmd[GMT_LEN256] = {""}; + char input[GMT_VF_LEN] = {""}, mask[GMT_VF_LEN] = {""}, cmd[GMT_LEN256] = {""}; static char *V_level = "qntcvld"; struct GMT_GRID *Gmask = NULL; struct GMT_VECTOR *V = NULL; diff --git a/src/test_JL.c b/src/test_JL.c index 21324ee7af1..63f174c70cb 100644 --- a/src/test_JL.c +++ b/src/test_JL.c @@ -7,8 +7,8 @@ int main () { void *API = NULL; /* The API control structure */ struct GMT_VECTOR *V[2] = {NULL, NULL}; /* Structure to hold input/output dataset as vectors */ struct GMT_MATRIX *M[2] = {NULL, NULL}; /* Structure to hold input/output dataset as matrix */ - char input[GMT_STR16] = {""}; /* String to hold virtual input filename */ - char output[GMT_STR16] = {""}; /* String to hold virtual output filename */ + char input[GMT_VF_LEN] = {""}; /* String to hold virtual input filename */ + char output[GMT_VF_LEN] = {""}; /* String to hold virtual output filename */ char args[128] = {""}; /* String to hold module command arguments */ /* Initialize the GMT session */ diff --git a/src/test_walter.c b/src/test_walter.c index da788d1a19a..97172690d08 100644 --- a/src/test_walter.c +++ b/src/test_walter.c @@ -19,7 +19,7 @@ int main (int argc, char **argv) { int *z = NULL; /* Just do demonstrate mixed types we use an integer user z array */ struct GMT_GRID *G_in = NULL; struct GMT_VECTOR *V_in = NULL, *V_out = NULL; - char grid[GMT_STR16] = {""}, input[GMT_STR16] = {""}, output[GMT_STR16] = {""}; + char grid[GMT_VF_LEN] = {""}, input[GMT_VF_LEN] = {""}, output[GMT_VF_LEN] = {""}; char args[256] = {""}; (void)(argc); /* Initialize a normal GMT session with 2 rows/cols for grid BC padding */ diff --git a/src/testapi.c b/src/testapi.c deleted file mode 100644 index 61dca7473de..00000000000 --- a/src/testapi.c +++ /dev/null @@ -1,381 +0,0 @@ -/*-------------------------------------------------------------------- - * - * Copyright (c) 1991-2020 by the GMT Team (https://www.generic-mapping-tools.org/team.html) - * See LICENSE.TXT file for copying and redistribution conditions. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; version 3 or any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * Contact info: www.generic-mapping-tools.org - *--------------------------------------------------------------------*/ -/* - * Author: Paul Wessel - * Date: 1-JAN-2010 - * Version: 6 API - * - * Brief synopsis: testapi allows us to test the API i/o functions. - * - */ - -#include "gmt_dev.h" - -#define THIS_MODULE_OPTIONS "->Vh" - -/* Control structure for testapi */ - -struct TESTAPI_CTRL { - struct T { /* -T sets data type */ - bool active; - int mode; - } T; - struct I { /* -I sets input method */ - bool active; - unsigned int mode; - } I; - struct W { /* -W sets output method */ - bool active; - unsigned int mode; - } W; -}; - -GMT_LOCAL void *New_Ctrl (struct GMT_CTRL *GMT) { /* Allocate and initialize a new control structure */ - struct TESTAPI_CTRL *C; - - C = gmt_M_memory (GMT, NULL, 1, struct TESTAPI_CTRL); - - /* Initialize values whose defaults are not 0/false/NULL */ - - return (C); -} - -GMT_LOCAL void Free_Ctrl (struct GMT_CTRL *GMT, struct TESTAPI_CTRL *C) { /* Deallocate control structure */ - if (!C) return; - gmt_M_free (GMT, C); -} - -GMT_LOCAL int usage (struct GMTAPI_CTRL *API, int level) { - GMT_Message (API, GMT_TIME_NONE, "testapi - test API i/o methods for any data type\n\n"); - GMT_Message (API, GMT_TIME_NONE, "usage: testapi -If|s|d|c|r -Td|t|g|c|i|p|m|v -Wf|s|d|c|r|m|v [%s] [%s]\n", GMT_V_OPT, GMT_h_OPT); - - if (level == GMT_SYNOPSIS) return (GMT_MODULE_SYNOPSIS); - - GMT_Message (API, GMT_TIME_NONE, "\t-I Specify input resource. Choose among:\n"); - GMT_Message (API, GMT_TIME_NONE, "\t f : File\n"); - GMT_Message (API, GMT_TIME_NONE, "\t s : Stream\n"); - GMT_Message (API, GMT_TIME_NONE, "\t d : File descriptor\n"); - GMT_Message (API, GMT_TIME_NONE, "\t c : Memory Copy\n"); - GMT_Message (API, GMT_TIME_NONE, "\t r : Memory Reference\n"); - GMT_Message (API, GMT_TIME_NONE, "\t-T Specify data type. Choose among:\n"); - GMT_Message (API, GMT_TIME_NONE, "\t d : Dataset\n"); - GMT_Message (API, GMT_TIME_NONE, "\t g : Grid\n"); - GMT_Message (API, GMT_TIME_NONE, "\t c : CPT\n"); - GMT_Message (API, GMT_TIME_NONE, "\t i : Image\n"); - GMT_Message (API, GMT_TIME_NONE, "\t p : PostScript\n"); - GMT_Message (API, GMT_TIME_NONE, "\t t : Textset\n"); - GMT_Message (API, GMT_TIME_NONE, "\t v : Vector\n"); - GMT_Message (API, GMT_TIME_NONE, "\t m : Matrix\n"); - GMT_Message (API, GMT_TIME_NONE, "\t-W Specify write destination. Choose among:\n"); - GMT_Message (API, GMT_TIME_NONE, "\t f : File\n"); - GMT_Message (API, GMT_TIME_NONE, "\t s : Stream\n"); - GMT_Message (API, GMT_TIME_NONE, "\t d : File descriptor\n"); - GMT_Message (API, GMT_TIME_NONE, "\t c : Memory Copy\n"); - GMT_Message (API, GMT_TIME_NONE, "\t r : Memory Reference\n"); - GMT_Message (API, GMT_TIME_NONE, "\n\tOPTIONS:\n"); - GMT_Option (API, "V,h,."); - - return (EXIT_FAILURE); -} - -GMT_LOCAL int parse (struct GMT_CTRL *GMT, struct TESTAPI_CTRL *Ctrl, struct GMT_OPTION *options) { - - /* This parses the options provided to grdcut and sets parameters in CTRL. - * Any GMT common options will override values set previously by other commands. - * It also replaces any file names specified as input or output with the data ID - * returned when registering these sources/destinations with the API. - */ - - unsigned int n_errors = 0; - struct GMT_OPTION *opt = NULL; - - for (opt = options; opt; opt = opt->next) { /* Process all the options given */ - - switch (opt->option) { - /* Processes program-specific parameters */ - - case 'I': /* Input */ - Ctrl->I.active = true; - switch (opt->arg[0]) { - case 'f': Ctrl->I.mode = GMT_IS_FILE; break; - case 's': Ctrl->I.mode = GMT_IS_STREAM; break; - case 'd': Ctrl->I.mode = GMT_IS_FDESC; break; - case 'c': Ctrl->I.mode = GMT_IS_DUPLICATE; break; - case 'r': Ctrl->I.mode = GMT_IS_REFERENCE; break; - } - break; - case 'T': /* Type */ - Ctrl->T.active = true; - switch (opt->arg[0]) { - case 'd': Ctrl->T.mode = GMT_IS_DATASET; break; - case 'g': Ctrl->T.mode = GMT_IS_GRID; break; - case 'c': Ctrl->T.mode = GMT_IS_PALETTE; break; - case 'i': Ctrl->T.mode = GMT_IS_IMAGE; break; - case 'p': Ctrl->T.mode = GMT_IS_POSTSCRIPT; break; - case 'v': Ctrl->T.mode = GMT_IS_VECTOR; break; - case 'm': Ctrl->T.mode = GMT_IS_MATRIX; break; - } - break; - - case 'W': /* Output */ - Ctrl->W.active = true; - switch (opt->arg[0]) { - case 'f': Ctrl->W.mode = GMT_IS_FILE; break; - case 's': Ctrl->W.mode = GMT_IS_STREAM; break; - case 'd': Ctrl->W.mode = GMT_IS_FDESC; break; - case 'c': Ctrl->W.mode = GMT_IS_DUPLICATE; break; - case 'r': Ctrl->W.mode = GMT_IS_REFERENCE; break; - } - break; - default: /* Report bad options */ - n_errors += gmt_default_error (GMT, opt->option); - break; - } - } - - return (n_errors ? GMT_PARSE_ERROR : GMT_NOERROR); -} - -#define bailout(code) {gmt_M_free_options (mode); return (code);} -#define Return(code) {Free_Ctrl (GMT, Ctrl); bailout (code);} - -int GMT_testapi (void *V_API, int mode, void *args) { - int error = 0, in_ID, out_ID; - int geometry[] = {GMT_IS_POINT, GMT_IS_SURFACE, GMT_IS_SURFACE, GMT_IS_NONE, GMT_IS_NONE, GMT_IS_NONE, GMT_IS_SURFACE, GMT_IS_POINT, GMT_IS_NONE}; - - char *ikind[] = {"DATASET", "GRID", "IMAGE", "PALETTE", "POSTSCRIPT", "TEXTSET", "MATRIX", "VECTOR", "COORD"}; - char *method[] = {"FILE", "STREAM", "FDESC", "COPY", "REF"}; - char *ifile[] = {"dtesti.txt", "gtesti.nc", "itesti.jpg", "ctesti.cpt", "ptesti.ps", "ttesti.txt", "mtesti.bin", "vtesti.bin", "-"}; - char *ofile[] = {"dtesto.txt", "gtesto.nc", "itesto.jpg", "ctesto.cpt", "ptesto.ps", "ttesto.txt", "mtesto.bin", "vtesto.bin", "-"}; - char string[GMT_STR16]; - - FILE *fp = NULL; - int *fdp = NULL, fd = 0; - - struct TESTAPI_CTRL *Ctrl = NULL; - struct GMT_MATRIX *M = NULL; - struct GMT_VECTOR *V = NULL; - void *In = NULL, *Out = NULL, *Intmp = NULL; - struct GMT_CTRL *GMT = NULL; - struct GMT_OPTION *options = NULL; - struct GMTAPI_CTRL *API = gmt_get_api_ptr (V_API); /* Cast from void to GMTAPI_CTRL pointer */ - - /*----------------------- Standard module initialization and parsing ----------------------*/ - - if (API == NULL) return (GMT_NOT_A_SESSION); - options = GMT_Create_Options (API, mode, args); if (API->error) return (API->error); /* Set or get option list */ - - if ((error = gmt_report_usage (API, options, 0, usage)) != GMT_NOERROR) bailout (error); /* Give usage if requested */ - - /* Parse the command-line arguments */ - -#if 0 - GMT = gmt_init_module (API, NULL, THIS_MODULE_CLASSIC_NAME, &GMT_cpy); /* Save current state */ -#endif - GMT = API->GMT; - if (GMT_Parse_Common (API, THIS_MODULE_OPTIONS, options)) Return (API->error); - Ctrl = New_Ctrl (GMT); /* Allocate and initialize a new control structure */ - if ((error = parse (GMT, Ctrl, options)) != 0) Return (error); - - /*---------------------------- This is the testapi main code ----------------------------*/ - - /* Get input and register it */ - - GMT_Report (API, GMT_MSG_INFORMATION, "Read %s %s with method %s and write to %s with method %s\n", ikind[Ctrl->T.mode], ifile[Ctrl->T.mode], method[Ctrl->I.mode], ofile[Ctrl->T.mode], method[Ctrl->W.mode]); - - if (GMT_Init_IO (API, Ctrl->T.mode, geometry[Ctrl->T.mode], GMT_IN, GMT_ADD_FILES_IF_NONE, 0, options) != GMT_NOERROR) { /* Registers default input destination, unless already set */ - Return (API->error); - } - - if (Ctrl->T.mode == GMT_IS_IMAGE) gmt_set_pad (GMT, 0U); /* Temporary turn off padding (and thus BC setting) since we will use image exactly as is */ - switch (Ctrl->I.mode) { - case GMT_IS_FILE: /* Pass filename */ - if ((in_ID = GMT_Register_IO (API, Ctrl->T.mode, Ctrl->I.mode, geometry[Ctrl->T.mode], GMT_IN, NULL, ifile[Ctrl->T.mode])) == GMT_NOTSET) { - Return (API->error); - } - break; - case GMT_IS_STREAM: - switch (Ctrl->T.mode) { /* Can only do d, c, p, m, v */ - case GMT_IS_DATASET: case GMT_IS_PALETTE: case GMT_IS_POSTSCRIPT: case GMT_IS_MATRIX: case GMT_IS_VECTOR: - fp = gmt_fopen (GMT, ifile[Ctrl->T.mode], "r"); - if ((in_ID = GMT_Register_IO (API, Ctrl->T.mode, Ctrl->I.mode, geometry[Ctrl->T.mode], GMT_IN, NULL, fp)) == GMT_NOTSET) { - Return (API->error); - } - break; - default: - GMT_Report (API, GMT_MSG_ERROR, "GMT_IS_STREAM only allows d, t, c, p, m, v!\n"); - Return (GMT_NOT_A_VALID_FAMILY); - break; - } - break; - case GMT_IS_FDESC: - switch (Ctrl->T.mode) { /* Can only do d, c, p, m, v */ - case GMT_IS_DATASET: case GMT_IS_PALETTE: case GMT_IS_POSTSCRIPT: case GMT_IS_MATRIX: case GMT_IS_VECTOR: - fd = open (ifile[Ctrl->T.mode], O_RDONLY); - fdp = &fd; - if ((in_ID = GMT_Register_IO (API, Ctrl->T.mode, Ctrl->I.mode, geometry[Ctrl->T.mode], GMT_IN, NULL, fdp)) == GMT_NOTSET) { - Return (API->error); - } - break; - default: - GMT_Report (API, GMT_MSG_ERROR, "GMT_IS_FDESC only allows d, t, c, p, m, v!\n"); - Return (GMT_NOT_A_VALID_FAMILY); - break; - } - break; - case GMT_IS_DUPLICATE: case GMT_IS_REFERENCE: - if ((Intmp = GMT_Read_Data (API, Ctrl->T.mode, GMT_IS_FILE, geometry[Ctrl->T.mode], GMT_READ_NORMAL, NULL, ifile[Ctrl->T.mode], NULL)) == NULL) { - Return (API->error); - } - if ((in_ID = GMT_Register_IO (API, Ctrl->T.mode, Ctrl->I.mode, geometry[Ctrl->T.mode], GMT_IN, NULL, Intmp)) == GMT_NOTSET) { - Return (API->error); - } - break; - default: - GMT_Report (API, GMT_MSG_ERROR, "Bad Input mode\n"); - Return (GMT_NOT_A_VALID_METHOD); - break; - } - - /* Now get the data from the registered source */ - - if ((In = GMT_Get_Data (API, in_ID, 0, NULL)) == NULL) { - Return (API->error); - } - - if (Ctrl->T.mode == GMT_IS_IMAGE) { /* Since writing is not supported we just make a plot via GMT_psimage */ - char buffer[GMT_BUFSIZ]; - - gmt_set_pad(GMT, API->pad); /* Reset to GMT default */ - if ((in_ID = GMT_Register_IO (API, Ctrl->T.mode, GMT_IS_REFERENCE, geometry[Ctrl->T.mode], GMT_IN, NULL, In)) == GMT_NOTSET) { - Return (API->error); - } - if (GMT_Encode_ID (API, string, in_ID) != GMT_NOERROR) { - Return (API->error); /* Make filename with embedded object ID */ - } - sprintf (buffer, "%s -Dx0/0+w6i -P -F+p0.25p+c0 --PS_MEDIA=letter --PS_CHAR_ENCODING=Standard+", string); - if (GMT_Call_Module (API, "psimage", GMT_MODULE_CMD, buffer) != GMT_NOERROR) { /* Plot the image */ - Return (API->error); - } - if (GMT_Destroy_Data (API, &Intmp) != GMT_NOERROR) { - Return (API->error); - } - Return (GMT_NOERROR); - } - - /* Get output and register it */ - - switch (Ctrl->W.mode) { - case GMT_IS_FILE: /* Pass filename */ - if ((out_ID = GMT_Register_IO (API, Ctrl->T.mode, Ctrl->W.mode, geometry[Ctrl->T.mode], GMT_OUT, NULL, ofile[Ctrl->T.mode])) == GMT_NOTSET) { - Return (API->error); - } - break; - case GMT_IS_STREAM: - switch (Ctrl->T.mode) { /* Can only do d, c, p, m, v */ - case GMT_IS_DATASET: case GMT_IS_PALETTE: case GMT_IS_POSTSCRIPT: case GMT_IS_MATRIX: case GMT_IS_VECTOR: - fp = gmt_fopen (GMT, ofile[Ctrl->T.mode], "w"); - if ((out_ID = GMT_Register_IO (API, Ctrl->T.mode, Ctrl->W.mode, geometry[Ctrl->T.mode], GMT_OUT, NULL, fp)) == GMT_NOTSET) { - Return (API->error); - } - break; - default: - GMT_Report (API, GMT_MSG_ERROR, "GMT_IS_STREAM only allows d, t, c, p, m, v!\n"); - Return (GMT_NOT_A_VALID_FAMILY); - break; - } - break; - case GMT_IS_FDESC: - switch (Ctrl->T.mode) { /* Can only do d, c, p, m, v */ - case GMT_IS_DATASET: case GMT_IS_PALETTE: case GMT_IS_POSTSCRIPT: case GMT_IS_MATRIX: case GMT_IS_VECTOR: -#ifdef WIN32 - /* I think they exist on Win too, but no much time to find out how. JL */ - fd = open (ofile[Ctrl->T.mode], O_WRONLY | O_CREAT); -#else - fd = open (ofile[Ctrl->T.mode], O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR); -#endif - fdp = &fd; - if ((out_ID = GMT_Register_IO (API, Ctrl->T.mode, Ctrl->W.mode, geometry[Ctrl->T.mode], GMT_OUT, NULL, fdp)) == GMT_NOTSET) { - Return (API->error); - } - break; - default: - GMT_Report (API, GMT_MSG_ERROR, "GMT_IS_FDESC only allows d, t, c, p, m, v!\n"); - Return (GMT_NOT_A_VALID_FAMILY); - break; - } - break; - case GMT_IS_DUPLICATE: case GMT_IS_REFERENCE: - if ((out_ID = GMT_Register_IO (API, Ctrl->T.mode, Ctrl->W.mode, geometry[Ctrl->T.mode], GMT_OUT, NULL, NULL)) == GMT_NOTSET) { - Return (API->error); - } - break; - default: - GMT_Report (API, GMT_MSG_ERROR, "Bad Input mode\n"); - Return (GMT_NOT_A_VALID_METHOD); - break; - } - - /* Now put the data to the registered destination */ - - if (GMT_Init_IO (API, Ctrl->T.mode, geometry[Ctrl->T.mode], GMT_OUT, GMT_ADD_EXISTING, 0, options) != GMT_NOERROR) { /* Registers default output destination, unless already set */ - Return (API->error); - } - if (GMT_Put_Data (API, out_ID, 0, In) != GMT_NOERROR) { - Return (API->error); - } - - if (Ctrl->W.mode == GMT_IS_DUPLICATE || Ctrl->W.mode == GMT_IS_REFERENCE) { /* Must write out what is in memory to the file */ - if ((Out = GMT_Retrieve_Data (API, out_ID)) == NULL) { - Return (API->error); - } - if (GMT_Write_Data (API, Ctrl->T.mode, GMT_IS_FILE, geometry[Ctrl->T.mode], GMT_WRITE_SET, NULL, ofile[Ctrl->T.mode], Out) != GMT_NOERROR) { - Return (API->error); - } - } - - if (GMT_Destroy_Data (API, &Intmp) != GMT_NOERROR) { - Return (API->error); - } - if (GMT_Destroy_Data (API, &M) != GMT_NOERROR) { - Return (API->error); - } - if (GMT_Destroy_Data (API, &V) != GMT_NOERROR) { - Return (API->error); - } - if (!(Ctrl->I.mode == GMT_IS_REFERENCE && Ctrl->W.mode == GMT_IS_REFERENCE) && GMT_Destroy_Data (API, &Out) != GMT_NOERROR) { - Return (API->error); - } - Return (GMT_NOERROR); -} - -int main (int argc, char *argv[]) { - - int status = 0; /* Status code from GMT API */ - struct GMTAPI_CTRL *API = NULL; /* GMT API control structure */ - - /* 1. Initializing new GMT session */ - if ((API = GMT_Create_Session (argv[0], GMT_PAD_DEFAULT, GMT_SESSION_NORMAL, NULL)) == NULL) exit (EXIT_FAILURE); - - /* 2. Run GMT cmd function, or give usage message if errors arise during parsing */ - status = GMT_testapi (API, argc-1, (argv+1)); - - /* 3. Destroy GMT session */ - if (GMT_Destroy_Session (API)) exit (EXIT_FAILURE); - - exit (status); -} diff --git a/src/testapi_matrix.c b/src/testapi_matrix.c index f39cf2e642f..d43a6ddb53e 100644 --- a/src/testapi_matrix.c +++ b/src/testapi_matrix.c @@ -6,8 +6,8 @@ int main () { void *API = NULL; /* The API control structure */ struct GMT_MATRIX *M[2] = {NULL, NULL}; /* Structure to hold input/output dataset as matrix */ - char input[GMT_STR16] = {""}; /* String to hold virtual input filename */ - char output[GMT_STR16] = {""}; /* String to hold virtual output filename */ + char input[GMT_VF_LEN] = {""}; /* String to hold virtual input filename */ + char output[GMT_VF_LEN] = {""}; /* String to hold virtual output filename */ char args[128] = {""}; /* String to hold module command arguments */ /* Initialize the GMT session */ API = GMT_Create_Session ("test", 2U, GMT_SESSION_EXTERNAL, NULL); diff --git a/src/testapi_matrix_plot.c b/src/testapi_matrix_plot.c index 4238fb36bdc..9c75fc2e2cd 100644 --- a/src/testapi_matrix_plot.c +++ b/src/testapi_matrix_plot.c @@ -6,7 +6,7 @@ int main () { void *API = NULL; /* The API control structure */ struct GMT_MATRIX *M = NULL; /* Structure to hold input matrix */ - char input[GMT_STR16] = {""}; /* String to hold virtual input filename */ + char input[GMT_VF_LEN] = {""}; /* String to hold virtual input filename */ char args[128] = {""}; /* String to hold module command arguments */ /* Initialize the GMT session */ API = GMT_Create_Session ("test", 2U, GMT_SESSION_EXTERNAL, NULL); diff --git a/src/testapi_mixmatrix.c b/src/testapi_mixmatrix.c index 1a4fa3c9d02..baf9e2eb92a 100644 --- a/src/testapi_mixmatrix.c +++ b/src/testapi_mixmatrix.c @@ -14,7 +14,7 @@ int main () { uint64_t dim[4] = {NCOLS, NROWS, 1, 0}; /* ncols, nrows, nlayers, type */ unsigned int mode = GMT_SESSION_EXTERNAL; struct GMT_MATRIX *M = NULL; /* Structure to hold input datasets as matrix */ - char input[GMT_STR16] = {""}; /* String to hold virtual input filename */ + char input[GMT_VF_LEN] = {""}; /* String to hold virtual input filename */ char args[128] = {""}; /* String to hold module command arguments */ int coord[NM] = {1, 2, 2, 3, 3, 4}; /* 3 points */ char *strings[NROWS] = {"First label", "Second label", "Third label"}; diff --git a/src/testapi_userdataset.c b/src/testapi_userdataset.c index 2df3086363c..37eca810432 100644 --- a/src/testapi_userdataset.c +++ b/src/testapi_userdataset.c @@ -180,8 +180,8 @@ int deploy_test (unsigned int intype, unsigned int outtype, int alloc_in_GMT, in double diff; //void *API = NULL; /* The API control structure */ struct GMT_MATRIX *M[2] = {NULL, NULL}; /* Structure to hold input/output datasets as matrix */ - char input[GMT_STR16] = {""}; /* String to hold virtual input filename */ - char output[GMT_STR16] = {""}; /* String to hold virtual output filename */ + char input[GMT_VF_LEN] = {""}; /* String to hold virtual input filename */ + char output[GMT_VF_LEN] = {""}; /* String to hold virtual output filename */ char args[128] = {""}; /* String to hold module command arguments */ void *in_data = NULL, *out_data = NULL; struct GMTAPI_CTRL *API = NULL; diff --git a/src/testapi_usergrid.c b/src/testapi_usergrid.c index 85abcbf732e..4bcac41ad08 100644 --- a/src/testapi_usergrid.c +++ b/src/testapi_usergrid.c @@ -191,8 +191,8 @@ int deploy_test (unsigned int intype, unsigned int outtype, int alloc_in_GMT, in double diff, wesn[6] = {1.0, NCOLS, 1.0, NROWS, 0.0, 0.0}, inc[2] = {1.0, 1.0}; //void *API = NULL; /* The API control structure */ struct GMT_MATRIX *M[2] = {NULL, NULL}; /* Structure to hold input/output grids as matrix */ - char input[GMT_STR16] = {""}; /* String to hold virtual input filename */ - char output[GMT_STR16] = {""}; /* String to hold virtual output filename */ + char input[GMT_VF_LEN] = {""}; /* String to hold virtual input filename */ + char output[GMT_VF_LEN] = {""}; /* String to hold virtual output filename */ char args[128] = {""}; /* String to hold module command arguments */ void *in_data = NULL, *out_data = NULL; struct GMTAPI_CTRL *API = NULL; diff --git a/src/testapi_uservectors.c b/src/testapi_uservectors.c index c2521739244..47d581c26ea 100644 --- a/src/testapi_uservectors.c +++ b/src/testapi_uservectors.c @@ -196,8 +196,8 @@ int deploy_test (unsigned int intype, unsigned int outtype, int alloc_in_GMT, in double diff, range[2] = {1.0, NROWS}, inc[2] = {1.0, 1.0}; //void *API = NULL; /* The API control structure */ struct GMT_VECTOR *V[2] = {NULL, NULL}; /* Structure to hold input/output datasets as vectors */ - char input[GMT_STR16] = {""}; /* String to hold virtual input filename */ - char output[GMT_STR16] = {""}; /* String to hold virtual output filename */ + char input[GMT_VF_LEN] = {""}; /* String to hold virtual input filename */ + char output[GMT_VF_LEN] = {""}; /* String to hold virtual output filename */ char args[128] = {""}; /* String to hold module command arguments */ void *in_data[NCOLS] = {NULL, NULL}, *out_data[NCOLS] = {NULL, NULL}; struct GMTAPI_CTRL *API = NULL; diff --git a/src/testapi_vector.c b/src/testapi_vector.c index 81975b4487d..4d2d7360ad5 100644 --- a/src/testapi_vector.c +++ b/src/testapi_vector.c @@ -6,8 +6,8 @@ int main () { void *API = NULL; /* The API control structure */ struct GMT_VECTOR *V[2] = {NULL, NULL}; /* Structure to hold input/output dataset as vectors */ - char input[GMT_STR16] = {""}; /* String to hold virtual input filename */ - char output[GMT_STR16] = {""}; /* String to hold virtual output filename */ + char input[GMT_VF_LEN] = {""}; /* String to hold virtual input filename */ + char output[GMT_VF_LEN] = {""}; /* String to hold virtual output filename */ char args[128] = {""}; /* String to hold module command arguments */ /* Initialize the GMT session */ diff --git a/src/testgmt.c b/src/testgmt.c deleted file mode 100644 index 0c1aae9b578..00000000000 --- a/src/testgmt.c +++ /dev/null @@ -1,86 +0,0 @@ -/*-------------------------------------------------------------------- - * - * Copyright (c) 1991-2020 by the GMT Team (https://www.generic-mapping-tools.org/team.html) - * See LICENSE.TXT file for copying and redistribution conditions. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; version 3 or any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * Contact info: www.generic-mapping-tools.org - *--------------------------------------------------------------------*/ -/* - * Demonstration program for how GMT may handle i/o and passing data - * from one GMT_* module to another. - * - * Currently shows how "grdcut t.nc -R2/4/2/4 -Gnew.nc -V" is obtained - * but calling GMT_grdcut from this main. - * - * Version: 5 - * Created: 13-Nov-2009 - * - */ - -#include "gmt_dev.h" - -int main () { - - int status = 0; /* Status code from GMT API */ - struct GMT_OPTION *head = NULL, *new_opt = NULL; /* Linked list of options */ - struct GMTAPI_CTRL *API = NULL; /* GMT API control structure */ - - int in_grdcut_ID, out_grdcut_ID; - char *in_grid = "t.nc", *out_grid = "new.nc", string[GMT_STR16] = {""}, arg[GMT_LEN256] = {""}; - double w = 2.0, e = 4.0, s = 1.0, n = 3.0; /* Hardwired region for test */ - struct GMT_GRID *Gin = NULL, *Gout = NULL; - - /* 1. Initializing new GMT session */ - if ((API = GMT_Create_Session ("TEST", GMT_PAD_DEFAULT, GMT_SESSION_NORMAL, NULL)) == NULL) exit (EXIT_FAILURE); - - /* 2. READING IN A GRID */ - if ((Gin = GMT_Read_Data (API, GMT_IS_GRID, GMT_IS_FILE, GMT_IS_SURFACE, GMT_CONTAINER_AND_DATA, NULL, in_grid, NULL)) == NULL) exit (EXIT_FAILURE); - - /* 3. PREPARING SOURCE AND DESTINATION FOR GMT_grdcut */ - /* 3a. Register the Gin grid to be the source read by grdcut by passing a pointer */ - if ((in_grdcut_ID = GMT_Register_IO (API, GMT_IS_GRID, GMT_IS_DUPLICATE, GMT_IS_SURFACE, GMT_IN, NULL, Gin)) == GMT_NOTSET) exit (EXIT_FAILURE); - /* 3b. Register a grid struct Gout to be the destination allocated and written to by grdcut */ - if ((out_grdcut_ID = GMT_Register_IO (API, GMT_IS_GRID, GMT_IS_REFERENCE, GMT_IS_SURFACE, GMT_OUT, NULL, NULL)) == GMT_NOTSET) exit (EXIT_FAILURE); - - /* 4. Create linked options for GMT_grdcut equivalent to "grdcut t.nc -R2/4/2/4 -Gnew.nc -V" */ - - if (GMT_Encode_ID (API, string, in_grdcut_ID) != GMT_NOERROR) exit (EXIT_FAILURE); /* Make filename with embedded object ID */ - if ((new_opt = GMT_Make_Option (API, '<', string)) == NULL) exit (EXIT_FAILURE); - if ((head = GMT_Append_Option (API, new_opt, NULL)) == NULL) exit (EXIT_FAILURE); - sprintf (arg, "%g/%g/%g/%g", w, e, s, n); /* Create argument for -R option */ - if ((new_opt = GMT_Make_Option (API, 'R', arg)) == NULL) exit (EXIT_FAILURE); - if ((head = GMT_Append_Option (API, new_opt, head)) == NULL) exit (EXIT_FAILURE); - if (GMT_Encode_ID (API, string, out_grdcut_ID) != GMT_NOERROR) exit (EXIT_FAILURE); /* Make -Gfilename with embedded object ID */ - if ((new_opt = GMT_Make_Option (API, 'G', string)) == NULL) exit (EXIT_FAILURE); - if ((head = GMT_Append_Option (API, new_opt, head)) == NULL) exit (EXIT_FAILURE); - if ((new_opt = GMT_Make_Option (API, 'V', NULL)) == NULL) exit (EXIT_FAILURE); /* Add -V*/ - if ((head = GMT_Append_Option (API, new_opt, head)) == NULL) exit (EXIT_FAILURE); - - /* 5. Run GMT cmd function, or give usage message if errors arise during parsing */ - status = GMT_Call_Module (API, "grdcut", GMT_MODULE_OPT, head); /* This allocates memory for the export grid associated with the -G option */ - if (status) { - GMT_Report (API, GMT_MSG_ERROR, "GMT_grdcut returned error %d\n", status); - exit (EXIT_FAILURE); - } - if ((Gout = GMT_Retrieve_Data (API, out_grdcut_ID)) == NULL) exit (EXIT_FAILURE); - - /* 6. Destroy local linked option list */ - if (GMT_Destroy_Options (API, &head)) exit (EXIT_FAILURE); - - /* 7. WRITING THE RESULT TO FILE */ - if (GMT_Write_Data (API, GMT_IS_GRID, GMT_IS_FILE, GMT_IS_SURFACE, GMT_CONTAINER_AND_DATA, NULL, out_grid, Gout) != GMT_NOERROR) exit (EXIT_FAILURE); - - /* 8. Destroy GMT session */ - if (GMT_Destroy_Session (API)) exit (EXIT_FAILURE); - - exit (GMT_NOERROR); /* Return the status from this program */ -} diff --git a/src/testio.c b/src/testio.c deleted file mode 100644 index 3b07e1bca64..00000000000 --- a/src/testio.c +++ /dev/null @@ -1,129 +0,0 @@ -/*-------------------------------------------------------------------- - * - * Copyright (c) 1991-2020 by the GMT Team (https://www.generic-mapping-tools.org/team.html) - * See LICENSE.TXT file for copying and redistribution conditions. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; version 3 or any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * Contact info: www.generic-mapping-tools.org - *--------------------------------------------------------------------*/ -/* - * Demonstration program for how GMT may handle i/o and passing data - * from one GMT_* module to another. - * - * Currently shows how "grdcut t.nc -R2/4/2/4 -Gnew.nc -V" is obtained - * but calling GMT_grdcut from this main. - * - * Version: 5 - * Created: 13-Nov-2009 - * - */ - -#include "gmt_dev.h" - -int main () { - - int status = 0, xrow, in_ID, out_ID; - uint64_t row, col, ij; - struct GMTAPI_CTRL *API = NULL; /* GMT API control structure */ - float x[4] = {1.0f, 2.0f, 3.0f, 4.0f}, y[4] = {0.5f, 1.5f, 2.5f, 3.5f}, z[4] = {3.3f, 8.1f, 2.9f, 4.4f}; - char i_string[GMT_STR16], o_string[GMT_STR16], buffer[GMT_BUFSIZ]; - struct GMT_VECTOR *Vi = NULL, *Vo = NULL; - struct GMT_GRID *G = NULL; - - /* 1. Initializing new GMT session */ - if ((API = GMT_Create_Session ("TEST", GMT_PAD_DEFAULT, GMT_SESSION_NORMAL, NULL)) == NULL) exit (EXIT_FAILURE); - - Vi = gmt_create_vector (API->GMT, 3U, GMT_IN); - Vi->type[0] = Vi->type[1] = Vi->type[2] = GMT_FLOAT; - Vi->n_rows = 4; - Vi->data[0].f4 = x; Vi->data[1].f4 = y; Vi->data[2].f4 = z; - Vo = gmt_create_vector (API->GMT, 3U, GMT_OUT); - - if ((in_ID = GMT_Register_IO (API, GMT_IS_VECTOR, GMT_IS_REFERENCE, GMT_IS_POINT, GMT_IN, NULL, Vi)) == GMT_NOTSET) exit (EXIT_FAILURE); - - Vo->type[0] = Vo->type[1] = Vo->type[2] = GMT_DOUBLE; - if ((out_ID = GMT_Register_IO (API, GMT_IS_VECTOR, GMT_IS_DUPLICATE, GMT_IS_POINT, GMT_OUT, NULL, NULL)) == GMT_NOTSET) exit (EXIT_FAILURE); - - /* 4. Create command options for GMT_mapproject */ - - if (GMT_Encode_ID (API, i_string, in_ID) != GMT_NOERROR) exit (EXIT_FAILURE); /* Make filename with embedded object ID */ - if (GMT_Encode_ID (API, o_string, out_ID) != GMT_NOERROR) exit (EXIT_FAILURE); /* Make filename with embedded object ID */ - sprintf (buffer, "-<%s -R0/5/0/5 -Jm1 -Fk -bi3 ->%s", i_string, o_string); - - /* 5. Run GMT cmd function, or give usage message if errors arise during parsing */ - status = GMT_Call_Module (API, "mapproject", GMT_MODULE_CMD, buffer); - if (status) { - GMT_Report (API, GMT_MSG_ERROR, "GMT_mapproject returned error %d\n", status); - exit (EXIT_FAILURE); - } - if ((Vo = GMT_Retrieve_Data (API, out_ID)) == NULL) exit (EXIT_FAILURE); - - /* 6. Create command options for GMT_xyz2grd */ - - if ((in_ID = GMT_Register_IO (API, GMT_IS_VECTOR, GMT_IS_REFERENCE, GMT_IS_POINT, GMT_IN, NULL, Vi)) == GMT_NOTSET) exit (EXIT_FAILURE); - if ((out_ID = GMT_Register_IO (API, GMT_IS_GRID, GMT_IS_REFERENCE, GMT_IS_SURFACE, GMT_OUT, NULL, NULL)) == GMT_NOTSET) exit (EXIT_FAILURE); - if (GMT_Encode_ID (API, i_string, in_ID) != GMT_NOERROR) exit (EXIT_FAILURE); /* Make filename with embedded object ID */ - if (GMT_Encode_ID (API, o_string, out_ID) != GMT_NOERROR) exit (EXIT_FAILURE); /* Make filename with embedded object ID */ - sprintf (buffer, "-<%s -R0/3/0/3 -I1 -G%s", i_string, o_string); - - /* 5. Run GMT cmd function, or give usage message if errors arise during parsing */ - status = GMT_Call_Module (API, "xyz2grd", GMT_MODULE_CMD, buffer); - if (status) { - GMT_Report (API, GMT_MSG_ERROR, "GMT_xyz2grd returned error %d\n", status); - exit (EXIT_FAILURE); - } - if ((G = GMT_Retrieve_Data (API, out_ID)) == NULL) exit (EXIT_FAILURE); - - /* Now print out the results locally */ - - for (row = 0; row < Vo->n_rows; row++) { - for (col = 0; col < Vo->n_columns; col++) printf ("%g\t", Vo->data[col].f8[row]); - printf ("\n"); - } - gmt_free_vector (API->GMT, &Vo, true); - - printf ("n_columns,n_rows = %d %d\n", G->header->n_columns, G->header->n_rows); - gmt_M_grd_loop (API->GMT, G, xrow, col, ij) if (!gmt_M_is_fnan (G->data[ij])) printf ("%g\n", G->data[ij]); - - if (GMT_Destroy_Data (API, &G) != GMT_NOERROR) { - GMT_Report (API, GMT_MSG_ERROR, "Failed to free G\n"); - } - - /* 6. Create command options for GMT_gmtselect */ - - Vo = gmt_create_vector (API->GMT, 3U, GMT_OUT); - if ((in_ID = GMT_Register_IO (API, GMT_IS_VECTOR, GMT_IS_REFERENCE, GMT_IS_POINT, GMT_IN, NULL, Vi)) == GMT_NOTSET) exit (EXIT_FAILURE); - if ((out_ID = GMT_Register_IO (API, GMT_IS_VECTOR, GMT_IS_DUPLICATE, GMT_IS_POINT, GMT_OUT, NULL, NULL)) == GMT_NOTSET) exit (EXIT_FAILURE); - if (GMT_Encode_ID (API, i_string, in_ID) != GMT_NOERROR) exit (EXIT_FAILURE); /* Make filename with embedded object ID */ - if (GMT_Encode_ID (API, o_string, out_ID) != GMT_NOERROR) exit (EXIT_FAILURE); /* Make filename with embedded object ID */ - sprintf (buffer, "-<%s -R0/3/0/3 ->%s", i_string, o_string); - - /* 5. Run GMT cmd function, or give usage message if errors arise during parsing */ - GMT_Message (API, GMT_TIME_NONE, "\ngmtselect output\n"); - status = GMT_Call_Module (API, "gmtselect", GMT_MODULE_CMD, buffer); - if (status) { - GMT_Report (API, GMT_MSG_ERROR, "GMT_gmtselect returned error %d\n", status); - exit (EXIT_FAILURE); - } - if ((Vo = GMT_Retrieve_Data (API, out_ID)) == NULL) exit (EXIT_FAILURE); - gmt_free_vector (API->GMT, &Vi, false); - for (row = 0; row < Vo->n_rows; row++) { - for (col = 0; col < Vo->n_columns; col++) printf ("%g\t", Vo->data[col].f8[row]); - printf ("\n"); - } - gmt_free_vector (API->GMT, &Vo, true); - gmt_free_vector (API->GMT, &Vi, false); - - /* 8. Destroy GMT session */ - if (GMT_Destroy_Session (API)) exit (EXIT_FAILURE); - - exit (GMT_NOERROR); /* Return the status from this program */ -} diff --git a/src/testpsl.c b/src/testpsl.c index 42d3039a8c2..5880bd93838 100644 --- a/src/testpsl.c +++ b/src/testpsl.c @@ -29,7 +29,7 @@ int main () { int status = 0; /* Status code from GMT API */ char cmd[BUFSIZ] = {""}; /* Command string */ - char string[GMT_STR16] = {""}; /* Encoded ID */ + char string[GMT_VF_LEN] = {""}; /* Encoded ID */ struct GMTAPI_CTRL *API = NULL; /* GMT API control structure */ struct GMT_POSTSCRIPT *PS = NULL; /* Holds our plot */