Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

Chapter Contents
Chapter Introduction
NAG Toolbox

# NAG Toolbox: nag_fit_2dspline_sort (e02za)

## Purpose

nag_fit_2dspline_sort (e02za) sorts two-dimensional data into rectangular panels.

## Syntax

[point, ifail] = e02za(lamda, mu, x, y, 'px', px, 'py', py, 'm', m)
[point, ifail] = nag_fit_2dspline_sort(lamda, mu, x, y, 'px', px, 'py', py, 'm', m)

## Description

A set of $m$ data points with rectangular Cartesian coordinates ${x}_{r},{y}_{r}$ are sorted into panels defined by lines parallel to the $y$ and $x$ axes. The intercepts of these lines on the $x$ and $y$ axes are given in ${\mathbf{lamda}}\left(\mathit{i}\right)$, for $\mathit{i}=5,6,\dots ,{\mathbf{px}}-4$ and ${\mathbf{mu}}\left(\mathit{j}\right)$, for $\mathit{j}=5,6,\dots ,{\mathbf{py}}-4$, respectively. The function orders the data so that all points in a panel occur before data in succeeding panels, where the panels are numbered from bottom to top and then left to right, with the usual arrangement of axes, as shown in the diagram. Within a panel the points maintain their original order.
Figure 1
A data point lying exactly on one or more panel sides is taken to be in the highest-numbered panel adjacent to the point. The function does not physically rearrange the data, but provides the array point which contains a linked list for each panel, pointing to the data in that panel. The total number of panels is $\left({\mathbf{px}}-7\right)×\left({\mathbf{py}}-7\right)$.

None.

## Parameters

### Compulsory Input Parameters

1:     $\mathrm{lamda}\left({\mathbf{px}}\right)$ – double array
${\mathbf{lamda}}\left(5\right)$ to ${\mathbf{lamda}}\left({\mathbf{px}}-4\right)$ must contain, in nondecreasing order, the intercepts on the $x$ axis of the sides of the panels parallel to the $y$ axis.
2:     $\mathrm{mu}\left({\mathbf{py}}\right)$ – double array
${\mathbf{mu}}\left(5\right)$ to ${\mathbf{mu}}\left({\mathbf{py}}-4\right)$ must contain, in nondecreasing order, the intercepts on the $y$ axis of the sides of the panels parallel to the $x$ axis.
3:     $\mathrm{x}\left({\mathbf{m}}\right)$ – double array
4:     $\mathrm{y}\left({\mathbf{m}}\right)$ – double array
The coordinates of the $\mathit{r}$th data point $\left({x}_{\mathit{r}},{y}_{\mathit{r}}\right)$, for $\mathit{r}=1,2,\dots ,m$.

### Optional Input Parameters

1:     $\mathrm{px}$int64int32nag_int scalar
2:     $\mathrm{py}$int64int32nag_int scalar
Default: the dimension of the arrays lamda, mu. (An error is raised if these dimensions are not equal.)
px and py must specify eight more than the number of intercepts on the $x$ axis and $y$ axis, respectively.
Constraint: ${\mathbf{px}}\ge 8$ and ${\mathbf{py}}\ge 8$.
3:     $\mathrm{m}$int64int32nag_int scalar
Default: the dimension of the arrays x, y. (An error is raised if these dimensions are not equal.)
The number $m$ of data points.

### Output Parameters

1:     $\mathrm{point}\left(\mathit{npoint}\right)$int64int32nag_int array
$\mathit{npoint}={\mathbf{m}}+\left({\mathbf{px}}-7\right)×\left({\mathbf{py}}-7\right)$.
For $i=1,2,\dots ,\mathit{npoint}$, ${\mathbf{point}}\left(m+i\right)=\mathrm{I1}$ is the index of the first point in panel $i$, ${\mathbf{point}}\left(\mathrm{I1}\right)=\mathrm{I2}$ is the index of the second point in panel $i$ and so on.
${\mathbf{point}}\left(\mathrm{In}\right)=0$ indicates that ${\mathbf{x}}\left(\mathrm{In}\right),{\mathbf{y}}\left(\mathrm{In}\right)$ was the last point in the panel.
The coordinates of points in panel $i$ can be accessed in turn by means of the following instructions:
in = point(m+i);

while (in ~= 0)

xi = x(in);

yi = y(in);

.

.

.

in = point(in);

end

...
2:     $\mathrm{ifail}$int64int32nag_int scalar
${\mathbf{ifail}}={\mathbf{0}}$ unless the function detects an error (see Error Indicators and Warnings).

## Error Indicators and Warnings

Errors or warnings detected by the function:
${\mathbf{ifail}}=1$
The intercepts in the array lamda, or in the array mu, are not in nondecreasing order.
${\mathbf{ifail}}=2$
 On entry, ${\mathbf{px}}<8$, or ${\mathbf{py}}<8$, or ${\mathbf{m}}\le 0$, or $\mathit{nadres}\ne \left({\mathbf{px}}-7\right)×\left({\mathbf{py}}-7\right)$, or $\mathit{npoint}<{\mathbf{m}}+\left({\mathbf{px}}-7\right)×\left({\mathbf{py}}-7\right)$.
${\mathbf{ifail}}=-99$
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.

## Accuracy

Not applicable.

The time taken is approximately proportional to $m×\mathrm{log}\left(\mathit{npoint}\right)$.
This function was written to sort two-dimensional data in the manner required by function nag_fit_2dspline_panel (e02da). The first $9$ arguments of nag_fit_2dspline_sort (e02za) are the same as the arguments in nag_fit_2dspline_panel (e02da) which have the same name.

## Example

This example reads in data points and the intercepts of the panel sides on the $x$ and $y$ axes; it calls nag_fit_2dspline_sort (e02za) to set up the index array point; and finally it prints the data points in panel order.
function e02za_example

fprintf('e02za example results\n\n');

xknots = [1];       kx = size(xknots,2);
yknots = [0.8 1.2]; ky = size(yknots,2);

lamda = zeros(kx+8,1);
mu    = zeros(ky+8,1);
lamda(5:kx+4) = xknots;
mu(5:ky+4)    = yknots;

x = [0.00  0.70  1.44  0.21  1.01  1.84  0.71  1.00  0.54  1.53];
y = [0.77  1.06  0.33  0.44  0.50  0.02  1.95  1.20  0.04  0.18];
m = size(x,2);

[point, ifail] = e02za(lamda, mu, x, y);

% Output points in panel order

for i = 1:(kx+1)*(ky+1)
fprintf('\nPanel %4d\n', i);
ip = m + i;

while ip>0
ip = point(ip);
if (ip>0)
fprintf('%7.2f%7.2f\n',x(ip), y(ip));
end
end
end

e02za example results

Panel    1
0.00   0.77
0.21   0.44
0.54   0.04

Panel    2
0.70   1.06

Panel    3
0.71   1.95

Panel    4
1.44   0.33
1.01   0.50
1.84   0.02
1.53   0.18

Panel    5

Panel    6
1.00   1.20