1 | function mdot(mmat, dotfile,f) |
---|
2 | %MDOT - Export a dependency graph into DOT language |
---|
3 | % MDOT(MMAT, DOTFILE) loads a .mat file generated by M2HTML using option |
---|
4 | % ('save','on') and writes an ascii file using the DOT language that can |
---|
5 | % be drawn using <dot> or <neato> . |
---|
6 | % MDOT(MMAT, DOTFILE,F) builds the graph containing M-file F and its |
---|
7 | % neighbors only. |
---|
8 | % See the following page for more details: |
---|
9 | % <http://www.graphviz.org/> |
---|
10 | % |
---|
11 | % Example: |
---|
12 | % mdot('m2html.mat','m2html.dot'); |
---|
13 | % !dot -Tps m2html.dot -o m2html.ps |
---|
14 | % !neato -Tps m2html.dot -o m2html.ps |
---|
15 | % |
---|
16 | % See also M2HTML |
---|
17 | |
---|
18 | % Copyright (C) 2004 Guillaume Flandin <Guillaume@artefact.tk> |
---|
19 | % $Revision: 1.1 $Date: 2004/05/05 17:14:09 $ |
---|
20 | |
---|
21 | error(nargchk(2,3,nargin)); |
---|
22 | |
---|
23 | if ischar(mmat) |
---|
24 | load(mmat); |
---|
25 | elseif iscell(mmat) |
---|
26 | hrefs = mmat{1}; |
---|
27 | names = mmat{2}; |
---|
28 | options = mmat{3}; |
---|
29 | if nargin == 3, mfiles = mmat{4}; end |
---|
30 | mdirs = cell(size(names)); |
---|
31 | [mdirs{:}] = deal(''); |
---|
32 | if nargin == 2 & length(mmat) > 3, |
---|
33 | mdirs = mmat{4}; |
---|
34 | end; |
---|
35 | else |
---|
36 | error('[mdot] Invalid argument: mmat.'); |
---|
37 | end |
---|
38 | |
---|
39 | fid = fopen(dotfile,'wt'); |
---|
40 | if fid == -1, error(sprintf('[mdot] Cannot open %s.',dotfile)); end |
---|
41 | |
---|
42 | fprintf(fid,'/* Created by mdot for Matlab */\n'); |
---|
43 | fprintf(fid,'digraph m2html {\n'); |
---|
44 | |
---|
45 | % if 'names' contains '.' then they should be surrounded by '"' |
---|
46 | |
---|
47 | if nargin == 2 |
---|
48 | for i=1:size(hrefs,1) |
---|
49 | n = find(hrefs(i,:) == 1); |
---|
50 | m{i} = n; |
---|
51 | for j=1:length(n) |
---|
52 | fprintf(fid,[' ' names{i} ' -> ' names{n(j)} ';\n']); |
---|
53 | end |
---|
54 | end |
---|
55 | %m = unique([m{:}]); |
---|
56 | fprintf(fid,'\n'); |
---|
57 | for i=1:size(hrefs,1) |
---|
58 | fprintf(fid,[' ' names{i} ' [URL="' ... |
---|
59 | fullurl(mdirs{i},[names{i} options.extension]) '"];\n']); |
---|
60 | end |
---|
61 | else |
---|
62 | i = find(strcmp(f,mfiles)); |
---|
63 | if length(i) ~= 1 |
---|
64 | error(sprintf('[mdot] Cannot find %s.',f)); |
---|
65 | end |
---|
66 | n = find(hrefs(i,:) == 1); |
---|
67 | for j=1:length(n) |
---|
68 | fprintf(fid,[' ' names{i} ' -> ' names{n(j)} ';\n']); |
---|
69 | end |
---|
70 | m = find(hrefs(:,i) == 1); |
---|
71 | for j=1:length(m) |
---|
72 | if n(j) ~= i |
---|
73 | fprintf(fid,[' ' names{m(j)} ' -> ' names{i} ';\n']); |
---|
74 | end |
---|
75 | end |
---|
76 | n = unique([n(:)' m(:)']); |
---|
77 | fprintf(fid,'\n'); |
---|
78 | for i=1:length(n) |
---|
79 | fprintf(fid,[' ' names{n(i)} ' [URL="' fullurl(mdirs{i}, ... |
---|
80 | [names{n(i)} options.extension]) '"];\n']); |
---|
81 | end |
---|
82 | end |
---|
83 | |
---|
84 | fprintf(fid,'}'); |
---|
85 | |
---|
86 | fid = fclose(fid); |
---|
87 | if fid == -1, error(sprintf('[mdot] Cannot close %s.',dotfile)); end |
---|
88 | |
---|
89 | %=========================================================================== |
---|
90 | function f = fullurl(varargin) |
---|
91 | %- Build full url from parts (using '/' and not filesep) |
---|
92 | |
---|
93 | f = strrep(fullfile(varargin{:}),'\','/'); |
---|