subroutine transform_states(orig_orbs, transformed_orbs, n_states, orig_states, &
orig_weights, orig_iluts, transformed_states, transformed_weights, &
transformed_states_ilut, sort_ind)
integer, intent(in) :: orig_orbs(nBasis / 2), transformed_orbs(nBasis / 2)
integer, intent(in) :: n_states
integer, intent(inout) :: orig_states(nel, n_states)
real(dp), intent(inout) :: orig_weights(n_states)
integer(n_int), intent(inout) :: orig_iluts(0:niftot, n_states)
integer, intent(out) :: transformed_states(nel, n_states)
real(dp), intent(out) :: transformed_weights(n_states)
integer, intent(out), optional :: sort_ind(n_states)
integer(n_int), intent(out) :: transformed_states_ilut(0:niftot, n_states)
#ifdef DEBUG_
character(*), parameter :: this_routine = "transform_states"
#endif
integer :: i, n_phase, ind(n_states)
real(dp) :: tmp_sign(lenof_sign)
tmp_sign = 0.0_dp
! do it plain ans stupid for now..
do i = 1, n_states
call apply_transformation(orig_states(:, i), orig_orbs, &
transformed_orbs, transformed_states(:, i), n_phase)
transformed_weights(i) = real(n_phase, dp) * orig_weights(i)
tmp_sign(1) = transformed_weights(i)
call EncodeBitDet(transformed_states(:, i), transformed_states_ilut(:, i))
call encode_sign(transformed_states_ilut(:, i), tmp_sign)
end do
! the original highest pop list is sorted by weight i guess..
! sort them by the integers in the ilut representation
ind = [(i, i=1, n_states)]
call sort(orig_iluts, ind)
orig_states = orig_states(:, ind)
orig_weights = orig_weights(ind)
ind = [(i, i=1, n_states)]
call sort(transformed_states_ilut, ind)
transformed_states = transformed_states(:, ind)
transformed_weights = transformed_weights(ind)
if (present(sort_ind)) then
sort_ind = ind
end if
end subroutine transform_states