NAG Library Routine Document
M01DCF ranks a vector of character data in ASCII or reverse ASCII order of a specified substring.
||M1, M2, L1, L2, IRANK(M2), IFAIL
M01DCF 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
. The ranking is stable: equal elements preserve their ordering in the input data.
Only the substring (L1
) of each element of the array CH
is used to determine the rank order.
Knuth D E (1973) The Art of Computer Programming (Volume 3) (2nd Edition) Addison–Wesley
- 1: CH(M2) – CHARACTER(*) arrayInput
: elements M1
must contain character data to be ranked.
the length of each element of CH
must not exceed
- 2: M1 – INTEGERInput
: the index of the first element of CH
to be ranked.
- 3: M2 – INTEGERInput
: the index of the last element of CH
to be ranked.
- 4: L1 – INTEGERInput
- 5: L2 – INTEGERInput
: only the substring (L1
) of each element of CH
is to be used in determining the rank order.
- 6: ORDER – CHARACTER(1)Input
, the values will be ranked in ASCII order.
If , in reverse ASCII order.
- 7: IRANK(M2) – INTEGER arrayOutput
: elements M1
contain the ranks of the corresponding elements of CH
. Note that the ranks are in the range M1
: thus, if
is the first element in the rank order,
is set to M1
- 8: IFAIL – INTEGERInput/Output
must be set to
. 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
is recommended. If the output of error messages is undesirable, then the value
is recommended. Otherwise, if you are not familiar with this parameter, the recommended value is
. When the value is used it is essential to test the value of IFAIL on exit.
unless the routine detects an error or a warning has been flagged (see Section 6
6 Error Indicators and Warnings
If on entry
, explanatory error messages are output on the current error message unit (as defined by X04AAF
Errors or warnings detected by the routine:
|On entry,||ORDER is not 'A' or 'R'.|
|On entry,||the length of each element of CH exceeds .|
The average time taken by the routine is approximately proportional to , where .
The routine relies on the Fortran intrinsic functions LLT and LGT to order characters according to the ASCII collating sequence.
This example reads a file of -character records, and ranks them in reverse ASCII order on characters to .
9.1 Program Text
Program Text (m01dcfe.f90)
9.2 Program Data
Program Data (m01dcfe.d)
9.3 Program Results
Program Results (m01dcfe.r)