Subroutine to sort a vector of integers, according a vector of reals
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer(kind=I4), | intent(in) | :: | g | |||
integer(kind=I4), | intent(in) | :: | d | |||
real(kind=R8), | intent(inout), | dimension(:) | :: | rtabref | ||
integer(kind=I4), | intent(inout), | dimension(:) | :: | itab1 |
recursive subroutine sort_real_1int(g, d, rtabref, itab1)
implicit none
integer(kind=I4), intent(in) :: g, d
real(kind=R8), dimension(:), intent(inout) :: rtabref
integer(kind=I4), dimension(:), intent(inout) :: itab1
integer(kind=I4) :: i, j, mil, itmp
real(kind=R8) :: rtmp, cle
i = g
j = d
mil = (g+d)/2
cle = rtabref(mil)
if (g>=d) return
do while (i<=j)
do while (rtabref(i)<cle)
i = i + 1
enddo
do while (rtabref(j)>cle)
j = j - 1
enddo
if (i<=j) then
! échange des éléments du tableau
rtmp = rtabref(i)
rtabref(i) = rtabref(j)
rtabref(j) = rtmp
! échange des éléments du vecteur 2
itmp = itab1(i)
itab1(i) = itab1(j)
itab1(j) = itmp
i = i + 1
j = j - 1
endif
enddo
if (g<j) call sort_real_1int(g, j, rtabref, itab1)
if (d>i) call sort_real_1int(i, d, rtabref, itab1)
return
endsubroutine sort_real_1int