#! /usr/bin/perl $version ="1.00"; $date ="2002-11-19"; $author = "kaa"; # This script makes the Chandra ACIS rmf and arf. It is run by the xselect # routine xsl_rspsav. # we need CIAO... if($ENV{'ASCDS_BIN'} !~/\S/) { print "\n You need to set up CIAO to calculate this response.\n\n"; exit(0); } # Check that we were given an input filename if(@ARGV != 1) { print "\n usage : xsl_chandra_acis_makeresp infile\n"; exit(0); } $infile = $ARGV[0]; # get the rootname $dot = index($infile,"."); $rootname = substr($infile, 0, $dot); $rmffile = $rootname . ".rmf"; $arffile = $rootname . ".arf"; $wgtfile = $rootname . ".wgt"; # the difficult part of this script is to fix the ardlib parameter file so # that mkwarf and mkrmf can find the bad pixel file for this observation. # first construct the bad pixel filename. fkeypar doesn't work at the moment # with the CONTINUE keyword in the Chandra files so we have to use fkeyprint # which is a pain. $tmpfile = $rootname . ".tmp"; $command = "fkeyprint infile=$infile+0 keynam=BPIXFILE outfile=$tmpfile clobber=yes"; system($command); open(FILE, $tmpfile); while() { if (/^BPIXFILE=\s+(.*)/) { $bpixfile = $1; } elsif (/^CONTINUE\s+(.*)/) { $bpixfile .= $1; } } close(FILE); $command = "rm -f $tmpfile"; system($command); $bpixfile =~ tr/'& //d; $temp = reverse($bpixfile); $temp = substr($temp,0,index($temp,"/")); $bpixfile = reverse($temp); # now need to look around to try to find a copy of this file... $bpixpath = "NONE"; if (-r $bpixfile) { $bpixpath = $bpixfile; } $bpixtest = "primary/" . $bpixfile; if (-r $bpixtest) { $bpixpath = $bpixtest; } $bpixtest = "../primary/" . $bpixfile; if (-r $bpixtest) { $bpixpath = $bpixtest; } $bpixtest = "secondary/" . $bpixfile; if (-r $bpixtest) { $bpixpath = $bpixtest; } $bpixtest = "../secondary/" . $bpixfile; if (-r $bpixtest) { $bpixpath = $bpixtest; } if ($bpixpath eq "NONE") { print "I cannot find a bad pixel file - ardlib not set\n"; } else { $command = "fkeypar $bpixpath DETNAM"; system($command); ($chips = `pget fkeypar value`) =~ tr/A-Z\-'\n//d; @chipno = split(//, $chips); foreach $c (@chipno) { $command = "pset ardlib AXAF_ACIS" . $c . "_BADPIX_FILE = $bpixpath\[BADPIX" . $c . "\]"; system($command); print $command, "\n"; } } # set the name for the WMAP $wmapfile = $infile . "[WMAP]"; # remove the FILTER keyword from the input file because this causes problems with # CALDB access $command = "fkeypar fitsfile='$wmapfile' keyword=FILTER"; system($command); ($exist = `pget fkeypar exist`) =~ tr/\n//d; if ($exist eq "yes") { $command = "fparkey value=junk fitsfile='$wmapfile' keyword=-FILTER"; system($command); } # run mkwarf to make the arf and weighted fef file that mkrmf will need $command = "mkwarf infile='$wmapfile' outfile=$arffile weightfile=$wgtfile spectrumfile=none egridspec=0.3:11:0.01 feffile=CALDB"; print "\n",$command,"\n"; system($command); # run mkrmf to make the rmf $logfile = $rootname . ".log"; $command = "mkrmf infile='CALDB' outfile=$rmffile weights=$wgtfile axis1='energy=0.3:11:0.01' axis2='pi=1:1024:1' logfile=$logfile"; print "\n",$command,"\n"; system($command); $command = "rm -f $logfile $wgtfile"; system($command); # set the RESPFILE and ANCRFILE keywords in the spectrum to point to the # files that have been created $command = "fparkey value=$rmffile fitsfile=$infile\[SPECTRUM\] keyword=RESPFILE"; system($command); $command = "fparkey value=$arffile fitsfile=$infile\[SPECTRUM\] keyword=ANCRFILE"; system($command);