subroutine write_core_space(rep)
use Parallel_neci, only: MPIBarrier
type(core_space_t), intent(in) :: rep
integer :: i, k, iunit, ierr
write(stdout, '(a35)') "Writing the core space to a file..."
iunit = get_free_unit()
! Only let the root process write the states.
if (iProcIndex == root) then
open(iunit, file='CORESPACE', status='replace')
do i = 1, rep%determ_space_size
do k = 0, nifd
write(iunit, '(i24)', advance='no') rep%core_space(k, i)
end do
write(iunit, '()')
end do
call neci_flush(iunit)
close(iunit)
end if
call MPIBarrier(ierr)
end subroutine write_core_space