diff --git a/find-first-fail/find-first-fail b/find-first-fail/find-first-fail index a7ddf90..f36cf04 100755 --- a/find-first-fail/find-first-fail +++ b/find-first-fail/find-first-fail @@ -11,7 +11,7 @@ fragment (or numeric argument) =head1 SYNOPSIS -B [-2] [-q] [-s I] [-v] [-V] I +B [-2] [-q] [-s I] [-e I] [-v] [-V] I B -f I [-s I] [-q] [-v] [-V] I @@ -57,7 +57,15 @@ Quiet. Ignore output from I. =item B<-s I> -Start searching from the value I. Normally searching will start from the value 1. +Start searching from the value I. Normally searching will start +from the value 1. + + +=item B<-e I> + +End searching at the value I. Normally this value will be +determined automatically, but you can limit the search to be below +the value I. =item B<-v> @@ -116,7 +124,7 @@ Complex commands can also be run: =head2 Find the second limit of a program Assume you have a program that is OK in the range 123..12345. How do -you find the limits? +you find those limits? myprog() { perl -e '$a=shift;if($a <= 123) { exit 0; } else { exit ($a <= 12345) }' "$@"; } @@ -231,7 +239,7 @@ find-first-fail() { } _find_in_arg() { - # If function(1) = false: run 'not function()' instead + # If function($start) == false: run 'not function()' instead local not if _run "$start" "$start" "?" "$@" ; then not='' @@ -239,19 +247,25 @@ find-first-fail() { not='!' fi - # exponential search for the first value that is false - # low = previous value (function($low) == true) - # high = low * 2 (function($high) == false) - local high=$(( $start*2 )) local low=$start - while _run $low $high "?" "$@" ; do - low=$high - high=$(( $high*2 )) - if [ $high -gt 4611686018427387900 ] ; then - echo "find-first-fail: Error: exit value does not change of '$@'" >&2 - return - fi - done + local high + if [ -z "$end" ] ; then + # No end value given with -e: + # exponential search for the first value that is false + # low = previous value (function($low) == true) + # high = low * 2 (function($high) == false) + high=$(( $start*2 )) + while _run $low $high "?" "$@" ; do + low=$high + high=$(( $high*2 )) + if [ $high -gt 4611686018427387900 ] ; then + echo "find-first-fail: Error: exit value does not change of '$@'" >&2 + return + fi + done + else + high=$end + fi # low = tested good # high = tested fail @@ -366,8 +380,8 @@ find-first-fail() { version() { cat < This is free software: you are free to change and redistribute it. find-first-fail comes with no warranty. @@ -385,12 +399,13 @@ EOF unset OPTIND # Parse and remove options - while getopts "2f:qs:vV" options; do + while getopts "2e:f:qs:vV" options; do case "${options}" in (2) opt2=true;; (f) optf=true; inputfile="$OPTARG";; (q) quiet=">/dev/null 2>/dev/null";; (s) start="$OPTARG";; + (e) end="$OPTARG";; (v) verbose=true;; (V) version; exit 0;; (-) break;; diff --git a/find-first-fail/testsuite b/find-first-fail/testsuite index 154a040..a85192f 100644 --- a/find-first-fail/testsuite +++ b/find-first-fail/testsuite @@ -97,6 +97,14 @@ test_file_start_middle_end() { find-first-fail -s1 -f "$tmp" myparser } +test_end() { + echo 'Find 12' + myprog() { perl -e 'exit (shift > 12)' "$@"; } + export -f myprog + find-first-fail -v -e 13 myprog + find-first-fail -v -s 11 -e 15 myprog +} + export -f $(compgen -A function | grep test_) compgen -A function | grep test_ | LC_ALL=C sort | parallel --timeout 1000% --tag -k --joblog /tmp/jl-`basename $0` '{} 2>&1' diff --git a/plotpipe/plotpipe b/plotpipe/plotpipe index dd39460..369a7fc 100755 --- a/plotpipe/plotpipe +++ b/plotpipe/plotpipe @@ -109,34 +109,36 @@ input.csv: cat input.csv | plotpipe -=head1 EXAMPLE +=head1 EXAMPLE: No x column input.csv: - #Title line 1 - #This is title line 2 - X axis header,Values 1,Values 2 - 1,28,32 - 2,12,35 - 3,3.5,3.5 + #Plot with no x-value column + Values 1,Values 2 + 28,32 + 12,35 + 3.5,3.5 - cat input.csv | plotpipe + cat input.csv | plotpipe --nox + +=head1 EXAMPLE: Log + +input.csv: + + #Plot with log y + 2^n 3^n 4^n + 1 1 1 + 2 3 4 + 4 9 16 + 8 27 64 + + cat input.csv | plotpipe --nox --logy =head1 LIMITS B is limited by Gnuplot. -13x113425 = 28 MB -43x13203 = 10 MB -43x24068 = 5.8 MB -10x315636 -Gnuplot will complain: - - line -1: warning: Cannot find or open file "/tmp/plotXXXXX" - -if the input is too big. The plot will then be incomplete. - =head1 AUTHOR