M01DZF ranks arbitrary data according to a user-supplied comparison routine.
M01DZF is a general purpose routine for ranking arbitrary data. M01DZF does not access the data directly; instead it calls
COMPAR to determine the relative ordering of any two data items. The data items are identified simply by an integer in the range
M1 to
M2.
M01DZF uses a variant of list-merging, as described on pages 165–166 in
Knuth (1973). The routine takes advantage of natural ordering in the data, and uses a simple list insertion in a preparatory pass to generate ordered lists of length at least
$10$.
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).
Not applicable.
Not applicable.
The average time taken by the routine is approximately proportional to
$n\times \mathrm{log}\left(n\right)$, where
$n={\mathbf{M2}}-{\mathbf{M1}}+1$; it will usually be dominated by the time taken in
COMPAR.
This example reads records, each of which contains an integer key and a real number. The program ranks the records first of all in ascending order of the integer key; records with equal keys are ranked in descending order of the real number if the key is negative, in ascending order of the real number if the key is positive, and in their original order if the key is zero. After calling M01DZF, the program calls
M01ZAF to convert the ranks to indices, and prints the records in rank order. Note the use of COMMON to communicate the data between the main program and
COMPAR.