pic_sorting_ord_sort Submodule

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.

Example

    ...
    ! 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 )
    ...

Uses

  • module~~pic_sorting_ord_sort~~UsesGraph module~pic_sorting_ord_sort pic_sorting_ord_sort module~pic_sorting pic_sorting module~pic_sorting_ord_sort->module~pic_sorting module~pic_optional_value pic_optional_value module~pic_sorting->module~pic_optional_value module~pic_types pic_types module~pic_sorting->module~pic_types module~pic_optional_value->module~pic_types iso_c_binding iso_c_binding module~pic_types->iso_c_binding iso_fortran_env iso_fortran_env module~pic_types->iso_fortran_env

Variables

Type Visibility Attributes Name Initial
integer, private, parameter :: max_merge_stack = int(ceiling(log(2._dp**64)/log(1.6180339887_dp)))

Derived Types

type ::  run_type

Used to pass state around in a stack among helper functions for the ORD_SORT and SORT_INDEX algorithms

Components

Type Visibility Attributes Name Initial
integer(kind=int_index), public :: base = 0
integer(kind=int_index), public :: len = 0

Subroutines

subroutine char_decrease_ord_sort(array, work)

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(inout) :: array(0:)
character(len=len), intent(out), optional :: work(0:)

subroutine char_increase_ord_sort(array, work)

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(inout) :: array(0:)
character(len=len), intent(out), optional :: work(0:)

subroutine dp_decrease_ord_sort(array, work)

Arguments

Type IntentOptional Attributes Name
real(kind=dp), intent(inout) :: array(0:)
real(kind=dp), intent(out), optional :: work(0:)

subroutine dp_increase_ord_sort(array, work)

Arguments

Type IntentOptional Attributes Name
real(kind=dp), intent(inout) :: array(0:)
real(kind=dp), intent(out), optional :: work(0:)

subroutine int32_decrease_ord_sort(array, work)

Arguments

Type IntentOptional Attributes Name
integer(kind=int32), intent(inout) :: array(0:)
integer(kind=int32), intent(out), optional :: work(0:)

subroutine int32_increase_ord_sort(array, work)

Arguments

Type IntentOptional Attributes Name
integer(kind=int32), intent(inout) :: array(0:)
integer(kind=int32), intent(out), optional :: work(0:)

subroutine int64_decrease_ord_sort(array, work)

Arguments

Type IntentOptional Attributes Name
integer(kind=int64), intent(inout) :: array(0:)
integer(kind=int64), intent(out), optional :: work(0:)

subroutine int64_increase_ord_sort(array, work)

Arguments

Type IntentOptional Attributes Name
integer(kind=int64), intent(inout) :: array(0:)
integer(kind=int64), intent(out), optional :: work(0:)

subroutine sp_decrease_ord_sort(array, work)

Arguments

Type IntentOptional Attributes Name
real(kind=sp), intent(inout) :: array(0:)
real(kind=sp), intent(out), optional :: work(0:)

subroutine sp_increase_ord_sort(array, work)

Arguments

Type IntentOptional Attributes Name
real(kind=sp), intent(inout) :: array(0:)
real(kind=sp), intent(out), optional :: work(0:)

Module Subroutines

module subroutine char_ord_sort(array, work, reverse)

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(inout) :: array(0:)
character(len=len), intent(out), optional :: work(0:)
logical, intent(in), optional :: reverse

module subroutine dp_ord_sort(array, work, reverse)

Arguments

Type IntentOptional Attributes Name
real(kind=dp), intent(inout) :: array(0:)
real(kind=dp), intent(out), optional :: work(0:)
logical, intent(in), optional :: reverse

module subroutine int32_ord_sort(array, work, reverse)

Arguments

Type IntentOptional Attributes Name
integer(kind=int32), intent(inout) :: array(0:)
integer(kind=int32), intent(out), optional :: work(0:)
logical, intent(in), optional :: reverse

module subroutine int64_ord_sort(array, work, reverse)

Arguments

Type IntentOptional Attributes Name
integer(kind=int64), intent(inout) :: array(0:)
integer(kind=int64), intent(out), optional :: work(0:)
logical, intent(in), optional :: reverse

module subroutine sp_ord_sort(array, work, reverse)

Arguments

Type IntentOptional Attributes Name
real(kind=sp), intent(inout) :: array(0:)
real(kind=sp), intent(out), optional :: work(0:)
logical, intent(in), optional :: reverse