File indexing completed on 2024-09-08 03:29:00
0001 #!/usr/bin/perl 0002 # 0003 # read-hippo.pl For reading kstars hipNNN.dat data files 0004 0005 use strict; 0006 my $ERROR; 0007 my @STARS; 0008 my @DEC_REGIONS = ( 0009 # [90, 50], [50, 20], [20, -20], 0010 [-20, -50], [-50, -90]); 0011 0012 0013 while(<>) { 0014 m/^\s*#/ and do { next}; 0015 m/\S/ or do { next;}; 0016 chomp; 0017 my $star = kstars_unpack($_) or do { 0018 warn sprintf("%4d: FORMAT ERROR ($ERROR):\n$_\n", $.); 0019 next; 0020 }; 0021 $star->{line} = $.; 0022 push @STARS, $star; 0023 #$star->{name} or next; 0024 #print_star_line($star); 0025 } 0026 0027 @STARS = sort { $b->{pm} <=> $a->{pm} } @STARS; 0028 for my $star ( @STARS ) { 0029 print_star_line($star); 0030 } 0031 0032 exit; 0033 #my @missing = grep {! $_->{gname} || $_->{gname} =~ /^xx/} @STARS; 0034 0035 0036 0037 sub print_star_line { 0038 my $star = shift; 0039 printf "%8.2f ", $star->{pm}; 0040 printf "%s %s %s%s%s %s%s%s %s%s", 0041 @$star{qw/ra_str dec_str dra ddec parallax mag bv_index spec_type mult/}; 0042 my $s2; 0043 $star->{var_range} || $star->{var_period} and do { 0044 $s2 = sprintf " %4.2f %6.2f", @$star{qw/var_range var_period/}; 0045 }; 0046 $star->{name} || $star->{gname} and $s2 ||= " " x 12; 0047 $s2 and print $s2; 0048 $star->{name} and print $star->{name}; 0049 $star->{name} and $star->{gname} and print " "; 0050 $star->{gname} and print ": $star->{gname}"; 0051 print "\n"; 0052 } 0053 #print_stars(@missing); 0054 exit; 0055 0056 #========================================================================== 0057 # 0058 # 0059 0060 0061 sub print_stars { 0062 my @stars = sort {$a->{ra} <=> $b->{ra}} @_; 0063 for my $dec_region (@DEC_REGIONS) { 0064 my ($top, $bot) = @$dec_region; 0065 print "\nFrom $top to $bot:\n"; 0066 for my $star ( @stars) { 0067 my $dec = $star->{dec}; 0068 next unless $dec < $top and $dec >= $bot; 0069 printf "%4d: %s %s %6.2f %2s %8s %s\n\n", 0070 @$star{(qw/line ra_hm dec_hm mag spec_type gname name/)}; 0071 0072 } 0073 } 0074 } 0075 0076 sub kstars_unpack { 0077 my $line = shift; 0078 chomp $line; 0079 my $s1 = substr($line, 0, 60, ""); 0080 $s1 =~ m{^(\d{6}\.\d\d)\s # RA HHMMSS.SS 0081 ([+-]\d{6}\.\d)\s # DEC DDMMSS.SS 0082 ([+-]\d{6}\.\d) # dRA/dt 0083 ([+-]\d{6}\.\d) # dDec/dt 0084 (\d{5}\.\d)\s # Parallax 0085 ([\d-]\d\.\d\d) # Magnitude 0086 ([\d-]\d\.\d\d) # B-V index 0087 ([A-Z ].|sd)\s # Spectral Type 0088 (\d) # Multiplicity 0089 }x or do 0090 { 0091 $ERROR = "Positional Error (0-59)"; 0092 return; 0093 }; 0094 my $star = { 0095 ra_str => $1, 0096 dec_str => $2, 0097 dra => $3, 0098 ddec => $4, 0099 parallax => $5, 0100 mag => $6, 0101 bv_index => $7, 0102 spec_type => $8, 0103 mult => $9, 0104 line => $., 0105 pm => sqrt($3 * $3 + $4 * $4), 0106 }; 0107 $star->{ra} = hms_to_hour($star->{ra_str}); 0108 $star->{dec} = hms_to_hour($star->{dec_str}); 0109 $star->{ra_hm} = hms_to_hm($star->{ra_str}); 0110 $star->{dec_hm} = hms_to_hm($star->{dec_str}); 0111 0112 $line or return $star; 0113 0114 my $s2 = substr($line, 0, 12, ""); 0115 #print "$s2\n"; 0116 $s2 =~ m/^\s+(\d\.\d\d)? # var range 0117 \s+(\d+\.\d\d)? # var period 0118 /x or do 0119 { 0120 $ERROR = "Variable params (61 - 71)"; 0121 return; 0122 }; 0123 $star->{var_range} = $1; 0124 $star->{var_period} = $2; 0125 $line or return $star; 0126 0127 $star->{gname} = $line =~ s/\s*:\s*(\S.*)$// ? $1 : ""; 0128 $star->{name} = $line ? $line : ""; 0129 return $star; 0130 } 0131 0132 sub hms_to_hour { 0133 my $string = shift; 0134 $string =~ /^([+-]?\d\d)(\d\d)(\d\d(?:\.\d*)?)/ or return; 0135 my ($h, $m, $s) = ($1, $2, $3); 0136 my $sign = $h < 0 ? -1 : 1; 0137 $h = abs($h); 0138 $m += $s / 60; 0139 return $sign * ($h + $m / 60); 0140 } 0141 0142 sub hms_to_hm { 0143 my $string = shift; 0144 $string =~ s/([+-]?\d\d)(\d\d).*/$1:$2/; 0145 return $string; 0146 }