| 1 | package Astro::Catalog::IO::FINDOFF; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||
| 5 | Astro::Catalog::IO::FINDOFF - Catalog I/O for Astro::Catalog for Starlink FINDOFF | ||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | $cat = Astro::Catalog::IO::FINDOFF->_read_catalog(\@lines); | ||||||||||||||||||||||||||||||||||||||||||
| 10 | $arrref = Astro::Catalog::IO::FINDOFF->_write_catalog($cat, %options); | ||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | This class provides read and write methods for catalogs in the Starlink | ||||||||||||||||||||||||||||||||||||||||||
| 15 | FINDOFF input and output file format. The methods are not public and should, | ||||||||||||||||||||||||||||||||||||||||||
| 16 | in general only be called from the C<Astro::Catalog> C<write_catalog> and | ||||||||||||||||||||||||||||||||||||||||||
| 17 | C<read_catalog> methods. | ||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||
| 21 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 22 | 2 | ▶ | use warnings::register; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 23 | 2 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||
| 26 | 2 | ▶ | use Astro::Catalog; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | 2 | ▶ | use Astro::Catalog::Item; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | 2 | ▶ | use base qw/Astro::Catalog::IO::ASCII/; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||
| 31 | 2 | our $VERSION = '4.38'; | |||||||||||||||||||||||||||||||||||||||||
| 32 | 2 | our $DEBUG = 0; | |||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||
| 34 | =head1 METHODS | ||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||
| 36 | =head2 Private Methods | ||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||
| 38 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||
| 40 | =item B<_read_catalog> | ||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||
| 42 | Parses the catalog lines and returns a new C<Astro::Catalog> | ||||||||||||||||||||||||||||||||||||||||||
| 43 | object containing the catalog entries. | ||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||
| 45 | $cat = Astro::Catalog::IO::FINDOFF->_read_catalog(\@lines, %options); | ||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||
| 47 | There are currently no supported options. | ||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||
| 49 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||
| 51 | 2 | ▶ | sub _read_catalog { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_read_catalog: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 52 | 2 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||
| 53 | 2 | my $lines = shift; | |||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||
| 55 | 2 | ▶ | croak "Must supply catalog contents as a reference to an array" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 56 | unless ref($lines) eq 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||
| 58 | # Create the Astro::Catalog object. | ||||||||||||||||||||||||||||||||||||||||||
| 59 | 2 | my $catalog = new Astro::Catalog(); | |||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||
| 61 | # Chew up the lines. For position list files in FINDOFF, the first | ||||||||||||||||||||||||||||||||||||||||||
| 62 | # three columns are ID, X, and Y. Any columns after that could be | ||||||||||||||||||||||||||||||||||||||||||
| 63 | # anything, really, so put them in the Star's comment string. | ||||||||||||||||||||||||||||||||||||||||||
| 64 | 2 | my @lines = @$lines; # Dereference, make own copy. | |||||||||||||||||||||||||||||||||||||||||
| 65 | 2 | for (@lines) { | |||||||||||||||||||||||||||||||||||||||||
| 66 | 10 | my $line = $_; | |||||||||||||||||||||||||||||||||||||||||
| 67 | 10 | ▶ | next unless $line =~ /^\s*([\w\-.]+)\s+([\w\-.]+)\s+([\w\-.]+)(?:\s+(.+))*$/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 68 | 10 | my $id = $1; | |||||||||||||||||||||||||||||||||||||||||
| 69 | 10 | my $x = $2; | |||||||||||||||||||||||||||||||||||||||||
| 70 | 10 | my $y = $3; | |||||||||||||||||||||||||||||||||||||||||
| 71 | 10 | my $comment = $4; | |||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||
| 73 | # Create the Astro::Catalog::Item object. | ||||||||||||||||||||||||||||||||||||||||||
| 74 | 10 | my $star = new Astro::Catalog::Item( | |||||||||||||||||||||||||||||||||||||||||
| 75 | ID => $id, | ||||||||||||||||||||||||||||||||||||||||||
| 76 | X => $x, | ||||||||||||||||||||||||||||||||||||||||||
| 77 | Y => $y, | ||||||||||||||||||||||||||||||||||||||||||
| 78 | Comment => $comment); | ||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||
| 80 | # And push the star onto the catalog. | ||||||||||||||||||||||||||||||||||||||||||
| 81 | 10 | $catalog->pushstar($star); | |||||||||||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||
| 84 | # Set the catalog's origin. | ||||||||||||||||||||||||||||||||||||||||||
| 85 | 2 | $catalog->origin('IO::FINDOFF'); | |||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||
| 87 | # And return; | ||||||||||||||||||||||||||||||||||||||||||
| 88 | 2 | return $catalog; | |||||||||||||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||
| 91 | =item B<_write_catalog> | ||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||
| 93 | Create an output catalog in the Starlink FINDOFF format and return | ||||||||||||||||||||||||||||||||||||||||||
| 94 | the lines in an array. | ||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||
| 96 | $ref = Astro::Catalog::IO::FINDOFF->_write_catalog($catalog); | ||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||
| 98 | The sole mandatory argument is an C<Astro::Catalog> object. | ||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||
| 100 | As the Starlink FINDOFF is ID in column 1, X position in column 2, | ||||||||||||||||||||||||||||||||||||||||||
| 101 | Y position in column 3, and miscellaneous information in the remaining | ||||||||||||||||||||||||||||||||||||||||||
| 102 | columns that gets carried through to the output file, this method | ||||||||||||||||||||||||||||||||||||||||||
| 103 | writes a new ID, X, and Y in the first three columns. A new ID is | ||||||||||||||||||||||||||||||||||||||||||
| 104 | formed by removing any non-numbers from the original ID because | ||||||||||||||||||||||||||||||||||||||||||
| 105 | FINDOFF cannot understand non-integer IDs. This ID is also written | ||||||||||||||||||||||||||||||||||||||||||
| 106 | to the fourth column because FINDOFF trounces the original input | ||||||||||||||||||||||||||||||||||||||||||
| 107 | ID when doing matching, and being able to have the original ID | ||||||||||||||||||||||||||||||||||||||||||
| 108 | is a good thing. | ||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||
| 110 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||
| 112 | 1 | ▶ | sub _write_catalog { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_write_catalog: called CC=6 SCAR=19.1
| |||||||||||||||||||||||||||||||||||||||||||
| 113 | 1 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||
| 114 | 1 | my $catalog = shift; | |||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||
| 116 | 1 | ▶ | croak "Must supply catalog contents as a reference to an array" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 117 | unless UNIVERSAL::isa($catalog, "Astro::Catalog"); | ||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||
| 119 | # Set up variables for output. | ||||||||||||||||||||||||||||||||||||||||||
| 120 | 1 | my @output; | |||||||||||||||||||||||||||||||||||||||||
| 121 | my $output_line; | ||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||
| 123 | 1 | my $newid = 1; | |||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||
| 125 | # Loop through the stars. | ||||||||||||||||||||||||||||||||||||||||||
| 126 | 1 | foreach my $star ($catalog->stars) { | |||||||||||||||||||||||||||||||||||||||||
| 127 | # We need at a bare minimum the X, Y, and ID. | ||||||||||||||||||||||||||||||||||||||||||
| 128 | 5 | ▶ | next if (! defined($star->x) || | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
defined $star->x and defined $star->y and defined $star->id
defined $star->x and defined $star->y
MC/DC0%0/3
defined $star->x and defined $star->y and defined $star->id
defined $star->x
defined $star->y
defined $star->id
Truth table25%1/4
A and B and C
A= defined $star->xB= defined $star->yC= defined $star->id
| |||||||||||||||||||||||||||||||||||||||||||
| 129 | ! defined($star->y) || | ||||||||||||||||||||||||||||||||||||||||||
| 130 | ! defined($star->id)); | ||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||
| 132 | 5 | (my $comment = $star->id) =~ s/[^\d]//g; | |||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||
| 134 | # Start off the output string. | ||||||||||||||||||||||||||||||||||||||||||
| 135 | 5 | $output_line = join(' ', $newid, $star->x, $star->y, $newid); | |||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||
| 137 | # And push this string to the output array. | ||||||||||||||||||||||||||||||||||||||||||
| 138 | 5 | push @output, $output_line; | |||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||
| 140 | 5 | $newid ++; | |||||||||||||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||
| 143 | # All done looping through the stars, so return the array reference. | ||||||||||||||||||||||||||||||||||||||||||
| 144 | 1 | return \@output; | |||||||||||||||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||
| 147 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||
| 149 | __END__ | ||||||||||||||||||||||||||||||||||||||||||