parse_hip.pl 3.17 KB
Newer Older
1 2 3 4 5 6
#!/usr/bin/perl

# Creates hipparcos data file for use with Stellarium
# from source hip_main.dat data file available at
# http://cdsweb.u-strasbg.fr/viz-bin/Cat?I/239

7
# Copyright (C) 2005 Robert Spearman
8
#
9 10 11 12
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA  02110-1335, USA.

13 14 15 16 17 18 19 20 21 22
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
23 24


25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148

print "\nConverting hip_main.dat to hipparcos.fab\n\n";
print "WARNING: This script has only been tested on x86 Linux.\n";
print "It may produce incorrect results on other platforms.\n\n";

sleep 2;

open(IN, "hip_main.dat") || die "Can't find hip_main.dat\n";
open(OUT, ">hipparcos.fab") || die "Can't write hipparcos.fab\n";

my $dmin = 1000000000000;
my $dmax = 0;

while(<IN>) {

	chomp;
	$_ =~ s/\|/\t/g;
	@f = split('\t', $_);

#	print("$f[1] : $f[3] : $f[4] : $f[5] : $f[76]\n");

	$hp = $f[1];
	$mag = $f[5];

	if($hp > $high) { $high = $hp; }  # data isn't contiguous...

	# ra and de in hms
	if( $f[3] =~ /(\-*)(\d\d) (\d\d) (\d\d\.\d\d)/ ) {
		$ra = $2 + $3/60 + $4/3600;
		if($1 eq "-") { $ra *= -1; }
	} else {
		print "error with ra on hp $hp\n";
		next;
	}

	if( $f[4] =~ /(\-*)(\d\d) (\d\d) (\d\d.\d)/ ) {
		$de = $2 + $3/60 + $4/3600;
		if($1) { $de *= -1; }
	} else {
		print "error with de on hp $hp\n";
		next;
	}

	$f[76] =~/^(.)(.)/;

	if( $1 eq "0") { 
		$sptype = 0; 
	} elsif($1 eq "B") {
		$sptype = 1;
	} elsif($1 eq "A") {
		$sptype = 2;
	} elsif($1 eq "F") { 
		$sptype = 3;
	} elsif($1 eq "G") { 
		$sptype = 4;
	} elsif($1 eq "K") { 
		$sptype = 5;
	} elsif($1 eq "M") { 
		$sptype = 6;
	} elsif($1 eq "R") { 
		$sptype = 7;
	} elsif($1 eq "S") { 
		$sptype = 8;
	} elsif($1 eq "N") { 
		$sptype = 9;
	} elsif($1 eq "W") {
		if($2 eq "N") {
			$sptype = 10;
		} else {
			$sptype = 11;
		}
	} else {
		$sptype = 12;
	}
	
	$spcode = $1;
	if($sptype == 11) {
		$spcode = "X";
	} elsif($sptype == 12) {
		$spcode = "?";
	}

#	print "$hp\t$ra\t$de\t$f[5]\t$f[76] ($sptype)\n";

	$x = 256*$mag;

#	printf( "%d\t%d\t%.4f\t%.4f\t%s\n", $hp, $x, $ra, $de, $spcode);

	# distance
	if($f[11]==0) {
		$ly = 0;
		print "No parallax for hp $hp\n";
	} else {
		$ly = abs(3.2616/($f[11]/1000));

		if($ly<$dmin) {$dmin = $ly;}
		if($ly>$dmax) {$dmax = $ly;}
	}


	$out{int($hp)} = pack("ffSCf", $ra, $de, $x, $sptype, $ly);
#	$out{int($hp)} = pack("ffSxC", $ra, $de, $x, $sptype);


}


# catalog size

print "Highest hp = $high\n";
print "ly min: $dmin\tlymax: $dmax\n";

print OUT pack("L", $high+1);  # hp numbers start at 1

# data isn't sorted or contiguous in source file!
for( $a=0; $a<=$high; $a++) {

	if($out{$a} eq "" ) {
		print OUT pack("xxxxxxxxxxxxxxx");
	} else {
		print OUT $out{$a};
	}

}