Scripts for manipulating and calculating statistics from .csc files

This commit is contained in:
Adam Dunkels 2011-02-11 08:41:40 +01:00
parent bb8377dfee
commit 4633e2fcfd
2 changed files with 83 additions and 0 deletions

View File

@ -0,0 +1,54 @@
#!/usr/bin/perl
$num = 0;
$override_range = $ARGV[0];
# Go through the .csc file; find the transmission range and all the
# nodes' x and y coordinates.
while(<STDIN>) {
if(/\<transmitting_range\>([\d.]+)\<\//) {
$range = $1;
}
if(/\<x\>([\d.]+)\</) {
$x[$num] = $1;
}
if(/\<y\>([\d.]+)\</) {
$y[$num] = $1;
$num++;
}
}
print "Range $range num $num override range $override_range\n";
if($override_range) {
$range = $override_range;
}
$no_neighbors = 0;
$all_neighbors = 0;
$total_neighbors = 0;
# Go through all nodes, find how many are in their range.
for($i = 0; $i < $num; $i++) {
$neighbors = 0;
for($j = 0; $j < $num; $j++) {
if($i != $j) {
if(($x[$i] - $x[$j]) * ($x[$i] - $x[$j]) +
($y[$i] - $y[$j]) * ($y[$i] - $y[$j]) <=
$range * $range) {
$neighbors++;
}
}
}
if($neighbors == 0) {
$no_neighbors++;
}
if($neighbors == $num - 1) {
$all_neighbors++;
}
$total_neighbors += $neighbors;
}
print "Num nodes $num, average neighbors " . ($total_neighbors / $num) .
", $no_neighbors nodes (" . (100 * $no_neighbors / $num) .
"%) have no neighbors, $all_neighbors (" . (100 * $all_neighbors / $num) .
"%) have all nodes as neighbors\n";

View File

@ -0,0 +1,29 @@
#!/usr/bin/perl
$csc = $ARGV[0];
$range = $ARGV[1];
$success = $ARGV[2];
if(!$success) {
print "takes a .csc file as input, creates a .csc file with a given tx range and reliability\n";
exit 0;
}
open(F, $csc);
$csc =~ s/\.csc/-$range-$success.csc/g;
open(O, "> $csc");
while(<F>) {
if(m-\<transmitting_range\>[\d.]+\</transmitting_range\>-) {
print O "<transmitting_range>$range</transmitting_range>\n";
} elsif(m-\<interference_range\>[\d.]+\</interference_range\>-) {
print O "<interference_range>" . ($range * 2) . "</transmitting_range>\n";
} elsif(m-\<success_ratio_rx\>[\d.]+\</success_ratio_rx\>-) {
print O "<success_ratio_rx>$success</success_ratio_rx>\n";
} else {
print O;
}
}