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

Function main

src/testapi_cube.c:8–38  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6 */
7
8int main () {
9 /* Run the test using the specified in and out types */
10 char input[GMT_VF_LEN] = {""}, output[GMT_VF_LEN] = {""}, cmd[256] = {""};
11 unsigned int mode = GMT_SESSION_EXTERNAL;
12 double range[6] = {3.0, 8.0, 4.0, 6.0, 2.0, 4.0};
13 struct GMT_CUBE *C = NULL, *C2 = NULL; /* Structure to hold cubes */
14 struct GMTAPI_CTRL *API = NULL;
15
16 /* Initialize a GMT session */
17 API = GMT_Create_Session ("test", 2U, mode, NULL);
18 /* Read in a small 3-D data cube from file */
19 if ((C = GMT_Read_Data (API, GMT_IS_CUBE, GMT_IS_FILE, GMT_IS_VOLUME, GMT_CONTAINER_AND_DATA, range, "cube.nc", NULL)) == NULL) return (EXIT_FAILURE);
20 /* Test basic writing of cube to file (for now a stack of 2-D grids) */
21 if (GMT_Write_Data (API, GMT_IS_CUBE, GMT_IS_FILE, GMT_IS_VOLUME, GMT_CONTAINER_AND_DATA, NULL, "cube-out-%g.nc", C)) return (EXIT_FAILURE);
22 /* Interpolate the cube by passing it as a memory object to sphinterpolate and retrieve a memory cube*/
23 GMT_Open_VirtualFile (API, GMT_IS_CUBE, GMT_IS_VOLUME, GMT_IN, C, input);
24 GMT_Open_VirtualFile (API, GMT_IS_CUBE, GMT_IS_VOLUME, GMT_OUT, NULL, output);
25 sprintf (cmd, "%s -T4 -G%s", input, output);
26 /* Run the command */
27 GMT_Call_Module (API, "grdinterpolate", GMT_MODULE_CMD, cmd);
28 /* Get the data cube from virtual file */
29 C2 = GMT_Read_VirtualFile (API, output);
30 /* Write the grid to file */
31 if (GMT_Write_Data (API, GMT_IS_CUBE, GMT_IS_FILE, GMT_IS_VOLUME, GMT_CONTAINER_AND_DATA, NULL, "newlayer.nc", C2)) return (EXIT_FAILURE);
32 /* Free the cube memories */
33 GMT_Destroy_Data (API, &C);
34 GMT_Destroy_Data (API, &C2);
35 /* Destroy session, which will free all GMT-allocated memory */
36 if (GMT_Destroy_Session (API)) return EXIT_FAILURE;
37 exit (0);
38}

Callers

nothing calls this directly

Calls 8

GMT_Create_SessionFunction · 0.85
GMT_Read_DataFunction · 0.85
GMT_Write_DataFunction · 0.85
GMT_Open_VirtualFileFunction · 0.85
GMT_Call_ModuleFunction · 0.85
GMT_Read_VirtualFileFunction · 0.85
GMT_Destroy_DataFunction · 0.85
GMT_Destroy_SessionFunction · 0.85

Tested by

no test coverage detected