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

 M-FILE INFO: Get information about this methods by calling
              >> history.getInfo('hist2dot')

              Get information about a specified set-plist by calling:
              >> history.getInfo('hist2dot', 'set')

 VERSION:     $Id: hist2dot.m,v 1.6 2008/09/04 15:29:30 ingo Exp $

 HISTORY:     23-05-2007 M Hewitson
                 Creation

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

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 % HIST2DOT converts a history object to a 'DOT' file suitable for processing with graphviz
0002 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0003 %
0004 % DESCRIPTION: HIST2DOT converts a history object to a 'DOT' file suitable for
0005 %              processing with graphviz (www.graphviz.org).
0006 %
0007 % CALL:        hist2dot(h, 'foo.dot');
0008 %
0009 % INPUT:       h       - history object
0010 %              foo.dot - file name to view the graphic with the programm
0011 %                        graphviz
0012 %
0013 % M-FILE INFO: Get information about this methods by calling
0014 %              >> history.getInfo('hist2dot')
0015 %
0016 %              Get information about a specified set-plist by calling:
0017 %              >> history.getInfo('hist2dot', 'set')
0018 %
0019 % VERSION:     $Id: hist2dot.m,v 1.6 2008/09/04 15:29:30 ingo Exp $
0020 %
0021 % HISTORY:     23-05-2007 M Hewitson
0022 %                 Creation
0023 %
0024 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0025 
0026 function varargout = hist2dot(varargin)
0027 
0028   %%% Check if this is a call for parameters
0029   if utils.helper.isinfocall(varargin{:})
0030     varargout{1} = getInfo(varargin{3});
0031     return
0032   end
0033 
0034   %%% Set inputs
0035   h        = varargin{1};
0036   filename = varargin{2};
0037 
0038 
0039   %%% Write .dot file
0040 
0041   fd = fopen(filename, 'w+');
0042 
0043   %%% write header
0044   fprintf(fd, 'digraph G \n{\n');
0045 
0046   [n,a, nodes] = getNodes(h, [], 0, 1, []);
0047 
0048   %%% Write block set
0049   fprintf(fd, 'end [label="END"];\n');
0050   for j=1:length(nodes)
0051     node = nodes(j);
0052     % wrap label
0053     % Do some command substitution
0054     fcn = node.names;
0055     shape = 'rectangle';
0056     fsize  = 12;
0057     Opsize = 24;
0058     opextras = 'style=filled, fillcolor=gray90 fixedsize=true width=0.5';
0059     extras  = '';
0060     switch fcn
0061       case 'times'
0062         fcn = '*';
0063         shape = 'circle';
0064         fsize = Opsize;
0065         extras = opextras;
0066       case 'mtimes'
0067         fcn = '.*';
0068         shape = 'circle';
0069         fsize = Opsize;
0070         extras = opextras;
0071       case 'plus'
0072         fcn = '+';
0073         shape = 'circle';
0074         fsize = Opsize;
0075         extras = opextras;
0076       case 'minus'
0077         fcn = '-';
0078         shape = 'circle';
0079         fsize = Opsize;
0080         extras = opextras;
0081       case 'rdivide'
0082         fcn = './';
0083         shape = 'circle';
0084         fsize = Opsize;
0085         extras = opextras;
0086       case 'mrdivide'
0087         fcn = '/';
0088         shape = 'circle';
0089         fsize = Opsize;
0090         extras = opextras;
0091     end
0092 
0093     wstr = utils.prog.wrapstring([fcn char(node.params)], 10);
0094     ss = '';
0095     for s=wstr
0096       ss = [ss '\n' char(s)];
0097     end
0098     ss = ss(3:end);
0099     fprintf(fd, '%s_%d [%s fontsize=%d shape=%s label="%s"];\n', node.names, j, extras, fsize, shape, ss);
0100   end
0101 
0102   %%% Write node list
0103   fprintf(fd, '\n');
0104   fprintf(fd, '\n');
0105 
0106   for j=length(nodes):-1:1
0107     %   disp('----------------')
0108     node = nodes(j);
0109     if node.pn > 0
0110       dst  = nodes(node.pn);
0111       fprintf(fd, '%s_%d -> %s_%d;\n', node.names, j, dst.names, dst.n);
0112     else
0113       fprintf(fd, '%s_%d -> end;\n', node.names, j);
0114     end
0115     %   disp('----------------')
0116   end
0117 
0118 
0119   %%% close
0120   fprintf(fd, '}\n');
0121 
0122   %%% Close
0123   fclose(fd);
0124 
0125 end
0126 
0127 
0128 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0129 %                               Local Functions                               %
0130 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0131 
0132 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0133 %
0134 % FUNCTION:    getInfo
0135 %
0136 % DESCRIPTION: Get Info Object
0137 %
0138 % HISTORY:     11-07-07 M Hewitson
0139 %                Creation.
0140 %
0141 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0142 
0143 function ii = getInfo(varargin)
0144   if nargin == 1 && strcmpi(varargin{1}, 'None')
0145     sets = {};
0146     pl   = [];
0147   else
0148     sets = {'Default'};
0149     pl   = getDefaultPlist;
0150   end
0151   % Build info object
0152   ii = minfo(mfilename, 'history', '', utils.const.categories.output, '$Id: hist2dot.m,v 1.6 2008/09/04 15:29:30 ingo Exp $', sets, pl);
0153 end
0154 
0155 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0156 %
0157 % FUNCTION:    getDefaultPlist
0158 %
0159 % DESCRIPTION: Get Default Plist
0160 %
0161 % HISTORY:     11-07-07 M Hewitson
0162 %                Creation.
0163 %
0164 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0165 
0166 function plo = getDefaultPlist()
0167   plo = plist();
0168 end
0169

Generated on Mon 08-Sep-2008 13:18:47 by m2html © 2003