subroutine cart_to_tor_check_if_confined_p(pchunk,ar,R0,X_X,X_Y,X_Z, &
T_R,T_T,T_Z,flag_cache)
INTEGER, INTENT(IN) :: pchunk
REAL(rp), INTENT(IN) :: R0,ar
REAL(rp), INTENT(IN),DIMENSION(pchunk) :: X_X,X_Y,X_Z
REAL(rp), INTENT(OUT),DIMENSION(pchunk) :: T_R,T_T,T_Z
INTEGER(is), INTENT(INOUT),DIMENSION(pchunk) :: flag_cache
REAL(rp),DIMENSION(pchunk) :: RR
INTEGER :: cc
!! Particle chunk iterator.
!$OMP SIMD
! !$OMP& aligned(RR,X_X,X_Y,T_R,T_T,T_Z,X_Z)
do cc=1_idef,pchunk
RR(cc)=SQRT(X_X(cc)*X_X(cc) + X_Y(cc)*X_Y(cc)) - R0
T_R(cc) = SQRT( RR(cc)*RR(cc) + X_Z(cc)*X_Z(cc) )
T_T(cc) = ATAN2(X_Z(cc), RR(cc))
T_T(cc) = MODULO(T_T(cc),2.0_rp*C_PI)
T_Z(cc) = ATAN2(X_X(cc),X_Y(cc))
T_Z(cc) = MODULO(T_Z(cc),2.0_rp*C_PI)
end do
!$OMP END SIMD
!$OMP SIMD
do cc=1_idef,pchunk
if (T_R(cc) .GT. ar) then
flag_cache(cc) = 0_is
end if
end do
!$OMP END SIMD
end subroutine cart_to_tor_check_if_confined_p