
module createmshelixmod {         # Create multiscale helix filter lags and mis
use mshelix
use createhelixmod
use bound
contains
  function createmshelix( nd, center, gap, jump, na)  result( msaa) {
    type( msfilter)                   :: msaa    # needed by mshelicon.
    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) :: jump	 # jump(ns) stretch scales
    type( filter)                     :: aa
    integer                           :: is, ns, nh, n123 
    aa = createhelix( nd, center, gap, na)
    ns = size( jump);  nh = size( aa%lag);  n123 = product( nd)
    call msallocate( msaa, nh, ns)
    do is = 1, ns	
        msaa%lag(:,is) = aa%lag(:)*jump(is)	 # set lags for expanded scale
    call deallocatehelix( aa)
    allocate( msaa%mis( n123, ns))
    do is = 1, ns {				 # for all scales
     call onescale( is, msaa, aa);  nullify( aa%mis)	# extract a filter
     call boundn( nd, nd, na*jump(is), aa)		# set up its boundaries
     msaa%mis( :, is) = aa%mis;  deallocate( aa%mis)	# save them
    }
  }
}
