aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjthorn <jthorn@df1f8a13-aa1d-4dd4-9681-27ded5b42416>2004-06-27 10:52:05 +0000
committerjthorn <jthorn@df1f8a13-aa1d-4dd4-9681-27ded5b42416>2004-06-27 10:52:05 +0000
commit2240036087871e5ce61ec90a9655e09c81daaf19 (patch)
tree05d360de74d83c89cb9042c634abb6e3c4607c11
parent1e384d1c7dbd91b3b9ad1924e5f86e44f0a3628d (diff)
Cleanup of error handling:
* always return an error code if we find an error --> this fixes CactusBase/1623 ("LocalInterp reports error to screen, but does not return error code") * change error return codes to use #define codes in src/include/util_ErrorCodes.h src/include/cctk_Interp.h There should be no change in non-error behavior. git-svn-id: http://svn.cactuscode.org/arrangements/CactusBase/LocalInterp/trunk@185 df1f8a13-aa1d-4dd4-9681-27ded5b42416
-rw-r--r--src/Interpolate.c50
1 files changed, 29 insertions, 21 deletions
diff --git a/src/Interpolate.c b/src/Interpolate.c
index 024ee58..51ac0c5 100644
--- a/src/Interpolate.c
+++ b/src/Interpolate.c
@@ -31,7 +31,9 @@
#include <string.h>
#include <stdio.h>
+#include "util_ErrorCodes.h" /* defines error codes */
#include "cctk.h"
+#include "cctk_Interp.h" /* defines error codes */
#include "cctk_Parameters.h"
#include "Interpolate.h"
@@ -50,6 +52,9 @@ CCTK_FILEVERSION(CactusBase_LocalInterp_Interpolate_c)
/* the highest dimension for variables we can deal with (so far) */
#define MAXDIM 3
+/* we return this if we are successful */
+#define RETURN_SUCCESS 0
+
/******************************************************************************/
/*@@
@@ -293,46 +298,49 @@ int LocalInterp_Interpolate (int order,
CCTK_REAL coeff[MAXDIM][MAXORDER + 1];
- /* verify parameters and check against our restrictions */
- retval = -1;
+ retval = RETURN_SUCCESS;
+
+ /*
+ * verify parameters and check against our restrictions
+ */
if (num_dims < 1)
{
CCTK_WARN (1, "Number of dimensions must be positive");
+ return UTIL_ERROR_BAD_INPUT;
}
- else if (num_dims > MAXDIM)
+
+ if (num_dims > MAXDIM)
{
CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING,
"Interpolation of %d-dimensional arrays not implemented",
num_dims);
+ return UTIL_ERROR_BAD_INPUT;
}
- else if (order < 1)
+
+ if (order < 1)
{
CCTK_WARN (1, "Inperpolation order must be positive");
+ return UTIL_ERROR_BAD_INPUT;
}
- else if (order > MAXORDER)
+
+ if (order > MAXORDER)
{
CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING,
"Interpolation order %d not implemented", order);
+ return UTIL_ERROR_BAD_INPUT;
}
- else if (num_points < 0)
+
+ if (num_points < 0)
{
CCTK_WARN (1, "Negative number of points given");
- }
- else
- {
- retval = 0;
+ return UTIL_ERROR_BAD_INPUT;
}
- /* immediately return in case of errors */
- if (retval)
- {
- return (retval);
- }
/* also immediately return if there's nothing to do */
if (num_points == 0)
{
- return (retval);
+ return RETURN_SUCCESS;
}
/* avoid divisions by delta later on */
@@ -377,7 +385,7 @@ int LocalInterp_Interpolate (int order,
/* check that the stencil/molecule isn't bigger than the grid */
if (order+1 > dims[i]) /* stencil/molecule size = order+1 */
{
- return -1;
+ return CCTK_ERROR_INTERP_GRID_TOO_SMALL;
}
/* if beyond lower bound shift the grid point to the right */
@@ -464,10 +472,8 @@ if (n == LocalInterp_verbose_debug_n)
"Internal error: %d dimensions aren't supported", num_dims);
}
- /* the negative total number of out-of-bounds points will be returned */
- retval--;
-
- continue;
+ retval = CCTK_ERROR_INTERP_POINT_OUTSIDE;
+ continue; /* with next interpolation point */
}
/*
@@ -553,6 +559,7 @@ if (n == LocalInterp_verbose_debug_n)
CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING,
"Datatype for input and/or output array with index %d "
"is invalid", a);
+ retval = UTIL_ERROR_BAD_INPUT;
continue;
}
@@ -560,6 +567,7 @@ if (n == LocalInterp_verbose_debug_n)
if (in_types[a] != out_types[a])
{
CCTK_WARN (1, "Type casting of interpolation results not implemented");
+ retval = UTIL_ERROR_BAD_INPUT;
continue;
}