1 /*--------------------------------------------------------------------
2 *
3 * Copyright (c) 1991-2021 by the GMT Team (https://www.generic-mapping-tools.org/team.html)
4 * See LICENSE.TXT file for copying and redistribution conditions.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation; version 3 or any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Lesser General Public License for more details.
14 *
15 * Contact info: www.generic-mapping-tools.org
16 *--------------------------------------------------------------------*/
17 /*
18 * Author: Paul Wessel
19 * Date: 7-JUN-2016
20 * Version: 6 API
21 *
22 * Brief synopsis: testapiconv tests GMT_Convert_Data function.
23 *
24 */
25
26 #include "gmt_dev.h"
27 #include <string.h>
28
main(int argc,char * argv[])29 int 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 }
81