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

Commit

Permalink
Replaced all the old sorting routines with new ones. util_index is no…
Browse files Browse the repository at this point in the history
…w part of the generic util_sort
  • Loading branch information
daminton committed Jul 27, 2021
1 parent 49b18b0 commit 81ecfaf
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 115 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
8
1 4.9125474498983623693e-11 0.0014751237493860230134
201 4.9125474498983623693e-11 0.0014751237493860230134
1.6306381826061645943e-05
-0.032433320146471017464 0.30732647407569840814 0.0280888997405028297
-0.033622812072399158034 -0.0019305604712619159943 0.0029264451427202888868
2 7.243452483873646905e-10 0.006759082196678506012
4.0453784346544178454e-05
-0.6608991468450423623 -0.28805695486041710263 0.034183953683804932377
0.007943018642097033136 -0.018635382188272479886 -0.00071410720992500279457
3 8.9970113821660187435e-10 0.010044863223462002622
1003 8.9970113821660187435e-10 0.010044863223462002622
4.25875607065040958e-05
0.5665449483756358484 -0.84285201543201082597 3.8152874628327130158e-05
0.0139986033055793102076 0.009533392738922031109 -5.008237574040859916e-07
Expand Down
26 changes: 19 additions & 7 deletions src/modules/swiftest_classes.f90
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ module swiftest_classes
public :: tides_kick_getacch_pl, tides_step_spin_system
public :: user_kick_getacch_body
public :: util_coord_b2h_pl, util_coord_b2h_tp, util_coord_h2b_pl, util_coord_h2b_tp, util_exit, util_fill_body, util_fill_pl, util_fill_tp, &
util_index, util_peri_tp, util_reverse_status, util_set_beg_end_pl, util_set_ir3h, util_set_msys, util_set_mu_pl, &
util_peri_tp, util_reverse_status, util_set_beg_end_pl, util_set_ir3h, util_set_msys, util_set_mu_pl, &
util_set_mu_tp, util_set_rhill, util_set_rhill_approximate, util_sort, util_spill_body, util_spill_pl, util_spill_tp, util_valid, util_version

!********************************************************************************************************************************
Expand Down Expand Up @@ -789,12 +789,6 @@ module subroutine util_fill_tp(self, inserts, lfill_list)
logical, dimension(:), intent(in) :: lfill_list !! Logical array of bodies to merge into the keeps
end subroutine util_fill_tp

module subroutine util_index(arr, index)
implicit none
integer(I4B), dimension(:), intent(out) :: index
real(DP), dimension(:), intent(in) :: arr
end subroutine util_index

module subroutine util_peri_tp(self, system, param)
implicit none
class(swiftest_tp), intent(inout) :: self !! Swiftest test particle object
Expand Down Expand Up @@ -856,15 +850,33 @@ module subroutine util_sort_i4b(arr)
integer(I4B), dimension(:), intent(inout) :: arr
end subroutine util_sort_i4b

module subroutine util_sort_index_i4b(arr,ind)
implicit none
integer(I4B), dimension(:), intent(in) :: arr
integer(I4B), dimension(:), intent(out) :: ind
end subroutine util_sort_index_i4b

module subroutine util_sort_sp(arr)
implicit none
real(SP), dimension(:), intent(inout) :: arr
end subroutine util_sort_sp

module subroutine util_sort_index_sp(arr,ind)
implicit none
real(SP), dimension(:), intent(in) :: arr
integer(I4B), dimension(:), intent(out) :: ind
end subroutine util_sort_index_sp

module subroutine util_sort_dp(arr)
implicit none
real(DP), dimension(:), intent(inout) :: arr
end subroutine util_sort_dp

module subroutine util_sort_index_dp(arr,ind)
implicit none
real(DP), dimension(:), intent(in) :: arr
integer(I4B), dimension(:), intent(out) :: ind
end subroutine util_sort_index_dp
end interface

interface
Expand Down
103 changes: 0 additions & 103 deletions src/util/util_index.f90

This file was deleted.

87 changes: 84 additions & 3 deletions src/util/util_sort.f90
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
module subroutine util_sort_dp(arr)
!! author: David A. Minton
!!
!! Sort input double precision array into ascending numerical order using insertion sort.
!! Sort input double precision array in place into ascending numerical order using insertion sort.
!! This algorithm works well for partially sorted arrays (which is usually the case here)
!!
implicit none
Expand All @@ -26,10 +26,37 @@ module subroutine util_sort_dp(arr)
return
end subroutine util_sort_dp

module subroutine util_sort_index_dp(arr, ind)
!! author: David A. Minton
!!
!! Sort input double precision array by index in ascending numerical order using insertion sort.
!! This algorithm works well for partially sorted arrays (which is usually the case here)
!!
implicit none
! Arguments
real(DP), dimension(:), intent(in) :: arr
integer(I4B), dimension(:), intent(out) :: ind
! Internals
real(DP) :: tmp
integer(I4B) :: n, i, j

n = size(arr)
ind = [(i, i=1, n)]
do i = 2, n
tmp = arr(ind(i))
do j = i - 1, 1, -1
if (arr(ind(j)) <= tmp) exit
ind(j + 1) = ind(j)
end do
ind(j + 1) = i
end do
return
end subroutine util_sort_index_dp

module subroutine util_sort_i4b(arr)
!! author: David A. Minton
!!
!! Sort input integer array into ascending numerical order using insertion sort.
!! Sort input integer array in place into ascending numerical order using insertion sort.
!! This algorithm works well for partially sorted arrays (which is usually the case here)
!!
implicit none
Expand All @@ -51,10 +78,37 @@ module subroutine util_sort_i4b(arr)
return
end subroutine util_sort_i4b

module subroutine util_sort_index_i4b(arr, ind)
!! author: David A. Minton
!!
!! Sort input integer array by index in ascending numerical order using insertion sort.
!! This algorithm works well for partially sorted arrays (which is usually the case here)
!!
implicit none
! Arguments
integer(I4B), dimension(:), intent(in) :: arr
integer(I4B), dimension(:), intent(out) :: ind
! Internals
integer(I4B) :: tmp
integer(I4B) :: n, i, j

n = size(arr)
ind = [(i, i=1, n)]
do i = 2, n
tmp = arr(ind(i))
do j = i - 1, 1, -1
if (arr(ind(j)) <= tmp) exit
ind(j + 1) = ind(j)
end do
ind(j + 1) = i
end do
return
end subroutine util_sort_index_i4b

module subroutine util_sort_sp(arr)
!! author: David A. Minton
!!
!! Sort input single precision array into ascending numerical order using insertion sort.
!! Sort input single precision array in place into ascending numerical order using insertion sort.
!! This algorithm works well for partially sorted arrays (which is usually the case here)
!
implicit none
Expand All @@ -75,4 +129,31 @@ module subroutine util_sort_sp(arr)
end do
return
end subroutine util_sort_sp

module subroutine util_sort_index_sp(arr, ind)
!! author: David A. Minton
!!
!! Sort input single precision array by index in ascending numerical order using insertion sort.
!! This algorithm works well for partially sorted arrays (which is usually the case here)
!!
implicit none
! Arguments
real(SP), dimension(:), intent(in) :: arr
integer(I4B), dimension(:), intent(out) :: ind
! Internals
real(SP) :: tmp
integer(I4B) :: n, i, j

n = size(arr)
ind = [(i, i=1, n)]
do i = 2, n
tmp = arr(ind(i))
do j = i - 1, 1, -1
if (arr(ind(j)) <= tmp) exit
ind(j + 1) = ind(j)
end do
ind(j + 1) = i
end do
return
end subroutine util_sort_index_sp
end submodule s_util_sort

0 comments on commit 81ecfaf

Please sign in to comment.