-
Notifications
You must be signed in to change notification settings - Fork 377
/
Copy pathtest_JL.c
54 lines (52 loc) · 2.95 KB
/
test_JL.c
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include "gmt.h"
/*
* Testing a specific case where we wish to pass and receive a GMT_VECTOR or GMT_MATRIX
* to/from a module that expect to read/write GMT_DATASETs.
*/
int main () {
void *API = NULL; /* The API control structure */
struct GMT_VECTOR *V[2] = {NULL, NULL}; /* Structure to hold input/output dataset as vectors */
struct GMT_MATRIX *M[2] = {NULL, NULL}; /* Structure to hold input/output dataset as matrix */
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, GMT_SESSION_EXTERNAL, NULL);
/* FIRST TEST GMT_VECTOR */
/* Read in our data table to memory */
V[GMT_IN] = GMT_Read_Data (API, GMT_IS_VECTOR, GMT_IS_FILE, GMT_IS_PLP, GMT_READ_NORMAL, NULL, "belgium.txt", NULL);
/* Associate our data table with a virtual file */
GMT_Open_VirtualFile (API, GMT_IS_DATASET, GMT_IS_PLP, GMT_IN, V[GMT_IN], input);
/* Create a virtual file to hold the sampled points */
GMT_Open_VirtualFile (API, GMT_IS_VECTOR, GMT_IS_PLP, GMT_OUT|GMT_IS_REFERENCE, NULL, output);
/* Prepare the module arguments */
sprintf (args, "-sa %s -Gtopo.nc ->%s", input, output);
/* Call the grdtrack module */
GMT_Call_Module (API, "grdtrack", GMT_MODULE_CMD, args);
/* Obtain the data from the virtual file */
V[GMT_OUT] = GMT_Read_VirtualFile (API, output);
/* Close the virtual files */
GMT_Close_VirtualFile (API, input);
GMT_Close_VirtualFile (API, output);
/* Write the data to file */
if (GMT_Write_Data (API, GMT_IS_VECTOR, GMT_IS_FILE, GMT_IS_PLP, GMT_WRITE_NORMAL, NULL, "vjunk.txt", V[GMT_OUT])) return EXIT_FAILURE;
/* NEXT TEST GMT_MATRIX */
M[GMT_IN] = GMT_Read_Data (API, GMT_IS_MATRIX, GMT_IS_FILE, GMT_IS_PLP, GMT_READ_NORMAL, NULL, "belgium.txt", NULL);
/* Associate our data table with a virtual file */
GMT_Open_VirtualFile (API, GMT_IS_DATASET, GMT_IS_PLP, GMT_IN, M[GMT_IN], input);
/* Create a virtual file to hold the sampled points */
GMT_Open_VirtualFile (API, GMT_IS_MATRIX, GMT_IS_PLP, GMT_OUT|GMT_IS_REFERENCE, NULL, output);
/* Prepare the module arguments */
sprintf (args, "-sa %s -Gtopo.nc ->%s", input, output);
/* Call the grdtrack module */
GMT_Call_Module (API, "grdtrack", GMT_MODULE_CMD, args);
/* Obtain the data from the virtual file */
M[GMT_OUT] = GMT_Read_VirtualFile (API, output);
/* Close the virtual files */
GMT_Close_VirtualFile (API, input);
GMT_Close_VirtualFile (API, output);
/* Write the data to file */
if (GMT_Write_Data (API, GMT_IS_MATRIX, GMT_IS_FILE, GMT_IS_PLP, GMT_WRITE_NORMAL, NULL, "mjunk.txt", M[GMT_OUT])) return EXIT_FAILURE;
/* Destroy the GMT session */
if (GMT_Destroy_Session (API)) return EXIT_FAILURE;
};