      subroutine dipole(xq,yq,zq,a,mi,md,m,xp,yp,zp,bx,by,bz)
c
c  Subroutine DIPOLE computes the three components of magnetic
c  induction caused by a uniformly magnetized sphere.  X Axis
c  is north, z axis is down.  
c
c  Input parameters:
c    Observation point located at (xp,yp,zp).  Sphere centered  
c    at (xq,yq,zq).  Magnetization of sphere defined by 
c    intensity m, inclination mi, and declination md.  Units 
c    of distance irrelevant but must be consistent. All angles 
c    in degrees.  Intensity of magnetization in A/m.  Requires 
c    subroutine DIRCOS.
c
c  Output parameters:
c    The three components of magnetic induction (bx,by,bz) in 
c    units of nT.
c
      real mi,md,m,mx,my,mz,moment
      data pi/3.14159265/,t2nt/1.e9/,cm/1.e-7/
      call dircos(mi,md,0.,mx,my,mz)
      rx=xp-xq
      ry=yp-yq
      rz=zp-zq
      r2=rx**2+ry**2+rz**2
      r=sqrt(r2)
      if(r.eq.0.)pause 'DIPOLE:  Bad argument detected.'
      r5=r**5
      dot=rx*mx+ry*my+rz*mz
      moment=4.*pi*(a**3)*m/3
      bx=cm*moment*(3.*dot*rx-r2*mx)/r5
      by=cm*moment*(3.*dot*ry-r2*my)/r5
      bz=cm*moment*(3.*dot*rz-r2*mz)/r5
      bx=bx*t2nt
      by=by*t2nt
      bz=bz*t2nt
      return
      end                        
