MCPcopy Create free account
hub / github.com/GenericMappingTools/gmt / gmtapi_vector2dataset

Function gmtapi_vector2dataset

src/gmt_api.c:14917–14943  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

14915/* GMT_VECTOR to GMT_* : */
14916
14917GMT_LOCAL void * gmtapi_vector2dataset (struct GMTAPI_CTRL *API, struct GMT_VECTOR *In, struct GMT_DATASET *Out, unsigned int header) {
14918 /* Convert a vector to a dataset (one table with one segment).
14919 * header controls what we do with headers.
14920 * If Out is not NULL then we assume it has enough rows and columns to hold the dataset records.
14921 */
14922 uint64_t row, col;
14923 unsigned int mode = (In->text) ? GMT_WITH_STRINGS : 0;
14924 bool alloc = (Out == NULL);
14925 struct GMT_CTRL *GMT = API->GMT;
14926 struct GMT_DATASEGMENT *SD = NULL;
14927 GMT_getfunction api_get_val;
14928 if (header) GMT_Report (API, GMT_MSG_WARNING, "gmtapi_vector2dataset: Header stripping not implemented yet - ignored!\n");
14929 if (alloc && (Out = gmtlib_create_dataset (GMT, 1U, 1U, In->n_rows, In->n_columns, GMT_IS_POINT, mode, true)) == NULL)
14930 return_null (API, GMT_MEMORY_ERROR);
14931 SD = Out->table[0]->segment[0]; /* Shorthand to only segment in the dataset */
14932 for (col = 0; col < In->n_columns; col++) {
14933 if ((api_get_val = gmtapi_select_get_function (API, In->type[col])) == NULL)
14934 return_null (API, GMT_NOT_A_VALID_TYPE);
14935 for (row = 0; row < In->n_rows; row++)
14936 api_get_val (&(In->data[col]), row, &(SD->data[col][row]));
14937 }
14938 if (mode) { /* Duplicate the strings */
14939 for (row = 0; row < In->n_rows; row++)
14940 SD->text[row] = strdup (In->text[row]); /* Duplicate the strings */
14941 }
14942 return Out;
14943}
14944
14945GMT_LOCAL void * gmtapi_vector2matrix (struct GMTAPI_CTRL *API, struct GMT_VECTOR *In, struct GMT_MATRIX *Out, unsigned int header, unsigned int mode) {
14946 /* Convert a vector to a matrix.

Callers 1

GMT_Convert_DataFunction · 0.85

Calls 4

GMT_ReportFunction · 0.85
gmtlib_create_datasetFunction · 0.85
strdupFunction · 0.85

Tested by

no test coverage detected