#! /bin/tcsh -f # This script takes a list of OM fast mode timeseries FITS files and concatenate # them into a single fits file, including a barycentric correction, if wanted # Routine uses the SAS task barycen and FTOOLS routines only # Input files are provided in an ascii list # To run the script requires 5 command line parameters: # (1) the name of an ascii file containing the list of OM per-exposure timeseries # (TIMESR) files to be joined, 1 file per line # (2) the filter to process (V, B, U, UVW1, UVM2, UVW2 or ALL) # (3) the name of an ascii output file that will contain some basic exposure information # (4) the name of the output FITS file to contain the concatenated timeseries # (5) whether to perform barycentric corrections (Y/N). # e.g. # concatenate_OM_fast_timeseries.scr omts.list ALL summary.txt concatenated.fits Y # # Note, for the source of interest, the user needs to identify the files associated # with the fast mode window it is in and the source number within that window. In # files of the form PooooooooooOMSeeeTIMESRwnnn.FIT, w is the window number and nnn # is the source number (oooooooooo and eee being the 10 digit observation ID and # the exposure ID, respectively). However, when there is more than one source in # the fast mode window, the source identifier may not be consistent between exposures # and the user wil need to carefully check which timeseries files relate to their # source (best based on coordinates). # # Users need to set up the following environment variables (only if applying # a barycentric correction), pointing to relevant observation files: # # for bash, e.g. # export SAS_ODF=`pwd`/2201_0670170401_SCX00000SUM.SAS # export SAS_CCFPATH=/ccf/valid # export SAS_CCF=`pwd`/P0670170401OBX000CALIND0000.FTZ # # for csh, e.g. # setenv SAS_ODF `pwd`/2201_0670170401_SCX00000SUM.SAS # setenv SAS_CCFPATH /ccf/valid # setenv SAS_CCF `pwd`/P0670170401OBX000CALIND0000.FTZ # NOTE: SAS_CCF can point to the P*CALIND*.F* file from the pipeline # processed products (from the XSA) or to the (default-named) ccf.cif # file (or user-specified file name) if cifbuild is run as part of a # local processing. # The SAS_ODF variable must point to the *SUM*.SAS file generated locally # by running odfingest. The SAS_CCFPATH should point to where the calibration # (CCF) files are stored # In addition, users need also to define the path to where FTOOL pfiles # are written. This should be done either externally, by defining the PFILES # environment variable, e.g. export PFILES= and using # the option 1 below or by defining the path directly as in option 2. # comment out one or other of these two options. Currently using option 1 set pfilepath=$PFILES # OPTION 1 ## set pfilepath= #e.g. set pfilepath=/home/user1/pfiles/ OPTION 2 # Check arguments if($#argv != 5)then echo " enter" echo " 1) list of timeseries (P*OM*TIMESR*.F*) files to process" echo " 2) Filter to process (V, B, U, UVW1, UVM2, UVW2, WHITE or ALL)" echo " 3) Name of file for output of exposure summary information" echo " 4) Name of output concatenated FITS file " echo " 5) Barycentrically correct data (Y/N) " exit endif set list=$argv[1] set cfilt=$argv[2] set sumfile=$argv[3] set tsout=$argv[4] set baryc=$argv[5] set cfilt = ` echo $cfilt | tr "[a-z]" "[A-Z]" ` # convert to uppercase # rmove any existing files if (-e ${sumfile} )then rm ${sumfile} endif if (-e ${tsout} ) then rm ${tsout} endif if (-e files2merge.list ) then rm files2merge.list endif # header info into summary file echo " file FILTER RA DEC Tstart Tbin" >> ${sumfile} # loop over TIMESR files in the input list @ nfiles = 0 echo " " foreach file (`cat $list`) echo " Processing ${file} " # for each one, extract the filter, observation date and object RA and DEC fkeypar ${file}+1 FILTER set filt=`pget ${pfilepath}/fkeypar.par value | sed -e "s/'//g" ` set len=`echo -n $filt| wc -m` set pfilt="" if ( $len == 1 )then set pfilt=" " endif # get filter and only process if it matches what is requested if ( $filt == $cfilt || $cfilt == "ALL" ) then @ nfiles++ # extract necessary keyword values fkeypar ${file}+1 DATE-OBS set dates=`pget ${pfilepath}/fkeypar.par value | sed -e "s/'//g" ` fkeypar ${file}+1 RA_OBJ set ra=`pget ${pfilepath}/fkeypar.par value` fkeypar ${file}+1 DEC_OBJ set dec=`pget ${pfilepath}/fkeypar.par value` fkeypar ${file}+1 MJDREF set mjdref=`pget ${pfilepath}/fkeypar.par value` fkeypar ${file}+1 TIMEDEL set tbin=`pget ${pfilepath}/fkeypar.par value` fkeypar ${file}+1 TSTART set tstart=`pget ${pfilepath}/fkeypar.par value` fkeypar ${file}+0 EXP_ID set expid=`pget ${pfilepath}/fkeypar.par value | sed -e "s/'//g" ` set obsid=`echo ${expid} | cut -c 1-10` echo "${file} ${pfilt}${filt} ${ra} ${dec} ${tstart} ${tbin}" >> $sumfile # apply barycentric correction if required if (${baryc} == "Y" || ${baryc} == "y") then # as barycen overwrites time column, copy original for safe keeping cp $file ${file}_orig # run barycen barycen table=${file}:RATE #withsrccoordinates=true srcra=${ra} srcdec=${dec} # move processed file to *_bary and copy original back mv ${file} ${file}_bary mv ${file}_orig ${file} set file2proc=${file}_bary set tcol="BMJD" else # use original file if not barycentrically correcting set file2proc=${file} set tcol="MJD" endif # now use ftools to add the BMJD column and the filter column rm temp.fits temp_${expid}.fits fcalc infile=${file2proc} outfile=temp.fits clname=${tcol} expr="${mjdref}+(TIME/86400.0)" #${string} fcalc infile=temp.fits outfile=temp_${expid}.fits clname=filter expr="'${filt}'" tform="4A" echo "temp_${expid}.fits" >> files2merge.list endif end # Now use fmerge to merge the files echo " " echo " Merging files -> ${tsout}" echo " " fmerge infiles=@files2merge.list outfile=${tsout} columns='-' exit