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. If you update it manually
12 # load/keps will load the latest version into the cluster
14 # This program is designed to be called from /etc/aliases or
15 # a .forward file so you can get yourself on the keps mailing
16 # list from AMSAT and have the keps updated automatically once
19 # I will distribute the latest keps with every patch but you can
20 # get your own data from:
22 # http://www.amsat.org/amsat/ftp/keps/current/nasa.all
24 # Please note that this will UPDATE your keps file
27 # email | convkeps.pl (in amsat email format)
28 # convkeps.pl -p keps.in (a file with just plain keps)
30 # if you add the -c flag then the %keps hash will be cleared down
31 # before adding the new ones.
33 # Copyright (c) 2000 Dirk Koopman G1TLH
41 # search local then perl directories
43 # root of directory tree for this system
45 $root = $ENV{'DXSPIDER_ROOT'} if $ENV{'DXSPIDER_ROOT'};
47 unshift @INC, "$root/perl"; # this IS the right way round!
48 unshift @INC, "$root/local";
52 use vars qw($root %keps);
57 my $fn = "$root/local/Keps.pm";
75 my $arg = shift @ARGV;
78 } elsif ($arg eq '-e') {
80 } elsif ($arg eq '-c') {
82 } elsif ($arg =~ /^-/) {
83 die "Usage: convkeps.pl [-c] [-e|-p] [<filename>]\n\t-p - plain file just containing keps\n\t-e - amsat email format input file (default)\n\t-c - clear Keps data before adding this lot\n";
85 open (IN, $arg) or die "cannot open $arg (!$)";
101 if ($state == 0 && /^Decode/i) {
103 } elsif ($state == 1) {
105 next if m{^To\s+all}i;
107 if (/^([- \w]+)(?:\s+\[[-+\w]\])?$/) {
112 $ref = $keps{$name} = {};
115 } elsif ($state == 2) {
117 my ($id, $number, $epoch, $decay, $mm2, $bstar, $elset) = unpack "xxa5xxa5xxxa15xa10xa8xa8xxxa4x", $_;
118 $ref->{id} = $id - 0;
119 $ref->{number} = $number - 0;
120 $ref->{epoch} = $epoch - 0;
121 $ref->{mm1} = $decay - 0;
122 $ref->{mm2} = genenum($mm2);
123 $ref->{bstar} = genenum($bstar);
124 $ref->{elset} = $elset - 0;
125 #print "$id $number $epoch $decay $mm2 $bstar $elset\n";
126 #print "mm2: $ref->{mm2} bstar: $ref->{bstar}\n";
130 #print "out of order on line $line\n";
135 } elsif ($state == 3) {
137 my ($id, $incl, $raan, $ecc, $peri, $man, $mmo, $orbit) = unpack "xxa5xa8xa8xa7xa8xa8xa11a5x", $_;
138 $ref->{meananomaly} = $man - 0;
139 $ref->{meanmotion} = $mmo - 0;
140 $ref->{inclination} = $incl - 0;
141 $ref->{eccentricity} = ".$ecc" - 0;
142 $ref->{argperigee} = $peri - 0;
143 $ref->{raan} = $raan - 0;
144 $ref->{orbit} = $orbit - 0;
147 #print "out of order on line $line\n";
156 my $dd = new Data::Dumper([\%keps], [qw(*keps)]);
159 open(OUT, ">$fn") or die "$fn $!";
160 print OUT "#\n# this file is automatically produced by convkeps.pl\n#\n";
161 print OUT "# Last update: ", scalar gmtime, "\n#\n";
162 print OUT "\npackage Sun;\n\n";
163 print OUT $dd->Dumpxs;
168 print "$count keps converted\n";
169 exit($count ? 0 : -1);
172 # convert (+/-)00000-0 to (+/-).00000e-0
175 my ($sign, $frac, $esign, $exp) = unpack "aa5aa", shift;
176 $esign = '+' if $esign eq ' ';
177 my $n = $sign . "." . $frac . 'e' . $esign . $exp;