subroutine expand_corespace_buf(buffer, buffer_size)
use real_time_data, only: ssht, wn_threshold
use real_time_aux, only: add_semistochastic_state
use FciMCData, only: AllTotParts
implicit none
integer(n_int), intent(inout) :: buffer(0:, 1:)
integer, intent(inout) :: buffer_size
integer(int64) :: i
real(dp) :: sgn(lenof_sign)
do i = 1, TotWalkers
call extract_sign(CurrentDets(:, i), sgn)
if (sum(abs(sgn)) / inum_runs > wn_threshold * sum(abs(AllTotParts)) / inum_runs) then
call add_semistochastic_state(buffer, buffer_size, ssht, CurrentDets(:, i))
end if
end do
end subroutine expand_corespace_buf