# tab2ps.tcl - nimmt eine ASCII- # Erzeugt aus Tabelle (Name Wert) als Eingabe # eine Balkengraphik und speichert diese als Postscript # Aufruf: bltwish -f tab2ps.tcl "Titel" "X-Titel" "Y-Titel" # Benötigt Tcl 7.3, Tk 3.6, Blt 1.7 set xdata "" set ydata "" set graph ".g" set wname "." option add *Blt_barchart.title "" option add *Blt_barchart.Font *Helvetica-Bold-R*18* option add *Blt_barchart.xFont *Helvetica-Medium-R*12* option add *Blt_barchart.yFont *Helvetica-Medium-R*12* option add *Blt_barchart.legendFont *Helvetica-Bold-R*12* option add *Blt_barchart.elemBackground red option add *Blt_barchart.background white option add *Blt_barchart.foreground black option add *Blt_barchart.elemRelief raised option add *Blt_barchart.relief sunken option add *Blt_barchart.width 400 option add *Blt_barchart.height 400 set fname [lindex $argv 0] set f [open $fname r] set count 0 while {[eof $f] == 0} { gets $f line if {[llength $line] > 0} { lappend xdata [lindex $line 0] lappend ydata [lindex $line 1] incr count } } close $f set names $xdata proc FormatLabel { wname w value } { global names return [lindex $names [expr round($value)-1]] } blt_barchart $graph -plotbackground lightgray $graph xaxis configure -rotate 90 -command "FormatLabel $wname" $graph xaxis configure -title [lindex $argv 2] $graph yaxis configure -title [lindex $argv 3] $graph legend configure -mapped false $graph configure -title [lindex $argv 1] for {set i 1} {$i <= $count} {incr i} { set elem [lindex $names [expr $i-1] ] if {[lsearch -exact [$graph element names] $elem ] == -1} { $graph element create $elem \ -xdata $i \ -ydata [lindex $ydata [expr $i-1]] \ -fg red \ -bg gray50 \ -relief raised \ -bd 1 } else { puts stderr "Element \"$elem\" already exists!" } } pack $graph -expand yes -fill both $graph postscript "$fname.ps" exit