Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=dp), | intent(inout), | dimension(:, :) | :: | non_sorted | ||
real(kind=dp), | intent(out), | dimension(:, :) | :: | sorted |
subroutine sort(non_sorted, sorted)
!========================================!
use w90_constants, only: dp
implicit none
real(dp), intent(inout), dimension(:, :) :: non_sorted
real(dp), intent(out), dimension(:, :) :: sorted
integer, dimension(1) :: min_loc
integer :: num_col, i
num_col = size(non_sorted, 2)
do i = 1, num_col
!
!look for the location of the minimum value of the coordinates in non_sorted
!
min_loc = minloc(non_sorted(2, :))
!
!now the index in the first row of sorted is the index non_sorted(1,min_loc)
!
sorted(1, i) = non_sorted(1, min_loc(1))
!
!here is the corresponding coordinate
!
sorted(2, i) = non_sorted(2, min_loc(1))
!
!here one replaces the minimum coordinate with 10**10 such that this value
!will not be picked-up again by minloc
!
non_sorted(2, min_loc(1)) = 10.0**10
enddo
return
endsubroutine sort