subroutine get_bfield(igrid,x,tloc,b)
use mod_global_parameters
use mod_usr_methods, only: usr_particle_analytic, usr_particle_fields
integer,intent(in) :: igrid
double precision,dimension(3), intent(in) :: x
double precision, intent(in) :: tloc
double precision,dimension(ndir), intent(out) :: b
double precision,dimension(ndir) :: vec1, vec2, vec
double precision :: td
integer :: ic1,ic2,ic3,idir
if (associated(usr_particle_analytic)) then
call usr_particle_analytic(bp, x, tloc, vec)
else if (associated(usr_particle_fields)) then
call get_vec(bp, igrid, x, tloc, vec)
else
do idir=1,ndir
call interpolate_var(igrid,ixGlo1,ixGlo2,ixGlo3,ixGhi1,ixGhi2,ixGhi3,&
ixMlo1,ixMlo2,ixMlo3,ixMhi1,ixMhi2,ixMhi3,&
gridvars(igrid)%w(ixGlo1:ixGhi1,ixGlo2:ixGhi2,ixGlo3:ixGhi3,&
bp(idir)), ps(igrid)%x(ixGlo1:ixGhi1,ixGlo2:ixGhi2,ixGlo3:ixGhi3,&
1:ndim),x,vec(idir))
end do
if (time_advance) then
do idir=1,ndir
call interpolate_var(igrid,ixGlo1,ixGlo2,ixGlo3,ixGhi1,ixGhi2,ixGhi3,&
ixMlo1,ixMlo2,ixMlo3,ixMhi1,ixMhi2,ixMhi3,&
gridvars(igrid)%wold(ixGlo1:ixGhi1,ixGlo2:ixGhi2,ixGlo3:ixGhi3,&
bp(idir)), ps(igrid)%x(ixGlo1:ixGhi1,ixGlo2:ixGhi2,ixGlo3:ixGhi3,&
1:ndim),x,vec2(idir))
end do
td = (tloc - global_time) / dt
vec(:) = vec(:) * (1.0d0 - td) + vec2(:) * td
end if
end if
b(:) = vec(:)
end subroutine get_bfield