#!/usr/local/bin/perl -w # # reads two nfiles # and finds matchine events to plot their diffs # # ~/_cons/widata/whata.p > What_a/d $file1 = "What_a/n.18B" ; $file2 = "What_a/n.19B" ; $ccol = 5 ; # which col c is found in. (in nfile) $changed = 10.0 ; # value beyond which delta t is judged to # have changed $history = 6 ; $verbose = 1 ; eval "\$$1=\$2" while @ARGV && $ARGV[0]=~ /^(\w+)=(.*)/ && shift; $ccol -- ; # zero offset! $tcol = $ccol + 1 ; # column with time in it for ( $h = 0 ; $h <= $history ; $h ++ ) { $dt[$h] = 0.0 ; $c[$h] = 0 ; } open ( B1 , "<$file1" ) ; open ( B2 , "<$file2" ) ; $c1 = 0 ; $c2 = 0 ; $b1 = 0 ; $b2 = 0 ; $ldiff = 0 ; &read1 ; &read2 ; $l = 0 ; while ( $c1 && $c2 ) { if ( $c1 == $c2 ) { $l ++ ; # printf "%8.3g %8.3g %8.3g %4d\n", $t1-$t2, $t1, $t2, $c1 ; printf "%8.3g %8.3g %8.3g %4d\n", $t1-$t2, $t1, $t2, $c1 ; $dt[0] = $t1-$t2 ; $c[0] = $c1 ; # look for a change $same = 0 ; $diff = 0 ; for ( $h = $history ; $h >= 1 ; $h -- ) { $ddt = $dt[$h] - $dt[0] ; if ( abs($ddt) <= $changed ) { # then it is the same as a piece of history $same ++ ; } else { $diff ++ ; # } } if ( $diff >= $same ) { # this is an outlier, or a change. # check most recent line with an outlier / change if ( $ldiff && ( $ldiff == $l - 1 ) ) { if ( !$ldiff2 || ( $ldiff2 != $l - 2 ) ) { print STDERR "new block at line $ldiff.\t c=$c1, \tcpast=$c[$history]..$c[2],$c[1]\n" ; } $ldiff2 = $ldiff ; } $ldiff = $l ; } # shuffle history for ( $h = $history ; $h >= 1 ; $h -- ) { $dt[$h] = $dt[$h-1] ; $c[$h] = $c[$h-1] ; } &read1 ; &read2 ; } elsif ( $c1 > $c2 ) { while ( $c2 && ($c1 > $c2) ) { &read2 ; } } else { while ( $c1 && ( $c1 < $c2 ) ) { &read1 ; } } } print STDERR "wrote $l lines, read $b1 and $b2\n" ; sub read1 { if(defined($_ = )) { $b1 ++ ; # s/^\s+//g ; @a = split ; $c1 = $a[$ccol] ; $t1 = $a[$tcol] ; } else { $c1 = 0 ; } return $c1 ; } sub read2 { if(defined($_ = )) { $b2 ++ ; # s/^\s+//g ; @a = split ; $c2 = $a[$ccol] ; $t2 = $a[$tcol] ; } else { $c2 = 0 ; } return $c2 ; }