Sorts a rank-1 array of real numbers
x so the y results are algebraically nondecreasing,
y1 ≤
y2 ≤
… yn.
X — Rank-1 array containing the numbers to be sorted. (Output)
Y — Rank-1 array containing the sorted numbers. (Output)
nsize
= n (Input)
Uses the sub-array of size n for the numbers.
Default value: n = size(x)
iperm
= iperm (Input/Output)
Applies interchanges of elements
that occur to the entries of iperm(:). If the values iperm(i)=i,i=1,n are assigned prior to
call, then the output array is moved to its proper order by the subscripted
array assignment y = x(iperm(1:n)).
icycle
= icycle (Output)
Permutations applied to the input data
are converted to cyclic interchanges. Thus, the output array y is given by the
following elementary interchanges, where :=: denotes a swap:
j =
icycle(i)
y(j) :=: y(i), i = 1,n
iopt
= iopt(:) (Input)
Derived type array with the same
precision as the input matrix; used for passing optional data to the routine.
The options are as follows:
iopt(IO) =
?_options(?_sort_real_scan_for_NaN, ?_dummy)
Examines each input array
entry to find the first value such that
See the isNaN() function, Chapter 10.
Default: Does not scan for NaNs.
Generic: CALL SORT_REAL (X, Y [,…])
Specific: The specific interface names are S_SORT_REAL and D_SORT_REAL.
For a detailed description, see the Description section of routine SVRGN, which appears later in this chapter.
See the messages.gls file for error messages for SORT_REAL. These error messages are numbered 561−567; 581−587.
An array of random numbers is obtained. The values are sorted so they are nondecreasing.
! This is Example 1 for SORT_REAL.
real(kind(1e0)), dimension(n) :: x, y
! Generate random data to sort.
! Sort the data so it is non-decreasing.
! Check that the sorted array is not decreasing.
if (count(y(1:n-1) > y(2:n)) == 0) then
write (*,*) 'Example 1 for SORT_REAL is correct.'
Example 1 for SORT_REAL is correct.
A set of n random numbers is sorted so the results are nonincreasing. The columns of an n × n random matrix are moved to the order given by the permutation defined by the interchange of the entries. Since the routine sorts the results to be algebraically nondecreasing, the array of negative values is used as input. Thus, the negative value of the sorted output order is nonincreasing. The optional argument “iperm=” records the final order and is used to move the matrix columns to that order. This example illustrates the principle of sorting record keys, followed by direct movement of the records to sorted order.
! This is Example 2 for SORT_REAL.
real(kind(1e0)) a(n,n), x(n), y(n), temp(n*n)
! Generate a random array and matrix of values.
! Initialize permutation to the identity.
! Sort using negative values so the final order is
call sort_real(-x, y, iperm=ip)
! Final movement of keys and matrix columns.
if (count(y(1:n-1) < y(2:n)) == 0) then
write (*,*) 'Example 2 for SORT_REAL is correct.'
Example 2 for SORT_REAL is correct.
Visual Numerics, Inc. PHONE: 713.784.3131 FAX:713.781.9260 |