daord Subroutine

private subroutine daord(a, n)

Used to reorder the elements of the double precision array a so that abs(a(i)) <= abs(a(i+1)) for i = 1,...,n-1. it is assumed that n >= 1.

Arguments

Type IntentOptional Attributes Name
real(kind=wp), intent(inout) :: a(n)
integer, intent(in) :: n

Called by

proc~~daord~~CalledByGraph proc~daord polyroots_module::daord proc~dqtcrt polyroots_module::dqtcrt proc~dqtcrt->proc~daord

Source Code

subroutine daord(a,n)

    integer,intent(in) :: n
    real(wp),intent(inout) :: a(n)

    integer :: i , ii , imax , j , jmax , ki , l , ll
    real(wp) :: s

    integer,dimension(10),parameter :: k = [1, 4, 13, 40, 121, 364, &
                                            1093, 3280, 9841, 29524]

    ! selection of the increments k(i) = (3**i-1)/2
    if ( n<2 ) return
    imax = 1
    do i = 3 , 10
        if ( n<=k(i) ) exit
        imax = imax + 1
    enddo

    ! stepping through the increments k(imax),...,k(1)
    i = imax
    do ii = 1 , imax
        ki = k(i)
        ! sorting elements that are ki positions apart
        ! so that abs(a(j)) <= abs(a(j+ki))
        jmax = n - ki
        do j = 1 , jmax
            l = j
            ll = j + ki
            s = a(ll)
            do while ( abs(s)<abs(a(l)) )
                a(ll) = a(l)
                ll = l
                l = l - ki
                if ( l<=0 ) exit
            enddo
            a(ll) = s
        enddo
        i = i - 1
    enddo

 end subroutine daord