# NAG Library Function Document

## 1Purpose

nag_2d_panel_sort (e02zac) sorts two-dimensional data into rectangular panels.

## 2Specification

 #include #include
 void nag_2d_panel_sort (Integer px, Integer py, const double lamda[], const double mu[], Integer m, const double x[], const double y[], Integer point[], NagError *fail)

## 3Description

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}-1\right]$, for $\mathit{i}=5,6,\dots ,{\mathbf{px}}-4$ and ${\mathbf{mu}}\left[\mathit{j}-1\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.

## 5Arguments

1:    $\mathbf{px}$IntegerInput
2:    $\mathbf{py}$IntegerInput
On entry: 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:    $\mathbf{lamda}\left[{\mathbf{px}}\right]$const doubleInput
On entry: ${\mathbf{lamda}}\left[4\right]$ to ${\mathbf{lamda}}\left[{\mathbf{px}}-5\right]$ must contain, in nondecreasing order, the intercepts on the $x$ axis of the sides of the panels parallel to the $y$ axis.
4:    $\mathbf{mu}\left[{\mathbf{py}}\right]$const doubleInput
On entry: ${\mathbf{mu}}\left[4\right]$ to ${\mathbf{mu}}\left[{\mathbf{py}}-5\right]$ must contain, in nondecreasing order, the intercepts on the $y$ axis of the sides of the panels parallel to the $x$ axis.
5:    $\mathbf{m}$IntegerInput
On entry: the number $m$ of data points.
6:    $\mathbf{x}\left[{\mathbf{m}}\right]$const doubleInput
7:    $\mathbf{y}\left[{\mathbf{m}}\right]$const doubleInput
On entry: the coordinates of the $\mathit{r}$th data point $\left({x}_{\mathit{r}},{y}_{\mathit{r}}\right)$, for $\mathit{r}=1,2,\dots ,m$.
8:    $\mathbf{point}\left[\mathit{dim}\right]$IntegerOutput
Note: the dimension, dim, of the array point must be at least $\left({\mathbf{m}}+\left({\mathbf{px}}-7\right)×\left({\mathbf{py}}-7\right)\right)$.
On exit: for $i=1,2,\dots ,\left({\mathbf{m}}+\left({\mathbf{px}}-7\right)×\left({\mathbf{py}}-7\right)\right)$, ${\mathbf{point}}\left[m+i-1\right]=\mathrm{I1}$ is the index of the first point in panel $i$, ${\mathbf{point}}\left[\mathrm{I1}-1\right]=\mathrm{I2}$ is the index of the second point in panel $i$ and so on.
${\mathbf{point}}\left[\mathrm{In}-1\right]=0$ indicates that ${\mathbf{x}}\left[\mathrm{In}-1\right],{\mathbf{y}}\left[\mathrm{In}-1\right]$ was the last point in the panel.
9:    $\mathbf{fail}$NagError *Input/Output
The NAG error argument (see Section 3.7 in How to Use the NAG Library and its Documentation).

## 6Error Indicators and Warnings

NE_ALLOC_FAIL
Dynamic memory allocation failed.
See Section 2.3.1.2 in How to Use the NAG Library and its Documentation for further information.
On entry, argument $〈\mathit{\text{value}}〉$ had an illegal value.
NE_INT
On entry, ${\mathbf{m}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{m}}>0$.
On entry, ${\mathbf{px}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{px}}\ge 8$.
On entry, ${\mathbf{py}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{py}}\ge 8$.
NE_INT_2
On entry, ${\mathbf{px}}=〈\mathit{\text{value}}〉$ and ${\mathbf{py}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{px}}\ge 8$ and ${\mathbf{py}}\ge 8$.
NE_INTERNAL_ERROR
An internal error has occurred in this function. Check the function call and any array sizes. If the call is correct then please contact NAG for assistance.
See Section 2.7.6 in How to Use the NAG Library and its Documentation for further information.
NE_NO_LICENCE
Your licence key may have expired or may not have been installed correctly.
See Section 2.7.5 in How to Use the NAG Library and its Documentation for further information.
NE_NOT_NON_DECREASING
On entry, $\mathit{I}=〈\mathit{\text{value}}〉$, ${\mathbf{lamda}}\left[\mathit{I}-1\right]=〈\mathit{\text{value}}〉$ and ${\mathbf{lamda}}\left[\mathit{I}-2\right]=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{lamda}}\left[\mathit{I}-1\right]\ge {\mathbf{lamda}}\left[\mathit{I}-2\right]$.
On entry, $\mathit{I}=〈\mathit{\text{value}}〉$, ${\mathbf{mu}}\left[\mathit{I}-1\right]=〈\mathit{\text{value}}〉$ and ${\mathbf{mu}}\left[\mathit{I}-2\right]=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{mu}}\left[\mathit{I}-1\right]\ge {\mathbf{mu}}\left[\mathit{I}-2\right]$.

Not applicable.

## 8Parallelism and Performance

nag_2d_panel_sort (e02zac) is not threaded in any implementation.

The time taken is approximately proportional to $m×\mathrm{log}\left(\left({\mathbf{m}}+\left({\mathbf{px}}-7\right)×\left({\mathbf{py}}-7\right)\right)\right)$.
This function was written to sort two-dimensional data in the manner required by function nag_2d_spline_fit_panel (e02dac). The first $9$ arguments of nag_2d_panel_sort (e02zac) are the same as the arguments in nag_2d_spline_fit_panel (e02dac) which have the same name.

## 10Example

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

### 10.1Program Text

Program Text (e02zace.c)

### 10.2Program Data

Program Data (e02zace.d)

### 10.3Program Results

Program Results (e02zace.r)

© The Numerical Algorithms Group Ltd, Oxford, UK. 2017