Advertisement
cd62131

Maximum and Local Maximum

Dec 22nd, 2017
1,813
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Awk 0.58 KB | None | 0 0
  1. #!/usr/bin/awk -f
  2. BEGIN {
  3.   format1 = "local-maximum: %.1f %.9f\n"
  4.   format2 = "maximum: %.1f %.9f\n"
  5.   out1 = "local-maximum.dat"
  6.   out2 = "maximum.dat"
  7.   printf "" >out1
  8.   printf "" >out2
  9. }
  10. NF {
  11.   if (!max_y) {
  12.     max_x = $1; max_y = $2
  13.   }
  14.   if (max_y < $2) {
  15.     max_x = $1; max_y = $2
  16.   }
  17.   if (py && y && py < y && y > $2) {
  18.     printf format1, x, y >out1
  19.   }
  20.   px = x; py = y; x = $1; y = $2
  21. }
  22. !NF {
  23.   printf format2, max_x, max_y >out2
  24.   max_x = max_y = "";
  25.   px = py = x = y = "";
  26. }
  27. END {
  28.   if (max_y) {
  29.     printf format2, max_x, max_y >out2
  30.   }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement