-
Notifications
You must be signed in to change notification settings - Fork 2
/
translatehdr
executable file
·145 lines (99 loc) · 3.45 KB
/
translatehdr
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#!/usr/bin/perl -w
=head1 NAME
translatehdr - Translate the FITS header from the supplied file
=head1 SYNOPSIS
translatehdr mytest.sdf
=head1 DESCRIPTION
This command reads a FITS header from the supplied file (either a FITS
file or NDF) and writes the translated header information to
standard out.
=head1 ARGUMENTS
=over 4
=item B<--help>
Simple usage information.
=item B<--man>
The manual page.
=item B<--version>
Version number for this command.
=item B<--test-to-fits>
Also output the results of converting the translated header information
back to instrument-specific FITS headers. This option is primarily
intended for use in testing the operation of the FITS header translation
software.
=back
=cut
use strict;
use warnings;
use Getopt::Long;
use Pod::Usage;
use Astro::FITS::Header;
use Astro::FITS::HdrTrans;
# Options
my ($help, $man, $version, $test_bidi);
my $status = GetOptions("help" => \$help,
"man" => \$man,
"version" => \$version,
"test-to-fits" => \$test_bidi,
);
pod2usage(1) if $help;
pod2usage(-exitstatus => 0, -verbose => 2) if $man;
if ($version) {
print "translatehdr - Translate a FITS header to generic form\n";
print "Version: ", $Astro::FITS::HdrTrans::VERSION, "\n";
exit;
}
my $file = shift(@ARGV);
die "Must supply a filename\n" unless $file;
# Get the header
my $hdr;
if ($file =~ /\.sdf$/) {
require Astro::FITS::Header::NDF;
$hdr = Astro::FITS::Header::NDF->new( File => $file );
} elsif ($file =~ /\.(gsd|dat)$/) {
# assume GSD??
require Astro::FITS::Header::GSD;
$hdr = Astro::FITS::Header::GSD->new( File => $file );
} else {
require Astro::FITS::Header::CFITSIO;
$hdr = Astro::FITS::Header::CFITSIO->new( File => $file, ReadOnly => 1 );
}
# tie to a hash
my %header;
tie %header, "Astro::FITS::Header", $hdr;
my %translation = Astro::FITS::HdrTrans::translate_from_FITS( \%header );
for my $k (sort keys %translation) {
next if $k =~ /^_/;
my $v = $translation{$k};
$v = "undef" if !defined $v; # should be trapped by HdrTrans
$v = join ",\n ", @$v if 'ARRAY' eq ref $v;
print "$k => $v\n";
}
if ($test_bidi) {
print "\n";
my %retranslation = Astro::FITS::HdrTrans::translate_to_FITS(\%translation);
for my $k (sort keys %retranslation) {
my $v = $retranslation{$k};
$v = 'undef' unless defined $v;
print "$k => $v\n";
}
}
=head1 NOTES
Currently an input file containing multiple subheaders is not handled
properly and the headers will not merged. This is true, for example,
with UKIRT .HEADER + .I1, .I2 data.
=head1 AUTHORS
Tim Jenness E<lt>[email protected]<gt>,
=head1 COPYRIGHT
Copyright (C) 2008 Science and Technology Facilities Council.
All Rights Reserved.
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation; either version 3 of the License, or (at your option) any later
version.
This program is distributed in the hope that it will be useful,but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
Place,Suite 330, Boston, MA 02111-1307, USA
=cut