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

Function gmtapi_export_cube

src/gmt_api.c:6529–6735  ·  view source on GitHub ↗

! Writes out a single cube to destination */

Source from the content-addressed store, hash-verified

6527
6528/*! Writes out a single cube to destination */
6529GMT_LOCAL int gmtapi_export_cube (struct GMTAPI_CTRL *API, int object_ID, unsigned int mode, struct GMT_CUBE *U_obj) {
6530 int item, error;
6531 bool done = true;
6532 unsigned int method;
6533 openmp_int row, col, i0, i1, j0, j1;
6534 uint64_t k0, k1, ij, ijp, ij_orig, k, here = 0;
6535 size_t size;
6536 double dx, dy;
6537 p_func_uint64_t GMT_2D_to_index = NULL;
6538 GMT_putfunction api_put_val = NULL;
6539 struct GMTAPI_DATA_OBJECT *S_obj = NULL;
6540 struct GMT_CUBE *U_copy = NULL;
6541 struct GMT_MATRIX *M_obj = NULL;
6542 struct GMT_MATRIX_HIDDEN *MH = NULL;
6543 struct GMT_CUBE_HIDDEN *UH = gmt_get_U_hidden (U_obj), *UH2 = NULL;
6544 struct GMT_CTRL *GMT = API->GMT;
6545
6546 GMT_Report (API, GMT_MSG_DEBUG, "gmtapi_export_cube: Passed ID = %d and mode = %d\n", object_ID, mode);
6547
6548 if (object_ID == GMT_NOTSET) return (gmtlib_report_error (API, GMT_OUTPUT_NOT_SET));
6549 if (U_obj->data == NULL && !(mode & GMT_CONTAINER_ONLY)) return (gmtlib_report_error (API, GMT_PTR_IS_NULL));
6550 if ((item = gmtlib_validate_id (API, GMT_IS_CUBE, object_ID, GMT_OUT, GMT_NOTSET)) == GMT_NOTSET) return (gmtlib_report_error (API, API->error));
6551
6552 S_obj = API->object[item]; /* The current object whose data we will export */
6553 if (S_obj->status != GMT_IS_UNUSED && !(mode & GMT_IO_RESET))
6554 return (gmtlib_report_error (API, GMT_WRITTEN_ONCE)); /* Only allow writing of a data set once, unless overridden by mode */
6555 if (mode & GMT_IO_RESET) mode -= GMT_IO_RESET;
6556 if (S_obj->region) { /* See if this is really a subset or just the same region as the cube */
6557 if (U_obj->header->wesn[XLO] == S_obj->wesn[XLO] && U_obj->header->wesn[XHI] == S_obj->wesn[XHI] && \
6558 U_obj->header->wesn[YLO] == S_obj->wesn[YLO] && U_obj->header->wesn[YHI] == S_obj->wesn[YHI] && \
6559 U_obj->z_range[0] == S_obj->wesn[ZLO] && U_obj->z_range[1] == S_obj->wesn[ZHI])
6560 S_obj->region = false;
6561 }
6562 if (mode & GMT_DATA_IS_GEO) gmt_set_geographic (GMT, GMT_OUT); /* From API to tell cube is geographic */
6563 gmtapi_cube_set_units (GMT, U_obj); /* Ensure unit strings are set, regardless of destination */
6564
6565 method = gmtapi_set_method (S_obj); /* Get the actual method to use since may be MATRIX or VECTOR masquerading as GRID */
6566 switch (method) {
6567 case GMT_IS_FILE: /* Name of a cube file to write to disk */
6568 if (mode & GMT_CONTAINER_ONLY) { /* Update header structure only */
6569 GMT_Report (API, GMT_MSG_INFORMATION, "Updating cube header for file %s not implemented\n", S_obj->filename);
6570 return (gmtlib_report_error (API, GMT_RUNTIME_ERROR));
6571 }
6572 else {
6573 GMT_Report (API, GMT_MSG_INFORMATION, "Writing cube to file %s\n", S_obj->filename);
6574 if (gmt_nc_write_cube (GMT, U_obj, S_obj->wesn, S_obj->filename) != GMT_NOERROR)
6575 return (gmtlib_report_error (API, API->error));
6576 done = true;
6577 }
6578 break;
6579
6580 case GMT_IS_DUPLICATE: /* Duplicate GMT cube and header to a GMT_CUBE container object. Subset allowed */
6581 if (S_obj->resource) return (gmtlib_report_error (API, GMT_PTR_NOT_NULL)); /* The output resource pointer must be NULL */
6582 if (mode & GMT_CONTAINER_ONLY) return (gmtlib_report_error (API, GMT_NOT_A_VALID_MODE));
6583 if (gmtapi_adjust_grdpadding (U_obj->header, GMT->current.io.pad)) {
6584 GMT_Report (API, GMT_MSG_INFORMATION, "Reference cube must have standard padding\n");
6585 gmtlib_report_error (API, GMT_PADDING_NOT_ALLOWED);
6586 }

Callers 1

gmtapi_export_dataFunction · 0.85

Calls 15

gmt_get_U_hiddenFunction · 0.85
GMT_ReportFunction · 0.85
gmtlib_report_errorFunction · 0.85
gmtlib_validate_idFunction · 0.85
gmt_set_geographicFunction · 0.85
gmtapi_cube_set_unitsFunction · 0.85
gmtapi_set_methodFunction · 0.85
gmt_nc_write_cubeFunction · 0.85
gmtapi_adjust_grdpaddingFunction · 0.85
gmtlib_duplicate_cubeFunction · 0.85
gmt_BC_initFunction · 0.85
gmt_cube_BC_setFunction · 0.85

Tested by

no test coverage detected