aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Interpolate.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/src/Interpolate.c b/src/Interpolate.c
index b387b19..65e797a 100644
--- a/src/Interpolate.c
+++ b/src/Interpolate.c
@@ -17,6 +17,7 @@
@version $Id$
@@*/
+#include <math.h>
#include <stdlib.h>
#include <string.h>
@@ -250,8 +251,16 @@ int PUGHInterp_Interpolate (int order,
/* loop over all dimensions */
for (i = 0; i < num_dims; i++)
{
- /* nearest grid point for stencil */
- point[i] = (coord[num_dims*n + i] - origin[i]) / delta[i];
+ /* closest grid point for stencil */
+ point[i] = floor ((coord[num_dims*n + i] - origin[i]) / delta[i]
+ - 0.5 * (order - 1));
+
+ /* if beyond lower bound shift the grid point to the right */
+ shift = point[i];
+ if (shift < 0)
+ {
+ point[i] -= shift;
+ }
/* if beyond upper bound shift the grid point to the left */
shift = point[i] + order - (dims[i] - 1);