Sorts a real array by nondecreasing absolute value and return the permutation that rearranges the array.
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.
IPERM — Vector of
length N.
(Input/Output)
On input, IPERM should be
initialized to the values 1, 2, …, N. On output, IPERM contains a
record of permutations made on the vector IA.
N — Number of
elements in the array to be sorted. (Input)
Default: N = size
(IPERM,1).
Generic: CALL SVRBP (RA, RB, IPERM [,…])
Specific: The specific interface names are S_SVRBP and D_SVRBP.
Single: CALL SVRBP (N, RA, RB, IPERM)
Double: The double precision name is DSVRBP.
Routine SVRBP sorts the elements of an array, A, into ascending order by absolute value, keeping a record in P of the permutations to the array A. That is, the elements of P are moved in the same manner as are the elements in A as A is being sorted. The routine SVRBP uses the algorithm discussed in SVRGN. On completion, Aj ≤ Ai for j < i.
For wider applicability, integers (1, 2, …, N) that are to be associated with RA(I) for I = 1, 2, …, N may be entered into IPERM(I) in any order. Note that these integers must be unique.
This example sorts the 10-element array RA by absolute value.
USE SVRBP_INT
USE UMACH_INT
IMPLICIT NONE
! Declare variables
INTEGER N, J, NOUT, I
PARAMETER (N=10)
REAL RA(N), RB(N)
INTEGER IPERM(N)
! Set values for RA and IPERM
! RA = ( 10.0 9.0 8.0 7.0 6.0 5.0 -4.0 3.0 -2.0 1.0 )
!
! IPERM = ( 1 2 3 4 5 6 7 8 9 10 )
!
DATA RA/10.0, 9.0, 8.0, 7.0, 6.0, 5.0, -4.0, 3.0, -2.0, 1.0/
DATA IPERM/1, 2, 3, 4, 5, 6, 7, 8, 9, 10/
! Sort RA by absolute value into RB
CALL SVRBP (RA, RB, IPERM)
! Print results
CALL UMACH (2,NOUT)
WRITE (NOUT, 99998) (RB(J),J=1,N)
WRITE (NOUT, 99999) (IPERM(I),I=1,N)
!
99998 FORMAT (' The output vector is:', /, 10(1X,F5.1))
99999 FORMAT (' The permutation vector is:', /, 10(1X,I5))
END
The output vector is:
1.0
-2.0 3.0 -4.0 5.0 6.0
7.0 8.0 9.0 10.0
The permutation vector
is:
10 9
8 7 6
5 4 3
2 1
Visual Numerics, Inc. PHONE: 713.784.3131 FAX:713.781.9260 |