line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
=head1 NAME |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
Astro::FITS::HdrTrans::JAC - Base class for translation of Joint |
5
|
|
|
|
|
|
|
Astronomy Centre instruments. |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 SYNOPSIS |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
use Astro::FITS::HdrTrans::JAC; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 DESCRIPTION |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
This class provides a generic set of translations that are common to |
14
|
|
|
|
|
|
|
instrumentation from the Joint Astronomy Centre. It should not be used |
15
|
|
|
|
|
|
|
directly for translation of instrument FITS headers. |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=cut |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
use 5.006; |
20
|
27
|
|
|
27
|
|
14405387
|
use warnings; |
|
27
|
|
|
|
|
216
|
|
21
|
27
|
|
|
27
|
|
134
|
use strict; |
|
27
|
|
|
|
|
66
|
|
|
27
|
|
|
|
|
740
|
|
22
|
27
|
|
|
27
|
|
119
|
use Carp; |
|
27
|
|
|
|
|
46
|
|
|
27
|
|
|
|
|
512
|
|
23
|
27
|
|
|
27
|
|
162
|
|
|
27
|
|
|
|
|
68
|
|
|
27
|
|
|
|
|
1440
|
|
24
|
|
|
|
|
|
|
use DateTime; |
25
|
27
|
|
|
27
|
|
10979
|
use DateTime::TimeZone; |
|
27
|
|
|
|
|
6221787
|
|
|
27
|
|
|
|
|
821
|
|
26
|
27
|
|
|
27
|
|
156
|
# Cache UTC definition |
|
27
|
|
|
|
|
127
|
|
|
27
|
|
|
|
|
1117
|
|
27
|
|
|
|
|
|
|
our $UTC = DateTime::TimeZone->new( name => 'UTC' ); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
# Inherit from the Base translation class and not HdrTrans itself |
30
|
|
|
|
|
|
|
# (which is just a class-less wrapper). |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
use base qw/ Astro::FITS::HdrTrans::FITS /; |
33
|
27
|
|
|
27
|
|
125
|
|
|
27
|
|
|
|
|
77
|
|
|
27
|
|
|
|
|
11702
|
|
34
|
|
|
|
|
|
|
use vars qw/ $VERSION /; |
35
|
27
|
|
|
27
|
|
153
|
|
|
27
|
|
|
|
|
46
|
|
|
27
|
|
|
|
|
17265
|
|
36
|
|
|
|
|
|
|
$VERSION = "1.65"; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
# in each class we have three sets of data. |
39
|
|
|
|
|
|
|
# - constant mappings |
40
|
|
|
|
|
|
|
# - unit mappings |
41
|
|
|
|
|
|
|
# - complex mappings |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
# For a constant mapping, there is no FITS header, just a generic |
44
|
|
|
|
|
|
|
# header that is constant. |
45
|
|
|
|
|
|
|
my %CONST_MAP = ( |
46
|
|
|
|
|
|
|
); |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
# Unit mapping implies that the value propagates directly |
49
|
|
|
|
|
|
|
# to the output with only a keyword name change. |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
my %UNIT_MAP = ( |
52
|
|
|
|
|
|
|
MSBID => 'MSBID', |
53
|
|
|
|
|
|
|
MSB_TRANSACTION_ID => 'MSBTID', |
54
|
|
|
|
|
|
|
SHIFT_TYPE => "OPER_SFT", |
55
|
|
|
|
|
|
|
); |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
# Create the translation methods. |
58
|
|
|
|
|
|
|
__PACKAGE__->_generate_lookup_methods( \%CONST_MAP, \%UNIT_MAP ); |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=head1 METHODS |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=over 4 |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=item B<translate_from_FITS> |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
This routine overrides the base class implementation to enable the |
67
|
|
|
|
|
|
|
caches to be cleared and for the location of the DATE-OBS/DATE-END field to |
68
|
|
|
|
|
|
|
be found so that base class implementations will work correctly. |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
This means that some conversion methods (in particular those using time in |
71
|
|
|
|
|
|
|
a base class) may not work properly outside the context of a full translation |
72
|
|
|
|
|
|
|
unless they have been subclassed locally. |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=cut |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
my $class = shift; |
77
|
|
|
|
|
|
|
my $headers = shift; |
78
|
19
|
|
|
19
|
1
|
85
|
|
79
|
19
|
|
|
|
|
32
|
# sort out DATE-OBS and DATE-END |
80
|
|
|
|
|
|
|
$class->_fix_dates( $headers ); |
81
|
|
|
|
|
|
|
|
82
|
19
|
|
|
|
|
130
|
# Go to the base class |
83
|
|
|
|
|
|
|
return $class->SUPER::translate_from_FITS( $headers, @_ ); |
84
|
|
|
|
|
|
|
} |
85
|
19
|
|
|
|
|
114
|
|
86
|
|
|
|
|
|
|
=back |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=head1 COMPLEX CONVERSIONS |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
These methods are more complicated than a simple mapping. We have to |
91
|
|
|
|
|
|
|
provide both from- and to-FITS conversions All these routines are |
92
|
|
|
|
|
|
|
methods and the to_ routines all take a reference to a hash and return |
93
|
|
|
|
|
|
|
the translated value (a many-to-one mapping). The from_ methods take |
94
|
|
|
|
|
|
|
a reference to a generic hash and return a translated hash (sometimes |
95
|
|
|
|
|
|
|
these are many-to-many). |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=over 4 |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=item B<to_OBSERVATION_ID> |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
Converts the C<OBSID> header directly into the C<OBSERVATION_ID> |
102
|
|
|
|
|
|
|
generic header, or if that header does not exist, converts the |
103
|
|
|
|
|
|
|
C<INSTRUME>, C<RUNNR>, and C<DATE-OBS> headers into C<OBSERVATION_ID>. |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
The form of the observation ID string is documented in |
106
|
|
|
|
|
|
|
JSA/ANA/001 (http://docs.jach.hawaii.edu/JCMT/JSA/ANA/001/jsa_ana_001.pdf). |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=cut |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
my $self = shift; |
111
|
|
|
|
|
|
|
my $FITS_headers = shift; |
112
|
|
|
|
|
|
|
|
113
|
18
|
|
|
18
|
1
|
45
|
my $return; |
114
|
18
|
|
|
|
|
44
|
if ( exists( $FITS_headers->{'OBSID'} ) && |
115
|
|
|
|
|
|
|
defined( $FITS_headers->{'OBSID'} ) ) { |
116
|
18
|
|
|
|
|
27
|
$return = $FITS_headers->{'OBSID'}; |
117
|
18
|
100
|
66
|
|
|
67
|
} else { |
118
|
|
|
|
|
|
|
|
119
|
3
|
|
|
|
|
217
|
my $instrume = lc( $self->to_INSTRUMENT( $FITS_headers ) ); |
120
|
|
|
|
|
|
|
my $obsnum = $self->to_OBSERVATION_NUMBER( $FITS_headers ); |
121
|
|
|
|
|
|
|
my $dateobs = $self->to_UTSTART( $FITS_headers ); |
122
|
15
|
|
|
|
|
420
|
|
123
|
15
|
|
|
|
|
340
|
my $datetime; |
124
|
15
|
|
|
|
|
87
|
if ( defined $dateobs && defined $obsnum ) { |
125
|
|
|
|
|
|
|
$datetime = $dateobs->datetime; |
126
|
15
|
|
|
|
|
32
|
$datetime =~ s/-//g; |
127
|
15
|
50
|
33
|
|
|
75
|
$datetime =~ s/://g; |
128
|
15
|
|
|
|
|
66
|
|
129
|
15
|
|
|
|
|
931
|
$return = join '_', $instrume, $obsnum, $datetime; |
130
|
15
|
|
|
|
|
117
|
} |
131
|
|
|
|
|
|
|
} |
132
|
15
|
|
|
|
|
79
|
|
133
|
|
|
|
|
|
|
return $return; |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
} |
136
|
18
|
|
|
|
|
196
|
|
137
|
|
|
|
|
|
|
=item B<_fix_dates> |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
Sort out DATE-OBS and DATE-END in cases where they are not available directly. |
140
|
|
|
|
|
|
|
This is mainly an issue with database retrievals where the date format is not |
141
|
|
|
|
|
|
|
FITS compliant. |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
Astro::FITS::HdrTrans::JAC->_fix_dates( \%headers ); |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=cut |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
my ( $class, $FITS_headers ) = @_; |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
# DATE-OBS can be from DATE_OBS |
150
|
|
|
|
|
|
|
# For compatability with Sybase database, also accept LONGDATEOBS LONGDATE |
151
|
45
|
|
|
45
|
|
101
|
__PACKAGE__->_try_dates( $FITS_headers, 'DATE-OBS', qw/ DATE_OBS LONGDATEOBS LONGDATE / ); |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
# DATE-END can be from DATE_END |
154
|
|
|
|
|
|
|
# For compatability with Sybase database, also accept LONGDATEEND |
155
|
45
|
|
|
|
|
163
|
__PACKAGE__->_try_dates( $FITS_headers, 'DATE-END', qw/ DATE_END LONGDATEEND / ); |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
return; |
158
|
|
|
|
|
|
|
} |
159
|
45
|
|
|
|
|
105
|
|
160
|
|
|
|
|
|
|
# helper routine for _fix_dates |
161
|
45
|
|
|
|
|
64
|
my ( $class, $FITS_headers, $outkey, @tests ) = @_; |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
if (!exists $FITS_headers->{$outkey}) { |
164
|
|
|
|
|
|
|
for my $key (@tests) { |
165
|
|
|
|
|
|
|
if ( exists( $FITS_headers->{$key} ) ) { |
166
|
90
|
|
|
90
|
|
192
|
my $date = _convert_mysql_date( $FITS_headers->{$key} ); |
167
|
|
|
|
|
|
|
if( defined( $date ) ) { |
168
|
90
|
100
|
|
|
|
223
|
$FITS_headers->{$outkey} = $date->datetime; |
169
|
16
|
|
|
|
|
119
|
last; |
170
|
40
|
50
|
|
|
|
199
|
} |
171
|
0
|
|
|
|
|
0
|
} |
172
|
0
|
0
|
|
|
|
0
|
} |
173
|
0
|
|
|
|
|
0
|
} |
174
|
0
|
|
|
|
|
0
|
return; |
175
|
|
|
|
|
|
|
} |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
# Convert MySQL date string to DateTime object. |
178
|
|
|
|
|
|
|
# For compatability, also accepts Sybase date strings. |
179
|
90
|
|
|
|
|
1586
|
my $date = shift; |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
$date =~ s/\s*$//; |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
if ($date =~ /\s*(\d\d\d\d)-(\d\d)-(\d\d)\s+(\d{1,2}):(\d\d):(\d\d)/) { |
184
|
|
|
|
|
|
|
|
185
|
0
|
|
|
0
|
|
|
my $return = DateTime->new( year => $1, |
186
|
|
|
|
|
|
|
month => $2, |
187
|
0
|
|
|
|
|
|
day => $3, |
188
|
|
|
|
|
|
|
hour => $4, |
189
|
0
|
0
|
|
|
|
|
minute => $5, |
|
|
0
|
|
|
|
|
|
190
|
|
|
|
|
|
|
second => $6, |
191
|
0
|
|
|
|
|
|
time_zone => $UTC, |
192
|
|
|
|
|
|
|
); |
193
|
|
|
|
|
|
|
return $return; |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
} elsif ($date =~ /\s*(\w+)\s+(\d{1,2})\s+(\d{4})\s+(\d{1,2}):(\d\d):(\d\d)(?::\d\d\d)?(AM|PM)/) { |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
my $hour = $4; |
198
|
|
|
|
|
|
|
if (uc($7) eq 'AM' && $hour == 12) { |
199
|
0
|
|
|
|
|
|
$hour = 0; |
200
|
|
|
|
|
|
|
} elsif ( uc($7) eq 'PM' && $hour < 12 ) { |
201
|
|
|
|
|
|
|
$hour += 12; |
202
|
|
|
|
|
|
|
} |
203
|
0
|
|
|
|
|
|
|
204
|
0
|
0
|
0
|
|
|
|
my %mon_lookup = ( 'Jan' => 1, |
|
|
0
|
0
|
|
|
|
|
205
|
0
|
|
|
|
|
|
'Feb' => 2, |
206
|
|
|
|
|
|
|
'Mar' => 3, |
207
|
0
|
|
|
|
|
|
'Apr' => 4, |
208
|
|
|
|
|
|
|
'May' => 5, |
209
|
|
|
|
|
|
|
'Jun' => 6, |
210
|
0
|
|
|
|
|
|
'Jul' => 7, |
211
|
|
|
|
|
|
|
'Aug' => 8, |
212
|
|
|
|
|
|
|
'Sep' => 9, |
213
|
|
|
|
|
|
|
'Oct' => 10, |
214
|
|
|
|
|
|
|
'Nov' => 11, |
215
|
|
|
|
|
|
|
'Dec' => 12 ); |
216
|
|
|
|
|
|
|
my $month = $mon_lookup{$1}; |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
my $return = DateTime->new( year => $3, |
219
|
|
|
|
|
|
|
month => $month, |
220
|
|
|
|
|
|
|
day => $2, |
221
|
|
|
|
|
|
|
hour => $hour, |
222
|
0
|
|
|
|
|
|
minute => $5, |
223
|
|
|
|
|
|
|
second => $6, |
224
|
0
|
|
|
|
|
|
time_zone => $UTC, |
225
|
|
|
|
|
|
|
); |
226
|
|
|
|
|
|
|
return $return; |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
} else { |
229
|
|
|
|
|
|
|
return undef; |
230
|
|
|
|
|
|
|
} |
231
|
|
|
|
|
|
|
} |
232
|
0
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
=back |
234
|
|
|
|
|
|
|
|
235
|
0
|
|
|
|
|
|
=head1 SEE ALSO |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
C<Astro::FITS::HdrTrans>, C<Astro::FITS::HdrTrans::Base>. |
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
=head1 AUTHOR |
240
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
Brad Cavanagh E<lt>b.cavanagh@jach.hawaii.eduE<gt>. |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
=head1 COPYRIGHT |
244
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
Copyright (C) 2007 Science and Technology Facilities Council. |
246
|
|
|
|
|
|
|
Copyright (C) 2006 Particle Physics and Astronomy Research Council. |
247
|
|
|
|
|
|
|
All Rights Reserved. |
248
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify |
250
|
|
|
|
|
|
|
it under the terms of the GNU General Public License as published by |
251
|
|
|
|
|
|
|
the Free Software Foundation; either Version 2 of the License, or (at |
252
|
|
|
|
|
|
|
your option) any later version. |
253
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,but |
255
|
|
|
|
|
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of |
256
|
|
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
257
|
|
|
|
|
|
|
General Public License for more details. |
258
|
|
|
|
|
|
|
|
259
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License |
260
|
|
|
|
|
|
|
along with this program; if not, write to the Free Software |
261
|
|
|
|
|
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, |
262
|
|
|
|
|
|
|
USA. |
263
|
|
|
|
|
|
|
|
264
|
|
|
|
|
|
|
=cut |
265
|
|
|
|
|
|
|
|
266
|
|
|
|
|
|
|
1; |