module nhelix {                            # Define nonstationary filter type
  use helix
	use helixcartmod
  type nfilter {                                 #  nd  is data length.
    logical,       dimension(:), pointer :: mis  # (nd) boundary conditions
    integer,       dimension(:), pointer :: pch  # (nd) patches
    type( filter), dimension(:), pointer :: hlx  # (np) filters
  }
contains
  subroutine nallocate( aa, nh, pch) {         # allocate a filter
    type( nfilter)                       :: aa
    integer, dimension(:), intent( in)   :: nh, pch  
    integer                              :: ip, np, nd
    np = size( nh); allocate( aa%hlx( np))
    do ip = 1, np{
       call allocatehelix( aa%hlx( ip), nh( ip))
		}
    nd = size( pch); allocate( aa%pch( nd)) 
    aa%pch = pch
    nullify( aa%mis)				   # set null pointer for mis.
#		write(0,*) "done with allocate",aa%pch
  }
  subroutine ndeallocate( aa) {		           # destroy a filter
    type( nfilter) :: aa
    integer        :: ip
    do ip = 1, size( aa%hlx)
	    call deallocatehelix( aa%hlx( ip))
    deallocate( aa%hlx, aa%pch)
    if( associated( aa%mis))			   # if logicals were allocated
        deallocate( aa%mis)			   # free them
  }
}
