#! /bin/sh # This is the LHEA perl script: /cvmfs/extras-fp7.egi.eu/extras/heasoft/ftools/x86_64-unknown-linux-gnu-libc2.19-0/bin/make_se # The purpose of this special block is to make this script work with # the user's local perl, regardless of where that perl is installed. # The variable LHEAPERL is set by the initialization script to # point to the local perl installation. #------------------------------------------------------------------------------- eval ' if [ "x$LHEAPERL" = x ]; then echo "Please run standard LHEA initialization before attempting to run /cvmfs/extras-fp7.egi.eu/extras/heasoft/ftools/x86_64-unknown-linux-gnu-libc2.19-0/bin/make_se." exit 3 elif [ "$LHEAPERL" = noperl ]; then echo "During LHEA initialization, no acceptable version of Perl was found." echo "Cannot execute script /cvmfs/extras-fp7.egi.eu/extras/heasoft/ftools/x86_64-unknown-linux-gnu-libc2.19-0/bin/make_se." exit 3 elif [ `$LHEAPERL -v < /dev/null 2> /dev/null | grep -ic "perl"` -eq 0 ]; then echo "LHEAPERL variable does not point to a usable perl." exit 3 else # Force Perl into 32-bit mode (to match the binaries) if necessary: if [ "x$HD_BUILD_ARCH_32_BIT" = xyes ]; then if [ `$LHEAPERL -V 2> /dev/null | grep -ic "USE_64_BIT"` -ne 0 ]; then VERSIONER_PERL_PREFER_32_BIT=yes export VERSIONER_PERL_PREFER_32_BIT fi fi exec $LHEAPERL -x $0 ${1+"$@"} fi ' if(0); # Do not delete anything above this comment from an installed LHEA script! #------------------------------------------------------------------------------- #! /usr1/local/bin/perl # # MAKE_SE # # XTE Data Analysis script, to take a list of GoodXenon files or # Transparent Mode files, check them, and divide them into appropriate # groupings to apply the XENON2FITS or TRANS2FITS, as necessary, and # create a series of output XTE/SE files. # # Alan P. Smale Nov/Dec 1995 # XTE GOF, NASA/GSFC # # Version history: # 0.20 (12/1/95): # $Version_number = "0.20"; require "utils.pl"; use Getopt::Std; # #==============================================================# # Startup banner. # print "Starting up MAKE_SE v.".$Version_number." \n\n"; # #==============================================================# # Flag check; read in the options, and provide feedback to user # about each. 'Help' comes first, then the others grouped by # function. # getopts('dhi:lp:'); if (defined $opt_h) { print <make_se.log") || die "Can't create logfile"); $Logging && print LOGFILE "Starting up MAKE_SE v.".$Version_number." \n\n"; if( defined $opt_d ) { $Defaults = 1; $string= " ** Going with preset defaults where applicable.\n"; # &announce($string); print "$string"; $Logging && print LOGFILE $string; } # Go with all defaults except where # overriden by command line. no Q/A if( defined $opt_i ){ print " ** Input filename provided for FITS filelist: $opt_i \n"; -e $opt_i || die " !! Exiting: file $opt_i does not exist.\n"; $inname = $opt_i; } else { unless ( $Defaults ) { print " > Give name of file containing FITS filelist [".$inname."] > "; chop($dummy=); until ($dummy eq '' || -e $dummy) { print " > File not found. Please try again. > "; chop($dummy=); } unless ($dummy eq '') { $inname = $dummy; } } } if( defined $opt_p ){ print " ** Product (output) filename root supplied: ".$opt_p."\n"; $outroot = $opt_p; } else { unless ( $Defaults ) { print " > Give root for product (output) filenames [$outroot] > "; chop($dummy=); unless ($dummy eq '') {$outroot = $dummy;} } } #==============================================================# # Sanity check section, may be either commented out or enhanced # in delivered version. # Creates a string containing the relevant status variables and # prints it to STDOUT, and also to LOGFILE if $Logging is True. # (no ;;;; - extended string) $string = "\n----------------------------------------------------- Input file name: $inname Output file root: $outroot -----------------------------------------------------\n\n"; print $string; $Logging && print LOGFILE $string; #==============================================================# # OK, now we're ready to read in the complete contents of the input # filename list and check and subgroup it. # # We chop the data into $head (i.e. path) and $tail (i.e. filename) # pairs and store them in an associative arrays called $files. # The tails also live in an array called @tail. # # GoodXenon data can come in the following varieties, and should be # combined as noted: # # GoodXenon1_2s + GoodXenon2_2s. # GoodXenon1_16s + GoodXenon2_16s. # # Transparent mode can come in the following varieties, and should be # combined as noted: # # Transparent1_4s + Transparent2_4s + Transparent3_4s # Transparent1_16s + Transparent2_16s + Transparent3_16s # Transparent1_128s + Transparent2_128s + Transparent3_128s # Transparent1_1024s + Transparent2_1024s + Transparent3_1024s # # These data are generally found in files FS37, FS3b, FS3f, FS4f. # However, we need to read the DATAMODE keyword for each file to # tell what type of data we're dealing with. So we do that. If a # datafile is GoodXenon1, we add it to the gx_1 array. GoodXenon2 # goes to the gx_2 array. Likewise for the Transparent mode data # t_1, t_2, t_3. # # We keep all the paths to the individual files in the %files # associative array for later use. We keep the start times of the # individual files in the %times array. open(INFILE,$inname) || die "!! Can't open $inname. \n"; while ( ) { chomp; $longname = $_; $keyword= "DATAMODE"; $word = >KEYWORDS($longname, $keyword); $keyword= "TSTART"; $starttime = >KEYWORDR($longname, $keyword); $slash = rindex($longname, "/"); if($slash != -1) { $head = substr($longname, 0, $slash); } else { $head = ''; } $tail = substr($longname, $slash+1); @tail = (@tail, $tail); $files{$tail} = $head; $times{$tail} = $starttime; print "$tail $starttime $word \n"; $Logging && print LOGFILE "$tail $starttime $word \n"; #----------------------------------------------------------- if ($word =~ /Transparent1/ ) { @t_1 = ( @t_1, $tail ); $t_1{$tail} = $starttime; } elsif ($word =~ /Transparent2/ ) { @t_2 = ( @t_2, $tail ); $t_2{$tail} = $starttime; } elsif ($word =~ /Transparent3/ ) { @t_3 = ( @t_3, $tail ); $t_3{$tail} = $starttime; } elsif ($word =~ /GoodXenon1/ ) { @gx_1 = ( @gx_1, $tail ); $gx_1{$tail} = $starttime; } elsif ($word =~ /GoodXenon2/ ) { @gx_2 = ( @gx_2, $tail ); $gx_2{$tail} = $starttime; } else { print "! This is neither GX nor T - we won't be processing it\n"; } #----------------------------------------------------------- } # How long are these arrays? $gx1 = @gx_1; $gx2 = @gx_2; $t1 = @t_1; $t2 = @t_2; $t3 = @t_3; $tail = @tail; $command_string="\nThere are $tail files in total. GoodXenon1 : $gx1 GoodXenon2 : $gx2 Transparent1 : $t1 Transparent2 : $t2 Transparent3 : $t3 \n\n"; print "$command_string"; $Logging && print LOGFILE "$command_string"; if ( ($gx1 ne $gx2) || ($t1 ne $t2) || ($t1 ne $t3) ) { $command_string="!! Inconsistent dataset - unequal number of input files !! of each type. Please fix this and run me again. \n"; print "$command_string"; $Logging && print LOGFILE "$command_string"; exit; } close(INFILE); # # For each type of data, we make an associative array of # filenames and start times, sort the filenames by start times, # and end up with an array of time-sorted filenames. Got that? # # Sort using the legendary "spacecraft operator" from the Llama Book! @sorted_gx_1 = sort { $gx_1{$a} <=> $gx_1{$b} } keys(%gx_1); @sorted_gx_2 = sort { $gx_2{$a} <=> $gx_2{$b} } keys(%gx_2); @sorted_t_1 = sort { $t_1{$a} <=> $t_1{$b} } keys(%t_1); @sorted_t_2 = sort { $t_2{$a} <=> $t_2{$b} } keys(%t_2); @sorted_t_3 = sort { $t_3{$a} <=> $t_3{$b} } keys(%t_3); #==============================================================# # Optional break point for debugging purposes. # print "Exiting before calling FTOOLS (parameter entry checking only)\n"; # exit; # #==============================================================# # We're now good to go. Let's call some FTOOLS. # # Transparent datamode files first. $nloop = @sorted_t_1; if ($nloop gt 0) { for ($i = 0; $i <= $nloop-1; $i++) { # Stick the little heads on the tails again now. But only if we have # specfied a path along with the file being input. If we haven't # then we just insert the filename read out of the input file. # Rindex returns -1 if / was not found in the input parameter - meaning # that a path wasn't specified - if there wasn't a path specified with the # filename, then it is not necessary to attempt to reconstruct the path # when creating the input files for Xenon2fits or Trans2fits. if($slash != -1) { $in1 = $files{$sorted_t_1[$i]}."/".$sorted_t_1[$i]; $in2 = $files{$sorted_t_2[$i]}."/".$sorted_t_2[$i]; $in3 = $files{$sorted_t_3[$i]}."/".$sorted_t_3[$i]; } else { $in1 = $sorted_t_1[$i]; $in2 = $sorted_t_2[$i]; $in3 = $sorted_t_3[$i]; } $outfile = $outroot."_t".$i; $ip1 = $i + 1; $command_string="\n Calling TRANS2FITS ($ip1) with \n$in1 \n$in2 \n$in3 \n$outfile"; print "\n$command_string\n\n"; $Logging && print LOGFILE "$command_string\n\n"; $command_string='trans2fits trans1="'.$in1.'" trans2="'.$in2.'" trans3="'.$in3.'" outfile="'.$outfile.'" wrtparm=x clobber=Yes mode=h'; print "$command_string\n"; $Logging && print LOGFILE "$command_string\n\n"; @result=&runcom($command_string, "1"); } } # Now GoodXenon datamode files. $nloop = @sorted_gx_1; if ($nloop gt 0) { for ($i = 0; $i <= $nloop-1; $i++) { # Stick the little heads on the tails again now. if($slash != -1){ $in1 = $files{$sorted_gx_1[$i]}."/".$sorted_gx_1[$i]; $in2 = $files{$sorted_gx_2[$i]}."/".$sorted_gx_2[$i]; } else { $in1 = $sorted_gx_1[$i]; $in2 = $sorted_gx_2[$i]; } $outfile = $outroot."_gx".$i; $ip1 = $i + 1; $command_string="Calling XENON2FITS ($ip1) with \n$in1 \n$in2 \n$outfile"; print "\n$command_string\n"; $Logging && print LOGFILE "\n$command_string\n\n"; $command_string='xenon2fits xenon1="'.$in1.'" xenon2="'.$in2.'" outfile="'.$outfile.'" wrtparm=x clobber=Yes mode=h'; print "$command_string\n"; $Logging && print LOGFILE "$command_string\n\n"; @result=&runcom($command_string, "1"); } } # ==================================================================== # Quit tidily. If LOGFILE is open, close it. print "MAKE_SE successfully completed.\n"; $Logging && print LOGFILE "MAKE_SE successfully completed.\n"; $Logging && close(LOGFILE); exit; # End. #==============================================================# # sub GTKEYWORDR (real number keyword) #==============================================================# sub GTKEYWORDR { local($filename, $keyword) = @_; local($starttime) = 0; $command_string='fkeyprint infile="'.$filename.'" keynam="'.$keyword.'" mode=h'; @result=&runcom($command_string); # Now search @result for the string within quotes. foreach $line (@result) { $start = index($line,"="); if ($start gt 0) { $starttime = substr($line, $start+1,30); $end = index($starttime,"/",1); $starttime = substr($starttime, 0, $end); } $start = 0; } $starttime; } # End. #==============================================================# # sub GTKEYWORDS (string keyword) #==============================================================# sub GTKEYWORDS { local($filename, $keyword) = @_; local($word) = 0; $command_string='fkeyprint infile="'.$filename.'" keynam="'.$keyword.'" mode=h'; @result=&runcom($command_string); # Now search @result for the string in quotes. foreach $line (@result) { $start = index($line,"'"); if ($start gt 0) { $word = substr($line, $start+1,20); $end = index($word,"'",1); $word = substr($word, 0, $end); } $start = 0; } $word; } # End.