mirror of
https://github.com/dkogan/feedgnuplot.git
synced 2025-05-06 06:21:16 +08:00
driveGnuPlots.pl speedups. Removed the threadqueue in !streaming, rearranged data
Ignore-this: 66c1ef6d9b45a1bd3db49c3696a2b309 darcs-hash:20090910221151-0cb85-becf9bad1e4c07e1c60c8b8c7517d36986076d0f.gz
This commit is contained in:
parent
278f0d8fd5
commit
5bf3b09d0c
@ -10,10 +10,9 @@ use Thread::Queue;
|
|||||||
|
|
||||||
autoflush STDOUT 1;
|
autoflush STDOUT 1;
|
||||||
|
|
||||||
# list containing the plot data. Each element is a hash describing the extra
|
# list containing the plot data. Each element is a reference to a list,
|
||||||
# plotting options for each curve we're plotting, and the actual data to
|
# representing the data for one curve. The first "point" is a string of plot
|
||||||
# plot for each curve. The length of this list grows as the data comes
|
# options
|
||||||
# in
|
|
||||||
my @curves = ();
|
my @curves = ();
|
||||||
|
|
||||||
# stream in the data by default
|
# stream in the data by default
|
||||||
@ -57,7 +56,7 @@ if( defined $options{"help"} )
|
|||||||
}
|
}
|
||||||
|
|
||||||
# now start the data acquisition and plotting threads
|
# now start the data acquisition and plotting threads
|
||||||
my $dataQueue = Thread::Queue->new();
|
my $dataQueue;
|
||||||
my $xwindow;
|
my $xwindow;
|
||||||
|
|
||||||
if($options{"stream"})
|
if($options{"stream"})
|
||||||
@ -73,6 +72,7 @@ if($options{"stream"})
|
|||||||
}
|
}
|
||||||
$xwindow = $options{"xlen"};
|
$xwindow = $options{"xlen"};
|
||||||
|
|
||||||
|
$dataQueue = Thread::Queue->new();
|
||||||
my $addThr = threads->create(\&mainThread);
|
my $addThr = threads->create(\&mainThread);
|
||||||
my $plotThr = threads->create(\&plotThread);
|
my $plotThr = threads->create(\&plotThread);
|
||||||
|
|
||||||
@ -89,11 +89,6 @@ if($options{"stream"})
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
while(<>)
|
|
||||||
{
|
|
||||||
$dataQueue->enqueue($_);
|
|
||||||
}
|
|
||||||
$dataQueue->enqueue(undef);
|
|
||||||
mainThread();
|
mainThread();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -140,6 +135,7 @@ sub mainThread {
|
|||||||
print PIPE "set output \"$temphardcopyfile\"\n";
|
print PIPE "set output \"$temphardcopyfile\"\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
print PIPE "set terminal x11\n";
|
||||||
print PIPE "set xtics\n";
|
print PIPE "set xtics\n";
|
||||||
if($options{"y2"})
|
if($options{"y2"})
|
||||||
{
|
{
|
||||||
@ -168,7 +164,7 @@ sub mainThread {
|
|||||||
my $str = " axes x1y2 linewidth 3";
|
my $str = " axes x1y2 linewidth 3";
|
||||||
if(exists $curves[$y2idx])
|
if(exists $curves[$y2idx])
|
||||||
{
|
{
|
||||||
$curves[$y2idx]{"extraopts"} .= $str;
|
$curves[$y2idx][0] .= $str;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -179,17 +175,18 @@ sub mainThread {
|
|||||||
# 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]+)?)/;
|
||||||
my $xlast;
|
my $xlast;
|
||||||
while( $_ = $dataQueue->dequeue() )
|
|
||||||
|
while( $_ = ($dataQueue && $dataQueue->dequeue()) || <> )
|
||||||
{
|
{
|
||||||
if(!/Plot now/)
|
if($_ ne "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/gco or next;
|
||||||
$xlast = $1;
|
$xlast = $1;
|
||||||
|
|
||||||
while(/([0-9]+) ($numRE)/gc)
|
while(/([0-9]+) $numRE/gco)
|
||||||
{
|
{
|
||||||
my $idx = $1;
|
my $idx = $1;
|
||||||
my $point = $2;
|
my $point = $2;
|
||||||
@ -200,7 +197,7 @@ sub mainThread {
|
|||||||
newCurve("", "");
|
newCurve("", "");
|
||||||
}
|
}
|
||||||
|
|
||||||
push @{$curves[$idx]->{"data"}}, [$xlast, $point];
|
push @{$curves[$idx]}, [$xlast, $point];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -251,14 +248,13 @@ sub mainThread {
|
|||||||
sub cutOld
|
sub cutOld
|
||||||
{
|
{
|
||||||
my ($oldestx) = @_;
|
my ($oldestx) = @_;
|
||||||
foreach (@curves)
|
|
||||||
{
|
|
||||||
my $xy = $_->{"data"};
|
|
||||||
|
|
||||||
if( @$xy )
|
foreach my $xy (@curves)
|
||||||
{
|
{
|
||||||
my $firstInWindow = first_index {$_->[0] >= $oldestx} @$xy;
|
if( @$xy > 1 )
|
||||||
splice( @$xy, 0, $firstInWindow ) unless $firstInWindow == -1;
|
{
|
||||||
|
my $firstInWindow = first_index {$_->[0] >= $oldestx} @{$xy}[1..$#$xy];
|
||||||
|
splice( @$xy, 1, $firstInWindow ) unless $firstInWindow == -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -268,14 +264,16 @@ sub plotStoredData
|
|||||||
my ($xmin, $xmax) = @_;
|
my ($xmin, $xmax) = @_;
|
||||||
print PIPE "set xrange [$xmin:$xmax]\n" if defined $xmin;
|
print PIPE "set xrange [$xmin:$xmax]\n" if defined $xmin;
|
||||||
|
|
||||||
my @extraopts = map {$_->{"extraopts"}} grep {@{$_->{"data"}}} @curves;
|
# get the options for those curves that have any data
|
||||||
|
my @extraopts = map {$_->[0]} grep {@$_ > 1} @curves;
|
||||||
|
|
||||||
print PIPE 'plot ' . join(', ' , map({ '"-"' . $_} @extraopts) ) . "\n";
|
print PIPE 'plot ' . join(', ' , map({ '"-"' . $_} @extraopts) ) . "\n";
|
||||||
|
|
||||||
foreach my $curve (@curves)
|
foreach my $buf (@curves)
|
||||||
{
|
{
|
||||||
my $buf = $curve->{"data"};
|
# send each point to gnuplot. Ignore the first "point" since it's the
|
||||||
next unless @$buf;
|
# options string
|
||||||
for my $elem (@$buf) {
|
for my $elem (@{$buf}[1..$#$buf]) {
|
||||||
my ($x, $y) = @$elem;
|
my ($x, $y) = @$elem;
|
||||||
print PIPE "$x $y\n";
|
print PIPE "$x $y\n";
|
||||||
}
|
}
|
||||||
@ -289,10 +287,14 @@ sub newCurve()
|
|||||||
if($title) { $opts = "title \"$title\" $opts" }
|
if($title) { $opts = "title \"$title\" $opts" }
|
||||||
else { $opts = "notitle $opts" }
|
else { $opts = "notitle $opts" }
|
||||||
|
|
||||||
$newpoint = [] unless defined $newpoint;
|
if( defined $newpoint )
|
||||||
push ( @curves,
|
{
|
||||||
{"extraopts" => " $opts",
|
push @curves, [" $opts", $newpoint];
|
||||||
"data" => $newpoint} );
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
push @curves, [" $opts"];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sub usage {
|
sub usage {
|
||||||
|
Loading…
Reference in New Issue
Block a user