SVRBP

Sorts a real array by nondecreasing absolute value and return the permutation that rearranges the array.

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.

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.

Optional Arguments

N — Number of elements in the array to be sorted. (Input)
Default: N = size (IPERM,1).

FORTRAN 90 Interface

Generic: CALL SVRBP (RA, RB, IPERM [])

Specific: The specific interface names are S_SVRBP and D_SVRBP.

FORTRAN 77 Interface

Single: CALL SVRBP (N, RA, RB, IPERM)

Double: The double precision name is DSVRBP.

Description

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.

Comments

1. 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.

Example

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

Output

 

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