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

Function main

src/test_example1.c:3–32  ·  view source on GitHub ↗

Demonstrate how to use the API to read a table and grid it with greenspline, then write a grid file */

Source from the content-addressed store, hash-verified

1#include "gmt.h"
2/* Demonstrate how to use the API to read a table and grid it with greenspline, then write a grid file */
3int main () {
4 void *API; /* The API control structure */
5 struct GMT_DATASET *D = NULL; /* Structure to hold input dataset */
6 struct GMT_GRID *G = NULL; /* Structure to hold output grid */
7 char input[GMT_VF_LEN] = {""}; /* String to hold virtual input filename */
8 char output[GMT_VF_LEN] = {""}; /* String to hold virtual output filename */
9 char args[128] = {""}; /* String to hold module command arguments */
10
11 /* Initialize the GMT session */
12 API = GMT_Create_Session ("test", 2U, 0, NULL);
13 /* Read in our data table to memory */
14 D = GMT_Read_Data (API, GMT_IS_DATASET, GMT_IS_FILE, GMT_IS_PLP, GMT_READ_NORMAL, NULL, "table_5.11", NULL);
15 /* Associate our data table with a virtual file */
16 GMT_Open_VirtualFile (API, GMT_IS_DATASET, GMT_IS_PLP, GMT_IN, D, input);
17 /* Create a virtual file to hold the resulting grid */
18 GMT_Open_VirtualFile (API, GMT_IS_GRID, GMT_IS_SURFACE, GMT_OUT|GMT_IS_REFERENCE, NULL, output);
19 /* Prepare the module arguments */
20 sprintf (args, "-R0/7/0/7 -I0.2 -D1 -St0.3 %s -G%s", input, output);
21 /* Call the greenspline module */
22 GMT_Call_Module (API, "greenspline", GMT_MODULE_CMD, args);
23 /* Obtain the grid from the virtual file */
24 G = GMT_Read_VirtualFile (API, output);
25 /* Close the virtual files */
26 GMT_Close_VirtualFile (API, input);
27 GMT_Close_VirtualFile (API, output);
28 /* Write the grid to file */
29 if (GMT_Write_Data (API, GMT_IS_GRID, GMT_IS_FILE, GMT_IS_SURFACE, GMT_CONTAINER_AND_DATA, NULL, "junk.nc", G)) return EXIT_FAILURE;
30 /* Destroy the GMT session */
31 if (GMT_Destroy_Session (API)) return EXIT_FAILURE;
32};

Callers

nothing calls this directly

Calls 8

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

Tested by

no test coverage detected