diff options
Diffstat (limited to 'packages/sundials/src/helpers.c')
-rw-r--r-- | packages/sundials/src/helpers.c | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/packages/sundials/src/helpers.c b/packages/sundials/src/helpers.c new file mode 100644 index 0000000..f0ca592 --- /dev/null +++ b/packages/sundials/src/helpers.c | |||
@@ -0,0 +1,44 @@ | |||
1 | #include <stdio.h> | ||
2 | #include <math.h> | ||
3 | #include <arkode/arkode.h> /* prototypes for ARKODE fcts., consts. */ | ||
4 | #include <nvector/nvector_serial.h> /* serial N_Vector types, fcts., macros */ | ||
5 | #include <sunmatrix/sunmatrix_dense.h> /* access to dense SUNMatrix */ | ||
6 | #include <sunlinsol/sunlinsol_dense.h> /* access to dense SUNLinearSolver */ | ||
7 | #include <arkode/arkode_direct.h> /* access to ARKDls interface */ | ||
8 | #include <sundials/sundials_types.h> /* definition of type realtype */ | ||
9 | #include <sundials/sundials_math.h> | ||
10 | |||
11 | /* Check function return value... | ||
12 | opt == 0 means SUNDIALS function allocates memory so check if | ||
13 | returned NULL pointer | ||
14 | opt == 1 means SUNDIALS function returns a flag so check if | ||
15 | flag >= 0 | ||
16 | opt == 2 means function allocates memory so check if returned | ||
17 | NULL pointer | ||
18 | */ | ||
19 | int check_flag(void *flagvalue, const char *funcname, int opt) | ||
20 | { | ||
21 | int *errflag; | ||
22 | |||
23 | /* Check if SUNDIALS function returned NULL pointer - no memory allocated */ | ||
24 | if (opt == 0 && flagvalue == NULL) { | ||
25 | fprintf(stderr, "\nSUNDIALS_ERROR: %s() failed - returned NULL pointer\n\n", | ||
26 | funcname); | ||
27 | return 1; } | ||
28 | |||
29 | /* Check if flag < 0 */ | ||
30 | else if (opt == 1) { | ||
31 | errflag = (int *) flagvalue; | ||
32 | if (*errflag < 0) { | ||
33 | fprintf(stderr, "\nSUNDIALS_ERROR: %s() failed with flag = %d\n\n", | ||
34 | funcname, *errflag); | ||
35 | return 1; }} | ||
36 | |||
37 | /* Check if function returned NULL pointer - no memory allocated */ | ||
38 | else if (opt == 2 && flagvalue == NULL) { | ||
39 | fprintf(stderr, "\nMEMORY_ERROR: %s() failed - returned NULL pointer\n\n", | ||
40 | funcname); | ||
41 | return 1; } | ||
42 | |||
43 | return 0; | ||
44 | } | ||