mdot

PURPOSE ^

MDOT - Export a dependency graph into DOT language

SYNOPSIS ^

function mdot(mmat, dotfile,f)

DESCRIPTION ^

MDOT - Export a dependency graph into DOT language
  MDOT(MMAT, DOTFILE) loads a .mat file generated by M2HTML using option
  ('save','on') and writes an ascii file using the DOT language that can
  be drawn using <dot> or <neato> .
  MDOT(MMAT, DOTFILE,F) builds the graph containing M-file F and its
  neighbors only.
  See the folowing page for more details:
  <http://www.research.att.com/sw/tools/graphviz/>

  Example:
    mdot('m2html.mat','m2html.dot');
    !dot -Tps m2html.dot -o m2html.ps
    !neato -Tps m2html.dot -o m2html.ps

  See also M2HTML

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function mdot(mmat, dotfile,f)
0002 %MDOT - Export a dependency graph into DOT language
0003 %  MDOT(MMAT, DOTFILE) loads a .mat file generated by M2HTML using option
0004 %  ('save','on') and writes an ascii file using the DOT language that can
0005 %  be drawn using <dot> or <neato> .
0006 %  MDOT(MMAT, DOTFILE,F) builds the graph containing M-file F and its
0007 %  neighbors only.
0008 %  See the folowing page for more details:
0009 %  <http://www.research.att.com/sw/tools/graphviz/>
0010 %
0011 %  Example:
0012 %    mdot('m2html.mat','m2html.dot');
0013 %    !dot -Tps m2html.dot -o m2html.ps
0014 %    !neato -Tps m2html.dot -o m2html.ps
0015 %
0016 %  See also M2HTML
0017 
0018 %  Copyright (C) 2003 Guillaume Flandin <Guillaume@artefact.tk>
0019 %  $Revision: 1.0 $Date: 2003/29/04 17:33:43 $
0020 
0021 error(nargchk(2,3,nargin));
0022 
0023 if ischar(mmat)
0024     load(mmat);
0025 elseif iscell(mmat)
0026     hrefs  = mmat{1};
0027     names  = mmat{2};
0028     options = mmat{3};
0029     if nargin == 3, mfiles = mmat{4}; end
0030 else
0031     error('[mdot] Invalid argument: mmat.');
0032 end
0033 
0034 if 1
0035     URLnames=names;
0036 else
0037     %relative path needed for URL of mfile documentation
0038     mfiles = mmat{4};
0039     URLnames=cell(size(hrefs,1),1);
0040     for i=1:size(hrefs,1)
0041         if 0
0042             rem=mfiles{i};
0043             while ~isempty(rem)
0044                 [str,rem]=strtok(rem,'/');
0045             end
0046             URLnames{i}=str(1:end-2);
0047         else
0048             URLnames{i}=mfiles{i}(length(options.mFiles{1})+2:end-2);
0049         end
0050     end
0051     pause(eps)
0052 end
0053 
0054 fid = fopen(dotfile,'w');
0055 if fid == -1, error(sprintf('[mdot] Cannot open %s.',dotfile)); end
0056 
0057 fprintf(fid,'/* Created by mdot for Matlab */\n');
0058 fprintf(fid,'digraph m2html {\n');
0059 
0060 if nargin == 2
0061     for i=1:size(hrefs,1)
0062         n = find(hrefs(i,:) == 1);
0063         m{i} = n;
0064         for j=1:length(n)
0065             fprintf(fid,['  ' names{i} ' -> ' names{n(j)} ';\n']);
0066         end
0067     end
0068     %m = unique([m{:}]);
0069     fprintf(fid,'\n');
0070     for i=1:size(hrefs,1)
0071         fprintf(fid,['  ' names{i} ' [URL="' URLnames{i} options.extension '"];\n']);
0072     end
0073 else
0074     i = find(strcmp(f,mfiles));
0075     if length(i) ~= 1
0076         error(sprintf('[mdot] Cannot find %s.',f));
0077     end
0078     n = find(hrefs(i,:) == 1);
0079     for j=1:length(n)
0080         fprintf(fid,['  ' names{i} ' -> ' names{n(j)} ';\n']);
0081     end
0082     m = find(hrefs(:,i) == 1);
0083     for j=1:length(m)
0084         if n(j) ~= i
0085             fprintf(fid,['  ' names{m(j)} ' -> ' names{i} ';\n']);
0086         end
0087     end
0088     n = unique([n(:)' m(:)']);
0089     fprintf(fid,'\n');
0090     for i=1:length(n)
0091         fprintf(fid,['  ' names{n(i)} ' [URL="' URLnames{n(i)} options.extension '"];\n']);
0092     end
0093 end
0094 
0095 fprintf(fid,'}');
0096 
0097 fid = fclose(fid);
0098 if fid == -1, error(sprintf('[mdot] Cannot close %s.',dotfile)); end

Generated on Thu 21-Jun-2012 15:39:23 by m2html © 2003