3
# See POD docs at end of this file for genereal info
11
use constant PROG_DESCRIPTION => "asteroid orbital elements converter";
12
use constant PROG_COPYRIGHT => "(C) 2007; released under the GNU GPL version 2";
13
use constant PROG_VERSION => "0.02";
14
use constant PROG_AUTHOR => "Matthew Gates";
16
my $this_script = basename($0);
20
my $gs_flg_data_url = "http://hamilton.dm.unipi.it/astdys/catalogs/allnum.cat";
21
my $gs_flg_name_url = "http://cfa-www.harvard.edu/iau/lists/MPNames.html";
22
my $gs_flg_id_list = "1-10";
23
my $gs_flg_data_age = 3600 * 24 * 30; # only fetch data if current files older than 1 month
25
# process command line options. Praise Bob, I love Getopt::Long!
27
'all' => \$gs_flg_all,
28
'data-url=s' => \$gs_flg_data_url,
29
'force-refresh' => sub { $gs_flg_data_age = 0; },
30
'help' => sub { usage(0,1) },
31
'ids=s' => \$gs_flg_id_list,
32
'name-url=s' => \$gs_flg_name_url,
33
'version' => sub { version_message(); exit 0; },
36
# some globals. yeah yeah, so sue me.
37
my @ga_field_order = (qw(Epoch SemiMajorAxis Eccentricity Inclination AscendingNode ArgOfPericenter MeanAnomaly mag albedo));
38
my %gh_names; # key is asteroid ID
39
my %gh_data; # key is asteroid ID
40
my %gh_selection; # list of IDs which we want
41
my $gs_selection_max = 0;
42
my $gs_data_filename = "../builds/asteroid_orbits.dat";
43
my $gs_name_filename = "../builds/asteroid_names.dat";
44
my $gs_unknown_name_counter = 0;
46
if ( ! $gs_flg_all ) {
47
foreach my $i (split(",", $gs_flg_id_list)) {
48
# handle ranges if necessary
49
my ($l, $u); # lower and upper range values
50
if ( $i =~ /^\d+$/ ) { $l = $i; $u = $i; }
51
elsif ( $i =~ /^(\d+)-(\d+)$/ ) { $l = $1; $u = $2; }
54
for(my $n=$l; $n<=$u; $n++) {
55
$gh_selection{$n} = 1;
56
if ( $n > $gs_selection_max ) { $gs_selection_max = $n; }
61
download_data_files();
66
###############################################################################
68
###############################################################################
70
my $level = shift || 0;
71
my $verbose = shift || 0;
73
if ( $level !~ /^\d+$/ ) { die "argument must be integer"; }
76
if ( $verbose ) { $cmd = "pod2usage -verbose 1 $this_script"; }
77
else { $cmd = "pod2usage $this_script"; }
79
open(CMD, "$cmd|") || die "error executing $cmd: $!";
80
while(<CMD>) { print; }
86
if ( ! defined(&PROG_DESCRIPTION) ) {
87
warn "You should define the constant PROG_DESCRIPTION in your program\n";
89
print &PROG_DESCRIPTION . " ";
92
if ( ! defined(&PROG_VERSION) ) {
93
warn "You should define the constant PROG_VERSION in your program\n";
95
print &PROG_VERSION . "\n";
98
if ( ! defined(&PROG_COPYRIGHT) ) {
99
warn "You should define the constant PROG_COPYRIGHT in your program\n";
101
print &PROG_COPYRIGHT . "\n";
104
if ( defined(&PROG_AUTHOR) ) {
105
print "Written by " . &PROG_AUTHOR . "\n";
109
sub download_data_files {
111
my @statinfo = stat($gs_data_filename);
112
if ( ! defined($statinfo[9]) ) { $download = 1; }
113
elsif ( time - $statinfo[9] > $gs_flg_data_age ) { $download = 1; }
115
system("curl '$gs_flg_data_url' > '$gs_data_filename'") && die "cannot download $gs_flg_data_url";
118
print STDERR "No need to download $gs_data_filename - we have a recent copy locally\n";
122
@statinfo = stat($gs_name_filename);
123
if ( ! defined($statinfo[9]) ) { $download = 1; }
124
elsif ( time - $statinfo[9] > $gs_flg_data_age ) { $download = 1; }
126
system("curl '$gs_flg_name_url' > '$gs_name_filename'") && die "cannot download $gs_flg_name_url : $!";
129
print STDERR "No need to download $gs_name_filename - we have a recent copy locally\n";
135
open(DATA, "<$gs_data_filename") || die "cannot open data file for reading : $!";
138
if (/END_OF_HEADER/) {
142
if ($header) { next };
145
if (/^\s*\!/) { next };
148
my($id, @data) = unpack("A10 A17 A25 A25 A25 A25 A25 A25 A6 A6", $_);
150
if ( $id > $gs_selection_max && ! $gs_flg_all ) { last; }
152
if ( ! defined($gh_selection{$id}) && ! $gs_flg_all ) { next; }
155
for(my $i=0; $i<=$#ga_field_order; $i++) {
156
$data[$i] =~ s/^\s+//;
157
$data[$i] =~ s/\s+$//;
158
$datahash{$ga_field_order[$i]} = $data[$i];
160
$gh_data{$id} = \%datahash;
166
open(NAMES, "<$gs_name_filename") || die "cannot open name file for reading : $!";
174
if ( ! $in_pre ) { next; }
176
if ( /<\/pre>/ ) { last; }
183
my(undef, $id, $name) = split(/[\(\)]/, $_);
185
if ( defined($gh_data{$id}) ) {
188
$gh_names{$id} = $name;
194
foreach my $id (sort {$a <=> $b} keys %gh_data) {
196
if (defined($gh_names{$id})) {
197
$name = $gh_names{$id};
200
$name = "unknown_name_$gs_unknown_name_counter";
201
$gs_unknown_name_counter++;
203
printf "[%s]\n", lc($name);
204
print "name = $name\n";
205
print "parent = Sun\n";
206
print "oblateness = 0.0\n";
207
print "color = 1.0,1.0,1.0\n";
208
print "coord_func = comet_orbit\n";
209
print "halo = false\n";
210
print "lighting = false\n";
211
print "tex_halo = star16x16.png\n";
212
print "radius = 25\n";
213
print "tex_map = nomap.png\n";
214
my $sp = (($gh_data{$id}{"SemiMajorAxis"} ** 3) ** 0.5) * 365.256363051;
215
print "sidereal_period = $sp\n";
216
foreach my $field (reverse sort @ga_field_order) {
218
if ($field eq "mag") { next; }
219
elsif ($field ne "albedo") { $prefix = "orbit_"; }
221
my $val = sprintf("%.15f", $gh_data{$id}{$field});
223
printf "%s%s = %s\n", $prefix, $field, $val;
234
generate_asteroid_ssystem.pl - generate asteroid orbital data for ssystem.ini
238
generate_asteroid_ssystem.pl [options]
242
Downloads asteroid data and outputs sections intended for use in the Stellarium data file, ssystem.ini.
250
Select all asteroids for output. Note this is a lot and will
253
=item B<--data-url>=I<u>
255
Fetch orbital data from url I<u>. The default is
256
http://hamilton.dm.unipi.it/astdys/catalogs/allnum.cat
258
=item B<--force-refresh>
260
Fetch orbital and name data even if the files are less than a month old.
264
Print the command line syntax an option details.
268
Specify the list of asteroid IDs to output. This is a comma separated list of numbers or ranges of numbers, e.g.
272
Would select asteroids with numbers 1, 3, 4, 5, 6, and 12. The default is 1-10.
274
=item B<--name-url>=I<u>
276
Fetch name data from url I<u>. The default is
277
http://cfa-www.harvard.edu/iau/lists/MPNames.html
281
Print the program description and version.
289
=item STUFF_?_DBLEVEL
291
Sets debugging levels. The ? can be D for database, M for module,
292
or S for script debugging messages. Generally only S and D are
293
interesting for users, M is mostly just used during development.
309
generate_asteroid_ssystem.pl is released under the GNU GPL (version 2, June 1991). A
310
copy of the license should have been provided in the distribution of
311
the software in a file called "LICENSE". If you can't find this, then
312
try here: http://www.gnu.org/copyleft/gpl.html
316
Matthew Gates <matthew@porpoisehead.net>
318
http://porpoisehead.net/
324
=item Date:2007-05-29 Created, Author MNG
328
=item Date:2007-11-06 Bug fixes, Author MNG
330
Download error status fixed. Fixed --all option. Fixed undefined name error.
336
Please report bugs to the author.