Merge branch 'master' of git@git.gromacs.org:gromacs
[gromacs/rigid-bodies.git] / include / gmx_fatal.h
bloba756bf8e0b833c6f344e10e8768f29dc12814737
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>
47 #include "typedefs.h"
49 #ifdef __cplusplus
50 extern "C" {
51 #endif
53 void
54 _where(const char *file,int line);
55 #define where() _where(__FILE__,__LINE__)
56 /* Prints filename and line to stdlog and only on amba memvail */
58 void
59 _set_fatal_tmp_file(const char *fn, const char *file, int line);
60 #define set_fatal_tmp_file(fn) _set_fatal_tmp_file(fn,__FILE__,__LINE__)
61 /* set filename to be removed when fatal_error is called */
63 void
64 _unset_fatal_tmp_file(const char *fn, const char *file, int line);
65 #define unset_fatal_tmp_file(fn) _unset_fatal_tmp_file(fn,__FILE__,__LINE__)
66 /* unsets filename to be removed */
68 void
69 gmx_fatal(int fatal_errno,const char *file,int line,const char *fmt,...);
70 #define FARGS 0,__FILE__,__LINE__
72 * Routine gmx_fatal prints
74 * "fatal error file %s line %s \n\t "
76 * followed by the string specified by fmt and supplied parameters. If
77 * errno is 0, only the message and arguments are printed. If errno is
78 * a legal system errno or -1, a perror like message is printed after the
79 * first message, if errno is -1, the last system errno will be used.
80 * The format of fmt is that like printf etc, only %d, %x, %c, %f, %g and %s
81 * are allowed as format specifiers.
83 * Tip of the week:
84 * call this function using the FARGS macro:
85 * gmx_fatal(FARGS,fmt,...)
88 extern void
89 gmx_fatal_collective(int f_errno,const char *file,int line,
90 bool bMaster,
91 const char *fmt,...);
92 /* As gmx_fatal, but only process with bMaster=TRUE prints the error message.
93 * This is useful for handling errors in code that is executed identically
94 * for all processes.
97 void
98 gmx_fatal_set_log_file(FILE *fp);
99 /* Set the log file for printing error messages */
101 void
102 _invalid_case(const char *fn,int line);
103 #define invalid_case() _invalid_case(__FILE__,__LINE__)
104 /* Issue a warning stating 'Invalid case in switch' */
106 extern void _unexpected_eof(const char *fn,int line,const char *srcfn,int srcline);
107 #define unexpected_eof(fn,line) _unexpected_eof(fn,line,__FILE__,__LINE__)
110 * Functions can write to this file for debug info
111 * Before writing to it, it should be checked whether
112 * the file is not NULL:
113 * if (debug) fprintf(debug,"%s","Hallo");
115 extern FILE *debug;
116 extern bool gmx_debug_at;
118 void init_debug (const int dbglevel,const char *dbgfile);
120 extern bool bDebugMode(void);
121 /* Return TRUE when the program was started in debug mode */
123 #if (defined __sgi && defined USE_SGI_FPE)
124 extern void doexceptions(void);
125 /* Set exception handlers for debugging */
126 #endif
128 /* warn_str is allowed to be NULL.
130 extern void _range_check(int n,int n_min,int n_max,const char *warn_str,
131 const char *var,
132 const char *file,int line);
134 #define range_check_mesg(n,n_min,n_max,str) _range_check(n,n_min,n_max,str,#n,__FILE__,__LINE__)
135 /* Range check will terminate with an error message if not
136 * n E [ n_min, n_max >
137 * That is n_min is inclusive but not n_max.
140 #define range_check(n,n_min,n_max) _range_check(n,n_min,n_max,NULL,#n,__FILE__,__LINE__)
141 /* Range check will terminate with an error message if not
142 * n E [ n_min, n_max >
143 * That is n_min is inclusive but not n_max.
146 extern char *gmx_strerror(const char *key);
147 /* Return error message corresponding to the key.
148 * Maybe a multi-line message.
149 * The messages are stored in src/gmxlib/fatal.c
152 extern void _gmx_error(const char *key,const char *msg,const char *file,int line);
153 #define gmx_error(key,msg) _gmx_error(key,msg,__FILE__,__LINE__)
154 /* Error msg of type key is generated and the program is
155 * terminated unless and error handle is set (see below)
158 /* Some common error types */
159 #define gmx_bug(msg) gmx_error("bug",msg)
160 #define gmx_call(msg) gmx_error("call",msg)
161 #define gmx_comm(msg) gmx_error("comm",msg)
162 #define gmx_file(msg) gmx_error("file",msg)
163 #define gmx_cmd(msg) gmx_error("cmd",msg)
164 #define gmx_impl(msg) gmx_error("impl",msg)
165 #define gmx_incons(msg) gmx_error("incons",msg)
166 #define gmx_input(msg) gmx_error("input",msg)
167 #define gmx_mem(msg) gmx_error("mem",msg)
168 #define gmx_open(fn) gmx_error("open",fn)
170 void
171 set_gmx_error_handler(void (*func)(const char *msg));
172 /* An error function will be called that terminates the program
173 * with a fatal error, unless you override it with another function.
174 * i.e.:
175 * set_gmx_error_handler(my_func);
176 * where my_func is a function that takes a string as an argument.
177 * The string may be a multi-line string.
180 extern void gmx_warning(const char *fmt,...);
181 /* Print a warning message to stderr.
182 * The format of fmt is that like printf etc, only %d, %x, %c, %f, %g and %s
183 * are allowed as format specifiers.
184 * The message string should NOT start with "WARNING"
185 * and should NOT end with a newline.
188 #ifdef __cplusplus
190 #endif
192 #endif /* _fatal_h */