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";
67 my $arg = shift @ARGV;
70 } elsif ($arg eq '-e') {
72 } elsif ($arg eq '-c') {
74 } elsif ($arg =~ /^-/) {
75 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";
77 open (IN, $arg) or die "cannot open $arg (!$)";
93 if ($state == 0 && /^Decode/i) {
95 } elsif ($state == 1) {
97 next if m{^To\s+all}i;
102 $ref = $keps{$name} = {};
105 } elsif ($state == 2) {
107 my ($id, $number, $epoch, $decay, $mm2, $bstar, $elset) = unpack "xxa5xxa5xxxa15xa10xa8xa8xxxa4x", $_;
108 $ref->{id} = $id - 0;
109 $ref->{number} = $number - 0;
110 $ref->{epoch} = $epoch - 0;
111 $ref->{mm1} = $decay - 0;
112 $ref->{mm2} = genenum($mm2);
113 $ref->{bstar} = genenum($bstar);
114 $ref->{elset} = $elset - 0;
115 #print "$id $number $epoch $decay $mm2 $bstar $elset\n";
116 #print "mm2: $ref->{mm2} bstar: $ref->{bstar}\n";
120 #print "out of order on line $line\n";
125 } elsif ($state == 3) {
127 my ($id, $incl, $raan, $ecc, $peri, $man, $mmo, $orbit) = unpack "xxa5xa8xa8xa7xa8xa8xa11a5x", $_;
128 $ref->{meananomaly} = $man - 0;
129 $ref->{meanmotion} = $mmo - 0;
130 $ref->{inclination} = $incl - 0;
131 $ref->{eccentricity} = ".$ecc" - 0;
132 $ref->{argperigee} = $peri - 0;
133 $ref->{raan} = $raan - 0;
134 $ref->{orbit} = $orbit - 0;
137 #print "out of order on line $line\n";
146 my $dd = new Data::Dumper([\%keps], [qw(*keps)]);
149 open(OUT, ">$fn") or die "$fn $!";
150 print OUT "#\n# this file is automatically produced by convkeps.pl\n#\n";
151 print OUT "# Last update: ", scalar gmtime, "\n#\n";
152 print OUT "\npackage Sun;\n\n";
153 print OUT $dd->Dumpxs;
158 print "$count keps converted\n";
159 exit($count ? 0 : -1);
162 # convert (+/-)00000-0 to (+/-).00000e-0
165 my ($sign, $frac, $esign, $exp) = unpack "aa5aa", shift;
166 $esign = '+' if $esign eq ' ';
167 my $n = $sign . "." . $frac . 'e' . $esign . $exp;