commit 704c3f16074ce74add9e0c8681ccac9eb3b27f16 Author: Dima Kogan Date: Sat Dec 19 20:46:06 2009 -0800 added realtime gnuplot script from http://users.softlab.ece.ntua.gr/~ttsiod/gnuplotStreaming.html diff --git a/driveGnuPlots.pl b/driveGnuPlots.pl new file mode 100755 index 0000000..82ed79f --- /dev/null +++ b/driveGnuPlots.pl @@ -0,0 +1,104 @@ +#!/usr/bin/perl -w +use strict; + +sub usage { + print "Usage: $0 \n"; + print < ...per stream2... +... + ...per streamN... + Stream1_YRangeMin Stream1_YRangeMax Min and Max values for stream 1 + Min and Max values for stream 2 +... + Min and Max values for stream N + +OEF + exit(1); +} + +sub Arg { + if ($#ARGV < $_[0]) { + print "Expected parameter missing...\n\n"; + usage; + } + $ARGV[int($_[0])]; +} + +sub main { + my $argIdx = 0; + my $numberOfStreams = Arg($argIdx++); + print "Will display $numberOfStreams Streams (in $numberOfStreams windows)...\n"; + my @sampleSizes; + for(my $i=0; $i<$numberOfStreams; $i++) { + my $samples = Arg($argIdx++); + push @sampleSizes, $samples; + print "Stream ".($i+1)." will use a window of $samples samples\n"; + } + my @ranges; + for(my $i=0; $i<$numberOfStreams; $i++) { + my $miny = Arg($argIdx++); + my $maxy = Arg($argIdx++); + push @ranges, [ $miny, $maxy ]; + print "Stream ".($i+1)." will use a range of [$miny, $maxy]\n"; + } + my @gnuplots; + my @buffers; + shift @ARGV; # number of streams + for(my $i=0; $i<$numberOfStreams; $i++) { + shift @ARGV; # sample size + shift @ARGV; # miny + shift @ARGV; # maxy + local *PIPE; + open PIPE, "|gnuplot" || die "Can't initialize gnuplot number ".($i+1)."\n"; + select((select(PIPE), $| = 1)[0]); + push @gnuplots, *PIPE; + print PIPE "set xtics\n"; + print PIPE "set ytics\n"; + print PIPE "set yrange [".($ranges[$i]->[0]).":".($ranges[$i]->[1])."]\n"; + print PIPE "set style data linespoints\n"; + print PIPE "set grid\n"; + my @data = []; + push @buffers, @data; + } + my $streamIdx = 0; + select((select(STDOUT), $| = 1)[0]); + my $xcounter = 0; + while(<>) { + chomp; + my $buf = $buffers[$streamIdx]; + my $pip = $gnuplots[$streamIdx]; + + # data buffering (up to stream sample size) + push @{$buf}, $_; + #print "stream $streamIdx: "; + print $pip "set xrange [".($xcounter-$sampleSizes[$streamIdx]).":".($xcounter+1)."]\n"; + print $pip "plot \"-\" notitle\n"; + my $cnt = 0; + for my $elem (reverse @{$buf}) { + #print " ".$elem; + print $pip ($xcounter-$cnt)." ".$elem."\n"; + $cnt += 1; + } + #print "\n"; + print $pip "e\n"; + if ($cnt>=$sampleSizes[$streamIdx]) { + shift @{$buf}; + } + $streamIdx++; + if ($streamIdx == $numberOfStreams) { + $streamIdx = 0; + $xcounter++; + } + } + for(my $i=0; $i<$numberOfStreams; $i++) { + my $pip = $gnuplots[$i]; + print $pip "exit;\n"; + close $pip; + } +} + +main;