count_switches Function

public function count_switches(ilut) result(num_s)

Arguments

Type IntentOptional Attributes Name
integer(kind=n_int), intent(in) :: ilut(0:niftot)

Return Value integer


Source Code

    function count_switches(ilut) result(num_s)
        ! I tested a bit operation version of this function, but could not see
        ! a noticeable speedup and decided to use this more human readable
        ! version.
        integer(n_int), intent(in) :: ilut(0:niftot)
        integer :: num_s, sv(nSpatOrbs), i, curr_s, prev_s

        sv = calc_step_vector(ilut)

        num_s = 0
        prev_s = 0
        do i = 1, size(sv)
            if (sv(i) == 1 .or. sv(i) == 2) then
                curr_s = sv(i)
                if (curr_s * prev_s == 2) then
                    num_s = num_s + 1
                end if
                prev_s = curr_s
            end if
        end do

    end function count_switches