Index: mttroot/mtt/bin/trans/struc2gnuplot_txt2wish ================================================================== --- mttroot/mtt/bin/trans/struc2gnuplot_txt2wish +++ mttroot/mtt/bin/trans/struc2gnuplot_txt2wish @@ -26,17 +26,17 @@ ## states canvas canvas .cx listbox .cx.l scrollbar .cx.sy -orient v -label .cx.t -text "States" +checkbutton .cx.t -text "States" ## outputs canvas canvas .cy listbox .cy.l scrollbar .cy.sy -orient v -label .cy.t -text "Outputs" +checkbutton .cy.t -text "Outputs" ## configure scrollbars .cx.sy configure -command ".cx.l yview" .cy.sy configure -command ".cy.l yview" .cx.l configure -yscrollcommand ".cx.sy set" @@ -43,23 +43,62 @@ .cy.l configure -yscrollcommand ".cy.sy set" ## bind lists bind .cx.l <> { plot [ .cx.l get anchor ] } bind .cy.l <> { plot [ .cy.l get anchor ] } + +proc "reverse_name" "name" { + set delim "_" + set split_name [split \$name \$delim] + set reversed_name [lindex \$split_name 0] + for {set i 1} {\$i<[llength \$split_name]} {incr i} { + set reversed_name [lindex \$split_name \$i]\$delim\$reversed_name + } + return \$reversed_name +} + +proc "reverse_sort" "list" { + set temp_list {} + set delim " " + foreach name [split \$list \$delim] { + set temp_list \$temp_list\$delim[reverse_name \$name] + } + set temp_list [lsort -ascii \$temp_list] + set list {} + foreach name [split \$temp_list \$delim] { + set list \$list\$delim[reverse_name \$name] + } + return \$list +} + +proc "sort_list" "list sortorder" { + puts "sortorder: \$sortorder" + if ("\$sortorder"=="normal") { + return [lsort -ascii \$list] + } + if ("\$sortorder"=="reverse") { + return [reverse_sort \$list] + } +} EOF ## create states and outputs lists awk ' ($1 == "state") { - printf ".cx.l insert end state:%s\n", $4 + printf "lappend xl state:%s\n", $4 } ($1 == "output") { - printf ".cy.l insert end output:%s\n", $4 + printf "lappend yl output:%s\n", $4 }' ${struc} >> ${out} cat <> ${out} +.cx.l configure -listvar xl +.cy.l configure -listvar yl + +.cx.t configure -command { set xl [sort_list \$xl \$xsortorder] } -indicatoron false -onvalue "reverse" -offvalue "normal" -variable xsortorder +.cy.t configure -command { set yl [sort_list \$yl \$ysortorder] } -indicatoron false -onvalue "reverse" -offvalue "normal" -variable ysortorder pack .cx.t -expand false -fill x -side top pack .cy.t -expand false -fill x -side top pack .cx.sy -expand false -fill y -side right @@ -74,12 +113,12 @@ radiobutton .states -text "States" -value states -variable view -command { raise .cx } -relief solid radiobutton .outputs -text "Outputs" -value outputs -variable view -command { raise .cy } -relief solid pack .states .outputs -side left -pack .quit -expand false -fill x -side right -pack .print -expand false -fill x -side right +pack .quit -expand false -fill x -side right +pack .print -expand false -fill x -side right ## map names to column numbers EOF @@ -101,21 +140,21 @@ cat <> ${out} ## call gnuplot proc "plot_var" "title column" { - exec echo plot \\\"${dat2}\\\" using 1:\$column title \\\"\$title\\\" with lines > ${tmp} + exec echo plot \"${dat2}\" using 1:\$column title \"\$title\" with lines > ${tmp} exec echo pause -1 >> ${tmp} exec gnuplot -title "\$title" ${tmp} & } ## print output proc "print" "" { exec echo set term postscript > ${tmp}.print - exec echo set output \\\"../${sys}_gnuplot.ps\\\" >> ${tmp}.print + exec echo set output \"../${sys}_gnuplot.ps\" >> ${tmp}.print exec grep -v pause ${tmp} >> ${tmp}.print exec gnuplot ${tmp}.print puts "Graph printed to ${sys}_gnuplot.ps" } EOF chmod +x ${out}