idxPreSort Subroutine

private subroutine idxPreSort(iCI, idxAlphaBetaOrbs, ex, signCI)

Uses

Arguments

Type IntentOptional Attributes Name
integer, intent(in) :: iCI
integer, intent(in) :: idxAlphaBetaOrbs(nbasis)
integer, intent(inout) :: ex(2,n_store_ci_level)
integer, intent(out) :: signCI

Contents

Source Code


Source Code

    subroutine idxPreSort(iCI, idxAlphaBetaOrbs, ex, signCI)
        use util_mod, only: swap
        integer, intent(in)  :: iCI, idxAlphaBetaOrbs(nbasis)
        integer, intent(out) :: signCI
        integer, intent(inout) :: ex(2, n_store_ci_level)
        integer  :: j, k, p

        ! indices conversion
        do k = 1, iCI
            do p = 1, nel
                if (ex(1, k) == idxAlphaBetaOrbs(p)) then
                    ex(1, k) = p
                    exit
                end if
            end do
            do p = nel + 1, nbasis
                if (ex(2, k) == idxAlphaBetaOrbs(p)) then
                    ex(2, k) = p - nel
                    exit
                end if
            end do
        end do
        ! insertion sort
        signCI = 1
        do p = 1, 2
            do k = 2, iCI
                do j = k, 2, -1
                    if (ex(p, j) < ex(p, j - 1)) then
                        call swap(ex(p, j), ex(p, j - 1))
                        ! minus sign for odd number of permutations
                        signCI = -signCI
                    else
                        exit
                    end if
                end do
            end do
        end do
    end subroutine idxPreSort