Find closests beam_grid indices ind
to position pos
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=Float64), | intent(in), | dimension(3) | :: | pos | Position [cm] |
|
integer(kind=Int32), | intent(out), | dimension(3) | :: | ind | Closest indices to position |
subroutine get_indices(pos, ind)
!+ Find closests [[libfida:beam_grid]] indices `ind` to position `pos`
real(Float64), dimension(3), intent(in) :: pos
!+ Position [cm]
integer(Int32), dimension(3), intent(out) :: ind
!+ Closest indices to position
real(Float64), dimension(3) :: mini
integer(Int32), dimension(3) :: maxind
integer :: i
maxind(1) = beam_grid%nx
maxind(2) = beam_grid%ny
maxind(3) = beam_grid%nz
mini(1) = minval(beam_grid%xc) - 0.5*beam_grid%dr(1)
mini(2) = minval(beam_grid%yc) - 0.5*beam_grid%dr(2)
mini(3) = minval(beam_grid%zc) - 0.5*beam_grid%dr(3)
do i=1,3
ind(i) = floor((pos(i)-mini(i))/beam_grid%dr(i)) + 1
if (ind(i).gt.maxind(i)) ind(i)=maxind(i)
if (ind(i).lt.1) ind(i)=1
enddo
end subroutine get_indices