#! /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/ascii2flc # 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/ascii2flc." 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/ascii2flc." 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! #------------------------------------------------------------------------------- #!/usr/local/bin/perl5 #helpful(?) note: in the following /^\s*[+\-]?[0-9.]/ is meant #to match any line that starts with a "number" if anyone has a better #idea, feel free eval { $task="ascii2flc1.0"; $bailout= "bailout"; use Getopt::Std; require 'utils.pl'; getopt('io'); $infile=$opt_i; $outfile=$opt_o; if($opt_h) { print <); if(($infile =~ /^\s*(\d+)\s*$/)&&($infile <= @likely_files)){ $infile=$likely_files[$1-1];} die "Can't seem to find a file. Exiting.\n" if $i > 5; $i++; } unless ($outfile) { $outfile_def = $infile; $outfile_def =~ s/\..*$/\.fits/; print "Output Filename ( for default $outfile_def): "; chop ($outfile = ); $outfile = $outfile_def unless $outfile; } #until ($cstring =~ /c/i) { #print "Please assign column type numbers to your input file columns:\n"; #print "A TIME column\n"; #print "B TIME_ERROR column \n"; #print "C RATE column \n"; #print "D RATE_ERROR column \n"; #print "E EXPOSURE column \n"; #print "Input a list of column letters giving the order of the columns\n"; #print "in your file (you must specify at least column 'C'): "; #chop($cstring = ); #} #$ncol = 0; #column numbering starts with ONE! #foreach $clet (split(/[^ABCDEabcde]/,$cstring)){ # $clet =~ tr/a-e/A-E/; # $ncol++; # $column{$clet} = $ncol; #} print "Please input the number of the TIME column in your file,\n"; print "(RETURN or 0 for no time column): "; chop($column{"TIME"} = ); $timeunit="NONE" unless $column{"TIME"}; until ($timeunit =~ /^(s|d|NONE)$/){ print "What are the time units of input data ('d' or 's')? "; chop($timeunit = ); } print "Please input the number of the RATE[ERROR] column in your file,\n"; print "[ERROR] is optional: "; chop($raterec = ); ($column{"RATE"},$column{"ERROR"}) = split(/[[\]]/,$raterec); until ($dtype =~ /^(count|count\/s)$/){ print "What are the RATE column units ('count' or 'count/s')? "; chop($dtype = ); } print "Please input the number of the EXPOSURE column in your file,\n"; print "(RETURN or 0 for no exposure column): "; chop($column{"EXPO"} = ); open(INFILE,$infile); while () { next unless(/^\s*[+\-]?[0-9.]/); @elements = split(' '); push(@timecol,$elements[$column{"TIME"}-1]) if $column{"TIME"}; push(@rate,$elements[$column{"RATE"}-1]) if $column{"RATE"}; push(@rate_error,$elements[$column{"ERROR"}-1]) if $column{"ERROR"}; push(@exposure,$elements[$column{"EXPO"}-1]) if $column{"EXPO"}; } close(INFILE); #get defaults $tstart_def = $timecol[0]; $tstop_def = $timecol[$#timecol]; until ($timeunit_head =~ /^(s|d|NONE)$/){ print "What are the time unit for the header keywords \n"; print "TSTART, TSTOP, TIMEDEL, (and TIMEZERO) ('d' or 's')? "; chop($timeunit_head = ); } until ($timedel =~ /^\s*[+\-]?[0-9.]/){ print "What is input file bin size (TIMEDEL keyword)? "; chop($timedel = ); } until ($tstart =~ /^\s*[+\-]?[0-9.]/){ print "Input Start time (TSTART keyword): "; print "[$tstart_def]" if $tstart_def; chop($tstart = ); $tstart = $tstart_def if $tstart =~ /^\s*$/; } $tstop_def = $tstart + $timedel*@rate unless defined($tstop_def); until ($tstop =~ /^\s*[+\-]?[0-9.]/){ print "Input Stop time (TSTOP keyword): "; print "[$tstop_def]" if $tstop_def; chop($tstop = ); $tstop = $tstop_def if $tstop =~ /^\s*$/; } # ask for TIMEZERO only if no TIME column in the file $timezero = 0; if(not $column{"TIME"}){ until ($timezero =~ /^\s*[+\-]?[0-9.]/){ print "Input Zero time (TIMEZERO keyword): "; print "[$tstart]"; chop($timezero = ); $timezero = $tstart if $timezero =~ /^\s*$/; } } $CDFILE = "col.txt$$"; open(CDFILE,">$CDFILE"); print CDFILE "TIME 1D $timeunit\n" if $column{"TIME"}; if ($dtype eq "count") { print CDFILE "COUNT 1E $dtype\n"; } else { print CDFILE "RATE 1E $dtype\n"; } print CDFILE "ERROR 1E $dtype\n" if $column{"ERROR"}; print CDFILE "FRACEXP 1E \n" if $column{"EXPO"}; close(CDFILE); $HEADFILE = "header.txt$$"; open(HEADFILE, ">$HEADFILE"); print HEADFILE "TIMEUNIT '$timeunit_head'\n"; print HEADFILE "TSTART $tstart\n"; print HEADFILE "TSTOP $tstop\n"; print HEADFILE "TIMEDEL $timedel\n"; print HEADFILE "TIMEZERO $timezero\n"; print HEADFILE "HISTORY File created by ascii2lc using input $infile\n"; close(HEADFILE); $DATAFILE = "data.txt$$"; open(DATAFILE, ">$DATAFILE"); while (@rate) { $rec = ''; $rec .= shift(@timecol).' '; $rec .= shift(@rate).' '; $rec .= shift(@rate_error).' '; $rec .= shift(@exposure)."\n"; print DATAFILE $rec; } close(DATAFILE); print "Creating the fits file...\n"; &runcom("fcreate cdfile=$CDFILE datafile=$DATAFILE outfile=$outfile headfile=$HEADFILE tbltype=\"binary\" nskip=0 nrows=0 history=no morehdr=0 extname=\" \" anull=\" \" inull=0 clobber=yes", $bailout,"Couldn't create output file $outfile"); sub bailout { unlink($CDFILE,$HEADFILE, $DATAFILE) unless $opt_d; die("\n$task: $_[0]\n$task: Fatal Error\n"); } format FLAGS = @<<<<<<<<<<<<<<< ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<~ $flag_name, $flag_means ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<~~ $flag_means . format TEXT1 = @||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| $task ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<~~ $paragraph_string COMMAND LINE PARAMETERS (if any are omitted or confused, you will be prompted): . } ; if($@) {print $@;} else {print "Done.\n";} unlink($CDFILE,$HEADFILE, $DATAFILE) unless $opt_d;