Expand PMF_FN_* macros.
[netbsd-mini2440.git] / usr.sbin / traceroute / median.awk
blobe9ad5fd12bdcb97d9478f169d77eed34cb893df5
1 #!/bin/awk -f
2 # $NetBSD: median.awk,v 1.1.1.3 1997/10/03 22:25:29 christos Exp $
3 /^ *[0-9]/ {
4 # print out the median time to each hop along a route.
5 tottime = 0; n = 0;
6 for (f = 5; f <= NF; ++f) {
7 if ($f == "ms") {
8 ++n
9 time[n] = $(f - 1)
12 if (n > 0) {
13 # insertion sort the times to find the median
14 for (i = 2; i <= n; ++i) {
15 v = time[i]; j = i - 1;
16 while (time[j] > v) {
17 time[j+1] = time[j];
18 j = j - 1;
19 if (j < 0)
20 break;
22 time[j+1] = v;
24 if (n > 1 && (n % 2) == 0)
25 median = (time[n/2] + time[(n/2) + 1]) / 2
26 else
27 median = time[(n+1)/2]
29 print $1, median