Use an indirect introspection sort on an array of numbers
Example usage
program argSortTest use variableKind use m_strings, only: str use m_random, only: rngInteger,rngNormal use m_arrays, only: isSorted use m_Sort, only: argSort real(r64),allocatable :: d1D(:) integer(i32),allocatable :: i1D(:) integer(i32),allocatable :: indx(:) integer(i32) :: i, k, N N = 10000 call allocate(indx,N) call arange(indx, 1, N) call allocate(d1D,N) call rngNormal(d1D) k = (size(d1D)+1)/2 call argSelect(d1D, indx, k) write(*,'(a)') 'Double array is indirectly sorted? '//str(isSorted(d1D(indx))) call arange(indx, 1, N) call allocate(i1D,N) call rngInteger(i1D) call argSelectt(i1D, indx, k) write(*,'(a)') 'Integer array is indirectly sorted? '//str(isSorted(i1D(indx))) end program
Interfaced with argSelect()
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer(kind=i32), | intent(in) | :: | this(:) | 1D array |
||
integer(kind=i32), | intent(inout) | :: | indx(:) | Index to choose kth smallest from |
||
integer(kind=i32), | intent(in) | :: | k | kth smallest element |
||
integer(kind=i32) | :: | res | Index of the kth smallest element |
|||
integer(kind=i32), | intent(in), | optional | :: | left | Select over the region left:right |
|
integer(kind=i32), | intent(in), | optional | :: | right | Select over the region left:right |
Interfaced with argSelect()
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer(kind=i64), | intent(in) | :: | this(:) | 1D array |
||
integer(kind=i32), | intent(inout) | :: | indx(:) | Index to choose kth smallest from |
||
integer(kind=i32), | intent(in) | :: | k | kth smallest element |
||
integer(kind=i32) | :: | res | Index of the kth smallest element |
|||
integer(kind=i32), | intent(in), | optional | :: | left | Select over the region left:right |
|
integer(kind=i32), | intent(in), | optional | :: | right | Select over the region left:right |
Interfaced with argSelect()
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=r32), | intent(in) | :: | this(:) | 1D array |
||
integer(kind=i32), | intent(inout) | :: | indx(:) | Index to choose kth smallest from |
||
integer(kind=i32), | intent(in) | :: | k | kth smallest element |
||
integer(kind=i32) | :: | res | Index of the kth smallest element |
|||
integer(kind=i32), | intent(in), | optional | :: | left | Select over the region left:right |
|
integer(kind=i32), | intent(in), | optional | :: | right | Select over the region left:right |
Interfaced with argSelect()
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=r64), | intent(in) | :: | this(:) | 1D array |
||
integer(kind=i32), | intent(inout) | :: | indx(:) | Index to choose kth smallest from |
||
integer(kind=i32), | intent(in) | :: | k | kth smallest element |
||
integer(kind=i32) | :: | res | Index of the kth smallest element |
|||
integer(kind=i32), | intent(in), | optional | :: | left | Select over the region left:right |
|
integer(kind=i32), | intent(in), | optional | :: | right | Select over the region left:right |