File Coverage

blib/lib/Astro/Catalog/IO/XY.pm
Criterion Covered Total %
statement 19 21 90.4
branch n/a
condition n/a
subroutine 7 7 100.0
pod n/a
total 26 28 92.8


line stmt bran cond sub pod time code
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 catalogue.
15              
16             =cut
17              
18 2     2   3746048 use 5.006;
  2         8  
  2         104  
19 2     2   14 use warnings;
  2         6  
  2         142  
20 2     2   76 use warnings::register;
  2         4  
  2         486  
21 2     2   11 use Carp;
  2         4  
  2         381  
22 2     2   13 use strict;
  2         3  
  2         91  
23              
24 2     2   12 use Carp;
  2         12  
  2         111  
25              
26 2     2   927 use Astro::Catalog;
  0            
  0            
27             use Astro::Catalog::Star;
28              
29             use base qw/ Astro::Catalog::IO::ASCII /;
30              
31             use vars qw/$VERSION $DEBUG/;
32              
33             $VERSION = '4.31';
34             $DEBUG = 0;
35              
36             =head1 REVISION
37              
38             $Id: XY.pm,v 1.1 2006/05/02 21:41:39 cavanagh Exp $
39              
40             =begin __PRIVATE_METHODS__
41              
42             =head1 Private Methods
43              
44             These methods are for internal use only and are called from the
45             Astro::Catalog module. It is not expected that anyone would want to
46             call them from outside that module.
47              
48             =over 4
49              
50             =item B<_read_catalog>
51              
52             Parses the catalogue lines and returns a new C object
53             containing the catalogue entries.
54              
55             $cat = Astro::Catalog::IO::XY->_read_catalog( \@lines );
56              
57             The catalogue lines must be as described in the FORMAT section, below.
58              
59             =cut
60              
61             sub _read_catalog {
62             croak( 'Usage: _read_catalog( \@lines )' ) unless scalar(@_) >= 1;
63             my $class = shift;
64             my $arg = shift;
65             my @lines = @{$arg};
66              
67             # Create an Astro::Catalog object;
68             my $catalog = new Astro::Catalog();
69              
70             # Loop through the lines.
71             foreach my $i ( 0 .. $#lines ) {
72              
73             # Skip commented and blank lines
74             next if ( $lines[$i] =~ /^\s*[\#\*\%]/);
75             next if ( $lines[$i] =~ /^\s*$/);
76              
77             # Create an Astro::Catalog::Item object.
78             my $item = new Astro::Catalog::Item;
79              
80             # Split up the line.
81             my @values = split /\s+/, $lines[$i];
82              
83             if( $values[0] eq '' ) {
84             next if ( ! defined( $values[2] ) || ! defined( $values[1] ) );
85             $item->x( $values[1] );
86             $item->y( $values[2] );
87             } else {
88             next if ( ! defined( $values[1] ) || ! defined( $values[0] ) );
89             $item->x( $values[0] );
90             $item->y( $values[1] );
91             }
92              
93             # Push the Item onto the Catalog.
94             $catalog->pushstar( $item );
95              
96             }
97              
98             # Set the catalogue origin and return.
99             $catalog->origin( 'IO::XY' );
100             return $catalog;
101              
102             }
103              
104             =item B<_write_catalog>
105              
106             Will write the catalogue object to a simple output format of the form
107             "x y", where x is the x-position and y is the y-position of each
108             object in the catalogue.
109              
110             \@lines = Astro::Catalog::IO::XY->_write_catalog( $catalog );
111              
112             $catalog is an Astro::Catalog object.
113              
114             =cut
115              
116             sub _write_catalog {
117             my $class = shift;
118             my $catalog = shift;
119              
120             my @return;
121              
122             my $stars = $catalog->stars();
123             foreach my $star ( @$stars ) {
124             my $output_string;
125             $output_string .= $star->x . " " . $star->y;
126             push( @return, $output_string );
127             }
128              
129             return \@return;
130              
131             }
132              
133             =back
134              
135             =end __PRIVATE_METHODS__
136              
137             =head1 FORMAT
138              
139             The XY format is simply:
140              
141             X Y
142              
143             The values are separated by any non-zero amount of whitespace. Postive
144             and negative values are allowed. Comment lines begin with a hash:
145              
146             # This is a comment line.
147              
148             Any amount of leading or trailing whitespace is allowed.
149              
150             =head1 COPYRIGHT
151              
152             Copyright (C) 2006 Particle Physics and Astronomy Research
153             Council. All Rights Reserved.
154              
155             This module is free software; you can redistribute it and/or modify it
156             under the terms of version 2 of the GNU General Public License.
157              
158             =head1 AUTHORS
159              
160             Brad Cavanagh Eb.cavanagh@jach.hawaii.eduE
161              
162             =cut
163              
164             1;