subroutine analytical_fields_Bmag_p(pchunk,F,Y_R,Y_PHI,Y_Z,Bmag,E_PHI)
INTEGER, INTENT(IN) :: pchunk
TYPE(FIELDS), INTENT(IN) :: F
REAL(rp) :: R0,B0,lam,q0,EF0
REAL(rp),DIMENSION(pchunk),INTENT(IN) :: Y_R,Y_PHI,Y_Z
REAL(rp),DIMENSION(pchunk) :: B_R,B_PHI,B_Z,rm,qprof
REAL(rp),DIMENSION(pchunk),INTENT(OUT) :: Bmag,E_PHI
integer(ip) :: cc
B0=F%Bo
EF0=F%Eo
lam=F%AB%lambda
R0=F%AB%Ro
q0=F%AB%qo
!$OMP SIMD
! !$OMP& aligned(Y_R,Y_PHI,Y_Z,B_R,B_PHI,B_Z,rm,qprof,Bmag)
do cc=1_idef,pchunk
rm(cc)=sqrt((Y_R(cc)-R0)*(Y_R(cc)-R0)+Y_Z(cc)*Y_Z(cc))
qprof(cc) = 1.0_rp + (rm(cc)*rm(cc)/(lam*lam))
B_R(cc)=B0*Y_Z(cc)/(q0*qprof(cc)*Y_R(cc))
B_PHI(cc)=-B0*R0/Y_R(cc)
B_Z(cc)=-B0*(Y_R(cc)-R0)/(q0*qprof(cc)*Y_R(cc))
Bmag(cc)=sqrt(B_R(cc)*B_R(cc)+B_PHI(cc)*B_PHI(cc)+B_Z(cc)*B_Z(cc))
E_PHI(cc)=EF0*R0/Y_R(cc)
end do
!$OMP END SIMD
end subroutine analytical_fields_Bmag_p