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

Function main

src/testapi_conv.c:29–80  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

27#include <string.h>
28
29int main (int argc, char *argv[]) {
30 unsigned int n = 0;
31 void *API = NULL;
32 struct GMT_DATASET *D = NULL;
33 struct GMT_MATRIX *M = NULL;
34 struct GMT_VECTOR *V = NULL;
35 struct GMT_GRID **G = NULL;
36 struct GMT_PALETTE **C = NULL;
37 struct GMT_POSTSCRIPT **P = NULL;
38 unsigned int flag[2] = {0, 0};
39 gmt_M_unused(argc);
40 /*----------------------- Standard module initialization and parsing ----------------------*/
41
42 /* 0. Initializing new GMT session */
43 if ((API = GMT_Create_Session (argv[0], 2U, GMT_SESSION_NORMAL, NULL)) == NULL) exit (EXIT_FAILURE);
44
45 /* Test reading several grid headers */
46
47 if ((G = GMT_Read_Group (API, GMT_IS_GRID, GMT_IS_FILE, GMT_IS_SURFACE, GMT_CONTAINER_ONLY, NULL, "*.nc", &n, NULL)) == NULL) exit (EXIT_FAILURE);
48 /* Then read grid data */
49 if ((G = GMT_Read_Group (API, GMT_IS_GRID, GMT_IS_FILE, GMT_IS_SURFACE, GMT_DATA_ONLY, NULL, "*.nc", NULL, G)) == NULL) exit (EXIT_FAILURE);
50 if (GMT_Destroy_Group (API, &G, n) != GMT_NOERROR) exit (EXIT_FAILURE);
51 /* Test reading several CPTs */
52 n = 0;
53 if ((C = GMT_Read_Group (API, GMT_IS_PALETTE, GMT_IS_FILE, GMT_IS_NONE, GMT_READ_NORMAL, NULL, "*.cpt", &n, NULL)) == NULL) exit (EXIT_FAILURE);
54 if (GMT_Destroy_Group (API, &C, n) != GMT_NOERROR) exit (EXIT_FAILURE);
55#if 0
56 /* Test reading several image files but allow for this to fail due to GDAL etc */
57 n = 0;
58 if ((I = GMT_Read_Group (API, GMT_IS_IMAGE, GMT_IS_FILE, GMT_IS_SURFACE, GMT_READ_NORMAL, NULL, "*.png", &n, NULL)) != NULL) {
59 if (GMT_Destroy_Group (API, &I, n) != GMT_NOERROR) exit (EXIT_FAILURE);
60 }
61#endif
62 /* Test reading several Postscript files */
63 n = 0;
64 if ((P = GMT_Read_Group (API, GMT_IS_POSTSCRIPT, GMT_IS_FILE, GMT_IS_NONE, GMT_READ_NORMAL, NULL, "*.ps", &n, NULL)) == NULL) exit (EXIT_FAILURE);
65 if (GMT_Destroy_Group (API, &P, n) != GMT_NOERROR) exit (EXIT_FAILURE);
66
67 /* 1. Read in two data tables; this DATASET is our starting point */
68
69 if ((D = GMT_Read_Data (API, GMT_IS_DATASET, GMT_IS_FILE, GMT_IS_PLP, GMT_READ_NORMAL, NULL, "[AB].txt", NULL)) == NULL) exit (EXIT_FAILURE);
70
71 /* Write a matrix */
72 flag[0] = 3; flag[1] = 0; if ((M = GMT_Convert_Data (API, D, GMT_IS_DATASET, NULL, GMT_IS_MATRIX, flag)) == NULL) exit (EXIT_FAILURE); /* Convert to matrix */
73 if (GMT_Write_Data (API, GMT_IS_MATRIX, GMT_IS_FILE, GMT_IS_POINT, GMT_WRITE_SET, NULL, "AB_dataM.txt", M) != GMT_NOERROR) exit (EXIT_FAILURE); /* run module */
74 /* Write a vector */
75 if ((V = GMT_Convert_Data (API, D, GMT_IS_DATASET, NULL, GMT_IS_VECTOR, flag)) == NULL) exit (EXIT_FAILURE); /* Convert to vector */
76 if (GMT_Write_Data (API, GMT_IS_VECTOR, GMT_IS_FILE, GMT_IS_POINT, GMT_WRITE_SET, NULL, "AB_dataV.txt", V) != GMT_NOERROR) exit (EXIT_FAILURE); /* run module */
77
78 /* 8. Destroy GMT session */
79 if (GMT_Destroy_Session (API)) exit (EXIT_FAILURE);
80}

Callers

nothing calls this directly

Calls 7

GMT_Create_SessionFunction · 0.85
GMT_Read_GroupFunction · 0.85
GMT_Destroy_GroupFunction · 0.85
GMT_Read_DataFunction · 0.85
GMT_Convert_DataFunction · 0.85
GMT_Write_DataFunction · 0.85
GMT_Destroy_SessionFunction · 0.85

Tested by

no test coverage detected