Home > classes > @history > hist2dot.m

hist2dot

PURPOSE ^

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

SYNOPSIS ^

function hist2dot(h, filename)

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.m,v 1.3 2007/07/18 13:58:44 ingo Exp $

 HISTORY:     23-05-2007 M Hewitson
                 Creation

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

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function hist2dot(h, filename)
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.m,v 1.3 2007/07/18 13:58:44 ingo Exp $
0016 %
0017 % HISTORY:     23-05-2007 M Hewitson
0018 %                 Creation
0019 %
0020 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0021 
0022 
0023 %% Write .dot file
0024 
0025 fd = fopen(filename, 'w+');
0026 
0027 % write header
0028 fprintf(fd, 'digraph G \n{\n');
0029 
0030 [n,a, nodes] = getNodes(h, [], 0, 1, []);
0031 
0032 % Write block set
0033 fprintf(fd, 'end [label="END"];\n');
0034 for j=1:length(nodes)
0035   node = nodes(j);
0036   % wrap label
0037   % Do some command substitution
0038   fcn = node.names;
0039   shape = 'rectangle';
0040   fsize  = 12;
0041   Opsize = 24;
0042   opextras = 'style=filled, fillcolor=gray90 fixedsize=true width=0.5';
0043   extras  = '';
0044   switch fcn
0045     case 'times'
0046       fcn = '*';
0047       shape = 'circle';
0048       fsize = Opsize;
0049       extras = opextras;
0050     case 'mtimes'
0051       fcn = '.*';
0052       shape = 'circle';
0053       fsize = Opsize;
0054       extras = opextras;
0055     case 'plus'
0056       fcn = '+';
0057       shape = 'circle';
0058       fsize = Opsize;
0059       extras = opextras;
0060     case 'minus'
0061       fcn = '-';
0062       shape = 'circle';
0063       fsize = Opsize;
0064       extras = opextras;
0065     case 'rdivide'
0066       fcn = './';
0067       shape = 'circle';
0068       fsize = Opsize;
0069       extras = opextras;
0070     case 'mrdivide'
0071       fcn = '/';
0072       shape = 'circle';
0073       fsize = Opsize;
0074       extras = opextras;
0075   end
0076 
0077   wstr = wrapstring([fcn char(node.params)], 10);
0078   ss = '';
0079   for s=wstr
0080     ss = [ss '\n' char(s)];
0081   end
0082   ss = ss(3:end);
0083   fprintf(fd, '%s_%d [%s fontsize=%d shape=%s label="%s"];\n', node.names, j, extras, fsize, shape, ss);
0084 end
0085 
0086 % Write node list
0087 fprintf(fd, '\n');
0088 fprintf(fd, '\n');
0089 
0090 for j=length(nodes):-1:1
0091 %   disp('----------------')
0092   node = nodes(j);
0093   if node.pn > 0
0094     dst  = nodes(node.pn);
0095     fprintf(fd, '%s_%d -> %s_%d;\n', node.names, j, dst.names, dst.n);
0096   else
0097     fprintf(fd, '%s_%d -> end;\n', node.names, j);
0098   end
0099 %   disp('----------------')
0100 end
0101 
0102 
0103 % close
0104 fprintf(fd, '}\n');
0105 
0106 % Close
0107 fclose(fd);
0108

Generated on Mon 03-Sep-2007 12:12:34 by m2html © 2003