1 #include "gmt.h"
2 /*
3  * Testing a specific case where we wish to pass and receive a GMT_VECTOR or GMT_MATRIX
4  * to/from a module that expect to read/write GMT_DATASETs.
5  */
main()6 int main () {
7 	void *API = NULL;                 /* The API control structure */
8 	struct GMT_MATRIX *M[2] = {NULL, NULL};     /* Structure to hold input/output dataset as matrix */
9 	char input[GMT_VF_LEN] = {""};     			/* String to hold virtual input filename */
10 	char output[GMT_VF_LEN] = {""};    			/* String to hold virtual output filename */
11 	char args[128] = {""};            			/* String to hold module command arguments */
12 	/* Initialize the GMT session */
13 	API = GMT_Create_Session ("test", 2U, GMT_SESSION_EXTERNAL, NULL);
14 	M[GMT_IN] = GMT_Read_Data (API, GMT_IS_MATRIX, GMT_IS_FILE, GMT_IS_PLP, GMT_READ_NORMAL, NULL, "belgium.txt", NULL);
15 	/* Associate our data table with a virtual file */
16 	GMT_Open_VirtualFile (API, GMT_IS_DATASET|GMT_VIA_MATRIX, GMT_IS_PLP, GMT_IN, M[GMT_IN], input);
17 	/* Open a virtual file to hold the sampled points */
18 	GMT_Open_VirtualFile (API, GMT_IS_DATASET|GMT_IS_MATRIX, GMT_IS_PLP, GMT_OUT|GMT_IS_REFERENCE, NULL, output);
19 	/* Prepare the module arguments */
20 	sprintf (args, "-sa %s -Gtopo.nc ->%s", input, output);
21 	/* Call the grdtrack module */
22 	GMT_Call_Module (API, "grdtrack", GMT_MODULE_CMD, args);
23 	/* Obtain the data from the virtual file */
24 	M[GMT_OUT] = GMT_Read_VirtualFile (API, output);
25 	/* Close the virtual files */
26 	GMT_Close_VirtualFile (API, input);
27 	GMT_Close_VirtualFile (API, output);
28 	/* Associate our sampled table with a virtual file */
29 	GMT_Open_VirtualFile (API, GMT_IS_DATASET|GMT_VIA_MATRIX, GMT_IS_PLP, GMT_IN, M[GMT_OUT], input);
30 	/* Prepare the module arguments */
31 	sprintf (args, "-R3/9/50/54 -JM6i -P -Baf -W0.5p %s ->apimat.ps", input);
32 	/* Call the psxy module */
33 	GMT_Call_Module (API, "psxy", GMT_MODULE_CMD, args);
34 	/* Close the virtual files */
35 	GMT_Close_VirtualFile (API, input);
36 	if (GMT_Destroy_Session (API)) return EXIT_FAILURE;
37 };
38