Manage gnuplot with IPC::Open3, so we allow fancy output filenames, with spaces!
This commit is contained in:
parent
a43b67fe7e
commit
410b1363b6
@ -3,6 +3,7 @@
|
|||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
use Getopt::Long;
|
use Getopt::Long;
|
||||||
|
use IPC::Open3;
|
||||||
use Time::Piece;
|
use Time::Piece;
|
||||||
|
|
||||||
my $error = "Usage: $0 --input <CSV file> --output <output PDF> [--max <n.n>] [--low <n.n>] [--high <n.n>]\n";
|
my $error = "Usage: $0 --input <CSV file> --output <output PDF> [--max <n.n>] [--low <n.n>] [--high <n.n>]\n";
|
||||||
@ -27,19 +28,17 @@ GetOptions ("input=s" => \$input, # The name of the CSV file from whic
|
|||||||
"low:f" => \$min_glucose, # The low end of your target blood glucose level
|
"low:f" => \$min_glucose, # The low end of your target blood glucose level
|
||||||
"max:i" => \$graph_max, # The highest displayed glucose level on each graph
|
"max:i" => \$graph_max, # The highest displayed glucose level on each graph
|
||||||
"graphs:i" => \$days_per_page) # The number of days printed on each page
|
"graphs:i" => \$days_per_page) # The number of days printed on each page
|
||||||
or die $error;
|
or die $error;
|
||||||
|
|
||||||
die $error unless ( defined $input and defined $output );
|
open( my $ifh, '<:encoding(UTF-8)', $input )
|
||||||
|
|
||||||
open( my $fh, '<:encoding(UTF-8)', $input )
|
|
||||||
or die "Could not open file '$input' $!";
|
or die "Could not open file '$input' $!";
|
||||||
|
|
||||||
while ( my $row = <$fh> ) {
|
while ( my $row = <$ifh> ) {
|
||||||
chomp( $row );
|
chomp( $row );
|
||||||
push @lines, $row;
|
push @lines, $row;
|
||||||
}
|
}
|
||||||
|
|
||||||
close( $fh )
|
close( $ifh )
|
||||||
or warn "close failed: $!";
|
or warn "close failed: $!";
|
||||||
|
|
||||||
# Set up basic gnuplot options for reading the CSV data
|
# Set up basic gnuplot options for reading the CSV data
|
||||||
@ -98,7 +97,7 @@ reset
|
|||||||
set datafile separator whitespace
|
set datafile separator whitespace
|
||||||
|
|
||||||
set terminal pdf size 29.7cm,21.0cm enhanced font 'Calibri,14' linewidth 1
|
set terminal pdf size 29.7cm,21.0cm enhanced font 'Calibri,14' linewidth 1
|
||||||
set output '$output'
|
#set output '$output'
|
||||||
set key off
|
set key off
|
||||||
set style data lines
|
set style data lines
|
||||||
set xdata time
|
set xdata time
|
||||||
@ -134,7 +133,7 @@ foreach my $d ( sort keys %seen ) {
|
|||||||
|
|
||||||
push @data, qq(
|
push @data, qq(
|
||||||
set title "Daily Glucose Summary for $title" font "Calibri,18"
|
set title "Daily Glucose Summary for $title" font "Calibri,18"
|
||||||
set xlabel "Time" offset 0,1
|
set xlabel "Time" offset 0,-0.25
|
||||||
set ylabel "Blood glucose"
|
set ylabel "Blood glucose"
|
||||||
set xtics left tc rgb "#000000"
|
set xtics left tc rgb "#000000"
|
||||||
set ytics 2 tc rgb "#000000"
|
set ytics 2 tc rgb "#000000"
|
||||||
@ -152,7 +151,7 @@ undefine \$SmoothData$label
|
|||||||
# Add an x grid
|
# Add an x grid
|
||||||
set multiplot previous
|
set multiplot previous
|
||||||
set title " "
|
set title " "
|
||||||
set xlabel " " offset 0,1
|
set xlabel " " offset 0,-0.25
|
||||||
set ylabel " "
|
set ylabel " "
|
||||||
set xtics tc rgb "#ffffff00"
|
set xtics tc rgb "#ffffff00"
|
||||||
set ytics tc rgb "#ffffff00"
|
set ytics tc rgb "#ffffff00"
|
||||||
@ -173,9 +172,39 @@ push @data, qq(
|
|||||||
unset multiplot
|
unset multiplot
|
||||||
);
|
);
|
||||||
|
|
||||||
# output the gnuplot data
|
# run the data through gnuplot
|
||||||
$gnuplot_data = join "\n", @data;
|
$gnuplot_data = join "\n", @data;
|
||||||
print $gnuplot_data;
|
|
||||||
#gnuplot(@data);
|
open( my $ofh, '>', $output )
|
||||||
|
or die "Could not open file '$output' $!";
|
||||||
|
|
||||||
|
my ( $pid, $stdin, $stdout, $stderr );
|
||||||
|
use Symbol 'gensym';
|
||||||
|
$stderr = gensym;
|
||||||
|
|
||||||
|
$pid = open3( $stdin, $stdout, $stderr, 'gnuplot' );
|
||||||
|
|
||||||
|
print $stdin $gnuplot_data;
|
||||||
|
close( $stdin );
|
||||||
|
|
||||||
|
while ( <$stdout> ) {
|
||||||
|
print $ofh "$_";
|
||||||
|
}
|
||||||
|
|
||||||
|
while ( <$stderr> ) {
|
||||||
|
warn $_;
|
||||||
|
}
|
||||||
|
|
||||||
|
close($stdout);
|
||||||
|
close($stderr);
|
||||||
|
|
||||||
|
waitpid( $pid, 0 );
|
||||||
|
my $child_exit_status = $? >> 8;
|
||||||
|
|
||||||
|
close( $ofh )
|
||||||
|
or warn "close failed: $!";
|
||||||
|
|
||||||
|
#open (GNUPLOT, "|gnuplot");
|
||||||
|
#print GNUPLOT $gnuplot_data;
|
||||||
|
|
||||||
# vim: set expandtab shiftwidth=4 softtabstop=4 :
|
# vim: set expandtab shiftwidth=4 softtabstop=4 :
|
||||||
|
Loading…
Reference in New Issue
Block a user