Home > classes > @history > getNodes.m

getNodes

PURPOSE ^

GETNODES converts a history object to a nodes structure suitable for plotting as a tree.

SYNOPSIS ^

function [varargout] = getNodes(varargin)

DESCRIPTION ^

 GETNODES converts a history object to a nodes structure suitable for plotting as a tree.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

 DESCRIPTION: GETNODES converts a history object to a nodes structure suitable
              for plotting as a tree.

 CALL:        [n,a, nodes] = getNodes(hist, [], 0, 1, []);

 OUTPUT:      n:     A vector of parent pointers
              a:     Number of nodes
              nodes: Struct of the nodes

 VERSION:     $Id: getNodes.html,v 1.14 2008/03/31 10:27:38 hewitson Exp $

 HISTORY:     02-02-2007 M Hewitson
                 Creation

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [varargout] = getNodes(varargin)
0002 % GETNODES converts a history object to a nodes structure suitable for plotting as a tree.
0003 %
0004 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0005 %
0006 % DESCRIPTION: GETNODES converts a history object to a nodes structure suitable
0007 %              for plotting as a tree.
0008 %
0009 % CALL:        [n,a, nodes] = getNodes(hist, [], 0, 1, []);
0010 %
0011 % OUTPUT:      n:     A vector of parent pointers
0012 %              a:     Number of nodes
0013 %              nodes: Struct of the nodes
0014 %
0015 % VERSION:     $Id: getNodes.html,v 1.14 2008/03/31 10:27:38 hewitson Exp $
0016 %
0017 % HISTORY:     02-02-2007 M Hewitson
0018 %                 Creation
0019 %
0020 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0021 
0022 VERSION  = '$Id: getNodes.html,v 1.14 2008/03/31 10:27:38 hewitson Exp $';
0023 CATEGORY = 'Internal';
0024 
0025 % Prepare outputs
0026 n     = [];
0027 a     = [];
0028 nodes = [];
0029 
0030 % Check if this is a call for parameters
0031 if nargin == 2
0032   if isa(varargin{1}, 'history') && ischar(varargin{2})
0033     in = char(varargin{2});
0034     if strcmp(in, 'Params')
0035       varargout{1} = plist;
0036       return
0037     elseif strcmp(in, 'Version')
0038       varargout{1} = VERSION;
0039       return
0040     elseif strcmp(in, 'Category')
0041       varargout{1} = CATEGORY;
0042       return
0043     end
0044   end
0045 end
0046 
0047 % Set input
0048 h     = varargin{1};
0049 n     = varargin{2};
0050 pn    = varargin{3};
0051 a     = varargin{4};
0052 nodes = varargin{5};
0053 
0054 % set my node to next number
0055 nn = h.n;
0056 if nn<0
0057   h.n = a;
0058 end
0059 
0060 % set my parent node
0061 nn = h.pn; 
0062 if nn<0
0063   h.pn = pn;
0064   n = [n pn];
0065   pl = h.plist;
0066   nodes(a).pn     = pn;
0067   nodes(a).invars = h.invars;
0068   nodes(a).n      = h.n; 
0069   nodes(a).names  = h.name;
0070   nodes(a).params = char(pl);
0071   nodes(a).pl     = pl;
0072   nodes(a).h      = h;
0073   disp(sprintf(' -- scanning node %d [%s]', pn, char(nodes(a).names)));
0074 end
0075 
0076 % I need my parent node
0077 pn = h.n;
0078 
0079 % get my children nodes
0080 ihs = h.inhists;
0081 
0082 % Now decide what to do with my children
0083 if isa(ihs, 'history')
0084   for i=1:length(ihs)
0085     % get child number
0086     nn = ihs(i).n;
0087     % if this child is not set
0088     if nn < 0
0089       % set it
0090       a = a + 1;
0091       [n,a, nodes] = getNodes(ihs(i), n, pn, a, nodes);
0092     else % else go back to my parent
0093       [n,a, nodes] = getNodes(h, n, get(h,'pn'), a, nodes);
0094     end
0095   end
0096 end
0097 
0098 % Set outputs
0099 varargout{1} = n;
0100 varargout{2} = a;
0101 varargout{3} = nodes;
0102 
0103 
0104

Generated on Mon 31-Mar-2008 12:20:24 by m2html © 2003