subroutine interp_nRE(params,Y_R,Y_PHI,Y_Z,PSIp,EPHI,ne,Te,nRE, &
nAr0,nAr1,nAr2,nAr3,nD,nD1,g_test,fRE_out,rho1D)
TYPE(KORC_PARAMS), INTENT(IN) :: params
REAL(rp),INTENT(IN) :: Y_R,Y_PHI,Y_Z,g_test
REAL(rp),INTENT(OUT) :: PSIp,EPHI,ne,Te,nRE,fRE_out
REAL(rp),INTENT(OUT) :: nAr0,nAr1,nAr2,nAr3,nD,nD1
REAL(rp) :: RHON
INTEGER(is),DIMENSION(1) :: flag_cache
REAL(rp), INTENT(IN),optional :: rho1D
flag_cache=1_is
call check_if_in_profiles_domain_p(1,(/Y_R/),(/Y_PHI/),(/Y_Z/), &
flag_cache)
if (flag_cache(1).ne.0_is) then
call EZspline_interp(bfield_2d%A,efield_2d%PHI, &
profiles_2d%ne,profiles_2d%Te, &
profiles_2d%nRE,profiles_2d%nAr0,profiles_2d%nAr1, &
profiles_2d%nAr2,profiles_2d%nAr3,profiles_2d%nD,profiles_2d%nD1, &
profiles_2d%RHON,Y_R,Y_Z, &
PSIp,EPHI,ne,Te,nRE,nAr0,nAr1,nAr2,nAr3,nD,nD1,RHON,ezerr)
call EZspline_error(ezerr)
!write(6,*) 'RHON',RHON
if ((RHON.le.1).and.(RHON.gt.0)) then
if(present(rho1D)) RHON=rho1D
call EZspline_interp(hollmann_2d%fRE_E,RHON,g_test,fRE_out,ezerr)
call EZspline_error(ezerr)
if (ezerr .NE. 0) then ! We flag the particle as lost
write(6,*) 'R,Z',Y_R*params%cpp%length,Y_Z*params%cpp%length
write(6,*) 'RHON',RHON
end if
else
fRE_out=0._rp
endif
if (fRE_OUT.lt.0) fRE_OUT=0._rp
else
fRE_OUT=0._rp
nRE=0._rp
endif
end subroutine interp_nRE