1
0
mirror of git://projects.qi-hardware.com/wernermisc.git synced 2024-11-15 11:50:37 +02:00

m1rc3/norruption/2/plot-corr: options -n and -i to set samples and interval

Simulation with both -n and -i also doesn't need to read a log file.
This commit is contained in:
Werner Almesberger 2011-10-12 09:49:28 -03:00
parent 1c331b3b5c
commit 36b52a976d

View File

@ -2,34 +2,45 @@
sub usage sub usage
{ {
print STDERR "usage: $0 [-s] [log_file]\n"; print STDERR "usage: $0 [-s [-n samples] [-i interval]] [log_file]\n";
exit(1); exit(1);
} }
if ($ARGV[0] eq "-s") { while ($ARGV[0] =~ /^-/) {
shift @ARGV; $opt = shift @ARGV;
$sim = 1; if ($opt eq "-s") {
$sim = 1;
} elsif ($opt eq "-n") {
$sim_n = shift @ARGV;
&usage unless defined $sim_n;
} elsif ($opt eq "-i") {
$sim_t = shift @ARGV;
&usage unless defined $sim_t;
} else {
&usage;
}
} }
&usage if $ARGV[0] =~ /^-/;
$n = 1; unless ($sim && defined $sim_n && defined $sim_t) {
while (<>) { $n = 1;
next unless /^=== (\d+) ===/; while (<>) {
while ($1 != $n) { next unless /^=== (\d+) ===/;
push(@f, $n); while ($1 != $n) {
push(@f, $n);
$n++;
}
$n++; $n++;
} }
$n++;
}
$n--; $n--;
$t = int($n/@f+0.5); $t = int($n/@f+0.5);
$last = 0; $last = 0;
for (@f) { for (@f) {
push(@d, $_-$last); push(@d, $_-$last);
$last = $_; $last = $_;
}
} }
if ($sim) { if ($sim) {
@ -39,9 +50,11 @@ if ($sim) {
# -T*ln(1-y) = x # -T*ln(1-y) = x
$type = " (SIMULATED)"; $type = " (SIMULATED)";
$sim_n = @f unless defined $sim_n;
$sim_t = $t unless defined $sim_t;
@d = (); @d = ();
for ($i = 0; $i != @f; $i++) { for ($i = 0; $i != $sim_n; $i++) {
push(@d, -$t*log(1-rand)); push(@d, -$sim_t*log(1-rand));
} }
} }