#!/bin/sh
# eliminates rows in data file in order to eliminate/reduce 2d overlap of symbols in plot
# parameters: colX colY radX radY; 5th parameter "i" inverts colX 
colX=${1:-1}
colY=${2:-2}
radX=${3:-1.0}
radY=${4:-1.0}
INV=${5}

export LANG=en_US.UTF-8

if [ "${INV}" == "i" ]
then
	grep -v "#" | awk '{if ((NF>0)&&($'${colX}'!=0)) print $0 }' | awk '{X=1.0/$'${colX}'; Y=$'${colY}'; if (NR>1){dX=X-Xold; dY=Y-Yold; \
	if ((dX/'${radX}')**2+(dY/'${radY}')**2>1) {print $0; Xold=X; Yold=Y}} else {print $0; Xold=X; Yold=Y}}'
else
	grep -v "#" | awk '{X=$'${colX}'; Y=$'${colY}'; if (NR>1){dX=X-Xold; dY=Y-Yold; \
	if ((dX/'${radX}')**2+(dY/'${radY}')**2>1) {print $0; Xold=X; Yold=Y}} else {print $0; Xold=X; Yold=Y}}'
fi
# print "#", X, dX, Xold, Y, dY, Yold; 