| 1 |
/* Convert a rooted tree to a hierarchy of clusters for patchwork. |
| 2 |
* ARGV[0] is desired root |
| 3 |
*/ |
| 4 |
BEG_G { |
| 5 |
node_t rt; |
| 6 |
node_t n; |
| 7 |
graph_t cg; |
| 8 |
graph_t sg; |
| 9 |
int depth; |
| 10 |
int mark[node_t]; |
| 11 |
graph_t stk[int]; |
| 12 |
|
| 13 |
if (! $.directed) { |
| 14 |
printf(2,"Input graph is not directed\n"); |
| 15 |
exit (1); |
| 16 |
} |
| 17 |
rt = isNode($,ARGV[0]); |
| 18 |
if (rt == NULL) { |
| 19 |
printf(2,"Root node \"%s\" not found\n", ARGV[0]); |
| 20 |
exit (1); |
| 21 |
} |
| 22 |
$tvroot = rt; |
| 23 |
$tvtype = TV_prepostfwd; |
| 24 |
cg = graph(rt.name,"U"); |
| 25 |
} |
| 26 |
|
| 27 |
N { |
| 28 |
if (mark[$]) { |
| 29 |
depth--; |
| 30 |
} |
| 31 |
else { |
| 32 |
mark[$] = 1; |
| 33 |
if (depth > 0) { |
| 34 |
if (fstout($)) { |
| 35 |
sg = subg(stk[depth-1], "cluster_" + $.name); |
| 36 |
if (($.style == "filled") && ($.fillcolor != "")) |
| 37 |
sg.bgcolor = $.fillcolor; |
| 38 |
} |
| 39 |
else { |
| 40 |
sg = NULL; |
| 41 |
n = node(stk[depth-1], $.name); |
| 42 |
n.style = "filled"; |
| 43 |
n.fillcolor = $.fillcolor; |
| 44 |
} |
| 45 |
} |
| 46 |
else sg = cg; |
| 47 |
stk[depth] = sg; |
| 48 |
depth++; |
| 49 |
} |
| 50 |
} |
| 51 |
END_G { |
| 52 |
write(cg); |
| 53 |
} |
| 54 |
|