# 1 "<stdin>"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "<stdin>"

module box
! Convert helix filter to hypercube: cube(na(1),na(2),...)
  use helix
  use cartesian
  implicit none
  contains
  subroutine boxn( nd, center, na, aa, cube)
    integer, dimension (:), intent( in) :: nd, center, na
    ! (ndim)
    type( filter), intent( in) :: aa
    real, dimension( :), intent( out) :: cube
    integer, dimension( size( nd)) :: ii
    integer :: j, lag0a, lag0d, id, ia
    cube = 0.
! cube=0
    call cart2line( na, center, lag0a)
    ! locate the 1.0 in the na_cube.
    cube( lag0a) = 1. ! place it.
    call cart2line( nd, center, lag0d)
    ! locate the 1.0 in the nd_cube.
    do j = 1, size( aa%lag)
! inspect the entire helix
      id = aa%lag( j) + lag0d ! index = helix_lag + center_d
      call line2cart( nd, id, ii) ! ii(id) = cartesian indices
      call cart2line( na, ii, ia) ! ia(ii) = linear index in aa
      cube( ia) = aa%flt( j) ! copy the filter coefficient
    end do
  end subroutine
end module
