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