-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathsundial.cpp
More file actions
44 lines (39 loc) · 1.34 KB
/
sundial.cpp
File metadata and controls
44 lines (39 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include "sundial.h"
void CheckFlag(const void *flagvalue, const char *funcname,
const int opt) {
int *errflag;
/* Check if SUNDIALS function returned NULL pointer - no memory allocated */
if (opt == 0 && flagvalue == NULL) {
fprintf(stderr, "\nSUNDIALS_ERROR: %s() failed - returned NULL pointer\n\n",
funcname);
throw std::runtime_error("SUNDIALS:Sundials error.");
return;
}
/* Check if flag < 0 */
else if (opt == 1) {
errflag = (int *) flagvalue;
if (*errflag < 0) {
fprintf(stderr, "\nSUNDIALS_ERROR: %s() failed with flag = %d\n\n",
funcname, *errflag);
throw std::runtime_error("SUNDIALS:Sundials error.");
return;
}
}
/* Check if function returned NULL pointer - no memory allocated */
else if (opt == 2 && flagvalue == NULL) {
fprintf(stderr, "\nMEMORY_ERROR: %s() failed - returned NULL pointer\n\n",
funcname);
throw std::runtime_error("SUNDIALS:Memory error.");
return;
}
/* Check if CV_SUCCESS for integration. */
else if (opt == 3) {
errflag = (int *) flagvalue;
if (*errflag != CV_SUCCESS) {
fprintf(stderr, "\nCV_SUCCESS error: %s() failed with flag = %d\n\n",
funcname, *errflag);
throw std::runtime_error("SUNDIALS:CV_SUCCESS error");
return;
}
}
}