sort Function

private pure recursive function sort(x) result(res)

Arguments

Type IntentOptional AttributesName
real(kind=wp), intent(in), dimension(:):: x

Input array

Return Value real(kind=wp), dimension(size(x))


Calls

proc~~sort~~CallsGraph proc~sort sort proc~sort->proc~sort split split proc~sort->split head head proc~sort->head tail tail proc~sort->tail

Called by

proc~~sort~~CalledByGraph proc~sort sort proc~sort->proc~sort proc~grevilleabscissae GrevilleAbscissae proc~grevilleabscissae->proc~sort

Contents

Source Code


Source Code

        pure recursive function sort(x) result(res)
            real(wp), dimension(:), intent(in) :: x !< Input array
            real(wp), dimension(size(x)) :: res
            real(wp), dimension(size(x)-1) :: rest
            real(wp) :: pivot
            if(size(x) > 1)then
                pivot = head(split(x, 2))
                rest = [split(x, 1), tail(split(x, 2))]
                res = [sort(pack(rest, rest < pivot)), pivot, &
                        sort(pack(rest, rest >= pivot))]
            else
                res = x
            endif
        end function sort