| 1 | package Astro::Catalog::IO::TST; | ||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||
| 3 | =head1 NAME | ||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||
| 5 | Astro::Catalog::IO::TST - Standard Tab Separated Table format I/O | ||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||
| 7 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||
| 9 | $cat = Astro::Catalog::IO::TST->_read_catalog(\@lines); | ||||||||||||||||||||||||||||||||||||
| 10 | \@lines = Astro::Catalog::IO::TST->_write_catalog($cat); | ||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||
| 12 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||
| 14 | Performs IO for catalogs that use the standard Tab Separated Table | ||||||||||||||||||||||||||||||||||||
| 15 | (TST) format. The TST format is commonly returned by astronomical catalog | ||||||||||||||||||||||||||||||||||||
| 16 | servers that use the Astronomical Catalog Library (ACL) format, although | ||||||||||||||||||||||||||||||||||||
| 17 | it is also perfectly reasonable to read and write this format to disk. | ||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||
| 19 | =cut | ||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||
| 21 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 22 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 23 | 2 | ▶ | use warnings::register; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 24 | 2 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 25 | 2 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||
| 27 | 2 | ▶ | use Astro::Catalog; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 28 | 2 | ▶ | use Astro::Catalog::Item; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 29 | 2 | ▶ | use Astro::Coords; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||
| 31 | 2 | ▶ | use base qw/Astro::Catalog::IO::ASCII/; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||
| 33 | 2 | our $DEBUG = 0; | |||||||||||||||||||||||||||||||||||
| 34 | 2 | our $VERSION = '4.38'; | |||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||
| 36 | =begin __PRIVATE_METHODS__ | ||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||
| 38 | =head1 Private Methods | ||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||
| 40 | These methods are usually called automatically from the C<Astro::Catalog> | ||||||||||||||||||||||||||||||||||||
| 41 | constructor. | ||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||
| 43 | =over 4 | ||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||
| 45 | =item B<_read_catalog> | ||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||
| 47 | Read contents of a TST catalog (supplied as an array of lines) and | ||||||||||||||||||||||||||||||||||||
| 48 | return a corresponding C<Astro::Catalog> object. | ||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||
| 50 | $cat = Astro::Catalog::IO::TST->_read_catalog(\@lines, %opts); | ||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||
| 52 | Generally assumes that the first three columns in the table | ||||||||||||||||||||||||||||||||||||
| 53 | are ID, RA and Dec. | ||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||
| 55 | The supplied options can be used to specify non-standard | ||||||||||||||||||||||||||||||||||||
| 56 | column positions. eg | ||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||
| 58 | ra_col => 5, dec_col => 6 | ||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||
| 60 | would indicate that "ra" and "dec" are in columns 5 and 6 rather than | ||||||||||||||||||||||||||||||||||||
| 61 | columns 2 and 3. Note that all options passed in here are treated | ||||||||||||||||||||||||||||||||||||
| 62 | identically to TST parameters. ie the parameters read from the | ||||||||||||||||||||||||||||||||||||
| 63 | TST file are merged with the supplied parameters (with the supplied | ||||||||||||||||||||||||||||||||||||
| 64 | parameters over-writing file content). If "id", "ra" and "dec" are | ||||||||||||||||||||||||||||||||||||
| 65 | missing, they are assumed to be columns 0, 1 and 2 respectively. | ||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||
| 67 | =cut | ||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||
| 69 | 2 | ▶ | sub _read_catalog { | ||||||||||||||||||||||||||||||||||
|
Subroutine
_read_catalog: called CC=76 SCAR=64.2
| |||||||||||||||||||||||||||||||||||||
| 70 | 2 | my $class = shift; | |||||||||||||||||||||||||||||||||||
| 71 | 2 | my $lines = shift; | |||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||
| 73 | 2 | my %options = @_; | |||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||
| 75 | # Are we in the main table yet? | ||||||||||||||||||||||||||||||||||||
| 76 | 2 | my $intable; | |||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||
| 78 | # Parameters | ||||||||||||||||||||||||||||||||||||
| 79 | my %params; | ||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||
| 81 | # Descriptive comments | ||||||||||||||||||||||||||||||||||||
| 82 | 2 | my @descr; | |||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||
| 84 | # General comments (usually ignored) | ||||||||||||||||||||||||||||||||||||
| 85 | 2 | my @comments; | |||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||
| 87 | # Column names in order | ||||||||||||||||||||||||||||||||||||
| 88 | 2 | my @columns; | |||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||
| 90 | # Actual star information | ||||||||||||||||||||||||||||||||||||
| 91 | 2 | my @stars; | |||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||
| 93 | # Column formats, types and units (optional) | ||||||||||||||||||||||||||||||||||||
| 94 | 2 | my %extras; | |||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||
| 96 | # Loop over each line | ||||||||||||||||||||||||||||||||||||
| 97 | 2 | my $counter = 0; | |||||||||||||||||||||||||||||||||||
| 98 | 2 | for (@$lines) { | |||||||||||||||||||||||||||||||||||
| 99 | # increment line counter | ||||||||||||||||||||||||||||||||||||
| 100 | 29 | $counter++; | |||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||
| 102 | # Make sure we have a copy since there is some processing | ||||||||||||||||||||||||||||||||||||
| 103 | # of the line and we do not want the content of the supplied | ||||||||||||||||||||||||||||||||||||
| 104 | # catalog to change from under the caller. | ||||||||||||||||||||||||||||||||||||
| 105 | 29 | my $line = $_; | |||||||||||||||||||||||||||||||||||
| 106 | 29 | chomp($line); | |||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||
| 108 | # Simply loop if there is no content | ||||||||||||||||||||||||||||||||||||
| 109 | 29 | ▶ | print "PARSING line $counter\n" if $DEBUG; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 110 | 29 | ▶ | next unless $line =~ /\S/; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||
| 112 | # Look for comments | ||||||||||||||||||||||||||||||||||||
| 113 | 24 | ▶ | if ($line =~ /^\[EOD\]/) { | ||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||
| 114 | # Usually indicates that we can stop parsing. | ||||||||||||||||||||||||||||||||||||
| 115 | # At the very least this means end of data. | ||||||||||||||||||||||||||||||||||||
| 116 | # so reset $intable | ||||||||||||||||||||||||||||||||||||
| 117 | 0 | ▶ | print " FOUND EOD - no need to continue\n" if $DEBUG; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 118 | 0 | last; | |||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||||||||||
| 121 | elsif ($line =~ /^\s*\#/) { | ||||||||||||||||||||||||||||||||||||
| 122 | # probably a comment although CURSA extensions allow | ||||||||||||||||||||||||||||||||||||
| 123 | # some column information | ||||||||||||||||||||||||||||||||||||
| 124 | 5 | ▶ | if ($line =~ /^\s*\#column-(.*):/) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 125 | # Special key: usually units, types or formats | ||||||||||||||||||||||||||||||||||||
| 126 | 3 | my $key = $1; | |||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||
| 128 | # Remove the crud | ||||||||||||||||||||||||||||||||||||
| 129 | 3 | $line =~ s/^\s*\#column-$key://; | |||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||
| 131 | 3 | my @content = $class->_parse_line($line); | |||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||
| 133 | # and store it for now | ||||||||||||||||||||||||||||||||||||
| 134 | 3 | ▶ | $extras{$key} = [] unless exists $extras{$key}; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 135 | 3 | push(@{ $extras{$key} }, @content); | |||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||
| 137 | 3 | ▶ | warnings::warnif("CURSA-style parameters encountered whilst inside table!") | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 138 | if $intable; | ||||||||||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||||||||||
| 140 | else { | ||||||||||||||||||||||||||||||||||||
| 141 | # Standard comment - strip the hash | ||||||||||||||||||||||||||||||||||||
| 142 | 2 | $line =~ s/^\s*\#//; | |||||||||||||||||||||||||||||||||||
| 143 | 2 | push(@comments, $line); | |||||||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||||||||||
| 146 | elsif ($line =~ /\t/) { | ||||||||||||||||||||||||||||||||||||
| 147 | # Parse the line in standard manner | ||||||||||||||||||||||||||||||||||||
| 148 | 12 | ▶ | print " FOUND standard line\n" if $DEBUG; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 149 | 12 | my @content = $class->_parse_line( $line ); | |||||||||||||||||||||||||||||||||||
| 150 | 12 | ▶ | print Dumper(@content) if $DEBUG; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||
| 152 | # If the line includes tab characters it is probably a table | ||||||||||||||||||||||||||||||||||||
| 153 | # entry. Either the header or the content or the separator | ||||||||||||||||||||||||||||||||||||
| 154 | 12 | ▶ | if ($intable) { | ||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||
| 155 | # Must be reading real content | ||||||||||||||||||||||||||||||||||||
| 156 | 8 | ▶ | warnings::warnif("Column mismatch: name count different to actual content!:\n$line\n") if @columns != @content; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 157 | 8 | ▶ | print " FOUND content line\n" if $DEBUG; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||
| 159 | # Store the content in a hash indexed by the associated columns | ||||||||||||||||||||||||||||||||||||
| 160 | # This will be a problem for degenerate headings! | ||||||||||||||||||||||||||||||||||||
| 161 | 8 | my %star = map { lc($columns[$_]), $content[$_] } (0..$#content); | |||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||
| 163 | 8 | push(@stars, \%star); | |||||||||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||||||||||
| 165 | elsif (! @columns) { | ||||||||||||||||||||||||||||||||||||
| 166 | # We have read no column information so this must be | ||||||||||||||||||||||||||||||||||||
| 167 | # the table description | ||||||||||||||||||||||||||||||||||||
| 168 | 2 | ▶ | print " FOUND table description line\n" if $DEBUG; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 169 | 2 | @columns = @content; | |||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||
| 171 | #} elsif ($line =~ /^[-\t]+$/) { # This doesn't seem to parse the | ||||||||||||||||||||||||||||||||||||
| 172 | # SuperCOSMOS TST separator, not | ||||||||||||||||||||||||||||||||||||
| 173 | # sure what's going on here. | ||||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||||||||||
| 176 | ▶ | elsif ( $content[0] =~ /^[-]+$/ && $content[1] =~ /^[-]+$/ ) { | |||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$content[0] =~ /^[-]+$/ and $content[1] =~ /^[-]+$/
MC/DC0%0/2
$content[0] =~ /^[-]+$/ and $content[1] =~ /^[-]+$/
$content[0] =~ /^[-]+$/
$content[1] =~ /^[-]+$/
Truth table33%1/3
A and B
A= $content[0] =~ /^[-]+$/B= $content[1] =~ /^[-]+$/
| |||||||||||||||||||||||||||||||||||||
| 177 | # this is probably safe enough, but its another un-Godly hack, | ||||||||||||||||||||||||||||||||||||
| 178 | # sorry Tim, have a look at the SuperCOSMOS.pm module and turn | ||||||||||||||||||||||||||||||||||||
| 179 | # on debugging in TST to see whats going on here during parsing. | ||||||||||||||||||||||||||||||||||||
| 180 | 2 | ▶ | warnings::warnif("Table separator has already been encountered!") | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 181 | if $intable; | ||||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||||
| 183 | # separator, so next time around is a real table | ||||||||||||||||||||||||||||||||||||
| 184 | 2 | $intable = 1; | |||||||||||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||||||||||
| 186 | else { | ||||||||||||||||||||||||||||||||||||
| 187 | # Should not get here | ||||||||||||||||||||||||||||||||||||
| 188 | 0 | croak "Fatal parse error reading TST table, line '$line'"; | |||||||||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||||||||||
| 191 | elsif ($line =~ /^\w+:/) { | ||||||||||||||||||||||||||||||||||||
| 192 | # A parameter is some characters ending in a colon | ||||||||||||||||||||||||||||||||||||
| 193 | 2 | my ($key, $value) = $line =~ /^(\w+):\s*(.*?)\s*$/; | |||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||
| 195 | 2 | ▶ | if (defined $key && defined $value) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $key and defined $value
MC/DC0%0/2
defined $key and defined $value
defined $key
defined $value
Truth table33%1/3
A and B
A= defined $keyB= defined $value
| |||||||||||||||||||||||||||||||||||||
| 196 | 2 | $params{$key} = $value; | |||||||||||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||||||||||
| 198 | else { | ||||||||||||||||||||||||||||||||||||
| 199 | 0 | warnings::warnif("Error extracting parameter from line '$line'"); | |||||||||||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||||
| 202 | 2 | ▶ | warnings::warnif("Parameter specified after table has been started. This is non-standard!") | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 203 | if $intable; | ||||||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||||||||||
| 206 | else { | ||||||||||||||||||||||||||||||||||||
| 207 | # This is probably general description | ||||||||||||||||||||||||||||||||||||
| 208 | 5 | push(@descr, $line); | |||||||||||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||||
| 212 | # First merge the supplied parameters into those read from the file | ||||||||||||||||||||||||||||||||||||
| 213 | # itself. The supplied values override values read from the file | ||||||||||||||||||||||||||||||||||||
| 214 | 2 | %params = (%params, %options); | |||||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||||
| 216 | 2 | ▶ | print Dumper(\@descr, \@comments, \@columns, \%params, \%extras, \@stars) | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 217 | if $DEBUG; | ||||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||||
| 219 | # Now we need to go through the parameters to see whether there are | ||||||||||||||||||||||||||||||||||||
| 220 | # any _col parameters that we need to map to an "ra", "dec" and "id" | ||||||||||||||||||||||||||||||||||||
| 221 | # field | ||||||||||||||||||||||||||||||||||||
| 222 | 2 | for my $key (keys %params) { | |||||||||||||||||||||||||||||||||||
| 223 | 2 | ▶ | next unless $key =~ /^(\w+)_col$/; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 224 | 0 | my $col = lc($1); | |||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||
| 226 | # find the column name (noting that the column numbers start | ||||||||||||||||||||||||||||||||||||
| 227 | # counting at 0) | ||||||||||||||||||||||||||||||||||||
| 228 | 0 | my $colnum = $params{$key}; | |||||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||||||
| 230 | # This is the translated name [either the name supplied | ||||||||||||||||||||||||||||||||||||
| 231 | # directly or a column number | ||||||||||||||||||||||||||||||||||||
| 232 | 0 | my $oldname; | |||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||
| 234 | # it is possible that this number is actually a column name | ||||||||||||||||||||||||||||||||||||
| 235 | 0 | ▶ | if ($colnum =~ /[A-Za-z]/) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 236 | # has a word character | ||||||||||||||||||||||||||||||||||||
| 237 | 0 | $oldname = lc($colnum); | |||||||||||||||||||||||||||||||||||
| 238 | } | ||||||||||||||||||||||||||||||||||||
| 239 | else { | ||||||||||||||||||||||||||||||||||||
| 240 | # Need to map column number to a name | ||||||||||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||||||||||
| 242 | # Negative value indicates that we are not actually specifying | ||||||||||||||||||||||||||||||||||||
| 243 | # a column | ||||||||||||||||||||||||||||||||||||
| 244 | 0 | ▶ | if ($colnum == -1) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 245 | # should the entry "$col" be deleted from each star hash | ||||||||||||||||||||||||||||||||||||
| 246 | # if it is present but has been designated -1 by a parameter? | ||||||||||||||||||||||||||||||||||||
| 247 | 0 | next; | |||||||||||||||||||||||||||||||||||
| 248 | } | ||||||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||||||
| 250 | # The old column name | ||||||||||||||||||||||||||||||||||||
| 251 | 0 | $oldname = lc( $columns[$colnum]); | |||||||||||||||||||||||||||||||||||
| 252 | } | ||||||||||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||||||||||
| 254 | # Insert new column into hash | ||||||||||||||||||||||||||||||||||||
| 255 | # overwriting existing content if required without warning | ||||||||||||||||||||||||||||||||||||
| 256 | # Assuming $star->{$oldname} actually exists | ||||||||||||||||||||||||||||||||||||
| 257 | 0 | for my $star (@stars) { | |||||||||||||||||||||||||||||||||||
| 258 | 0 | ▶ | $star->{$col} = $star->{$oldname} if exists $star->{$oldname}; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 259 | } | ||||||||||||||||||||||||||||||||||||
| 260 | } | ||||||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||||||
| 262 | # if we do not yet have id, ra or dec assume columns (0,1,2) | ||||||||||||||||||||||||||||||||||||
| 263 | # Is this the correct thing to do? The spec in SSN/75 is vague | ||||||||||||||||||||||||||||||||||||
| 264 | # on this since it seems to imply that the first 3 columns may be | ||||||||||||||||||||||||||||||||||||
| 265 | # ra,dec and id without being called that and that *_col must be | ||||||||||||||||||||||||||||||||||||
| 266 | # present as parameters if the first 3 columns are not id,ra,dec | ||||||||||||||||||||||||||||||||||||
| 267 | # content. How do I know if they are id,ra and dec if they are not | ||||||||||||||||||||||||||||||||||||
| 268 | # called that. | ||||||||||||||||||||||||||||||||||||
| 269 | 2 | ▶ | if (@stars) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 270 | 2 | my $colnum = 0; | |||||||||||||||||||||||||||||||||||
| 271 | 2 | for my $key (qw/ id ra dec /) { | |||||||||||||||||||||||||||||||||||
| 272 | # only check first star | ||||||||||||||||||||||||||||||||||||
| 273 | 6 | ▶ | if (not exists $stars[0]->{$key}) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 274 | # did not have it, loop over all | ||||||||||||||||||||||||||||||||||||
| 275 | 0 | warnings::warnif("Guessing column $colnum contains $key"); | |||||||||||||||||||||||||||||||||||
| 276 | 0 | for (@stars) { | |||||||||||||||||||||||||||||||||||
| 277 | 0 | $_->{$key} = $_->{lc($columns[$colnum])}; | |||||||||||||||||||||||||||||||||||
| 278 | } | ||||||||||||||||||||||||||||||||||||
| 279 | } | ||||||||||||||||||||||||||||||||||||
| 280 | 6 | $colnum++; | |||||||||||||||||||||||||||||||||||
| 281 | } | ||||||||||||||||||||||||||||||||||||
| 282 | } | ||||||||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||||||||
| 284 | # Now convert the information into a star object | ||||||||||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||||||||||
| 286 | # This is a back-of-the-envelope data dictionary from looking at | ||||||||||||||||||||||||||||||||||||
| 287 | # USNO-A2, 2MASS, Bright Star Catalogs and SuperCOSMOS. Maps the | ||||||||||||||||||||||||||||||||||||
| 288 | # Astro::Catalog::Item methods to different columns names | ||||||||||||||||||||||||||||||||||||
| 289 | 2 | my %datadict = ( | |||||||||||||||||||||||||||||||||||
| 290 | field => [ qw/ field /, qw/ fldno / ], | ||||||||||||||||||||||||||||||||||||
| 291 | quality => [ qw/ qual /, qw/ qflg /, qw/ quality / ], | ||||||||||||||||||||||||||||||||||||
| 292 | distance => [ "d'" ], | ||||||||||||||||||||||||||||||||||||
| 293 | posangle => [ qw/ pa /, qw/ _r / ], | ||||||||||||||||||||||||||||||||||||
| 294 | ); | ||||||||||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||||||||||
| 296 | # precalculate EQUINOX (type for Astro::Coords at the moment | ||||||||||||||||||||||||||||||||||||
| 297 | # since it can not deal with JXXXX.XX format) | ||||||||||||||||||||||||||||||||||||
| 298 | 2 | my $type = $params{EQUINOX}; | |||||||||||||||||||||||||||||||||||
| 299 | 2 | ▶ | if (defined $type) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 300 | 1 | ▶ | if ($type =~ /(B1950|J2000)(\.0*)?$/) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 301 | 1 | $type = $1; | |||||||||||||||||||||||||||||||||||
| 302 | } | ||||||||||||||||||||||||||||||||||||
| 303 | else { | ||||||||||||||||||||||||||||||||||||
| 304 | 0 | warnings::warnif("Unsupported equinox '$type'. Defaulting to J2000"); | |||||||||||||||||||||||||||||||||||
| 305 | 0 | $type = "J2000"; | |||||||||||||||||||||||||||||||||||
| 306 | } | ||||||||||||||||||||||||||||||||||||
| 307 | } | ||||||||||||||||||||||||||||||||||||
| 308 | else { | ||||||||||||||||||||||||||||||||||||
| 309 | # default to J2000 | ||||||||||||||||||||||||||||||||||||
| 310 | 1 | $type = "J2000"; | |||||||||||||||||||||||||||||||||||
| 311 | } | ||||||||||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||||||||||
| 313 | 2 | for my $star (@stars) { | |||||||||||||||||||||||||||||||||||
| 314 | 8 | my %construct; | |||||||||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||||||||||
| 316 | # Create some coordinates | ||||||||||||||||||||||||||||||||||||
| 317 | # decimal degrees or sexagesimal hours/deg | ||||||||||||||||||||||||||||||||||||
| 318 | 8 | ▶ | if (exists $star->{ra} && exists $star->{dec}) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
exists $star->{"ra"} and exists $star->{"dec"}
MC/DC0%0/2
exists $star->{"ra"} and exists $star->{"dec"}
exists $star->{"ra"}
exists $star->{"dec"}
Truth table33%1/3
A and B
A= exists $star->{"ra"}B= exists $star->{"dec"}
| |||||||||||||||||||||||||||||||||||||
| 319 | 8 | my $units; | |||||||||||||||||||||||||||||||||||
| 320 | 8 | ▶ | if ($star->{ra} =~ /:/) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 321 | 8 | $units = "sex"; | |||||||||||||||||||||||||||||||||||
| 322 | } | ||||||||||||||||||||||||||||||||||||
| 323 | else { | ||||||||||||||||||||||||||||||||||||
| 324 | # must be decimal degrees | ||||||||||||||||||||||||||||||||||||
| 325 | 0 | $units = "deg"; | |||||||||||||||||||||||||||||||||||
| 326 | } | ||||||||||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||||||||||
| 328 | my $c = new Astro::Coords( | ||||||||||||||||||||||||||||||||||||
| 329 | ra => $star->{ra}, | ||||||||||||||||||||||||||||||||||||
| 330 | dec => $star->{dec}, | ||||||||||||||||||||||||||||||||||||
| 331 | type => $type, | ||||||||||||||||||||||||||||||||||||
| 332 | units => $units, | ||||||||||||||||||||||||||||||||||||
| 333 | name => $star->{id} | ||||||||||||||||||||||||||||||||||||
| 334 | 8 | ); | |||||||||||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||||||||||
| 336 | 8 | ▶ | if (defined $c) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 337 | 8 | $construct{coords} = $c; | |||||||||||||||||||||||||||||||||||
| 338 | } | ||||||||||||||||||||||||||||||||||||
| 339 | else { | ||||||||||||||||||||||||||||||||||||
| 340 | 0 | warnings::warnif("Error instantiating coordinate object"); | |||||||||||||||||||||||||||||||||||
| 341 | } | ||||||||||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||||||||||
| 343 | } | ||||||||||||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||||||||||
| 345 | # Assume that some field names are standardised. This is | ||||||||||||||||||||||||||||||||||||
| 346 | # probably rubbish (whoever heard of standards!). | ||||||||||||||||||||||||||||||||||||
| 347 | # Need to create a data dictionary with all the alternatives | ||||||||||||||||||||||||||||||||||||
| 348 | # that are in use. | ||||||||||||||||||||||||||||||||||||
| 349 | # Be very scared if we have to provide mapping routines | ||||||||||||||||||||||||||||||||||||
| 350 | 8 | for my $starkey (keys %datadict) { | |||||||||||||||||||||||||||||||||||
| 351 | 32 | for my $colname (@{ $datadict{$starkey} }) { | |||||||||||||||||||||||||||||||||||
| 352 | 64 | ▶ | if (exists $star->{$colname}) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 353 | 0 | $construct{$starkey} = $star->{$colname}; | |||||||||||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||||||||||
| 355 | # stop looking | ||||||||||||||||||||||||||||||||||||
| 356 | 0 | next; | |||||||||||||||||||||||||||||||||||
| 357 | } | ||||||||||||||||||||||||||||||||||||
| 358 | } | ||||||||||||||||||||||||||||||||||||
| 359 | } | ||||||||||||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||||||||||
| 361 | # In GSC, posangle has junk on the end. We know it should be | ||||||||||||||||||||||||||||||||||||
| 362 | # a number | ||||||||||||||||||||||||||||||||||||
| 363 | 8 | ▶ | $construct{posangle} =~ s/\D+$// if exists $construct{posangle}; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||||||||||
| 365 | # gsc flag requires some work | ||||||||||||||||||||||||||||||||||||
| 366 | 8 | ▶ | if (exists $star->{gsc}) { | ||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||
| 367 | 0 | ▶ | $construct{gsc} = ( $star->{gsc} eq '+' ? "TRUE" : "FALSE"); | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 368 | } | ||||||||||||||||||||||||||||||||||||
| 369 | elsif ($params{gsc}) { | ||||||||||||||||||||||||||||||||||||
| 370 | 0 | $construct{gsc} = "TRUE"; | |||||||||||||||||||||||||||||||||||
| 371 | } | ||||||||||||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||||||||||
| 373 | # Magnitudes <- anything that ends in mag | ||||||||||||||||||||||||||||||||||||
| 374 | # Assdume filter is in X_mag | ||||||||||||||||||||||||||||||||||||
| 375 | # If no prefix assume R (yeah right) - we do not know the | ||||||||||||||||||||||||||||||||||||
| 376 | # source of the catalog at this point so can not even guess | ||||||||||||||||||||||||||||||||||||
| 377 | 8 | $construct{magnitudes} = {}; | |||||||||||||||||||||||||||||||||||
| 378 | 8 | $construct{magerr} = {}; | |||||||||||||||||||||||||||||||||||
| 379 | 8 | for my $key (keys %$star) { | |||||||||||||||||||||||||||||||||||
| 380 | 36 | ▶ | print "LOOPING KEY = $key\n" if $DEBUG; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||||||||||
| 382 | # Un-Goldy hack number #5 for the SuperCOSMOS catalog, for some | ||||||||||||||||||||||||||||||||||||
| 383 | # bloody stupid reason they've decided to label their magntitudes | ||||||||||||||||||||||||||||||||||||
| 384 | # B_J, R_1, R_2 and I. God help me, if I ever find the guy responsible | ||||||||||||||||||||||||||||||||||||
| 385 | # for this stupid idea. For now lets munge these here and cross our | ||||||||||||||||||||||||||||||||||||
| 386 | # fingers. | ||||||||||||||||||||||||||||||||||||
| 387 | 36 | ▶ | if ($key eq "b_j") { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 388 | 0 | $$star{bj_mag} = $star->{$key}; | |||||||||||||||||||||||||||||||||||
| 389 | 0 | delete $star->{$key}; | |||||||||||||||||||||||||||||||||||
| 390 | 0 | $key = "bj_mag"; | |||||||||||||||||||||||||||||||||||
| 391 | } | ||||||||||||||||||||||||||||||||||||
| 392 | 36 | ▶ | if ($key eq "r_1") { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 393 | 0 | $$star{r1_mag} = $star->{$key}; | |||||||||||||||||||||||||||||||||||
| 394 | 0 | delete $star->{$key}; | |||||||||||||||||||||||||||||||||||
| 395 | 0 | $key = "r1_mag" ; | |||||||||||||||||||||||||||||||||||
| 396 | } | ||||||||||||||||||||||||||||||||||||
| 397 | 36 | ▶ | if ($key eq "r_2") { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 398 | 0 | $$star{r2_mag} = $star->{$key}; | |||||||||||||||||||||||||||||||||||
| 399 | 0 | delete $star->{$key}; | |||||||||||||||||||||||||||||||||||
| 400 | 0 | $key = "r2_mag" ; | |||||||||||||||||||||||||||||||||||
| 401 | } | ||||||||||||||||||||||||||||||||||||
| 402 | 36 | ▶ | if ($key eq "i") { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 403 | 0 | $$star{i_mag} = $star->{$key}; | |||||||||||||||||||||||||||||||||||
| 404 | 0 | delete $star->{$key}; | |||||||||||||||||||||||||||||||||||
| 405 | 0 | $key = "i_mag" ; | |||||||||||||||||||||||||||||||||||
| 406 | } | ||||||||||||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||||||||||
| 408 | # drop through unless we have a magnitude | ||||||||||||||||||||||||||||||||||||
| 409 | 36 | ▶ | next unless $key =~ /^(.*?)_?mag$/; # non-greedy | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||||||||||
| 411 | # No capture - assume R | ||||||||||||||||||||||||||||||||||||
| 412 | 0 | ▶ | my $filter = ( $1 ? uc($1) : "R" ); | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||||||||||
| 414 | # if the filter starts with e_ then it is probably an | ||||||||||||||||||||||||||||||||||||
| 415 | # error in the magnitude | ||||||||||||||||||||||||||||||||||||
| 416 | 0 | ▶ | if ($filter =~ /^E_(\w+)$/i) { | ||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||
| 417 | # error in magnitude | ||||||||||||||||||||||||||||||||||||
| 418 | 0 | my $err = $1; | |||||||||||||||||||||||||||||||||||
| 419 | $construct{magerr}->{$err} = $star->{$key} | ||||||||||||||||||||||||||||||||||||
| 420 | 0 | ▶ | if $star->{$key} =~ /\d/; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 421 | 0 | ▶ | print "Found Mag Error $err ... \n" if $DEBUG; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 422 | } | ||||||||||||||||||||||||||||||||||||
| 423 | elsif ($filter =~ /_/) { | ||||||||||||||||||||||||||||||||||||
| 424 | # is this a color? | ||||||||||||||||||||||||||||||||||||
| 425 | 0 | warnings::warnif "Found unrecognised filter string: $filter\n"; | |||||||||||||||||||||||||||||||||||
| 426 | } | ||||||||||||||||||||||||||||||||||||
| 427 | else { | ||||||||||||||||||||||||||||||||||||
| 428 | # Assume it is a filter | ||||||||||||||||||||||||||||||||||||
| 429 | 0 | $construct{magnitudes}->{$filter} = $star->{$key}; | |||||||||||||||||||||||||||||||||||
| 430 | 0 | ▶ | print "Found filter $filter ...\n" if $DEBUG; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 431 | } | ||||||||||||||||||||||||||||||||||||
| 432 | } | ||||||||||||||||||||||||||||||||||||
| 433 | |||||||||||||||||||||||||||||||||||||
| 434 | 8 | my (@fluxes, @colors); | |||||||||||||||||||||||||||||||||||
| 435 | 8 | foreach my $fkey (keys %{$construct{magnitudes}}) { | |||||||||||||||||||||||||||||||||||
| 436 | 0 | my $num; | |||||||||||||||||||||||||||||||||||
| 437 | 0 | ▶ | if (defined $construct{magerr}->{$fkey}) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 438 | $num = new Number::Uncertainty( | ||||||||||||||||||||||||||||||||||||
| 439 | Value => $construct{magnitudes}->{$fkey}, | ||||||||||||||||||||||||||||||||||||
| 440 | 0 | Error => $construct{magerr}->{$fkey}); | |||||||||||||||||||||||||||||||||||
| 441 | } | ||||||||||||||||||||||||||||||||||||
| 442 | else { | ||||||||||||||||||||||||||||||||||||
| 443 | $num = new Number::Uncertainty( | ||||||||||||||||||||||||||||||||||||
| 444 | 0 | Value => $construct{magnitudes}->{$fkey}); | |||||||||||||||||||||||||||||||||||
| 445 | } | ||||||||||||||||||||||||||||||||||||
| 446 | 0 | my $mag = new Astro::Flux($num, 'mag', "$fkey"); | |||||||||||||||||||||||||||||||||||
| 447 | 0 | push @fluxes, $mag; | |||||||||||||||||||||||||||||||||||
| 448 | } | ||||||||||||||||||||||||||||||||||||
| 449 | 8 | delete $construct{magnitudes}; | |||||||||||||||||||||||||||||||||||
| 450 | 8 | ▶ | delete $construct{magerr} if defined $construct{magerr}; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 451 | |||||||||||||||||||||||||||||||||||||
| 452 | # Colors: Look for B-V | ||||||||||||||||||||||||||||||||||||
| 453 | 8 | $construct{colours} = {}; | |||||||||||||||||||||||||||||||||||
| 454 | 8 | for my $key (keys %$star) { | |||||||||||||||||||||||||||||||||||
| 455 | 36 | ▶ | next unless $key =~ /^(\w)-(\w)$/; # non-greedy | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 456 | 0 | $construct{colours}->{uc($key)} = $star->{$key}; | |||||||||||||||||||||||||||||||||||
| 457 | 0 | ▶ | print "Found colour ".uc($key)." ... \n" if $DEBUG; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 458 | } | ||||||||||||||||||||||||||||||||||||
| 459 | 8 | foreach my $ckey (keys %{$construct{colours}}) { | |||||||||||||||||||||||||||||||||||
| 460 | 0 | my @filters = split "-", $ckey; | |||||||||||||||||||||||||||||||||||
| 461 | my $color = new Astro::FluxColor( | ||||||||||||||||||||||||||||||||||||
| 462 | upper => new Astro::WaveBand(Filter => $filters[0]), | ||||||||||||||||||||||||||||||||||||
| 463 | lower => new Astro::WaveBand(Filter => $filters[1]), | ||||||||||||||||||||||||||||||||||||
| 464 | 0 | quantity => new Number::Uncertainty(Value => $construct{colours}->{$ckey})); | |||||||||||||||||||||||||||||||||||
| 465 | 0 | push @colors, $color; | |||||||||||||||||||||||||||||||||||
| 466 | } | ||||||||||||||||||||||||||||||||||||
| 467 | 8 | delete $construct{colours}; | |||||||||||||||||||||||||||||||||||
| 468 | |||||||||||||||||||||||||||||||||||||
| 469 | # build the fluxes object from the available data | ||||||||||||||||||||||||||||||||||||
| 470 | 8 | ▶ | if (defined $fluxes[0] && defined $colors[0]) { | ||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition33%1/3
defined $fluxes[0] and defined $colors[0]
MC/DC0%0/2
defined $fluxes[0] and defined $colors[0]
defined $fluxes[0]
defined $colors[0]
Truth table33%1/3
A and B
A= defined $fluxes[0]B= defined $colors[0]
| |||||||||||||||||||||||||||||||||||||
| 471 | 0 | $construct{fluxes} = new Astro::Fluxes(@fluxes, @colors); | |||||||||||||||||||||||||||||||||||
| 472 | } | ||||||||||||||||||||||||||||||||||||
| 473 | elsif (defined $colors[0] ) { | ||||||||||||||||||||||||||||||||||||
| 474 | 0 | $construct{fluxes} = new Astro::Fluxes(@colors); | |||||||||||||||||||||||||||||||||||
| 475 | } | ||||||||||||||||||||||||||||||||||||
| 476 | elsif (defined $fluxes[0] ) { | ||||||||||||||||||||||||||||||||||||
| 477 | 0 | $construct{fluxes} = new Astro::Fluxes(@fluxes); | |||||||||||||||||||||||||||||||||||
| 478 | } | ||||||||||||||||||||||||||||||||||||
| 479 | else { | ||||||||||||||||||||||||||||||||||||
| 480 | 8 | ▶ | delete $construct{fluxes} if defined $construct{fluxes}; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 481 | } | ||||||||||||||||||||||||||||||||||||
| 482 | |||||||||||||||||||||||||||||||||||||
| 483 | 8 | ▶ | print Dumper(\%construct) . "\n" if $DEBUG; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 484 | |||||||||||||||||||||||||||||||||||||
| 485 | # Modify the array in place | ||||||||||||||||||||||||||||||||||||
| 486 | 8 | $star = new Astro::Catalog::Item( id => $star->{id}, %construct ); | |||||||||||||||||||||||||||||||||||
| 487 | } | ||||||||||||||||||||||||||||||||||||
| 488 | |||||||||||||||||||||||||||||||||||||
| 489 | 2 | return new Astro::Catalog(Stars => \@stars); | |||||||||||||||||||||||||||||||||||
| 490 | } | ||||||||||||||||||||||||||||||||||||
| 491 | |||||||||||||||||||||||||||||||||||||
| 492 | =item B<_write_catalog> | ||||||||||||||||||||||||||||||||||||
| 493 | |||||||||||||||||||||||||||||||||||||
| 494 | Create an output catalog in the TST format and return the lines | ||||||||||||||||||||||||||||||||||||
| 495 | in an array. | ||||||||||||||||||||||||||||||||||||
| 496 | |||||||||||||||||||||||||||||||||||||
| 497 | $ref = Astro::Catalog::IO::TST->_write_catalog($catalog); | ||||||||||||||||||||||||||||||||||||
| 498 | |||||||||||||||||||||||||||||||||||||
| 499 | Argument is an C<Astro::Catalog> object. | ||||||||||||||||||||||||||||||||||||
| 500 | |||||||||||||||||||||||||||||||||||||
| 501 | =cut | ||||||||||||||||||||||||||||||||||||
| 502 | |||||||||||||||||||||||||||||||||||||
| 503 | 1 | ▶ | sub _write_catalog { | ||||||||||||||||||||||||||||||||||
|
Subroutine
_write_catalog: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||
| 504 | 1 | ▶ | croak ('Usage: _write_catalog($catalog, [%opts])') unless scalar(@_) >= 1; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 505 | 1 | my $class = shift; | |||||||||||||||||||||||||||||||||||
| 506 | 1 | my $catalog = shift; | |||||||||||||||||||||||||||||||||||
| 507 | |||||||||||||||||||||||||||||||||||||
| 508 | 1 | my @output; | |||||||||||||||||||||||||||||||||||
| 509 | |||||||||||||||||||||||||||||||||||||
| 510 | # First, the header. We're only going to write the ID, RA, and Dec. | ||||||||||||||||||||||||||||||||||||
| 511 | 1 | push @output, "Id\tra\tdec"; | |||||||||||||||||||||||||||||||||||
| 512 | 1 | push @output, "--\t--\t---"; | |||||||||||||||||||||||||||||||||||
| 513 | |||||||||||||||||||||||||||||||||||||
| 514 | # Now loop through the stars and push their respective IDs, RAs, and | ||||||||||||||||||||||||||||||||||||
| 515 | # Decs onto the output array. | ||||||||||||||||||||||||||||||||||||
| 516 | 1 | foreach my $star ($catalog->stars) { | |||||||||||||||||||||||||||||||||||
| 517 | 4 | my $output_string = ""; | |||||||||||||||||||||||||||||||||||
| 518 | |||||||||||||||||||||||||||||||||||||
| 519 | 4 | $output_string .= $star->id; | |||||||||||||||||||||||||||||||||||
| 520 | 4 | $output_string .= "\t"; | |||||||||||||||||||||||||||||||||||
| 521 | 4 | $output_string .= $star->coords->ra->string; | |||||||||||||||||||||||||||||||||||
| 522 | 4 | $output_string .= "\t"; | |||||||||||||||||||||||||||||||||||
| 523 | 4 | $output_string .= $star->coords->dec->string; | |||||||||||||||||||||||||||||||||||
| 524 | |||||||||||||||||||||||||||||||||||||
| 525 | 4 | push @output, $output_string; | |||||||||||||||||||||||||||||||||||
| 526 | } | ||||||||||||||||||||||||||||||||||||
| 527 | |||||||||||||||||||||||||||||||||||||
| 528 | 1 | return \@output; | |||||||||||||||||||||||||||||||||||
| 529 | } | ||||||||||||||||||||||||||||||||||||
| 530 | |||||||||||||||||||||||||||||||||||||
| 531 | =item B<_parse_line> | ||||||||||||||||||||||||||||||||||||
| 532 | |||||||||||||||||||||||||||||||||||||
| 533 | Internal routine for doing the tab delimited parsing. | ||||||||||||||||||||||||||||||||||||
| 534 | Returns back the columns. | ||||||||||||||||||||||||||||||||||||
| 535 | |||||||||||||||||||||||||||||||||||||
| 536 | @content = $class->_parse_line($line); | ||||||||||||||||||||||||||||||||||||
| 537 | |||||||||||||||||||||||||||||||||||||
| 538 | This routine is trivial but it seemed sensible to put it in a function | ||||||||||||||||||||||||||||||||||||
| 539 | since the parse is done in more than one place in _read_catalog. | ||||||||||||||||||||||||||||||||||||
| 540 | Whitespace around the column separators is stripped. | ||||||||||||||||||||||||||||||||||||
| 541 | |||||||||||||||||||||||||||||||||||||
| 542 | =cut | ||||||||||||||||||||||||||||||||||||
| 543 | |||||||||||||||||||||||||||||||||||||
| 544 | 15 | ▶ | sub _parse_line { | ||||||||||||||||||||||||||||||||||
|
Subroutine
_parse_line: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||
| 545 | 15 | my $class = shift; | |||||||||||||||||||||||||||||||||||
| 546 | 15 | my $line = shift; | |||||||||||||||||||||||||||||||||||
| 547 | |||||||||||||||||||||||||||||||||||||
| 548 | # Just so we do things correctly, add a ' ' to the | ||||||||||||||||||||||||||||||||||||
| 549 | # end of a string if it ends in a tab. Otherwise for blank | ||||||||||||||||||||||||||||||||||||
| 550 | # last column we end up being a column short | ||||||||||||||||||||||||||||||||||||
| 551 | 15 | ▶ | $line .= " " if $line =~ /\t$/; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 552 | |||||||||||||||||||||||||||||||||||||
| 553 | # Do the split on tab and then clean up each string | ||||||||||||||||||||||||||||||||||||
| 554 | # Safer since \s include \t | ||||||||||||||||||||||||||||||||||||
| 555 | 15 | my @cols = split /\t/, $line; | |||||||||||||||||||||||||||||||||||
| 556 | |||||||||||||||||||||||||||||||||||||
| 557 | 15 | for (@cols) { | |||||||||||||||||||||||||||||||||||
| 558 | 72 | s/^\s*//; | |||||||||||||||||||||||||||||||||||
| 559 | 72 | s/\s*$//; | |||||||||||||||||||||||||||||||||||
| 560 | } | ||||||||||||||||||||||||||||||||||||
| 561 | |||||||||||||||||||||||||||||||||||||
| 562 | 15 | return @cols; | |||||||||||||||||||||||||||||||||||
| 563 | } | ||||||||||||||||||||||||||||||||||||
| 564 | |||||||||||||||||||||||||||||||||||||
| 565 | 2 | 1; | |||||||||||||||||||||||||||||||||||
| 566 | |||||||||||||||||||||||||||||||||||||
| 567 | __END__ | ||||||||||||||||||||||||||||||||||||