E02 Chapter Contents
E02 Chapter Introduction
NAG Library Manual

# NAG Library Routine DocumentE02ZAF

Note:  before using this routine, please read the Users' Note for your implementation to check the interpretation of bold italicised terms and other implementation-dependent details.

## 1  Purpose

E02ZAF sorts two-dimensional data into rectangular panels.

## 2  Specification

 SUBROUTINE E02ZAF ( PX, PY, LAMDA, MU, M, X, Y, POINT, NPOINT, ADRES, NADRES, IFAIL)

## 3  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 subroutine 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 subroutine 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.

## 5  Parameters

1:     PX – INTEGERInput
2:     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:     LAMDA(PX) – REAL (KIND=nag_wp) arrayInput
On entry: ${\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.
4:     MU(PY) – REAL (KIND=nag_wp) arrayInput
On entry: ${\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.
5:     M – INTEGERInput
On entry: the number $m$ of data points.
6:     X(M) – REAL (KIND=nag_wp) arrayInput
7:     Y(M) – REAL (KIND=nag_wp) arrayInput
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:     POINT(NPOINT) – INTEGER arrayOutput
On exit: for $i=1,2,\dots ,{\mathbf{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 = M + I 10 IN = POINT(IN) IF (IN.EQ. 0) GOTO 20 XI = X(IN) YI = Y(IN) . . . GOTO 10 20 ... `
9:     NPOINT – INTEGERInput
On entry: the dimension of the array POINT as declared in the (sub)program from which E02ZAF is called.
Constraint: ${\mathbf{NPOINT}}\ge {\mathbf{M}}+\left({\mathbf{PX}}-7\right)×\left({\mathbf{PY}}-7\right)$.
On entry: the value $\left({\mathbf{PX}}-7\right)×\left({\mathbf{PY}}-7\right)$, the number of panels into which the $\left(x,y\right)$ plane is divided.
12:   IFAIL – INTEGERInput/Output
On entry: IFAIL must be set to $0$, $-1\text{​ or ​}1$. If you are unfamiliar with this parameter you should refer to Section 3.3 in the Essential Introduction for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value $-1\text{​ or ​}1$ is recommended. If the output of error messages is undesirable, then the value $1$ is recommended. Otherwise, if you are not familiar with this parameter, the recommended value is $0$. When the value $-\mathbf{1}\text{​ or ​}\mathbf{1}$ is used it is essential to test the value of IFAIL on exit.
On exit: ${\mathbf{IFAIL}}={\mathbf{0}}$ unless the routine detects an error or a warning has been flagged (see Section 6).

## 6  Error Indicators and Warnings

If on entry ${\mathbf{IFAIL}}={\mathbf{0}}$ or $-{\mathbf{1}}$, explanatory error messages are output on the current error message unit (as defined by X04AAF).
Errors or warnings detected by the routine:
${\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 ${\mathbf{NADRES}}\ne \left({\mathbf{PX}}-7\right)×\left({\mathbf{PY}}-7\right)$, or ${\mathbf{NPOINT}}<{\mathbf{M}}+\left({\mathbf{PX}}-7\right)×\left({\mathbf{PY}}-7\right)$.

## 7  Accuracy

Not applicable.

The time taken is approximately proportional to $m×\mathrm{log}\left({\mathbf{NPOINT}}\right)$.
This subroutine was written to sort two-dimensional data in the manner required by routine E02DAF. The first $9$ parameters of E02ZAF are the same as the parameters in E02DAF which have the same name.

## 9  Example

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

### 9.1  Program Text

Program Text (e02zafe.f90)

### 9.2  Program Data

Program Data (e02zafe.d)

### 9.3  Program Results

Program Results (e02zafe.r)