diff --git a/bash/DemoData/rootsdata.txt b/bash/DemoData/rootsdata.txt index d09b846..2e18ab0 100644 --- a/bash/DemoData/rootsdata.txt +++ b/bash/DemoData/rootsdata.txt @@ -5,3 +5,5 @@ 5 -0.2 6 0.1 7 0.15 +8 0.1 +9 0.0 diff --git a/bash/get_roots_from_datafile.sh b/bash/get_roots_from_datafile.sh index 64b3406..67b4084 100755 --- a/bash/get_roots_from_datafile.sh +++ b/bash/get_roots_from_datafile.sh @@ -23,7 +23,7 @@ then echo " value (minimum or maximum)" echo " yextr: extremum value of y at xextr" echo " " - echo " DEMO: run $0 DemoData/rootsdata.txt" + echo " DEMO: run $0 DemoData/rootsdata.txt 1 2 0" echo " ------------------------------------------------------------" echo " " exit 1 @@ -41,7 +41,7 @@ Nheader=$4 -awk -v xcol=$xcol -v ycol=$ycol -v Nheader=$Nheader <$file 'NR==(Nheader+1) {mode=-1; I=0.0; xroot1=0.0; xroot2=0.0; xprev=0.0; yprev=1.0; check=0} NR>Nheader { +awk -v xcol=$xcol -v ycol=$ycol -v Nheader=$Nheader <$file 'NR==(Nheader+1) {mode=-1; I=0.0; xroot1=0.0; xroot2=0.0; xprev=0.0; yprev=1.0; check=0; extr2found=0} NR>Nheader { x=$(xcol); y=$(ycol); @@ -62,13 +62,25 @@ awk -v xcol=$xcol -v ycol=$ycol -v Nheader=$Nheader <$file 'NR==(Nheader+1) {mo { if ( y <= yextr ) { - yextr=y; - xextr=x; + yextr=y; yextr2=yextr; + xextr=x; xextr2=xextr; } else {check=2;} } + # Find maximum after the minimum + if( (check>1) && (extr2found==0) ) + { + if ( y >= yextr2 ) + { + yextr2=y; + xextr2=x; + } + else + {extr2found=1;} + } + # Find second zero point if (check==2 && (y > 0) ) { @@ -90,12 +102,27 @@ awk -v xcol=$xcol -v ycol=$ycol -v Nheader=$Nheader <$file 'NR==(Nheader+1) {mo # Find maximum after zero point if ( check==1 ) { - if ( y > yextr ) - {yextr=y; xextr=x} + if ( y >= yextr ) + { + yextr=y; yextr2=yextr; + xextr=x; xextr2=xextr; + } else {check=2}; } + # Find minimum after the maximum + if( (check>1) && (extr2found==0) ) + { + if ( y <= yextr2 ) + { + yextr2=y; + xextr2=x; + } + else + {extr2found=1;} + } + # Find second zero point if (check==2 && (y < 0) ) { @@ -115,4 +142,4 @@ awk -v xcol=$xcol -v ycol=$ycol -v Nheader=$Nheader <$file 'NR==(Nheader+1) {mo xprev=x; yprev=y; - } END {printf xroot1" "xroot2" "xextr" "yextr" \n"}' + } END {printf xroot1" "xroot2" "xextr" "yextr" "xextr2" "yextr2" \n"}'