FNLMath : Utilities : SVIBP
SVIBP
Sorts an integer array by nondecreasing absolute value and return the permutation that rearranges the array.
Required Arguments
IA — Integer vector of length N containing the array to be sorted. (Input)
IB — Integer vector of length N containing the sorted array. (Output)
If IA is not needed, IA and IB 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 (IA,1).
FORTRAN 90 Interface
Generic: CALL SVIBP (IA, IB, IPERM [])
Specific: The specific interface name is S_SVIBP.
FORTRAN 77 Interface
Single: CALL SVIBP (N, IA, IB, IPERM)
Description
Routine SVIBP sorts the elements of an integer 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 SVIBP 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 IA(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 IA by absolute value.
 
USE SVIBP_INT
USE UMACH_INT
 
 
 
PARAMETER (N=10)
INTEGER IA(N), IB(N), IPERM(N)
! Set values for IA
! IA = ( 10 9 8 7 6 5 -4 3 -2 1 )
!
! IPERM = ( 1 2 3 4 5 6 7 8 9 10 )
!
DATA IA/10, 9, 8, 7, 6, 5, -4, 3, -2, 1/
DATA IPERM/1, 2, 3, 4, 5, 6, 7, 8, 9, 10/
! Sort IA by absolute value into IB
CALL SVIBP (IA, IB, IPERM)
! Print results
CALL UMACH (2,NOUT)
WRITE (NOUT, 99998) (IB(J),J=1,N)
WRITE (NOUT, 99999) (IPERM(J),J=1,N)
!
99998 FORMAT (' The output vector is:', /, 10(1X,I5))
99999 FORMAT (' The permutation vector is:', /, 10(1X,I5))
END
Output
 
The Output vector is:
1 -2 3 -4 5 6 7 8 9 10
 
The permutation vector is:
10 9 8 7 6 5 4 3 2 1