#---------- interval scanner ----------
-our (%interval,%last);
-# $now{V} value at this instant
-# $now{S} seconds
-# $now{U} microseconds
-# $now{Slop} slop in current transition; undef = no transition here
-# $last{V} value at last instant } undef =
-# $last{S} time of last instant (seconds) } before first
-# $last{U} time of last instant (microseconds) } instant
-# $last{Slop} irrelevant
-# $interval{V} value in the current interval; undef = before first val
-# $interval{S} } start of current interval
-# $interval{U} } undef = no transition found yet
-# $interval{Slop} }
+our ($begintmin,$begintmax);
+our ($lastt,$lastvalue);
-sub found_datapoint ($$$$) {
- # found_datapoint($s,$u,$value,$inacc) is called
- # when we find that $value was measured at between $s.$u and $s.$u+$inacc
- my (%now) = (S => $_[0], U => $_[1], V => $_[2]);
- my ($inacc) = $_[3];
- my ($minlen,$maxlen);
-
- if (exists $interval{V} and $now{V} ne $interval{V}) {
- # found a transition
- $now{Slop}= usec_from_to(\%last,\%now) + $inacc;
- }
- if (defined $now{Slop} and defined $interval{S}) {
- # found an interval
- $minlen= usec_from_to(\%interval,\%now) - $now{Slop};
- $maxlen= $minlen + $interval{Slop};
- printf("\@<%10d.%06d %6d..%-6d %s ",
- $now{S},$now{U}, $minlen,$maxlen, $interval{V});
- found_interval($interval{V}, $minlen, $maxlen);
- }
- if (defined $now{Slop}) { # found a transition ? mark it as last one
- %interval= %now;
+sub found_datapoint ($$) {
+ my ($t,$value) = @_;
+ # called when we find that $value was measured at $t
+
+ if ($value > -0.01 && $value < 0.01) {
+ return; # treat as zero, ignore
}
- if (!defined $interval{V}) { # if right at start, simply not current V
- $interval{V}= $now{V};
+
+ if (defined $lastt && $value * $lastvalue < 0) {
+ if (defined $begintmin) {
+ found_interval($value > 0, $lastt-$begintmax, $t-$begintmin);
+ }
+ $begintmin= $lastt;
+ $begintmax= $t;
}
- %last= %now;
+ $lastt= $t;
+ $lastvalue= $value;
}
#---------- datapoint reader ----------
sub read_input_file() {
- my (%now,%last);
-
reset_bit_decoder();
while (<STDIN>) {
last if STDIN->eof;
- m/^(\d+)\.(\d+) ([0-9a-f]{2})$/ or die "$_ ?";
-
- %now= (S => $1,
- U => $2,
- V => $3);
- if (defined $last{V}) {
- found_datapoint($last{S}, $last{U}, $last{V},
- usec_from_to(\%last, \%now));
- }
- %last= %now;
+ next if m/^\;/;
+ m/^\s*([-.0-9e]+)\s+([-.0-9e]+)\s*$/ or die "$_ ?";
+ found_datapoint($1 * 1e6, $2);
}
die $! if STDIN->error;
}