#! /usr/bin/perl $version ="1.00"; $date ="2008-12-04"; $author = "kaa"; # This script takes an input response matrix and splits it into an rmf and an # arf under the assumption that the rmf should have each row normalized to unity # Check that we were given the right number of arguments if(@ARGV < 1 || @ARGV > 2 || $ARGV[0] eq "-h") { print "\n usage : split_rsp_to_rmf_arf rootname echo?\n\n"; print "Splits a response matrix file into an rmf and an arf under the\n"; print "assumption that each row of the rmf sums to unity. The filename\n"; print "given should be without the '.rsp' suffix. Output files will be\n"; print "created using this root with '.rmf' and '.arf' suffices.\n\n"; print "$version $author $date\n"; exit(0); } $rootname = $ARGV[0]; $echo = "no"; if ( @ARGV == 2 && $ARGV[1] eq "yes" ) { $echo = "yes"; } $rspfile = $rootname . ".rsp"; $rmffile = $rootname . ".rmf"; $arffile = $rootname . ".arf"; # Create the arf file by calculating the sum of the MATRIX vector column in # the rsp file. $command = "ftcopy 'infile=$rspfile\[MATRIX\]\[col ENERG_LO; ENERG_HI; SPECRESP=SUM\(MATRIX\)\]' outfile=$arffile"; if ( $echo eq "yes" ) { print $command,"\n"; } system($command); # remove the EBOUNDS extension $command = "ftdelhdu infile=$arffile\[EBOUNDS\] outfile=none confirm=YES > /dev/null"; if ( $echo eq "yes" ) { print $command,"\n"; } system($command); # change the name and add keywords for the arf $txtfile = $rootname . ".txt"; open TXTFILE, ">$txtfile"; print TXTFILE "EXTNAME = 'SPECRESP'\n"; print TXTFILE "HDUNAME = 'SPECRESP'\n"; print TXTFILE "HDUCLAS2 = 'SPECRESP'\n"; print TXTFILE "HDUVERS = '1.1.0'\n"; print TXTFILE "-DETCHANS\n"; print TXTFILE "-RMFVERSN\n"; print TXTFILE "-NUMGRP\n"; print TXTFILE "-NUMELT\n"; print TXTFILE "-PHAFILE\n"; print TXTFILE "-LO_THRES\n"; print TXTFILE "-HDUCLAS3\n"; close TXTFILE; $command = "fthedit infile=$arffile\[MATRIX\] keyword=\@$txtfile"; if ( $echo eq "yes" ) { print $command,"\n"; } system($command); # We are now done with the arf so next divide the MATRIX column in the rsp by the arf. First # make the rmf file from the rsp file and copy in the SPECRESP column from the arf. $command = "ftpaste infile='$rspfile\[MATRIX\]' pastefile='$arffile\[SPECRESP\]\[col SPECRESP\]' outfile=$rmffile copyall=YES"; if ( $echo eq "yes" ) { print $command,"\n"; } system($command); # Now divide the MATRIX vector column by the SPECRESP column $tmpfile = $rootname . ".tmp"; $command = "ftcalc infile=$rmffile outfile=$tmpfile column=MATRIX expression='SUM(MATRIX)>0?MATRIX/SPECRESP:0.0'"; if ( $echo eq "yes" ) { print $command,"\n"; } system($command); # and remove the SPECRESP column from the rmf. $command = "ftcopy infile='$tmpfile\[MATRIX\]\[col -SPECRESP\]' outfile=$rmffile clobber=YES"; if ( $echo eq "yes" ) { print $command,"\n"; } system($command); # tidy up the temporary files unlink $txtfile; unlink $tmpfile;