subroutine remove_states_not_on_proc(ilut_list, ilut_list_size, update_trial_vector)
use FciMCData, only: trial_wfs
use load_balance_calcnodes, only: DetermineDetNode
integer, intent(inout) :: ilut_list_size
integer(n_int), intent(inout) :: ilut_list(0:, :)
logical, intent(in) :: update_trial_vector
integer :: i, counter, proc
integer :: nI(nel)
counter = 0
do i = 1, ilut_list_size
call decode_bit_det(nI, ilut_list(0:NIfTot, i))
proc = DetermineDetNode(nel, nI, 0)
! If this state and the previous one were identical, don't add this state to the
! list so that repeats aren't included.
if (proc == iProcIndex) then
counter = counter + 1
ilut_list(:, counter) = ilut_list(:, i)
if (update_trial_vector) trial_wfs(:, counter) = trial_wfs(:, i)
end if
end do
ilut_list_size = counter
end subroutine remove_states_not_on_proc