NAG FL Interface
e01zaf (dimn_​grid)

Settings help

FL Name Style:


FL Specification Language:


1 Purpose

e01zaf interpolates data at a point in n-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)
The routine may be called by the names e01zaf or nagf_interp_dimn_grid.

3 Description

e01zaf interpolates an n-dimensional point within a set of gridded data points, Z= {z1j1,z2j2,,zdjd} , with corresponding data values F= {f1j1,f2j2,,fdjd} where, for the ith dimension, ji=1,,ni and ni is the number of ordinates in the ith dimension.
A hypercube of (2k)d data points [h1,h2,,h(2k)d]Z, where hi=(hi1,hi2,,hid) and the corresponding data values are f(hi)F, around the given point, x=(x1,x2,,xd), is found and then used to interpolate using one of the following three methods.
  1. (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
    Q (x) = r=1 (2k)d wr (x) fr r=1 (2k)d wr (x) ,  
    where fr=f(hr), wr (x) = 1 D (|x-hr|) and D (y) = y1ρ+y2ρ++ydρ, for a given value of ρ.
  2. (ii)Linear Interpolation, which takes 2d surrounding data points (k=1) and performs two one-dimensional linear interpolations in each dimension on data points ha and hb, reducing the dimension every iteration until it has reached an answer. The formula for linear interpolation in dimension i is simply
    f = fa + (xi-hai) fb-fa hbi-hai ,  
    where fr=f(hr) and hai<xi<hbi.
  3. (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 (k=2), two in each direction (h−1,h0,h1,h2). The following is used to calculate the one-dimensional interpolant in dimension i
    f = 12 ( 1 t t2 t3 ) ( 0 2 0 0 −1 0 1 0 2 −5 4 −1 −1 3 −3 1 ) ( f−1 f0 f1 f2 )  
    where t=xi-h0i and fr=f(hr).

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: d Integer Input
On entry: d, the number of dimensions.
Constraint: d2.
2: narr(d) Integer array Input
On entry: the number of data ordinates in each dimension, with narr(i)=ni, for i=1,2,,d.
Constraint: narr(i)2.
3: uniform Logical Input
On entry: states whether the data points are uniformly spaced.
uniform=.TRUE.
The data points are uniformly spaced.
uniform=.FALSE.
The data points are not uniformly spaced.
Constraint: if method=3, uniform must be .TRUE..
4: axis(lx) 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 (x11,x1n1,,xd1,xdnd) .
If the data points are not uniformly spaced, axis should contain all the data ordinates for each dimension (x11,x12,,x1n1,,xd1,xd2,,xdnd).
Constraint: axis must be strictly increasing in each dimension.
5: lx Integer Input
On entry: the dimension of the array axis as declared in the (sub)program from which e01zaf is called.
Constraints:
  • if uniform=.TRUE., lx=2d;
  • if uniform=.FALSE., lx=i=1dnarr(i).
6: v(*) Real (Kind=nag_wp) array Input
Note: the dimension of the array v must be at least i=1 d narr(i).
On entry: holds the values of the data points in such an order that the index of a data value with coordinates (z1,z2,,zd) is
i=1 d zinSin,  
where Si={narr(l):l=1,,i-1} e.g., ((x11,x21,,xd1),(x12,x21,,xd1),,(x1nd,x21,,xd1),(x11,x22,,xd1),(x12,x22,,xd1),,(x1nd,x2nd,,xdnd)).
7: point(d) Real (Kind=nag_wp) array Input
On entry: x, 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: method Integer Input
On entry: the method to be used.
method=1
Weighted Average.
method=2
Linear Interpolation.
method=3
Cubic Interpolation.
Constraint: method=1, 2 or 3.
9: k Integer Input
On entry: if method=1, 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 (2k)d.
If method1, then k is not referenced and need not be set.
Constraint: if method=1, k1.
10: wf 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 method=1, 1.0wf15.0.
11: ans Real (Kind=nag_wp) Output
On exit: holds the result of the interpolation.
12: ifail Integer Input/Output
On entry: ifail must be set to 0, −1 or 1 to set behaviour on detection of an error; these values have no effect when no error is detected.
A value of 0 causes the printing of an error message and program execution will be halted; otherwise program execution continues. A value of −1 means that an error message is printed while a value of 1 means that it is not.
If halting is not appropriate, the value −1 or 1 is recommended. If message printing is undesirable, then the value 1 is recommended. Otherwise, the value 0 is recommended. When the value -1 or 1 is used it is essential to test the value of ifail on exit.
On exit: ifail=0 unless the routine detects an error or a warning has been flagged (see Section 6).

6 Error Indicators and Warnings

If on entry ifail=0 or −1, explanatory error messages are output on the current error message unit (as defined by x04aaf).
Errors or warnings detected by the routine:
ifail=1
On entry, d=value.
Constraint: d2.
ifail=2
On entry, narr(value)=value.
Constraint: narr(i)2.
ifail=4
On entry, axis decreases in dimension value.
Constraint: axis definition must be strictly increasing.
ifail=5
On entry, lx=value, d=value.
Constraint: if uniform=.TRUE., lx=2d.
On entry, lx=value, narr=value.
Constraint: if uniform=.FALSE., lx=narr.
ifail=7
On entry, k=value.
Constraint: if method=1, k1.
ifail=8
On entry, point(value)=value and data range =[value,value].
Constraint: point must be within the data range.
ifail=9
On entry, method=value.
Constraint: method=1, 2 or 3.
On entry, method=3 and uniform=.FALSE..
Constraint: if method=3, uniform must be .TRUE..
ifail=10
On entry, wf=value.
Constraint: if method=1, 1.0wf15.0.
ifail=101
Cubic Interpolation method does not have enough data surrounding point; interpolation not possible.
ifail=201
Warning: the size of k has been reduced, due to too few data points around point.
ifail=-99
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.
ifail=-399
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.
ifail=-999
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 wf<2.0 and k>1. This will include more data points and give them a greater influence to the answer.

8 Parallelism and Performance

Background information to multithreading can be found in the Multithreading documentation.
e01zaf is not threaded in any implementation.

9 Further Comments

None.

10 Example

This program takes a set of uniform three-dimensional grid data points which come from the function
f(x)= x13- x22+ x3 .  
e01zaf then interpolates the data at the point (1.10,0.25,0.75) using all three methods. The answers and the absolute errors are then printed.

10.1 Program Text

Program Text (e01zafe.f90)

10.2 Program Data

Program Data (e01zafe.d)

10.3 Program Results

Program Results (e01zafe.r)