File Coverage

blib/lib/Astro/Catalog/IO/FITSTable.pm
Criterion Covered Total %
statement 16 18 88.8
branch n/a
condition n/a
subroutine 6 6 100.0
pod n/a
total 22 24 91.6


line stmt bran cond sub pod time code
1             package Astro::Catalog::IO::FITSTable;
2              
3             =head1 NAME
4              
5             Astro::Catalog::IO::FITSTable - Binary FITS table I/O for Astro::Catalog.
6              
7             =head1 SYNOPSIS
8              
9             $cat = Astro::Catalog::IO::FITSTable->_read_catalog( $whatever );
10              
11             =cut
12              
13 1     1   2183565 use 5.006;
  1         17  
  1         154  
14 1     1   7 use warnings;
  1         1  
  1         103  
15 1     1   67 use warnings::register;
  1         3  
  1         360  
16 1     1   7 use Carp;
  1         2  
  1         1297  
17 1     1   7 use strict;
  1         2  
  1         125  
18              
19 1     1   2127 use Astro::Catalog;
  0            
  0            
20             use Astro::Catalog::Item;
21             use Astro::Catalog::Item::Morphology;
22             use Astro::Coords;
23             use Astro::FITS::CFITSIO qw/ :longnames :constants /;
24             use File::Temp qw/ tempfile /;
25              
26             use Astro::Flux;
27             use Astro::FluxColor;
28             use Astro::Fluxes;
29              
30             use DateTime;
31             use DateTime::Format::ISO8601;
32              
33             use base qw/ Astro::Catalog::IO::Binary /;
34              
35             use vars qw/ $VERSION $DEBUG /;
36              
37             $VERSION = '4.31';
38             $DEBUG = 0;
39              
40             =begin __PUBLIC_METHODS__
41              
42             =head1 PUBLIC METHODS
43              
44             These methods are usually called automatically from the C
45             constructor, but are available for public use.
46              
47             =over 4
48              
49             =item B
50              
51             Returns the requested input format for the FITSTable class, which is
52             'name', meaning the name of the file to be turned into an C
53             object.
54              
55             $input_format = Astro::Catalog::IO::FITSTable->input_format;
56              
57             =cut
58              
59             sub input_format {
60             return "name";
61             }
62              
63             =back
64              
65             =begin __PRIVATE_METHODS__
66              
67             =head1 PRIVATE METHODS
68              
69             These methods are usually called automatically from the C
70             constructor.
71              
72             =item B<_read_catalog>
73              
74             Parses the binary FITS table and returns a new C object
75             containing the catalogue entries.
76              
77             $cat = Astro::Catalog::IO::FITSTable->_read_catalog( $whatever );
78              
79             The current translations from FITS table column names to
80             C properties are:
81              
82             =over 4
83              
84             =item No. - ID
85              
86             =item X_coordinate - X
87              
88             =item Y_coordinate - Y
89              
90             =item RA & DEC - Coords
91              
92             =item Isophotal_flux, Total_flux, Core_flux, Core1_flux, Core2_flux,
93             Core3_flux, Core4_flux, Core5_flux - C objects pushed into
94             the C fluxes accessor.
95              
96             =item Ellipticity & Position_angle - Morphology
97              
98             =back
99              
100             RA and Dec are assumed to be in J2000 coordinates, and are in units
101             of radians. The isophotal flux is assumed to be in units of counts,
102             and is converted into a magnitude through the formula -2.5 * log10( flux ).
103             The position angle is assumed to be the angle measured counter-
104             clockwise from the positive x axis, in degrees.
105              
106             An attempt to read in the DATE-OBS header is made so that flux measurements
107             can be timestamped. If the DATE-OBS header does not exist, then the current
108             date and time will be used for the flux timestamps.
109              
110             =cut
111              
112             sub _read_catalog {
113             my $class = shift;
114             my %args = @_;
115              
116             if( ! defined( $args{'filename'} ) ) {
117             croak "Must supply a filename to read";
118             }
119             my $filename = $args{'filename'};
120              
121             my $obsid;
122             if( defined( $args{'obsid'} ) ) {
123             $obsid = $args{'obsid'};
124             } else {
125             $obsid = [];
126             }
127              
128             # A lookup table for column name mappings.
129             my %column_name = ( 'ID' => 'No.',
130             'X' => 'X_coordinate',
131             'Y' => 'Y_coordinate',
132             'RA' => 'RA',
133             'Dec' => 'DEC',
134             'isophotal_flux' => 'Isophotal_flux',
135             'total_flux' => 'Total_flux',
136             'core_flux' => 'Core_flux',
137             'core1_flux' => 'Core1_flux',
138             'core2_flux' => 'Core2_flux',
139             'core3_flux' => 'Core3_flux',
140             'core4_flux' => 'Core4_flux',
141             'core5_flux' => 'Core5_flux',
142             'ellipticity' => 'Ellipticity',
143             'position_angle' => 'Position_angle',
144             );
145              
146             # The new Astro::Catalog object.
147             my $catalog = new Astro::Catalog;
148              
149             # CFITSIO status variable.
150             my $status = 0;
151              
152             # Open the file using CFITSIO.
153             my $fptr = Astro::FITS::CFITSIO::open_file( $filename,
154             Astro::FITS::CFITSIO::READONLY(),
155             $status );
156             if( $status != 0 ) {
157             Astro::FITS::CFITSIO::fits_get_errstatus( $status, my $text );
158             croak "Error opening FITS file: $status $text";
159             }
160              
161             # Get the number of HDUs in the FITS file.
162             $fptr->get_num_hdus( my $num_hdus, $status );
163             if( $status != 0 ) {
164             Astro::FITS::CFITSIO::fits_get_errstatus( $status, my $text );
165             croak "Error retrieving number of HDUs from FITS file: $status $text";
166             }
167              
168             $fptr->get_hdu_num( my $hdu_pos );
169              
170             while( $hdu_pos <= $num_hdus ) {
171              
172             # Get the type of HDU for the one we're at.
173             $fptr->get_hdu_type( my $hdutype, $status );
174             if( $status != 0 ) {
175             Astro::FITS::CFITSIO::fits_get_errstatus( $status, my $text );
176             croak "Error retrieving HDU type from FITS file: $status $text";
177             }
178              
179             if( $hdutype == BINARY_TBL ) {
180              
181             # Try to retrieve the DATE-OBS header. This will be used
182             # to give each flux measurement a datetime stamp. If DATE-OBS
183             # cannot be determined, then set the datetime to the current
184             # time.
185             my $datetime;
186             $fptr->read_keyword( 'DATE-OBS', my $dateobs, my $comment, $status );
187             if( $status != 0 ) {
188             if( $status == KEY_NO_EXIST ) {
189             # We can deal with this, just take the current time and set
190             # the status back to 0 (good).
191             $datetime = DateTime->now;
192             $status = 0;
193             } else {
194             Astro::FITS::CFITSIO::fits_get_errstatus( $status, my $text );
195             croak "Error retrieving DATE-OBS header from FITS file: $status $text";
196             }
197             } else {
198             # Strip out any characters that aren't meant to be there.
199             # read_keyword() puts single quotes around strings, so we need
200             # to get rid of those, along with any trailing Zs.
201             $dateobs =~ s/['Z]//g;
202             $datetime = DateTime::Format::ISO8601->parse_datetime( $dateobs );
203             }
204              
205             my $waveband;
206             $fptr->read_keyword( 'FILTER', my $filter, my $filtercomment, $status );
207             if( $status != 0 ) {
208             if( $status == KEY_NO_EXIST ) {
209             # We can deal with this, just set the filter to be 'unknown'.
210             $filter = 'unknown';
211             $status = 0;
212             } else {
213             Astro::FITS::CFITSIO::fits_get_errstatus( $status, my $text );
214             croak "Error retrieving FILTER header from FITS file: $status $text";
215             }
216             } else {
217             # Strip out any characters that aren't meant to be there.
218             $filter =~ s/'//g;
219             $filter =~ s/^\s+//;
220             $filter =~ s/\s+$//;
221             }
222             $waveband = new Astro::WaveBand( Filter => $filter );
223              
224             # Get the number of rows in this table.
225             $fptr->get_num_rows( my $nrows, $status );
226             if( $status != 0 ) {
227             Astro::FITS::CFITSIO::fits_get_errstatus( $status, my $text );
228             croak "Error retrieving number of rows from HDU $hdu_pos from FITS file: $status $text";
229             }
230              
231             # Grab all the information we can from this HDU.
232             # First, get the column numbers for the ID, RA, Dec, flux,
233             # ellipticity, position angle, and x and y position.
234             $fptr->get_colnum( CASEINSEN, $column_name{'ID'}, my $id_column, $status );
235             if( $status == COL_NOT_FOUND ) {
236             $status = 0;
237             $id_column = -1;
238             } elsif( $status != 0 ) {
239             Astro::FITS::CFITSIO::fits_get_errstatus( $status, my $text );
240             croak "Error in finding ID column: $status $text";
241             }
242             if( $id_column == 0 ) { $id_column = -1; }
243             print "ID column: $id_column\n" if $DEBUG;
244              
245             $fptr->get_colnum( CASEINSEN, $column_name{'RA'}, my $ra_column, $status );
246             if( $status == COL_NOT_FOUND ) {
247             $status = 0;
248             $ra_column = -1;
249             } elsif( $status != 0 ) {
250             Astro::FITS::CFITSIO::fits_get_errstatus( $status, my $text );
251             croak "Error in finding RA column: $status $text";
252             }
253             if( $ra_column == 0 ) { $ra_column = -1; }
254             print "RA column: $ra_column\n" if $DEBUG;
255              
256             $fptr->get_colnum( CASEINSEN, $column_name{'Dec'}, my $dec_column, $status );
257             if( $status == COL_NOT_FOUND ) {
258             $status = 0;
259             $dec_column = -1;
260             } elsif( $status != 0 ) {
261             Astro::FITS::CFITSIO::fits_get_errstatus( $status, my $text );
262             croak "Error in finding Dec column: $status $text";
263             }
264             if( $dec_column == 0 ) { $dec_column = -1; }
265             print "Dec column: $dec_column\n" if $DEBUG;
266              
267             $fptr->get_colnum( CASEINSEN, $column_name{'isophotal_flux'}, my $iso_flux_column, $status );
268             if( $status == COL_NOT_FOUND ) {
269             $status = 0;
270             $iso_flux_column = -1;
271             } elsif( $status != 0 ) {
272             Astro::FITS::CFITSIO::fits_get_errstatus( $status, my $text );
273             croak "Error in finding isophotal flux column: $status $text";
274             }
275             if( $iso_flux_column == 0 ) { $iso_flux_column = -1; }
276             print "Isophotal flux column: $iso_flux_column\n" if $DEBUG;
277              
278             $fptr->get_colnum( CASEINSEN, $column_name{'total_flux'}, my $total_flux_column, $status );
279             if( $status == COL_NOT_FOUND ) {
280             $status = 0;
281             $total_flux_column = -1;
282             } elsif( $status != 0 ) {
283             Astro::FITS::CFITSIO::fits_get_errstatus( $status, my $text );
284             croak "Error in finding total flux column: $status $text";
285             }
286             if( $total_flux_column == 0 ) { $total_flux_column = -1; }
287             print "Total flux column: $total_flux_column\n" if $DEBUG;
288              
289             $fptr->get_colnum( CASEINSEN, $column_name{'core_flux'}, my $core_flux_column, $status );
290             if( $status == COL_NOT_FOUND ) {
291             $status = 0;
292             $core_flux_column = -1;
293             } elsif( $status != 0 ) {
294             Astro::FITS::CFITSIO::fits_get_errstatus( $status, my $text );
295             croak "Error in finding core flux column: $status $text";
296             }
297             if( $core_flux_column == 0 ) { $core_flux_column = -1; }
298             print "Core flux column: $core_flux_column\n" if $DEBUG;
299              
300             $fptr->get_colnum( CASEINSEN, $column_name{'core1_flux'}, my $core1_flux_column, $status );
301             if( $status == COL_NOT_FOUND ) {
302             $status = 0;
303             $core1_flux_column = -1;
304             } elsif( $status != 0 ) {
305             Astro::FITS::CFITSIO::fits_get_errstatus( $status, my $text );
306             croak "Error in finding core1 flux column: $status $text";
307             }
308             if( $core1_flux_column == 0 ) { $core1_flux_column = -1; }
309             print "Core1 flux column: $core1_flux_column\n" if $DEBUG;
310              
311             $fptr->get_colnum( CASEINSEN, $column_name{'core2_flux'}, my $core2_flux_column, $status );
312             if( $status == COL_NOT_FOUND ) {
313             $status = 0;
314             $core2_flux_column = -1;
315             } elsif( $status != 0 ) {
316             Astro::FITS::CFITSIO::fits_get_errstatus( $status, my $text );
317             croak "Error in finding core2 flux column: $status $text";
318             }
319             if( $core2_flux_column == 0 ) { $core2_flux_column = -1; }
320             print "Core2 flux column: $core2_flux_column\n" if $DEBUG;
321              
322             $fptr->get_colnum( CASEINSEN, $column_name{'core3_flux'}, my $core3_flux_column, $status );
323             if( $status == COL_NOT_FOUND ) {
324             $status = 0;
325             $core3_flux_column = -1;
326             } elsif( $status != 0 ) {
327             Astro::FITS::CFITSIO::fits_get_errstatus( $status, my $text );
328             croak "Error in finding core3 flux column: $status $text";
329             }
330             if( $core3_flux_column == 0 ) { $core3_flux_column = -1; }
331             print "Core3 flux column: $core3_flux_column\n" if $DEBUG;
332              
333             $fptr->get_colnum( CASEINSEN, $column_name{'core4_flux'}, my $core4_flux_column, $status );
334             if( $status == COL_NOT_FOUND ) {
335             $status = 0;
336             $core4_flux_column = -1;
337             } elsif( $status != 0 ) {
338             Astro::FITS::CFITSIO::fits_get_errstatus( $status, my $text );
339             croak "Error in finding core4 flux column: $status $text";
340             }
341             if( $core4_flux_column == 0 ) { $core4_flux_column = -1; }
342             print "Core4 flux column: $core4_flux_column\n" if $DEBUG;
343              
344             $fptr->get_colnum( CASEINSEN, $column_name{'core5_flux'}, my $core5_flux_column, $status );
345             if( $status == COL_NOT_FOUND ) {
346             $status = 0;
347             $core5_flux_column = -1;
348             } elsif( $status != 0 ) {
349             Astro::FITS::CFITSIO::fits_get_errstatus( $status, my $text );
350             croak "Error in finding core5 flux column: $status $text";
351             }
352             if( $core5_flux_column == 0 ) { $core5_flux_column = -1; }
353             print "Core5 flux column: $core5_flux_column\n" if $DEBUG;
354              
355             $fptr->get_colnum( CASEINSEN, $column_name{'ellipticity'}, my $ell_column, $status );
356             if( $status == COL_NOT_FOUND ) {
357             $status = 0;
358             $id_column = -1;
359             } elsif( $status != 0 ) {
360             Astro::FITS::CFITSIO::fits_get_errstatus( $status, my $text );
361             croak "Error in finding ellipticity column: $status $text";
362             }
363             if( $ell_column == 0 ) { $ell_column = -1; }
364             print "Ellipticity column: $ell_column\n" if $DEBUG;
365              
366             $fptr->get_colnum( CASEINSEN, $column_name{'position_angle'}, my $posang_column, $status );
367             if( $status == COL_NOT_FOUND ) {
368             $status = 0;
369             $id_column = -1;
370             } elsif( $status != 0 ) {
371             Astro::FITS::CFITSIO::fits_get_errstatus( $status, my $text );
372             croak "Error in finding position angle column: $status $text";
373             }
374             if( $posang_column == 0 ) { $posang_column = -1; }
375             print "Position angle column: $posang_column\n" if $DEBUG;
376              
377             $fptr->get_colnum( CASEINSEN, $column_name{'X'}, my $x_column, $status );
378             if( $status == COL_NOT_FOUND ) {
379             $status = 0;
380             $id_column = -1;
381             } elsif( $status != 0 ) {
382             Astro::FITS::CFITSIO::fits_get_errstatus( $status, my $text );
383             croak "Error in finding x-coordinate column: $status $text";
384             }
385             if( $x_column == 0 ) { $x_column = -1; }
386             print "X-coordinate column: $x_column\n" if $DEBUG;
387              
388             $fptr->get_colnum( CASEINSEN, $column_name{'Y'}, my $y_column, $status );
389             if( $status == COL_NOT_FOUND ) {
390             $status = 0;
391             $id_column = -1;
392             } elsif( $status != 0 ) {
393             Astro::FITS::CFITSIO::fits_get_errstatus( $status, my $text );
394             croak "Error in finding y-coordinate column: $status $text";
395             }
396             if( $y_column == 0 ) { $y_column = -1; }
397             print "Y-coordinate column: $y_column\n" if $DEBUG;
398              
399             # Now that we've got all the columns defined, we need to grab each column
400             # in one big array, then take those arrays and stuff the information into
401             # Astro::Catalog::Item objects
402             my $id;
403             my $ra;
404             my $dec;
405             my ( $iso_flux, $total_flux, $core_flux, $core1_flux, $core2_flux, $core3_flux );
406             my ( $core4_flux, $core5_flux );
407             my $ell;
408             my $posang;
409             my $x_pos;
410             my $y_pos;
411             if( $id_column != -1 ) {
412             $fptr->read_col( TFLOAT, $id_column, 1, 1, $nrows, undef, $id, undef, $status );
413             if( $status != 0 ) {
414             Astro::FITS::CFITSIO::fits_get_errstatus( $status, my $text );
415             croak "Error in retrieving data for ID column: $status $text";
416             }
417             }
418             if( $ra_column != -1 ) {
419             $fptr->read_col( TFLOAT, $ra_column, 1, 1, $nrows, undef, $ra, undef, $status );
420             if( $status != 0 ) {
421             Astro::FITS::CFITSIO::fits_get_errstatus( $status, my $text );
422             croak "Error in retrieving data for RA column: $status $text";
423             }
424             }
425             if( $dec_column != -1 ) {
426             $fptr->read_col( TFLOAT, $dec_column, 1, 1, $nrows, undef, $dec, undef, $status );
427             if( $status != 0 ) {
428             Astro::FITS::CFITSIO::fits_get_errstatus( $status, my $text );
429             croak "Error in retrieving data for Dec column: $status $text";
430             }
431             }
432             if( $iso_flux_column != -1 ) {
433             $fptr->read_col( TFLOAT, $iso_flux_column, 1, 1, $nrows, undef, $iso_flux, undef, $status );
434             if( $status != 0 ) {
435             Astro::FITS::CFITSIO::fits_get_errstatus( $status, my $text );
436             croak "Error in retrieving data for isophotal flux column: $status $text";
437             }
438             }
439             if( $total_flux_column != -1 ) {
440             $fptr->read_col( TFLOAT, $total_flux_column, 1, 1, $nrows, undef, $total_flux, undef, $status );
441             if( $status != 0 ) {
442             Astro::FITS::CFITSIO::fits_get_errstatus( $status, my $text );
443             croak "Error in retrieving data for tottal flux column: $status $text";
444             }
445             }
446             if( $core_flux_column != -1 ) {
447             $fptr->read_col( TFLOAT, $core_flux_column, 1, 1, $nrows, undef, $core_flux, undef, $status );
448             if( $status != 0 ) {
449             Astro::FITS::CFITSIO::fits_get_errstatus( $status, my $text );
450             croak "Error in retrieving data for core flux column: $status $text";
451             }
452             }
453             if( $core1_flux_column != -1 ) {
454             $fptr->read_col( TFLOAT, $core1_flux_column, 1, 1, $nrows, undef, $core1_flux, undef, $status );
455             if( $status != 0 ) {
456             Astro::FITS::CFITSIO::fits_get_errstatus( $status, my $text );
457             croak "Error in retrieving data for core1 flux column: $status $text";
458             }
459             }
460             if( $core2_flux_column != -1 ) {
461             $fptr->read_col( TFLOAT, $core2_flux_column, 1, 1, $nrows, undef, $core2_flux, undef, $status );
462             if( $status != 0 ) {
463             Astro::FITS::CFITSIO::fits_get_errstatus( $status, my $text );
464             croak "Error in retrieving data for core2 flux column: $status $text";
465             }
466             }
467             if( $core3_flux_column != -1 ) {
468             $fptr->read_col( TFLOAT, $core3_flux_column, 1, 1, $nrows, undef, $core3_flux, undef, $status );
469             if( $status != 0 ) {
470             Astro::FITS::CFITSIO::fits_get_errstatus( $status, my $text );
471             croak "Error in retrieving data for core3 flux column: $status $text";
472             }
473             }
474             if( $core4_flux_column != -1 ) {
475             $fptr->read_col( TFLOAT, $core4_flux_column, 1, 1, $nrows, undef, $core4_flux, undef, $status );
476             if( $status != 0 ) {
477             Astro::FITS::CFITSIO::fits_get_errstatus( $status, my $text );
478             croak "Error in retrieving data for core4 flux column: $status $text";
479             }
480             }
481             if( $core5_flux_column != -1 ) {
482             $fptr->read_col( TFLOAT, $core5_flux_column, 1, 1, $nrows, undef, $core5_flux, undef, $status );
483             if( $status != 0 ) {
484             Astro::FITS::CFITSIO::fits_get_errstatus( $status, my $text );
485             croak "Error in retrieving data for core5 flux column: $status $text";
486             }
487             }
488             if( $ell_column != -1 ) {
489             $fptr->read_col( TFLOAT, $ell_column, 1, 1, $nrows, undef, $ell, undef, $status );
490             if( $status != 0 ) {
491             Astro::FITS::CFITSIO::fits_get_errstatus( $status, my $text );
492             croak "Error in retrieving data for ellipticity column: $status $text";
493             }
494             }
495             if( $posang_column != -1 ) {
496             $fptr->read_col( TFLOAT, $posang_column, 1, 1, $nrows, undef, $posang, undef, $status );
497             if( $status != 0 ) {
498             Astro::FITS::CFITSIO::fits_get_errstatus( $status, my $text );
499             croak "Error in retrieving data for position angle column: $status $text";
500             }
501             }
502             if( $x_column != -1 ) {
503             $fptr->read_col( TFLOAT, $x_column, 1, 1, $nrows, undef, $x_pos, undef, $status );
504             if( $status != 0 ) {
505             Astro::FITS::CFITSIO::fits_get_errstatus( $status, my $text );
506             croak "Error in retrieving data for x-coordinate column: $status $text";
507             }
508             }
509             if( $y_column != -1 ) {
510             $fptr->read_col( TFLOAT, $y_column, 1, 1, $nrows, undef, $y_pos, undef, $status );
511             if( $status != 0 ) {
512             Astro::FITS::CFITSIO::fits_get_errstatus( $status, my $text );
513             croak "Error in retrieving data for y-coordinate column: $status $text";
514             }
515             }
516              
517             # Go through each array, grabbing the information and creating a
518             # new Astro::Catalog::Item object each time through.
519             for( my $i = 0; $i < $nrows; $i++ ) {
520             my $id_value;
521             if( defined( $id ) ) {
522             $id_value = $id->[$i];
523             }
524             my $ra_value;
525             if( defined( $ra ) ) {
526             $ra_value = $ra->[$i];
527             }
528             my $dec_value;
529             if( defined( $dec ) ) {
530             $dec_value = $dec->[$i];
531             }
532             my $iso_flux_value;
533             if( defined( $iso_flux ) ) {
534             $iso_flux_value = $iso_flux->[$i];
535             }
536             my $total_flux_value;
537             if( defined( $total_flux ) ) {
538             $total_flux_value = $total_flux->[$i];
539             }
540             my $core_flux_value;
541             if( defined( $core_flux ) ) {
542             $core_flux_value = $core_flux->[$i];
543             }
544             my $core1_flux_value;
545             if( defined( $core1_flux ) ) {
546             $core1_flux_value = $core1_flux->[$i];
547             }
548             my $core2_flux_value;
549             if( defined( $core2_flux ) ) {
550             $core2_flux_value = $core2_flux->[$i];
551             }
552             my $core3_flux_value;
553             if( defined( $core3_flux ) ) {
554             $core3_flux_value = $core3_flux->[$i];
555             }
556             my $core4_flux_value;
557             if( defined( $core4_flux ) ) {
558             $core4_flux_value = $core4_flux->[$i];
559             }
560             my $core5_flux_value;
561             if( defined( $core5_flux ) ) {
562             $core5_flux_value = $core5_flux->[$i];
563             }
564             my $ell_value;
565             if( defined( $ell ) ) {
566             $ell_value = $ell->[$i];
567             }
568             my $posang_value;
569             if( defined( $posang ) ) {
570             $posang_value = $posang->[$i];
571             }
572             my $x_pos_value;
573             if( defined( $x_pos ) ) {
574             $x_pos_value = $x_pos->[$i];
575             }
576             my $y_pos_value;
577             if( defined( $y_pos ) ) {
578             $y_pos_value = $y_pos->[$i];
579             }
580              
581             # Set up the Astro::Coords object, assuming our RA and Dec are in units
582             # of radians.
583             my $coords;
584             if( defined( $ra_value ) && defined( $dec_value ) ) {
585             $coords = new Astro::Coords( ra => $ra_value,
586             dec => $dec_value,
587             units => 'radians',
588             type => 'J2000',
589             );
590             }
591              
592             # Set up the Astro::Flux objects.
593             my $iso_flux_obj = new Astro::Flux( $iso_flux_value, 'isophotal_flux', $waveband,
594             datetime => $datetime, obsid => $obsid );
595             my $total_flux_obj = new Astro::Flux( $total_flux_value, 'total_flux', $waveband,
596             datetime => $datetime, obsid => $obsid );
597             my $core_flux_obj = new Astro::Flux( $core_flux_value, 'core_flux', $waveband,
598             datetime => $datetime, obsid => $obsid );
599             my $core1_flux_obj = new Astro::Flux( $core1_flux_value, 'core1_flux', $waveband,
600             datetime => $datetime, obsid => $obsid );
601             my $core2_flux_obj = new Astro::Flux( $core2_flux_value, 'core2_flux', $waveband,
602             datetime => $datetime, obsid => $obsid );
603             my $core3_flux_obj = new Astro::Flux( $core3_flux_value, 'core3_flux', $waveband,
604             datetime => $datetime, obsid => $obsid );
605             my $core4_flux_obj = new Astro::Flux( $core4_flux_value, 'core4_flux', $waveband,
606             datetime => $datetime, obsid => $obsid );
607             my $core5_flux_obj = new Astro::Flux( $core5_flux_value, 'core5_flux', $waveband,
608             datetime => $datetime, obsid => $obsid );
609              
610             # And set up the Astro::Catalog::Item::Morphology object.
611             my $morphology = new Astro::Catalog::Item::Morphology( ellipticity => $ell_value,
612             position_angle_pixel => $posang_value,
613             );
614              
615             # And create the Astro::Catalog::Item object from this conglomoration of data.
616             my $star = new Astro::Catalog::Item( ID => $id_value,
617             Fluxes => new Astro::Fluxes( $iso_flux_obj,
618             $total_flux_obj,
619             $core_flux_obj,
620             $core1_flux_obj,
621             $core2_flux_obj,
622             $core3_flux_obj,
623             $core4_flux_obj,
624             $core5_flux_obj ),
625             Coords => $coords,
626             X => $x_pos_value,
627             Y => $y_pos_value,
628             Morphology => $morphology );
629              
630             # Push it onto the Astro::Catalog object.
631             $catalog->pushstar( $star );
632             }
633              
634             }
635             $status = 0;
636              
637             # Move to the next one.
638             $fptr->movrel_hdu( 1, $hdutype, $status );
639             last if ( $status == END_OF_FILE );
640              
641             # And set $hdu_pos.
642             $fptr->get_hdu_num( $hdu_pos );
643              
644             }
645              
646             # Set the origin.
647             $catalog->origin( 'IO::FITSTable' );
648              
649             # And return.
650             return $catalog;
651              
652             }
653              
654             =item B<_write_catalog>
655              
656             Create an output catalog as a binary FITS table.
657              
658             $ref = Astro::Catalog::IO::FITSTable->_write_catalog( $catalog );
659              
660             Argument is an C object.
661              
662             This method is not yet implemented.
663              
664             =cut
665              
666             sub _write_catalog {
667             croak "Not yet implemented.";
668             }
669              
670             =back
671              
672             =head1 REVISION
673              
674             $Id: FITSTable.pm,v 1.9 2006/05/02 21:39:10 cavanagh Exp $
675              
676             =head1 SEE ALSO
677              
678             L
679              
680             =head1 COPYRIGHT
681              
682             Copyright (C) 2005 Particle Physics and Astronomy Research Council.
683             All Rights Reserved.
684              
685             This program is free software; you can redistribute it and/or modify it under
686             the terms of the GNU General Public License as published by the Free Software
687             Foundation; either version 2 of the License, or (at your option) any later
688             version.
689              
690             This program is distributed in the hope that it will be useful,but WITHOUT ANY
691             WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
692             PARTICULAR PURPOSE. See the GNU General Public License for more details.
693              
694             You should have received a copy of the GNU General Public License along with
695             this program; if not, write to the Free Software Foundation, Inc., 59 Temple
696             Place,Suite 330, Boston, MA 02111-1307, USA
697              
698             =head1 AUTHORS
699              
700             Brad Cavanagh Eb.cavanagh@jach.hawaii.eduE
701              
702             =cut
703              
704             1;