#! /bin/sh # This is the LHEA perl script: /cvmfs/extras-fp7.egi.eu/extras/heasoft/swift/x86_64-unknown-linux-gnu-libc2.19-0/bin/batglobalgti # 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/swift/x86_64-unknown-linux-gnu-libc2.19-0/bin/batglobalgti." 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/swift/x86_64-unknown-linux-gnu-libc2.19-0/bin/batglobalgti." 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! #------------------------------------------------------------------------------- #!/usr/bin/perl # # File: batglobalgti # # Description: Retrieve global good/bad science times # # Author: Craig Markwardt # Date: 2006-09-19 # # # Algorithm: # # The BAT global good/bad time gti file is retrieved, usually from # CALDB. This file is scanned for the user's desired QUALITY # filter. # use HEACORE::HEAINIT; my $taskname = "batglobalgti"; my $taskvers = "1.3"; # ================================================================== # Call the main task subroutine with an exception handler $status = 0; eval { $status = headas_main(\&batglobalgti); }; # =================================== # Check for errors and report them to the console if ($@) { if ($status == 0) { $status = -1; } warn $@; exit $status; } exit 0; # =================================== # Main subroutine sub batglobalgti { # Makes all environment variables available use Env; use Cwd; # The HEAUTILS module provides access to HDpar_stamp() # set_toolname(), set_toolversion(), and headas_clobberfile() use HEACORE::HEAUTILS; use HEACORE::PIL; # include the file specification functions use Astro::FITS::CFITSIO qw( :shortnames :constants ); # Use the standard HEAdas methods for registering the toolname and version number to be # used in error reporting and in the record of parameter values written by HDpar_stamp set_toolname($taskname); set_toolversion($taskvers); eval { $status = &batglobalgti_work(); }; if ($@) { if ($status == 0) { $status = -1; } warn $@; return $status; } return $status; } # ================================================================== # Main subroutine sub batglobalgti_work { # Makes all environment variables available use Env; use Cwd; # The HEAUTILS module provides access to HDpar_stamp() # set_toolname(), set_toolversion(), and headas_clobberfile() use HEACORE::HEAUTILS; use HEACORE::PIL; # include the file specification functions use Astro::FITS::CFITSIO qw( :shortnames :constants ); # User defined module which contains the Perl-CFITSIO interface functions use SimpleFITS; my ($infile, $outfile, $chatter); ($status = PILGetString('infile', $infile)) == 0 || die "error getting infile parameter"; ($status = PILGetFname('outfile', $outfile)) == 0 || die "error getting outfile parameter"; ($status = PILGetString('expr', $expr)) == 0 || die "error getting expr parameter"; ($status = PILGetBool('clobber', $clobber)) == 0 || die "error getting clobber parameter"; ($status = PILGetInt('chatter', $chatter)) == 0 || die "error getting chatter parameter"; print "$taskname $taskvers\n" if ($chatter >= 1); print "--------------------------------------------------------\n" if ($chatter >= 2); print " Selecting entries with '$expr'\n" if ($chatter >= 2); # Check for CALDB and retrieve if ("$infile" =~ m/CALDB/i) { # XXX NOTE: the hack by assuming "now" as the time $cmd = "quzcif mission=Swift instrument=BAT detector=- filter=- codename=STDGTI ". "date='now' time='00:00:00' expr='-' retrieve='NO' "; print "$cmd\n" if ($chatter >= 5); @result = `$cmd`; die "ERROR: CALDB query failed with error: @result\n" if ($?); $inspec = "$result[0]"; chomp($inspec); # Format is "filename extension" @inlist = split(/ +/,$inspec); $infile = "$inlist[0]"; # Defend against possible remote-CALDB if ("$infile" !~ m/^(http|ftp):/i and not -f "$infile") { die "ERROR: CALDB query failed to find the BAT global GTI file"; } $extno = "$inlist[1]"; } if ($extno eq "") { $extno = "1"; } $file_expr = "$infile"; $file_expr .= "[$extno]" if ($extno); $file_expr .= "[$expr]" if ($expr !~ m/NONE/i); $cmd = "ftcopy infile='$file_expr' outfile='$outfile'"; print "$cmd\n" if ($chatter >= 5); print "clobber=$clobber\n" if ($chatter >= 5); unlink ($outfile) if ($clobber); system($cmd); die "ERROR: could not create '$outfile'" if (! -f "$outfile"); system("ftlist infile='$outfile' option='H' | grep rows") if ($chatter >= 2); print "--------------------------------------------------------\n" if ($chatter >= 2); print "DONE\n" if ($chatter >= 1); return 0; }