File: test_example1.c

package info (click to toggle)
gmt 6.6.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 62,184 kB
  • sloc: ansic: 294,045; sh: 30,961; lisp: 86; fortran: 49; makefile: 43; perl: 32; csh: 9
file content (32 lines) | stat: -rw-r--r-- 1,825 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include "gmt.h"
/* Demonstrate how to use the API to read a table and grid it with greenspline, then write a grid file */
int main () {
    void *API;                        /* The API control structure */
    struct GMT_DATASET *D = NULL;     /* Structure to hold input dataset */
    struct GMT_GRID *G = NULL;        /* Structure to hold output grid */
    char input[GMT_VF_LEN] = {""};     /* String to hold virtual input filename */
    char output[GMT_VF_LEN] = {""};    /* String to hold virtual output filename */
    char args[128] = {""};            /* String to hold module command arguments */

    /* Initialize the GMT session */
    API = GMT_Create_Session ("test", 2U, 0, NULL);
    /* Read in our data table to memory */
    D = GMT_Read_Data (API, GMT_IS_DATASET, GMT_IS_FILE, GMT_IS_PLP, GMT_READ_NORMAL, NULL, "table_5.11", NULL);
    /* Associate our data table with a virtual file */
    GMT_Open_VirtualFile (API, GMT_IS_DATASET, GMT_IS_PLP, GMT_IN, D, input);
    /* Create a virtual file to hold the resulting grid */
    GMT_Open_VirtualFile (API, GMT_IS_GRID, GMT_IS_SURFACE, GMT_OUT|GMT_IS_REFERENCE, NULL, output);
    /* Prepare the module arguments */
    sprintf (args, "-R0/7/0/7 -I0.2 -D1 -St0.3 %s -G%s", input, output);
    /* Call the greenspline module */
    GMT_Call_Module (API, "greenspline", GMT_MODULE_CMD, args);
    /* Obtain the grid from the virtual file */
    G = GMT_Read_VirtualFile (API, output);
    /* Close the virtual files */
	GMT_Close_VirtualFile (API, input);
	GMT_Close_VirtualFile (API, output);
    /* Write the grid to file */
    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;
    /* Destroy the GMT session */
    if (GMT_Destroy_Session (API)) return EXIT_FAILURE;
};