#!/usr/bin/env perl # -*- perl -*- # Generate a histogram of science data # Version: $Id: c_hist,v 2.1 2007/05/04 13:47:26 goeke Exp goeke $ ######################################################################## # initial constants ######################################################################## $DIR = $ENV{CRATERTOOLS}; # needed to find rtlm $LLD = 0; # default LLD $HLD = 4095; # default HLD ######################################################################## # Main program ######################################################################## &Setup; &Histogram; &Display; exit 0; ######################################################################## # Subroutines follow ######################################################################## ######################################################################## # Display Results ######################################################################## sub Display { my $k = log(10); if ($Log) { $form = "%4d\t%4.2f\t%4.2f\t%4.2f\t%4.2f\t%4.2f\t%4.2f\n"; } else { $form = "%4d\t%6d\t%6d\t%6d\t%6d\t%6d\t%6d\n"; } # Put date and serial number in first across top # Require seven fields across top for users to depend on # date is "Time hh:mm:ss mm/dd/yy", serial is "SerialNumber xx" printf "### CRaTER %s\t%s\t%s\t%s\n",$Number,$Time; for ($ii=$LLD; $ii<$HLD; $ii++) { printf $form, $ii, $Log && $Count1[$ii]>0 ? log($Count1[$ii])/$k : $Count1[$ii], $Log && $Count2[$ii]>0 ? log($Count2[$ii])/$k : $Count2[$ii], $Log && $Count3[$ii]>0 ? log($Count3[$ii])/$k : $Count3[$ii], $Log && $Count4[$ii]>0 ? log($Count4[$ii])/$k : $Count4[$ii], $Log && $Count5[$ii]>0 ? log($Count5[$ii])/$k : $Count5[$ii], $Log && $Count6[$ii]>0 ? log($Count6[$ii])/$k : $Count6[$ii], } } ######################################################################## # Give Help ######################################################################## sub Help { print "Usage: $0 [-a #] [-b #] [-h] [-l] [-v] [file_name]\n"; print " flags: -a # specifies the lowest channel of interest [$LLD] -b # specifies the highest channel of interest [$HLD] -h gets full help message -l reports results log-base-10 -v makes the output verbose (to STDERR) Generates a tab-separated histogram of science data to STDOUT. If file_name given, it is assumed to be an LRO-standard data archive, otherwise STDIN is read, assumed to be the output of an rtlm -a process. " if ($Verbose); } ######################################################################## # Do the accumulation ######################################################################## sub Histogram { my ($jj,$d1,$d2,$d3,$d4,$d5,$d6); while () { # first get the time and serial number if (/Time/) { # (we know they occur in that order) $Time = $_; chop $Time; } elsif (/SerialNumber/) { $Number = $_; chop $Number; last; } } print STDERR "Serial Number: $Number\n" if $Verbose; while () { next if (!/^EventAmp/); my($foo,$d1,$d2,$d3,$d4,$d5,$d6) = split; # get the science data $Count1[$d1]++; # notch the counters $Count2[$d2]++; $Count3[$d3]++; $Count4[$d4]++; $Count5[$d5]++; $Count6[$d6]++; $jj++; last if ($jj>100 && $Verbose); print STDERR "Data: $d1 $d2 $d3 $d4 $d5 $d6\n" if ($Verbose); print STDERR "Sums: $Count1[$d1] $Count2[$d2] $Count3[$d3] $Count4[$d4] $Count5[$d5] $Count6[$d6] \n" 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 =~ /^-[lL]/) { $Log++; next; } if ($foo =~ /^-[vV]/) { # verbose $Verbose++; next; } if ($foo =~ /^-/) { print STDERR "Unknown flag: $foo\n"; &Help; exit 1; } $file = $foo; next; } print STDERR "Using $file as input\n" if ($Verbose); print STDERR "Setting LLD to $LLD; setting HLD to $HLD\n" if ($Verbose); if (!defined($file)) { open(RTLM,"<&STDIN") || die "Could not dup STDIN"; # print "Must define a target file to read\n"; # &Help; exit 4; } else { open(RTLM,"$DIR/rtlm -a -t -r $file |") || die "Could not open rtlm pipe"; } } ######################################################################## # Pod follows ######################################################################## =for html CRaTER -- c_hist =head2 NAME B -- Generate histogram of primary science results =head2 USAGE c_hist [-a #] [-b #] [-h] [-l] [-v] [file_name] =head2 FLAGS -a # specifies the lowest channel of interest -b # specifies the highest channel of interest -h gets full help message -l reports results log-base-10 -v makes the output verbose (to STDERR) =head2 DESCRIPTION We generate a tab-separated histogram of science data in the format Channel D1 D2 D3 D4 D5 D6 The lower and upper bounds of the channels of interest may be chosen with the B<-a> and B<-b> flags, respectively. The output may be either linear or logrithmic and is sent to STDOUT. (NB c_graph assumes a linear scale on its input.) The input file must be in LRO-standard CCSDS packet format. B is used to retrieve the data, so the file may be either normal or compressed. If no input file is provided, the program will read from STDIN, assuming a format compatible with the output of an B process. =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, c_graph =head2 AUTHOR Bob Goeke =head2 RCS Information $Id: c_hist,v 2.1 2007/05/04 13:47:26 goeke Exp goeke $ =cut ######################################################################## # history follows ######################################################################## # $Log: c_hist,v $ # Revision 2.1 2007/05/04 13:47:26 goeke # Name change and associated POD updates # # Revision 1.4 2007/04/26 19:54:10 goeke # Enable reading data on STDIN # # 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 #