Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- NR==FNR {
- if (FNR>1) {
- a[$1][++i]=$2
- b[$1][i]=$3
- }
- next
- }
- FNR==1 {
- fmt="%-7s%-10s%-10s%-10s%-10s\n"
- printf fmt,"Group","Start","End","NewStart","NewEnd"
- }
- FNR>1{
- $4=$2; $5=$3
- n=checkInside($1,$2,$3)
- if (n>0) {
- ff=0; x=$2; y=$3
- for (i=1; i<=n; i++) {
- ar=a[$1][R[i]]; br=b[$1][R[i]];
- getIntersect($2,$3,ar,br)
- getLargest($2,$3,ar,br)
- ovl=((i2-i1)/($3-$2))*100;
- ovr=((i2-i1)/(br-ar))*100;
- if (ovl>50 && ovr>50) {
- if (r1<x) x=r1
- if (r2>y) y=r2
- ff=1
- }
- }
- if (ff) {
- $4=x; $5=y
- }
- }
- printf fmt,$1,$2,$3,$4,$5
- }
- function getLargest(x1,y1,x2,y2) {
- r1=(x1<=x2)?x1:x2
- r2=(y1>=y2)?y1:y2
- }
- function getIntersect(x1,y1,x2,y2) {
- if (x1>=x2 && x1<=y2) {
- i1=x1;
- } else {
- i1=x2;
- }
- i2=(y1<=y2)?y1:y2
- }
- function checkInside(g,x,y,i,j,x1,y1) {
- R["x"]=0
- for (i in a[g]) {
- x1=a[g][i]; y1=b[g][i];
- if ((x>=x1 && x<=y1) || (y>=x1 && y<=y1)) {
- if (!(x==x1 && y==y1))
- R[++j]=i
- }
- }
- return j
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement