#! /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/chantrans # 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/chantrans." 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/chantrans." 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 spectrum file and a # a series or relative channel ranges and convert that to a range of # absolute channel 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:c:ph '); 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 $tmpfile !\n"; print "Input file used is $tmpfile\n"; close(INPUT_FILE); # We are finished with the input file. } else { -e $infile || die "Cannot find $infile !\n"; $tmpfile = $infile; } $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_c) { print "Relative channel ranges are: $opt_c \n"; $tmpchan = $opt_c; } else { print "Input relative channel range:[0-5, 16, 22-128]"; ($tmpchan = ); if($tmpchan =~ /^./ ){ chop($tmpchan); } else{ print "ERROR! No channel range specified!!!\n"; print "Nothing to do!... Aborting....\n"; exit; } } print "\n##########################################\n"; $rddescr_string = "rddescr phafil='$infile' "; $rddescr_string .= "chanfil=chanfil_${$} chatter='10' "; $rddescr_string .= "clobber='yes' mode='ql'"; @result=&runcom($rddescr_string); open(CHAN_FILE,"chanfil_${$}") || die "Sorry can't find chanfil_${$}\n"; # Open the input file $ichan = 0; $istore = 0; while() { chop; $chan_array[$ichan] = $_; @h = split(/\s+/,$chan_array[$ichan]); $itmpt = @h; # print "itmpt array is $itmpt\n"; if($h[3] != -1) { $tempval=$h[1]; while($tempval <= $h[2]){ $startval[$istore]=$tempval; # print "startval is $tempval, "; $tempval += $h[3]; # print " stopval is $tempval, "; # print " istore is $istore \n"; if($tempval <= $h[2]){ $stopval[$istore] = ($tempval-1); } else { $stopval[$istore]=$h[2]; } $istore++ } # for($icount = 1; $icount < $itmpt; $icount ++) { # print "Chan $ichan, Space $icount, value $h[$icount]\n"; # } } $ichan++; } $itmpt = @chan_array; #print "istore value is $istore\n"; if(defined $opt_p){ print "\n--------------------------------------------------------------------------\n"; print" Relative Channel: Absolute Start Channel Absolute Stop Channel\n"; for ($icount=0; $icount < $istore; $icount++){ printf " %5d %5d %5d \n",$icount,$startval[$icount],$stopval[$icount]; } print "--------------------------------------------------------------------------\n"; } $istore--; close(CHAN_FILE); unlink("chanfil_${$}") || print "Having trouble deleting chanfil_${$}\n"; #print "Finished parsing channels and working on chint"; @chan = split(/,/,$tmpchan); $itmpt = @chan; print "Number of channel ranges specified: $itmpt \n"; $itmpt--; for($icount = 0; $icount <= $itmpt; $icount++) { @k = split(/-/,$chan[$icount]); $ik = @k; if($ik == 1) { if($k[0] > $istore){ print "Specified value is out of range!\n"; print "You specified $k[0], but maximum relative channel for this file is $istore\n"; exit; } elsif($k[0] < 0){ print "Specified value is out of range!\n"; print "You specified $k[0], but minimum relative channel for this file is 0"; } if($startval[$k[0]] == $stopval[$k[0]]) { printf OUTPUT_FILE " %5d", $startval[$k[0]]; } else { printf OUTPUT_FILE " %5d %5d ", $startval[$k[0]],$stopval[$k[0]]; } } elsif($ik == 2) { if($k[0] > $istore){ print "Specified value is out of range!\n"; print "You specified $k[0], but maximum relative channel for this file is $istore\n"; exit; } elsif($k[0] < 0){ print "Specified value is out of range!\n"; print "You specified $k[0], but minimum relative channel for this file is 0"; } if($k[1] > $istore){ print "Specified value is out of range!\n"; print "You specified $k[1], but maximum relative channel for this file is $istore\n"; exit; } elsif($k[1] < 0){ print "Specified value is out of range!\n"; print "You specified $k[1], but minimum relative channel for this file is 0"; } if($startval[$k[0]] == $stopval[$k[1]]) { printf OUTPUT_FILE " %5d", $startval[$k[0]]; } else { printf OUTPUT_FILE " %5d %5d ", $startval[$k[0]],$stopval[$k[1]]; } } else { print "\n\nERROR! Your channel 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 channel 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 "\nWe are finished. The results are stored in $outfile.\n\n";