Skip to content
This repository was archived by the owner on Aug 28, 2024. It is now read-only.

Commit

Permalink
Merge branch 'debug'
Browse files Browse the repository at this point in the history
  • Loading branch information
daminton committed Oct 23, 2021
2 parents 2a8fefe + c01b21a commit 7b5d61b
Showing 1 changed file with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions src/util/util_sort.f90
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,12 @@ recursive pure subroutine qsort_index_DP(arr, ind)
!! author: David A. Minton
!!
!! Sort input DP precision array by index in ascending numerical order using quicksort sort.
!!
implicit none
! Arguments
real(DP), dimension(:), intent(inout) :: arr
integer(I4B),dimension(:),intent(out) :: ind
!! Internals
integer :: iq

if (size(arr) > 1) then
Expand All @@ -137,16 +140,24 @@ pure subroutine partition_DP(arr, marker, ind)
!! author: David A. Minton
!!
!! Partition function for quicksort on DP type
real(DP), intent(inout), dimension(:) :: arr
!!
implicit none
! Arguments
real(DP), intent(inout), dimension(:) :: arr
integer(I4B), intent(inout), dimension(:), optional :: ind
integer(I4B), intent(out) :: marker
integer(I4B) :: i, j, itmp
integer(I4B), intent(out) :: marker
! Internals
integer(I4B) :: i, j, itmp, narr, ipiv
real(DP) :: temp
real(DP) :: x ! pivot point
real(DP) :: x ! pivot point

narr = size(arr)

x = arr(1)
! Get center as pivot, as this is likely partially sorted
ipiv = narr / 2
x = arr(ipiv)
i = 0
j = size(arr) + 1
j = narr + 1

do
j = j - 1
Expand All @@ -164,9 +175,11 @@ pure subroutine partition_DP(arr, marker, ind)
temp = arr(i)
arr(i) = arr(j)
arr(j) = temp
itmp = ind(i)
ind(i) = ind(j)
ind(j) = itmp
if (present(ind)) then
itmp = ind(i)
ind(i) = ind(j)
ind(j) = itmp
end if
else if (i == j) then
marker = i + 1
return
Expand Down

0 comments on commit 7b5d61b

Please sign in to comment.