Enforced rotation: more rigorous calculation of ref centers
[gromacs/adressmacs.git] / include / gmx_fatal.h
blob13eb5ad00da646d82d80ce5e934563ed67d4c7b4
2 /*
3 *
4 * This source code is part of
5 *
6 * G R O M A C S
7 *
8 * GROningen MAchine for Chemical Simulations
9 *
10 * VERSION 3.2.0
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
33 * And Hey:
34 * Gromacs Runs On Most of All Computer Systems
37 #ifndef _fatal_h
38 #define _fatal_h
40 #ifdef HAVE_CONFIG_H
41 #include <config.h>
42 #endif
44 #include <stdio.h>
45 #include <stdarg.h>
46 #include <errno.h>
48 /* This include has now been moved upwards and the sky hasn't fallen... */
49 #include "typedefs.h"
51 #ifdef __cplusplus
52 extern "C" {
53 #endif
55 void
56 _where(const char *file,int line);
57 #define where() _where(__FILE__,__LINE__)
58 /* Prints filename and line to stdlog and only on amba memvail */
60 void
61 _set_fatal_tmp_file(const char *fn, const char *file, int line);
62 #define set_fatal_tmp_file(fn) _set_fatal_tmp_file(fn,__FILE__,__LINE__)
63 /* set filename to be removed when fatal_error is called */
65 void
66 _unset_fatal_tmp_file(const char *fn, const char *file, int line);
67 #define unset_fatal_tmp_file(fn) _unset_fatal_tmp_file(fn,__FILE__,__LINE__)
68 /* unsets filename to be removed */
70 void
71 gmx_fatal(int fatal_errno,const char *file,int line,const char *fmt,...);
72 #define FARGS 0,__FILE__,__LINE__
74 * Routine gmx_fatal prints
76 * "fatal error file %s line %s \n\t "
78 * followed by the string specified by fmt and supplied parameters. If
79 * errno is 0, only the message and arguments are printed. If errno is
80 * a legal system errno or -1, a perror like message is printed after the
81 * first message, if errno is -1, the last system errno will be used.
82 * The format of fmt is that like printf etc, only %d, %x, %c, %f and %s
83 * are allowed as format specifiers.
85 * Tip of the week:
86 * call this function using the FARGS macro:
87 * gmx_fatal(FARGS,fmt,...)
90 void
91 gmx_fatal_set_log_file(FILE *fp);
92 /* Set the log file for printing error messages */
94 void
95 init_warning(int maxwarning);
96 /* Set the max number of warnings */
98 void
99 set_warning_line(const char *fn,int line);
100 /* Set filename and linenumber for the warning */
102 int
103 get_warning_line(void);
104 /* Get linenumber for the warning */
107 const char *
108 get_warning_file(void);
109 /* Get filename for the warning */
111 extern char
112 warn_buf[1024];
113 /* Warning buffer of 1024 bytes, which can be used to print messages to */
115 void
116 warning(const char *s);
117 /* Issue a warning, with the string s. If s == NULL, then warn_buf
118 * will be printed instead. The file and line set by set_warning_line
119 * are printed, nwarn_warn (local) is incremented.
120 * A fatal error will be generated after processing the input
121 * when nwarn_warn is larger than maxwarning passed to init_warning.
122 * So warning should only be called for issues that should be resolved,
123 * otherwise warning_note should be called.
126 void
127 warning_note(const char *s);
128 /* Issue a note, with the string s. If s == NULL, then warn_buf
129 * will be printed instead. The file and line set by set_warning_line
130 * are printed, nwarn_note (local) is incremented.
131 * This is for issues which could be a problem for some systems,
132 * but 100% ok for other systems.
135 void
136 warning_error(const char *s);
137 /* Issue an error, with the string s. If s == NULL, then warn_buf
138 * will be printed instead. The file and line set by set_warning_line
139 * are printed, nwarn_error (local) is incremented.
142 void
143 check_warning_error(int f_errno,const char *file,int line);
144 /* When warning_error has been called at least once gmx_fatal is called,
145 * otherwise does nothing.
148 void
149 print_warn_num(bool bFatalError);
150 /* Print the total number of warnings, if larger than 0.
151 * When bFatalError == TRUE generates a fatal error
152 * when the number is larger than maxwarn.
155 void
156 _too_few(const char *fn,int line);
157 #define too_few() _too_few(__FILE__,__LINE__)
158 /* Issue a warning stating 'Too few parameters' */
160 void
161 _incorrect_n_param(const char *fn,int line);
162 #define incorrect_n_param() _incorrect_n_param(__FILE__,__LINE__)
163 /* Issue a warning stating 'Incorrect number of parameters' */
165 void
166 _invalid_case(const char *fn,int line);
167 #define invalid_case() _invalid_case(__FILE__,__LINE__)
168 /* Issue a warning stating 'Invalid case in switch' */
170 extern void _unexpected_eof(const char *fn,int line,const char *srcfn,int srcline);
171 #define unexpected_eof(fn,line) _unexpected_eof(fn,line,__FILE__,__LINE__)
174 * Functions can write to this file for debug info
175 * Before writing to it, it should be checked whether
176 * the file is not NULL:
177 * if (debug) fprintf(debug,"%s","Hallo");
179 extern FILE *debug;
180 extern bool gmx_debug_at;
182 void init_debug (const int dbglevel,const char *dbgfile);
184 extern bool bDebugMode(void);
185 /* Return TRUE when the program was started in debug mode */
187 #if (defined __sgi && defined USE_SGI_FPE)
188 extern void doexceptions(void);
189 /* Set exception handlers for debugging */
190 #endif
192 /* If msg == NULL, then warn_buf will be printed instead.
194 extern void _range_check(int n,int n_min,int n_max,const char *var,
195 const char *file,int line);
196 #define range_check(n,n_min,n_max) _range_check(n,n_min,n_max,#n,__FILE__,__LINE__)
197 /* Range check will terminate with an error message if not
198 * n E [ n_min, n_max >
199 * That is n_min is inclusive but not n_max.
202 extern char *gmx_strerror(const char *key);
203 /* Return error message corresponding to the key.
204 * Maybe a multi-line message.
205 * The messages are stored in src/gmxlib/fatal.c
208 extern void _gmx_error(const char *key,const char *msg,const char *file,int line);
209 #define gmx_error(key,msg) _gmx_error(key,msg,__FILE__,__LINE__)
210 /* Error msg of type key is generated and the program is
211 * terminated unless and error handle is set (see below)
214 /* Some common error types */
215 #define gmx_bug(msg) gmx_error("bug",msg)
216 #define gmx_call(msg) gmx_error("call",msg)
217 #define gmx_comm(msg) gmx_error("comm",msg)
218 #define gmx_file(msg) gmx_error("file",msg)
219 #define gmx_cmd(msg) gmx_error("cmd",msg)
220 #define gmx_impl(msg) gmx_error("impl",msg)
221 #define gmx_incons(msg) gmx_error("incons",msg)
222 #define gmx_input(msg) gmx_error("input",msg)
223 #define gmx_mem(msg) gmx_error("mem",msg)
224 #define gmx_open(fn) gmx_error("open",fn)
226 void
227 set_gmx_error_handler(void (*func)(const char *msg));
228 /* An error function will be called that terminates the program
229 * with a fatal error, unless you override it with another function.
230 * i.e.:
231 * set_gmx_error_handler(my_func);
232 * where my_func is a function that takes a string as an argument.
233 * The string may be a multi-line string.
236 #ifdef __cplusplus
238 #endif
240 #endif /* _fatal_h */