subroutine equalize_initial_phase()
use FciMCData, only: AllSumNoatHF
use bit_rep_data, only: extract_sign
use bit_reps, only: encode_sign
use util_mod, only: near_zero
implicit none
integer :: signs(lenof_sign), iGf
integer(int64) :: i
real(dp) :: tmp_sgn(lenof_sign)
signs = 1
if(.not. near_zero(AllSumNoatHF(1))) then
do i = 1, lenof_sign
if (AllSumNoatHF(i) / AllSumNoatHF(1) < 0) then
signs(i) = -1
else
signs(i) = 1
end if
end do
end if
if (any(signs < 0)) then
do i = 1, TotWalkers
call extract_sign(CurrentDets(:, i), tmp_sgn)
tmp_sgn = tmp_sgn * signs
call encode_sign(CurrentDets(:, i), tmp_sgn)
end do
do iGf = 1, gf_count
do i = 1, overlap_states(iGf)%nDets
call extract_sign(overlap_states(iGf)%dets(:, i), tmp_sgn)
tmp_sgn = tmp_sgn * signs
call encode_sign(overlap_states(iGf)%dets(:, i), tmp_sgn)
end do
end do
end if
end subroutine equalize_initial_phase