sort_array_real Subroutine

private recursive subroutine sort_array_real(g, d, rtabref)

Sort a vector of reals

Arguments

Type IntentOptional Attributes Name
integer(kind=I4), intent(in) :: g

left index

integer(kind=I4), intent(in) :: d

right index

real(kind=R8), intent(inout), dimension(:) :: rtabref

vector to sort


Source Code

   recursive subroutine sort_array_real(g, d, rtabref)
   !! Sort a vector of reals
   implicit none
   integer(kind=I4), intent(in)                  :: g          !! *left index*
   integer(kind=I4), intent(in)                  :: d          !! *right index*
   real(kind=R8),    intent(inout), dimension(:) :: rtabref    !! *vector to sort*

      integer(kind=I4) :: i, j, mil
      real(kind=R8)    :: tmp, 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
            tmp = rtabref(i)
            rtabref(i) = rtabref(j)
            rtabref(j) = tmp

            ! échange des éléments du vecteur position
            i = i + 1
            j = j - 1
         endif
      enddo

      if (g<j) call sort_array_real(g, j, rtabref)
      if (d>i) call sort_array_real(i, d, rtabref)

   return
   endsubroutine sort_array_real