NAG Library Routine Document

e02zaf (dim2_spline_sort)


    1  Purpose
    7  Accuracy


e02zaf sorts two-dimensional data into rectangular panels.


Fortran Interface
Subroutine e02zaf ( px, py, lamda, mu, m, x, y, point, npoint, adres, nadres, ifail)
Integer, Intent (In):: px, py, m, npoint, nadres
Integer, Intent (Inout):: ifail
Integer, Intent (Out):: point(npoint), adres(nadres)
Real (Kind=nag_wp), Intent (In):: lamda(px), mu(py), x(m), y(m)
C Header Interface
#include nagmk26.h
void  e02zaf_ (const Integer *px, const Integer *py, const double lamda[], const double mu[], const Integer *m, const double x[], const double y[], Integer point[], const Integer *npoint, Integer adres[], const Integer *nadres, Integer *ifail)


A set of m data points with rectangular Cartesian coordinates xr,yr 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 lamdai, for i=5,6,,px-4 and muj, for j=5,6,,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
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 px-7×py-7.




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: px8 and py8.
3:     lamdapx – Real (Kind=nag_wp) arrayInput
On entry: lamda5 to lamdapx-4 must contain, in nondecreasing order, the intercepts on the x axis of the sides of the panels parallel to the y axis.
4:     mupy – Real (Kind=nag_wp) arrayInput
On entry: mu5 to mupy-4 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:     xm – Real (Kind=nag_wp) arrayInput
7:     ym – Real (Kind=nag_wp) arrayInput
On entry: the coordinates of the rth data point xr,yr, for r=1,2,,m.
8:     pointnpoint – Integer arrayOutput
On exit: for i=1,2,,npoint, pointm+i=I1 is the index of the first point in panel i, pointI1=I2 is the index of the second point in panel i and so on.
pointIn=0 indicates that xIn,yIn 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: npointm+px-7×py-7.
10:   adresnadres – Integer arrayWorkspace
11:   nadres – IntegerInput
On entry: the value px-7×py-7, the number of panels into which the x,y plane is divided.
12:   ifail – IntegerInput/Output
On entry: ifail must be set to 0, -1​ or ​1. If you are unfamiliar with this argument you should refer to Section 3.4 in How to Use the NAG Library and its Documentation for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value -1​ 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 argument, the recommended value is 0. 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).

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:
The intercepts in the array lamda, or in the array mu, are not in nondecreasing order.
On entry,px<8,
An unexpected error has been triggered by this routine. Please contact NAG.
See Section 3.9 in How to Use the NAG Library and its Documentation for further information.
Your licence key may have expired or may not have been installed correctly.
See Section 3.8 in How to Use the NAG Library and its Documentation for further information.
Dynamic memory allocation failed.
See Section 3.7 in How to Use the NAG Library and its Documentation for further information.


Not applicable.

Parallelism and Performance

e02zaf is not threaded in any implementation.

Further Comments

The time taken is approximately proportional to m×lognpoint.
This subroutine was written to sort two-dimensional data in the manner required by routine e02daf. The first 9 arguments of e02zaf are the same as the arguments in e02daf which have the same name.


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.

Program Text

Program Text (e02zafe.f90)

Program Data

Program Data (e02zafe.d)

Program Results

Program Results (e02zafe.r)

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