~vcs-imports/stellarium/0.8

« back to all changes in this revision

Viewing changes to util/parse_hip.pl

  • Committer: digitalises
  • Date: 2005-07-24 18:21:33 UTC
  • Revision ID: Arch-1:unnamed@bazaar.ubuntu.com%series--4386--patch-737
Added script to generate hipparcos.fab to new util directory

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
while(<IN>) {
 
33
 
 
34
        chomp;
 
35
        $_ =~ s/\|/\t/g;
 
36
        @f = split('\t', $_);
 
37
 
 
38
#       print("$f[1] : $f[3] : $f[4] : $f[5] : $f[76]\n");
 
39
 
 
40
        $hp = $f[1];
 
41
        $mag = $f[5];
 
42
 
 
43
        if($hp > $high) { $high = $hp; }  # data isn't contiguous...
 
44
 
 
45
        # ra and de in hms
 
46
        if( $f[3] =~ /(\-*)(\d\d) (\d\d) (\d\d\.\d\d)/ ) {
 
47
                $ra = $2 + $3/60 + $4/3600;
 
48
                if($1 eq "-") { $ra *= -1; }
 
49
        } else {
 
50
                print "error with ra on hp $hp\n";
 
51
        }
 
52
 
 
53
        if( $f[4] =~ /(\-*)(\d\d) (\d\d) (\d\d.\d)/ ) {
 
54
                $de = $2 + $3/60 + $4/3600;
 
55
                if($1) { $de *= -1; }
 
56
        } else {
 
57
                print "error with de on hp $hp\n";
 
58
        }
 
59
 
 
60
        $f[76] =~/^(.)(.)/;
 
61
 
 
62
        if( $1 eq "0") { 
 
63
                $sptype = 0; 
 
64
        } elsif($1 eq "B") {
 
65
                $sptype = 1;
 
66
        } elsif($1 eq "A") {
 
67
                $sptype = 2;
 
68
        } elsif($1 eq "F") { 
 
69
                $sptype = 3;
 
70
        } elsif($1 eq "G") { 
 
71
                $sptype = 4;
 
72
        } elsif($1 eq "K") { 
 
73
                $sptype = 5;
 
74
        } elsif($1 eq "M") { 
 
75
                $sptype = 6;
 
76
        } elsif($1 eq "R") { 
 
77
                $sptype = 7;
 
78
        } elsif($1 eq "S") { 
 
79
                $sptype = 8;
 
80
        } elsif($1 eq "N") { 
 
81
                $sptype = 9;
 
82
        } elsif($1 eq "W") {
 
83
                if($2 eq "N") {
 
84
                        $sptype = 10;
 
85
                } else {
 
86
                        $sptype = 11;
 
87
                }
 
88
        } else {
 
89
                $sptype = 12;
 
90
        }
 
91
        
 
92
        $spcode = $1;
 
93
        if($sptype == 11) {
 
94
                $spcode = "X";
 
95
        } elsif($sptype == 12) {
 
96
                $spcode = "?";
 
97
        }
 
98
 
 
99
#       print "$hp\t$ra\t$de\t$f[5]\t$f[76] ($sptype)\n";
 
100
 
 
101
        $x = 256*$mag;
 
102
 
 
103
#       printf( "%d\t%d\t%.4f\t%.4f\t%s\n", $hp, $x, $ra, $de, $spcode);
 
104
 
 
105
        $out{int($hp)} = pack("ffSxC", $ra, $de, $x, $sptype);
 
106
 
 
107
 
 
108
}
 
109
 
 
110
 
 
111
# catalog size
 
112
 
 
113
print "Highest hp = $hp\n";
 
114
 
 
115
print OUT pack("L", $high+1);  # hp numbers start at 1
 
116
 
 
117
# data isn't sorted or contiguous in source file!
 
118
for( $a=0; $a<=$high; $a++) {
 
119
 
 
120
        if($out{$a} eq "" ) {
 
121
                print OUT pack("xxxxxxxxxxxx");
 
122
        } else {
 
123
                print OUT $out{$a};
 
124
        }
 
125
 
 
126
}