From 74e577ac110513669a6d677842ceca4c5b1252ca Mon Sep 17 00:00:00 2001 From: fishsoupisgood Date: Sat, 4 May 2019 12:37:04 +0100 Subject: cut #1 --- app/parse_alamanc.pl | 91 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100755 app/parse_alamanc.pl (limited to 'app/parse_alamanc.pl') 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; +} +} + + + -- cgit v1.2.3