ArgIntroSort
This routine performs an indirect sort on an array.
Reference: Coretran
It returns the integer array which can be used for obtaining the sorted array.
Calling example:
CALL ArgIntroSort(array, arg)
Then, array(arg) will be sorted in increasing order.
Interface
- ܀ Interface
- ️܀ See example
- ↢
MODULE PURE SUBROUTINE ArgIntroSort(array, arg)
  INTEGER(Int8| Int16 | Int32 | Int64) | REAL(Real32| Real64), INTENT(IN) :: array(:)
  INTEGER(I4B), INTENT(OUT) :: arg(0:)
END SUBROUTINE ArgIntroSort
- Here, entries of arrayare NOT modified by the routine.
- argshould be allocated by the user
- array(arg)returns the sorted array.
In this example we test ArgIntroSort.
PROGRAM main
USE easifemBase
  REAL(REAL64) :: avec(10)
  INTEGER( I4B ) :: arg(10)
  CALL RANDOM_NUMBER(avec)
  avec = avec * 10
  arg=arange(1,10,1)
  CALL Display( avec, msg="unsorted array", advance="NO", full=.true. )
  CALL ArgIntroSort(avec, arg )
  CALL Display( arg, msg="arg", advance="NO", full=.true. )
  CALL Display( avec(arg), msg="sorted array", full=.true. )
  CALL blanklines()
See results
results
unsorted array,  arg,  sorted array
--------------,  ---,  ------------
   5.54368    ,   3 ,    0.81292   
   6.02586    ,  10 ,    2.87233   
   0.81292    ,   9 ,    3.91444   
   7.37413    ,   1 ,    5.54368   
   7.36096    ,   2 ,    6.02586   
   9.06920    ,   5 ,    7.36096   
   9.95400    ,   4 ,    7.37413   
   8.88093    ,   8 ,    8.88093   
   3.91444    ,   6 ,    9.06920   
   2.87233    ,   7 ,    9.95400
END PROGRAM main