#! /bin/tcsh # NOTE: USER MAY HAVE TO EDIT THIS LINE TO FIND LOCAL tcsh # # UNIVERSITY OF LEICESTER # XMM-Newton EPIC Calibration # # Jenny Carter # jac48@star.le.ac.uk # 2006 # # PURPOSE: # To reduce an event file to include only # those events that fall within a # given separation from a set of coordinates and create # the corresponding exposure maps # # REQUIREMENTS: # The user must have downloaded the Mastertable.txt of # observation details, and the script BGexpmerge. # The user must have an event list from which to select # the relevant events in the same directory as the list # and script mentioned above. # The small python script galcoordstoradec.py is required # if the input coordinates are in galactic coordinates rather # than equatorial coordinates (right ascension and declination). # Therefore the user must have python installed and available # if they are going to use galactic coordinates. # The scripts BGexpmerge, galcoordstoradec.py, the table # Mastertable.txt and the exposure map directory, Exposures # must all be located in the directory specified by the swdir # argument. # # SOFTWARE USED: # XMM-Newton SAS # FTOOLS (various) # Python (in the case of using galactic coordinates) # # PROCEDURES CALLED: # BGexpmerge # galcoordstoradec.py # # # WARNINGS AND ERRORS: # Error - search radius greater than 90 degrees. # Too large, select smaller search radius. # (This is equivalent to 5400 arcmins) # Error - no component background information found. # Select a smaller search radius. # Error - files and directories. Merge script and/or # Master table may not be in the correct directory. # Events file may not be in the correct directory. # Adjust locations accordingly. # Error - coordinate type argument not G or E (g or E also # allowed). # Error - directory contain the auxillart files, e.g. # Mastertable.txt, does not exist. # Error - the Exposures directory does not exist. # Error - the events file does not exist # Error - the Mastertable.txt does not exist, or is not # found in the directory specified. # Error - the script BGexpmerge does not exist, or is not # found in the directory specified. # Error - the select parameter is not C, R or T. # Error - the revolution lower and upper values are out of bounds # Error - the time lower and upper values are out of bounds # # Warning - No relevant background areas found for the search criteria. # Widen search parameters. # # VERSION: # 1.0 200306 - original. # Version for blank sky event files website. JAC # 1.1 190606 - modification # Error message and comments corrected. JAC # 1.2 210606 - modification # Instead of deleting or directly appending # exposure extensions of evemts files, just append # 1.3 070806 - modification. JAC # Comments adapted # 1.4 160707 - modification # Rename from SelectRADec to BGSelector. # Coordinate arguments can be in galactic coordinates # as well as right ascension and declination. New # argument to select coordinate system added # Final exposure filename changed from SelectMerged # to ExposuresSelectedN/V. # 1.5 180707 - modification # Reduced number of input parameters by extracting # instr/filter/mode info from input events using fdump # 1.6 310707 - modification # Adjustments made to helps and headers. # Removal of refill argument in call to script. # Refill type established by fdump on primary header. # 1.7 270907 - modification. # Changes to include time selection and revolution number # section . This involves reordering of input paramters # and reworking of testing loop within the code. # Minor changes made to message outputs and selectedEvents # summary file. Note the master table used has now changed to # incorporate revolution numbers. # 1.8 021007 - modification. # Addition of selection with exposure time and nH. # 101007 - modification. # Some comment changes. # 121007 - modification # Check if user input to nH selection in format using # exponents, e.g. 1e2 # 291007 - modification # MaxDist for coordinate search made integer # 161107 - modification # Check PN files for direction pointing in medium and thin filter # full-frane case # 301107 - modification # Additional flags expression removed from event selection # set version=1.8 # nice +19 cat < 5 ) then echo " ERROR: for select parameter " $sflag " too many arguments:" $#argv "should be 5...exiting" echo " Check parameter select/no. arguments" exit endif if ( $sflag != C && $sflag != R && $sflag != T && $sflag != E && $sflag != N ) then echo " ERROR: select parameter " $sflag " not C, R, T, E or N ...exiting" echo " Check parameter select" exit endif if ( $sflag == C ) then if ($coordType != "G" && $coordType != "g" && $coordType != "E" && $coordType != "e") then echo " ERROR: CoordType " $coordType " not G/g or E/e ...exiting" echo " Check parameter coordType" exit endif set maxDist=`echo $maxDist | awk '{print int($1)}'` endif if ( $sflag == R ) then if ($coord1 < 0 || $coord2 < 0 || $coord1 > $coord2) then echo " ERROR: Revolution numbers out of bounds or ordered wrongly ...exiting" echo " Check parameter revn1 revn2, check order revn1, revn2" exit endif endif if ( $sflag == T ) then if ($coord1 <= 0 || $coord2 <= 0 || $coord1 > $coord2) then echo " ERROR: Time values out of bounds or ordered wrongly ...exiting" echo " Check parameter time1 time2, check order time1, time2" exit endif endif if ( $sflag == E ) then if ($coord1 <= 0 || $coord2 <= 0 || $coord1 > $coord2) then echo " ERROR: Exposure values out of bounds or ordered wrongly ...exiting" echo " Check parameter exp1 exp2, check order exp1, exp2" exit endif endif if ( $sflag == N ) then set c1int=`echo $coord1 | awk '{print int($1)}'` set c2int=`echo $coord2 | awk '{print int($1)}'` # Check exponents set echeck1a=`echo $coord1 | cut -d "E" -f2` set echeck2a=`echo $coord2 | cut -d "E" -f2` set echeck1b=`echo $coord1 | cut -d "e" -f2` set echeck2b=`echo $coord2 | cut -d "e" -f2` set firstc1=`echo $coord1 | cut -d "E" -f1` set firstc2=`echo $coord2 | cut -d "E" -f1` # echo 'Values c1int, c2int: ' $c1int $c2int # echo 'Values firstc1, firstc2: ' $firstc1 $firstc2 # echo 'Echeck 1a, 2a: ' $echeck1a $echeck2a # echo 'Echeck 1b, 2b: ' $echeck1b $echeck2b # exit #echo 'First check ' $c1int $c2int if ( $c1int == 0 && $c2int == 0 ) then set fc1=`echo $coord1 | cut -c1-1` set fc2=`echo $coord2 | cut -c1-1` set fc1a=`echo $coord1 | cut -c2-2` set fc2a=`echo $coord2 | cut -c2-2` #echo "First character 1, 2, 1a, 2a: " $fc1 $fc2 $fc1a $fc2a if ( $fc1 == "-" || $fc2 == "-" ) then echo " ERROR: nH values out of bounds or ordered wrongly ...exiting" echo " Check parameter nH1 nH2 and order nH1, nH2" exit endif if ( $fc1a != "." || $fc2a != "." ) then echo " ERROR: nH values out of bounds or ordered wrongly ...exiting" echo " Check parameter nH1 nH2 and order nH1, nH2" exit endif endif #echo 'Second check' set check=`echo $coord1 $coord2 | awk '{print int($1/$2)}'` if ($check == 1) then echo " ERROR: nH values out of bounds or ordered wrongly ...exiting" echo " Check parameter nH1 nH2 and order nH1, nH2" exit endif # Do check on inputs if ( $c1int == 0 ) set coord1=`echo $coord1 0.000001 | awk '{print ($1+$2)}'` if ( $c2int == 0 ) set coord2=`echo $coord2 0.000002 | awk '{print ($1+$2)}'` set testI=`echo $coord2 $coord1 | awk '{print int($1/$2)}'` #echo 'Third check ' $testI # Add this as if both numbers negative then the cc1/2 check starts if ($c1int < 0 || $c2int < 0 || $c1int > $c2int || $testI == 0) then echo " ERROR: nH values out of bounds or ordered wrongly ...exiting" echo " Check parameter nH1 nH2 and order nH1, nH2" exit endif # If using numbers with exponents convert here if ($c1int >= 10) set coord1=$c1int if ($c2int >= 10) set coord2=$c2int endif # Check directories and files if (! -e $diri) then echo " ERROR: Directory " $diri " does not exist ...exiting" echo " Check directory name with '/' e.g. home/" exit endif if (! -e $basicstring) then echo " ERROR: Directory " $basicstring " does not exist ...exiting" exit endif if (! -e $events) then echo " ERROR: Events file " $events " does not exist ...exiting" exit endif if (! -e $theList) then echo " ERROR: Master list " $theList " does not exist ...exiting" echo " Check that directory name ends with a '/'" exit endif if (! -e $mergeScript) then echo " ERROR: Exposure file merging script " $mergeScript " does not exist ...exiting" exit endif # Write to summary file set selectedEvents=selectedEvents if ( -e $selectedEvents ) rm -f $selectedEvents touch $selectedEvents echo ' Search criteria ' $sflag $coord1 $coord2 >> $selectedEvents echo ' ' >> $selectedEvents echo ' Component observations found ' >> $selectedEvents echo ' Revn., Obsn., RA, Dec, TELAPSE, Instr., Mode, Filter, TSTART, TSTOP, nH ' >> $selectedEvents echo ' ' >> $selectedEvents # Begin calculations if sflag is C if ( $sflag == 'C' ) then set radian=57.2957795 set pi=3.1415926535897931 # Check coordinates are realistic set intC1=`echo $coord1 | awk '{print int($1)}'` set intC2=`echo $coord2 | awk '{print int($1)}'` # Establish coordinate system if ($coordType == 'G' || $coordType == 'g') then echo 'BGSelector: search centre given in galactic coordinates' if ($intC1 > 360) then echo ' ERROR: galactic l coordinates outside of range ...exiting' exit endif if ( $intC2 > 90 || $intC2 < -90 ) then echo ' ERROR: galactic b coordinates outside of range ...exiting' exit endif # Convert to Right Ascension and Declination echo 'BGSelector: Calculations with galactic latitude' if ( -e tempPython) rm -f tempPython set pytfile=$pythdir'galcoordstoradec.py' echo 'BGSelector: conversion script: ' $pytfile python $pytfile $coord1 $coord2 if (! -e tempPython ) then echo ' ERROR: no conversion to ra and dec possible ...exiting' exit endif set ra=`cat tempPython | head -1 | tail -1` set dec=`cat tempPython | head -2 | tail -1` if ( -e tempPython) rm -f tempPython echo 'BGSelector: Right ascension calculated : ' $ra echo 'BGSelector: Declination calculated : ' $dec else # Purely equatorial set ra=$coord1 set dec=$coord2 echo 'BGSelector: Right ascension given : ' $ra echo 'BGSelector: Declination given : ' $dec endif echo 'BGSelector: Coords input : ' $coord1 $coord2 echo 'BGSelector: Coords taken : ' $ra $dec # Check coordinates are realistic set intC1=`echo $coord1 | awk '{print int($1)}'` set intC2=`echo $coord2 | awk '{print int($1)}'` set intMD=`echo $maxDist | awk '{print int($1)}'` if ($intC1 > 360 || $intC1 < 0 ) then echo ' ERROR: coord1 out of range (0 - 360 (ra) degrees) ...exiting' exit endif if ($intC2 > 90 || $intC2 < -90 ) then echo ' ERROR: coord2 out of range (-90 - +90 (dec) degrees) ...exiting' exit endif if ($maxDist < 0) echo 'Max dist less that zero' if ($maxDist < 0 || $maxDist == 0) then echo ' ERROR: search radius negative or zero ...exiting' exit endif # Input position calculation, convert to radians set cosra=`echo $ra $pi 180 | awk '{print cos(($1 * $2)/($3))}'` set sinra=`echo $ra $pi 180 | awk '{print sin(($1 * $2)/($3))}'` set cosdec=`echo $dec $pi 180 | awk '{print cos(($1 * $2)/($3))}'` set sindec=`echo $dec $pi 180 | awk '{print sin(($1 * $2)/($3))}'` # 130306 JAC input now in minutes # Max dist. away in radians set maxDistDegs=`echo $maxDist 60 | awk '{print ($1/($2))}'` echo 'BGSelector: Search radius in degrees : ' $maxDistDegs set maxDistRads=`echo $maxDistDegs $pi 180 | awk '{print (($1 * $2)/($3))}'` set cosmaxDistRads=`echo $maxDistRads | awk '{print cos($1)}'` # Check if maxDist less than 90 degrees/0.5*PI radians set halfpi=`echo $pi 0.5 | awk '{print ($1 * $2)}'` set testDist=`echo $halfpi 1 $maxDistRads | awk '{print (($1+$2)-$3)}'` set testDist2=`echo $halfpi 1 $maxDistRads | awk '{print int(($1+$2)-$3)}'` set testNeg=`echo $testDist2 | awk '{print int($1)}'` #echo $maxDistDegs $maxDistRads $cosmaxDistRads #echo $testDist $testDist2 $testNeg if ( $testDist2 == 0 || $testDist == 1 || $testNeg < 1 ) then # This occurs when the max separation given by the user is # too large echo " ERROR: separation argument greater than or equal to 90 degrees / 5400 arcmins...exiting" exit endif endif # Set up counting and total variables set badCount = 0 set nLines=`wc -l $theList | awk '{print $1}'` # totallivetime values and totalontime counts 130706 set totallivetime = 0 set totalliveti01 = 0 set totalliveti02 = 0 set totalliveti03 = 0 set totalliveti04 = 0 set totalliveti05 = 0 set totalliveti06 = 0 set totalliveti07 = 0 set totalliveti08 = 0 set totalliveti09 = 0 set totalliveti10 = 0 set totalliveti11 = 0 set totalliveti12 = 0 set totalontime = 0 set totalontime01 = 0 set totalontime02 = 0 set totalontime03 = 0 set totalontime04 = 0 set totalontime05 = 0 set totalontime06 = 0 set totalontime07 = 0 set totalontime08 = 0 set totalontime09 = 0 set totalontime10 = 0 set totalontime11 = 0 set totalontime12 = 0 set buildexp="prebuild" if ( -e tempRDWriteexp ) rm -f tempRDWriteexp if ( -e tempRDWriteexpV ) rm -f tempRDWriteexpV if ( -e tempPAIRS ) rm -f tempPAIRS touch tempRDWriteexp touch tempRDWriteexpV touch tempPAIRS # Dump information from events to find instr-filter-mode combo if ( -e tempDump ) rm -f tempDump fdump $events'+0' tempDump 1 1-1 clobber=yes set ref=`grep "XPROC0" < tempDump | head -1` set ref=`echo $ref | cut -d "=" -f3` if ( -e tempR ) rm -f tempR echo $ref > tempR set ref=`grep "REFILL" < tempR | head -1 ` if ( $ref == '' ) then set refill='N' else # echo "BGSelector: Refill string check " $ref set refill='Y' endif if ( -e tempR ) rm -f tempR if ( -e tempDump ) rm -f tempDump fdump $events'+1' tempDump 1 1-1 clobber=yes set instr=`grep "INSTRUME" < tempDump | head -1 | awk '{print $2}'` set instr=`echo $instr | cut -d "'" -f2` if ( $instr == 'EPN' ) set instr="PN" if ( $instr == 'EMOS1' ) set instr="M1" if ( $instr == 'EMOS2' ) set instr="M2" set filter=`grep "FILTER " < tempDump | head -1 | awk '{print $3}'` set filter=`echo $filter | cut -d "'" -f2` if ( $filter == 'Thin1' || $filter == 'Thin2') set filter='T' if ( $filter == 'Medium') set filter='M' if ( $filter == 'Thick') set filter='K' set mode=`grep "SUBMODE " < tempDump | head -1 | awk '{print $3}'` set mode=`echo $mode | cut -d "'" -f2` if ( $mode == 'PrimeFullWindow') set mode='FF' if ( $mode == 'PrimeFullWindowExt') set mode='EF' if ( $mode == 'PrimeFullWindowExtended') set mode='EF' echo 'BGSelector: Instr, filter, mode, refill : ' $instr $filter $mode $refill if ( -e tempDump ) rm -f tempDump echo ' ' echo "BGSelector: Checking files under requested conditions" set coincid = 0 set i=0 while ($i != $nLines) @ i = $i + 1 set thisLine=`cat $theList | head -$i | tail -1` # echo $thisLine set thisREVN=`echo $thisLine | cut -d " " -f2` set thisOBS=`echo $thisLine | cut -d " " -f3` set thisEXP=`echo $thisLine | cut -d " " -f4` set thisRA=`echo $thisLine | cut -d " " -f5` set thisDEC=`echo $thisLine | cut -d " " -f6` set thisTELAPSE=`echo $thisLine | cut -d " " -f7` set thisINSTR=`echo $thisLine | cut -d " " -f8` set thisMODE=`echo $thisLine | cut -d " " -f9` set thisFILTER=`echo $thisLine | cut -d " " -f10` set thisTLMIN1=`echo $thisLine | cut -d " " -f11` set thisTLMAX1=`echo $thisLine | cut -d " " -f12` set thisnH=`echo $thisLine | cut -d " " -f13` # echo $instr $mode $filter $thisINSTR $thisMODE $thisFILTER # Do EMOS1 etc. correction here if ( $thisINSTR == 'EMOS1' ) set thisINSTR='M1' if ( $thisINSTR == 'EMOS2' ) set thisINSTR='M2' if ( $thisINSTR == 'EPN' ) set thisINSTR='PN' # If compatible instrument, mode and filter take futher information and do # search if ( $thisINSTR == $instr && $thisMODE == $mode && $thisFILTER == $filter ) then set thisLivetime=`echo $thisLine | cut -d " " -f14` set thisLiveti01=`echo $thisLine | cut -d " " -f15` set thisLiveti02=`echo $thisLine | cut -d " " -f16` set thisLiveti03=`echo $thisLine | cut -d " " -f17` set thisLiveti04=`echo $thisLine | cut -d " " -f18` set thisLiveti05=`echo $thisLine | cut -d " " -f19` set thisLiveti06=`echo $thisLine | cut -d " " -f20` set thisLiveti07=`echo $thisLine | cut -d " " -f21` if ($instr == EPN || $instr == PN || $instr == pn ) then set thisLiveti08=`echo $thisLine | cut -d " " -f22` set thisLiveti09=`echo $thisLine | cut -d " " -f23` set thisLiveti10=`echo $thisLine | cut -d " " -f24` set thisLiveti11=`echo $thisLine | cut -d " " -f25` set thisLiveti12=`echo $thisLine | cut -d " " -f26` set thisontime=`echo $thisLine | cut -d " " -f27` set thisontime01=`echo $thisLine | cut -d " " -f28` set thisontime02=`echo $thisLine | cut -d " " -f29` set thisontime03=`echo $thisLine | cut -d " " -f30` set thisontime04=`echo $thisLine | cut -d " " -f31` set thisontime05=`echo $thisLine | cut -d " " -f32` set thisontime06=`echo $thisLine | cut -d " " -f33` set thisontime07=`echo $thisLine | cut -d " " -f34` set thisontime08=`echo $thisLine | cut -d " " -f35` set thisontime09=`echo $thisLine | cut -d " " -f36` set thisontime10=`echo $thisLine | cut -d " " -f37` set thisontime11=`echo $thisLine | cut -d " " -f38` set thisontime12=`echo $thisLine | cut -d " " -f39` else # 130706 adjustment for ontime - currently not included in MasterTable set thisontime=`echo $thisLine | cut -d " " -f22` set thisontime01=`echo $thisLine | cut -d " " -f23` set thisontime02=`echo $thisLine | cut -d " " -f24` set thisontime03=`echo $thisLine | cut -d " " -f25` set thisontime04=`echo $thisLine | cut -d " " -f26` set thisontime05=`echo $thisLine | cut -d " " -f27` set thisontime06=`echo $thisLine | cut -d " " -f28` set thisontime07=`echo $thisLine | cut -d " " -f29` endif set testpast = 'N' # Do testing if ( $sflag == 'C' ) then # Coordinate testing set thisRARads=`echo $thisRA $pi 180 | awk '{print (($1*$2)/$3)}'` set thisDECRads=`echo $thisDEC $pi 180 | awk '{print (($1*$2)/$3)}'` set cosra2=`echo $thisRA $pi 180 | awk '{print cos(($1*$2)/$3)}'` set sinra2=`echo $thisRA $radian | awk '{print sin($1/$2)}'` set cosdec2=`echo $thisDEC $radian | awk '{print cos($1/$2)}'` set sindec2=`echo $thisDEC $radian | awk '{print sin($1/$2)}'` set t1 = `echo $cosra $cosdec $cosra2 $cosdec2 | awk '{print $1*$2*$3*$4}'` set t2 = `echo $sinra $cosdec $sinra2 $cosdec2 | awk '{print $1*$2*$3*$4}'` set t3 = `echo $sindec $sindec2 | awk '{print $1*$2}'` set cosd = `echo $t1 $t2 $t3 | awk '{print $1+$2+$3}'` set test = `echo $cosd $cosmaxDistRads | awk ' {print int($2-$1)}'` set testNeg = `echo $cosd | awk ' {print int($1)}'` set testGreaterBasic = `echo $cosd $cosmaxDistRads 1 | awk ' {print (($2 + $3) -$1)}'` set testGreater = `echo $cosd $cosmaxDistRads 1 | awk ' {print int(($2 + $3) -$1)}'` # echo "Test cosd cosmaxDistRads testNeg testGreater: " $cosd $cosmaxDistRads $testNeg $testGreater if ( $testNeg >= 0 && $testGreater == 0 ) set testpast = 'Y' endif if ( $sflag == 'R' ) then if ( $thisREVN >= $coord1 && $thisREVN <= $coord2 ) set testpast = 'Y' endif if ( $sflag == 'T' ) then # Convert times to numbers set firstv=`echo $thisTLMIN1 | cut -d "." -f1` set decm=`echo $thisTLMIN1 | cut -d "." -f2` set decm=`echo $decm | cut -d "E" -f1` set exponent=`echo $thisTLMIN1 | cut -d "E" -f2` set exponent=`echo $exponent | cut -c3-3` set tdecm=`echo $decm | cut -c1-$exponent` set tlmin1_w=$firstv$tdecm set firstv=`echo $thisTLMAX1 | cut -d "." -f1` set decm=`echo $thisTLMAX1 | cut -d "." -f2` set decm=`echo $decm | cut -d "E" -f1` set exponent=`echo $thisTLMAX1 | cut -d "E" -f2` set exponent=`echo $exponent | cut -c3-3` set tdecm=`echo $decm | cut -c1-$exponent` set tlmax1_w=$firstv$tdecm if ( $tlmin1_w >= $coord1 && $tlmax1_w <= $coord2 ) set testpast = 'Y' endif if ( $sflag == 'E' ) then # Convert exposures to numbers set firstv=`echo $thisTELAPSE | cut -d "." -f1` set decm=`echo $thisTELAPSE | cut -d "." -f2` set decm=`echo $decm | cut -d "E" -f1` set exponent=`echo $thisTELAPSE | cut -d "E" -f2` set exponent=`echo $exponent | cut -c3-3` set tdecm=`echo $decm | cut -c1-$exponent` set telapse_n=$firstv$tdecm # echo 'This telapse: ' $thisTELAPSE ' as exposure in seconds: ' $telapse_n if ( $telapse_n >= $coord1 && $telapse_n <= $coord2 ) set testpast = 'Y' endif if ( $sflag == 'N' ) then set firstv=`echo $thisnH | cut -d "." -f1` set decm=`echo $thisnH | cut -d "." -f2` set decm=`echo $decm | cut -d "E" -f1` set exponent=`echo $thisnH | cut -d "E" -f2` set exponent=`echo $exponent | cut -c2-3` set diffe=`echo $exponent 20 | awk '{print $1-$2}'` if ($diffe == 0) then # Then just take first three numbers set thisnH_n=`echo $thisnH | cut -c1-4` endif if ($diffe > 0) then set extras=`echo $decm | cut -c1-$diffe` set diffe1=`echo $diffe 1 | awk '{print $1+$2}'` if ($diffe1 <= 2 ) then set endvalues=`echo $decm | cut -c$diffe1-2` else set endvalues='0' endif set thisnH_n=$firstv$extras'.'$endvalues endif if ($diffe < 0) then if ($diffe == -1 ) set zeros='' if ($diffe == -2 ) set zeros='0' if ($diffe == -3 ) set zeros='0' set extras=$decm set thisnH_n='0'.$zeros$firstv$extras #echo 'Original number nH : ' $thisnH ' and as exponent expanded: ' $thisnH_n #exit endif set test1=`echo $thisnH_n $coord1 | awk '{print int($1/$2)}'` set test2=`echo $thisnH_n $coord2 | awk '{print int($1/$2)}'` #echo 'This nH: ' $thisnH ' as number x10^20: ' $thisnH_n $coord1 $coord2 $test1 $test2 if ( $test1 > 0 && $test2 == 0 ) then #echo 'Passed with, this nH: ' $thisnH ' as number x10^20: ' $thisnH_n $coord1 $coord2 $test1 $test2 set testpast = 'Y' endif #exit endif if ( $testpast == 'Y' ) then # Within separation then take values and write to file set coincid = `echo $coincid 1 | awk '{print ($1 + $2)}'` if ( $sflag == 'C' ) echo " Requested specifications found within range at ra, dec: " $thisRA $thisDEC if ( $sflag == 'R' ) echo " Requested specifications found within range at revn: " $thisREVN if ( $sflag == 'T' ) echo " Requested specifications found within range at times: " $thisTLMIN1 $thisTLMAX1 if ( $sflag == 'E' ) echo " Requested specifications found within range at exposure: " $thisTELAPSE if ( $sflag == 'N' ) echo " Requested specifications found within range at nH: " $thisnH echo $thisREVN $thisOBS $thisRA $thisDEC $thisTELAPSE $thisINSTR $thisMODE $thisFILTER $thisTLMIN1 $thisTLMAX1 $thisnH >> $selectedEvents if ($refill == Y || $refill == y) then echo $basicstring"P"$thisOBS$instr$thisEXP"BGEXMNR000.FIT" >> tempRDWriteexp # This may change to refer to another of the master obs attributes that refer to an index in the set of files # For example $dir"file"$index"BGEXMVR000.FIT" >> tempRDWriteexpV echo $basicstring"P"$thisOBS$instr$thisEXP"BGEXMVR000.FIT" >> tempRDWriteexpV else echo $basicstring"P"$thisOBS$instr$thisEXP"BGEXMNU000.FIT" >> tempRDWriteexp echo $basicstring"P"$thisOBS$instr$thisEXP"BGEXMVU000.FIT" >> tempRDWriteexpV endif echo $thisTLMIN1 $thisTLMAX1 >> tempPAIRS # Print out all this information to a subset file to be used to extract events # or/and sum up livetime value and liveti0n values set totallivetime = `echo $totallivetime $thisLivetime | awk '{print ($1 + $2)}'` set totalliveti01 = `echo $totalliveti01 $thisLiveti01 | awk '{print ($1 + $2)}'` set totalliveti02 = `echo $totalliveti02 $thisLiveti02 | awk '{print ($1 + $2)}'` set totalliveti03 = `echo $totalliveti03 $thisLiveti03 | awk '{print ($1 + $2)}'` set totalliveti04 = `echo $totalliveti04 $thisLiveti04 | awk '{print ($1 + $2)}'` set totalliveti05 = `echo $totalliveti05 $thisLiveti05 | awk '{print ($1 + $2)}'` set totalliveti06 = `echo $totalliveti06 $thisLiveti06 | awk '{print ($1 + $2)}'` set totalliveti07 = `echo $totalliveti07 $thisLiveti07 | awk '{print ($1 + $2)}'` # 130706 totalontime calculations - currently not included in Master table set totalontime = `echo $totalontime $thisontime | awk '{print ($1 + $2)}'` set totalontime01 = `echo $totalontime $thisontime01 | awk '{print ($1 + $2)}'` set totalontime02 = `echo $totalontime $thisontime02 | awk '{print ($1 + $2)}'` set totalontime03 = `echo $totalontime $thisontime03 | awk '{print ($1 + $2)}'` set totalontime04 = `echo $totalontime $thisontime04 | awk '{print ($1 + $2)}'` set totalontime05 = `echo $totalontime $thisontime05 | awk '{print ($1 + $2)}'` set totalontime06 = `echo $totalontime $thisontime06 | awk '{print ($1 + $2)}'` set totalontime07 = `echo $totalontime $thisontime07 | awk '{print ($1 + $2)}'` #echo 'Check ontime for this obs: ' $thisontime #echo 'Check sequential ontime addition total: ' $totalontime if ($instr == EPN || $instr == PN || $instr == pn ) then set totalliveti08 = `echo $totalliveti07 $thisLiveti08 | awk '{print ($1 + $2)}'` set totalliveti09 = `echo $totalliveti07 $thisLiveti09 | awk '{print ($1 + $2)}'` set totalliveti10 = `echo $totalliveti07 $thisLiveti10 | awk '{print ($1 + $2)}'` set totalliveti11 = `echo $totalliveti07 $thisLiveti11 | awk '{print ($1 + $2)}'` set totalliveti12 = `echo $totalliveti07 $thisLiveti12 | awk '{print ($1 + $2)}'` set totalontime08 = `echo $totalontime $thisontime08 | awk '{print ($1 + $2)}'` set totalontime09 = `echo $totalontime $thisontime09 | awk '{print ($1 + $2)}'` set totalontime10 = `echo $totalontime $thisontime10 | awk '{print ($1 + $2)}'` set totalontime11 = `echo $totalontime $thisontime11 | awk '{print ($1 + $2)}'` set totalontime12 = `echo $totalontime $thisontime12 | awk '{print ($1 + $2)}'` endif else # Count unsuccessful tests set badCount = `echo $badCount 1 | awk '{print ($1 + $2)}'` endif endif end # Add other details to selectedEvents summary file echo " " >> $selectedEvents echo " Totals found " >> $selectedEvents echo " " >> $selectedEvents echo " No. files :" $coincid >> $selectedEvents # echo " Totalontime : " $totalontime >> $selectedEvents echo " Totallivetime: " $totallivetime >> $selectedEvents echo "BGSelector: Number of coincidence files is: " $coincid " out of: " $nLines " (all instr, mode, filter) with total livetime: " $totallivetime if ($instr == EPN || $instr == PN || $instr == pn ) then echo "BGSelector: coincidence files maybe in centre/anti-centre direction, checking event files" endif if ($coincid == 0) then # Clear up rm -f tempPAIRS rm -f tempRDWriteexp rm -f tempRDWriteexpV if ( -e tempGTI ) rm -f tempGTI if ( -e tempGTIfits ) rm -f tempGTIfits # Exit out of program if no components to the search area are found echo "WARNING: No relevant background areas found for your search specifications" echo " No output will be returned from this run" if ( $sflag == 'C' ) echo " Please widen the search radius, or choose different RA and declination values" if ( $sflag == 'R' ) echo " Please widen the revolution number lower and higher values" if ( $sflag == 'T' ) echo " Please extend the time lower and higher values" echo " See the advice given with this script or on the Blank Sky web pages" echo " Script exiting ..." exit endif # Write type file for gti file, create GTI file if ( -e tempGTI ) rm -f tempGTI if ( -e tempGTIfits ) rm -f tempGTIfits touch tempGTI echo "START D" >> tempGTI echo "STOP D" >> tempGTI fcreate tempGTI tempPAIRS tempGTIfits fparkey "J.A. Carter" tempGTIfits+0 CREATOR add=yes fparkey "J.A. Carter" tempGTIfits+1 CREATOR add=yes fparkey "0000:00:00T00:00:00.0" tempGTIfits+0 DATE add=yes fparkey "0000:00:00T00:00:00.0" tempGTIfits+1 DATE add=yes ##### Event file selection of events ############ echo "BGSelector: creating event file " echo "BGSelector: Select appropriate events from event list: " #exit if ( -e tempEvents ) rm -f tempEvents if ($instr == EPN || $instr == PN || $instr == pn ) then echo "BGSelector: PN file select events" # -w 0 -v 0 evselect -w 0 -V 0 table=$events withfilteredset=Y filteredset=tempEvents \ destruct=Y keepfilteroutput=T expression='gti(tempGTIfits,TIME)' else echo "BGSelector: MOS file select events" evselect -w 0 -V 0 table=$events withfilteredset=Y filteredset=tempEvents \ destruct=Y keepfilteroutput=T expression='gti(tempGTIfits,TIME)' endif # Save temporary events file to final file as specified by the user set outevents='EventsSelected.FIT' mv -f tempEvents $outevents ####### Exit and clean if no tempEvents file created ####### if ( -e checkRows ) rm -f checkRows touch checkRows fkeyprint $outevents+1 NAXIS2 >> checkRows set erows=`grep "=" < checkRows | head -1 | awk '{print $3}'` echo 'BGSelector: number of events in new events file: ' $erows if ( -e checkRows ) rm -f checkRows if ( $erows == 0 ) then echo "WARNING: No relevant background areas found for input event file" echo " No output will be returned from this run, delete selectedEvents" echo " For PN case, check input file for galactic centre of anti-centre pointing" echo " Script exiting ..." rm -f ExpIndex ExpIndexV if ( -e tempRDWriteexp ) rm -f tempRDWriteexp if ( -e tempRDWriteexpV ) rm -f tempRDWriteexpV if ( -e tempRDWriteexp ) rm -f tempRDWriteexp if ( -e tempRDWriteexpV ) rm -f tempRDWriteexpV if ( -e tempPAIRS ) rm -f tempPAIRS if ( -e tempFIRST ) rm -f tempFIRST if ( -e tempGTI ) rm -f tempGTI if ( -e tempGTIfits ) rm -f tempGTIfits if ( -e selectedEvents ) rm -f selectedEvents exit endif ######################### Take these observations and merge exposure maps ########################### # Non-vignetted exposure maps if ( -e ExpIndex ) rm -f ExpIndex ls `ls tempRDWriteexp` > ExpIndex set nexL=`wc -l ExpIndex | awk '{print $1}'` #echo 'BGSelector: File count, for exposure maps is: ' $nexL set i=0 while ($i != $nexL) @ i = $i + 1 #echo 'At file in list, or filename: ' $i set thisFile=`cat ExpIndex | head -$i | tail -1` #echo 'Filename now is: ' $thisFile echo 'BGSelector: creating non-vignetted exposure map ' $mergeScript $thisFile $instr $filter $mode 5 # SPECIFIC Script end # Vignetted exposure maps if ( -e ExpIndexV ) rm -f ExpIndexV ls `ls tempRDWriteexpV` > ExpIndexV set nexL=`wc -w ExpIndex | awk '{print $1}'` #echo 'BGSelector: File count, for exposure maps is: ' $nexL set i=0 while ($i != $nexL) @ i = $i + 1 #echo 'At file in list, or filename: ' $i set thisFile=`cat ExpIndexV | head -$i | tail -1` #echo 'Filename now is: ' $thisFile echo 'BGSelector: creating vignetted exposure map ' $mergeScript $thisFile $instr $filter $mode 5 Y # SPECIFIC Script end rm -f ExpIndex ExpIndexV if ( -e tempRDWriteexp ) rm -f tempRDWriteexp if ( -e tempRDWriteexpV ) rm -f tempRDWriteexpV if ( -e tempRDWriteexp ) rm -f tempRDWriteexp if ( -e tempRDWriteexpV ) rm -f tempRDWriteexpV if ( -e tempPAIRS ) rm -f tempPAIRS if ( -e tempFIRST ) rm -f tempFIRST if ( -e tempGTI ) rm -f tempGTI if ( -e tempGTIfits ) rm -f tempGTIfits echo 'BGSelector: task completed' exit