Calculates range of gyro-angles that would hit the NPA detector
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer, | intent(in) | :: | ichan | Index of NPA detector |
||
type(GyroSurface), | intent(in) | :: | gs | |||
real(kind=Float64), | intent(out), | dimension(2,4) | :: | gyrange | ||
integer, | intent(out) | :: | nrange |
subroutine npa_gyro_range(ichan, gs, gyrange, nrange)
!+ Calculates range of gyro-angles that would hit the NPA detector
integer, intent(in) :: ichan
!+ Index of NPA detector
type(GyroSurface), intent(in) :: gs
real(Float64), dimension(2,4), intent(out) :: gyrange
integer, intent(out) :: nrange
type(LocalEMFields) :: fields
integer :: i, j, a_nrange, d_nrange
real(Float64) :: a0, a, b, c, d
real(Float64), dimension(2,4) :: a_gyrange, d_gyrange
nrange = 0
gyrange = 0.d0
call gyro_range(npa_chords%det(ichan)%aperture, gs, a_gyrange, a_nrange)
if(a_nrange.eq.0) return
call gyro_range(npa_chords%det(ichan)%detector, gs, d_gyrange, d_nrange)
if(d_nrange.eq.0) return
if((a_nrange.eq.1).and.approx_eq(a_gyrange(2,1),2*pi,1d-6)) then
gyrange = d_gyrange
nrange = d_nrange
return
endif
if((d_nrange.eq.1).and.approx_eq(d_gyrange(2,1),2*pi,1d-6)) then
gyrange = a_gyrange
nrange = a_nrange
return
endif
do i=1,a_nrange
do j=1, d_nrange
a0 = 0.d0
if(d_gyrange(1,j).gt.a_gyrange(1,i)) then
a0 = a_gyrange(1,i)
a = 0.d0
b = modulo(a_gyrange(1,i) + a_gyrange(2,i) - a0, 2*pi)
c = modulo(d_gyrange(1,j) - a0, 2*pi)
d = modulo(d_gyrange(1,j) + d_gyrange(2,j) - a0, 2*pi)
else
a0 = d_gyrange(1,j)
a = 0.d0
b = modulo(d_gyrange(1,j) + d_gyrange(2,j) - a0, 2*pi)
c = modulo(a_gyrange(1,i) - a0, 2*pi)
d = modulo(a_gyrange(1,i) + a_gyrange(2,i) - a0, 2*pi)
endif
if((c.lt.b).or.(d.lt.c)) then
if(c.lt.d) then
nrange = nrange + 1
gyrange(:,nrange) = [a0 + c, min(d-c,b-c)]
else
nrange = nrange + 1
gyrange(:,nrange) = [a0, d]
nrange = nrange + 1
gyrange(:,nrange) = [a0+c, b-c]
endif
endif
enddo
enddo
end subroutine npa_gyro_range