subroutine FindExcitBitDet(iLutnI, iLutnJ, IC, ExcitMat)
! This routine will find the bit-representation of an excitation by
! constructing the new ilut from the old one and the excitation matrix
!
! In: iLutnI (0:NIfD) - source bit det
! IC - Excitation level
! ExcitMat(2,2) - Excitation Matrix
! Out: iLutnJ (0:NIfD) - New bit det
integer, intent(in) :: IC
integer, intent(in) :: ExcitMat(2, ic)
integer(kind=n_int), intent(in) :: iLutnI(0:NIfTot)
integer(kind=n_int), intent(inout) :: iLutnJ(0:NIfTot)
integer :: pos(2, ic), bit(2, ic), i, ic_tmp
#ifdef DEBUG_
character(*), parameter :: this_routine = "FindExcitBitDet"
#endif
if (ic == 0) return
ASSERT(ic > 0 .and. ic <= 3)
iLutnJ = iLutnI
! Which integer and bit in ilut represent each element?
pos = (excitmat - 1) / bits_n_int
bit = mod(excitmat - 1, bits_n_int)
! [W.D.12.12.2017]:
! why is this changed back to single excitations for ic=3?
! has this to do with simons CSFs? i can't really find a reason..
! try to change it and then lets see what happens!
ic_tmp = ic
! Clear bits for excitation source, and set bits for target
do i = 1, ic_tmp
iLutnJ(pos(1, i)) = ibclr(iLutnJ(pos(1, i)), bit(1, i))
iLutnJ(pos(2, i)) = ibset(iLutnJ(pos(2, i)), bit(2, i))
end do
end subroutine FindExcitBitDet