From ff0404838271306075289a9c5b9b8a18e3db642f Mon Sep 17 00:00:00 2001 From: Dima Kogan Date: Thu, 27 Aug 2009 10:30:55 -0700 Subject: [PATCH] better handling of streaming and non-streaming plotting Ignore-this: f7cbc85b0382a4810db13d01e65f4bd5 darcs-hash:20090827173055-0cb85-aec6122e4405eb8a1f9d5bd61bf683c47837cba0.gz --- driveGnuPlots.pl | 39 ++++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/driveGnuPlots.pl b/driveGnuPlots.pl index a9c243d..0284e2f 100755 --- a/driveGnuPlots.pl +++ b/driveGnuPlots.pl @@ -72,20 +72,33 @@ my $xwindow = $options{"xlen"}; # now start the data acquisition and plotting threads my $dataQueue = Thread::Queue->new(); -my $addThr = threads->create(\&mainThread); -my $plotThr = threads->create(\&plotThread) if(!$options{"stream"}); -while(<>) + +if($options{"stream"}) { - $dataQueue->enqueue($_); + my $addThr = threads->create(\&mainThread); + my $plotThr = threads->create(\&plotThread); + + while(<>) + { + $dataQueue->enqueue($_); + } + + $dataQueue->enqueue("Plot now"); + $dataQueue->enqueue(undef); + + $addThr->join(); + $plotThr->join(); +} +else +{ + while(<>) + { + $dataQueue->enqueue($_); + } + $dataQueue->enqueue(undef); + mainThread(); } - -$dataQueue->enqueue("Plot now"); -$dataQueue->enqueue(undef); - -$addThr->join(); -$plotThr->join() if(!$options{"stream"}); - @@ -100,7 +113,7 @@ sub plotThread sub mainThread { local *PIPE; - open PIPE, "|gnuplot" || die "Can't initialize gnuplot\n"; + open PIPE, "|gnuplot --persist" || die "Can't initialize gnuplot\n"; autoflush PIPE 1; my $temphardcopyfile; @@ -195,6 +208,7 @@ sub mainThread { } } + # read in all of the data if($options{"stream"}) { print PIPE "exit;\n"; @@ -224,7 +238,6 @@ sub mainThread { return; } } - sleep 100000; } sub cutOld