module createhelixmod {            # Allocate a helix filter and find its lags
use helix
use helixcartmod
contains
  function createhelix( nd, center, gap, na)  result( aa) {
    type( filter)                     :: aa       # needed by helicon.
    integer, dimension(:), intent(in) :: nd, na   # data and filter axes
    integer, dimension(:), intent(in) :: center   # normally (na1/2,na2/2,...,1)
    integer, dimension(:), intent(in) :: gap      # normally ( 0,   0,  0,...,0)
    integer, dimension( size( nd))    :: ii       # cartesian indexes
    integer                           :: na123, ia, ndim, idim, h, lag0
    integer, dimension(:), allocatable:: lag
           h= 0.;   na123 = product( na);   ndim = size( nd)
    allocate(  lag( na123 ) )
    box: do ia = 1, na123 {               #    ia  is fortran linear subscript.
       call helix2cart( na, ia, ii)       # ii(ia) is fortran array subscript.
       if( all( ii == center)  .or.  any( ii <= gap))    next box  # A
       do idim = 1, ndim-1  {
           if( all( ii( idim+1:) == center( idim+1:)) )            # B
            if(     ii( idim   ) <  center( idim   )  )            # C
	                                        next box
           }
       if( ii( ndim) < center( ndim))           next box           # D
       h = h + 1                               # got one!
       call cart2helix( nd, ii, lag(h))
       }
    call cart2helix(  nd, center, lag0) 
    call allocatehelix( aa, h)			# Now h becomes the filter size.
    aa%lag = lag(1:h) - lag0;			# Shift so lag0 at zero lag
    aa%flt = 0.0;             deallocate( lag)
    }      
}
