| 1 | package Astro::Catalog::IO::XY; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | =head1 NAME | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | Astro::Catalog::IO::XY - X & Y position I/O for Astro::Catalog | ||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | $lines = Astro::Catalog::IO::XY->_write_catalog($catalog); | ||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | Performs simple IO, writing "x y" formatted strings for each | ||||||||||||||||||||||||||||
| 14 | Astro::Catalog::Item object in the catalog. | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | =cut | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | 2 | ▶ | use warnings::register; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | 2 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 2 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 2 | ▶ | use Astro::Catalog; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 26 | 2 | ▶ | use Astro::Catalog::Item; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 2 | ▶ | use base qw/Astro::Catalog::IO::ASCII/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 2 | our $VERSION = '4.38'; | |||||||||||||||||||||||||||
| 31 | 2 | our $DEBUG = 0; | |||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | =begin __PRIVATE_METHODS__ | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | =head1 Private Methods | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | These methods are for internal use only and are called from the | ||||||||||||||||||||||||||||
| 38 | Astro::Catalog module. It is not expected that anyone would want to | ||||||||||||||||||||||||||||
| 39 | call them from outside that module. | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | =over 4 | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | =item B<_read_catalog> | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | Parses the catalog lines and returns a new C<Astro::Catalog> object | ||||||||||||||||||||||||||||
| 46 | containing the catalog entries. | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | $cat = Astro::Catalog::IO::XY->_read_catalog(\@lines); | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | The catalog lines must be as described in the FORMAT section, below. | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | =cut | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 2 | ▶ | sub _read_catalog { | ||||||||||||||||||||||||||
|
Subroutine
_read_catalog: called CC=10 SCAR=23.9
| |||||||||||||||||||||||||||||
| 55 | 2 | ▶ | croak('Usage: _read_catalog(\@lines)') unless scalar(@_) >= 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 56 | 2 | my $class = shift; | |||||||||||||||||||||||||||
| 57 | 2 | my $arg = shift; | |||||||||||||||||||||||||||
| 58 | 2 | my @lines = @{$arg}; | |||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | # Create an Astro::Catalog object; | ||||||||||||||||||||||||||||
| 61 | 2 | my $catalog = new Astro::Catalog(); | |||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | # Loop through the lines. | ||||||||||||||||||||||||||||
| 64 | 2 | foreach my $i (0 .. $#lines) { | |||||||||||||||||||||||||||
| 65 | # Skip commented and blank lines | ||||||||||||||||||||||||||||
| 66 | 11 | ▶ | next if $lines[$i] =~ /^\s*[\#\*\%]/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 67 | 10 | ▶ | next if $lines[$i] =~ /^\s*$/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | # Create an Astro::Catalog::Item object. | ||||||||||||||||||||||||||||
| 70 | 10 | my $item = new Astro::Catalog::Item; | |||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | # Split up the line. | ||||||||||||||||||||||||||||
| 73 | 10 | my @values = split /\s+/, $lines[$i]; | |||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 10 | ▶ | if ($values[0] eq '') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 76 | 2 | ▶ | next if (! defined($values[2]) || ! defined($values[1])); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $values[2] and defined $values[1]
MC/DC0%0/2
defined $values[2] and defined $values[1]
defined $values[2]
defined $values[1]
Truth table33%1/3
A and B
A= defined $values[2]B= defined $values[1]
| |||||||||||||||||||||||||||||
| 77 | 2 | $item->x($values[1]); | |||||||||||||||||||||||||||
| 78 | 2 | $item->y($values[2]); | |||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||
| 80 | else { | ||||||||||||||||||||||||||||
| 81 | 8 | ▶ | next if (! defined($values[1]) || ! defined($values[0])); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $values[1] and defined $values[0]
MC/DC0%0/2
defined $values[1] and defined $values[0]
defined $values[1]
defined $values[0]
Truth table33%1/3
A and B
A= defined $values[1]B= defined $values[0]
| |||||||||||||||||||||||||||||
| 82 | 8 | $item->x($values[0]); | |||||||||||||||||||||||||||
| 83 | 8 | $item->y($values[1]); | |||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | # Push the Item onto the Catalog. | ||||||||||||||||||||||||||||
| 87 | 10 | $catalog->pushstar($item); | |||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | # Set the catalog origin and return. | ||||||||||||||||||||||||||||
| 91 | 2 | $catalog->origin('IO::XY'); | |||||||||||||||||||||||||||
| 92 | 2 | return $catalog; | |||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | =item B<_write_catalog> | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | Will write the catalog object to a simple output format of the form | ||||||||||||||||||||||||||||
| 98 | "x y", where x is the x-position and y is the y-position of each | ||||||||||||||||||||||||||||
| 99 | object in the catalog. | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | $lines = Astro::Catalog::IO::XY->_write_catalog($catalog); | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | $catalog is an Astro::Catalog object. | ||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | =cut | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | 1 | ▶ | sub _write_catalog { | ||||||||||||||||||||||||||
|
Subroutine
_write_catalog: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 108 | 1 | my $class = shift; | |||||||||||||||||||||||||||
| 109 | 1 | my $catalog = shift; | |||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | 1 | my @return; | |||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | 1 | my $stars = $catalog->stars(); | |||||||||||||||||||||||||||
| 114 | 1 | foreach my $star ( @$stars ) { | |||||||||||||||||||||||||||
| 115 | 5 | my $output_string; | |||||||||||||||||||||||||||
| 116 | 5 | $output_string .= $star->x . " " . $star->y; | |||||||||||||||||||||||||||
| 117 | 5 | push @return, $output_string; | |||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | 1 | return \@return; | |||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | 2 | 1; | |||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | __END__ | ||||||||||||||||||||||||||||