FNLMath : Utilities : PERMU
PERMU
Rearranges the elements of an array as specified by a permutation.
Required Arguments
X — Real vector of length N containing the array to be permuted. (Input)
IPERMU — Integer vector of length N containing a permutation
IPERMU(1), , IPERMU(N) of the integers 1, …, N. (Input)
XPERMU — Real vector of length N containing the array X permuted. (Output)
If X is not needed, X and XPERMU can share the same storage locations.
Optional Arguments
N — Length of the arrays X and XPERMU. (Input)
Default: N = size (IPERMU,1).
IPATH — Integer flag. (Input)
Default: IPATH = 1.
IPATH = 1 means IPERMU represents a forward permutation, i.e., X(IPERMU(I)) is moved to XPERMU(I). IPATH = 2 means IPERMU represents a backward permutation, i.e., X(I) is moved to XPERMU(IPERMU(I)).
FORTRAN 90 Interface
Generic: CALL PERMU (X, IPERMU, XPERMU [])
Specific: The specific interface names are S_PERMU and D_PERMU.
FORTRAN 77 Interface
Single: CALL PERMU (N, X, IPERMU, IPATH, XPERMU)
Double: The double precision name is DPERMU.
Description
Routine PERMU rearranges the elements of an array according to a permutation vector. It has the option to do both forward and backward permutations.
Example
This example rearranges the array X using IPERMU; forward permutation is performed.
 
USE PERMU_INT
USE UMACH_INT
 
IMPLICIT NONE
! Declare variables
INTEGER IPATH, N
PARAMETER (IPATH=1, N=4)
!
INTEGER IPERMU(N), J, NOUT
REAL X(N), XPERMU(N)
! Set values for X, IPERMU
!
! X = ( 5.0 6.0 1.0 4.0 )
! IPERMU = ( 3 1 4 2 )
!
DATA X/5.0, 6.0, 1.0, 4.0/, IPERMU/3, 1, 4, 2/
! Permute X into XPERMU
CALL PERMU (X, IPERMU, XPERMU)
! Get output unit number
CALL UMACH (2, NOUT)
! Print results
WRITE (NOUT,99999) (XPERMU(J),J=1,N)
!
99999 FORMAT (' The output vector is:', /, 10(1X,F10.2))
END
Output
 
The Output vector is:
1.00 5.00 4.00 6.00
Published date: 03/19/2020
Last modified date: 03/19/2020