function D = CutDic( partition, m, L, level )
% CutDic produces a non-uniform B spline dictionary
%  
% Usage:        D = CutDic( partition, m, L, level );
%
% Inputs:
%   partition   a partition to produce a non-uniform B spline dictionary (it can be 
%               computed by the function 'producepartition')
%   m           the order of the spline
%   L           the number of the sampling of the functions
%   level       it is related with the width of the B spline basis. When level=1, the 
%               function outputs the B spline basis.
%  
% Outputs:
%   D           the non-uniform B spline dictionary (matrix)

% See   http://www.ncrg.aston.ac.uk/Projects/HNLApprox/
%       http://www.nonlinear-approx.info/

D=[];
for k=1:level
    clear cutp;
    clear D0;
    if k==1 jilu=0; 
        else  jilu=1; cutp(1)=partition(1); 
    end
    for j=k:level:size(partition,2)-1
        jilu=jilu+1;
        cutp(jilu)=partition(j);
    end
    if cutp(end)~=partition(end) 
        cutp(end+1)=partition(end); 
    end
  
  
    D0=NonUniB(partition(1),partition(end),m,cutp,L);
  
    D=[D D0];
end

% Zhiqiang Xu (2009)
