mirror of
https://github.com/dkogan/feedgnuplot.git
synced 2025-05-06 06:21:16 +08:00
gnuplot driver limited to replotting at 1fps
Ignore-this: 2ce7b4bcffd97e593b34693ddab54147 darcs-hash:20090824213142-0cb85-3301d931b63db020724e83e3bd14b3b58d99a712.gz
This commit is contained in:
parent
13d6528473
commit
07a13f7977
122
driveGnuPlots.pl
122
driveGnuPlots.pl
@ -1,10 +1,12 @@
|
|||||||
#!/usr/bin/perl -w
|
#!/usr/bin/perl -w
|
||||||
use strict;
|
use strict;
|
||||||
use Getopt::Long;
|
use Getopt::Long;
|
||||||
use Time::HiRes qw( usleep );
|
use Time::HiRes qw( usleep gettimeofday tv_interval);
|
||||||
use IO::Handle;
|
use IO::Handle;
|
||||||
use List::MoreUtils qw( first_index );
|
use List::MoreUtils qw( first_index );
|
||||||
use Data::Dumper;
|
use Data::Dumper;
|
||||||
|
use threads;
|
||||||
|
use Thread::Queue;
|
||||||
|
|
||||||
autoflush STDOUT 1;
|
autoflush STDOUT 1;
|
||||||
|
|
||||||
@ -48,44 +50,55 @@ if($options{"points"}) { $style .= "points";}
|
|||||||
|
|
||||||
if(!$style) { $style = "points"; }
|
if(!$style) { $style = "points"; }
|
||||||
|
|
||||||
sub usage {
|
if( defined $options{"help"} )
|
||||||
print "Usage: $0 <options>\n";
|
{
|
||||||
print <<OEF;
|
usage();
|
||||||
--[no]stream Do [not] display the data a point at a time, as it comes in
|
return;
|
||||||
--[no]lines Do [not] draw lines to connect consecutive points
|
}
|
||||||
--xlabel xxx Set x-axis label
|
if( defined $options{"hardcopy"} && $options{"stream"} )
|
||||||
--ylabel xxx Set y-axis label
|
{
|
||||||
--y2label xxx Set y2-axis label
|
usage();
|
||||||
--title xxx Set the title of the plot
|
die("If making a hardcopy, we shouldn't be streaming. Doing nothing\n");
|
||||||
--legend xxx Set the label for a curve plot. Give this option multiple times for multiple curves
|
}
|
||||||
--xlen xxx Set the size of the x-window to plot
|
if( !defined $options{"xlen"} )
|
||||||
--ymin xxx Set the range for the y axis. Both or neither of these have to be specified
|
{
|
||||||
--ymax xxx Set the range for the y axis. Both or neither of these have to be specified
|
usage();
|
||||||
--y2min xxx Set the range for the y2 axis. Both or neither of these have to be specified
|
die("Must specify the size of the moving x-window. Doing nothing\n");
|
||||||
--y2max xxx Set the range for the y2 axis. Both or neither of these have to be specified
|
}
|
||||||
--y2 xxx Plot the data with this index on the y2 axis. These are 0-indexed
|
my $xwindow = $options{"xlen"};
|
||||||
--hardcopy xxx If not streaming, output to a file specified here. Format inferred from filename
|
|
||||||
OEF
|
|
||||||
|
|
||||||
|
|
||||||
|
# now start the data acquisition and plotting threads
|
||||||
|
my $dataQueue = Thread::Queue->new();
|
||||||
|
my $addThr = threads->create(\&mainThread);
|
||||||
|
my $plotThr = threads->create(\&plotThread);
|
||||||
|
|
||||||
|
while(<>)
|
||||||
|
{
|
||||||
|
$dataQueue->enqueue($_);
|
||||||
}
|
}
|
||||||
|
|
||||||
sub main {
|
$dataQueue->enqueue("Plot now");
|
||||||
if( defined $options{"help"} )
|
$dataQueue->enqueue(undef);
|
||||||
{
|
|
||||||
usage;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if( defined $options{"hardcopy"} && $options{"stream"} )
|
|
||||||
{
|
|
||||||
usage;
|
|
||||||
die("If making a hardcopy, we shouldn't be streaming. Doing nothing\n");
|
|
||||||
}
|
|
||||||
if( !defined $options{"xlen"} )
|
|
||||||
{
|
|
||||||
usage;
|
|
||||||
die("Must specify the size of the moving x-window. Doing nothing\n");
|
|
||||||
}
|
|
||||||
my $xwindow = $options{"xlen"};
|
|
||||||
|
|
||||||
|
$addThr->join();
|
||||||
|
$plotThr->join();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
sub plotThread
|
||||||
|
{
|
||||||
|
while(1)
|
||||||
|
{
|
||||||
|
sleep(1);
|
||||||
|
$dataQueue->enqueue("Plot now");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sub mainThread {
|
||||||
local *PIPE;
|
local *PIPE;
|
||||||
open PIPE, "|gnuplot" || die "Can't initialize gnuplot\n";
|
open PIPE, "|gnuplot" || die "Can't initialize gnuplot\n";
|
||||||
autoflush PIPE 1;
|
autoflush PIPE 1;
|
||||||
@ -149,13 +162,16 @@ sub main {
|
|||||||
|
|
||||||
# regexp for a possibly floating point, possibly scientific notation number
|
# regexp for a possibly floating point, possibly scientific notation number
|
||||||
my $numRE = qr/([-]?[0-9\.]+(?:e[-]?[0-9]+)?)/;
|
my $numRE = qr/([-]?[0-9\.]+(?:e[-]?[0-9]+)?)/;
|
||||||
while(<>)
|
my $xlast;
|
||||||
|
while( $_ = $dataQueue->dequeue() )
|
||||||
|
{
|
||||||
|
if(!/Plot now/)
|
||||||
{
|
{
|
||||||
# parse the incoming data lines. The format is
|
# parse the incoming data lines. The format is
|
||||||
# x idx0 dat0 idx1 dat1 ....
|
# x idx0 dat0 idx1 dat1 ....
|
||||||
# where idxX is the index of the curve that datX corresponds to
|
# where idxX is the index of the curve that datX corresponds to
|
||||||
/($numRE)/gc or next;
|
/($numRE)/gc or next;
|
||||||
my $x = $1;
|
$xlast = $1;
|
||||||
|
|
||||||
while(/([0-9]+) ($numRE)/gc)
|
while(/([0-9]+) ($numRE)/gc)
|
||||||
{
|
{
|
||||||
@ -168,13 +184,14 @@ sub main {
|
|||||||
newCurve("", "");
|
newCurve("", "");
|
||||||
}
|
}
|
||||||
|
|
||||||
push @{$curves[$idx]->{"data"}}, [$x, $point];
|
push @{$curves[$idx]->{"data"}}, [$xlast, $point];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if($options{"stream"})
|
elsif($options{"stream"})
|
||||||
{
|
{
|
||||||
cutOld($x - $xwindow);
|
cutOld($xlast - $xwindow);
|
||||||
plotStoredData($x - $xwindow, $x);
|
plotStoredData($xlast - $xwindow, $xlast);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -257,4 +274,23 @@ sub newCurve()
|
|||||||
"data" => $newpoint} );
|
"data" => $newpoint} );
|
||||||
}
|
}
|
||||||
|
|
||||||
main;
|
sub usage {
|
||||||
|
print "Usage: $0 <options>\n";
|
||||||
|
print <<OEF;
|
||||||
|
--[no]stream Do [not] display the data a point at a time, as it comes in
|
||||||
|
--[no]lines Do [not] draw lines to connect consecutive points
|
||||||
|
--xlabel xxx Set x-axis label
|
||||||
|
--ylabel xxx Set y-axis label
|
||||||
|
--y2label xxx Set y2-axis label
|
||||||
|
--title xxx Set the title of the plot
|
||||||
|
--legend xxx Set the label for a curve plot. Give this option multiple times for multiple curves
|
||||||
|
--xlen xxx Set the size of the x-window to plot
|
||||||
|
--ymin xxx Set the range for the y axis. Both or neither of these have to be specified
|
||||||
|
--ymax xxx Set the range for the y axis. Both or neither of these have to be specified
|
||||||
|
--y2min xxx Set the range for the y2 axis. Both or neither of these have to be specified
|
||||||
|
--y2max xxx Set the range for the y2 axis. Both or neither of these have to be specified
|
||||||
|
--y2 xxx Plot the data with this index on the y2 axis. These are 0-indexed
|
||||||
|
--hardcopy xxx If not streaming, output to a file specified here. Format inferred from filename
|
||||||
|
OEF
|
||||||
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user