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

Function gmtapi_export_data

src/gmt_api.c:7677–7748  ·  view source on GitHub ↗

! . */

Source from the content-addressed store, hash-verified

7675
7676/*! . */
7677GMT_LOCAL int gmtapi_export_data (struct GMTAPI_CTRL *API, enum GMT_enum_family family, int object_ID, unsigned int mode, void *data) {
7678 /* Function that will export the single data object referred to by the object_ID as registered by GMT_Register_IO.
7679 */
7680 int error, item;
7681 struct GMTAPI_DATA_OBJECT *S_obj = NULL;
7682
7683 if (API == NULL) return (GMT_NOT_A_SESSION); /* GMT_Create_Session has not been called */
7684 if (data == NULL) return (GMT_PTR_IS_NULL); /* Got a NULL data pointer */
7685 if (!API->registered[GMT_OUT]) return (gmtlib_report_error (API, GMT_NO_OUTPUT)); /* No destination registered yet */
7686
7687 /* Get information about this resource first */
7688 if ((item = gmtlib_validate_id (API, family, object_ID, GMT_OUT, GMT_NOTSET)) == GMT_NOTSET) return (gmtlib_report_error (API, API->error));
7689
7690 S_obj = API->object[item]; /* The current object we are trying to export */
7691 /* The case where object_ID is not set but a virtual (memory) file is found is a special case: we must supply the correct object_ID */
7692 if (object_ID == GMT_NOTSET && item && S_obj->method != GMT_IS_FILE)
7693 object_ID = S_obj->ID; /* Found virtual file; set actual object_ID */
7694
7695 /* Check if this is a container passed from the outside to capture output */
7696 gmtapi_reconsider_messenger (API, S_obj); /* This may set S_obj->messenger to false in some cases */
7697 if (S_obj->messenger && S_obj->resource) { /* Need to destroy the dummy container before passing data out */
7698 error = gmtapi_destroy_data_ptr (API, S_obj->actual_family, S_obj->resource); /* Do the dirty deed */
7699 if (error) return error;
7700 GMT_Report (API, GMT_MSG_DEBUG, "gmtapi_export_data: Messenger dummy output container for object %d [item %d] freed and set resource=data=NULL\n", S_obj->ID, item);
7701 S_obj->resource = NULL; /* Since we now have nothing */
7702 S_obj->messenger = false; /* OK, now clean for output */
7703 }
7704
7705#ifdef DEBUG
7706 //gmtapi_list_objects (API, "gmtapi_export_data-in");
7707#endif
7708 /* PW Note: Important that any exporter needing to create memory to hold an output
7709 * that will be returned to the caller: Never create/duplicate with the API functions
7710 * as these add memory registrations and thus leads to duplicate entries in the objects
7711 * table. Symptoms of this are memory junk back in the calling program because two objects
7712 * have a pointer to the same memory and one of them is destroyed, messing up the other.
7713 * Use the gmtlib functions like gmt_duplicate_grid, etc for these purposes herein. */
7714
7715 switch (family) {
7716 case GMT_IS_PALETTE: /* Export a CPT */
7717 error = gmtapi_export_palette (API, object_ID, mode, data);
7718 break;
7719 case GMT_IS_DATASET: /* Export a Data set */
7720 error = gmtapi_export_dataset (API, object_ID, mode, data);
7721 break;
7722 case GMT_IS_GRID: /* Export a GMT grid */
7723 error = gmtapi_export_grid (API, object_ID, mode, data);
7724 break;
7725 case GMT_IS_IMAGE: /* Export a GMT image */
7726 error = gmtapi_export_image (API, object_ID, mode, data);
7727 break;
7728 case GMT_IS_CUBE: /* Export a GMT cube */
7729 error = gmtapi_export_cube (API, object_ID, mode, data);
7730 break;
7731 case GMT_IS_POSTSCRIPT: /* Export PS */
7732 error = gmtapi_export_postscript (API, object_ID, mode, data);
7733 break;
7734 case GMT_IS_MATRIX: /* Export MATRIX */

Callers 1

gmtapi_put_dataFunction · 0.85

Calls 13

gmtlib_report_errorFunction · 0.85
gmtlib_validate_idFunction · 0.85
gmtapi_destroy_data_ptrFunction · 0.85
GMT_ReportFunction · 0.85
gmtapi_export_paletteFunction · 0.85
gmtapi_export_datasetFunction · 0.85
gmtapi_export_gridFunction · 0.85
gmtapi_export_imageFunction · 0.85
gmtapi_export_cubeFunction · 0.85
gmtapi_export_postscriptFunction · 0.85
gmtapi_export_matrixFunction · 0.85

Tested by

no test coverage detected