subroutine write_detected_photons(dects)
use detectors
use constants, only: fileplace
use utils, only : str
type(dect_array), intent(in) :: dects(:)
integer :: i, j, u
character(len=:), allocatable :: hdr
do i = 1, size(dects)
open(newunit=u, file=trim(fileplace)//"detectors/detector_"//str(i)//".dat")
associate(x => dects(i)%p)
select type(x)
type is(circle_dect)
! hdr = "# pos, layer, nbins, bin_wid, radius"//new_line("a")//str(x%pos)//","//str(x%layer)//","//str(x%nbins)//","//str(x%bin_wid)//","//str(x%radius)
! write(u, "(a)")hdr
! write(u, "(a)")"#data:"
do j = 1, x%nbins
write(u,*)real(j,kind=wp) * x%bin_wid, x%data(j)
end do
type is(annulus_dect)
! hdr = "#pos, layer, nbins, bin_wid, radius1, radius2"//new_line("a")//str(x%pos)//","//str(x%layer)//","//str(x%nbins)//","//str(x%bin_wid)//","//str(x%r1)//","//str(x%r2)
type is(camera)
print*,"Warning not yet implmented!"
end select
end associate
close(u)
end do
end subroutine write_detected_photons