| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Astro::FITS::CFITSIO::Simple::PDL; |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# ABSTRACT: support routines for using CFITSIO and PDL |
|
4
|
|
|
|
|
|
|
|
|
5
|
11
|
|
|
11
|
|
189
|
use 5.008002; |
|
|
11
|
|
|
|
|
41
|
|
|
6
|
11
|
|
|
11
|
|
56
|
use strict; |
|
|
11
|
|
|
|
|
35
|
|
|
|
11
|
|
|
|
|
203
|
|
|
7
|
11
|
|
|
11
|
|
109
|
use warnings; |
|
|
11
|
|
|
|
|
25
|
|
|
|
11
|
|
|
|
|
293
|
|
|
8
|
|
|
|
|
|
|
|
|
9
|
11
|
|
|
11
|
|
57
|
use Carp; |
|
|
11
|
|
|
|
|
21
|
|
|
|
11
|
|
|
|
|
640
|
|
|
10
|
|
|
|
|
|
|
|
|
11
|
11
|
|
|
11
|
|
63
|
use PDL::Core; |
|
|
11
|
|
|
|
|
43
|
|
|
|
11
|
|
|
|
|
74
|
|
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
# workaround for A::F::C v 1.02 |
|
14
|
|
|
|
|
|
|
BEGIN { |
|
15
|
11
|
|
|
11
|
|
3333
|
use Astro::FITS::CFITSIO qw/ :constants/; |
|
|
11
|
|
|
|
|
23
|
|
|
|
11
|
|
|
|
|
9264
|
|
|
16
|
11
|
|
|
11
|
|
46
|
eval { LONGLONG_IMG() }; |
|
|
11
|
|
|
|
|
80
|
|
|
17
|
|
|
|
|
|
|
|
|
18
|
0
|
|
|
|
|
0
|
*LONGLONG_IMG = sub { 64 } |
|
19
|
11
|
50
|
|
|
|
9287
|
if $@; |
|
20
|
|
|
|
|
|
|
} |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
require Exporter; |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
# Items to export into callers namespace by default. Note: do not export |
|
27
|
|
|
|
|
|
|
# names by default without a very good reason. Use EXPORT_OK instead. |
|
28
|
|
|
|
|
|
|
# Do not simply export all your public functions/methods/constants. |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
# This allows declaration use Astro::FITS::CFITSIO::PDL ':all'; |
|
31
|
|
|
|
|
|
|
# If you do not need this, moving things directly into @EXPORT or @EXPORT_OK |
|
32
|
|
|
|
|
|
|
# will save memory. |
|
33
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( |
|
34
|
|
|
|
|
|
|
'all' => [ qw( |
|
35
|
|
|
|
|
|
|
pdl2cfitsio |
|
36
|
|
|
|
|
|
|
fits2pdl_coltype |
|
37
|
|
|
|
|
|
|
fits2pdl_imgtype |
|
38
|
|
|
|
|
|
|
my_badvalue |
|
39
|
|
|
|
|
|
|
) ] ); |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
our @EXPORT = qw( |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
); |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
our $VERSION = '0.20'; |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
our %PDL2CFITSIO = ( |
|
50
|
|
|
|
|
|
|
float => [ TDOUBLE, TFLOAT ], |
|
51
|
|
|
|
|
|
|
double => [ TDOUBLE, TFLOAT ], |
|
52
|
|
|
|
|
|
|
short => [ TSHORT, TINT, TLONG ], |
|
53
|
|
|
|
|
|
|
long => [ TSHORT, TINT, TLONG ], |
|
54
|
|
|
|
|
|
|
ushort => [ TBYTE, TUSHORT, TUINT, TULONG ], |
|
55
|
|
|
|
|
|
|
byte => [ TBYTE, TUSHORT, TUINT, TULONG ], |
|
56
|
|
|
|
|
|
|
); |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub pdl2cfitsio { |
|
59
|
118
|
|
|
118
|
1
|
218
|
my ( $arg ) = @_; |
|
60
|
|
|
|
|
|
|
|
|
61
|
118
|
|
|
|
|
177
|
my $pdl_type; |
|
62
|
|
|
|
|
|
|
|
|
63
|
118
|
50
|
|
|
|
577
|
if ( UNIVERSAL::isa( $arg, 'PDL' ) ) { |
|
|
|
50
|
|
|
|
|
|
|
64
|
0
|
|
|
|
|
0
|
$pdl_type = $arg->type; |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
} |
|
67
|
|
|
|
|
|
|
elsif ( UNIVERSAL::isa( $arg, 'PDL::Type' ) ) { |
|
68
|
118
|
|
|
|
|
203
|
$pdl_type = $arg; |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
} |
|
71
|
|
|
|
|
|
|
else { |
|
72
|
0
|
|
|
|
|
0
|
die "argument should be a PDL object or PDL::Type token\n"; |
|
73
|
|
|
|
|
|
|
} |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
# test for real datatypes |
|
76
|
118
|
50
|
|
|
|
504
|
exists $PDL2CFITSIO{$pdl_type} |
|
77
|
|
|
|
|
|
|
or die "PDL type $pdl_type not supported"; |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
|
|
80
|
118
|
|
|
|
|
954
|
my $pdl_size = PDL::Core::howbig( $pdl_type ); |
|
81
|
|
|
|
|
|
|
|
|
82
|
118
|
|
|
|
|
997
|
foreach ( @{ $PDL2CFITSIO{$pdl_type} } ) { |
|
|
118
|
|
|
|
|
250
|
|
|
83
|
151
|
100
|
|
|
|
1207
|
return $_ if $pdl_size == Astro::FITS::CFITSIO::sizeof_datatype( $_ ); |
|
84
|
|
|
|
|
|
|
} |
|
85
|
|
|
|
|
|
|
|
|
86
|
0
|
|
|
|
|
0
|
die "no CFITSIO type for PDL type $pdl_type\n"; |
|
87
|
|
|
|
|
|
|
} |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
########################################################################## |
|
91
|
|
|
|
|
|
|
# |
|
92
|
|
|
|
|
|
|
# Columns |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
our %FITS2CFITSIO_COL = ( |
|
98
|
|
|
|
|
|
|
'X' => TBIT, |
|
99
|
|
|
|
|
|
|
'B' => TBYTE, |
|
100
|
|
|
|
|
|
|
'L' => TLOGICAL, |
|
101
|
|
|
|
|
|
|
'A' => TSTRING, |
|
102
|
|
|
|
|
|
|
'I' => TSHORT, |
|
103
|
|
|
|
|
|
|
'J' => TLONG, |
|
104
|
|
|
|
|
|
|
'E' => TFLOAT, |
|
105
|
|
|
|
|
|
|
'D' => TDOUBLE, |
|
106
|
|
|
|
|
|
|
'C' => TCOMPLEX, |
|
107
|
|
|
|
|
|
|
'M' => TDBLCOMPLEX, |
|
108
|
|
|
|
|
|
|
'S' => TSBYTE, |
|
109
|
|
|
|
|
|
|
# 'K' => TLONGLONG, |
|
110
|
|
|
|
|
|
|
); |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
our %CFITSIO2PDL_COL = ( |
|
113
|
|
|
|
|
|
|
TSTRING() => undef, # A |
|
114
|
|
|
|
|
|
|
TUSHORT() => ushort, # |
|
115
|
|
|
|
|
|
|
TSHORT() => short, # I |
|
116
|
|
|
|
|
|
|
TLONG() => long, # J |
|
117
|
|
|
|
|
|
|
TINT() => long, # J |
|
118
|
|
|
|
|
|
|
TUINT() => long, # incorrect, but gotta do something! |
|
119
|
|
|
|
|
|
|
TULONG() => long, # incorrect, but gotta do something! |
|
120
|
|
|
|
|
|
|
TFLOAT() => float, # E |
|
121
|
|
|
|
|
|
|
TDOUBLE() => double, # D |
|
122
|
|
|
|
|
|
|
TBIT() => byte, # X |
|
123
|
|
|
|
|
|
|
TLOGICAL() => byte, # L |
|
124
|
|
|
|
|
|
|
TBYTE() => byte, # B |
|
125
|
|
|
|
|
|
|
TSBYTE() => byte, # S |
|
126
|
|
|
|
|
|
|
# TLONGLONG() => longlong # |
|
127
|
|
|
|
|
|
|
); |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
# we don't support these (yet?) |
|
130
|
|
|
|
|
|
|
#define TCOMPLEX 83 /* complex (pair of floats) 'C' */ |
|
131
|
|
|
|
|
|
|
#define TDBLCOMPLEX 163 /* double complex (2 doubles) 'M' */ |
|
132
|
|
|
|
|
|
|
#define TUINT 30 /* unsigned int */ |
|
133
|
|
|
|
|
|
|
#define TULONG 40 /* unsigned long */ |
|
134
|
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
sub fits2pdl_coltype { |
|
136
|
|
|
|
|
|
|
|
|
137
|
102
|
|
|
102
|
1
|
222
|
my ( $fits_type ) = @_; |
|
138
|
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
my $nfits_type |
|
140
|
|
|
|
|
|
|
= exists $FITS2CFITSIO_COL{$fits_type} |
|
141
|
102
|
50
|
|
|
|
284
|
? $FITS2CFITSIO_COL{$fits_type} |
|
142
|
|
|
|
|
|
|
: $fits_type; |
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
croak( "unsupported CFITSIO/FITS type: $fits_type\n" ) |
|
145
|
102
|
50
|
|
|
|
243
|
unless exists $CFITSIO2PDL_COL{$nfits_type}; |
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
|
|
148
|
102
|
|
|
|
|
246
|
return $CFITSIO2PDL_COL{$nfits_type}; |
|
149
|
|
|
|
|
|
|
} |
|
150
|
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
########################################################################## |
|
153
|
|
|
|
|
|
|
# |
|
154
|
|
|
|
|
|
|
# Images |
|
155
|
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
our %CFITSIO2PDL_IMG = ( |
|
158
|
|
|
|
|
|
|
BYTE_IMG() => byte, |
|
159
|
|
|
|
|
|
|
SHORT_IMG() => short, |
|
160
|
|
|
|
|
|
|
LONG_IMG() => long, |
|
161
|
|
|
|
|
|
|
FLOAT_IMG() => float, |
|
162
|
|
|
|
|
|
|
DOUBLE_IMG() => double |
|
163
|
|
|
|
|
|
|
); |
|
164
|
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
# we don't support these (yet?) |
|
166
|
|
|
|
|
|
|
#define LONGLONG_IMG 64 |
|
167
|
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
sub fits2pdl_imgtype { |
|
169
|
|
|
|
|
|
|
|
|
170
|
2
|
|
|
2
|
1
|
8
|
my ( $fits_type ) = @_; |
|
171
|
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
croak( "unsupported Image CFITSIO/FITS type: $fits_type\n" ) |
|
173
|
2
|
50
|
|
|
|
11
|
unless exists $CFITSIO2PDL_IMG{$fits_type}; |
|
174
|
|
|
|
|
|
|
|
|
175
|
2
|
|
|
|
|
7
|
$CFITSIO2PDL_IMG{$fits_type}; |
|
176
|
|
|
|
|
|
|
} |
|
177
|
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
# PDL >= 2.039 badvalue returns an ndarray, not a Perl scalar. |
|
179
|
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
*my_badvalue |
|
184
|
121
|
|
|
121
|
|
375
|
= PDL->VERSION < 2.039 ? \&PDL::badvalue : sub { PDL::badvalue( @_ )->sclr }; |
|
185
|
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
# |
|
187
|
|
|
|
|
|
|
# This file is part of Astro-FITS-CFITSIO-Simple |
|
188
|
|
|
|
|
|
|
# |
|
189
|
|
|
|
|
|
|
# This software is Copyright (c) 2008 by Smithsonian Astrophysical Observatory. |
|
190
|
|
|
|
|
|
|
# |
|
191
|
|
|
|
|
|
|
# This is free software, licensed under: |
|
192
|
|
|
|
|
|
|
# |
|
193
|
|
|
|
|
|
|
# The GNU General Public License, Version 3, June 2007 |
|
194
|
|
|
|
|
|
|
# |
|
195
|
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
1; |
|
197
|
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
__END__ |