mirror of
https://github.com/dkogan/feedgnuplot.git
synced 2025-05-06 06:21:16 +08:00
rehauled drivegnuplot, support all-at-once plotting as a cmdline option
Ignore-this: 77ef24b11e28017f77c9a2015701d73c darcs-hash:20090209111726-0cb85-ac339192253c86d402a4486152ee3f9babcf5bcf.gz
This commit is contained in:
parent
855a0d5583
commit
44c2d22c59
@ -1,10 +1,15 @@
|
|||||||
#!/usr/bin/perl -w
|
#!/usr/bin/perl -w
|
||||||
use strict;
|
use strict;
|
||||||
use Getopt::Long;
|
use Getopt::Long;
|
||||||
|
use Data::Dumper;
|
||||||
|
|
||||||
|
# stream in the data by default
|
||||||
# point plotting by default
|
# point plotting by default
|
||||||
my %options = ( "lines" => 0);
|
my %options = ( "stream" => 1,
|
||||||
|
"lines" => 0);
|
||||||
|
|
||||||
GetOptions(\%options,
|
GetOptions(\%options,
|
||||||
|
"stream!",
|
||||||
"lines!");
|
"lines!");
|
||||||
|
|
||||||
# set up plotting style
|
# set up plotting style
|
||||||
@ -32,14 +37,6 @@ sub Arg {
|
|||||||
$ARGV[int($_[0])];
|
$ARGV[int($_[0])];
|
||||||
}
|
}
|
||||||
|
|
||||||
sub plotHeader
|
|
||||||
{
|
|
||||||
my ($xcounter, $samples, $numberOfStreams, $pipe) = @_;
|
|
||||||
#print "stream $streamIdx: ";
|
|
||||||
print $pipe "set xrange [".($xcounter-$samples).":".($xcounter+1)."]\n";
|
|
||||||
print $pipe 'plot ' . join(', ' , ('"-" notitle') x $numberOfStreams) . "\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
sub main {
|
sub main {
|
||||||
my $argIdx = 0;
|
my $argIdx = 0;
|
||||||
my $numberOfStreams = Arg($argIdx++);
|
my $numberOfStreams = Arg($argIdx++);
|
||||||
@ -69,44 +66,64 @@ sub main {
|
|||||||
print PIPE "set grid\n";
|
print PIPE "set grid\n";
|
||||||
|
|
||||||
for(my $i=0; $i<$numberOfStreams; $i++) {
|
for(my $i=0; $i<$numberOfStreams; $i++) {
|
||||||
my @data = [];
|
push @buffers, [];
|
||||||
push @buffers, @data;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
my $streamIdx = 0;
|
my $streamIdx = 0;
|
||||||
select((select(STDOUT), $| = 1)[0]);
|
select((select(STDOUT), $| = 1)[0]);
|
||||||
my $xcounter = 0;
|
my $xlast = 0;
|
||||||
while(<>) {
|
while(<>)
|
||||||
|
{
|
||||||
chomp;
|
chomp;
|
||||||
my $line = $_;
|
my $line = $_;
|
||||||
plotHeader($xcounter, $samples, $numberOfStreams, *PIPE) if($streamIdx == 0);
|
foreach my $point ($line =~ /([-]?[0-9\.]+)/g) {
|
||||||
foreach my $point ($line =~ /([-]?[0-9\.]+)/g)
|
|
||||||
{
|
|
||||||
my $buf = $buffers[$streamIdx];
|
my $buf = $buffers[$streamIdx];
|
||||||
|
|
||||||
# data buffering (up to stream sample size)
|
# data buffering (up to stream sample size)
|
||||||
push @{$buf}, $point;
|
push @{$buf}, $point;
|
||||||
|
shift @{$buf} if(@{$buf} > $samples && $options{"stream"});
|
||||||
|
|
||||||
my $cnt = 0;
|
|
||||||
for my $elem (reverse @{$buf}) {
|
|
||||||
#print " ".$elem;
|
|
||||||
print PIPE ($xcounter-$cnt)." ".$elem."\n";
|
|
||||||
$cnt++;
|
|
||||||
}
|
|
||||||
#print "\n";
|
|
||||||
print PIPE "e\n";
|
|
||||||
if ($cnt>=$samples) {
|
|
||||||
shift @{$buf};
|
|
||||||
}
|
|
||||||
$streamIdx++;
|
$streamIdx++;
|
||||||
if ($streamIdx == $numberOfStreams) {
|
if ($streamIdx == $numberOfStreams) {
|
||||||
$streamIdx = 0;
|
$streamIdx = 0;
|
||||||
$xcounter++;
|
plotStoredData($xlast, $samples, $numberOfStreams, *PIPE, \@buffers) if($options{"stream"});
|
||||||
|
$xlast++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if($options{"stream"})
|
||||||
|
{
|
||||||
print PIPE "exit;\n";
|
print PIPE "exit;\n";
|
||||||
close PIPE;
|
close PIPE;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$samples = @{$buffers[0]};
|
||||||
|
plotStoredData($xlast, $samples, $numberOfStreams, *PIPE, \@buffers);
|
||||||
|
}
|
||||||
|
sleep 100000;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
main;
|
main;
|
||||||
|
Loading…
Reference in New Issue
Block a user