module wem_wnbmap_mod
  implicit none

contains
  !!----------------------------------------------------------
  !!.. Calculate the k map
  !!----------------------------------------------------------
  subroutine k_map(k,n,d)
    real,  dimension(:) :: k
    integer, intent(in) :: n
    real,    intent(in) :: d
    integer             :: i,m
    real, parameter     :: PI = 3.14159265359
    k=0.
    if(n/=1) then
       m = n/2
       do i=1,m+1
          k(i)=i-1
       end do
       do i=m+2,n
          k(i)=i-n-1
       end do
    else
       k=0. !! make sure k=0 if n=1
    end if

    k = k / (n*d)      !! 1/length
    k = 2 * PI * k     !! radians
    return
  end subroutine

  !!----------------------------------------------------------
  !!.. Calculate the k-square map
  !!----------------------------------------------------------
  subroutine k2_map(k,n,d)
    real,  dimension(:) :: k
    integer, intent(in) :: n
    real,    intent(in) :: d
    integer             :: i,m
    real, parameter     :: PI = 3.14159265359
    k=0.
    if(n/=1) then
       m = n/2
       do i=1,m+1
          k(i)=i-1
       end do
       do i=m+2,n
          k(i)=i-n-1
       end do
    else
       k=0. !! make sure k=0 if n=1
    end if

    k = k / (n*d)      !! 1/length
    k = 2 * PI * k     !! radians
    k = k * k          !! k square
    return
  end subroutine


end module
