SVRGN
Sorts a real array by algebraically increasing value.
Required Arguments
RA — Vector of length N containing the array to be sorted. (Input)
RB — Vector of length N containing the sorted array. (Output)
If RA is not needed, RA and RB can share the same storage locations.
Optional Arguments
N — Number of elements in the array to be sorted. (Input)
Default: N = size (RA,1).
FORTRAN 90 Interface
Generic: CALL SVRGN (RA, RB [, …])
Specific: The specific interface names are S_SVRGN and D_SVRGN.
FORTRAN 77 Interface
Single: CALL SVRGN (N, RA, RB)
Double: The double precision name is DSVRGN.
Description
Routine SVRGN sorts the elements of an array, A, into ascending order by algebraic value. The array A is divided into two parts by picking a central element T of the array. The first and last elements of A are compared with T and exchanged until the three values appear in the array in ascending order. The elements of the array are rearranged until all elements greater than or equal to the central element appear in the second part of the array and all those less than or equal to the central element appear in the first part. The upper and lower subscripts of one of the segments are saved, and the process continues iteratively on the other segment. When one segment is finally sorted, the process begins again by retrieving the subscripts of another unsorted portion of the array. On completion, Aj ≤ Ai for j < i. For more details, see Singleton (1969), Griffin and Redish (1970), and Petro (1970).
Example
This example sorts the 10-element array RA algebraically.
USE SVRGN_INT
USE UMACH_INT
IMPLICIT NONE
! Declare variables
INTEGER N, NOUT, J
PARAMETER (N=10)
REAL RA(N), RB(N)
! Set values for RA
! RA = ( -1.0 2.0 -3.0 4.0 -5.0 6.0 -7.0 8.0 -9.0 10.0 )
!
DATA RA/-1.0, 2.0, -3.0, 4.0, -5.0, 6.0, -7.0, 8.0, -9.0, 10.0/
! Sort RA by algebraic value into RB
CALL SVRGN (RA, RB)
! Print results
CALL UMACH (2,NOUT)
WRITE (NOUT, 99999) (RB(J),J=1,N)
!
99999 FORMAT (' The output vector is:', /, 10(1X,F5.1))
END
The Output vector is:
-9.0 -7.0 -5.0 -3.0 -1.0 2.0 4.0 6.0 8.0 10.0