NAG FL Interface
e01zaf (dimn_grid)
1
Purpose
e01zaf interpolates data at a point in -dimensional space, that is defined by a set of gridded data points. It offers three methods to interpolate the data: Linear Interpolation, Cubic Interpolation and Weighted Average.
2
Specification
Fortran Interface
Subroutine e01zaf ( |
d, narr, uniform, axis, lx, v, point, method, k, wf, ans, ifail) |
Integer, Intent (In) |
:: |
d, narr(d), lx, method, k |
Integer, Intent (Inout) |
:: |
ifail |
Real (Kind=nag_wp), Intent (In) |
:: |
axis(lx), v(*), point(d), wf |
Real (Kind=nag_wp), Intent (Out) |
:: |
ans |
Logical, Intent (In) |
:: |
uniform |
|
C Header Interface
#include <nag.h>
void |
e01zaf_ (const Integer *d, const Integer narr[], const logical *uniform, const double axis[], const Integer *lx, const double v[], const double point[], const Integer *method, const Integer *k, const double *wf, double *ans, Integer *ifail) |
|
C++ Header Interface
#include <nag.h> extern "C" {
void |
e01zaf_ (const Integer &d, const Integer narr[], const logical &uniform, const double axis[], const Integer &lx, const double v[], const double point[], const Integer &method, const Integer &k, const double &wf, double &ans, Integer &ifail) |
}
|
The routine may be called by the names e01zaf or nagf_interp_dimn_grid.
3
Description
e01zaf interpolates an -dimensional point within a set of gridded data points, , with corresponding data values where, for the th dimension, and is the number of ordinates in the th dimension.
A hypercube of
data points
, where
and the corresponding data values are
, around the given point,
, is found and then used to interpolate using one of the following three methods.
-
(i)Weighted Average, that is a modification of Shepard's method (Shepard (1968)) as used for scattered data in e01zmf. This method interpolates the data with the weighted mean
where , and , for a given value of .
-
(ii)Linear Interpolation, which takes surrounding data points () and performs two one-dimensional linear interpolations in each dimension on data points and , reducing the dimension every iteration until it has reached an answer. The formula for linear interpolation in dimension is simply
where and .
-
(iii)Cubic Interpolation, based on cubic convolution (Keys (1981)). In a similar way to the Linear Interpolation method, it performs the interpolations in one dimension reducing it each time, however it requires four surrounding data points in each dimension (), two in each direction . The following is used to calculate the one-dimensional interpolant in dimension
where and
.
4
References
Keys R (1981) Cubic Convolution Interpolation for Digital Image Processing
IEEE Transactions on Acoutstics, Speech, and Signal Processing Vol ASSP-29 No. 6 1153–1160
http://hmi.stanford.edu/doc/Tech_Notes/HMI-TN-2004-004-Interpolation/Keys_cubic_interp.pdf
Shepard D (1968) A two-dimensional interpolation function for irregularly spaced data Proc. 23rd Nat. Conf. ACM 517–523 Brandon/Systems Press Inc., Princeton
5
Arguments
-
1:
– Integer
Input
-
On entry: , the number of dimensions.
Constraint:
.
-
2:
– Integer array
Input
-
On entry: the number of data ordinates in each dimension, with
, for .
Constraint:
.
-
3:
– Logical
Input
-
On entry: states whether the data points are uniformly spaced.
- The data points are uniformly spaced.
- The data points are not uniformly spaced.
Constraint:
if
,
uniform must be .TRUE..
-
4:
– Real (Kind=nag_wp) array
Input
-
On entry: defines the axis. If the data points are uniformly spaced (see argument
uniform)
axis should contain the start and end of each dimension
.
If the data points are not uniformly spaced,
axis should contain all the data ordinates for each dimension
.
Constraint:
axis must be strictly increasing in each dimension.
-
5:
– Integer
Input
-
On entry: the dimension of the array
axis as declared in the (sub)program from which
e01zaf is called.
Constraints:
- if , ;
- if , .
-
6:
– Real (Kind=nag_wp) array
Input
Note: the dimension of the array
v
must be at least
.
On entry: holds the values of the data points in such an order that the index of a data value with coordinates
is
where
e.g.,
.
-
7:
– Real (Kind=nag_wp) array
Input
-
On entry: , the point at which the data value is to be interpolated.
Constraint:
the point must lie inside the limits of the data values in each dimension supplied in
axis.
-
8:
– Integer
Input
-
On entry: the method to be used.
- Weighted Average.
- Linear Interpolation.
- Cubic Interpolation.
Constraint:
, or .
-
9:
– Integer
Input
-
On entry: if
,
k controls the number of data points used in the Weighted Average method, with
k points used in each dimension, either side of the interpolation point. The total number of data points used for the interpolation will therefore be
.
If
, then
k is not referenced and need not be set.
Constraint:
if , .
-
10:
– Real (Kind=nag_wp)
Input
-
On entry: the power used for the weighted average such that a high power will cause closer points to be more heavily weighted.
Constraint:
if , .
-
11:
– Real (Kind=nag_wp)
Output
-
On exit: holds the result of the interpolation.
-
12:
– Integer
Input/Output
-
On entry:
ifail must be set to
,
or
to set behaviour on detection of an error; these values have no effect when no error is detected.
A value of causes the printing of an error message and program execution will be halted; otherwise program execution continues. A value of means that an error message is printed while a value of means that it is not.
If halting is not appropriate, the value
or
is recommended. If message printing is undesirable, then the value
is recommended. Otherwise, the value
is recommended.
When the value or is used it is essential to test the value of ifail on exit.
On exit:
unless the routine detects an error or a warning has been flagged (see
Section 6).
6
Error Indicators and Warnings
If on entry
or
, explanatory error messages are output on the current error message unit (as defined by
x04aaf).
Errors or warnings detected by the routine:
-
On entry, .
Constraint: .
-
On entry, .
Constraint: .
-
On entry,
axis decreases in dimension
.
Constraint:
axis definition must be strictly increasing.
-
On entry, , .
Constraint: if , .
On entry,
,
narr.
Constraint: if
,
.
-
On entry, .
Constraint: if , .
-
On entry,
and data range
.
Constraint:
point must be within the data range.
-
On entry, .
Constraint: , or .
On entry,
and
.
Constraint: if
,
uniform must be .TRUE..
-
On entry, .
Constraint: if , .
-
Cubic Interpolation method does not have enough data surrounding
point; interpolation not possible.
-
Warning: the size of
k has been reduced, due to too few data points around
point.
An unexpected error has been triggered by this routine. Please
contact
NAG.
See
Section 7 in the Introduction to the NAG Library FL Interface for further information.
Your licence key may have expired or may not have been installed correctly.
See
Section 8 in the Introduction to the NAG Library FL Interface for further information.
Dynamic memory allocation failed.
See
Section 9 in the Introduction to the NAG Library FL Interface for further information.
7
Accuracy
For most data the Cubic Interpolation method will provide the best interpolation but it is data dependent. If the data is linear, the Linear Interpolation method will be best. For noisy data the Weighted Average method is advised with and . This will include more data points and give them a greater influence to the answer.
8
Parallelism and Performance
e01zaf is not threaded in any implementation.
None.
10
Example
This program takes a set of uniform three-dimensional grid data points which come from the function
e01zaf then interpolates the data at the point using all three methods. The answers and the absolute errors are then printed.
10.1
Program Text
10.2
Program Data
10.3
Program Results