function get_pgen_pick_weighted_hole(this, nI, exc) result(pgenVal)
class(GAS_disc_ExcGenerator_t), intent(in) :: this
integer, intent(in) :: nI(nel)
type(Excite_2_t), intent(in) :: exc
character(*), parameter :: this_routine = 'get_pgen_pick_weighted_hole'
real(dp) :: pgenVal
integer :: src1, tgt1, src2, tgt2
real(dp) :: cSum(this%GAS_size(this%GAS_table(exc%val(2, 2))))
integer :: gasList(this%GAS_size(this%GAS_table(exc%val(2, 2)))), nOrbs
integer :: gasInd2
#ifdef DEBUG_
block
use util_mod, only: stop_all
use constants, only: stderr
if (.not. (defined(exc))) then
write(stderr, *) ""
write(stderr, *) "Assertion defined(exc)"
write(stderr, *) "failed in /scratch/jenkins/jobs/existing_branch_doc/workspace/build_config/gfortran-doc/src/gasci_dis&
&connected.fpp:388"
call stop_all (this_routine, "Assert fail: defined(exc)")
end if
end block
#endif
src1 = exc%val(1, 1); tgt1 = exc%val(2, 1)
src2 = exc%val(1, 2); tgt2 = exc%val(2, 2)
nOrbs = this%GAS_size(this%GAS_table(tgt2))
gasList = this%GAS_spin_orb_list(1:nOrbs, this%GAS_table(tgt2), get_spin(tgt2))
cSum = get_cumulative_list(gasList, nI, Excite_2_t(src1, tgt1, src2))
! we know gasList contains tgt2, so we can look up its index with binary search
gasInd2 = binary_search_first_ge(gasList, tgt2)
if (gasInd2 == 1) then
pgenVal = cSum(1)
else
pgenVal = (cSum(gasInd2) - cSum(gasInd2 - 1))
end if
end function get_pgen_pick_weighted_hole