00001 00002
00003 00004 00005 00006
00007 namespace eval jmath {
00008
00009 proc plot {data format {title "plot"}} {
00010 00011 00012 00013 00014
00015 00016 set nRows [$data size1]
00017 set nCols [$data size2]
00018 set dataFileName "${title}.dat.tmp"
00019 set dataFile [open $dataFileName "w"]
00020 puts $dataFile "\# $dataFileName - temporary file can safely be deleted"
00021
00022 for {set i 0} {$i < $nRows} {incr i} {
00023 for {set j 0} {$j < $nCols} {incr j} {
00024 puts -nonewline $dataFile "[$data get $i $j] "
00025 }
00026 puts $dataFile " "
00027 }
00028 close $dataFile
00029
00030
00031 set gp [open "|gnuplot" w]
00032 puts $gp "set term x11 persist"
00033 puts $gp "set title '$title'"
00034 puts -nonewline $gp "plot "
00035 puts $gp "\"$dataFileName\" $format"
00036 close $gp
00037 }00038
00039 proc displayMat {mat maxValue} {
00040 set nRows [$mat size1]
00041 set nCols [$mat size2]
00042 set display [open "|display -resize 400x400+256 -" w]
00043 puts $display "P3"
00044 puts $display "$nCols $nRows"
00045 puts $display "255"
00046 for {set i 0} {$i < $nRows} {incr i} {
00047 for {set j 0} {$j < $nCols} {incr j} {
00048 puts -nonewline $display "[_displayMatPixelColor [$mat get $j $i] $maxValue] "
00049 }
00050 puts -nonewline $display "\n"
00051 }
00052 close $display
00053 }00054
00055 proc _displayMatPixelColor {value maxValue} {
00056 set c [expr "round(255 - 255*abs($value)/$maxValue)"]
00057 if "$value>=0" {
00058 return "$c $c 255"
00059 } else {
00060 return "255 $c $c"
00061 }
00062 }00063
00064 }00065
00066 package provide jmath 0.1