diff --git a/m1rc3/norruption/2/plot-corr b/m1rc3/norruption/2/plot-corr index a8deee2..058777a 100755 --- a/m1rc3/norruption/2/plot-corr +++ b/m1rc3/norruption/2/plot-corr @@ -2,34 +2,45 @@ sub usage { - print STDERR "usage: $0 [-s] [log_file]\n"; + print STDERR "usage: $0 [-s [-n samples] [-i interval]] [log_file]\n"; exit(1); } -if ($ARGV[0] eq "-s") { - shift @ARGV; - $sim = 1; +while ($ARGV[0] =~ /^-/) { + $opt = shift @ARGV; + 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; -while (<>) { - next unless /^=== (\d+) ===/; - while ($1 != $n) { - push(@f, $n); +unless ($sim && defined $sim_n && defined $sim_t) { + $n = 1; + while (<>) { + next unless /^=== (\d+) ===/; + while ($1 != $n) { + push(@f, $n); + $n++; + } $n++; } - $n++; -} -$n--; -$t = int($n/@f+0.5); + $n--; + $t = int($n/@f+0.5); -$last = 0; -for (@f) { - push(@d, $_-$last); - $last = $_; + $last = 0; + for (@f) { + push(@d, $_-$last); + $last = $_; + } } if ($sim) { @@ -39,9 +50,11 @@ if ($sim) { # -T*ln(1-y) = x $type = " (SIMULATED)"; + $sim_n = @f unless defined $sim_n; + $sim_t = $t unless defined $sim_t; @d = (); - for ($i = 0; $i != @f; $i++) { - push(@d, -$t*log(1-rand)); + for ($i = 0; $i != $sim_n; $i++) { + push(@d, -$sim_t*log(1-rand)); } }