4 * This source code is part of
8 * GROningen MAchine for Chemical Simulations
11 * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others.
12 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
13 * Copyright (c) 2001-2004, The GROMACS development team,
14 * check out http://www.gromacs.org for more information.
16 * This program is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU General Public License
18 * as published by the Free Software Foundation; either version 2
19 * of the License, or (at your option) any later version.
21 * If you want to redistribute modifications, please consider that
22 * scientific software is very special. Version control is crucial -
23 * bugs must be traceable. We will be happy to consider code for
24 * inclusion in the official distribution, but derived work must not
25 * be called official GROMACS. Details are found in the README & COPYING
26 * files - if they are missing, get the official version at www.gromacs.org.
28 * To help us fund GROMACS development, we humbly ask that you cite
29 * the papers on the package - you can find them in the top README file.
31 * For more info, check our website at http://www.gromacs.org
34 * Gromacs Runs On Most of All Computer Systems
43 #include "types/simple.h"
49 #ifndef __has_feature // Optional.
50 #define __has_feature(x) 0 // Compatibility with non-clang compilers.
53 /* This documentation block seems to produce warnings with some Doxygen
54 * versions, so it's disabled for now. Maybe because the file itself
55 * is not documented. */
56 /* \def GMX_ATTRIBUTE_NORETURN
58 * Indicate that a function is not expected to return.
60 * WARNING: In general this flag should not be used for compiler
61 * optimizations, since set_gmx_error_handler can be set to a
62 * handler which does not quit.
64 #ifndef GMX_ATTRIBUTE_NORETURN
65 #if __has_feature(attribute_analyzer_noreturn)
66 #define GMX_ATTRIBUTE_NORETURN __attribute__((analyzer_noreturn))
68 #define GMX_ATTRIBUTE_NORETURN
73 _where(const char *file, int line);
74 #define where() _where(__FILE__, __LINE__)
75 /* Prints filename and line to stdlog and only on amba memvail */
78 _set_fatal_tmp_file(const char *fn, const char *file, int line);
79 #define set_fatal_tmp_file(fn) _set_fatal_tmp_file(fn, __FILE__, __LINE__)
80 /* set filename to be removed when fatal_error is called */
83 _unset_fatal_tmp_file(const char *fn, const char *file, int line);
84 #define unset_fatal_tmp_file(fn) _unset_fatal_tmp_file(fn, __FILE__, __LINE__)
85 /* unsets filename to be removed */
88 gmx_fatal(int fatal_errno, const char *file, int line, const char *fmt, ...) GMX_ATTRIBUTE_NORETURN;
89 #define FARGS 0, __FILE__, __LINE__
91 * Routine gmx_fatal prints
93 * "fatal error file %s line %s \n\t "
95 * followed by the string specified by fmt and supplied parameters. If
96 * errno is 0, only the message and arguments are printed. If errno is
97 * a legal system errno or -1, a perror like message is printed after the
98 * first message, if errno is -1, the last system errno will be used.
99 * The format of fmt is that like printf etc, only %d, %x, %c, %f, %g and %s
100 * are allowed as format specifiers.
102 * In case all MPI processes want to stop with the same fatal error,
103 * use gmx_fatal_collective, declared in gmx_fatal_collective.h,
104 * to avoid having as many error messages as processes.
107 * call this function using the FARGS macro:
108 * gmx_fatal(FARGS,fmt,...)
113 gmx_fatal_set_log_file(FILE *fp);
114 /* Set the log file for printing error messages */
117 _invalid_case(const char *fn, int line);
118 #define invalid_case() _invalid_case(__FILE__, __LINE__)
119 /* Issue a warning stating 'Invalid case in switch' */
121 void _unexpected_eof(const char *fn, int line, const char *srcfn, int srcline);
122 #define unexpected_eof(fn, line) _unexpected_eof(fn, line, __FILE__, __LINE__)
125 * Functions can write to this file for debug info
126 * Before writing to it, it should be checked whether
127 * the file is not NULL:
128 * if (debug) fprintf(debug,"%s","Hallo");
131 extern gmx_bool gmx_debug_at;
133 void init_debug (const int dbglevel, const char *dbgfile);
135 gmx_bool bDebugMode(void);
136 /* Return TRUE when the program was started in debug mode */
138 #if (defined __sgi && defined USE_SGI_FPE)
139 void doexceptions(void);
140 /* Set exception handlers for debugging */
143 /* warn_str is allowed to be NULL.
145 void _range_check(int n, int n_min, int n_max, const char *warn_str,
147 const char *file, int line);
149 #define range_check_mesg(n, n_min, n_max, str) _range_check(n, n_min, n_max, str,#n, __FILE__, __LINE__)
150 /* Range check will terminate with an error message if not
151 * n E [ n_min, n_max >
152 * That is n_min is inclusive but not n_max.
155 #define range_check(n, n_min, n_max) _range_check(n, n_min, n_max, NULL,#n, __FILE__, __LINE__)
156 /* Range check will terminate with an error message if not
157 * n E [ n_min, n_max >
158 * That is n_min is inclusive but not n_max.
161 char *gmx_strerror(const char *key);
162 /* Return error message corresponding to the key.
163 * Maybe a multi-line message.
164 * The messages are stored in src/gmxlib/fatal.c
167 void _gmx_error(const char *key, const char *msg, const char *file, int line) GMX_ATTRIBUTE_NORETURN;
168 #define gmx_error(key, msg) _gmx_error(key, msg, __FILE__, __LINE__)
169 /* Error msg of type key is generated and the program is
170 * terminated unless and error handle is set (see below)
173 /* Some common error types */
174 #define gmx_bug(msg) gmx_error("bug", msg)
175 #define gmx_call(msg) gmx_error("call", msg)
176 #define gmx_comm(msg) gmx_error("comm", msg)
177 #define gmx_file(msg) gmx_error("file", msg)
178 #define gmx_cmd(msg) gmx_error("cmd", msg)
179 #define gmx_impl(msg) gmx_error("impl", msg)
180 #define gmx_incons(msg) gmx_error("incons", msg)
181 #define gmx_input(msg) gmx_error("input", msg)
182 #define gmx_mem(msg) gmx_error("mem", msg)
183 #define gmx_open(fn) gmx_error("open", fn)
186 set_gmx_error_handler(void (*func)(const char *msg));
187 /* An error function will be called that terminates the program
188 * with a fatal error, unless you override it with another function.
190 * set_gmx_error_handler(my_func);
191 * where my_func is a function that takes a string as an argument.
192 * The string may be a multi-line string.
195 void gmx_warning(const char *fmt, ...);
196 /* Print a warning message to stderr.
197 * The format of fmt is that like printf etc, only %d, %x, %c, %f, %g and %s
198 * are allowed as format specifiers.
199 * The message string should NOT start with "WARNING"
200 * and should NOT end with a newline.
208 #endif /* _fatal_h */