Jafar
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
plot.tcl
00001 # $Id$ #
00002 
00003 #
00004 #/** Provides front-end to gnuplot to plot data in matrix. (limited to one plot !?) \file plot.tcl  \ingroup jmath */
00005 #
00006 
00007 namespace eval jmath {
00008 
00009     proc plot {data format {title "plot"}} {
00010         # call gnuplot to plot data with format
00011         # data is saved in a temporary file before plotting
00012         # format should not refer to any data file, example:
00013         # "using 1:2 with lines, '' using 1:3 with lines"
00014 
00015         # save data in temporary file
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
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on Wed Oct 15 2014 00:37:24 for Jafar by doxygen 1.7.6.1
LAAS-CNRS