| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Astro::Catalog::IO::ASSM; | 
| 2 |  |  |  |  |  |  |  | 
| 3 |  |  |  |  |  |  | =head1 NAME | 
| 4 |  |  |  |  |  |  |  | 
| 5 |  |  |  |  |  |  | Astro::Catalog::IO::ASSM - AJP ASSM format | 
| 6 |  |  |  |  |  |  |  | 
| 7 |  |  |  |  |  |  | =head1 SYNOPSIS | 
| 8 |  |  |  |  |  |  |  | 
| 9 |  |  |  |  |  |  | $catalog = Astro::Catalog::IO::ASSM->_read_catalog( \@lines ); | 
| 10 |  |  |  |  |  |  |  | 
| 11 |  |  |  |  |  |  | =head1 DESCRIPTION | 
| 12 |  |  |  |  |  |  |  | 
| 13 |  |  |  |  |  |  | Performs simple IO, reading or writing "id_string hh mm ss.s +dd mm ss.s" | 
| 14 |  |  |  |  |  |  | formated strings for each Astro::Catalog::Item object in the catalog. | 
| 15 |  |  |  |  |  |  |  | 
| 16 |  |  |  |  |  |  | =cut | 
| 17 |  |  |  |  |  |  |  | 
| 18 |  |  |  |  |  |  |  | 
| 19 |  |  |  |  |  |  | # L O A D   M O D U L E S -------------------------------------------------- | 
| 20 |  |  |  |  |  |  |  | 
| 21 | 1 |  |  | 1 |  | 5351294 | use 5.006; | 
|  | 1 |  |  |  |  | 11 |  | 
|  | 1 |  |  |  |  | 1132 |  | 
| 22 | 1 |  |  | 1 |  | 10 | use strict; | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 384 |  | 
| 23 | 1 |  |  | 1 |  | 204 | use warnings; | 
|  | 1 |  |  |  |  | 8 |  | 
|  | 1 |  |  |  |  | 97 |  | 
| 24 | 1 |  |  | 1 |  | 5 | use warnings::register; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 11429 |  | 
| 25 | 1 |  |  | 1 |  | 16 | use vars qw/ $VERSION /; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 394 |  | 
| 26 | 1 |  |  | 1 |  | 7 | use Carp; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 179 |  | 
| 27 |  |  |  |  |  |  |  | 
| 28 | 1 |  |  | 1 |  | 4437 | use Astro::Catalog; | 
|  | 0 |  |  |  |  |  |  | 
|  | 0 |  |  |  |  |  |  | 
| 29 |  |  |  |  |  |  | use Astro::Catalog::Item; | 
| 30 |  |  |  |  |  |  | use Astro::Coords; | 
| 31 |  |  |  |  |  |  | use Astro::Flux; | 
| 32 |  |  |  |  |  |  | use Astro::Fluxes; | 
| 33 |  |  |  |  |  |  |  | 
| 34 |  |  |  |  |  |  | use base qw/ Astro::Catalog::IO::ASCII /; | 
| 35 |  |  |  |  |  |  |  | 
| 36 |  |  |  |  |  |  | use vars qw/ $VERSION $DEBUG /; | 
| 37 |  |  |  |  |  |  |  | 
| 38 |  |  |  |  |  |  | $VERSION = '4.31'; | 
| 39 |  |  |  |  |  |  | $DEBUG = 0; | 
| 40 |  |  |  |  |  |  |  | 
| 41 |  |  |  |  |  |  |  | 
| 42 |  |  |  |  |  |  | =head1 METHODS | 
| 43 |  |  |  |  |  |  |  | 
| 44 |  |  |  |  |  |  | =head2 Private methods | 
| 45 |  |  |  |  |  |  |  | 
| 46 |  |  |  |  |  |  | These methods are for internal use only and are called from the | 
| 47 |  |  |  |  |  |  | Astro::Catalog module. It is not expected that anyone would want to | 
| 48 |  |  |  |  |  |  | call them from outside that module. | 
| 49 |  |  |  |  |  |  |  | 
| 50 |  |  |  |  |  |  | =over 4 | 
| 51 |  |  |  |  |  |  |  | 
| 52 |  |  |  |  |  |  | =item B<_read_catalog> | 
| 53 |  |  |  |  |  |  |  | 
| 54 |  |  |  |  |  |  | Parses a reference to an array containing a simply formatted catalogue | 
| 55 |  |  |  |  |  |  |  | 
| 56 |  |  |  |  |  |  | $catalog = Astro::Catalog::IO::ASSM->_read_catalog( \@lines ); | 
| 57 |  |  |  |  |  |  |  | 
| 58 |  |  |  |  |  |  | =cut | 
| 59 |  |  |  |  |  |  |  | 
| 60 |  |  |  |  |  |  | sub _read_catalog { | 
| 61 |  |  |  |  |  |  | my $class = shift; | 
| 62 |  |  |  |  |  |  | my $arg = shift; | 
| 63 |  |  |  |  |  |  | my @lines = @{$arg}; | 
| 64 |  |  |  |  |  |  |  | 
| 65 |  |  |  |  |  |  | # create an Astro::Catalog object; | 
| 66 |  |  |  |  |  |  | my $catalog = new Astro::Catalog(); | 
| 67 |  |  |  |  |  |  |  | 
| 68 |  |  |  |  |  |  | # loop through lines | 
| 69 |  |  |  |  |  |  | my $starnum = 1; | 
| 70 |  |  |  |  |  |  | my $hdrnotprocessed = 1; | 
| 71 |  |  |  |  |  |  | my @allfilters; | 
| 72 |  |  |  |  |  |  |  | 
| 73 |  |  |  |  |  |  | foreach my $i ( 0 .. $#lines ) { | 
| 74 |  |  |  |  |  |  |  | 
| 75 |  |  |  |  |  |  | # Skip commented and blank lines | 
| 76 |  |  |  |  |  |  | next if ($lines[$i] =~ /^\s*[\#*%]/); | 
| 77 |  |  |  |  |  |  | next if ($lines[$i] =~ /^\s*$/); | 
| 78 |  |  |  |  |  |  |  | 
| 79 |  |  |  |  |  |  | print $lines[$i]."\n" if $DEBUG; | 
| 80 |  |  |  |  |  |  |  | 
| 81 |  |  |  |  |  |  | # We need the last line of the header as it has the fieldnames, including | 
| 82 |  |  |  |  |  |  | # the filters | 
| 83 |  |  |  |  |  |  | if ( $hdrnotprocessed ) { | 
| 84 |  |  |  |  |  |  | print "Header processing\n" if $DEBUG; | 
| 85 |  |  |  |  |  |  |  | 
| 86 |  |  |  |  |  |  | # Extract last line of header, strip off the hash and any starting | 
| 87 |  |  |  |  |  |  | # whitespace and then split into fields | 
| 88 |  |  |  |  |  |  | my $colhdr = $lines[$i-1]; | 
| 89 |  |  |  |  |  |  | $colhdr =~s/^\s*#//g; | 
| 90 |  |  |  |  |  |  | my @hdrfields = split(/\s+/, $colhdr); | 
| 91 |  |  |  |  |  |  |  | 
| 92 |  |  |  |  |  |  | # Determine which columns are filters... | 
| 93 |  |  |  |  |  |  | my $idx = 0; | 
| 94 |  |  |  |  |  |  | my $first_filter_idx =0; | 
| 95 |  |  |  |  |  |  | my $last_filter_idx =0; | 
| 96 |  |  |  |  |  |  | foreach my $colname ( @hdrfields ) { | 
| 97 |  |  |  |  |  |  | if ( $colname eq 'DECdeg' ) { | 
| 98 |  |  |  |  |  |  | # We've found the leftmost edge of the filter columns | 
| 99 |  |  |  |  |  |  | $first_filter_idx = $idx + 1; | 
| 100 |  |  |  |  |  |  | } elsif ( $colname eq 'sptyp' ) { | 
| 101 |  |  |  |  |  |  | # We've found the rightmost edge of the filter columns | 
| 102 |  |  |  |  |  |  | $last_filter_idx = $idx - 1; | 
| 103 |  |  |  |  |  |  | } | 
| 104 |  |  |  |  |  |  | $idx++; | 
| 105 |  |  |  |  |  |  | } | 
| 106 |  |  |  |  |  |  |  | 
| 107 |  |  |  |  |  |  | @allfilters = @hdrfields[$first_filter_idx .. $last_filter_idx]; | 
| 108 |  |  |  |  |  |  | print "Found " . @allfilters . " Filters\n" if $DEBUG; | 
| 109 |  |  |  |  |  |  | for my $f ( @allfilters ) { | 
| 110 |  |  |  |  |  |  | print "filter was: $f\n" if $DEBUG; | 
| 111 |  |  |  |  |  |  | } | 
| 112 |  |  |  |  |  |  | $hdrnotprocessed = 0; | 
| 113 |  |  |  |  |  |  | } | 
| 114 |  |  |  |  |  |  | my @fields = split(/\s+/, $lines[$i]); | 
| 115 |  |  |  |  |  |  | my $ra_value = $fields[0]; | 
| 116 |  |  |  |  |  |  | my $dec_value = $fields[1]; | 
| 117 |  |  |  |  |  |  |  | 
| 118 |  |  |  |  |  |  | # Skip if the 3rd entry is 'NoStars' or there aren't the right number of fields | 
| 119 |  |  |  |  |  |  | next if $fields[2] eq 'NoStars' or @fields != @allfilters + 4; | 
| 120 |  |  |  |  |  |  |  | 
| 121 |  |  |  |  |  |  | my $star = new Astro::Catalog::Item(); | 
| 122 |  |  |  |  |  |  | # Set up the Astro::Coords object, assuming our RA and Dec are in units | 
| 123 |  |  |  |  |  |  | # of degrees. | 
| 124 |  |  |  |  |  |  |  | 
| 125 |  |  |  |  |  |  | my $coords; | 
| 126 |  |  |  |  |  |  | if ( defined( $ra_value ) && defined( $dec_value ) ) { | 
| 127 |  |  |  |  |  |  | $coords = new Astro::Coords( ra => $ra_value, | 
| 128 |  |  |  |  |  |  | dec => $dec_value, | 
| 129 |  |  |  |  |  |  | units => 'degrees', | 
| 130 |  |  |  |  |  |  | type => 'J2000', | 
| 131 |  |  |  |  |  |  | ); | 
| 132 |  |  |  |  |  |  | } | 
| 133 |  |  |  |  |  |  |  | 
| 134 |  |  |  |  |  |  | croak "Error creating coordinate object from $ra_value / $dec_value " | 
| 135 |  |  |  |  |  |  | unless defined $coords; | 
| 136 |  |  |  |  |  |  |  | 
| 137 |  |  |  |  |  |  | # and push it into the Astro::Catalog::Item object | 
| 138 |  |  |  |  |  |  | $star->coords( $coords ); | 
| 139 |  |  |  |  |  |  |  | 
| 140 |  |  |  |  |  |  | # Go through the passbands and create the Astro::Flux object for | 
| 141 |  |  |  |  |  |  | # this magnitude. | 
| 142 |  |  |  |  |  |  | my $waveband; | 
| 143 |  |  |  |  |  |  | my $filtnum = 2; | 
| 144 |  |  |  |  |  |  | my @mags; | 
| 145 |  |  |  |  |  |  | foreach my $filter ( @allfilters ) { | 
| 146 |  |  |  |  |  |  | print "Filter=$filter, " if $DEBUG; | 
| 147 |  |  |  |  |  |  | $waveband = new Astro::WaveBand( Filter => $filter ); | 
| 148 |  |  |  |  |  |  | # Create the Astro::Flux object for this magnitude. | 
| 149 |  |  |  |  |  |  | my $flux = new Astro::Flux( new Number::Uncertainty( Value => $fields[$filtnum] ), | 
| 150 |  |  |  |  |  |  | 'MAG_CATALOG', | 
| 151 |  |  |  |  |  |  | $waveband ); | 
| 152 |  |  |  |  |  |  | push @mags, $flux; | 
| 153 |  |  |  |  |  |  | $filtnum++; | 
| 154 |  |  |  |  |  |  | } | 
| 155 |  |  |  |  |  |  | print "\n" if $DEBUG; | 
| 156 |  |  |  |  |  |  | my $fluxes = new Astro::Fluxes( @mags ); | 
| 157 |  |  |  |  |  |  | # and push the fluxes into the catalog | 
| 158 |  |  |  |  |  |  | $star->fluxes( $fluxes ); | 
| 159 |  |  |  |  |  |  | $star->preferred_magnitude_type( 'MAG_CATALOG' ); | 
| 160 |  |  |  |  |  |  |  | 
| 161 |  |  |  |  |  |  | # get the sptype, strip out underscores | 
| 162 |  |  |  |  |  |  | my $spectype = $fields[5]; | 
| 163 |  |  |  |  |  |  | $spectype =~ s/_//g; | 
| 164 |  |  |  |  |  |  | print "Spectype=$spectype\n" if $DEBUG; | 
| 165 |  |  |  |  |  |  | # and push into object | 
| 166 |  |  |  |  |  |  | $star->spectype( $spectype ); | 
| 167 |  |  |  |  |  |  |  | 
| 168 |  |  |  |  |  |  | # push the source column into the Comment field | 
| 169 |  |  |  |  |  |  | $star->comment( $fields[6] ); | 
| 170 |  |  |  |  |  |  |  | 
| 171 |  |  |  |  |  |  | # push id number | 
| 172 |  |  |  |  |  |  | $star->id( $starnum ); | 
| 173 |  |  |  |  |  |  | # push it onto the stack | 
| 174 |  |  |  |  |  |  | $catalog->pushstar( $star ); | 
| 175 |  |  |  |  |  |  |  | 
| 176 |  |  |  |  |  |  | $starnum++; | 
| 177 |  |  |  |  |  |  | } | 
| 178 |  |  |  |  |  |  |  | 
| 179 |  |  |  |  |  |  | $catalog->origin( 'IO::ASSM' ); | 
| 180 |  |  |  |  |  |  | return $catalog; | 
| 181 |  |  |  |  |  |  |  | 
| 182 |  |  |  |  |  |  | } | 
| 183 |  |  |  |  |  |  |  | 
| 184 |  |  |  |  |  |  | =back | 
| 185 |  |  |  |  |  |  |  | 
| 186 |  |  |  |  |  |  | =head1 REVISION | 
| 187 |  |  |  |  |  |  |  | 
| 188 |  |  |  |  |  |  | $Id: ASSM.pm 5702 2012-05-19 00:45:23Z tlister $ | 
| 189 |  |  |  |  |  |  |  | 
| 190 |  |  |  |  |  |  | =head1 SEE ALSO | 
| 191 |  |  |  |  |  |  |  | 
| 192 |  |  |  |  |  |  | L, L | 
| 193 |  |  |  |  |  |  |  | 
| 194 |  |  |  |  |  |  |  | 
| 195 |  |  |  |  |  |  | =head1 FORMAT | 
| 196 |  |  |  |  |  |  |  | 
| 197 |  |  |  |  |  |  | The ASSM format is defined as follows: Any line that looks like | 
| 198 |  |  |  |  |  |  |  | 
| 199 |  |  |  |  |  |  | RAdeg Decdeg filter1mag filter2mag filter3mag sp. type source | 
| 200 |  |  |  |  |  |  |  | 
| 201 |  |  |  |  |  |  | =head1 COPYRIGHT | 
| 202 |  |  |  |  |  |  |  | 
| 203 |  |  |  |  |  |  | Copyright (C) 2012 Las Cumbres Observatory Global Telescope Network. | 
| 204 |  |  |  |  |  |  | All Rights Reserved. | 
| 205 |  |  |  |  |  |  |  | 
| 206 |  |  |  |  |  |  | This module is free software; | 
| 207 |  |  |  |  |  |  | you can redistribute it and/or modify it under the terms of the GNU | 
| 208 |  |  |  |  |  |  | Public License. | 
| 209 |  |  |  |  |  |  |  | 
| 210 |  |  |  |  |  |  | =head1 AUTHORS | 
| 211 |  |  |  |  |  |  |  | 
| 212 |  |  |  |  |  |  | Tim Lister Etlister@lcogt.netE | 
| 213 |  |  |  |  |  |  |  | 
| 214 |  |  |  |  |  |  | =cut | 
| 215 |  |  |  |  |  |  |  | 
| 216 |  |  |  |  |  |  | 1; |