subroutine generate_connection_kpnt(nI, ilutI, nJ, ilutJ, ex_flag, tAllExcitFound, nStore, &
excit_gen, hel, ncon)
use Determinants, only: get_helement
use SymExcit2, only: gensymexcitit2par_worker
integer :: nI(nel)
integer(n_int), intent(in) :: ilutI(0:NIfTot)
integer, intent(out) :: nJ(nel)
integer(n_int), intent(out) :: ilutJ(0:NIfTot)
integer, intent(inout) :: ex_flag
logical, intent(inout) :: tAllExcitFound
integer, intent(inout) :: nStore(6)
integer, intent(inout) :: excit_gen(:)
HElement_t(dp), optional, intent(out) :: hel
integer, optional, intent(inout) :: ncon
integer(n_int) :: ilut_tmp(0:NIfTot)
integer :: ic
! Generate the next determinant.
call GenSymExcitIt2Par_worker(nI, nel, G1, nBasis, .false., excit_gen, nJ, &
ic, nStore, ex_flag, 1, nel)
if (nJ(1) == 0) then
tAllExcitFound = .true.
return
end if
! Encode nJ in ilut.
call EncodeBitDet(nJ, ilutJ)
! If using HPHFs, and if this isn't the allowed state for this HPHF, find
! the the allowed state and continue with this as ilut.
if (tHPHF .and. (.not. TestClosedShellDet(ilutJ))) then
if (.not. IsAllowedHPHF(ilutJ(0:NIfD))) then
ilut_tmp = ilutJ
call FindExcitBitDetSym(ilut_tmp, ilutJ)
end if
end if
if (present(HEl)) HEl = get_helement(nI, nJ, ic, ilutI, ilutJ)
if (present(ncon)) ncon = ncon + 1
end subroutine generate_connection_kpnt