function [partition,parent] = mgetpart(catalog,code,node)
%MGETPART Returns a list of all possible partitions for a specified superblock.
%
%

% A. S. Bozin, 5-4-98.
% Copyright 1997-2000 The MathWorks, Inc.
% $Revision: 1.4 $ $Date: 2000/06/14 16:12:36 $

   partition = {};
   parent = [];
   [partition,parent] = getpartition(catalog,code,node,partition,parent);
   %
   % Remove duplicated entries
   %
   if (size(parent,1) > 1)
      [parent(:),ind] = sort(parent);
      partition(:) = partition(ind);
      k = 1;
      while (k < size(parent,1))
	 ind = find((parent(k+1:end) == parent(k)) & strcmp(partition(k+1:end),partition{k}))+k;
	 if (~isempty(ind))
	    parent(ind) = [];
	    partition(ind) = '';
	 end
	 k = k+1;
      end
   end
   return					   % Last card of MGETPART

function [partition,parent] = getpartition(catalog,code,node,partition,parent)
%GETPARTITION Browse through the catalog and return all possible partitions
%
%
   roots = catalog(node).parent;
   if (roots == size(catalog,1))
      %
      % Root of the linked list
      %
      partition{end+1,1} = catalog(roots).partition;
      parent(end+1,1) = node;
   else
      %
      % For all parents do
      %
      for (sb = roots)
	 kids = catalog(sb).sbChild;
	 ind = find(kids == node);
	 if (isempty(ind))
	    [partition,parent] = getpartition(catalog,code,sb,partition,parent);
	 else
	    blocks = catalog(sb).sbBlock(ind);
	    for (cb = blocks)
	       bstr = code(sb).str.blk{cb};	   % Strings associated with the current block
	       bint = code(sb).int.blk{cb};	   % Integers
	       indStr = bint(17)+1;
	       ind = mfindstr(bstr,indStr,'|');
	       ws = bstr(indStr:ind-1);
	       if (isempty(ws))
		  [partition,parent] = getpartition(catalog,code,sb,partition,parent);
	       else
		  partition{end+1,1} = ws;
		  parent(end+1,1) = node;
	       end
	    end
	 end
      end
   end
   return					   % Last card of GETPARTITION
