#! /bin/sh # This is the LHEA perl script: /cvmfs/extras-fp7.egi.eu/extras/heasoft/ftools/x86_64-unknown-linux-gnu-libc2.19-0/bin/timetrans # The purpose of this special block is to make this script work with # the user's local perl, regardless of where that perl is installed. # The variable LHEAPERL is set by the initialization script to # point to the local perl installation. #------------------------------------------------------------------------------- eval ' if [ "x$LHEAPERL" = x ]; then echo "Please run standard LHEA initialization before attempting to run /cvmfs/extras-fp7.egi.eu/extras/heasoft/ftools/x86_64-unknown-linux-gnu-libc2.19-0/bin/timetrans." exit 3 elif [ "$LHEAPERL" = noperl ]; then echo "During LHEA initialization, no acceptable version of Perl was found." echo "Cannot execute script /cvmfs/extras-fp7.egi.eu/extras/heasoft/ftools/x86_64-unknown-linux-gnu-libc2.19-0/bin/timetrans." exit 3 elif [ `$LHEAPERL -v < /dev/null 2> /dev/null | grep -ic "perl"` -eq 0 ]; then echo "LHEAPERL variable does not point to a usable perl." exit 3 else # Force Perl into 32-bit mode (to match the binaries) if necessary: if [ "x$HD_BUILD_ARCH_32_BIT" = xyes ]; then if [ `$LHEAPERL -V 2> /dev/null | grep -ic "USE_64_BIT"` -ne 0 ]; then VERSIONER_PERL_PREFER_32_BIT=yes export VERSIONER_PERL_PREFER_32_BIT fi fi exec $LHEAPERL -x $0 ${1+"$@"} fi ' if(0); # Do not delete anything above this comment from an installed LHEA script! #------------------------------------------------------------------------------- #!/usr1/local/bin/perl5 # # This script is designed to take an input light curve file and a # a series or relative time ranges and convert that to a range of # absolute time ranges. This script can be run silently by inputting # a series of flags/switches or run interactively and it will prompt you # for the information that is needed. # # Brian K. Elza 10/31/95 # XTE GSFC/NASA # use Getopt::Std; #============================================================# # # See if there are any flags: # getopts('i:f:t:h'); if (defined $opt_h) { print <); if($infile =~ /^./ ){ chop($infile); } else{ $infile = $infile2[0]; } } # Now we will test to see if the input file is a LIST of files. If it is # then we will copy all of the files contained within this file to a # unique filename if($infile =~ /^@/ ){ $infile =~ s/^@//; # Remove the @ symbol open(INPUT_FILE,"$infile") || die "Sorry can't find $infile\n"; # Open the input file $tmpfile = ; # Copy files from INFILE to OUTPUT chop($tmpfile); -e $tmpfile || die "Cannot find the file $tmpfile !\n"; print "Input file used is $tmpfile\n"; close(INPUT_FILE); # We are finished with the input file. } else { $tmpfile = $infile; if ($infile =~ /\+[0-9]/ ) { $infile =~ s/\+[0-9]//; } elsif ($infile =~ /\[[0-9]\]/ ) { $infile =~ s/\[[0-9]\]//; } else { } -e $infile || die "Cannot find $infile !\n"; } $infile = $tmpfile; if(defined $opt_f) { print "Output filename provided was: $opt_f \n"; $outfile = $opt_f; } else { print "Output filename:[outfile_${$}]"; ($outfile = ); if($outfile =~ /^./ ){ chop($outfile); } else{ $outfile = "outfile_${$}"; } } open(OUTPUT_FILE,">$outfile") || die "Sorry can't open $outfile\n"; # open a unique output file if(defined $opt_t) { print "Relative time ranges are: $opt_t \n"; $intime = $opt_t; } else { print "Input relative time range:[0-250.0, 350.0-500.0, 750.0-1000.0]"; ($intime = ); if($intime =~ /^./ ){ chop($intime); } else{ print "ERROR!!!! No time range specified!!!\n"; print "Nothing to do!... Aborting....\n"; exit; } } # Now we will test to see if the time-range is a LIST of files. If it is # then we will reconstruct the type of input expected. # This is a "shoe-horn" job which has to be inserted in this weird # manner to avoid screwing up pre-written sections of this script... if($intime =~ /^@/ ){ $intime =~ s/^@//; # Remove the @ symbol open(INPUT_FILE,"$intime") || die "Sorry can't find $intime\n"; # Open the input file $i=0; while() { $testtime = $_; # Copy time-ranges from INTIME to TESTTIME chop($testtime); if ( $i == 0 ) { $tmptime = "$testtime"; $i++; } else { $tmptime .= ",$testtime"; $i++; } } close(INPUT_FILE); # We are finished with the input file. print "\nThe time-ranges from the input file are $tmptime\n"; } else { $tmptime = $intime; } print "\n##########################################\n"; # Ok now that we have a filename input lets parse it and see if there are # any ['s or +'s in the filename. If there are, then I will NOT add an # extension, but if there are then I will tack on a +1 to go to the proper # data entension print "\n"; if ($infile =~ /\+[0-9]/ ) { print "We will use the extension specified by +n.\n"; } elsif ($infile =~ /\[[0-9]\]/ ) { print "We will use the extension specified by [n]\n"; } else { print "We will use the first data extension\n"; $infile .= "+1"; } $fkeyprint_stringi = "fkeyprint infile=$infile "; $fkeyprint_stringi .= "keynam='TIMEZERI' outfile=STDOUT "; $fkeyprint_stringi .= "exact=no clobber=no mode=ql "; @resulti=&runcom($fkeyprint_stringi); $length_of_array = @resulti; for($i_count=0; $i_count <= $length_of_array; $i_count++){ if($resulti[$i_count] =~ /^TIMEZERI=/) { @temp_array = split(/=/,$resulti[$i_count]); @temp = split(/ \/ /,$temp_array[1]); $timei = $temp[0]; } } $fkeyprint_stringf = "fkeyprint infile=$infile "; $fkeyprint_stringf .= "keynam='TIMEZERF' outfile=STDOUT "; $fkeyprint_stringf .= "exact=no clobber=no mode=ql "; @resultf=&runcom($fkeyprint_stringf); $length_of_array = @resultf; for($i_count=0; $i_count <= $length_of_array; $i_count++){ if($resultf[$i_count] =~ /^TIMEZERF=/) { @temp_array = split(/=/,$resultf[$i_count]); @temp = split(/ \/ /,$temp_array[1]); $timef = $temp[0]; } } $timezero = $timei + $timef; #--------------------------------------------------------------------- if($timezero == 0.0) { $fkeyprint_stringa = "fkeyprint infile=$infile "; $fkeyprint_stringa .= "keynam='TIMEZERO' outfile=STDOUT "; $fkeyprint_stringa .= "exact=no clobber=no mode=ql "; @resulta=&runcom($fkeyprint_stringa); $length_of_array = @resulta; for($i_count=0; $i_count <= $length_of_array; $i_count++){ if($resulta[$i_count] =~ /^TIMEZERO=/) { @temp_array = split(/=/,$resulta[$i_count]); @temp = split(/ \/ /,$temp_array[1]); $timea = $temp[0]; } } $timezero = $timea; } #---------------------------------------------------------------------- print "TIMEZERI from $infile is $timei \nTIMEZERF from $infile is $timef \n"; print "TIMEZERO from $infile is $timea \n\n"; #print "\nUnfortunately double precision only has 15 significant figures.\n"; #print "So anything after the 15th digit is meaningless.\n"; printf "Offset value TIMEZERO is %17.8f\n\n", $timezero; #---------------------------------------------------------------------- $fkeyprint_stringb = "fkeyprint infile=$infile "; $fkeyprint_stringb .= "keynam='TSTARTI' outfile=STDOUT "; $fkeyprint_stringb .= "exact=no clobber=no mode=ql "; @resultb=&runcom($fkeyprint_stringb); $length_of_array = @resultb; for($i_count=0; $i_count <= $length_of_array; $i_count++){ if($resultb[$i_count] =~ /^TSTARTI/) { @temp_array = split(/=/,$resultb[$i_count]); @temp = split(/ \/ /,$temp_array[1]); $timei = $temp[0]; } } $fkeyprint_stringc = "fkeyprint infile=$infile "; $fkeyprint_stringc .= "keynam='TSTARTF' outfile=STDOUT "; $fkeyprint_stringc .= "exact=no clobber=no mode=ql "; @resultc=&runcom($fkeyprint_stringc); $length_of_array = @resultc; for($i_count=0; $i_count <= $length_of_array; $i_count++){ if($resultc[$i_count] =~ /^TSTARTF/) { @temp_array = split(/=/,$resultc[$i_count]); @temp = split(/ \/ /,$temp_array[1]); $timef = $temp[0]; } } $timestart = $timei + $timef; #--------------------------------------------------------------------- if($timestart == 0.0) { $fkeyprint_stringd = "fkeyprint infile=$infile "; $fkeyprint_stringd .= "keynam='TSTART' outfile=STDOUT "; $fkeyprint_stringd .= "exact=no clobber=no mode=ql "; @resultd=&runcom($fkeyprint_stringd); $length_of_array = @resultd; for($i_count=0; $i_count <= $length_of_array; $i_count++){ if($resultd[$i_count] =~ /^TSTART/) { @temp_array = split(/=/,$resultd[$i_count]); @temp = split(/ \/ /,$temp_array[1]); $timea = $temp[0]; } } $timestart = $timea; } #---------------------------------------------------------------------- print "TSTARTI from $infile is $timei \nTSTARTF from $infile is $timef \n"; print "TSTART from $infile is $timea \n\n"; #print "\nUnfortunately double precision only has 15 significant figures.\n"; #print "So anything after the 15th digit is meaningless.\n"; $fkeyprint_stringj = "fkeyprint infile=$infile "; $fkeyprint_stringj .= "keynam='HDUCLAS1' outfile=STDOUT "; $fkeyprint_stringj .= "exact=no clobber=no mode=ql "; @resultj=&runcom($fkeyprint_stringj); $length_of_array = @resultj; for($i_count=0; $i_count <= $length_of_array; $i_count++){ if($resultj[$i_count] =~ /^HDUCLAS1/) { if($resultj[$i_count] =~ /LIGHTCURVE/){ print "--------------------------------------------------------\n"; print "Since LIGHTCURVE time values may be different in how we have to \nhandle the starting and trailing edge of each light bin we have to do some extra work."; print "Note that the TSTARTI and TSTARTF values account for this shift when \nadded to TIMEZERI and TIMEZERF, but the end times must be corrected.\n"; $fkeyprint_stringk = "fkeyprint infile=$infile "; $fkeyprint_stringk .= "keynam='TIMEDEL' outfile=STDOUT "; $fkeyprint_stringk .= "exact=no clobber=no mode=ql "; @resultk=&runcom($fkeyprint_stringk); $length_of_array2 = @resultk; for($i_count2=0; $i_count2 <= $length_of_array2; $i_count2++){ if($resultk[$i_count2] =~ /^TIMEDEL/) { @temp_array2 = split(/=/,$resultk[$i_count2]); @temp2 = split(/ \/ /,$temp_array2[1]); $timedel = $temp2[0]; print "\nThe bin-size for this light-curve was $timedel\n"; print "--------------------------------------------------------\n\n"; } } $fkeyprint_stringl = "fkeyprint infile=$infile "; $fkeyprint_stringl .= "keynam='TIMEPIXR' outfile=STDOUT "; $fkeyprint_stringl .= "exact=no clobber=no mode=ql "; @resultl=&runcom($fkeyprint_stringl); $length_of_array3 = @resultl; for($i_count3=0; $i_count3 <= $length_of_array3; $i_count3++){ if($resultl[$i_count3] =~ /^TIMEPIXR/) { @temp_array3 = split(/=/,$resultl[$i_count3]); @temp3 = split(/ \/ /,$temp_array3[1]); $timepixr = $temp3[0]; print "\nThe TIMEPIXR value for this light-curve was $timepixr\n"; if($timepixr == 0.0) { print "Timestamps align with leading edge of the time-bin.\n\n"; } if($timepixr == 0.5) { print "Timestamps align with mid-point of the time-bin.\n\n"; } if($timepixr == 1.0) { print "Timestamps align with trailing edge of the time-bin.\n\n"; } # $timedel = $timepixr * $timedel; print "--------------------------------------------------------\n\n"; } } $timestart = $timestart; } } } $timezero = $timezero + $timestart; printf "Total offset value for input time is %17.8f\n\n", $timezero; @time = split(/,/,$tmptime); $itmpt = @time; print "Number of time ranges specified: $itmpt \n"; $itmpt--; for($icount = 0; $icount <= $itmpt; $icount++) { @k = split(/-/,$time[$icount]); $ik = @k; if($ik == 1) { print "\nOnly 1 time value specified in this range!\n"; print "This is not valid for input into TIMEINT, but could be used for TIMEMIN or TIMEMAX.\n"; print "Not writing value to output file!\n"; $timeprint0 = 0.00000000000; $timeprint0 = $timezero + $k[0]; printf "Absolute time for $k[0] is %17.8f\n", $timeprint0; printf OUTPUT_FILE " %17.8f",$timeprint0; } elsif($ik == 2) { $timeprint0 = 0.000000000000; $timeprint1 = 0.000000000000; $timeprint0 = $timezero + $k[0]; $timeprint1 = $timezero + $k[1] + $timedel; printf OUTPUT_FILE " %19.8f %19.8f",$timeprint0,$timeprint1; } else { print "\n\nERROR! Your time range input is invalid!\nPlease check it and try again.\n\n"; } if($icount++ < $itmpt--){ print OUTPUT_FILE "\n"; $icount--; $itmpt++; } } print OUTPUT_FILE "\n"; close (OUTPUT_FILE); print "\nAbsolute time ranges are:\n"; open(OUTPUT_FILE,"$outfile"); while() { print $_; # Print the results stored in OUTPUT_FILE } close(OUTPUT_FILE); # We are finished with the input file. print "\nFinished.\n The results stored in $outfile can be input \ninto the extractors at the TIMEINT parameter.\n\n";