module gabor

  integer, parameter, private :: r8 = selected_real_kind(12,100)
  complex(r8), parameter, private :: imag = (0._r8, 1._r8)
  character(*), parameter, private ::  version = &
       & '$Id: gabor.f90,v 1.4 2003/10/17 14:22:49 pletzer Exp $'

contains

  function Gabor0(x, z, ak, sigma)

    ! Scalar Gabor function

    implicit none
    complex(r8) Gabor0
    real(r8), intent(in) :: x ! collocation point
    real(r8), intent(in) :: z ! envelop position
    real(r8), intent(in) :: ak ! wave number
    real(r8), intent(in) :: sigma ! inverse extent

    Gabor0 = exp(imag*ak*x) * exp(-0.5_r8 * sigma * (x-z)**2)
  end function Gabor0

  function GaborN(x, z, ak, sigma)

    ! N-dimensional Gabor function 

    implicit none
    complex(r8) GaborN
    real(r8), intent(in) :: x(:) ! collocation point
    real(r8), intent(in) :: z(:) ! envelop position
    real(r8), intent(in) :: ak(:) ! wave number
    real(r8), intent(in) :: sigma(:) ! inverse extent

    GaborN = exp(imag*dot_product(ak,x)) * exp(-0.5_r8 * dot_product(sigma, (x-z)**2))
  end function GaborN

end module gabor

