#! /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/sachip # 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/sachip." 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/sachip." 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 # # SACHIP # # XTE Data Analysis script, to run SAEXTRCT with filters, and supply # the user the option of plotting/saving the results using FPLOT # etc, hiding the temporary files, reducing the available options # to the useful few, and cleaning up afterwards. # # Alan P. Smale 9/25/95 # XTE GOF, NASA/GSFC # # Version history: # 0.1 (09/25/95): basic Perl functionality test shell. # 0.2 (early Oct): Getopts, plotting installed. First int.release # 0.21 (late Oct): Time/ch filters, logging, full Q/A added. # $Version_number = "0.21"; require "utils.pl"; use Getopt::Std; # #==============================================================# # Startup banner. # print "Starting up SACHIP 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('b:c:dghi:lmop:s:t:'); if (defined $opt_h) { print <sachip.log") || die "Can't create logfile"); $Logging && print LOGFILE "Starting up SACHIP 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;} } } $inname = "@".$inname; 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;} } } if( defined $opt_g ){ print " ** Columns = GOOD (the unalterable default) \n"; } if( defined $opt_b ){ $binsize = $opt_b; print " ** Binsize = $binsize \n"; } else { unless ( $Defaults ) { print " > Give binsize (in sec) for output light curve [$binsize] > "; chop($dummy=); unless ($dummy eq '') {$binsize = $dummy;} } } if( defined $opt_c ){ print " ** Channel filter info provided: $opt_c.\n"; $dummy=$opt_c; if ( &CHECK_RANGE($dummy) ) { $channels=$opt_c; } else { print " > Invalid channel range supplied: try again [$channels] > "; chop($dummy=); until( &CHECK_RANGE($dummy) || $dummy eq '') { print " > Invalid range: try again [$channels] > "; chop($dummy=); } unless ($dummy eq '') {$channels= $dummy;} } } else { unless ( $Defaults ) { print " > Give channel bounds [$channels] > "; chop($dummy=); until( &CHECK_RANGE($dummy) || $dummy eq '') { print " > Invalid range: try again [$channels] > "; chop($dummy=); } unless ($dummy eq '') {$channels= $dummy;} } } if( defined $opt_t ){ print " ** Time filter info provided: $opt_t.\n"; $dummy=$opt_t; if ( &CHECK_RANGE($dummy) ) { $times=$opt_t; } else {print " > Invalid time range supplied: try again [$times] > "; chop($dummy=); until( &CHECK_RANGE($dummy) || $dummy eq '') { print " > Invalid range: try again [$times] > "; chop($dummy=); } unless ($dummy eq '') {$times= $dummy;} } } else { unless ( $Defaults ) { print " > Give time ranges [$times] > "; chop($dummy=); until( &CHECK_RANGE($dummy) || $dummy eq '') { print " > Invalid range: try again [$times] > "; chop($dummy=); } unless ($dummy eq '') {$times= $dummy;} } } # If no channel selection has occurred, set default to INDEF. Do same # for time selection. (We didn't do this earlier because many users # won't understand a default of INDEF showing up in their prompt.) if ($channels eq "-") {$channels="INDEF"} if ($times eq "-") {$times="INDEF"} if( defined $opt_o && defined $opt_m ){ die " !! Fatal error: you have selected both one AND many !! Please supply EITHER -o OR -m, but not both\n\n"; } # Can't do both, dude. if( defined $opt_m ){ $accumulate="MANY"; print " ** MANY option selected\n"; } elsif ( defined $opt_o ){ $accumulate="ONE"; print " ** ONE option selected\n"; } else { unless ( $Defaults ) { print " > Give ONE or MANY for output curves/spectra [$accumulate] > "; chop($dummy=); $dummy=~ tr/a-z/A-Z/; # Uppercase it all until ($dummy eq '' || $dummy eq "MANY" || $dummy eq "ONE") { print " > Enter ONE or MANY, or ... > "; chop($dummy=); } unless($dummy eq '') {$accumulate = $dummy;} } } if( defined $opt_s ){ $device = $opt_s; print " ** Device = $device \n"; } else { unless ( $Defaults ) { print " > Give device to plot the output curve/spectrum to [$device] > "; chop($dummy=); unless ($dummy eq '') {$device = $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 = "----------------------------------------------------- Input file name: $inname Output file root: $outroot Binsize: $binsize Accumulate: $accumulate Channel filter: $channels Time filter: $times Device: $device -----------------------------------------------------\n"; print $string; $Logging && print LOGFILE $string; # print "Exiting before calling FTOOLS (parameter entry checking only)\n"; # exit; # #==============================================================# # We're now good to go. # # First, run SAEXTRCT. The command_string goes to the screen, # into the log, if set, and to the &yakker executer. # # Then, call FPLOT in a subroutine twice, # first for the light curve and then for the spectrum. print "\n Firing up SAEXTRCT now. Please wait; you won't see anything further until it has completed its accumulation ... \n\n"; $command_string='saextrct infile="'.$inname.'" outroot="'.$outroot.'" accumulate="'.$accumulate.'" columns="'.$columns.'" binsz="'.$binsize.'" printmode=BOTH lcmode=RATE spmode=SUM chint="'.$channels.'" timeint="'.$times.'" mode=h'; print "$command_string\n"; $Logging && print LOGFILE "$command_string\n"; @result=&yakker($command_string, "1"); # # Get the plot device from the environment variable XTEPLOT, if # set. If not, default to /xterm and tell the user what you're doing. # Nope, this is not multiplatform enough, so comment this out and # use a system call instead in CALL_FPLOT # # $device = $ENV{'XTEPLOT'}; # # while ( $device eq '') { # print "XTEPLOT environment variable not set -- use 'setenv XTEPLOT /xterm' # (or equivalent for your system). In the meantime, please supply a # plotting device at the prompt > "; # chop($device=); # } # # Call FPLOT. # &CALL_FPLOT($outroot, ".lc", $device); if ($accumulate eq "MANY") { print "** Warning: since you chose the MANY option, this plot \n"; print "** will contain several spectra which may overwrite. \n"; } &CALL_FPLOT($outroot, ".pha", $device); # ==================================================================== # Quit tidily. If LOGFILE is open, close it. $Logging && close(LOGFILE); exit; # ==================================================================== # sub CALL_FPLOT # ==================================================================== sub CALL_FPLOT { local($fname,$type,$dev) = @_; local($xparm,$yparm,$stringy); # Now: # if $type is ".lc", we're looking at a light curve and # xparm=TIME, yparm=RATE[ERROR] # elsif $type is ".pha", it's a spectrum and # xparm=CHANNEL, yparm= COUNTS[STAT_ERROR] # else the parameter has not been passed correctly and # it's time to die. if ($type eq ".lc") { $xparm = "TIME"; $yparm = "RATE[ERROR]"} elsif ($type eq ".pha") {$xparm = "CHANNEL"; $yparm="COUNTS[STAT_ERR]"} else { die "!! $type not recognized in CALL_FPLOT"} $stringy = 'fplot infile="'.$fname.$type.'" xparm="'.$xparm.'" yparm="'.$yparm.'" device="'.$dev.'" mode=h'; print "\n\n Plotting file $fname$type |------------------------------------------------------------------| | Type 'q' to quit, 'r x low high' to rescale X-axis between given | | values for low/high bounds, or any other QDP command. | |------------------------------------------------------------------|\n"; @result = system($stringy); } # ==================================================================== # sub CHECK_RANGE # ==================================================================== # S/R to (eventually) check that a supplied range is valid. # # The requirement for a range to be valid is that it consists of a # string with pairs of numbers linked by hyphens and delimited by # commas. Thus, if we break the line into an array of strings, one # for each range, and then break each of those into two numbers, # and each is a valid number and contains no letters or other # bizarreness, that's Test 1 complete. # # The status of the test is carried in $status; this is initially # set to 1 (true) but is reset to 0 (false) if an irregularity is # discovered. $status is then returned at the end of CHECK_RANGE. sub CHECK_RANGE { local($range) = @_; local(@ranges, @subranges); local($status, $a, $b, $c, $d, $e); $status=1; @ranges = split(/,/,$range); $a = @ranges; # print "$a items in ranges array\n"; # print "@ranges\n"; foreach ( @ranges ) { @subranges = (@subranges, split(/-/,$_) ); } $b = @subranges; # print "$b items in subranges array\n"; # print " @subranges\n"; # # Odd or even? $b must be divisible by 2. # $d = $b/2.0; $e = int($d); # print "$d, $e\n"; if ( ($d - $e) lt 0.01 ) { # number is even, everything is fine } else { print "Error: odd number of range items\n"; $status=0; } # # @subranges should contain nothing that isn't a number or a . # foreach $c ( @subranges ) { # print "In subranges loop $c \n"; if ( $c =~ /[^0-9.]/ ) { print "Error: element $c is not valid\n"; $status=0; } } # Test 2 is to make sure that in each case the lower bound is lower # than the upper bound. All other checking and reordering is done in # SAEXTRCT. This is not done yet. $status; } # ==================================================================== # sub DO_PRINT # ==================================================================== sub DO_PRINT { print @_; $Logging && print LOGFILE @_; }