diff options
author | fishsoupisgood <github@madingley.org> | 2019-05-04 12:37:04 +0100 |
---|---|---|
committer | fishsoupisgood <github@madingley.org> | 2019-05-04 12:39:08 +0100 |
commit | 74e577ac110513669a6d677842ceca4c5b1252ca (patch) | |
tree | cfe45c037717a740fa2fa6b1c99aa66814047055 /app/parse_alamanc.pl | |
parent | 1b0a5f886412f0a292ec2b198e65760e3a1f45a1 (diff) | |
download | clock-74e577ac110513669a6d677842ceca4c5b1252ca.tar.gz clock-74e577ac110513669a6d677842ceca4c5b1252ca.tar.bz2 clock-74e577ac110513669a6d677842ceca4c5b1252ca.zip |
cut #1
Diffstat (limited to 'app/parse_alamanc.pl')
-rwxr-xr-x | app/parse_alamanc.pl | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/app/parse_alamanc.pl b/app/parse_alamanc.pl new file mode 100755 index 0000000..ee946b7 --- /dev/null +++ b/app/parse_alamanc.pl @@ -0,0 +1,91 @@ +#!/usr/bin/env perl + +use strict; +use Data::Dumper; +use Math::Trig; + + + +sub rad_to_ss($) +{ +my $r=shift; +return undef unless defined $r; +return $r/pi; +} + + +sub rad_to_d_ss($) +{ +my $r=shift; +return undef unless defined $r; +return ($r/pi)-0.3; +} + + +sub squirt_bits($$$) +{ +my ($v,$n,$s)=@_; + +#die unless defined $v; + +$s=2.0**-$s; + +my $i=int(($v*$s) +.5); + +my $m=1 << $n; +if ($i<0) { + $i+=$m; +} + +print "v=$v became 0<=$i<$m\n"; + +my $b=reverse(sprintf ("%0".$n."B",$i)); + +return $b ." "; +} + + + +sub process_sv($) +{ +my $h=shift; +my $a=""; + + +$a.=squirt_bits($h->{'ID'},32,0); +$a.=squirt_bits($h->{'week'},32,0); +$a.=squirt_bits($h->{'Eccentricity'},16,-21); +$a.=squirt_bits($h->{'Time of Applicability(s)'},8,12); + + +$a.=squirt_bits(rad_to_d_ss($h->{'Orbital Inclination(rad)'}),16,-19); +$a.=squirt_bits(rad_to_ss($h->{'Rate of Right Ascen(r/s)'}),16,-38); +$a.=squirt_bits($h->{'SQRT(A) (m 1/2)'},16,-11); +$a.=squirt_bits(rad_to_ss($h->{'Right Ascen at Week(rad)'}),24,-23); +$a.=squirt_bits(rad_to_ss($h->{'Argument of Perigee(rad)'}),24,-23); +$a.=squirt_bits(rad_to_ss($h->{'Mean Anom(rad)'}),24,-23); +$a.=squirt_bits($h->{'Af0(s)'},11,-20); +$a.=squirt_bits($h->{'Af1(s/s)'},11,-38); + + +print Dumper($h); +} + + + +my $hash={}; + + +while (<>) { +chomp; + +if (/^\*{5}/) { + process_sv($hash); + $hash={}; +} elsif (/^([^:]+):\s*([^\r\n]+)[\r\n]*$/) { + $hash->{$1}=$2; +} +} + + + |