~ubuntu-branches/debian/squeeze/stellarium/squeeze

« back to all changes in this revision

Viewing changes to util/parse_hip.pl

  • Committer: Bazaar Package Importer
  • Author(s): Cédric Delfosse
  • Date: 2008-05-19 21:28:23 UTC
  • mfrom: (3.1.5 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080519212823-m5nfiuntxstxzxj7
Tags: 0.9.1-4
Add libxcursor-dev, libxfixes-dev, libxinerama-dev, libqt4-opengl-dev to
build-deps (Closes: #479906)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/perl
 
2
 
 
3
# Creates hipparcos data file for use with Stellarium
 
4
# from source hip_main.dat data file available at
 
5
# http://cdsweb.u-strasbg.fr/viz-bin/Cat?I/239
 
6
 
 
7
# Copyright 2005 Robert Spearman
 
8
#
 
9
# This program is free software; you can redistribute it and/or
 
10
# modify it under the terms of the GNU General Public License
 
11
# as published by the Free Software Foundation; either version 2
 
12
# of the License, or (at your option) any later version.
 
13
 
14
# This program is distributed in the hope that it will be useful,
 
15
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
16
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
17
# GNU General Public License for more details.
 
18
 
19
# You should have received a copy of the GNU General Public License
 
20
# along with this program; if not, write to the Free Software
 
21
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
22
 
 
23
print "\nConverting hip_main.dat to hipparcos.fab\n\n";
 
24
print "WARNING: This script has only been tested on x86 Linux.\n";
 
25
print "It may produce incorrect results on other platforms.\n\n";
 
26
 
 
27
sleep 2;
 
28
 
 
29
open(IN, "hip_main.dat") || die "Can't find hip_main.dat\n";
 
30
open(OUT, ">hipparcos.fab") || die "Can't write hipparcos.fab\n";
 
31
 
 
32
my $dmin = 1000000000000;
 
33
my $dmax = 0;
 
34
 
 
35
while(<IN>) {
 
36
 
 
37
        chomp;
 
38
        $_ =~ s/\|/\t/g;
 
39
        @f = split('\t', $_);
 
40
 
 
41
#       print("$f[1] : $f[3] : $f[4] : $f[5] : $f[76]\n");
 
42
 
 
43
        $hp = $f[1];
 
44
        $mag = $f[5];
 
45
 
 
46
        if($hp > $high) { $high = $hp; }  # data isn't contiguous...
 
47
 
 
48
        # ra and de in hms
 
49
        if( $f[3] =~ /(\-*)(\d\d) (\d\d) (\d\d\.\d\d)/ ) {
 
50
                $ra = $2 + $3/60 + $4/3600;
 
51
                if($1 eq "-") { $ra *= -1; }
 
52
        } else {
 
53
                print "error with ra on hp $hp\n";
 
54
                next;
 
55
        }
 
56
 
 
57
        if( $f[4] =~ /(\-*)(\d\d) (\d\d) (\d\d.\d)/ ) {
 
58
                $de = $2 + $3/60 + $4/3600;
 
59
                if($1) { $de *= -1; }
 
60
        } else {
 
61
                print "error with de on hp $hp\n";
 
62
                next;
 
63
        }
 
64
 
 
65
        $f[76] =~/^(.)(.)/;
 
66
 
 
67
        if( $1 eq "0") { 
 
68
                $sptype = 0; 
 
69
        } elsif($1 eq "B") {
 
70
                $sptype = 1;
 
71
        } elsif($1 eq "A") {
 
72
                $sptype = 2;
 
73
        } elsif($1 eq "F") { 
 
74
                $sptype = 3;
 
75
        } elsif($1 eq "G") { 
 
76
                $sptype = 4;
 
77
        } elsif($1 eq "K") { 
 
78
                $sptype = 5;
 
79
        } elsif($1 eq "M") { 
 
80
                $sptype = 6;
 
81
        } elsif($1 eq "R") { 
 
82
                $sptype = 7;
 
83
        } elsif($1 eq "S") { 
 
84
                $sptype = 8;
 
85
        } elsif($1 eq "N") { 
 
86
                $sptype = 9;
 
87
        } elsif($1 eq "W") {
 
88
                if($2 eq "N") {
 
89
                        $sptype = 10;
 
90
                } else {
 
91
                        $sptype = 11;
 
92
                }
 
93
        } else {
 
94
                $sptype = 12;
 
95
        }
 
96
        
 
97
        $spcode = $1;
 
98
        if($sptype == 11) {
 
99
                $spcode = "X";
 
100
        } elsif($sptype == 12) {
 
101
                $spcode = "?";
 
102
        }
 
103
 
 
104
#       print "$hp\t$ra\t$de\t$f[5]\t$f[76] ($sptype)\n";
 
105
 
 
106
        $x = 256*$mag;
 
107
 
 
108
#       printf( "%d\t%d\t%.4f\t%.4f\t%s\n", $hp, $x, $ra, $de, $spcode);
 
109
 
 
110
        # distance
 
111
        if($f[11]==0) {
 
112
                $ly = 0;
 
113
                print "No parallax for hp $hp\n";
 
114
        } else {
 
115
                $ly = abs(3.2616/($f[11]/1000));
 
116
 
 
117
                if($ly<$dmin) {$dmin = $ly;}
 
118
                if($ly>$dmax) {$dmax = $ly;}
 
119
        }
 
120
 
 
121
 
 
122
        $out{int($hp)} = pack("ffSCf", $ra, $de, $x, $sptype, $ly);
 
123
#       $out{int($hp)} = pack("ffSxC", $ra, $de, $x, $sptype);
 
124
 
 
125
 
 
126
}
 
127
 
 
128
 
 
129
# catalog size
 
130
 
 
131
print "Highest hp = $high\n";
 
132
print "ly min: $dmin\tlymax: $dmax\n";
 
133
 
 
134
print OUT pack("L", $high+1);  # hp numbers start at 1
 
135
 
 
136
# data isn't sorted or contiguous in source file!
 
137
for( $a=0; $a<=$high; $a++) {
 
138
 
 
139
        if($out{$a} eq "" ) {
 
140
                print OUT pack("xxxxxxxxxxxxxxx");
 
141
        } else {
 
142
                print OUT $out{$a};
 
143
        }
 
144
 
 
145
}