sort_real Subroutine

public recursive subroutine sort_real(g, d, rtabref)


Arguments

Type IntentOptional AttributesName
integer(kind=I4), intent(in) :: g
integer(kind=I4), intent(in) :: d
real(kind=R8), intent(inout), dimension(:):: rtabref

Contents

Source Code


Source Code

   recursive subroutine sort_real(g, d, rtabref)
      implicit none
      integer(kind=I4), intent(in)  :: g, d
      real(kind=R8), dimension(:), intent(inout)  :: rtabref
      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_real(g, j, rtabref)
      if (d>i) call sort_real(i, d, rtabref)

   return
   endsubroutine sort_real