| 1 |
package PDL::IO::HDF; |
| 2 |
|
| 3 |
=head1 NAME |
| 4 |
|
| 5 |
PDL::IO::HDF - A PDL interface to the HDF4 library. |
| 6 |
|
| 7 |
=head1 SYNOPSIS |
| 8 |
|
| 9 |
use PDL; |
| 10 |
use PDL::IO::HDF; |
| 11 |
|
| 12 |
# Open file 'foo.hdf' with all hdf interface: |
| 13 |
my $HDF = PDL::IO::HDF->new("foo.hdf"); |
| 14 |
|
| 15 |
# You can call functions from either the SD or VS interfaces: |
| 16 |
$HDF->{SD}->SDget("Foo_data"); |
| 17 |
$HDF->{VS}->VSgetnames(); |
| 18 |
|
| 19 |
# To close the file: |
| 20 |
$HDF->close(); |
| 21 |
|
| 22 |
=head1 DESCRIPTION |
| 23 |
|
| 24 |
This library provides functions to manipulate HDF files with the |
| 25 |
SD, VS, and V HDF interfaces. |
| 26 |
|
| 27 |
For more information on HDF, see http://hdf.ncsa.uiuc.edu/ |
| 28 |
|
| 29 |
The 'new' function of this package uses the 'new' functions for the |
| 30 |
individual HDF interfaces. This allows you to use all of the interfaces |
| 31 |
at one time (if you don't mind the extended syntax). |
| 32 |
|
| 33 |
Actually using the HDF files comes down to using one of the particular |
| 34 |
interfaces, for that see the docs on those modules. |
| 35 |
|
| 36 |
=cut |
| 37 |
|
| 38 |
use strict; |
| 39 |
use warnings; |
| 40 |
our $VERSION = '2.005'; |
| 41 |
$VERSION = eval $VERSION; |
| 42 |
|
| 43 |
use PDL::Primitive; |
| 44 |
use PDL::Basic; |
| 45 |
|
| 46 |
use PDL::IO::HDF::SD; |
| 47 |
use PDL::IO::HDF::VS; |
| 48 |
|
| 49 |
=head1 CONSTANTS |
| 50 |
|
| 51 |
These constants are now implemented using the perl 'use constant' pragma. |
| 52 |
|
| 53 |
Previously, they were just scalars that were changeable (which is a no-no). |
| 54 |
|
| 55 |
See constant(1) for more info on how to use these in your code. |
| 56 |
|
| 57 |
=head2 Access Modes |
| 58 |
|
| 59 |
=over 8 |
| 60 |
|
| 61 |
=item DFACC_READ |
| 62 |
|
| 63 |
Open the file in read-only mode. |
| 64 |
|
| 65 |
=item DFACC_WRITE |
| 66 |
|
| 67 |
Open the file in write-only mode. |
| 68 |
|
| 69 |
=item DFACC_CREATE |
| 70 |
|
| 71 |
Clobber the file (create it if it doesn't exist, and then open with RW mode). |
| 72 |
|
| 73 |
=item DFACC_ALL |
| 74 |
|
| 75 |
Open the file in read-write mode. |
| 76 |
|
| 77 |
=item DFACC_RDONLY |
| 78 |
|
| 79 |
Same as DFACC_READ |
| 80 |
|
| 81 |
=item DFACC_RDWR |
| 82 |
|
| 83 |
Open the file in read-write mode. |
| 84 |
|
| 85 |
=back |
| 86 |
|
| 87 |
=cut |
| 88 |
|
| 89 |
# Access modes: |
| 90 |
use constant { |
| 91 |
DFACC_READ => 1, |
| 92 |
DFACC_WRITE => 2, |
| 93 |
DFACC_CREATE => 4, |
| 94 |
DFACC_ALL => 7, |
| 95 |
DFACC_RDONLY => 1, |
| 96 |
DFACC_RDWR => 3, |
| 97 |
}; |
| 98 |
|
| 99 |
=head2 VS Interface Interlacing Modes |
| 100 |
|
| 101 |
=over 8 |
| 102 |
|
| 103 |
=item FULL_INTERLACE |
| 104 |
|
| 105 |
=item NO_INTERLACE |
| 106 |
|
| 107 |
=back |
| 108 |
|
| 109 |
=cut |
| 110 |
# VS interlace modes: |
| 111 |
use constant { |
| 112 |
FULL_INTERLACE => 0, |
| 113 |
NO_INTERLACE => 1, |
| 114 |
}; |
| 115 |
|
| 116 |
=head2 HDF4 Data Type Codes: |
| 117 |
|
| 118 |
=over 8 |
| 119 |
|
| 120 |
=item DFNT_UCHAR |
| 121 |
|
| 122 |
HDF's unsigned char ~= PDL's byte |
| 123 |
|
| 124 |
=item DFNT_CHAR |
| 125 |
|
| 126 |
HDF's char ~= PDL's byte |
| 127 |
|
| 128 |
=item DFNT_FLOAT32 |
| 129 |
|
| 130 |
HDF's 32-bit float ~= PDL's float |
| 131 |
|
| 132 |
=item DFNT_FLOAT64 |
| 133 |
|
| 134 |
HDF's 64-bit float ~= PDL's double |
| 135 |
|
| 136 |
=item DFNT_INT8 |
| 137 |
|
| 138 |
HDF's 8-bit integer ~= PDL's byte |
| 139 |
|
| 140 |
=item DFNT_UINT8 |
| 141 |
|
| 142 |
HDF's 8-bit unsigned integer ~= PDL's byte |
| 143 |
|
| 144 |
=item DFNT_INT16 |
| 145 |
|
| 146 |
HDF's 16-bit integer ~= PDL's short |
| 147 |
|
| 148 |
=item DFNT_UINT16 |
| 149 |
|
| 150 |
HDF's 16-bit unsigned integer ~= PDL's ushort |
| 151 |
|
| 152 |
=item DFNT_INT32 |
| 153 |
|
| 154 |
HDF's 32-bit integer ~= PDL's long |
| 155 |
|
| 156 |
=item DFNT_INT64 |
| 157 |
|
| 158 |
HDF's 32-bit integer ~= PDL's long |
| 159 |
|
| 160 |
=back |
| 161 |
|
| 162 |
=cut |
| 163 |
# HDF Data type numbers: |
| 164 |
use constant { |
| 165 |
DFNT_UCHAR => 3, |
| 166 |
DFNT_CHAR => 4, |
| 167 |
DFNT_FLOAT32 => 5, |
| 168 |
DFNT_FLOAT64 => 6, |
| 169 |
DFNT_INT8 => 20, |
| 170 |
DFNT_UINT8 => 21, |
| 171 |
DFNT_INT16 => 22, |
| 172 |
DFNT_UINT16 => 23, |
| 173 |
DFNT_INT32 => 24, |
| 174 |
DFNT_INT64 => 25, |
| 175 |
}; |
| 176 |
|
| 177 |
=head2 Misc. HDF Library Constants: |
| 178 |
|
| 179 |
=over 8 |
| 180 |
|
| 181 |
=item MAX_NC_NAME |
| 182 |
|
| 183 |
This is the max name length for SDS variables, attribtues, and just about anything else. |
| 184 |
|
| 185 |
=item MAX_VAR_DIMS |
| 186 |
|
| 187 |
This is the max number of dims a HDF variable can have. |
| 188 |
|
| 189 |
=back |
| 190 |
|
| 191 |
=cut |
| 192 |
|
| 193 |
# These are current with HDF4.2r1: |
| 194 |
# |
| 195 |
|
| 196 |
# Maximum Attr/SDS/VS name length: |
| 197 |
use constant MAX_NC_NAME => 256; |
| 198 |
|
| 199 |
# Maximum variable dims (use for alloc'ing mem for the low level calls that return dims: |
| 200 |
use constant MAX_VAR_DIMS => 32; |
| 201 |
|
| 202 |
use constant FAIL => -1; |
| 203 |
|
| 204 |
# Declaration of the different 'typemap' globals |
| 205 |
|
| 206 |
# NOTE: Since the keys & values below are constants, we need the () around them: |
| 207 |
|
| 208 |
#typemap pour convertir typePDL->typeHDF |
| 209 |
our $SDtypeTMAP = { |
| 210 |
PDL::byte->[0] => (DFNT_UINT8), |
| 211 |
PDL::short->[0] => (DFNT_INT16), |
| 212 |
PDL::ushort->[0] => (DFNT_UINT16), |
| 213 |
PDL::long->[0] => (DFNT_INT32), |
| 214 |
PDL::float->[0] => (DFNT_FLOAT32), |
| 215 |
PDL::double->[0] => (DFNT_FLOAT64), |
| 216 |
#PDL::byte->[0] => $DFNT_UCHAR ###attention PDL::byte 2x |
| 217 |
}; |
| 218 |
|
| 219 |
#typemap pour convertir typeHDF->typePDL |
| 220 |
our $SDinvtypeTMAP = { |
| 221 |
(DFNT_INT8) => sub { PDL::byte(@_); }, #badtype |
| 222 |
(DFNT_UINT8) => sub { PDL::byte(@_); }, |
| 223 |
(DFNT_INT16) => sub { PDL::short(@_); }, |
| 224 |
(DFNT_UINT16) => sub { PDL::ushort(@_); }, |
| 225 |
(DFNT_INT32) => sub { PDL::long(@_); }, |
| 226 |
(DFNT_INT64) => sub { PDL::long(@_); }, #badtype |
| 227 |
(DFNT_FLOAT32) => sub { PDL::float(@_); }, |
| 228 |
(DFNT_FLOAT64) => sub { PDL::double(@_); }, |
| 229 |
(DFNT_UCHAR) => sub { PDL::byte(@_); }, |
| 230 |
(DFNT_CHAR) => sub { PDL::byte(@_); } #badtype |
| 231 |
}; |
| 232 |
|
| 233 |
our $SDinvtypeTMAP2 = { |
| 234 |
(DFNT_INT8) => PDL::byte, |
| 235 |
(DFNT_UINT8) => PDL::byte, |
| 236 |
(DFNT_INT16) => PDL::short, |
| 237 |
(DFNT_UINT16) => PDL::ushort, |
| 238 |
(DFNT_INT32) => PDL::long, |
| 239 |
(DFNT_INT64) => PDL::long, |
| 240 |
(DFNT_FLOAT32) => PDL::float, |
| 241 |
(DFNT_FLOAT64) => PDL::double, |
| 242 |
(DFNT_UCHAR) => PDL::byte, |
| 243 |
(DFNT_CHAR) => PDL::byte, |
| 244 |
}; |
| 245 |
|
| 246 |
sub new |
| 247 |
{ |
| 248 |
my $type = shift; |
| 249 |
my $file = shift; |
| 250 |
|
| 251 |
my $obj = {}; |
| 252 |
|
| 253 |
$obj->{SD} = PDL::IO::HDF::SD->new( $file ); |
| 254 |
$obj->{VS} = PDL::IO::HDF::VS->new( $file ); |
| 255 |
|
| 256 |
bless $obj, $type; |
| 257 |
} # End of new()... |
| 258 |
|
| 259 |
sub close |
| 260 |
{ |
| 261 |
my $self = shift; |
| 262 |
$self->{SD}->close; |
| 263 |
$self->{VS}->close; |
| 264 |
} # End of close()... |
| 265 |
|
| 266 |
|
| 267 |
sub DESTROY |
| 268 |
{ |
| 269 |
my $self = shift; |
| 270 |
$self->close; |
| 271 |
} # End of DESTROY()... |
| 272 |
|
| 273 |
|
| 274 |
=head1 CURRENT AUTHOR & MAINTAINER |
| 275 |
|
| 276 |
Judd Taylor, Orbital Systems, Ltd. |
| 277 |
judd dot t at orbitalsystems dot com |
| 278 |
|
| 279 |
=head1 PREVIOUS AUTHORS |
| 280 |
|
| 281 |
Patrick Leilde [email protected] |
| 282 |
contribs of Olivier Archer [email protected] |
| 283 |
|
| 284 |
=head1 SEE ALSO |
| 285 |
|
| 286 |
perl(1), PDL(1), PDL::IO::HDF::SD(1), PDL::IO::HDF::VS(1), constant(1). |
| 287 |
|
| 288 |
=cut |
| 289 |
|
| 290 |
|