A reproducible maxloc function so b-vectors come in the same order each time
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=dp), | intent(in) | :: | dist((2*nsupcell+1)**3) | Distances from the origin of the unit cells in the supercell. |
function internal_maxloc(dist)
!=================================
!
!! A reproducible maxloc function
!! so b-vectors come in the same
!! order each time
!=================================
use w90_constants, only: eps8
implicit none
real(kind=dp), intent(in) :: dist((2*nsupcell + 1)**3)
!! Distances from the origin of the unit cells in the supercell.
integer :: internal_maxloc
integer :: guess(1), loop, counter
integer :: list((2*nsupcell + 1)**3)
list = 0
counter = 1
guess = maxloc(dist)
list(1) = guess(1)
! look for any degenerate values
do loop = 1, (2*nsupcell + 1)**3
if (loop == guess(1)) cycle
if (abs(dist(loop) - dist(guess(1))) < eps8) then
counter = counter + 1
list(counter) = loop
endif
end do
! and always return the lowest index
internal_maxloc = minval(list(1:counter))
end function internal_maxloc