#!/usr/bin/env perl # -*- perl -*- # Extract events out of a data stream # Version: $Id: c_grep,v 1.3 2007/04/27 19:30:16 goeke Exp goeke $ ######################################################################## # initial constants ######################################################################## $LLD = 0; # default LLD $HLD = 4095; # default HLD ######################################################################## # Main program ######################################################################## &Setup; &Filter; exit 0; ######################################################################## # Subroutines follow ######################################################################## ######################################################################## # Do the filtering # By /not/ passing event records which fail either mask or lld/hld test ######################################################################## sub Filter { if ($Strip) { while(<>) { if (/^Time/) { # (we know they occur in this order) print; next; } if (/^SerialNumber/) { print; last; } } } my @mask = split(" ",$Mask); while (<>) { if ($_ !~ /^EventAmp/) { print if (!$Strip); next; } my($saved) = $_; # save the line my(@data) = split; # get the science data for($ii=0; $ii<=$#mask; $ii++) { # All the mask combos for($jj=1; $jj<=6; $jj++) { # print "ii: $ii jj: $jj mask[ii]: $mask[$ii] data[jj]: $data[$jj]\n"; if($mask[$ii] =~ /$jj/) { # Is it in mask? goto LM if($data[$jj]<$LLD); # skip if too small goto LM if($data[$jj]>$HLD); # skip if too large } else { # It is not in mask goto LM if($data[$jj]>$LLD) && ($data[$jj]<$HLD); # skip if in range } } print $saved; # Then let it pass LM: next; } } } ######################################################################## # Give Help ######################################################################## sub Help { print "Usage: $0 [-a #] [-b #] [-h] [-l] [-s] [-v] 12 123 ...\n"; print " flags: -a # specifies the lowest channel of interest [$LLD] -b # specifies the highest channel of interest [$HLD] -h gets full help message -s strip out all non-event data -v makes the output verbose (to STDERR) args coincidence mask Filters out of the data stream all events failing either mask or amplitude criteria; input must be in rtlm -a format. " if ($Verbose); } ######################################################################## # Do the setup ######################################################################## sub Setup { my ($file,$foo); while ($foo = shift(@ARGV)) { if ($foo =~ /^-[aA]/) { # LLD flag $LLD = shift(@ARGV); # get number if (!defined($LLD) || $LLD =~ /\D/) { print STDERR "Flag $foo requires numeric arguement\n"; &Help; exit 2; } next; } if ($foo =~ /^-[bB]/) { # HLD flag $HLD = shift(@ARGV); # get number if (!defined($HLD) || $HLD =~ /\D/) { print STDERR "Flag $foo requires numeric arguement\n"; &Help; exit 2; } next; } if ($foo =~ /^-[hH]/) { $Verbose++; &Help; exit 0; } if ($foo =~ /^-[sS]/) { $Strip++; next; } if ($foo =~ /^-[vV]/) { # verbose $Verbose++; next; } if ($foo =~ /^-/) { print STDERR "Unknown flag: $foo\n"; &Help; exit 1; } if ($foo =~ /[^1-6]/) { print STDERR "Unknown coincidence mask arg.: $foo\n"; &Help; exit 2; } $Mask = $Mask . " " . $foo; } print STDERR "Using mask: $Mask\n" if ($Verbose); print STDERR "Setting LLD to $LLD; setting HLD to $HLD\n" if ($Verbose); if (!defined($Mask)) { print STDERR "Must provide at least one coincidence mask\n"; &Help; exit 4; } } ######################################################################## # Pod follows ######################################################################## =for html CRaTER -- c_grep =head2 NAME B -- Filter the CRaTER primary science data =head2 USAGE c_grep [-a #] [-b #] [-h] [-s] [-v] 12 123 ... =head2 FLAGS -a # specifies the lowest channel of interest -b # specifies the highest channel of interest -h gets full help message -s strip out all non-event data -v makes the output verbose (to STDERR) args discrimnator mask matches =head2 DESCRIPTION Assuming a datastream originating from an B command, c_grep looks (only) at the EventAmp data and discards any line which does not meet both the discriminator mask and low/high amplitude criteria specified. Normally all non-EventAmp lines are passed through unchanged; if the B<-s> flag is given, however, those lines are rejected also, so that the resulting stream consists of a single Time entry, a single SerialNumber entry, and EventAmp entries which meets the selection criteria. =head2 ENVIRONMENT perl5.002 Minimum version of Perl interpreter required CRATERTOOLS Environment variable containing path to CRaTER utilities =head2 BUGS None reported yet; but it's early. =head2 SEE ALSO rtlm =head2 AUTHOR Bob Goeke =head2 RCS Information $Id: c_grep,v 1.3 2007/04/27 19:30:16 goeke Exp goeke $ =cut ######################################################################## # history follows ######################################################################## # $Log: c_grep,v $ # Revision 1.3 2007/04/27 19:30:16 goeke # Fixed bad select logic # # Revision 1.2 2007/04/27 18:39:12 goeke # Updated POD to actually reflect this program! # # Revision 1.1 2007/04/26 19:48:58 goeke # Initial revision # # Revision 1.3 2007/04/26 15:43:56 goeke # Insert header line with s/n and date from rtlm stream # # Revision 1.2 2007/04/24 17:44:16 goeke # update POD # # Revision 1.1 2007/04/19 17:41:27 goeke # Initial revision #