Toast++
1.0.2 (r.539)
Forward and inverse modelling in optical tomography
Main Page
Related Pages
Modules
Classes
Files
File List
libmath
error.h
1
// -*-C++-*-
2
// ==========================================================================
3
// Module mathlib
4
// File error.h
5
// Error handling routines
6
// ==========================================================================
7
8
#ifndef __ERROR_H
9
#define __ERROR_H
10
11
#include "toastdef.h"
12
#include <fstream>
13
#include <iostream>
14
#include <stdio.h>
15
#include <stdarg.h>
16
17
#ifndef VERBOSE_LEVEL
18
#ifdef FEM_DEBUG
19
#define VERBOSE_LEVEL 0
20
#else
21
#define VERBOSE_LEVEL 0
22
#endif // FEM_DEBUG
23
#endif // !VERBOSE_LEVEL
24
25
#ifndef __FUNCTION__
26
#define __FUNCTION__ ""
27
#endif
28
29
#ifndef __PRETTY_FUNCTION__
30
#define __PRETTY_FUNCTION__ ""
31
#endif
32
33
MATHLIB
extern
int
toastVerbosity;
// global verbosity flag
34
35
#define ERROR_UNDEF Error_Undef(__PRETTY_FUNCTION__,__FILE__,__LINE__)
36
37
// unconditional error checking
38
#define xERROR(msg, ...) Error(__PRETTY_FUNCTION__,__FILE__,__LINE__, msg, ##__VA_ARGS__)
39
#define xASSERT(cond, msg, ...) if (!(cond)) xERROR(msg, ##__VA_ARGS__ )
40
#define xRANGE_CHECK(cond) if (!(cond)) xERROR("Index out of range.");
41
42
// error checking in debug environment
43
#ifdef FEM_DEBUG
44
#define dERROR(msg, ...) Error(__PRETTY_FUNCTION__,__FILE__,__LINE__, msg, ##__VA_ARGS__)
45
#define dASSERT(cond, msg, ...) if (!(cond)) dERROR(msg, ##__VA_ARGS__)
46
#define RANGE_CHECK(cond) if (!(cond)) dERROR("Index out of range.");
47
#else
48
#define dERROR(msg,...)
49
#define dASSERT(cond,msg,...)
50
#define RANGE_CHECK(cond)
51
#endif
52
53
// output to log file for different verbose levels
54
#define LOGOUT_ON LogoutOn()
55
#define LOGOUT_OFF LogoutOff()
56
#define LOGOUT(msg, ...) LogOut(msg, ##__VA_ARGS__)
57
#define LOGOUT_ENTER LogOut_Enter(__FUNCTION__)
58
#define LOGOUT_OPEN(msg) LogOut_Enter(msg)
59
#define LOGOUT_EXIT LogOut_Exit()
60
#define LOGOUT_INIT_PROGRESSBAR(name,len,maxcount) \
61
LogOut_InitProgressbar(name,len,maxcount)
62
#define LOGOUT_PROGRESS(count) LogOut_Progress(count)
63
64
#if (VERBOSE_LEVEL >= 1)
65
#define LOGOUT1(msg,...) LogOut(msg, ##__VA_ARGS__)
66
#define LOGOUT1_ENTER LogOut_Enter(__FUNCTION__)
67
#define LOGOUT1_OPEN(msg) LogOut_Enter(msg)
68
#define LOGOUT1_EXIT LogOut_Exit()
69
#define LOGOUT1_INIT_PROGRESSBAR(name,len,maxcount) \
70
LogOut_InitProgressbar(name,len,maxcount)
71
#define LOGOUT1_PROGRESS(count) LogOut_Progress(count)
72
#else
73
#define LOGOUT1(msg,...)
74
#define LOGOUT1_ENTER
75
#define LOGOUT1_OPEN(msg)
76
#define LOGOUT1_EXIT
77
#define LOGOUT1_INIT_PROGRESSBAR(name,len,maxcount)
78
#define LOGOUT1_PROGRESS(count)
79
#endif
80
81
#if (VERBOSE_LEVEL >= 2)
82
#define LOGOUT2(msg,...) LogOut(msg, ##__VA_ARGS__)
83
#define LOGOUT2_ENTER LogOut_Enter(__FUNCTION__)
84
#define LOGOUT2_OPEN(msg) LogOut_Enter(msg)
85
#define LOGOUT2_EXIT LogOut_Exit()
86
#define LOGOUT2_INIT_PROGRESSBAR(name,len,maxcount) \
87
LogOut_InitProgressbar(name,len,maxcount)
88
#define LOGOUT2_PROGRESS(count) LogOut_Progress(count)
89
#else
90
#define LOGOUT2(msg,...)
91
#define LOGOUT2_ENTER
92
#define LOGOUT2_OPEN(msg)
93
#define LOGOUT2_EXIT
94
#define LOGOUT2_INIT_PROGRESSBAR(name,len,maxcount)
95
#define LOGOUT2_PROGRESS(count)
96
#endif
97
98
// version string macros and functions
99
void
SetVersion (
const
char
*vstr);
100
MATHLIB
const
char
*Version (
const
char
*type,
const
char
*date);
101
void
OutputProgramInfo (std::ostream &os);
102
103
#ifdef FEM_DEBUG
104
#define VERSION_STRING Version("DEBUG", __DATE__)
105
#else
106
#define VERSION_STRING Version("RELEASE", __DATE__)
107
#endif
108
109
// handling of template instantiation
110
#ifdef __BORLANDC__
111
#define INSTTEMPLATE
112
#else
113
#define INSTTEMPLATE template
114
#endif
115
116
// error routines
117
MATHLIB
void
SetErrorhandler (
void
(*ErrorFunc)(
char
*));
118
MATHLIB
void
Error (
const
char
*name,
const
char
*file,
int
line);
119
MATHLIB
void
Error (
const
char
*name,
const
char
*file,
int
line,
const
char
*msg, ...);
120
MATHLIB
void
Error_Undef (
const
char
*name,
const
char
*file,
int
line);
121
122
// log file output routines
123
void
LogoutOn();
// turn on output to log file
124
void
LogoutOff();
// turn off output to log file
125
MATHLIB
void
LogfileOpen (
const
char
*fname,
bool
rewind =
false
);
126
void
LogfileClose ();
// close an open log file
127
MATHLIB
void
LogOut (
const
char
*msg, ...);
// write message `msg' to log file
128
void
LogOut_Enter (
const
char
*routine);
// write `enter' note to log file
129
void
LogOut_Exit ();
// write `leave routine' note to log file
130
MATHLIB
void
LogOut_InitProgressbar (
const
char
*name,
int
len,
int
maxcount);
131
// initialise output of progress bar of `len' characters, to monitor
132
// progress up to `maxcount'
133
MATHLIB
void
LogOut_Progress (
int
count);
134
// set progress bar to show state `count' of `maxcount'
135
#ifndef __ERROR_CC
136
MATHLIB
extern
char
logbuf[256];
137
MATHLIB
extern
std::ofstream logfile;
138
#endif
139
140
// expiry-checking routines
141
void
SetExpiryhandler (
void
(*ExpiryFunc)());
142
MATHLIB
void
Check_Expired (
int
month,
int
year);
143
#ifdef EXPIRY_YEAR
144
#ifndef EXPIRY_MONTH
145
#define EXPIRY_MONTH 1
146
#endif // !EXPIRY_MONTH
147
#define CHECK_EXPIRED() Check_Expired(EXPIRY_MONTH,EXPIRY_YEAR)
148
#else
149
#define CHECK_EXPIRED()
150
#endif // EXPIRY_YEAR
151
152
// flop counting routines
153
void
ResetFlops();
154
unsigned
int
FlopsAdd();
155
unsigned
int
FlopsMul();
156
void
Inc_FlopsAdd (
unsigned
int
n);
157
void
Inc_FlopsMul (
unsigned
int
n);
158
#ifdef COMPUTE_FLOPS
159
#define INC_FLOPS_ADD(n) Inc_FlopsAdd(n)
160
#define INC_FLOPS_MUL(n) Inc_FlopsMul(n)
161
#else
162
#define INC_FLOPS_ADD(n)
163
#define INC_FLOPS_MUL(n)
164
#endif
165
166
#endif // !__ERROR_H
Generated on Tue Sep 2 2014 17:14:26 for Toast++ by
1.8.6