plotpipe: added --header, --colsep, and --null.

This commit is contained in:
Ole Tange 2020-08-15 23:48:02 +02:00
parent b1bb72c63b
commit a9e198cd43

View file

@ -9,7 +9,7 @@ plotpipe - Plot 1D-data or 2D-data from a pipe
=head1 SYNOPSIS =head1 SYNOPSIS
I<datagenerator> | B<plotpipe> I<datagenerator> | B<plotpipe> [-H] [-0] [-C str] [-h] [-V]
=head1 DESCRIPTION =head1 DESCRIPTION
@ -17,6 +17,48 @@ I<datagenerator> | B<plotpipe>
B<plotpipe> is a simple wrapper for GNUPlot to simply plot 1D and 2D-data. B<plotpipe> is a simple wrapper for GNUPlot to simply plot 1D and 2D-data.
=head1 OPTIONS
=over 4
=item B<--colsep> I<string>
=item B<-C> I<string>
Use I<string> as column separator.
=item B<--header>
=item B<-H>
Ignore first line of input (it is a header).
=item B<--help>
=item B<-h>
Show help.
=item B<--null>
=item B<-0>
Use \0 (NUL) instead of newline (\n) as record separator.
=item B<--version>
=item B<-V>
Show version
=back
=head1 EXAMPLE =head1 EXAMPLE
Plot the points (1,101) .. (100,200): Plot the points (1,101) .. (100,200):
@ -60,8 +102,65 @@ B<gnuplot>
=cut =cut
use Getopt::Long;
sub options_hash() {
# Returns:
# %hash = the GetOptions config
return
("debug|D=s" => \$opt::D,
"version|V" => \$opt::version,
"colsep|col-sep|C=s" => \$opt::colsep,
"help|h" => \$opt::help,
"null|0" => \$opt::null,
"header|H" => \$opt::header,
);
}
sub version() {
# Returns: N/A
print join
("\n",
"GNU $Global::progname $Global::version",
"Copyright (C) 2020 Ole Tange, http://ole.tange.dk and Free Software",
"Foundation, Inc.",
"License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>",
"This is free software: you are free to change and redistribute it.",
"GNU $Global::progname comes with no warranty.",
"",
"Web site: https://gitlab.com/ole.tange/tangetools/-/tree/master/${Global::progname}\n",
"",
);
}
sub help() {
# Returns: N/A
print join
("\n",
"Usage:",
"",
"... | plotpipe [-H] [-0] [-C str]",
"",
"-H Ignore first line (header)",
'-0 Records separated by \0 instead of \n',
'-C str Columns separator',
'-V Show version',
"",
"See 'man $Global::progname' for details",
"",);
}
Getopt::Long::Configure("bundling","require_order");
my $retval = GetOptions(options_hash());
$Global::progname = "plotpipe";
$Global::version = 20200810;
if($opt::version) { version(); exit 0; }
if($opt::help) { help(); exit 0; }
if($opt::null) { $/ = "\0"; }
$opt::colsep ||= '\s+';
if($opt::header) { <> }
$line1 = <>; $line1 = <>;
@col = split /\s+/, $line1; @col = split /$opt::colsep/, $line1;
if($#col == 1) { if($#col == 1) {
# 2 col # 2 col
open GNUPLOT,"|-", q(gnuplot -p -e 'plot "/dev/stdin"') or die; open GNUPLOT,"|-", q(gnuplot -p -e 'plot "/dev/stdin"') or die;