NAG FL Interface
e01daf (dim2_​spline_​grid)

Settings help

FL Name Style:


FL Specification Language:


1 Purpose

e01daf computes a bicubic spline interpolating surface through a set of data values, given on a rectangular grid in the x-y plane.

2 Specification

Fortran Interface
Subroutine e01daf ( mx, my, x, y, f, px, py, lamda, mu, c, wrk, ifail)
Integer, Intent (In) :: mx, my
Integer, Intent (Inout) :: ifail
Integer, Intent (Out) :: px, py
Real (Kind=nag_wp), Intent (In) :: x(mx), y(my), f(mx*my)
Real (Kind=nag_wp), Intent (Out) :: lamda(mx+4), mu(my+4), c(mx*my), wrk((mx+6)*(my+6))
C Header Interface
#include <nag.h>
void  e01daf_ (const Integer *mx, const Integer *my, const double x[], const double y[], const double f[], Integer *px, Integer *py, double lamda[], double mu[], double c[], double wrk[], Integer *ifail)
The routine may be called by the names e01daf or nagf_interp_dim2_spline_grid.

3 Description

e01daf determines a bicubic spline interpolant to the set of data points ( x q , y r , f q , r ) , for q=1,2,,mx and r=1,2,,my. The spline is given in the B-spline representation
s(x,y)=i=1mxj=1mycijMi(x)Nj(y),  
such that
s(xq,yr)=fq,r,  
where Mi(x) and Nj(y) denote normalized cubic B-splines, the former defined on the knots λi to λi+4 and the latter on the knots μj to μj+4, and the cij are the spline coefficients. These knots, as well as the coefficients, are determined by the routine, which is derived from the routine B2IRE in Anthony et al. (1982). The method used is described in Section 9.2.
For further information on splines, see Hayes and Halliday (1974) for bicubic splines and de Boor (1972) for normalized B-splines.
Values and derivatives of the computed spline can subsequently be computed by calling e02def, e02dff or e02dhf as described in Section 9.3.

4 References

Anthony G T, Cox M G and Hayes J G (1982) DASL – Data Approximation Subroutine Library National Physical Laboratory
Cox M G (1975) An algorithm for spline interpolation J. Inst. Math. Appl. 15 95–108
de Boor C (1972) On calculating with B-splines J. Approx. Theory 6 50–62
Hayes J G and Halliday J (1974) The least squares fitting of cubic spline surfaces to general data sets J. Inst. Math. Appl. 14 89–103

5 Arguments

1: mx Integer Input
2: my Integer Input
On entry: mx and my must specify mx and my respectively, the number of points along the x and y axis that define the rectangular grid.
Constraint: mx4 and my4.
3: x(mx) Real (Kind=nag_wp) array Input
4: y(my) Real (Kind=nag_wp) array Input
On entry: x(q) and y(r) must contain xq, for q=1,2,,mx, and yr, for r=1,2,,my, respectively.
Constraints:
  • x(q)<x(q+1), for q=1,2,,mx-1;
  • y(r)<y(r+1), for r=1,2,,my-1.
5: f(mx×my) Real (Kind=nag_wp) array Input
On entry: f(my×(q-1)+r) must contain fq,r, for q=1,2,,mx and r=1,2,,my.
6: px Integer Output
7: py Integer Output
On exit: px and py contain mx+4 and my+4, the total number of knots of the computed spline with respect to the x and y variables, respectively.
8: lamda(mx+4) Real (Kind=nag_wp) array Output
9: mu(my+4) Real (Kind=nag_wp) array Output
On exit: lamda contains the complete set of knots λi associated with the x variable, i.e., the interior knots lamda(5),lamda(6),,lamda(px-4), as well as the additional knots
lamda(1)=lamda(2)=lamda(3)=lamda(4)=x(1)  
and
lamda(px-3)=lamda(px-2)=lamda(px-1)=lamda(px)=x(mx)  
needed for the B-spline representation.
In a similar way, mu contains the set of knots associated with the y variable.
10: c(mx×my) Real (Kind=nag_wp) array Output
On exit: the coefficients of the spline interpolant. c(my×(i-1)+j) contains the coefficient cij described in Section 3.
11: wrk((mx+6)×(my+6)) Real (Kind=nag_wp) array Workspace
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, mx=value.
Constraint: mx4.
On entry, my=value.
Constraint: my4.
ifail=2
On entry, the x or the y mesh points are not in strictly ascending order.
ifail=3
An intermediate set of linear equations is singular – the data is too ill-conditioned to compute B-spline coefficients.
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

The main sources of rounding errors are in steps 2, 3, 6 and 7 of the algorithm described in Section 9.2. It can be shown (see Cox (1975)) that the matrix Ax formed in step 2 has elements differing relatively from their true values by at most a small multiple of 3ε, where ε is the machine precision. Ax is ‘totally positive’, and a linear system with such a coefficient matrix can be solved quite safely by elimination without pivoting. Similar comments apply to steps 6 and 7. Thus the complete process is numerically stable.

8 Parallelism and Performance

e01daf makes calls to BLAS and/or LAPACK routines, which may be threaded within the vendor library used by this implementation. Consult the documentation for the vendor library for further information.
Please consult the X06 Chapter Introduction for information on how to control and interrogate the OpenMP environment used within this routine. Please also consult the Users' Note for your implementation for any additional implementation-specific information.

9 Further Comments

9.1 Timing

The time taken by e01daf is approximately proportional to mxmy.

9.2 Outline of Method Used

The process of computing the spline consists of the following steps:
  1. 1.choice of the interior x-knots λ5, λ6,,λmx as λi=xi-2, for i=5,6,,mx,
  2. 2.formation of the system
    AxE=F,  
    where Ax is a band matrix of order mx and bandwidth 4, containing in its qth row the values at xq of the B-splines in x, f is the mx×my rectangular matrix of values fq,r, and E denotes an mx×my rectangular matrix of intermediate coefficients,
  3. 3.use of Gaussian elimination to reduce this system to band triangular form,
  4. 4.solution of this triangular system for E,
  5. 5.choice of the interior y knots μ5, μ6,,μmy as μi=yi-2, for i=5,6,,my,
  6. 6.formation of the system
    AyCT=ET,  
    where Ay is the counterpart of Ax for the y variable, and C denotes the mx×my rectangular matrix of values of cij,
  7. 7.use of Gaussian elimination to reduce this system to band triangular form,
  8. 8.solution of this triangular system for CT and hence C.
For computational convenience, steps 2 and 3, and likewise steps 6 and 7, are combined so that the formation of Ax and Ay and the reductions to triangular form are carried out one row at a time.

9.3 Evaluation of Computed Spline

The values of the computed spline at the points (xk,yk) , for k=1,2,,m, may be obtained in the real array ff (see e02def), of length at least m, by the following call:
ifail = 0
Call e02def(m,px,py,x,y,lamda,mu,c,ff,wrk,iwrk,ifail)
where M=m and the coordinates xk, yk are stored in X(k), Y(k). PX and PY, LAMDA, MU and C have the same values as px and py lamda, mu and c output from e01daf. WRK is a real workspace array of length at least PY, and IWRK is an integer workspace array of length at least PY-4. (See e02def.)
To evaluate the computed spline on an mx×my rectangular grid of points in the x-y plane, which is defined by the x coordinates stored in x(j), for j=1,2,,mx, and the y coordinates stored in y(k), for k=1,2,,my , returning the results in the real array ff (see e02dff) which is of length at least mx×my, the following call may be used:
 ifail = 0
 Call e02dff(mx,my,px,py,x,y,lamda,mu,c,fg,wrk,lwrk,
*            iwrk,liwrk,ifail)
where MX=mx, MY=my. PX and PY, LAMDA, MU and C have the same values as px, py, lamda, mu and c output from e01daf. WRK is a real workspace array of length at least LWRK = min(nwrk1,nwrk2) , for nwrk1 = MX × 4 + PX , nwrk2 = MY × 4 + PY , and IWRK is an integer workspace array of length at least LIWRK = MY + PY - 4 if nwrk1 > nwrk2 , or MX + PX - 4 otherwise.
The result of the spline evaluated at grid point (j,k) is returned in element ( MY×(j-1)+k ) of the array FG.

10 Example

This example reads in values of mx, xq, for q=1,2,,mx, my and yr, for r=1,2,,my, followed by values of the ordinates fq,r defined at the grid points (xq,yr).
It then calls e01daf to compute a bicubic spline interpolant of the data values, and prints the values of the knots and B-spline coefficients. Finally it evaluates the spline at a small sample of points on a rectangular grid.

10.1 Program Text

Program Text (e01dafe.f90)

10.2 Program Data

Program Data (e01dafe.d)

10.3 Program Results

Program Results (e01dafe.r)