From a9e198cd4317c8821d9b95325005b49ec4f8a7ea Mon Sep 17 00:00:00 2001 From: Ole Tange Date: Sat, 15 Aug 2020 23:48:02 +0200 Subject: [PATCH] plotpipe: added --header, --colsep, and --null. --- plotpipe/plotpipe | 103 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 101 insertions(+), 2 deletions(-) diff --git a/plotpipe/plotpipe b/plotpipe/plotpipe index 5deb3f3..86ef3c3 100755 --- a/plotpipe/plotpipe +++ b/plotpipe/plotpipe @@ -9,7 +9,7 @@ plotpipe - Plot 1D-data or 2D-data from a pipe =head1 SYNOPSIS -I | B +I | B [-H] [-0] [-C str] [-h] [-V] =head1 DESCRIPTION @@ -17,6 +17,48 @@ I | B B is a simple wrapper for GNUPlot to simply plot 1D and 2D-data. +=head1 OPTIONS + +=over 4 + +=item B<--colsep> I + +=item B<-C> I + +Use I 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 Plot the points (1,101) .. (100,200): @@ -60,8 +102,65 @@ B =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 ", + "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 = <>; -@col = split /\s+/, $line1; +@col = split /$opt::colsep/, $line1; if($#col == 1) { # 2 col open GNUPLOT,"|-", q(gnuplot -p -e 'plot "/dev/stdin"') or die;