This is a simple -- and unefficient -- routine to sort a vector of
integers.
It is just used during some output to simplify comparisons with older
version of the code.
This function should not be used in efficiency-critical part of the code!
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer(kind=ip), | intent(in), | dimension(:) | :: | iv |
Input vector |
|
integer(kind=ip), | intent(out), | allocatable | :: | ov(:) |
Output, sorted vector |
subroutine sort_ivec(iv, ov)
!! This is a simple -- and unefficient -- routine to sort a vector of
!! integers.
!! It is just used during some output to simplify comparisons with older
!! version of the code.
!! @warning This function should not be used in efficiency-critical
!! part of the code!
use mod_memory, only: mallocate, mfree
implicit none
integer(ip), dimension(:), intent(in) :: iv
!! Input vector
integer(ip), allocatable, intent(out) :: ov(:)
!! Output, sorted vector
integer(ip) :: i, imin(1)
logical, allocatable :: mask(:)
if(allocated(ov)) call mfree('sort_ivec', ov)
call mallocate('sort_ivec', size(iv), ov)
allocate(mask(size(iv)))
mask = .true.
do i = 1, size(iv)
imin = minloc(iv, mask)
ov(i) = iv(imin(1))
mask(imin(1)) = .false.
end do
deallocate(mask)
end subroutine sort_ivec