Astro/Catalog/IO/Northstar.pm

filter: Statementstmt 96.5% 56 / 58 Branchbran 55.5% 10 / 18 Conditioncond 44.4% 4 / 9 MC/DCmcdc 20.0% 1 / 5 Subroutinesub 100% 10 / 10 Podpod n/a totaltotal 81.0% 81 / 100 CC 14 SCAR 24.3
CC
14
Cov
82%
_read_catalog
18.0
BEGIN
1.0
BEGIN
1.0
CRAP 11.3
« Astro/Catalog/Query/MPC.pm ↑ Summary Astro/Catalog/IO/ASCII.pm »
1 package Astro::Catalog::IO::Northstar;
2  
3 =head1 NAME
4  
5 Astro::Catalog::IO::Northstar - NorthStar format catalog parser
6  
7 =head1 SYNOPSIS
8  
9 $cat = Astro::Catalog::IO::Northstar->_read_catalog(\@lines);
10 $arrref = Astro::Catalog::IO::Northstar->_write_catalog($cat, %options);
11 $filename = Astro::Catalog::IO::Northstar->_default_file();
12  
13 =head1 DESCRIPTION
14  
15 This class provides read and write methods for catalogs in the
16 format used by the NorthStar proposal submission system. The methods
17 are not public and should, in general, only be called from the
18 C<Astro::Catalog> C<write_catalog> and C<read_catalog> methods.
19  
20 =cut
21  
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 strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
26  
27 2 ▶use Astro::Telescope;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 2 ▶use Astro::Coords;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 2 ▶use Astro::Catalog;
Subroutine BEGIN: called CC=1 SCAR=0.0
30 2 ▶use Astro::Catalog::Item;
Subroutine BEGIN: called CC=1 SCAR=0.0
31  
32 2 ▶use base qw/Astro::Catalog::IO::ASCII/;
Subroutine BEGIN: called CC=1 SCAR=0.0
33  
34 2 our $VERSION = '4.38';
35 2 our $DEBUG = 0;
36  
37 =head1 METHODS
38  
39 =over 4
40  
41 =item B<_read_catalog>
42  
43 Parses the catalog lines and returns a new C<Astro::Catalog>
44 object containing the catalog entries.
45  
46 $cat = Astro::Catalog::IO::Northstar->_read_catalog(\@lines, %options);
47  
48 Supported options (with defaults) are:
49  
50 telescope => Name of telescope to associate with each coordinate entry
51 (defaults to JCMT). If the telescope option is specified
52 but is undef or empty string, no telescope is used.
53  
54 =cut
55  
56 1 ▶sub _read_catalog {
Subroutine _read_catalog: called CC=14 SCAR=28.9
57 1 my $class = shift;
58 1 my $lines = shift;
59  
60 # Default options
61 1 my %defaults = (
62 telescope => 'JCMT',
63 incplanets => 1);
64  
65 1 my %options = (%defaults, @_);
66  
67 1 ▶ croak "Must supply catalog contents as a reference to an array"
Branch: 1 branch
BranchTrueFalseTotal
unless ref $lines eq "ARRAY" 0 1 1
68 unless ref($lines) eq 'ARRAY';
69  
70 # Create a new telescope to associate with this
71 1 my $tel;
72 $tel = new Astro::Telescope($options{telescope})
73 1 ▶ if $options{telescope};
Branch: 1 branch
BranchTrueFalseTotal
if $options{"telescope"} 1 0 1
74  
75 # Go through each line and parse it
76 1 my @stars;
77 1 for my $line (@$lines) {
78 2 $line =~ s/^\s*//;
79 2 $line =~ s/\s*$//;
80 2 ▶ next unless $line =~ /\w/;
Branch: 1 branch
BranchTrueFalseTotal
unless $line =~ /\w/ 0 2 2
81 2 my ($name, $c1, $c2, $system, $comment) = split (/\s+/,$line,5);
82 2 ▶ next unless (defined $c1 && defined $c2 && defined $system);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $c1 and defined $c2 and defined $system 0 2 2
Condition33%2/6
defined $c1 and defined $c2 and defined $system
!ll&&!rl&&r
002
defined $c1 and defined $c2
!ll&&!rl&&r
002
MC/DC0%0/3
defined $c1 and defined $c2 and defined $system
defined $c1 defined $c2 defined $system
Truth table25%1/4
A and B and C
A= defined $c1B= defined $c2C= defined $system
ABCresult
0XX0
10X0
1100
1111
83  
84 # skip "OTHER" since we do not know what to do with it
85 2 ▶ next if $system =~ /other/i;
Branch: 1 branch
BranchTrueFalseTotal
if $system =~ /other/i 0 2 2
86  
87 2 my ($ctype1, $ctype2);
88 2 ▶ if ($system =~ /gal/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($system =~ /gal/i) { } 0 2 2
89 0 $ctype1 = "long";
90 0 $ctype2 = "lat";
91 }
92 else {
93 2 $ctype1 = "ra";
94 2 $ctype2 = "dec";
95 }
96  
97 2 my $c = new Astro::Coords(
98 $ctype1 => $c1,
99 $ctype2 => $c2,
100 type => $system,
101 name => $name,
102 );
103 2 ▶ $c->telescope($tel) if defined $tel;
Branch: 1 branch
BranchTrueFalseTotal
if defined $tel 2 0 2
104 2 ▶ $c->comment($comment) if (defined $comment && $comment =~ /\w/);
Branch: 1 branch
BranchTrueFalseTotal
if defined $comment and $comment =~ /\w/ 1 1 2
Condition66%2/3
defined $comment and $comment =~ /\w/
!ll&&!rl&&r
101
MC/DC50%1/2
defined $comment and $comment =~ /\w/
defined $comment $comment =~ /\w/
Truth table66%2/3
A and B
A= defined $commentB= $comment =~ /\w/
ABresult
0X0
100
111
105  
106 # Field name should simply be linked to the telescope
107 2 ▶ my $field = (defined $tel ? $tel->name : '<UNKNOWN>');
Branch: 1 branch
BranchTrueFalseTotal
defined $tel ? : 2 0 2
108  
109 # now need the Item
110 2 my $item = new Astro::Catalog::Item(
111 id => $name,
112 field => $field,
113 coords => $c,
114 comment => $comment);
115 2 push(@stars, $item);
116 }
117  
118 1 return Astro::Catalog->new(Stars => \@stars, Origin => 'NorthStar');
119 }
120  
121 2 1;
122  
123 __END__
« Astro/Catalog/Query/MPC.pm ↑ Summary Astro/Catalog/IO/ASCII.pm »