#!/usr/bin/perl use strict; use warnings; # # Makes and applies GTI file to RGS event files. # # Requirements: # 0) must be in same directory as input event files. # 1) text file which lists the events files to process, one per line # For instance, to remove the section between 1.55e8 and 1.57e8 seconds: # 1.55e8 1.57e8 - # # To include the section between 1.64e8 and 1.68e8 seconds: # 1.64e8 1.68e8 + # my $currDir; chomp ($currDir = `pwd`); my $r1_evt1 = "r1_evt1.fits"; my $r2_evt1 = "r2_evt1.fits"; my $unittype = 'N'; my $count = 0; my $currLine; my @numbers; my $num; my @files; my $file; my $r1_evt ; my $r2_evt ; my $inst; my $process_r1 = 0; my $process_r2 = 0; # Set the environment variables. my @res1; my $baseDir; if ($currDir =~ m/proc/) { @res1 = split(/proc/, $currDir); $baseDir = $res1[0]; } if (-d $baseDir."ODF") { $ENV{SAS_ODFPATH} = $baseDir."ODF"; my $sumsas = glob ($baseDir."ODF/*SUM.SAS"); $ENV{SAS_ODF} = $sumsas; $ENV{SAS_CCF} = $baseDir."ODF/ccf.cif"; } if (-d $baseDir."odf") { $ENV{SAS_ODFPATH} = $baseDir."odf"; my $sumsas = glob ($baseDir."odf/*SUM.SAS"); $ENV{SAS_ODF} = $sumsas; $ENV{SAS_CCF} = $baseDir."odf/ccf.cif"; } # # I assume SAS has been initialized. Continue merrily on. # print "Enter the name of the file with the times to be kept or removed. \n "; chomp (my $times_file= <> ) ; $times_file = $currDir."/".$times_file; print "What spectrum binning should I use? \n"; print "1 = lambda (default; use this if you want to combine the same orders from different RGSes.) \n"; print "2 = beta \n" ; chomp (my $combine_test = <> ); if (($combine_test ne 1) and ($combine_test ne 2)) { print "Not expecting that! Stopping. \n "; exit; } my $spectrumbinning; if ($combine_test eq 1) { $spectrumbinning = 'lambda'; } else { $spectrumbinning = 'beta'; } my $counttimes = 0; my $countlines = 0; my @starttime; my @endtime; my $j=0; my $filtset; if (-e $times_file) { open(TIMES, "<", $times_file); while ($currLine = ) { $countlines ++; @numbers = split (/\s/, $currLine); # count array elements to confirm the correct format and assign to variables if (@numbers != 3) { print "The input file does not have the correct format. \n"; exit; } } close(TIMES); } else { print "Can't find the times file! \n"; exit; } if (! $countlines) { print "Times files is empty.\n"; exit; } # # Make the GTI files and apply the GTI files. # `gtibuild file=$times_file table=gti.fits`; print "Processing... Please wait, this will take a while.\n "; `rgsproc orders='1 2' auxgtitables=gti.fits bkgcorrect=no withmlambdacolumn=yes entrystage=3:filter finalstage=5:fluxing spectrumbinning=$spectrumbinning`; print "Done. \n";