Skip to content

Commit

Permalink
Merge pull request #14 from arinrb/patch-1
Browse files Browse the repository at this point in the history
Update src/sorting.f90
  • Loading branch information
certik committed Jan 31, 2013
2 parents 11454ca + f1a9672 commit e6f0f45
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/sorting.f90
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ function iargsort(a) result(b)
! iargsort([10, 9, 8, 7, 6]) ! Returns [5, 4, 3, 2, 1]

integer :: N ! number of numbers/vectors
integer :: i,imin,relimin(1) ! indices: i, i of smallest, relative imin
integer :: i,imin ! indices: i, i of smallest
integer :: temp ! temporary
integer :: a2(size(a))
a2 = a
Expand All @@ -166,8 +166,8 @@ function iargsort(a) result(b)
end do
do i = 1, N-1
! find ith smallest in 'a'
relimin = minloc(a2(i:))
imin = relimin(1) + i - 1
imin = minloc(a2(i:),1) + i - 1

! swap to position i in 'a' and 'b', if not already there
if (imin /= i) then
temp = a2(i); a2(i) = a2(imin); a2(imin) = temp
Expand All @@ -191,8 +191,8 @@ function rargsort(a) result(b)
! rargsort([4.1_dp, 2.1_dp, 2.05_dp, -1.5_dp, 4.2_dp]) ! Returns [4, 3, 2, 1, 5]

integer :: N ! number of numbers/vectors
integer :: i,imin,relimin(1) ! indices: i, i of smallest, relative imin
integer :: temp1 ! temporary
integer :: i,imin ! indices: i, i of smallest
integer :: temp1 ! temporary
real(dp) :: temp2
real(dp) :: a2(size(a))
a2 = a
Expand All @@ -202,8 +202,7 @@ function rargsort(a) result(b)
end do
do i = 1, N-1
! find ith smallest in 'a'
relimin = minloc(a2(i:))
imin = relimin(1) + i - 1
imin = minloc(a2(i:),1) + i - 1
! swap to position i in 'a' and 'b', if not already there
if (imin /= i) then
temp2 = a2(i); a2(i) = a2(imin); a2(imin) = temp2
Expand Down

0 comments on commit e6f0f45

Please sign in to comment.