nag_sort_charvec_rank (m01dc) uses a variant of list-merging, as described on pages 165–166 in
Knuth (1973). The function 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:
l2) of each element of the array
ch is used to determine the rank order.
Not applicable.
The function relies on the Fortran intrinsic functions LLT and LGT to order characters according to the ASCII collating sequence.
function m01dc_example
fprintf('m01dc example results\n\n');
ch = {'A02AAF 289'; ...
'A02ABF 523'; ...
'A02ACF 531'; ...
'C02ADF 169'; ...
'C02AEF 599'; ...
'C05ADF 1351'; ...
'C05AGF 240'; ...
'C05AJF 136'; ...
'C05AVF 211'; ...
'C05AXF 183'; ...
'C05AZF 2181'};
m1 = int64(1);
l1 = int64(7);
l2 = int64(12);
order = 'Reverse ASCII';
[irank, ifail] = m01dc( ...
ch, m1, l1, l2, order);
fprintf('Records ranked on columns %2d to %2d\n\n',l1,l2);
fprintf(' Data Ranks\n\n');
for i = 1:numel(ch)
fprintf('%s%7d\n',char(ch{i}),irank(i));
end