The generic subroutine implementing the ORD_SORT algorithm to return
an input array with its elements sorted in order of (non-)decreasing
value. Its use has the syntax:
call ord_sort( array[, work, reverse] )
with the arguments:
array: the rank 1 array to be sorted. It is an intent(inout)
argument of any of the types integer(int8), integer(int16),
integer(int32), integer(int64), real(real32), real(real64),
real(real128), character(*), type(string_type),
type(bitset_64), type(bitset_large). If both the
type of array is real and at least one of the elements is a
NaN, then the ordering of the result is undefined. Otherwise it
is defined to be the original elements in non-decreasing order.
work (optional): shall be a rank 1 array of the same type as
array, and shall have at least size(array)/2 elements. It is an
intent(out) argument to be used as “scratch” memory
for internal record keeping. If associated with an array in static
storage, its use can significantly reduce the stack memory requirements
for the code. Its value on return is undefined.
reverse (optional): shall be a scalar of type default logical. It
is an intent(in) argument. If present with a value of .true. then
array will be sorted in order of non-increasing values in stable
order. Otherwise index will sort array in order of non-decreasing
values in stable order.
...
! Read arrays from sorted files
call read_sorted_file( 'dummy_file1', array1 )
call read_sorted_file( 'dummy_file2', array2 )
! Concatenate the arrays
allocate( array( size(array1) + size(array2) ) )
array( 1:size(array1) ) = array1(:)
array( size(array1)+1:size(array1)+size(array2) ) = array2(:)
! Sort the resulting array
call ord_sort( array, work )
! Process the sorted array
call array_search( array, values )
...
| Type | Visibility | Attributes | Name | Initial | |||
|---|---|---|---|---|---|---|---|
| integer, | private, | parameter | :: | max_merge_stack | = | int(ceiling(log(2._dp**64)/log(1.6180339887_dp))) |
Used to pass state around in a stack among helper functions for the
ORD_SORT and SORT_INDEX algorithms
| Type | Visibility | Attributes | Name | Initial | |||
|---|---|---|---|---|---|---|---|
| integer(kind=int_index), | public | :: | base | = | 0 | ||
| integer(kind=int_index), | public | :: | len | = | 0 |
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(inout) | :: | array(0:) | |||
| character(len=len), | intent(out), | optional | :: | work(0:) |
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(inout) | :: | array(0:) | |||
| character(len=len), | intent(out), | optional | :: | work(0:) |
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| real(kind=dp), | intent(inout) | :: | array(0:) | |||
| real(kind=dp), | intent(out), | optional | :: | work(0:) |
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| real(kind=dp), | intent(inout) | :: | array(0:) | |||
| real(kind=dp), | intent(out), | optional | :: | work(0:) |
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| integer(kind=int32), | intent(inout) | :: | array(0:) | |||
| integer(kind=int32), | intent(out), | optional | :: | work(0:) |
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| integer(kind=int32), | intent(inout) | :: | array(0:) | |||
| integer(kind=int32), | intent(out), | optional | :: | work(0:) |
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| integer(kind=int64), | intent(inout) | :: | array(0:) | |||
| integer(kind=int64), | intent(out), | optional | :: | work(0:) |
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| integer(kind=int64), | intent(inout) | :: | array(0:) | |||
| integer(kind=int64), | intent(out), | optional | :: | work(0:) |
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| real(kind=sp), | intent(inout) | :: | array(0:) | |||
| real(kind=sp), | intent(out), | optional | :: | work(0:) |
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| real(kind=sp), | intent(inout) | :: | array(0:) | |||
| real(kind=sp), | intent(out), | optional | :: | work(0:) |
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(inout) | :: | array(0:) | |||
| character(len=len), | intent(out), | optional | :: | work(0:) | ||
| logical, | intent(in), | optional | :: | reverse |
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| real(kind=dp), | intent(inout) | :: | array(0:) | |||
| real(kind=dp), | intent(out), | optional | :: | work(0:) | ||
| logical, | intent(in), | optional | :: | reverse |
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| integer(kind=int32), | intent(inout) | :: | array(0:) | |||
| integer(kind=int32), | intent(out), | optional | :: | work(0:) | ||
| logical, | intent(in), | optional | :: | reverse |
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| integer(kind=int64), | intent(inout) | :: | array(0:) | |||
| integer(kind=int64), | intent(out), | optional | :: | work(0:) | ||
| logical, | intent(in), | optional | :: | reverse |
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| real(kind=sp), | intent(inout) | :: | array(0:) | |||
| real(kind=sp), | intent(out), | optional | :: | work(0:) | ||
| logical, | intent(in), | optional | :: | reverse |