Home > classes > @history > hist2dot.m

hist2dot

PURPOSE ^

HIST2DOT converts a history object to a 'DOT' file suitable for

SYNOPSIS ^

function hist2dot(h, filename)

DESCRIPTION ^

 HIST2DOT converts a history object to a 'DOT' file suitable for
 processing with graphviz (www.graphviz.org).
 
 Usage: hist2dot(h, 'foo.dot');
 
 M Hewitson 23-05-07
 
 $Id: hist2dot.html,v 1.1 2007/06/08 14:15:05 hewitson Exp $

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function hist2dot(h, filename)
0002 
0003 % HIST2DOT converts a history object to a 'DOT' file suitable for
0004 % processing with graphviz (www.graphviz.org).
0005 %
0006 % Usage: hist2dot(h, 'foo.dot');
0007 %
0008 % M Hewitson 23-05-07
0009 %
0010 % $Id: hist2dot.html,v 1.1 2007/06/08 14:15:05 hewitson Exp $
0011 %
0012 
0013 %% Write .dot file
0014 
0015 fd = fopen(filename, 'w+');
0016 
0017 % write header
0018 fprintf(fd, 'digraph G \n{\n');
0019 
0020 [n,a, nodes] = getNodes(h, [], 0, 1, []);
0021 
0022 % Write block set
0023 fprintf(fd, 'end [label="END"];\n');
0024 for j=1:length(nodes)
0025   node = nodes(j);
0026   % wrap label
0027   % Do some command substitution
0028   fcn = node.names;
0029   shape = 'rectangle';
0030   fsize  = 12;
0031   Opsize = 24;
0032   opextras = 'style=filled, fillcolor=gray90 fixedsize=true width=0.5';
0033   extras  = '';
0034   switch fcn
0035     case 'times'
0036       fcn = '*';
0037       shape = 'circle';
0038       fsize = Opsize;
0039       extras = opextras;
0040     case 'mtimes'
0041       fcn = '.*';
0042       shape = 'circle';
0043       fsize = Opsize;
0044       extras = opextras;
0045     case 'plus'
0046       fcn = '+';
0047       shape = 'circle';
0048       fsize = Opsize;
0049       extras = opextras;
0050     case 'minus'
0051       fcn = '-';
0052       shape = 'circle';
0053       fsize = Opsize;
0054       extras = opextras;
0055     case 'rdivide'
0056       fcn = './';
0057       shape = 'circle';
0058       fsize = Opsize;
0059       extras = opextras;
0060     case 'mrdivide'
0061       fcn = '/';
0062       shape = 'circle';
0063       fsize = Opsize;
0064       extras = opextras;
0065   end      
0066       
0067   wstr = wrapstring([fcn char(node.params)], 10);
0068   ss = '';
0069   for s=wstr
0070     ss = [ss '\n' char(s)];
0071   end
0072   ss = ss(3:end);  
0073   fprintf(fd, '%s_%d [%s fontsize=%d shape=%s label="%s"];\n', node.names, j, extras, fsize, shape, ss);  
0074 end
0075 
0076 % Write node list
0077 fprintf(fd, '\n');
0078 fprintf(fd, '\n');
0079 
0080 for j=length(nodes):-1:1
0081 %   disp('----------------')
0082   node = nodes(j);
0083   if node.pn > 0
0084     dst  = nodes(node.pn);
0085     fprintf(fd, '%s_%d -> %s_%d;\n', node.names, j, dst.names, dst.n);
0086   else
0087     fprintf(fd, '%s_%d -> end;\n', node.names, j);
0088   end
0089 %   disp('----------------')
0090 end
0091 
0092 
0093 % close
0094 fprintf(fd, '}\n');
0095 
0096 % Close
0097 fclose(fd);
0098 
0099 edit 'test.dot'

Generated on Fri 08-Jun-2007 16:09:11 by m2html © 2003