mirror of
https://github.com/dkogan/feedgnuplot.git
synced 2025-05-05 22:11:12 +08:00
driveGnuplot can make hardcopies
Ignore-this: 977b3fbc29030371c121450c8095f7ef darcs-hash:20090804230357-0cb85-2fb14bffc9b4f35a82e03a89c4b465b35f93e7d7.gz
This commit is contained in:
parent
dec8b6cac6
commit
a8bb73ec90
@ -1,6 +1,7 @@
|
||||
#!/usr/bin/perl -w
|
||||
use strict;
|
||||
use Getopt::Long;
|
||||
use Time::HiRes qw( usleep );
|
||||
use Data::Dumper;
|
||||
|
||||
# stream in the data by default
|
||||
@ -18,7 +19,8 @@ GetOptions(\%options,
|
||||
"title=s",
|
||||
"y2min=f",
|
||||
"y2max=f",
|
||||
"y2=i@");
|
||||
"y2=i@",
|
||||
"hardcopy=s");
|
||||
|
||||
# set up plotting style
|
||||
my $style = "";
|
||||
@ -47,6 +49,7 @@ also
|
||||
--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
|
||||
}
|
||||
|
||||
@ -66,6 +69,10 @@ sub main {
|
||||
usage;
|
||||
die("Both or neither of y2min,y2max should be specified\n");
|
||||
}
|
||||
if( defined $options{"hardcopy"} && $options{"stream"} )
|
||||
{
|
||||
die("If making a hardcopy, we shouldn't be streaming. Doing nothing\n");
|
||||
}
|
||||
|
||||
my $argIdx = 0;
|
||||
my $numberOfStreams = Arg($argIdx++);
|
||||
@ -88,6 +95,30 @@ sub main {
|
||||
open PIPE, "|gnuplot" || die "Can't initialize gnuplot\n";
|
||||
|
||||
select((select(PIPE), $| = 1)[0]);
|
||||
my $temphardcopyfile;
|
||||
my $outputfile;
|
||||
my $outputfileType;
|
||||
if( defined $options{"hardcopy"})
|
||||
{
|
||||
$outputfile = $options{"hardcopy"};
|
||||
($outputfileType) = $outputfile =~ /\.(ps|pdf|png)$/;
|
||||
if(!$outputfileType) { die("Only .ps, .pdf and .png supported\n"); }
|
||||
|
||||
if ($outputfileType eq "png")
|
||||
{
|
||||
print PIPE "set terminal png\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
print PIPE "set terminal postscript solid color landscape 10\n";
|
||||
}
|
||||
# write to a temporary file first
|
||||
$temphardcopyfile = $outputfile;
|
||||
$temphardcopyfile =~ s{/}{_}g;
|
||||
$temphardcopyfile = "/tmp/$temphardcopyfile";
|
||||
print PIPE "set output \"$temphardcopyfile\"\n";
|
||||
}
|
||||
|
||||
print PIPE "set xtics\n";
|
||||
print PIPE "set ytics\n";
|
||||
print PIPE "set y2tics\n";
|
||||
@ -147,6 +178,26 @@ sub main {
|
||||
{
|
||||
$samples = @{$buffers[0]};
|
||||
plotStoredData($xlast, $samples, $numberOfStreams, *PIPE, \@buffers, \@extraopts);
|
||||
|
||||
if( defined $options{"hardcopy"})
|
||||
{
|
||||
print PIPE "set output\n";
|
||||
# sleep until the plot file exists, and it is closed. Sometimes the output is
|
||||
# still being written at this point
|
||||
usleep(100_000) until -e $temphardcopyfile;
|
||||
usleep(100_000) until(system("fuser -s $temphardcopyfile"));
|
||||
|
||||
if($outputfileType eq "pdf")
|
||||
{
|
||||
system("ps2pdf $temphardcopyfile $outputfile");
|
||||
}
|
||||
else
|
||||
{
|
||||
system("mv $temphardcopyfile $outputfile");
|
||||
}
|
||||
printf "Wrote output to $outputfile\n";
|
||||
return;
|
||||
}
|
||||
}
|
||||
sleep 100000;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user