summaryrefslogtreecommitdiff
path: root/packages/sundials/src/helpers.c
diff options
context:
space:
mode:
authorDominic Steinitz <dominic@steinitz.org>2018-03-11 14:21:31 +0000
committerDominic Steinitz <dominic@steinitz.org>2018-03-11 14:21:31 +0000
commita22963fa83156b76dd73777b7044897eed50e3bc (patch)
tree325c1f1d19bb0764290650770733e6bf8db171f8 /packages/sundials/src/helpers.c
parentd83b17190029c11e3ab8b504e5cdc917f5863120 (diff)
The start of an hmatrix interface to sundials
Diffstat (limited to 'packages/sundials/src/helpers.c')
-rw-r--r--packages/sundials/src/helpers.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/packages/sundials/src/helpers.c b/packages/sundials/src/helpers.c
new file mode 100644
index 0000000..3498119
--- /dev/null
+++ b/packages/sundials/src/helpers.c
@@ -0,0 +1,37 @@
1#include <stdio.h>
2#include "helpers.h"
3
4/* Check function return value...
5 opt == 0 means SUNDIALS function allocates memory so check if
6 returned NULL pointer
7 opt == 1 means SUNDIALS function returns a flag so check if
8 flag >= 0
9 opt == 2 means function allocates memory so check if returned
10 NULL pointer
11*/
12int check_flag(void *flagvalue, const char *funcname, int opt)
13{
14 int *errflag;
15
16 /* Check if SUNDIALS function returned NULL pointer - no memory allocated */
17 if (opt == 0 && flagvalue == NULL) {
18 fprintf(stderr, "\nSUNDIALS_ERROR: %s() failed - returned NULL pointer\n\n",
19 funcname);
20 return 1; }
21
22 /* Check if flag < 0 */
23 else if (opt == 1) {
24 errflag = (int *) flagvalue;
25 if (*errflag < 0) {
26 fprintf(stderr, "\nSUNDIALS_ERROR: %s() failed with flag = %d\n\n",
27 funcname, *errflag);
28 return 1; }}
29
30 /* Check if function returned NULL pointer - no memory allocated */
31 else if (opt == 2 && flagvalue == NULL) {
32 fprintf(stderr, "\nMEMORY_ERROR: %s() failed - returned NULL pointer\n\n",
33 funcname);
34 return 1; }
35
36 return 0;
37}