      function mfilt(kx,ky,mx,my,mz,fx,fy,fz,z1,z2)
c
c  Function MFILT calculates the complex value of the earth 
c  filter at a single (kx,ky) location.
c
c  Input parameters:
c    kx - the wavenumber coordinate in the kx direction.
c    ky - the wavenumber coordinate in the ky direction.
c    mx - the x direction cosine of the magnetization vector.
c    my - the y direction cosine of the magnetization vector.
c    mz - the z direction cosine of the magnetization vector.
c    fx - the x direction cosine of the regional field vector.
c    fy - the y direction cosine of the regional field vector.
c    fz - the z direction cosine of the regional field vector.
c    z1 - the depth to the top of the layer.
c    z2 - the depth to the bottom of the layer.
c
c  Output parameters:
c    mfilt - the complex value of the earth filter.
c
      complex mfilt,thetam,thetaf,cmplx
      real kx,ky,k,mx,my,mz
      data pi/3.14159265/,cm/1.e-7/
      k=sqrt(kx**2+ky**2)
      if(k.eq.0.)then
         mfilt=0.
         else
            thetam=cmplx(mz,(kx*mx+ky*my)/k)
            thetaf=cmplx(fz,(kx*fx+ky*fy)/k)
            mfilt=2.*pi*cm*thetam*thetaf*(exp(-k*z1)-exp(-k*z2))
            end if
      return
      end
