module createnhelixmod {      # Create non-stationary helix filter lags and mis
use createhelixmod
use nhelix
use nbound
contains
  function createnhelix( nd, center, gap, na, pch) result (nsaa) {
    type( nfilter)                     :: nsaa   # needed by nhelicon
    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(:), intent(in)  :: pch	 # (prod(nd)) patching
    type( filter)                      :: aa
    integer                            :: n123, np, ip
    integer, dimension(:), allocatable :: nh


    aa = createhelix( nd, center, gap, na)
    n123 = product( nd);  np = maxval(pch)
    allocate (nh (np)); nh = size (aa%lag)
    call nallocate( nsaa, nh, pch)
    do ip = 1, np{
       nsaa%hlx( ip)%lag = aa%lag
#		write(0,*) ip,"check lags",nsaa%hlx(ip)%lag
		}
    call deallocatehelix (aa)
    call nboundn( nd,  nsaa) 
    }
}
