#!/usr/bin/perl use strict; use warnings; # # Repipelines the data assuming default parameter values. # # Requirements: # 0) Must be run from ODF/odf directory. # 1) Assumes that SAS has been initialized. # # Verify we're in the right directory. my @res1; my $baseDir; my $currDir; chomp ($currDir = `pwd`); if ($currDir =~ m/ODF/) { print "In the ODF directory, continuing. \n"; @res1 = split(/ODF/, $currDir); $baseDir = $res1[0]; } if ($currDir =~ m/odf/) { print "In the ODF directory, continuing. \n"; @res1 = split(/odf/, $currDir); $baseDir = $res1[0]; } if ($currDir !~ m/ODF/i) { print "Not in the ODF directory, stopping now. \n"; exit; } # # I assume SAS has been initialized. Continue merrily on. # # Let's get all the information we need at the start. my $specbinchoice; my $lcchoice; my $imagechoice; my $specbin = 'lambda'; my $lcbin = 0 ; my $lcflag = 0; my $imageflag = 0; print "You can process the data in one of these ways: \n"; print "1) with the option to combine 1st order spectra from RGS1 and RGS2 later on, or \n" ; print "2) with the option to combine 1st and 2nd order spectra from one RGS instrument later on. \n"; print "\n"; print "Which would you like? (1/2) "; chomp ($specbinchoice = <> ); if ($specbinchoice eq '2') { $specbin = 'beta'; print "Ok, setting the appropriate parameter value. \n" } if ($specbinchoice eq '1') { print "Ok, setting the appropriate parameter value. \n" } if (($specbinchoice ne '1') and ($specbinchoice ne '2')) { print "I don't know what that means; going with the default value (1). \n" } print "\n"; print "Would you like to make light curves? Y/N: "; chomp ($lcchoice = <>) ; if (($lcchoice eq 'Y') or ($lcchoice eq 'y')) { $lcflag = 1 ; } if (($lcchoice eq 'N') or ($lcchoice eq 'n')) { $lcflag = 0 ; } if (($lcchoice ne 'Y') and ($lcchoice ne 'y') and ($lcchoice ne 'N') and ($lcchoice ne 'n')) { print "I don't know what that means; I will assume it's a no. \n" ; } if ($lcflag eq 1) { print "Please enter the size of the time bins, in seconds, for the light curves.\n "; chomp ($lcbin = <>) ; if (($lcbin =~ m/\D+/) or ($lcbin =~ m/\s/)) { print "I don't know what that means; going with 10s.\n"; $lcbin = 10; } } print "\n"; print "Would you like to make images of PI, XDSP_CORR, and BETA_CORR? Y/N: "; chomp ($imagechoice = <>) ; if (($imagechoice eq 'Y') or ($imagechoice eq 'y')) { $imageflag = 1 ; } if (($imagechoice eq 'N') or ($imagechoice eq 'n')) { $imageflag = 0 ; } if (($imagechoice ne 'Y') and ($imagechoice ne 'y') and ($imagechoice ne 'N') and ($imagechoice ne 'n')) { print "I don't know what that means; assuming it's a no. \n" ; $imageflag = 0 ; } print "\n"; $ENV{SAS_ODF} = $currDir; $ENV{SAS_ODFPATH} = $currDir; print "Making the ccf.cif... \n"; `cifbuild`; $ENV{SAS_CCF} = $currDir.'/ccf.cif'; print "Extending the ODF summary file... \n"; `odfingest`; my $sumsas = glob ("*SUM.SAS"); $ENV{SAS_ODF} = $currDir.'/'.$sumsas; print "$ENV{SAS_ODF}\n"; print "$ENV{SAS_ODFPATH}\n"; print "$ENV{SAS_CCF}\n"; chdir $baseDir; if (! -d $baseDir.'proc') { `mkdir proc`; } chdir $baseDir.'proc'; print "Reprocessing the data.\n"; `rgsproc spectrumbinning=$specbin` ; my $r1_evt1 = glob ("*R1*EVENLI*.FIT"); my $r2_evt1 = glob ("*R2*EVENLI*.FIT"); `cp $r1_evt1 'r1_evt1.fits'`; `cp $r2_evt1 'r2_evt1.fits'`; if ($imageflag eq 1) { print "Making the images. \n" ; if (! -d $baseDir.'proc/image') { `mkdir image`; } chdir $baseDir.'proc/image'; `cp ../r1_evt1.fits .`; `cp ../r2_evt1.fits .`; `evselect table=r1_evt1.fits withimageset=yes imageset=r1_pi_bc_image.fits xcolumn=BETA_CORR ycolumn=PI imagebinning=imageSize ximagesize=600 yimagesize=600`; `evselect table=r2_evt1.fits withimageset=yes imageset=r2_pi_bc_image.fits xcolumn=BETA_CORR ycolumn=PI imagebinning=imageSize ximagesize=600 yimagesize=600`; `evselect table=r1_evt1.fits withimageset=yes imageset=r1_xd_bc_image.fits xcolumn=BETA_CORR ycolumn=XDSP_CORR imagebinning=imageSize ximagesize=600 yimagesize=600`; `evselect table=r2_evt1.fits withimageset=yes imageset=r2_xd_bc_image.fits xcolumn=BETA_CORR ycolumn=XDSP_CORR imagebinning=imageSize ximagesize=600 yimagesize=600`; `rm r1_evt1.fits`; `rm r2_evt1.fits`; } if ($lcflag eq 1) { print "Making light curves. \n" ; chdir $baseDir.'proc'; if (! -d $baseDir.'proc/lightcurve') { `mkdir lightcurve`; } my $r1_srcli = glob ("*R1*SRCLI*.FIT"); my $r2_srcli = glob ("*R2*SRCLI*.FIT"); `cp $r1_srcli 'r1_srcli.fits'`; `cp $r2_srcli 'r2_srcli.fits'`; chdir $baseDir.'proc/lightcurve'; `cp ../r1_evt1.fits .`; `cp ../r2_evt1.fits .`; `cp ../r1_srcli.fits .`; `cp ../r2_srcli.fits .`; `evselect table=r1_evt1.fits withrateset=yes rateset='r1_ltcrv_bin$lcbin.fits' maketimecolumn=yes timebinsize=$lcbin makeratecolumn=yes expression='(CCDNR==9)&&(REGION(r1_srcli.fits:RGS1_BACKGROUND,M_LAMBDA,XDSP_CORR))'`; `evselect table=r2_evt1.fits withrateset=yes rateset='r2_ltcrv_bin$lcbin.fits' maketimecolumn=yes timebinsize=$lcbin makeratecolumn=yes expression='(CCDNR==9)&&(REGION(r2_srcli.fits:RGS2_BACKGROUND,M_LAMBDA,XDSP_CORR))'`; `rm r1_evt1.fits`; `rm r2_evt1.fits`; `rm r1_srcli.fits`; `rm r2_srcli.fits`; chdir $baseDir.'proc'; } chdir $baseDir.'proc'; print "Done. \n";