From 902908cda32d6deffffd5fd3895491269f638070 Mon Sep 17 00:00:00 2001 From: caes Date: Wed, 29 Jun 2016 19:35:02 -0400 Subject: [PATCH] added script to prepare HEASOFT data --- scripts/power_lag_plot.pl | 32 +++++++++++++++--------------- scripts/round_time.pl | 41 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 16 deletions(-) create mode 100755 scripts/round_time.pl diff --git a/scripts/power_lag_plot.pl b/scripts/power_lag_plot.pl index 6f3b2d2..5da2d86 100755 --- a/scripts/power_lag_plot.pl +++ b/scripts/power_lag_plot.pl @@ -8,9 +8,9 @@ use Switch; use constant PI => 4 * atan2(1, 1); -# Enables debug output. -our $debug=1; -our $verbosedebug=0; +# Enables various levels of output. +our $verbose=1; +our $debug=0; # This section locates the output data of interest in a @@ -38,7 +38,7 @@ while(<$outputfile>) { $star_bytenum_2 = tell($outputfile); } } -if ($verbosedebug) { +if ($debug) { say encode($charset,"Final set found between lines "), $star_linenum_1, " and ", @@ -56,7 +56,7 @@ $bin_bounds_line = <$outputfile>; $bin_bounds_line =~ s/^#\s*(.*)$/$1/; #$line =~ / @bin_bounds = split /\s/,$bin_bounds_line; -if ($verbosedebug) { +if ($debug) { print encode($charset,"Found bin boundaries: "); foreach (@bin_bounds) {print encode($charset,"$_ ");} say encode($charset," "); @@ -84,7 +84,7 @@ foreach (@bin_bounds) { $numbins = keys %function_bin; say encode($charset,"$numbins frequency bins captured in output."); -if($debug) { +if($verbose) { say encode($charset,"freq μ freq σ"); while (each %function_bin ) { say encode($charset, @@ -102,7 +102,7 @@ increments to designate the data being captured. =cut -if ($debug) { +if ($verbose) { say encode($charset,""); say encode($charset, " New Curve -- Source PSD"); @@ -120,7 +120,7 @@ foreach ( sort { $a <=> $b } keys %function_bin ) { # } $function_bin{$_}{"source_PSD_μ"} = $μ; $function_bin{$_}{"source_PSD_σ"} = $σ; - if ($debug) { + if ($verbose) { say encode($charset, "freq = " . sprintf('%.3f',$_) . @@ -131,7 +131,7 @@ foreach ( sort { $a <=> $b } keys %function_bin ) { } } -if ($debug) { +if ($verbose) { say encode($charset,""); say encode($charset, " New Curve -- Reprocessed PSD"); @@ -148,7 +148,7 @@ foreach ( sort { $a <=> $b } keys %function_bin ) { # } $function_bin{$_}{"reproc_PSD_μ"} = $μ; $function_bin{$_}{"reproc_PSD_σ"} = $σ; - if ($debug) { + if ($verbose) { say encode($charset, "freq = " . sprintf('%.3f',$_) . @@ -160,7 +160,7 @@ foreach ( sort { $a <=> $b } keys %function_bin ) { } -if ($debug) { +if ($verbose) { say encode($charset,""); say encode($charset, " New Curve -- Cross Spectra PSD"); @@ -177,7 +177,7 @@ foreach ( sort { $a <=> $b } keys %function_bin ) { # } $function_bin{$_}{"cc_PSD_μ"} = $μ; $function_bin{$_}{"cc_PSD_σ"} = $σ; - if ($debug) { + if ($verbose) { say encode($charset, "freq = " . sprintf('%.3f',$_) . @@ -188,7 +188,7 @@ foreach ( sort { $a <=> $b } keys %function_bin ) { } } -if ($debug) { +if ($verbose) { say encode($charset,""); say encode($charset, " New Curve -- Phase Difference φ"); @@ -204,7 +204,7 @@ foreach ( sort { $a <=> $b } keys %function_bin ) { } $function_bin{$_}{"φdiff_μ"} = $μ; $function_bin{$_}{"φdiff_σ"} = $σ; - if ($debug) { + if ($verbose) { say encode($charset, "freq = " . sprintf('%.3f',$_) . @@ -217,7 +217,7 @@ foreach ( sort { $a <=> $b } keys %function_bin ) { $σ = $σ/(2*PI*$_); $function_bin{$_}{"timelag_μ"} = $μ; $function_bin{$_}{"timelag_σ"} = $σ; - if ($debug) { + if ($verbose) { say encode($charset, " timelag: μ = " . sprintf('%10.3e',$μ) . @@ -229,7 +229,7 @@ foreach ( sort { $a <=> $b } keys %function_bin ) { say encode($charset,""); -if($verbosedebug) { +if($debug) { while (each %function_bin ) { print encode($charset,$_ . ": "); while ( my ($key,$value) = each %{$function_bin{$_}} ) { diff --git a/scripts/round_time.pl b/scripts/round_time.pl new file mode 100755 index 0000000..5122ccc --- /dev/null +++ b/scripts/round_time.pl @@ -0,0 +1,41 @@ +#!/usr/local/bin/perl +use feature say; +use utf8; +use feature qw/switch/; +open(my $file,$ARGV[0]) or die("could not open file"); + +$keep = 1; +# Add two because need to read more digits for rounding. +$keep += 2; +$throw = 5 - $keep; + +<$file>; +while (<$file>) { + $_ =~ /^.{8}\s+([0-9]{4})\s+([0-9]{5})\.([0-9]{$keep})[0-9]{$throw}(.*)/; + $λ = $1; + $t𝓃 = $2; # characteristic + $t𝜀 = $3; # mantissa + $vals = $4; + if ($t𝜀 =~ /([0-9])([0-9])([0-9])/) { + $t𝜀 = $1; + given($2) { + when (/[6-8]/) { $t𝜀 += 1; } + when (/5/) { $t𝜀 += 1 if (!($2 == 0)); } + } + if ($t𝜀 > 9) { + $t𝓃 += 1; + $t𝜀 = 0; + } + # For rounding when even rules + #say $2 % 2; + #if (!($2%2 == 0) ) { + # $t𝜀 = $t𝜀 + 1; + #} + } + else { + die "Malformed data encountered"; + } + say "$λ\t$t𝓃.$t𝜀$vals"; +} +close($file); +