#!/usr/local/bin/perl -w # # reads several nfiles and writes a new nfile # containing all those bursts and blinks. # it renumbers consistently, using b=1.., c=1.. # the given values of b and c are ignored except in that equality of # two c's means the blink is one blink. # it is assumed that all blinks associated with one burst are # contiguous. # # usage # merger.p bmax=6 n-* > n6 # merger.p bmax=2 n-* > n2 # merger.p bmax=100 n-* > n100 # # see also Data/stripper.p to kill off antennae in an 'n' file. # see What_is_a for more usage # $nonames=1 ; # knock out the antenna names $bcol = 4 ; # which col b is found in. $bmax = 0 ; # number of bursts to collect from each file # if zero, then all bursts are taken. eval "\$$1=\$2" while @ARGV && $ARGV[0]=~ /^(\w+)=(.*)/ && shift; $bcol -- ; $ccol = $bcol + 1 ; $newb = 0 ; $newc = 0 ; $p = 0 ; print STDERR "Doing ... " ; foreach $f ( @ARGV ) { $latestb = 0 ; $latestc = 0 ; print STDERR "$f ... " ; open ( O , "<$f" ) ; $i = 0 ; while(defined($_ = )&&((!$bmax)||($latestb <= $bmax ))) { $i ++ ; s/^\s+//g ; @a = split ; $b = $a[$bcol] ; $c = $a[$ccol] ; if ( (!$bmax) || ( $b <= $bmax ) ) { if ( $b != $latestb ) { # we have gone to a new burst $newb ++ ; } $a[$bcol] = $newb ; if ( $c != $latestc ) { # we have gone to a new burst $newc ++ ; } $a[$ccol] = $newc ; if ($nonames ) { $a[0] = "" ; # this obliterates the antennae names } print join ( "\t" , @a ) , "\n" ; $p ++ ; } $latestb = $b ; $latestc = $c ; } close(O) ; } print STDERR "\ndone, printed $p lines \n" ; print STDERR "-B $newb -C $newc -N $p \n" ;