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";
65 my $arg = shift @ARGV;
68 } elsif ($arg eq '-e') {
70 } elsif ($arg eq '-c') {
72 } elsif ($arg =~ /^-/) {
73 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";
75 open (IN, $arg) or die "cannot open $arg (!$)";
89 if ($state == 0 && /^TO ALL/) {
91 } elsif ($state == 1) {
97 $ref = $keps{$name} = {};
100 } elsif ($state == 2) {
102 my ($id, $number, $epoch, $decay, $mm2, $bstar, $elset) = unpack "xxa5xxa5xxxa15xa10xa8xa8xxxa4x", $_;
103 $ref->{id} = $id - 0;
104 $ref->{number} = $number - 0;
105 $ref->{epoch} = $epoch - 0;
106 $ref->{mm1} = $decay - 0;
107 $ref->{mm2} = genenum($mm2);
108 $ref->{bstar} = genenum($bstar);
109 $ref->{elset} = $elset - 0;
110 #print "$id $number $epoch $decay $mm2 $bstar $elset\n";
111 #print "mm2: $ref->{mm2} bstar: $ref->{bstar}\n";
115 print "out of order on line $line\n";
120 } elsif ($state == 3) {
122 my ($id, $incl, $raan, $ecc, $peri, $man, $mmo, $orbit) = unpack "xxa5xa8xa8xa7xa8xa8xa11a5x", $_;
123 $ref->{meananomaly} = $man - 0;
124 $ref->{meanmotion} = $mmo - 0;
125 $ref->{inclination} = $incl - 0;
126 $ref->{eccentricity} = ".$ecc" - 0;
127 $ref->{argperigee} = $peri - 0;
128 $ref->{raan} = $raan - 0;
129 $ref->{orbit} = $orbit - 0;
131 print "out of order on line $line\n";
139 my $dd = new Data::Dumper([\%keps], [qw(*keps)]);
142 open(OUT, ">$fn") or die "$fn $!";
143 print OUT "#\n# this file is automatically produced by convkeps.pl\n#\n";
144 print OUT "# Last update: ", scalar gmtime, "\n#\n";
145 print OUT "\npackage Sun;\n\n";
146 print OUT $dd->Dumpxs;
151 # convert (+/-)00000-0 to (+/-).00000e-0
154 my ($sign, $frac, $esign, $exp) = unpack "aa5aa", shift;
155 $esign = '+' if $esign eq ' ';
156 my $n = $sign . "." . $frac . 'e' . $esign . $exp;