2009-12-20 12:46:06 +08:00
|
|
|
#!/usr/bin/perl -w
|
|
|
|
use strict;
|
2009-02-09 17:35:19 +08:00
|
|
|
use Getopt::Long;
|
2009-02-09 19:17:26 +08:00
|
|
|
use Data::Dumper;
|
2009-02-09 17:35:19 +08:00
|
|
|
|
2009-02-09 19:17:26 +08:00
|
|
|
# stream in the data by default
|
2009-02-09 17:35:19 +08:00
|
|
|
# point plotting by default
|
2009-02-09 19:17:26 +08:00
|
|
|
my %options = ( "stream" => 1,
|
|
|
|
"lines" => 0);
|
|
|
|
|
2009-02-09 17:35:19 +08:00
|
|
|
GetOptions(\%options,
|
2009-02-09 19:17:26 +08:00
|
|
|
"stream!",
|
2009-02-09 17:35:19 +08:00
|
|
|
"lines!");
|
|
|
|
|
|
|
|
# set up plotting style
|
|
|
|
my $style = "points";
|
|
|
|
$style = "linespoints" if($options{"lines"});
|
2009-12-20 12:46:06 +08:00
|
|
|
|
|
|
|
sub usage {
|
|
|
|
print "Usage: $0 <options>\n";
|
|
|
|
print <<OEF;
|
|
|
|
where mandatory options are (in order):
|
|
|
|
|
2009-01-24 08:56:57 +08:00
|
|
|
NumberOfStreams How many streams to plot
|
|
|
|
Stream_WindowSampleSize this many samples
|
|
|
|
Stream_YRangeMin Stream_YRangeMax Min and Max y values
|
2009-12-20 12:46:06 +08:00
|
|
|
|
|
|
|
OEF
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
sub Arg {
|
|
|
|
if ($#ARGV < $_[0]) {
|
2009-02-05 05:22:03 +08:00
|
|
|
print "Expected parameter missing...\n\n";
|
|
|
|
usage;
|
2009-12-20 12:46:06 +08:00
|
|
|
}
|
|
|
|
$ARGV[int($_[0])];
|
|
|
|
}
|
|
|
|
|
|
|
|
sub main {
|
|
|
|
my $argIdx = 0;
|
|
|
|
my $numberOfStreams = Arg($argIdx++);
|
2009-01-24 08:56:57 +08:00
|
|
|
print "Will display $numberOfStreams Streams...\n";
|
|
|
|
|
|
|
|
my $samples = Arg($argIdx++);
|
|
|
|
print "Will use a window of $samples samples\n";
|
|
|
|
|
|
|
|
my $miny = Arg($argIdx++);
|
|
|
|
my $maxy = Arg($argIdx++);
|
|
|
|
print "Will use a range of [$miny, $maxy]\n";
|
|
|
|
|
2009-12-20 12:46:06 +08:00
|
|
|
my @buffers;
|
|
|
|
shift @ARGV; # number of streams
|
2009-01-24 08:56:57 +08:00
|
|
|
shift @ARGV; # sample size
|
|
|
|
shift @ARGV; # miny
|
|
|
|
shift @ARGV; # maxy
|
|
|
|
local *PIPE;
|
|
|
|
|
|
|
|
open PIPE, "|gnuplot" || die "Can't initialize gnuplot\n";
|
|
|
|
|
|
|
|
select((select(PIPE), $| = 1)[0]);
|
|
|
|
print PIPE "set xtics\n";
|
|
|
|
print PIPE "set ytics\n";
|
|
|
|
print PIPE "set yrange [". $miny . ":" . $maxy ."]\n";
|
2009-02-09 17:35:19 +08:00
|
|
|
print PIPE "set style data $style\n";
|
2009-01-24 08:56:57 +08:00
|
|
|
print PIPE "set grid\n";
|
|
|
|
|
2009-12-20 12:46:06 +08:00
|
|
|
for(my $i=0; $i<$numberOfStreams; $i++) {
|
2009-02-09 19:17:26 +08:00
|
|
|
push @buffers, [];
|
2009-12-20 12:46:06 +08:00
|
|
|
}
|
2009-01-24 08:56:57 +08:00
|
|
|
|
2009-12-20 12:46:06 +08:00
|
|
|
my $streamIdx = 0;
|
|
|
|
select((select(STDOUT), $| = 1)[0]);
|
2009-02-09 19:17:26 +08:00
|
|
|
my $xlast = 0;
|
|
|
|
while(<>)
|
|
|
|
{
|
|
|
|
chomp;
|
|
|
|
my $line = $_;
|
|
|
|
foreach my $point ($line =~ /([-]?[0-9\.]+)/g) {
|
|
|
|
my $buf = $buffers[$streamIdx];
|
|
|
|
|
|
|
|
# data buffering (up to stream sample size)
|
|
|
|
push @{$buf}, $point;
|
|
|
|
shift @{$buf} if(@{$buf} > $samples && $options{"stream"});
|
|
|
|
|
|
|
|
$streamIdx++;
|
|
|
|
if ($streamIdx == $numberOfStreams) {
|
|
|
|
$streamIdx = 0;
|
|
|
|
plotStoredData($xlast, $samples, $numberOfStreams, *PIPE, \@buffers) if($options{"stream"});
|
|
|
|
$xlast++;
|
2009-01-24 08:56:57 +08:00
|
|
|
}
|
2009-02-09 19:17:26 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if($options{"stream"})
|
|
|
|
{
|
|
|
|
print PIPE "exit;\n";
|
|
|
|
close PIPE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$samples = @{$buffers[0]};
|
|
|
|
plotStoredData($xlast, $samples, $numberOfStreams, *PIPE, \@buffers);
|
2009-12-20 12:46:06 +08:00
|
|
|
}
|
2009-02-09 19:17:26 +08:00
|
|
|
sleep 100000;
|
2009-12-20 12:46:06 +08:00
|
|
|
}
|
|
|
|
|
2009-02-09 19:17:26 +08:00
|
|
|
sub plotStoredData
|
|
|
|
{
|
|
|
|
my ($xlast, $samples, $numberOfStreams, $pipe, $buffers) = @_;
|
|
|
|
|
|
|
|
my $x0 = $xlast - $samples + 1;
|
|
|
|
print $pipe "set xrange [$x0:$xlast]\n";
|
|
|
|
print $pipe 'plot ' . join(', ' , ('"-" notitle') x $numberOfStreams) . "\n";
|
|
|
|
|
|
|
|
foreach my $buf (@{$buffers})
|
|
|
|
{
|
|
|
|
# if the buffer isn't yet complete, skip the appropriate number of points
|
|
|
|
my $x = $x0 + $samples - @{$buf};
|
|
|
|
for my $elem (@{$buf}) {
|
|
|
|
print $pipe "$x $elem\n";
|
|
|
|
$x++;
|
|
|
|
}
|
|
|
|
print PIPE "e\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-20 12:46:06 +08:00
|
|
|
main;
|