Home > classes > @history > hist2dot.m

hist2dot

PURPOSE ^

HIST2DOT converts a history object to a 'DOT' file suitable for processing with graphviz

SYNOPSIS ^

function varargout = hist2dot(varargin)

DESCRIPTION ^

 HIST2DOT converts a history object to a 'DOT' file suitable for processing with graphviz

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

 DESCRIPTION: HIST2DOT converts a history object to a 'DOT' file suitable for
              processing with graphviz (www.graphviz.org).

 CALL:        hist2dot(h, 'foo.dot');

 INPUT:       h       - history object
              foo.dot - file name to view the graphic with the programm
                        graphviz

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

 HISTORY:     23-05-2007 M Hewitson
                 Creation

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

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function varargout = hist2dot(varargin)
0002 % HIST2DOT converts a history object to a 'DOT' file suitable for processing with graphviz
0003 %
0004 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0005 %
0006 % DESCRIPTION: HIST2DOT converts a history object to a 'DOT' file suitable for
0007 %              processing with graphviz (www.graphviz.org).
0008 %
0009 % CALL:        hist2dot(h, 'foo.dot');
0010 %
0011 % INPUT:       h       - history object
0012 %              foo.dot - file name to view the graphic with the programm
0013 %                        graphviz
0014 %
0015 % VERSION:     $Id: hist2dot.html,v 1.14 2008/03/31 10:27:38 hewitson Exp $
0016 %
0017 % HISTORY:     23-05-2007 M Hewitson
0018 %                 Creation
0019 %
0020 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0021 
0022 
0023 VERSION  = '$Id: hist2dot.html,v 1.14 2008/03/31 10:27:38 hewitson Exp $';
0024 CATEGORY = 'Output';
0025 
0026 % Check if this is a call for parameters
0027 if nargin == 2
0028   if isa(varargin{1}, 'history') && ischar(varargin{2})
0029     in = char(varargin{2});
0030     if strcmp(in, 'Params')
0031       varargout{1} = plist;
0032       return
0033     elseif strcmp(in, 'Version')
0034       varargout{1} = VERSION;
0035       return
0036     elseif strcmp(in, 'Category')
0037       varargout{1} = CATEGORY;
0038       return
0039     end
0040   end
0041 end
0042 
0043 % Set inputs
0044 h        = varargin{1};
0045 filename = varargin{2};
0046 
0047 
0048 %% Write .dot file
0049 
0050 fd = fopen(filename, 'w+');
0051 
0052 % write header
0053 fprintf(fd, 'digraph G \n{\n');
0054 
0055 [n,a, nodes] = getNodes(h, [], 0, 1, []);
0056 
0057 % Write block set
0058 fprintf(fd, 'end [label="END"];\n');
0059 for j=1:length(nodes)
0060   node = nodes(j);
0061   % wrap label
0062   % Do some command substitution
0063   fcn = node.names;
0064   shape = 'rectangle';
0065   fsize  = 12;
0066   Opsize = 24;
0067   opextras = 'style=filled, fillcolor=gray90 fixedsize=true width=0.5';
0068   extras  = '';
0069   switch fcn
0070     case 'times'
0071       fcn = '*';
0072       shape = 'circle';
0073       fsize = Opsize;
0074       extras = opextras;
0075     case 'mtimes'
0076       fcn = '.*';
0077       shape = 'circle';
0078       fsize = Opsize;
0079       extras = opextras;
0080     case 'plus'
0081       fcn = '+';
0082       shape = 'circle';
0083       fsize = Opsize;
0084       extras = opextras;
0085     case 'minus'
0086       fcn = '-';
0087       shape = 'circle';
0088       fsize = Opsize;
0089       extras = opextras;
0090     case 'rdivide'
0091       fcn = './';
0092       shape = 'circle';
0093       fsize = Opsize;
0094       extras = opextras;
0095     case 'mrdivide'
0096       fcn = '/';
0097       shape = 'circle';
0098       fsize = Opsize;
0099       extras = opextras;
0100   end
0101 
0102   wstr = wrapstring([fcn char(node.params)], 10);
0103   ss = '';
0104   for s=wstr
0105     ss = [ss '\n' char(s)];
0106   end
0107   ss = ss(3:end);
0108   fprintf(fd, '%s_%d [%s fontsize=%d shape=%s label="%s"];\n', node.names, j, extras, fsize, shape, ss);
0109 end
0110 
0111 % Write node list
0112 fprintf(fd, '\n');
0113 fprintf(fd, '\n');
0114 
0115 for j=length(nodes):-1:1
0116 %   disp('----------------')
0117   node = nodes(j);
0118   if node.pn > 0
0119     dst  = nodes(node.pn);
0120     fprintf(fd, '%s_%d -> %s_%d;\n', node.names, j, dst.names, dst.n);
0121   else
0122     fprintf(fd, '%s_%d -> end;\n', node.names, j);
0123   end
0124 %   disp('----------------')
0125 end
0126 
0127 
0128 % close
0129 fprintf(fd, '}\n');
0130 
0131 % Close
0132 fclose(fd);
0133

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