Sort a vector of integers and store the order
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer(kind=I4), | intent(in) | :: | g |
left index |
||
integer(kind=I4), | intent(in) | :: | d |
right index |
||
integer(kind=I4), | intent(inout), | dimension(:) | :: | itabref |
vector to sort |
|
integer(kind=I4), | intent(inout), | dimension(:) | :: | order |
sort order |
recursive subroutine sort_array_integer_with_order(g, d, itabref, order) !! Sort a vector of integers and store the order implicit none integer(kind=I4), intent(in ) :: g !! *left index* integer(kind=I4), intent(in ) :: d !! *right index* integer(kind=I4), intent(inout), dimension(:) :: itabref !! *vector to sort* integer(kind=I4), intent(inout), dimension(:) :: order !! *sort order* integer(kind=I4) :: i, j, mil, itmp integer(kind=I4) :: tmp, cle i = g j = d mil = (g+d)/2 cle = itabref(mil) if (g>=d) return do while (i<=j) do while (itabref(i)<cle) i = i + 1 enddo do while (itabref(j)>cle) j = j - 1 enddo if (i<=j) then ! échange des éléments du tableau tmp = itabref(i) itabref(i) = itabref(j) itabref(j) = tmp ! échange des éléments du tableau itmp = order(i) order(i) = order(j) order(j) = itmp ! échange des éléments du vecteur position i = i + 1 j = j - 1 endif enddo if (g<j) call sort_array_integer_with_order(g, j, itabref, order) if (d>i) call sort_array_integer_with_order(i, d, itabref, order) return endsubroutine sort_array_integer_with_order