1
0
mirror of git://projects.qi-hardware.com/ben-wpan.git synced 2024-12-23 18:36:47 +02:00
ben-wpan/usrp/range
Werner Almesberger 8ea171512b usrp/range: more useful diagnostic output and harden against underflows
- usrp/range: ignore "-inf" values
- usrp/range: print the average value when reporting an outlier
2010-12-01 11:08:41 -03:00

52 lines
762 B
Perl
Executable File

#!/usr/bin/perl
sub usage
{
print STDERR "usage: $0 [[-v] tolerance]\n";
exit(1);
}
$tol = 999;
if (@ARGV) {
$tol = shift @ARGV;
if ($tol eq "-v") {
$verbose = 1;
$tol = shift @ARGV;
}
&usage unless $tol =~ /^[0-9.]+$/;
&usage if @ARGV;
}
while (<>) {
chop;
next if $_ eq "-inf";
push(@v, $_);
$s += $_;
}
$avg = $s/@v;
$n = 0;
for (@v) {
$n++;
next if $_ eq "-inf";
if ($_ < $avg-$tol || $_ > $avg+$tol) {
print STDERR "sample $n is outlier ($avg): $_\n" if $verbose;
next;
}
$sum += $_;
$ns++;
$min = $_ if $_ < $min || !defined $min;
$max = $_ if $_ > $max || !defined $max;
}
if (!$ns) {
print STDERR "no samples\n";
exit(1);
}
print $sum/$ns, " $min $max\n";