Advertisement
hakonhagland

Overlap2

Feb 1st, 2014
341
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. NR==FNR {
  2. if (FNR>1) {
  3. a[$1][++i]=$2
  4. b[$1][i]=$3
  5. }
  6. next
  7. }
  8. FNR==1 {
  9. fmt="%-7s%-10s%-10s%-10s%-10s\n"
  10. printf fmt,"Group","Start","End","NewStart","NewEnd"
  11. }
  12. FNR>1{
  13. $4=$2; $5=$3
  14. n=checkInside($1,$2,$3)
  15. if (n>0) {
  16. ff=0; x=$2; y=$3
  17. for (i=1; i<=n; i++) {
  18. ar=a[$1][R[i]]; br=b[$1][R[i]];
  19. getIntersect($2,$3,ar,br)
  20. getLargest($2,$3,ar,br)
  21. ovl=((i2-i1)/($3-$2))*100;
  22. ovr=((i2-i1)/(br-ar))*100;
  23. if (ovl>50 && ovr>50) {
  24. if (r1<x) x=r1
  25. if (r2>y) y=r2
  26. ff=1
  27. }
  28. }
  29. if (ff) {
  30. $4=x; $5=y
  31. }
  32. }
  33. printf fmt,$1,$2,$3,$4,$5
  34. }
  35.  
  36. function getLargest(x1,y1,x2,y2) {
  37. r1=(x1<=x2)?x1:x2
  38. r2=(y1>=y2)?y1:y2
  39. }
  40.  
  41. function getIntersect(x1,y1,x2,y2) {
  42. if (x1>=x2 && x1<=y2) {
  43. i1=x1;
  44. } else {
  45. i1=x2;
  46. }
  47. i2=(y1<=y2)?y1:y2
  48. }
  49.  
  50. function checkInside(g,x,y,i,j,x1,y1) {
  51. R["x"]=0
  52. for (i in a[g]) {
  53. x1=a[g][i]; y1=b[g][i];
  54. if ((x>=x1 && x<=y1) || (y>=x1 && y<=y1)) {
  55. if (!(x==x1 && y==y1))
  56. R[++j]=i
  57. }
  58. }
  59. return j
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement