summaryrefslogtreecommitdiffstats
path: root/app/parse_alamanc.pl
blob: ee946b7dcf918d96292ce2de68bcc7145632bae2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
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;
}
}