Werner's Miscellanea
Sign in or create your account | Project List | Help
Werner's Miscellanea Commit Details
Date: | 2011-10-12 14:49:28 (12 years 1 month ago) |
---|---|
Author: | Werner Almesberger |
Commit: | 36b52a976d287876f06a12bdf34dfe13c80d7df0 |
Message: | 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. |
Files: |
m1rc3/norruption/2/plot-corr (2 diffs) |
Change Details
m1rc3/norruption/2/plot-corr | ||
---|---|---|
2 | 2 | |
3 | 3 | sub usage |
4 | 4 | { |
5 | print STDERR "usage: $0 [-s] [log_file]\n"; | |
5 | print STDERR "usage: $0 [-s [-n samples] [-i interval]] [log_file]\n"; | |
6 | 6 | exit(1); |
7 | 7 | } |
8 | 8 | |
9 | 9 | |
10 | if ($ARGV[0] eq "-s") { | |
11 | shift @ARGV; | |
12 | $sim = 1; | |
10 | while ($ARGV[0] =~ /^-/) { | |
11 | $opt = shift @ARGV; | |
12 | if ($opt eq "-s") { | |
13 | $sim = 1; | |
14 | } elsif ($opt eq "-n") { | |
15 | $sim_n = shift @ARGV; | |
16 | &usage unless defined $sim_n; | |
17 | } elsif ($opt eq "-i") { | |
18 | $sim_t = shift @ARGV; | |
19 | &usage unless defined $sim_t; | |
20 | } else { | |
21 | &usage; | |
22 | } | |
13 | 23 | } |
14 | &usage if $ARGV[0] =~ /^-/; | |
15 | 24 | |
16 | $n = 1; | |
17 | while (<>) { | |
18 | next unless /^=== (\d+) ===/; | |
19 | while ($1 != $n) { | |
20 | push(@f, $n); | |
25 | unless ($sim && defined $sim_n && defined $sim_t) { | |
26 | $n = 1; | |
27 | while (<>) { | |
28 | next unless /^=== (\d+) ===/; | |
29 | while ($1 != $n) { | |
30 | push(@f, $n); | |
31 | $n++; | |
32 | } | |
21 | 33 | $n++; |
22 | 34 | } |
23 | $n++; | |
24 | } | |
25 | 35 | |
26 | $n--; | |
27 | $t = int($n/@f+0.5); | |
36 | $n--; | |
37 | $t = int($n/@f+0.5); | |
28 | 38 | |
29 | $last = 0; | |
30 | for (@f) { | |
31 | push(@d, $_-$last); | |
32 | $last = $_; | |
39 | $last = 0; | |
40 | for (@f) { | |
41 | push(@d, $_-$last); | |
42 | $last = $_; | |
43 | } | |
33 | 44 | } |
34 | 45 | |
35 | 46 | if ($sim) { |
... | ... | |
39 | 50 | # -T*ln(1-y) = x |
40 | 51 | |
41 | 52 | $type = " (SIMULATED)"; |
53 | $sim_n = @f unless defined $sim_n; | |
54 | $sim_t = $t unless defined $sim_t; | |
42 | 55 | @d = (); |
43 | for ($i = 0; $i != @f; $i++) { | |
44 | push(@d, -$t*log(1-rand)); | |
56 | for ($i = 0; $i != $sim_n; $i++) { | |
57 | push(@d, -$sim_t*log(1-rand)); | |
45 | 58 | } |
46 | 59 | } |
47 | 60 |
Branches:
master