3 # Convert an Amsat 2 line keps bull into Sun.pm format
5 # This program will accept on stdin a standard AMSAT 2 line keps
6 # bull such as you would find in an email or from the packet network
8 # It will write a file called /spider/local/Keps.pm, this means that
9 # the latest version will be read in every time you restart the
10 # cluster.pl. You can also call Sun::load from a cron line if
11 # you like to re-read it automatically.
13 # This program is designed to be called from /etc/aliases or
14 # a .forward file so you can get yourself on the keps mailing
15 # list from AMSAT and have the keps updated automatically once
18 # I will distribute the latest keps with every patch but you can
19 # get your own data from:
21 # http://www.amsat.org/amsat/ftp/keps/current/nasa.all
23 # Copyright (c) 2000 Dirk Koopman G1TLH
30 # search local then perl directories
32 # root of directory tree for this system
34 $root = $ENV{'DXSPIDER_ROOT'} if $ENV{'DXSPIDER_ROOT'};
36 unshift @INC, "$root/perl"; # this IS the right way round!
37 unshift @INC, "$root/local";
45 my $fn = "$root/local/Keps.pm";
61 if ($state == 0 && /^TO ALL/) {
63 } elsif ($state == 1) {
69 $ref = $keps{$name} = {};
72 } elsif ($state == 2) {
74 my ($id, $number, $epoch, $decay, $mm2, $bstar, $elset) = unpack "xxa5xxa5xxxa15xa10xa8xa8xxxa4x", $_;
76 $ref->{number} = $number - 0;
77 $ref->{epoch} = $epoch - 0;
78 $ref->{mm1} = $decay - 0;
79 $ref->{mm2} = genenum($mm2);
80 $ref->{bstar} = genenum($bstar);
81 $ref->{elset} = $elset - 0;
82 # print "$id $number $epoch $decay $mm2 $bstar $elset\n";
83 # print "mm2: $ref->{mm2} bstar: $ref->{bstar}\n";
87 print "out of order on line $line\n";
92 } elsif ($state == 3) {
94 my ($id, $incl, $raan, $ecc, $peri, $man, $mmo, $orbit) = unpack "xxa5xa8xa8xa7xa8xa8xa11a5x", $_;
95 $ref->{meananomaly} = $man - 0;
96 $ref->{meanmotion} = $mmo - 0;
97 $ref->{inclination} = $incl - 0;
98 $ref->{eccentricity} = ".$ecc" - 0;
99 $ref->{argperigee} = $peri - 0;
100 $ref->{raan} = $raan - 0;
101 $ref->{orbit} = $orbit - 0;
103 print "out of order on line $line\n";
111 my $dd = new Data::Dumper([\%keps], [qw(*keps)]);
114 open(OUT, ">$fn") or die "$fn $!";
115 print OUT "#\n# this file is automatically produced by convkeps.pl\n#\n";
116 print OUT "\npackage Sun;\n\n";
117 print OUT $dd->Dumpxs;
122 # convert (+/-)00000-0 to (+/-).00000e-0
125 my ($sign, $frac, $esign, $exp) = unpack "aa5aa", shift;
126 my $n = $sign . "." . $frac . 'e' . $esign . $exp;