2016-06-20 18:26:27 +00:00
|
|
|
|
#!/usr/local/bin/perl
|
|
|
|
|
|
|
|
|
|
use utf8;
|
|
|
|
|
use Encode qw(encode decode);
|
|
|
|
|
use feature 'say';
|
|
|
|
|
use locale;
|
|
|
|
|
use Switch;
|
|
|
|
|
|
2016-06-21 08:56:27 +00:00
|
|
|
|
use constant PI => 4 * atan2(1, 1);
|
2016-06-20 18:26:27 +00:00
|
|
|
|
|
2016-06-29 23:35:02 +00:00
|
|
|
|
# Enables various levels of output.
|
|
|
|
|
our $verbose=1;
|
|
|
|
|
our $debug=0;
|
2016-06-20 18:26:27 +00:00
|
|
|
|
|
|
|
|
|
|
2016-06-21 08:56:27 +00:00
|
|
|
|
# This section locates the output data of interest in a
|
2016-06-20 18:26:27 +00:00
|
|
|
|
# psdlab output file.
|
|
|
|
|
if (!${^UTF8LOCALE}) {
|
|
|
|
|
say encode($charset,"You are not using UTF-8 encoding. :(");
|
|
|
|
|
}
|
|
|
|
|
my $charset=$ENV{LANG};
|
|
|
|
|
our $outputfilename=decode($charset,$ARGV[0]);
|
|
|
|
|
open $outputfile,'<',$outputfilename or die $!;
|
|
|
|
|
|
|
|
|
|
my $star_linenum_1=0;
|
|
|
|
|
my $star_linenum_2=0;
|
|
|
|
|
my $star_bytenum_1=0;
|
|
|
|
|
my $star_bytenum_2=0;
|
|
|
|
|
|
|
|
|
|
my $linenum=0;
|
|
|
|
|
while(<$outputfile>) {
|
|
|
|
|
$linenum++;
|
|
|
|
|
if ($_ =~ /^\*+$/) {
|
|
|
|
|
$star_linenum_1=$star_linenum_2;
|
2016-06-20 21:04:44 +00:00
|
|
|
|
$star_linenum_2 = $linenum;
|
2016-06-20 18:26:27 +00:00
|
|
|
|
$star_bytenum_1=$star_bytenum_2;
|
2016-06-20 21:04:44 +00:00
|
|
|
|
#$star_bytenum_2 = $outputfile.tell();
|
|
|
|
|
$star_bytenum_2 = tell($outputfile);
|
2016-06-20 18:26:27 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2016-06-29 23:35:02 +00:00
|
|
|
|
if ($debug) {
|
2016-06-20 18:26:27 +00:00
|
|
|
|
say encode($charset,"Final set found between lines "),
|
|
|
|
|
$star_linenum_1,
|
|
|
|
|
" and ",
|
|
|
|
|
$star_linenum_2;
|
|
|
|
|
|
|
|
|
|
say encode($charset,"Final set found between bytes "),
|
|
|
|
|
$star_bytenum_1,
|
|
|
|
|
" and ",
|
|
|
|
|
$star_bytenum_2;
|
|
|
|
|
}
|
|
|
|
|
seek($outputfile,$star_bytenum_1,0);
|
|
|
|
|
<$outputfile>;
|
|
|
|
|
$bin_bounds_line = <$outputfile>;
|
|
|
|
|
#say $bin_bounds_line;
|
|
|
|
|
$bin_bounds_line =~ s/^#\s*(.*)$/$1/;
|
|
|
|
|
#$line =~ /
|
|
|
|
|
@bin_bounds = split /\s/,$bin_bounds_line;
|
2016-06-29 23:35:02 +00:00
|
|
|
|
if ($debug) {
|
2016-06-20 18:26:27 +00:00
|
|
|
|
print encode($charset,"Found bin boundaries: ");
|
|
|
|
|
foreach (@bin_bounds) {print encode($charset,"$_ ");}
|
|
|
|
|
say encode($charset," ");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# This captures the frequency bins.
|
2016-06-21 08:56:27 +00:00
|
|
|
|
our %function_bin = ();
|
|
|
|
|
|
2016-06-20 18:26:27 +00:00
|
|
|
|
my $upper_bound = 0;
|
|
|
|
|
my $lower_bound = 0;
|
|
|
|
|
foreach (@bin_bounds) {
|
|
|
|
|
$lower_bound = $upper_bound;
|
|
|
|
|
$upper_bound = $_;
|
|
|
|
|
if ($lower_bound == 0) {next}
|
2016-06-21 08:56:27 +00:00
|
|
|
|
my $μ = ($upper_bound + $lower_bound)/2;
|
|
|
|
|
my $Δ = ($upper_bound - $lower_bound)/2;
|
|
|
|
|
#say ($μ,":",$Δ);
|
|
|
|
|
# push(@freq_coords_mean,$μ);
|
|
|
|
|
# push(@freq_coords_err,$Δ);
|
|
|
|
|
$function_bin{$μ} = {"Δ" => $Δ};
|
2016-06-20 18:26:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-06-21 08:56:27 +00:00
|
|
|
|
$numbins = keys %function_bin;
|
|
|
|
|
say encode($charset,"$numbins frequency bins captured in output.");
|
2016-06-20 21:04:44 +00:00
|
|
|
|
|
2016-06-29 23:35:02 +00:00
|
|
|
|
if($verbose) {
|
2016-06-21 17:56:59 +00:00
|
|
|
|
say encode($charset,"freq μ freq σ");
|
2016-06-21 08:56:27 +00:00
|
|
|
|
while (each %function_bin ) {
|
2016-06-21 17:56:59 +00:00
|
|
|
|
say encode($charset,
|
|
|
|
|
sprintf("%f %f",$_,$function_bin{$_}{"Δ"}));
|
2016-06-21 08:56:27 +00:00
|
|
|
|
}
|
2016-06-20 21:04:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2016-06-20 18:26:27 +00:00
|
|
|
|
|
|
|
|
|
|
2016-06-21 08:56:27 +00:00
|
|
|
|
=pod
|
2016-06-20 18:26:27 +00:00
|
|
|
|
|
2016-06-21 08:56:27 +00:00
|
|
|
|
This section collects the various quantities. The mode counter
|
|
|
|
|
increments to designate the data being captured.
|
2016-06-20 18:26:27 +00:00
|
|
|
|
|
2016-06-21 08:56:27 +00:00
|
|
|
|
=cut
|
2016-06-20 18:26:27 +00:00
|
|
|
|
|
2016-06-29 23:35:02 +00:00
|
|
|
|
if ($verbose) {
|
2016-06-21 08:56:27 +00:00
|
|
|
|
say encode($charset,"");
|
|
|
|
|
say encode($charset,
|
|
|
|
|
" New Curve -- Source PSD");
|
|
|
|
|
say encode($charset,
|
2016-06-21 17:56:59 +00:00
|
|
|
|
"──────────────────────────────────────────────────");
|
2016-06-21 08:56:27 +00:00
|
|
|
|
}
|
2016-06-20 18:26:27 +00:00
|
|
|
|
|
2016-06-21 08:56:27 +00:00
|
|
|
|
foreach ( sort { $a <=> $b } keys %function_bin ) {
|
|
|
|
|
my $μ = my $σ = <$outputfile>;
|
|
|
|
|
$μ =~ s/^([\-\+e0-9\.]+)+\s+[\-\+e0-9\.]+\s*$/$1/;
|
|
|
|
|
$σ =~ s/^[\-\+e0-9\.]+\s+([\-\+e0-9\.]+)\s*$/$1/;
|
2016-06-21 09:07:31 +00:00
|
|
|
|
# if ($μ<0) {
|
|
|
|
|
# $μ = abs($μ);
|
|
|
|
|
# $function_bin{$_}{"φdiff_μ"} = PI;
|
|
|
|
|
# }
|
2016-06-21 08:56:27 +00:00
|
|
|
|
$function_bin{$_}{"source_PSD_μ"} = $μ;
|
|
|
|
|
$function_bin{$_}{"source_PSD_σ"} = $σ;
|
2016-06-29 23:35:02 +00:00
|
|
|
|
if ($verbose) {
|
2016-06-21 08:56:27 +00:00
|
|
|
|
say encode($charset,
|
2016-06-21 17:56:59 +00:00
|
|
|
|
"freq = " .
|
|
|
|
|
sprintf('%.3f',$_) .
|
|
|
|
|
": μ = " .
|
|
|
|
|
sprintf('%10.3e',$μ) .
|
|
|
|
|
"; σ = " .
|
|
|
|
|
sprintf('%10.3e',$σ));
|
2016-06-21 08:56:27 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2016-06-20 18:26:27 +00:00
|
|
|
|
|
2016-06-29 23:35:02 +00:00
|
|
|
|
if ($verbose) {
|
2016-06-21 08:56:27 +00:00
|
|
|
|
say encode($charset,"");
|
|
|
|
|
say encode($charset,
|
2016-06-21 17:56:59 +00:00
|
|
|
|
" New Curve -- Reprocessed PSD");
|
2016-06-21 08:56:27 +00:00
|
|
|
|
say encode($charset,
|
2016-06-21 17:56:59 +00:00
|
|
|
|
"──────────────────────────────────────────────────");
|
2016-06-21 08:56:27 +00:00
|
|
|
|
}
|
|
|
|
|
foreach ( sort { $a <=> $b } keys %function_bin ) {
|
|
|
|
|
my $μ = my $σ = <$outputfile>;
|
|
|
|
|
$μ =~ s/^([\-\+e0-9\.]+)+\s+[\-\+e0-9\.]+\s*$/$1/;
|
|
|
|
|
$σ =~ s/^[\-\+e0-9\.]+\s+([\-\+e0-9\.]+)\s*$/$1/;
|
2016-06-21 09:07:31 +00:00
|
|
|
|
# if ($μ<0) {
|
|
|
|
|
# $μ = abs($μ);
|
|
|
|
|
# $function_bin{$_}{"φdiff_μ"} = PI;
|
|
|
|
|
# }
|
2016-06-21 08:56:27 +00:00
|
|
|
|
$function_bin{$_}{"reproc_PSD_μ"} = $μ;
|
|
|
|
|
$function_bin{$_}{"reproc_PSD_σ"} = $σ;
|
2016-06-29 23:35:02 +00:00
|
|
|
|
if ($verbose) {
|
2016-06-21 08:56:27 +00:00
|
|
|
|
say encode($charset,
|
2016-06-21 17:56:59 +00:00
|
|
|
|
"freq = " .
|
|
|
|
|
sprintf('%.3f',$_) .
|
|
|
|
|
": μ = " .
|
|
|
|
|
sprintf('%10.3e',$μ) .
|
|
|
|
|
"; σ = " .
|
|
|
|
|
sprintf('%10.3e',$σ));
|
2016-06-21 08:56:27 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2016-06-20 18:26:27 +00:00
|
|
|
|
|
|
|
|
|
|
2016-06-29 23:35:02 +00:00
|
|
|
|
if ($verbose) {
|
2016-06-21 08:56:27 +00:00
|
|
|
|
say encode($charset,"");
|
|
|
|
|
say encode($charset,
|
2016-06-21 17:56:59 +00:00
|
|
|
|
" New Curve -- Cross Spectra PSD");
|
2016-06-21 08:56:27 +00:00
|
|
|
|
say encode($charset,
|
2016-06-21 17:56:59 +00:00
|
|
|
|
"──────────────────────────────────────────────────");
|
2016-06-21 08:56:27 +00:00
|
|
|
|
}
|
|
|
|
|
foreach ( sort { $a <=> $b } keys %function_bin ) {
|
|
|
|
|
my $μ = my $σ = <$outputfile>;
|
|
|
|
|
$μ =~ s/^([\-\+e0-9\.]+)+\s+[\-\+e0-9\.]+\s*$/$1/;
|
|
|
|
|
$σ =~ s/^[\-\+e0-9\.]+\s+([\-\+e0-9\.]+)\s*$/$1/;
|
2016-06-21 09:07:31 +00:00
|
|
|
|
# if ($μ<0) {
|
|
|
|
|
# $μ = abs($μ);
|
|
|
|
|
# $function_bin{$_}{"φdiff_μ"} = PI;
|
|
|
|
|
# }
|
2016-06-21 08:56:27 +00:00
|
|
|
|
$function_bin{$_}{"cc_PSD_μ"} = $μ;
|
|
|
|
|
$function_bin{$_}{"cc_PSD_σ"} = $σ;
|
2016-06-29 23:35:02 +00:00
|
|
|
|
if ($verbose) {
|
2016-06-21 08:56:27 +00:00
|
|
|
|
say encode($charset,
|
2016-06-21 17:56:59 +00:00
|
|
|
|
"freq = " .
|
|
|
|
|
sprintf('%.3f',$_) .
|
|
|
|
|
": μ = " .
|
|
|
|
|
sprintf('%10.3e',$μ) .
|
|
|
|
|
"; σ = " .
|
|
|
|
|
sprintf('%10.3e',$σ));
|
2016-06-21 08:56:27 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2016-06-20 18:26:27 +00:00
|
|
|
|
|
2016-06-29 23:35:02 +00:00
|
|
|
|
if ($verbose) {
|
2016-06-21 08:56:27 +00:00
|
|
|
|
say encode($charset,"");
|
|
|
|
|
say encode($charset,
|
2016-06-21 17:56:59 +00:00
|
|
|
|
" New Curve -- Phase Difference φ");
|
2016-06-21 08:56:27 +00:00
|
|
|
|
say encode($charset,
|
2016-06-21 17:56:59 +00:00
|
|
|
|
"──────────────────────────────────────────────────");
|
2016-06-21 08:56:27 +00:00
|
|
|
|
}
|
|
|
|
|
foreach ( sort { $a <=> $b } keys %function_bin ) {
|
|
|
|
|
my $μ = my $σ = <$outputfile>;
|
|
|
|
|
$μ =~ s/^([\-\+e0-9\.]+)+\s+[\-\+e0-9\.]+\s*$/$1/;
|
|
|
|
|
$σ =~ s/^[\-\+e0-9\.]+\s+([\-\+e0-9\.]+)\s*$/$1/;
|
|
|
|
|
if (exists $function_bin{$_}{"φdiff_μ"}) {
|
|
|
|
|
$μ = $function_bin{$_}{"φdiff_μ"} + $μ;
|
|
|
|
|
}
|
|
|
|
|
$function_bin{$_}{"φdiff_μ"} = $μ;
|
|
|
|
|
$function_bin{$_}{"φdiff_σ"} = $σ;
|
2016-06-29 23:35:02 +00:00
|
|
|
|
if ($verbose) {
|
2016-06-21 08:56:27 +00:00
|
|
|
|
say encode($charset,
|
2016-06-21 17:56:59 +00:00
|
|
|
|
"freq = " .
|
|
|
|
|
sprintf('%.3f',$_) .
|
|
|
|
|
": μ = " .
|
|
|
|
|
sprintf('%10.3e',$μ) .
|
|
|
|
|
"; σ = " .
|
|
|
|
|
sprintf('%10.3e',$σ));
|
|
|
|
|
}
|
|
|
|
|
$μ = $μ/(2*PI*$_);
|
|
|
|
|
$σ = $σ/(2*PI*$_);
|
|
|
|
|
$function_bin{$_}{"timelag_μ"} = $μ;
|
|
|
|
|
$function_bin{$_}{"timelag_σ"} = $σ;
|
2016-06-29 23:35:02 +00:00
|
|
|
|
if ($verbose) {
|
2016-06-21 17:56:59 +00:00
|
|
|
|
say encode($charset,
|
|
|
|
|
" timelag: μ = " .
|
|
|
|
|
sprintf('%10.3e',$μ) .
|
|
|
|
|
"; σ = " .
|
|
|
|
|
sprintf('%10.3e',$σ)) .
|
|
|
|
|
"\n";
|
2016-06-21 08:56:27 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2016-06-20 18:26:27 +00:00
|
|
|
|
|
2016-06-21 08:56:27 +00:00
|
|
|
|
say encode($charset,"");
|
2016-06-20 18:26:27 +00:00
|
|
|
|
|
2016-06-29 23:35:02 +00:00
|
|
|
|
if($debug) {
|
2016-06-21 08:56:27 +00:00
|
|
|
|
while (each %function_bin ) {
|
|
|
|
|
print encode($charset,$_ . ": ");
|
|
|
|
|
while ( my ($key,$value) = each %{$function_bin{$_}} ) {
|
|
|
|
|
print encode($charset,$key . " => " . $value . "; ");
|
|
|
|
|
}
|
|
|
|
|
say encode($charset,"");
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-06-20 18:26:27 +00:00
|
|
|
|
|
2016-06-21 08:56:27 +00:00
|
|
|
|
close($outputfile);
|
2016-06-20 18:26:27 +00:00
|
|
|
|
|
2016-06-21 08:56:27 +00:00
|
|
|
|
open($datafile,'>',"tmp.sourcePSD") or die $!;
|
|
|
|
|
while( each %function_bin) {
|
|
|
|
|
say $datafile
|
|
|
|
|
$_ . " " .
|
|
|
|
|
$function_bin{$_}{"source_PSD_μ"} . " " .
|
|
|
|
|
$function_bin{$_}{"Δ"} . " " .
|
|
|
|
|
$function_bin{$_}{"source_PSD_σ"};
|
|
|
|
|
}
|
|
|
|
|
close($datafile);
|
2016-06-20 18:26:27 +00:00
|
|
|
|
|
2016-06-21 08:56:27 +00:00
|
|
|
|
open($datafile,'>',"tmp.reprocPSD") or die $!;
|
|
|
|
|
while( each %function_bin) {
|
|
|
|
|
say $datafile
|
|
|
|
|
$_ . " " .
|
|
|
|
|
$function_bin{$_}{"reproc_PSD_μ"} . " " .
|
|
|
|
|
$function_bin{$_}{"Δ"} . " " .
|
|
|
|
|
$function_bin{$_}{"reproc_PSD_σ"};
|
|
|
|
|
}
|
|
|
|
|
close($datafile);
|
|
|
|
|
|
|
|
|
|
open($datafile,'>',"tmp.ccPSD") or die $!;
|
|
|
|
|
while( each %function_bin) {
|
|
|
|
|
say $datafile
|
|
|
|
|
$_ . " " .
|
|
|
|
|
$function_bin{$_}{"cc_PSD_μ"} . " " .
|
|
|
|
|
$function_bin{$_}{"Δ"} . " " .
|
|
|
|
|
$function_bin{$_}{"cc_PSD_σ"};
|
|
|
|
|
}
|
|
|
|
|
close($datafile);
|
2016-06-20 18:26:27 +00:00
|
|
|
|
|
2016-06-21 17:56:59 +00:00
|
|
|
|
open($datafile,'>',"tmp.timelag") or die $!;
|
|
|
|
|
while( each %function_bin) {
|
|
|
|
|
say $datafile
|
|
|
|
|
$_ . " " .
|
|
|
|
|
$function_bin{$_}{"timelag_μ"} . " " .
|
|
|
|
|
$function_bin{$_}{"Δ"} . " " .
|
|
|
|
|
$function_bin{$_}{"timelag_σ"};
|
|
|
|
|
}
|
|
|
|
|
close($datafile);
|
2016-06-20 18:26:27 +00:00
|
|
|
|
|
|
|
|
|
|
2016-06-21 08:56:27 +00:00
|
|
|
|
#open($datafile,'>',"tmp.reprocPSD") or die $!;
|