#! /bin/sh # nodegraph -gif # ToDo: # - Color parent link red in std graph # - Keep non parent links in root graph, invisible. This # lets both styles overlay each other for comparison fontname="fontname=helvetica" output=png format=nodes label=true epsilon=0.5 start="" edgecolor=blue awk=nawk [ -f /usr/bin/$awk ] || awk=awk while [ $# -gt 0 ]; do case $1 in -gif) shift; output=gif ;; # output a gif file -ps) shift; output=ps ;; # output a postscript file -png) shift; output=png ;; # output a png file -dot) shift; output=dot ;; # output a dot file -cat) shift; output=cat ;; # output the dot input txt file -graph*)shift; format=graph ;; # output std graph -root*) shift; format=root; ;; # show just parent links -rand) shift; start="start=rand;" ;;# try a different rand seed -hard) shift; epsilon=1.0 ;; # make calcs easier -label) shift; label=true ;; # insert a title -nolabel) shift; label=false ;; # dont insert a title -thumb) shift; output=thumb; label=false ;; # make small "thumbnail" *) echo "Bad arg: $1."; exit ;; esac done sed -n ' 1s/^/aa /p /^Level.*:/s/^/ab /p /^Average.*:/s/^/ac /p /^Small.*:/s/^/ad /p /}\[/ { s/^/ba !/p s/^..../bc =/p } 1s/.*/bb-SEPARATOR/p ' | sort > /tmp/ng1.$$ sed ' s/^...// /!/,/SEP/ { s/: /:/;s/ .*//; s/:/: / s/!// } /SEP/,$ { s/{.*: [0-9][0-9]*// /^=[0-9]*$/d } ' < /tmp/ng1.$$ | \ $awk -v start="$start" -v edgecolor=$edgecolor -v epsilon=$epsilon \ -v label=$label -v format=$format \ ' BEGIN { OFS = "" print "graph test123 {" print "size=\"6,6\";" print "margin=.5;" print "pcenter=true;" print "epsilon=", epsilon print start print "node [height=.3];" print "node [width=.3];" print "node [color=blue];" print "node [fontsize=12];" print "node [nodesep=20];" # print "edge [color=red];" print "edge [color=", (format=="root")?"red":"blue", "];" } /^[A-Z].*[0-9]:/ { name=$0; sub(":.*","", name); bigname=$0; sub("^.*: ","", bigname); print "//name=", name } /^Level/ { edges=$0; sub("^.*Edges.*= *","", edges); nodes=$0; sub(",.*","", nodes); sub("^.*=","", nodes); mxavmd=$0; sub(";.*","", mxavmd); sub("^.*=","", mxavmd); maxlevel=mxavmd; sub("/.*","", maxlevel); edgelimit=nodes * 4 if ( edges >= edgelimit ) edgelen = (maxlevel <= 6)?2.0:1.0; else edgelen = (maxlevel <= 3)?1.7:(maxlevel <=6)?1.0:(maxlevel <=10)?0.75:0.5; print "edge [len=", edgelen, "];" } /^Average/ { search=$0; sub(";.*","", search); sub("^.*=","", search); pathmxavmd=$0; sub("^.*=","", pathmxavmd); } /^Small/ { clust=$0; sub("^.*=","", clust); print "label=\"", name, " E=", edges, " C/L/D=", clust, " Mx/Av/Md=", mxavmd, "\"" } # /^[0-9]/{ # if ( format == "root" ) { # sub(": ",":"); sub(" .*",""); sub(":",": "); # } # } /{0}/{ node=$0; sub("[^0-9].*","", node); print node, " [style=filled, color=red];" } /{1}/{ node=$0; sub("[^0-9].*","", node); print node, " [style=filled, color=green];" } /{2}/{ node=$0; sub("[^0-9].*","", node); print node, " [style=filled, color=yellow];" } /{3}/{ node=$0; sub("[^0-9].*","", node); print node, " [color=red];" } /{.*}/{ sub("{.*:",""); sub(" *"," -- {"); sub("$","};"); } /^=[0-9]/{ sub("^=",""); sub(" *"," -- {"); sub("$","};"); } /^SEP/{ if ( format == "root" ) print "edge [style=invis];" else print "edge [color=blue];" } /^[0-9]/{ print; } END { print "}"; } ' > /tmp/ng2.$$ case $output in thumb) neato -Tgif < /tmp/ng2.$$ > /tmp/big$$.gif; convert -geometry 128x128 -sharpen 90 \ /tmp/ng.big$$.gif /tmp/ng.sm$$.gif; cat /tmp/ng.sm$$.gif ;; gif) neato -Tgif < /tmp/ng2.$$;; png) neato -Tgif < /tmp/ng2.$$ | gif2png -O -b ffffff -f ;; ps) neato -Tps < /tmp/ng2.$$;; dot) neato < /tmp/ng2.$$ ;; cat) cat /tmp/ng2.$$ ;; esac rm /tmp/ng*$$* exit if ( format == "root" ) print "edge [color=red];" else print "edge [color=blue];" if ( format == "root" ) edgelen=1.0; else if ( edges >= edgelimit ) edgelen = (maxlevel <= 6)?2.0:1.0; else