#!/usr/bin/perl

$sumbw = 0;
$valid = 0;
print "cprobe $ARGV[0] $ARGV[1] times\ntrial# available_bw\n";
for ($i=0; $i< $ARGV[1]; $i++) {
	system("cprobe  $ARGV[0] > test.cp.bw");
        open(TEST, "test.cp.bw");
        $first = 0;
        while (<TEST>) {
		if (/Available Bandwidth/) {
			@fields=split(/:/, $_);
			$bw = @fields[1];
		}
        }
        print "$i\t$bw";
	$_ = $bw;
	unless (/^ 0\.0/) {
		$sumbw += $bw;
		$valid++;
	}
}
$avgbw=$sumbw/$valid;
print "valid trial#=$valid, average available bw=$avgbw\n";
