Code covered by the BSD License  

Highlights from
Matgraph

from Matgraph by Ed Scheinerman
Toolbox for working with simple, undirected graphs

Description of dot
Home > matgraph > @graph > dot.m

dot

PURPOSE ^

dot(g,filename) --- save graph for use by graphviz.

SYNOPSIS ^

function dot(g,filename)

DESCRIPTION ^

 dot(g,filename) --- save graph for use by graphviz.
 filename is the name of the file to save and should end with ".dot"
 writes the graph to disk in a form that can be read into the graphviz
 tools such as dot, neato, etc. 
 If the graph is labeled, we use the vertex labels instead of the vertex
 numbers. In this case, it is vital that the labels be distinct.

CROSS-REFERENCE INFORMATION ^

This function calls:
  • clear_labels clearl_labels(g) --- delete all labels in g
  • edges edges(g) --- list the edges in g as a 2-column matrix
  • get_label get_label(g) or get_label(g,v) --- get vertex label(s)
  • is_labeled is_labeled(g) --- determine if there are labels on vertices.
  • label Assign labels to vertices of g
  • ne ne(g) --- number of edges in g or ne(g,h) --- check for inequality
  • nv nv(g) --- number of vertices in g
This function is called by:
  • shiftgraph shiftgraph(g,k,t) -- create a shiftgraph g based on t-tuples of k symbols

SOURCE CODE ^

0001 function dot(g,filename)
0002 % dot(g,filename) --- save graph for use by graphviz.
0003 % filename is the name of the file to save and should end with ".dot"
0004 % writes the graph to disk in a form that can be read into the graphviz
0005 % tools such as dot, neato, etc.
0006 % If the graph is labeled, we use the vertex labels instead of the vertex
0007 % numbers. In this case, it is vital that the labels be distinct.
0008 
0009 graph_name = ['Graph_', int2str(g.idx)];
0010 
0011 if nargin==1
0012     filename = [graph_name,'.dot'];
0013 end
0014 
0015 fid = fopen(filename,'w');
0016 if (fid<0)
0017     error(['Cannot open ', filename, ' for writing']);
0018 end
0019 
0020 label_state = is_labeled(g);
0021 if (~label_state)
0022     label(g)
0023 end
0024 
0025 fprintf(fid,['strict graph ', graph_name, '{ \n']);
0026 
0027 n = nv(g);
0028 
0029 for v=1:n
0030     fprintf(fid,'"%s";\n', get_label(g,v));
0031 end
0032 
0033 elist = edges(g);
0034 m = ne(g);
0035 
0036 for k=1:m
0037     a = get_label(g,elist(k,1));
0038     b = get_label(g,elist(k,2));
0039     fprintf(fid, '"%s" -- "%s"; \n', a, b);
0040 end
0041 
0042 fprintf(fid,'}\n');
0043 
0044 
0045 if (~label_state)
0046     clear_labels(g);
0047 end
0048 
0049 disp(['Wrote "', filename,'"']);
0050 fclose(fid);

Generated on Thu 13-Mar-2008 14:23:52 by m2html © 2003

Contact us at files@mathworks.com