#! /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/xronwin # 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/xronwin." 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/xronwin." 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 $task="xronwin1.0"; $bailout= "bailout"; $maxtwin = 1000; $maxpwin = 10; $maxfwin = 10; $series = 1; $btype = "O"; $form = "S"; $epoch = "Undefined"; $period = "Undefined"; %type = ("O","Orig. Bins","N","New Bins ","I","Intervals "); use Getopt::Std; require 'utils.pl'; getopt('io'); $infile=$opt_i; $outfile=$opt_o; #DEBUG!!! #$opt_c = 1; if (!system('echo teststring | more -E 2> /dev/null 1> /dev/null' )){ #in case somebody has set more == less $more = "more -d -E"; } elsif (!system('echo teststring | more -e 2>/dev/null 1>/dev/null' )){ #for the OSF version of more $more = "more -d -e"; } else { $more = "more -d"; } print "Using '$more' as more\n" if $opt_v; if($opt_h) { print<); CASE: { &change_time_windows, last CASE if $action_letter =~ /^[tT]/; &change_phase_windows, last CASE if $action_letter =~ /^[pP]/; &change_flux_windows, last CASE if $action_letter =~ /^[fF]/; &change_expo_windows, last CASE if $action_letter =~ /^[eE]/; &read_win_file, last CASE if $action_letter =~ /^[rR]/; &show_windows, last CASE if $action_letter =~ /^[sS]/; &clear_windows, last CASE if $action_letter =~ /^[cC]/; $missing_e_or_p = &write_win_file, last CASE if $action_letter =~ /^[wW]/; exit(0) if $action_letter =~ /^[qQ]/ ; &def_series, last CASE if $action_letter =~ /^[dD][sS]/; &def_btype, last CASE if $action_letter =~ /^[dD][bB]/; &def_epoch, last CASE if $action_letter =~ /^[dD][eE]/; &def_period, last CASE if $action_letter =~ /^[dD][pP]/; ©_windows, last CASE if $action_letter =~ /^[dD][wW]/; } } sub copy_windows { print "Enter numbers n and m to copy windows from series n to series m: "; chop($action = ); return if length($action) == 0 ; ($n,$m) = split(" ",$action); print "Copy series $n to series $m? (y or n) "; chop($action = ); unless ($action =~ /^[nN]/) { if($n >= 1 and $n <= 4 and $m >= 1 and $m <= 4) { foreach $ibtype ("O","N","I") { $n_array ="flux_win_${ibtype}_$n"; $m_array ="flux_win_${ibtype}_$m"; @$m_array = @$n_array; $the_array = "expo_win_$ibtype"; $$the_array[$m] = $$the_array[$n]; } } } } sub clear_windows { $series = 1; $btype = "O"; $epoch = "Undefined"; $period = "Undefined"; undef(@time_wins); undef(@phase_wins); foreach $iseries (1..4) { foreach $ibtype ("O","N","I") { $the_array ="flux_win_${ibtype}_$iseries"; undef(@$the_array); $the_array = "expo_win_$ibtype"; $$the_array[$iseries] = "Undefined"; } } } sub def_period{ local(%form=("S","Seconds","D","Days")); DPERIOD: while(1) { system("clear") if $opt_c; if($broken) { $broken=0; print "Illegal entry. Ignored.\n" if $opt_v; } print "Current Period is: $period days\n"; print "Current Input Format is $form{$form}.\n"; print "[D] Change input format to Days.\n"; print "[S] Change input format to Seconds.\n"; print "[#] Set Period to #.\n"; print " to Main menu.\n"; print "Action: "; chop($action = ); if (length($action) == 0 ) { last DPERIOD; } elsif($action =~ /^[Dd]/) { $form = "D"; } elsif ($action =~ /^[Ss]/) { $form = "S"; } elsif ($action =~ /[^\-+0-9.eE ]/) { $broken = 1; } else { $period = $action; if ($form eq "S") {$period /= 86400;} } } } sub def_epoch { DEPOCH: while(1) { system("clear") if $opt_c; if($broken) { $broken=0; print "Illegal Epoch entered. Ignored.\n" if $opt_v; } print "Current Epoch is: $epoch days\n"; print "Enter Epoch ( to main menu): "; local($sav_epoch = $epoch); chop($epoch = ); if (length($epoch) == 0 ) { $epoch=$sav_epoch; last DEPOCH; } elsif ($epoch =~ /[^\-+0-9.eE ]/) { $broken = 1; $epoch = $sav_epoch; } else { $epoch = &convert_t($epoch); } } } sub def_series { local($broken=0); DSER: while(1) { system("clear") if $opt_c; if($broken) { $broken=0; print "Illegal series entered. Ignored.\n" if $opt_v; } print "Current series is: $series\n"; print "Enter series number 1-4 ( to main menu): "; local($sav_ser = $series); chop($series = ); if (length($series) == 0 ) { $series=$sav_ser; last DSER; } elsif ($series < 1 or $series > 4) { $broken = 1; $series = $sav_ser; } } } sub def_btype { local($broken=0); DBTYPE: while(1) { system("clear") if $opt_c; if($broken) { $broken=0; print "Illegal bintype entered. Ignored.\n" if $opt_v; } print "Current bin type is: $type{$btype}\n"; print "[O] original bin windows\n[N] new bin windows\n"; print "[I] interval windows\nBin type ( to main menu): "; local($sav_btype = $btype); chop($btype = ); $btype = uc($btype); if (length($btype) == 0 ) { $btype = $sav_btype; last DBTYPE; } elsif ($btype !~ /^(O|N|I)/){ $broken = 1; $btype = $sav_btype; } } } sub print_menu { print "[T] Change TIME Windows\n"; print "[P] Change PHASE Windows\n"; print "[F] Change FLUX Windows\n"; print "[E] Change EXPOSURE Windows\n"; print "[R] READ an Input file\n"; print "[S] SHOW All Defined Windows\n"; print "[C] CLEAR All Defined Windows\n"; print "[W] WRITE Window file\n"; print "[Q] QUIT Window Program\n"; print "[DS] Define Series Number (Currently $series)\n"; print "[DB] Define Bin Type (Currently $type{$btype})\n"; print "[DE] Define Epoch for Phase Windows (Currently $epoch)\n"; print "[DP] Define Period for Phase Windows (Currently $period)\n"; print "[DW] Copy Defined Windows from Series to Series\n"; print "Choose an action: "; } sub show_windows{ system("clear") if $opt_c; open(MORE,"|$more"); if(@time_wins) { print MORE "Time Windows (days):\n"; print MORE "Window\tStart\t\tStop\n"; &print_array_mo(@time_wins); } if(@phase_wins) { print MORE "Phase Windows:\n"; print MORE "Epoch: $epoch\tPeriod: $period\n"; print MORE "Window\tStart\t\tStop\n"; &print_array_mo(@phase_wins); } foreach $iseries (1..4) { foreach $ibtype ("O","N","I") { $the_array ="flux_win_${ibtype}_$iseries"; next unless @$the_array; print MORE "Intensity Windows for $type{$ibtype} series $iseries: \n"; &print_array_mo(@$the_array); } } foreach $iseries (1..4) { print MORE "Exposure Windows for series $iseries: \n"; print MORE "Original bins: $expo_win_O[$iseries]\n"; print MORE "New bins: $expo_win_N[$iseries]\n"; print MORE "Intervals: $expo_win_I[$iseries]\n"; } close(MORE); print " to main menu: "; $grot = ; } sub read_win_file{ #get legal input file $i=0; until (length($infile) != 0 && -r $infile ){ system("clear") if $opt_c; if(length($infile) != 0) {print "I can't read input file: \"$infile\"\n";} &print_likely_files('*.wi'); print "Input Filename(or number): "; chop($infile = ); if(($infile =~ /^\s*(\d+)\s*$/)&&($infile <= @likely_files)){ $infile=$likely_files[$1-1];} print "Can't seem to find a file. Exiting.\n", return if $i > 5; $i++; } open(IN,"<$infile"); $firstline = ; $ntime = ; $ntime =~ /^\s*(\d*)/; $ntime = $1; print "Read $ntime time windows\n" if ($opt_v and $ntime > 0); foreach $i (1..$ntime) { chop($timerec = ); ($tmin,$tmax,$nrec) = split(" ",$timerec); push(@time_wins,"$tmin\t\t$tmax"); } $nphase = ; $nphase =~ /^\s*(\d*)/; $nphase = $1; print "Read $nphase phase windows\n" if ($opt_v and $nphase > 0); if($nphase >=1) { #get epoch and period chop ($erec = ) ; ($epoch,$period) = split(" ",$erec); } foreach $i (1..$nphase) { chop($phaserec = ); ($pmin,$pmax,$nrec) = split(" ",$phaserec); push(@phase_wins,"$pmin\t\t$pmax"); } foreach $iseries (1..4) { foreach $ibtype ("O","N","I") { $the_array ="flux_win_${ibtype}_$iseries"; $nflux = ; $nflux =~ /^\s*(\d*)/; $nflux = $1; print "Read $nflux Intensity windows for $type{$ibtype} series $iseries.\n" if ($opt_v and $nflux > 0); foreach $i (1..$nflux) { chop($fluxrec = ); ($fmin,$fmax,$nrec) = split(" ",$fluxrec); push(@$the_array,"$fmin\t\t$fmax"); } } foreach $ibtype ("O","N","I") { $nex = ; $nex =~ /^\s*(\d*)/; $nex = $1; $the_array = "expo_win_$ibtype"; print "Read $nex Exposure window for $type{$ibtype} series $iseries.\n" if ($opt_v and $nex > 0); if($nex == 0) { $$the_array[$iseries] = "Undefined"; } else { chop($exrec = ); ($emin,$emax,$nrec) = split(" ",$exrec); $$the_array[$iseries] = "$emin\t\t$emax"; } } } close(IN); undef($infile); } sub write_win_file { if (@phase_wins and ($epoch =~ /^U/ or $period =~ /^U/)) { #we need an epoch or a period return 1; } until ($outfile) { print "What should I call your output window file: "; chop($outfile = ); } $outfile .= ".wi" unless $outfile =~ /\.wi$/; #first figure out how many we have of each thing $ntime_wins = 0; $nphase_wins = 0; $nflux_wins = 0; $nexpo_wins = 0; $ntime_wins += @time_wins; $nphase_wins += @phase_wins; foreach $iseries (1..4) { foreach $ibtype ("O","N","I") { $the_array ="flux_win_${ibtype}_$iseries"; $nflux_wins += @$the_array; } } $nexpo_wins += grep(/^[^U]/,@expo_win_O); $nexpo_wins += grep(/^[^U]/,@expo_win_N); $nexpo_wins += grep(/^[^U]/,@expo_win_I); $totwin = $ntime_wins + $nphase_wins + $nflux_wins + $nexpo_wins; open(OUT,">$outfile") or die; print OUT " $totwin Windows in this < Xronos Window File >\n"; print OUT " $ntime_wins Time Wind.: start stop (days)\n"; $i = 0; foreach $time_rec (@time_wins) { $i++; $time_rec .= "\t$i"; $time_rec =~ s/\t/ /g; print OUT " $time_rec\n"; } print OUT " $nphase_wins Phase Wind.: epoch period (days)/ start stop (0->1) phases max 10\n"; print OUT " $epoch $period\n" if $nphase_wins; $i = 0; foreach $phase_rec (@phase_wins) { $i++; $phase_rec .= "\t$i"; $phase_rec =~ s/\t/ /g; print OUT " $phase_rec\n"; } foreach $iseries (1..4) { foreach $ibtype ("O","N","I") { $the_array ="flux_win_${ibtype}_$iseries"; $nwin = 0; $nwin += @$the_array; print OUT " $nwin Ints. Wind. for $type{$ibtype} in Series $iseries : min max (c/s) max 10\n"; $i = 0; foreach $flux_rec (@$the_array) { $i++; $flux_rec .= "\t$i"; $flux_rec =~ s/\t/ /g; print OUT " $flux_rec\n"; } } foreach $ibtype ("O","N","I") { $nwin = 1; $the_array = "expo_win_$ibtype"; $nwin = 0 if $$the_array[$iseries] =~ /^U/; print OUT " $nwin Exps. Wind. for $type{$ibtype} in Series $iseries : min max (0->50) max 1\n"; print OUT " $$the_array[$iseries] 1\n" if $nwin; } } close(OUT); undef($outfile); return(0); } sub change_flux_windows{ local (%typen = ("O","Original Bins","N","New Bins","I","Intervals")); local($broken = 0); $action = "go"; $the_array ="flux_win_${btype}_$series"; $broken = &check_array($the_array) if @$the_array; ACTION: while ($action) { system("clear") if $opt_c; print "ERROR: Windows cannot be ordered, please fix this!\nFirst \"broken\" window appears to be number $broken\n" if $broken; if(@$the_array) { print "Current Intensity Windows for $typen{$btype} Series $series are: \n"; print "Window\tMinimum\t\tMaximum\n"; &print_array(@$the_array); } else { print "Currently no Intensity Windows for $typen{$btype} Series $series. \n"; } print "[A] add more windows\n[#] delete window number #\n"; print " to main menu\n Action: "; chop($action = ); if($action =~ /^[\-+0-9]/) { next ACTION if $action > @$the_array; if($action == 1) { shift(@$the_array); $action = "deleted"; } else { @$the_array = @$the_array[0..$action-2,$action..$#$the_array]; $action = "deleted"; } } elsif ($action =~ /^[aA]/){ FGET_LOOP: while (1) { #add new flux windows print "Maximum number of windows reached.\n", last FGET_LOOP if @$the_array > $maxfwin; print "Input minimum intensity: "; chop($flux_min = ) ; last FGET_LOOP if ($flux_min eq "-" or $flux_min eq ""); print "Input maximum intensity: "; chop($flux_max = ) ; last FGET_LOOP if ($flux_max eq "-" or $flux_max eq ""); $flux_max = &convert_t($flux_max); unless ($flux_max <= $flux_min) { push(@$the_array,"$flux_min\t\t$flux_max"); $action = "added"; } else { print "Maximum Intensity <= Minimum Intensity, please reenter\n"; } } } elsif (length($action)==0 and not $broken) { last ACTION; } else { $action = "donothing"; } $broken = &check_array($the_array) if @$the_array; } } sub change_expo_windows{ EGET: while(1) { system("clear") if $opt_c; print "Current Exposure Window for series $series, $type{$btype} is: \n"; $the_array = "expo_win_$btype"; print "$$the_array[$series]\n"; print "[#] Minimum exposure\n[-] Delete this window\n"; print " to main menu.\n"; print "Action: "; chop($action = ) ; if ($action eq "-"){ $expo_min = "UNDEF"; $expo_max = "UNDEF"; } elsif (length($action) == 0) { last EGET; } elsif ($action =~ /[^\-+0-9.eE ]/) { next EGET; } else { $expo_min = $action; print "Input maximum exposure: "; chop($expo_max= ) ; } if ($expo_max >= $expo_min or $expo_min eq "UNDEF") { $$the_array[$series] = "$expo_min\t\t$expo_max"; $$the_array[$series] = "Undefined" if $expo_min eq "UNDEF"; $action = "changed"; } else { print "maximum expo. <= minimum expo., please reenter\n"; } } } sub check_array{ #makes sure an array of windows doesn't have overlaps local($tw = shift); return 0 if @$tw == 1; @$tw = sort {$a <=> $b} @$tw; ($tmin_o,$tmax_o) = split(" ",$$tw[0]); $i=1; foreach $t (@$tw[1..$#$tw]) { $i++; ($tmin,$tmax) = split(" ",$t); return $i if $tmin < $tmax_o; $tmin_o=$tmin; $tmax_o=$tmax; } return 0; } sub check_parray{ #makes sure an array of phase windows doesn't have overlaps local($tw = shift); return 0 if @$tw == 1; @$tw = sort {$a <=> $b} @$tw; ($tmin_o,$tmax_o) = split(" ",$$tw[0]); $tmin1 = $tmin_o; $i=1; if (@$tw > 2) { foreach $t (@$tw[1..$#$tw-1]) { $i++; ($tmin,$tmax) = split(" ",$t); return $i if $tmin < $tmax_o or $tmin > $tmax; $tmin_o=$tmin; $tmax_o=$tmax; } } $i++; ($tmin,$tmax) = split(" ",$$tw[$#$tw]); return $i if $tmin < $tmax_o or $tmax < $tmin && $tmax > $tmin1; return 0; } sub convert_t{ #takes input string in d, d s, or d h m s ms and returns d local($tstring=shift); @t = split(" ",$tstring); if (@t == 1) { #already have days return $t[0]; } elsif (@t == 2 and $t[1] =~ /\./) { #have d s return $t[0]+$t[1]/86400; } else { #have d h m s ms return $t[0]+$t[1]/24+$t[2]/1440+$t[3]/86400+$t[4]/86400.0e3; } } sub print_array{ for($i=1;$i-1<=$#_;$i++) { print "$i\t$_[$i-1]\n"; } } sub print_array_mo{ #same function as print_array, but uses a pipehandle MORE #MORE must have already been opened for($i=1;$i-1<=$#_;$i++) { print MORE "$i\t$_[$i-1]\n"; } } sub change_time_windows{ local($broken = 0); $action = "go"; $broken = &check_array(\@time_wins) if @time_wins; ACTION: while ($action) { system("clear") if $opt_c; open(MORE,"|$more"); if(@time_wins) { print MORE "Current Time Windows are: \n"; print MORE "Window\tStart\t\tStop\n"; &print_array_mo(@time_wins); } print MORE "ERROR: Windows cannot be time ordered, please fix this!\nFirst \"broken\" window appears to be number $broken\n" if $broken; print MORE "[A] Add more windows\n[#] delete window number: #\n"; print MORE " to main menu\n"; close(MORE); print "Action: "; chop($action = ); if($action =~ /^[\-+0-9]/) { next ACTION if $action > @time_wins; if($action == 1) { shift(@time_wins); $action = "deleted"; } else { @time_wins = @time_wins[0..$action-2,$action..$#time_wins]; $action = "deleted"; } } elsif ($action =~ /^[aA]/){ print "Enter time format as dd.d , dd ss.s , dd hh mm ss ms\n"; TGET_LOOP: while (1) { #add new time windows print "Maximum number of windows reached.\n", last TGET_LOOP if @time_wins > $maxtwin; print "Input minimum time: "; chop($time_min = ) ; last TGET_LOOP if ($time_min eq "-" or $time_min eq ""); $time_min = &convert_t($time_min); print "Input maximum time: "; chop($time_max = ) ; last TGET_LOOP if ($time_max eq "-" or $time_max eq ""); $time_max = &convert_t($time_max); unless ($time_max <= $time_min) { push(@time_wins,"$time_min\t\t$time_max"); $action = "added"; } else { print "Tmax <= Tmin, please reenter\n"; } } } elsif (length($action)==0 and not $broken) { return; } else { $action = "donothing"; } $broken = &check_array(\@time_wins) if @time_wins; } } sub change_phase_windows{ local($broken = 0); $action = "go"; $broken = &check_array(\@phase_wins) if @phase_wins; ACTION: while ($action) { system("clear") if $opt_c; print "ERROR: Windows cannot be phase ordered, please fix this!\nFirst \"broken\" window appears to be number $broken\n" if $broken; if(@phase_wins) { print "Current Phase Windows are: \n"; print "Window\tStart\t\tStop\n"; &print_array(@phase_wins); } print "[A] Add more windows\n[#] delete window number: #\n"; print " to main menu\n"; print "Action: "; chop($action = ); if($action =~ /^[0-9]/) { next ACTION if $action > @phase_wins; if($action == 1) { shift(@phase_wins); $action = "deleted"; } else { @phase_wins = @phase_wins[0..$action-2,$action..$#phase_wins]; $action = "deleted"; } } elsif ($action =~ /^[aA]/){ print "Phase ranges 0.0-1.0 \n"; PGET_LOOP: while (1) { #add new phase windows print "Maximum number of windows reached.\n", last PGET_LOOP if @phase_wins > $maxpwin; print "Input minimum phase: "; chop($phase_min = ) ; last PGET_LOOP if ($phase_min eq "-" or $phase_min eq ""); print "Input maximum phase: "; chop($phase_max = ) ; last PGET_LOOP if ($phase_max eq "-" or $phase_max eq ""); if ($phase_max <= 1 and $phase_min < 1 and $phase_max > 0 and $phase_min >= 0) { push(@phase_wins,"$phase_min\t\t$phase_max"); $action = "added"; } else { print "Phases must be in range 0 through 1, please reenter\n"; } $action = "added"; } } elsif (length($action)==0 and not $broken) { return; } else { $action = "donothing"; } $broken = &check_parray(\@phase_wins) if @phase_wins; } } format FLAGS = @<<<<<<<<<<<<<<< ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<~ $flag_name, $flag_means ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<~~ $flag_means . format TEXT1 = @||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| $task ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<~~ $paragraph_string .