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 /*
19 * Include file for GMT error codes
20 *
21 * Author: Paul Wessel
22 * Date: 1-JAN-2010
23 * Version: 6 API
24 */
25
26 /*!
27 * \file gmt_error.h
28 * \brief Include file for GMT error codes
29 */
30
31 #ifndef GMT_ERROR_H
32 #define GMT_ERROR_H
33
34 /* Grid i/o error codes */
35
36 /* External array with error descriptions */
37 EXTERN_MSC const char* gmt_error_string[];
38
39 enum Gmt_error_code {
40 GMT_NOERROR_UNUSED=0, /* The real GMT_NOERROR is declared in gmt_resources.h and is part of API */
41 GMT_GRDIO_NONUNIQUE_FORMAT,
42 GMT_GRDIO_UNKNOWN_FORMAT,
43 GMT_GRDIO_UNKNOWN_TYPE,
44 GMT_GRDIO_UNKNOWN_ID,
45 GMT_GRDIO_PIPE_CODECHECK,
46 GMT_GRDIO_DOMAIN_VIOLATION,
47 GMT_GRDIO_OPEN_FAILED,
48 GMT_GRDIO_CREATE_FAILED,
49 GMT_GRDIO_READ_FAILED,
50 GMT_GRDIO_WRITE_FAILED,
51 GMT_GRDIO_STAT_FAILED,
52 GMT_GRDIO_SEEK_FAILED,
53 GMT_GRDIO_FILE_NOT_FOUND,
54 GMT_GRDIO_BAD_VAL,
55 GMT_GRDIO_BAD_XINC,
56 GMT_GRDIO_BAD_XRANGE,
57 GMT_GRDIO_BAD_YINC,
58 GMT_GRDIO_BAD_YRANGE,
59 GMT_GRDIO_BAD_IMG_LAT,
60 GMT_GRDIO_NO_2DVAR,
61 GMT_GRDIO_NO_VAR,
62 GMT_GRDIO_BAD_DIM,
63 GMT_GRDIO_NC_NO_PIPE,
64 GMT_GRDIO_NC_NOT_COARDS,
65 GMT_GRDIO_NOT_RAS,
66 GMT_GRDIO_NOT_8BIT_RAS,
67 GMT_GRDIO_NOT_SURFER,
68 GMT_GRDIO_SURF7_UNSUPPORTED,
69 GMT_GRDIO_GRD98_XINC,
70 GMT_GRDIO_GRD98_YINC,
71 GMT_GRDIO_GRD98_BADMAGIC,
72 GMT_GRDIO_GRD98_BADLENGTH,
73 GMT_GRDIO_ESRI_NONSQUARE,
74 GMT_GRDIO_RI_OLDBAD,
75 GMT_GRDIO_RI_NEWBAD,
76 GMT_GRDIO_RI_NOREPEAT,
77 GMT_IO_BAD_PLOT_DEGREE_FORMAT,
78 GMT_CHEBYSHEV_NEG_ORDER,
79 GMT_CHEBYSHEV_BAD_DOMAIN,
80 GMT_MAP_EXCEEDS_360,
81 GMT_MAP_BAD_ELEVATION_MIN,
82 GMT_MAP_BAD_ELEVATION_MAX,
83 GMT_MAP_BAD_LAT_MIN,
84 GMT_MAP_BAD_LAT_MAX,
85 GMT_MAP_NO_REGION,
86 GMT_MAP_NO_PROJECTION,
87 GMT_MAP_BAD_DIST_FLAG,
88 GMT_MAP_BAD_MEASURE_UNIT
89 };
90
91 EXTERN_MSC const char * GMT_strerror (int err);
92
93 #define gmt_M_is_verbose(C,level) (MAX(C->parent->verbose, C->current.setting.verbose) >= level)
94
95 /* Check condition and report error if true */
96 #define gmt_M_check_condition(C,condition,...) ((condition) ? 1+GMT_Report(C->parent,GMT_MSG_ERROR,__VA_ARGS__) : 0)
97 /* Check if a module option has been called more than once (context has opt available) */
98 #define gmt_M_repeated_module_option(API,active) (gmt_M_check_condition (API->GMT, active, "Option -%c: Given more than once (offending option is -%c%s)\n", opt->option, opt->option, opt->arg))
99
100 /* Set __func__ identifier */
101 #ifndef HAVE___FUNC__
102 # ifdef HAVE___FUNCTION__
103 # define __func__ __FUNCTION__
104 # else
105 # define __func__ "<unknown>"
106 # endif
107 #endif
108
109 /* Concatenate __FILE__ and __LINE__ as string */
110 #define STRINGIFY(x) #x
111 #define TOSTRING(x) STRINGIFY(x)
112 #define __SOURCE_LINE __FILE__ ":" TOSTRING(__LINE__)
__source_line_func(const char * src_line,const char * func)113 static inline char* __source_line_func (const char* src_line, const char* func) {
114 /* This function is not thread-safe */
115 static char str[GMT_LEN256];
116 const char *c = src_line;
117 size_t len;
118 *str = '\0';
119 while ((c = strpbrk (c, "/\\")) != NULL) /* get basename of src_line */
120 src_line = ++c;
121 strncat (str, src_line, GMT_LEN256-1);
122 len = strlen (src_line);
123 strncat (str, "(", GMT_LEN256 - 2 - len);
124 strncat (str, func, GMT_LEN256 - 3 - len);
125 strcat (str, ")");
126 return str;
127 }
128 #define __SOURCE_LINE_FUNC __source_line_func (__FILE__ ":" TOSTRING(__LINE__), __func__)
129
130 /* Convenience functions to gmt_err_func */
131 #ifdef DEBUG
132 # define gmt_M_err_pass(C,err,file) gmt_err_func(C,err,false,file,__SOURCE_LINE_FUNC)
133 # define gmt_M_err_fail(C,err,file) gmt_err_func(C,err,true,file,__SOURCE_LINE_FUNC)
134 #else
135 # define gmt_M_err_pass(C,err,file) gmt_err_func(C,err,false,file,__func__)
136 # define gmt_M_err_fail(C,err,file) gmt_err_func(C,err,true,file,__func__)
137 #endif
138
139 #endif /* GMT_ERROR_H */
140