Skip to content

Commit

Permalink
ADDED: bash/get_roots: find second extremum
Browse files Browse the repository at this point in the history
  • Loading branch information
CharleySchaefer committed Jun 25, 2018
1 parent 7d320f9 commit 86e236a
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 7 deletions.
2 changes: 2 additions & 0 deletions bash/DemoData/rootsdata.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@
5 -0.2
6 0.1
7 0.15
8 0.1
9 0.0
41 changes: 34 additions & 7 deletions bash/get_roots_from_datafile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
Expand All @@ -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) )
{
Expand All @@ -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) )
{
Expand All @@ -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"}'

0 comments on commit 86e236a

Please sign in to comment.