1*41123Sbostic/^ *[0-9]/	{
2*41123Sbostic	# print out the median time to each hop along a route.
3*41123Sbostic	tottime = 0; n = 0;
4*41123Sbostic	for (f = 5; f <= NF; ++f) {
5*41123Sbostic		if ($f == "ms") {
6*41123Sbostic			++n
7*41123Sbostic			time[n] = $(f - 1)
8*41123Sbostic		}
9*41123Sbostic	}
10*41123Sbostic	if (n > 0) {
11*41123Sbostic		# insertion sort the times to find the median
12*41123Sbostic		for (i = 2; i <= n; ++i) {
13*41123Sbostic			v = time[i]; j = i - 1;
14*41123Sbostic			while (time[j] > v) {
15*41123Sbostic				time[j+1] = time[j];
16*41123Sbostic				j = j - 1;
17*41123Sbostic				if (j < 0)
18*41123Sbostic					break;
19*41123Sbostic			}
20*41123Sbostic			time[j+1] = v;
21*41123Sbostic		}
22*41123Sbostic		if (n > 1 && (n % 2) == 0)
23*41123Sbostic			median = (time[n/2] + time[(n/2) + 1]) / 2
24*41123Sbostic		else
25*41123Sbostic			median = time[(n+1)/2]
26*41123Sbostic
27*41123Sbostic		print $1, median
28*41123Sbostic	}
29*41123Sbostic}
30