#! /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/pcaprepfile2 # 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/pcaprepfile2." 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/pcaprepfile2." 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: pcaprepfile2 # # Description: Prepare one PCA Standard2 file for analysis # # Author: C. B. Markwardt # use Getopt::Std; getopts(':h'); if (defined $opt_h) { print < hkfiles_file3.lis # Run on FS4a_file.gz pcaprepfile2 infile=FS4a_file3.gz filterfile=filt_file3.xfl.gz \ hkfiles=\@hkfiles_file3.lis \ bkgfile=FS4a_file3_bkg dtfile=FS4a_file3_DT dtbkgfile=FS4a_file3_DTbkg \ # Outputs are FS4a_file3{_bkg,_DT,_DTbkg} CAVEATS The user is strongly recommended to use an updated RXTE Calibration database (CALDB), and to set breakfile=CALDB, modelfile=CALDB, saahfile=CALDB. The user is strongly recommended to compute the files with dead-time quantities and use those for downstream processing. BUGS Please report problems to xtehelp\@athena.gsfc.nasa.gov. SEE ALSO pcadeadcalc2, pcabackest EOHELP exit; } use HEACORE::HEAINIT; # ================================================================== # Call the main task subroutine with an exception handler $status = 0; $cleanup = 1; @scratchfiles = (); @scratchfiles_badonly = (); eval { $status = headas_main(\&pcaprepfile2); }; # =================================== # Check for errors and report them to the console if ($@) { if ($status == 0) { $status = -1; } warn $@; exit $status; } exit 0; # =================================== # Main subroutine sub pcaprepfile2 { $taskname = "pcaprepfile2"; $taskvers = "1.0"; # 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 = &pcaprepfile2_work(); }; # Special effort to remove scratch files if ($cleanup) { foreach $scratchfile (@scratchfiles) { unlink "$scratchfile"; } # Delete some product files only if we exited with an error if ($@) { foreach $scratchfile (@scratchfiles_badonly) { unlink "$scratchfile"; } } } if ($@) { if ($status == 0) { $status = -1; } warn $@; return $status; } return $status; } # ================================================================== # Working subroutine sub pcaprepfile2_work { # 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 :longnames); # User defined module which contains the Perl-CFITSIO interface functions use SimpleFITS; my ($infile, $outfile, $chatter); my ($fits1, $fits2, $handle1, $handle2); my ($mode, $tddes5); ($status = PILGetFname('infile', $infile)) == 0 || die "error getting infile parameter"; ($status = PILGetFname('bkgfile', $bkgfile)) == 0 || die "error getting bkgfile parameter"; ($status = PILGetFname('dtfile', $dtfile)) == 0 || die "error getting dtfile parameter"; ($status = PILGetFname('dtbkgfile', $dtbkgfile)) == 0 || die "error getting dtbkgfile parameter"; ($status = PILGetString('hkfiles', $hkfile)) == 0 || die "error getting hkfile parameter"; ($status = PILGetString('filterfile', $filterfile)) == 0 || die "error getting filterfile parameter"; ($status = PILGetString('modelfile', $modelfile)) == 0 || die "error getting modelfile parameter"; ($status = PILGetString('breakfile', $breakfile)) == 0 || die "error getting breakfile parameter"; ($status = PILGetString('saahfile', $saahfile)) == 0 || die "error getting saahfile parameter"; ($status = PILGetReal('bkginterval', $bkginterval)) == 0 || die "error getting bkginterval parameter"; ($status = PILGetString('bkglayers', $layers)) == 0 || die "error getting bkglayers parameter"; ($status = PILGetString('bkgfullspec', $fullspec)) == 0 || die "error getting bkgfullspec parameter"; ($status = PILGetString('zero_bad', $zero_bad)) == 0 || die "error getting zero_bad parameter"; ($status = PILGetString('transition_bad', $transition_bad)) == 0 || die "error getting transition_bad parameter"; ($status = PILGetString('propane_bad', $propane_bad)) == 0 || die "error getting propane_bad parameter"; ($status = PILGetBool('clobber', $clobber)) == 0 || die "error getting clobber parameter"; ($status = PILGetBool('cleanup', $cleanup)) == 0 || die "error getting cleanup parameter"; ($status = PILGetInt('chatter', $chatter)) == 0 || die "error getting chatter parameter"; print "Running $taskname v$taskvers\n" if ($chatter >= 1); print "----------------------------------------\n" if ($chatter >= 2); undef $dtfile if ($dtfile =~ m/^none$/i); undef $dtbkgfile if ($dtbkgfile =~ m/^none$/i); undef $breakfile if ($breakfile =~ m/^none$/i); $clobstr = $clobber ? "YES" : "NO"; $cleanstr = $cleanup ? "YES" : "NO"; if (defined($dtbkgfile) && ! defined($dtfile)) { die "ERROR: you must specify dtfile together with dtbkgfile"; } # =================================================== # Create background file &headas_clobberfile($bkgfile); $cmd = "pcabackest infile='$infile' outfile='$bkgfile' ". "modelfile='$modelfile' filterfile='$filterfile' ". "saahfile='$saahfile' ". "modeltype=both interval=$bkginterval propane=NO ". "layers=$layers gaincorr=NO gcorrfile=CALDB ". "fullspec=$fullspec interp=YES syserr=NO maxmodels=2000 timeslop=128 "; print "COMMAND: $cmd\n" if ($chatter >= 5); @cmdlog = `$cmd`; if ($? || ! -f "$bkgfile") { print "@cmdlog"; die "ERROR: could not create '$bkgfile'"; } push @scratchfiles_badonly, "$bkgfile"; # Double-check that pcabackest produced something viable, since # it can crash in mid-stream and leave a malformed turd. $bkgfitsfile = SimpleFITS->open("$bkgfile",ext=>3,access=>"readonly"); die "ERROR: background file was corrupt" if (! $bkgfitsfile ); $bkgfitsfile->setstatus(0)->close(); # =================================================== # Create deadtime correction file if ($dtfile) { headas_clobberfile($dtfile); $cmd = "pcadeadcalc2 infile='$infile' outfile='$dtfile' std2file=NONE ". "hkfiles='$hkfile' breakfile='$breakfile' ". "transition_bad=$transition_bad zero_bad=$zero_bad propane_bad=$propane_bad ". "cleanup='$cleanstr' "; print "COMMAND: $cmd\n" if ($chatter >= 5); @cmdlog = `$cmd`; if ($? || ! -f "$dtfile") { print "@cmdlog"; die "ERROR: could not create '$dtfile'"; } push @scratchfiles_badonly, "$dtfile"; } # =================================================== # Create deadtime-corrected background file if ($dtbkgfile) { headas_clobberfile($dtbkgfile); $cmd = "pcadeadcalc2 infile='$bkgfile' outfile='$dtbkgfile' std2file='$dtfile' ". "hkfiles='$hkfile' breakfile='$breakfile' ". "transition_bad=$transition_bad zero_bad=$zero_bad propane_bad=$propane_bad ". "cleanup='$cleanstr'"; print "COMMAND: $cmd\n" if ($chatter >= 5); @cmdlog = `$cmd`; if ($? || ! -f "$dtbkgfile") { print "@cmdlog"; die "ERROR: could not create '$dtbkgfile'"; } push @scratchfiles_badonly, "$dtbkgfile"; } return $status; }