| 1 |
use strict; |
| 2 |
use warnings; |
| 3 |
|
| 4 |
pp_addpm({At => 'Top'}, <<'EOD'); |
| 5 |
use strict; |
| 6 |
use warnings; |
| 7 |
|
| 8 |
=head1 NAME |
| 9 |
|
| 10 |
PDL::IO::HDF::VS - An interface library for HDF4 files. |
| 11 |
|
| 12 |
=head1 SYNOPSIS |
| 13 |
|
| 14 |
use PDL; |
| 15 |
use PDL::IO::HDF::VS; |
| 16 |
|
| 17 |
#### no doc for now #### |
| 18 |
|
| 19 |
=head1 DESCRIPTION |
| 20 |
|
| 21 |
This library provides functions to manipulate |
| 22 |
HDF4 files with VS and V interface (reading, writing, ...) |
| 23 |
|
| 24 |
For more information on HDF4, see http://www.hdfgroup.org/products/hdf4/ |
| 25 |
|
| 26 |
=head1 FUNCTIONS |
| 27 |
|
| 28 |
=cut |
| 29 |
EOD |
| 30 |
|
| 31 |
pp_addhdr(<<'EOH'); |
| 32 |
|
| 33 |
#include <hdf.h> |
| 34 |
#include <mfhdf.h> |
| 35 |
#include <hfile.h> |
| 36 |
#include <string.h> |
| 37 |
#include <stdio.h> |
| 38 |
|
| 39 |
#include <perl.h> |
| 40 |
#include <EXTERN.h> |
| 41 |
#include <XSUB.h> |
| 42 |
|
| 43 |
#define PDLchar pdl |
| 44 |
#define PDLuchar pdl |
| 45 |
#define PDLshort pdl |
| 46 |
#define PDLint pdl |
| 47 |
#define PDLlong pdl |
| 48 |
#define PDLfloat pdl |
| 49 |
#define PDLdouble pdl |
| 50 |
#define PDLvoid pdl |
| 51 |
#define uchar unsigned char |
| 52 |
|
| 53 |
#define PDLlist pdl |
| 54 |
|
| 55 |
EOH |
| 56 |
|
| 57 |
#define AVRef AV |
| 58 |
#pp_bless ("PDL::IO::HDF::VS"); |
| 59 |
|
| 60 |
use FindBin; |
| 61 |
use lib "$FindBin::Bin/.."; |
| 62 |
use buildfunc; |
| 63 |
|
| 64 |
|
| 65 |
#------------------------------------------------------------------------- |
| 66 |
# Create low level interface from HDF VS and V header file. |
| 67 |
#------------------------------------------------------------------------- |
| 68 |
|
| 69 |
create_low_level (<<'EODEF'); |
| 70 |
# |
| 71 |
# HDF (H) Interface |
| 72 |
# |
| 73 |
int Hishdf(const char *filename); |
| 74 |
int Hopen(const char *filename, int access, int n_dds); |
| 75 |
int Hclose(int file_id)+1; |
| 76 |
# |
| 77 |
# VGROUP/VDATA Interface |
| 78 |
# |
| 79 |
int Vstart(int hdfid); |
| 80 |
int Vend(int hdfid); |
| 81 |
int Vgetid(int hdfid, int vgroup_ref); |
| 82 |
int Vattach(int hdfid, int vgroup_ref, const char *access); |
| 83 |
int Vdetach(int vgroup_id); |
| 84 |
int Vntagrefs(int vgroup_id); |
| 85 |
|
| 86 |
int Vgettagref(int vgroup_id, int index, int *tag, int *ref); |
| 87 |
|
| 88 |
int Vsetname(int vgroup_id, const char *vgroup_name); |
| 89 |
int Vsetclass(int vgroup_id, const char *vgroup_class); |
| 90 |
int Visvg(int vgroup_id, int obj_ref); |
| 91 |
int Visvs(int vgroup_id, int obj_ref); |
| 92 |
int Vaddtagref(int vgroup_id, int tag, int ref); |
| 93 |
int Vinsert(int vgroup_id, int v_id); |
| 94 |
|
| 95 |
int VSsetname(int vdata_id, const char *vdata_name); |
| 96 |
int VSsetclass(int vdata_id, const char *vdata_class); |
| 97 |
int VSgetid(int hdfid, int vdata_ref); |
| 98 |
int VSattach(int hdfid, int vdata_ref, const char *access); |
| 99 |
int VSdetach(int vdata_id); |
| 100 |
int VSelts(int vdata_id); |
| 101 |
int VSsizeof(int vdata_id, const char *fields); |
| 102 |
int VSfind(int hdfid, const char *vdata_name); |
| 103 |
int VFfieldtype(int vdata_id, int field_index); |
| 104 |
int VFnfields(int vdata_ref); |
| 105 |
int VFfieldorder(int vdata_ref, int field_index); |
| 106 |
|
| 107 |
int VSfdefine(int vata_id, const char *fieldname, int data_type, int order)+1; |
| 108 |
int VSsetfields(int vata_id, const char *fieldname_list)+1; |
| 109 |
int VSwrite(int vdata_id, const PDLvoid *databuf, int n_records, int interlace_mode); |
| 110 |
int VSread(int vdata_id, PDLvoid *databuf, int n_records, int interlace_mode); |
| 111 |
#int VSlone(int file_id, int *ref_array, int max_ref); |
| 112 |
|
| 113 |
int VSfnattrs(int vdata_id, int field_index); |
| 114 |
int VSgetattr(int vdata_id, int field_index, int attr_index, PDLlong *values); |
| 115 |
int VSisattr(int vdata_id); |
| 116 |
|
| 117 |
int SDstart(const char *filename, int access_mode); |
| 118 |
int SDreftoindex(int sd_id, int sds_ref); |
| 119 |
int SDselect(int sd_id, int index); |
| 120 |
int SDgetinfo(int sds_id, char *sds_name, int *rank, int *dimsizes, int *number_type, int *nattrs); |
| 121 |
int SDendaccess(int sds_id); |
| 122 |
int SDend(int sd_id); |
| 123 |
|
| 124 |
EODEF |
| 125 |
|
| 126 |
pp_addxs('',<<'ENDOFXS'); |
| 127 |
|
| 128 |
int |
| 129 |
_WriteMultPDL(VID, nb_records, nb_fields, interlace_mode, sizeofPDL, sdimofPDL, listofPDL); |
| 130 |
int VID |
| 131 |
int nb_records |
| 132 |
int nb_fields |
| 133 |
int interlace_mode |
| 134 |
AV *sizeofPDL |
| 135 |
AV *sdimofPDL |
| 136 |
AV *listofPDL |
| 137 |
PROTOTYPE: @ |
| 138 |
CODE: |
| 139 |
unsigned long int total_size = 0; |
| 140 |
int i, j, k; |
| 141 |
for(i=0; i<nb_fields; i++) |
| 142 |
{ |
| 143 |
SV **SvTmp1 = av_fetch(sizeofPDL, i, 0); |
| 144 |
int curvalue = SvIV( *SvTmp1 ); |
| 145 |
SV **SvTmp3 = av_fetch(sdimofPDL, i, 0); |
| 146 |
int cursdim = SvIV( *SvTmp3 ); |
| 147 |
total_size += curvalue * cursdim; |
| 148 |
} |
| 149 |
total_size *= nb_records; |
| 150 |
unsigned char *databuff = (unsigned char *)malloc( total_size ); |
| 151 |
if(databuff==NULL) |
| 152 |
croak("memory allocation error"); |
| 153 |
unsigned char *ptrbuff = databuff; |
| 154 |
if(interlace_mode == 0) |
| 155 |
{ |
| 156 |
for(i=0; i<nb_records; i++) |
| 157 |
{ |
| 158 |
for(j=0; j<nb_fields; j++) |
| 159 |
{ |
| 160 |
SV **SvTmp2 = av_fetch(listofPDL, j, 0); |
| 161 |
pdl *curPDL = PDL->SvPDLV( *SvTmp2 ); |
| 162 |
SV **SvTmp3 = av_fetch(sdimofPDL, j, 0); |
| 163 |
int cursdim = SvIV( *SvTmp3 ); |
| 164 |
SV **SvTmp1 = av_fetch(sizeofPDL, j, 0); |
| 165 |
int curvalue = SvIV( *SvTmp1 ); |
| 166 |
for(k=0; k<cursdim; k++) |
| 167 |
{ |
| 168 |
memcpy( ptrbuff, (unsigned char *)(curPDL->data + curvalue*i + curvalue*k*nb_records), curvalue ); |
| 169 |
ptrbuff += curvalue; |
| 170 |
} |
| 171 |
} |
| 172 |
} |
| 173 |
} |
| 174 |
else |
| 175 |
{ |
| 176 |
for(j=0; j<nb_fields; j++) |
| 177 |
{ |
| 178 |
SV **SvTmp2 = av_fetch(listofPDL, j, 0); |
| 179 |
pdl *curPDL = PDL->SvPDLV( *SvTmp2 ); |
| 180 |
SV **SvTmp3 = av_fetch(sdimofPDL, j, 0); |
| 181 |
int cursdim = SvIV( *SvTmp3 ); |
| 182 |
SV **SvTmp1 = av_fetch(sizeofPDL, j, 0); |
| 183 |
int curvalue = SvIV( *SvTmp1 ); |
| 184 |
memcpy( ptrbuff, (unsigned char *)(curPDL->data), curvalue*nb_records*cursdim ); |
| 185 |
ptrbuff += curvalue*nb_records*cursdim; |
| 186 |
#printf("buffer %d= %d\n", k, curvalue*nb_records*cursdim); |
| 187 |
} |
| 188 |
interlace_mode = 1; |
| 189 |
} |
| 190 |
fprintf(stderr, "Calling VSwrite(VID=%d, databuff=%p, nb_records=%d, interlace_mode=%d)...\n", |
| 191 |
VID, databuff, nb_records, interlace_mode); |
| 192 |
RETVAL = VSwrite(VID, databuff, nb_records, interlace_mode); |
| 193 |
free(databuff); |
| 194 |
OUTPUT: |
| 195 |
RETVAL |
| 196 |
|
| 197 |
SV * |
| 198 |
_Vgetname(vgroup_id); |
| 199 |
int vgroup_id |
| 200 |
CODE: |
| 201 |
#if LIBVER_MAJOR == 4 && LIBVER_MINOR >= 4 |
| 202 |
char vgroup_name[VGNAMELENMAX]; |
| 203 |
size_t buf_size = sizeof(vgroup_name); |
| 204 |
Vgetname(vgroup_id,vgroup_name,&buf_size); |
| 205 |
RETVAL = newSVpvn(vgroup_name,buf_size); |
| 206 |
#else |
| 207 |
uint16 len; |
| 208 |
if (Vgetnamelen(vgroup_id, &len)) croak("Failed to get Vgetnamelen for ID=%d", vgroup_id); |
| 209 |
char vgroup_name[len+1]; |
| 210 |
Vgetname(vgroup_id,vgroup_name); |
| 211 |
RETVAL = newSVpvn(vgroup_name,len); |
| 212 |
#endif |
| 213 |
OUTPUT: |
| 214 |
RETVAL |
| 215 |
|
| 216 |
SV * |
| 217 |
_VSgetname(vdata_id); |
| 218 |
int vdata_id |
| 219 |
CODE: |
| 220 |
char vdata_name[VGNAMELENMAX]; |
| 221 |
VSgetname(vdata_id,vdata_name); |
| 222 |
RETVAL = newSVpv(vdata_name,0); |
| 223 |
OUTPUT: |
| 224 |
RETVAL |
| 225 |
|
| 226 |
SV * |
| 227 |
_Vgetclass(vgroup_id); |
| 228 |
int vgroup_id |
| 229 |
CODE: |
| 230 |
#if LIBVER_MAJOR == 4 && LIBVER_MINOR >= 4 |
| 231 |
char vgroup_class[VGNAMELENMAX]; |
| 232 |
size_t buf_size = sizeof(vgroup_class); |
| 233 |
Vgetclass(vgroup_id,vgroup_class,&buf_size); |
| 234 |
RETVAL = newSVpvn(vgroup_class,buf_size); |
| 235 |
#else |
| 236 |
uint16 len; |
| 237 |
if (Vgetclassnamelen(vgroup_id, &len)) croak("Failed to get Vgetclassnamelen for ID=%d", vgroup_id); |
| 238 |
char vgroup_class[len+1]; |
| 239 |
Vgetclass(vgroup_id,vgroup_class); |
| 240 |
RETVAL = newSVpvn(vgroup_class,len); |
| 241 |
#endif |
| 242 |
OUTPUT: |
| 243 |
RETVAL |
| 244 |
|
| 245 |
SV * |
| 246 |
_VSgetclass(vdata_id); |
| 247 |
int vdata_id |
| 248 |
CODE: |
| 249 |
char vdata_class[VGNAMELENMAX]; |
| 250 |
VSgetclass(vdata_id,vdata_class); |
| 251 |
RETVAL = newSVpv(vdata_class,0); |
| 252 |
OUTPUT: |
| 253 |
RETVAL |
| 254 |
|
| 255 |
int |
| 256 |
_VSgetfields(vdata_id, fields); |
| 257 |
int vdata_id |
| 258 |
char *fields |
| 259 |
CODE: |
| 260 |
char tmpfields[10000]; |
| 261 |
RETVAL=VSgetfields(vdata_id, tmpfields); |
| 262 |
fields = tmpfields; |
| 263 |
OUTPUT: |
| 264 |
RETVAL |
| 265 |
fields |
| 266 |
|
| 267 |
AV * |
| 268 |
_VSlone(file_id); |
| 269 |
int file_id; |
| 270 |
CODE: |
| 271 |
AV *ref_vdata_list=newAV(); |
| 272 |
int ref_array[MAX_FIELD_SIZE]; |
| 273 |
int32 nlone = VSlone(file_id, ref_array, MAX_FIELD_SIZE); |
| 274 |
int32 i; |
| 275 |
for(i=0;i<nlone;i++){ |
| 276 |
av_push(ref_vdata_list, newSViv((IV)ref_array[i])); |
| 277 |
} |
| 278 |
RETVAL=ref_vdata_list; |
| 279 |
OUTPUT: |
| 280 |
RETVAL |
| 281 |
|
| 282 |
void |
| 283 |
_VSinquire(vdata_id, n_records, interlace, fields, vdata_size, vdata_name); |
| 284 |
int vdata_id |
| 285 |
int *n_records |
| 286 |
int *interlace |
| 287 |
char *fields |
| 288 |
int *vdata_size |
| 289 |
char *vdata_name |
| 290 |
CODE: |
| 291 |
char tmpfields[10000]; |
| 292 |
char tmpname[VGNAMELENMAX]; |
| 293 |
if (VSinquire(vdata_id, n_records, interlace, tmpfields, vdata_size, tmpname)) |
| 294 |
croak("PDL::IO::HDF::VS::_VSinquire (vdata_id=%d)",vdata_id); |
| 295 |
vdata_name=tmpname; |
| 296 |
fields = tmpfields; |
| 297 |
OUTPUT: |
| 298 |
n_records |
| 299 |
interlace |
| 300 |
fields |
| 301 |
vdata_size |
| 302 |
vdata_name |
| 303 |
|
| 304 |
ENDOFXS |
| 305 |
|
| 306 |
pp_addpm(<<'EOPM'); |
| 307 |
|
| 308 |
use PDL::Primitive; |
| 309 |
use PDL::Basic; |
| 310 |
|
| 311 |
use PDL::IO::HDF; |
| 312 |
|
| 313 |
my $TMAP = { |
| 314 |
PDL::byte->[0] => 1, |
| 315 |
PDL::short->[0] => 2, |
| 316 |
PDL::ushort->[0] => 2, |
| 317 |
PDL::long->[0] => 4, |
| 318 |
PDL::float->[0] => 4, |
| 319 |
PDL::double->[0] => 8 |
| 320 |
}; |
| 321 |
|
| 322 |
sub _pkg_name |
| 323 |
{ return "PDL::IO::HDF::VS::" . shift() . "()"; } |
| 324 |
|
| 325 |
=head2 new |
| 326 |
|
| 327 |
=for ref |
| 328 |
|
| 329 |
Open or create a new HDF object with VS and V interface. |
| 330 |
|
| 331 |
=for usage |
| 332 |
|
| 333 |
Arguments: |
| 334 |
1 : The name of the HDF file. |
| 335 |
If you want to write to it, prepend the name with the '+' character : "+name.hdf" |
| 336 |
If you want to create it, prepend the name with the '-' character : "-name.hdf" |
| 337 |
Otherwise the file will be opened in read only mode. |
| 338 |
|
| 339 |
Returns the hdf object (die on error) |
| 340 |
|
| 341 |
=for example |
| 342 |
|
| 343 |
my $hdf = PDL::IO::HDF::VS->new("file.hdf"); |
| 344 |
|
| 345 |
=cut |
| 346 |
|
| 347 |
sub new |
| 348 |
{ |
| 349 |
# general |
| 350 |
my $type = shift; |
| 351 |
my $filename = shift; |
| 352 |
|
| 353 |
my $self = {}; |
| 354 |
|
| 355 |
if (substr($filename, 0, 1) eq '+') |
| 356 |
{ # open for writing |
| 357 |
$filename = substr ($filename, 1); # chop off + |
| 358 |
$self->{ACCESS_MODE} = PDL::IO::HDF->DFACC_WRITE + PDL::IO::HDF->DFACC_READ; |
| 359 |
} |
| 360 |
if (substr($filename, 0, 1) eq '-') |
| 361 |
{ # Creating |
| 362 |
$filename = substr ($filename, 1); # chop off - |
| 363 |
$self->{ACCESS_MODE} = PDL::IO::HDF->DFACC_CREATE; |
| 364 |
} |
| 365 |
|
| 366 |
unless( defined($self->{ACCESS_MODE}) ) |
| 367 |
{ |
| 368 |
$self->{ACCESS_MODE} = PDL::IO::HDF->DFACC_READ; |
| 369 |
} |
| 370 |
|
| 371 |
$self->{FILE_NAME} = $filename; |
| 372 |
|
| 373 |
$self->{HID} = PDL::IO::HDF::VS::_Hopen( $self->{FILE_NAME}, $self->{ACCESS_MODE}, 20 ); |
| 374 |
if ($self->{HID}) |
| 375 |
{ |
| 376 |
PDL::IO::HDF::VS::_Vstart( $self->{HID} ); |
| 377 |
|
| 378 |
my $SDID = PDL::IO::HDF::VS::_SDstart( $self->{FILE_NAME}, $self->{ACCESS_MODE} ); |
| 379 |
|
| 380 |
#### search for vgroup |
| 381 |
my $vgroup = {}; |
| 382 |
|
| 383 |
my $vg_ref = -1; |
| 384 |
while( ($vg_ref = PDL::IO::HDF::VS::_Vgetid( $self->{HID}, $vg_ref )) != PDL::IO::HDF->FAIL) |
| 385 |
{ |
| 386 |
my $vg_id = PDL::IO::HDF::VS::_Vattach( $self->{HID}, $vg_ref, 'r' ); |
| 387 |
my $vg_name = PDL::IO::HDF::VS::_Vgetname($vg_id); |
| 388 |
$vgroup->{$vg_name}{ref} = $vg_ref; |
| 389 |
$vgroup->{$vg_name}{class} = PDL::IO::HDF::VS::_Vgetclass($vg_id); |
| 390 |
my $n_pairs = PDL::IO::HDF::VS::_Vntagrefs( $vg_id ); |
| 391 |
for ( 0 .. $n_pairs-1 ) |
| 392 |
{ |
| 393 |
my ($tag, $ref); |
| 394 |
my $res = PDL::IO::HDF::VS::_Vgettagref( $vg_id, $_, $tag = 0, $ref = 0 ); |
| 395 |
if($tag == 1965) |
| 396 |
{ # Vgroup |
| 397 |
my $id = PDL::IO::HDF::VS::_Vattach( $self->{HID}, $ref, 'r' ); |
| 398 |
my $name = PDL::IO::HDF::VS::_Vgetname($id); |
| 399 |
PDL::IO::HDF::VS::_Vdetach( $id ); |
| 400 |
$vgroup->{$vg_name}->{children}->{$name} = $ref; |
| 401 |
$vgroup->{$name}->{parents}->{$vg_name} = $vg_ref; |
| 402 |
} |
| 403 |
elsif($tag == 1962) |
| 404 |
{ # Vdata |
| 405 |
my $id = PDL::IO::HDF::VS::_VSattach( $self->{HID}, $ref, 'r' ); |
| 406 |
my $name = PDL::IO::HDF::VS::_VSgetname( $id ); |
| 407 |
my $class = PDL::IO::HDF::VS::_VSgetclass( $id ); |
| 408 |
PDL::IO::HDF::VS::_VSdetach( $id ); |
| 409 |
$vgroup->{$vg_name}->{attach}->{$name}->{type} = 'VData'; |
| 410 |
$vgroup->{$vg_name}->{attach}->{$name}->{ref} = $ref; |
| 411 |
$vgroup->{$vg_name}->{attach}->{$name}->{class} = $class |
| 412 |
if( $class ne '' ); |
| 413 |
} |
| 414 |
if( ($SDID != PDL::IO::HDF->FAIL) && ($tag == 720)) #tag for SDS tag/ref (see 702) |
| 415 |
{ |
| 416 |
my $i = _SDreftoindex( $SDID, $ref ); |
| 417 |
my $sds_ID = _SDselect( $SDID, $i ); |
| 418 |
my $name = " "x(PDL::IO::HDF->MAX_NC_NAME+1); |
| 419 |
my $rank = 0; |
| 420 |
my $dimsize = " "x( (4 * PDL::IO::HDF->MAX_VAR_DIMS) + 1 ); |
| 421 |
my $numtype = 0; |
| 422 |
my $nattrs = 0; |
| 423 |
|
| 424 |
$res = _SDgetinfo( $sds_ID, $name, $rank, $dimsize , $numtype, $nattrs ); |
| 425 |
$vgroup->{$vg_name}->{attach}->{$name}->{type} = 'SDS_Data'; |
| 426 |
$vgroup->{$vg_name}->{attach}->{$name}->{ref} = $ref; |
| 427 |
} |
| 428 |
} # for each pair... |
| 429 |
PDL::IO::HDF::VS::_Vdetach( $vg_id ); |
| 430 |
} # while vg_ref... |
| 431 |
|
| 432 |
PDL::IO::HDF::VS::_SDend( $SDID ); |
| 433 |
$self->{VGROUP} = $vgroup; |
| 434 |
|
| 435 |
#### search for vdata |
| 436 |
my $vdata_ref=-1; |
| 437 |
my $vdata_id=-1; |
| 438 |
my $vdata = {}; |
| 439 |
|
| 440 |
# get lone vdata (not member of a vgroup) |
| 441 |
my $lone=PDL::IO::HDF::VS::_VSlone($self->{HID}); |
| 442 |
|
| 443 |
while ( $vdata_ref = shift @$lone ) |
| 444 |
{ |
| 445 |
my $mode="r"; |
| 446 |
if ( $self->{ACCESS_MODE} != PDL::IO::HDF->DFACC_READ ) |
| 447 |
{ |
| 448 |
$mode="w"; |
| 449 |
} |
| 450 |
$vdata_id = PDL::IO::HDF::VS::_VSattach( $self->{HID}, $vdata_ref, $mode ); |
| 451 |
my $n_records = 0; |
| 452 |
my $interlace = 0; |
| 453 |
my $fields = ""; |
| 454 |
my $vdata_size = 0; |
| 455 |
my $vdata_name = ""; |
| 456 |
|
| 457 |
PDL::IO::HDF::VS::_VSinquire( |
| 458 |
$vdata_id, $n_records, $interlace, $fields, $vdata_size, $vdata_name ); |
| 459 |
$vdata->{$vdata_name}->{REF} = $vdata_ref; |
| 460 |
$vdata->{$vdata_name}->{NREC} = $n_records; |
| 461 |
$vdata->{$vdata_name}->{INTERLACE} = $interlace; |
| 462 |
|
| 463 |
$vdata->{$vdata_name}->{ISATTR} = PDL::IO::HDF::VS::_VSisattr( $vdata_id ); |
| 464 |
|
| 465 |
my $field_index = 0; |
| 466 |
foreach my $onefield ( split( ",", $fields ) ) |
| 467 |
{ |
| 468 |
$vdata->{$vdata_name}->{FIELDS}->{$onefield}->{TYPE} = |
| 469 |
PDL::IO::HDF::VS::_VFfieldtype( $vdata_id, $field_index ); |
| 470 |
$vdata->{$vdata_name}->{FIELDS}->{$onefield}->{INDEX} = $field_index; |
| 471 |
$field_index++; |
| 472 |
} |
| 473 |
|
| 474 |
PDL::IO::HDF::VS::_VSdetach( $vdata_id ); |
| 475 |
} # while vdata_ref... |
| 476 |
|
| 477 |
$self->{VDATA} = $vdata; |
| 478 |
} # if $self->{HDID}... |
| 479 |
|
| 480 |
bless($self, $type); |
| 481 |
} # End of new()... |
| 482 |
|
| 483 |
sub Vgetchildren |
| 484 |
{ |
| 485 |
my ($self, $name) = @_; |
| 486 |
return( undef ) |
| 487 |
unless defined( $self->{VGROUP}->{$name}->{children} ); |
| 488 |
|
| 489 |
return sort keys %{$self->{VGROUP}->{$name}->{children}}; |
| 490 |
} # End of Vgetchildren()... |
| 491 |
# Now defunct: |
| 492 |
sub Vgetchilds |
| 493 |
{ |
| 494 |
my $self = shift; |
| 495 |
return $self->Vgetchildren( @_ ); |
| 496 |
} # End of Vgetchilds()... |
| 497 |
|
| 498 |
sub Vgetattach |
| 499 |
{ |
| 500 |
my ($self, $name) = @_; |
| 501 |
return( undef ) |
| 502 |
unless defined( $self->{VGROUP}->{$name}->{attach} ); |
| 503 |
|
| 504 |
return sort keys %{$self->{VGROUP}->{$name}->{children}}; |
| 505 |
} # End of Vgetattach()... |
| 506 |
|
| 507 |
sub Vgetparents |
| 508 |
{ |
| 509 |
my ($self, $name) = @_; |
| 510 |
return( undef ) |
| 511 |
unless defined( $self->{VGROUP}->{$name}->{parents} ); |
| 512 |
|
| 513 |
return sort keys %{$self->{VGROUP}->{$name}->{parents}}; |
| 514 |
} # End of Vgetparents()... |
| 515 |
|
| 516 |
sub Vgetmains |
| 517 |
{ |
| 518 |
my ($self) = @_; |
| 519 |
my @rlist; |
| 520 |
foreach( sort keys %{$self->{VGROUP}} ) |
| 521 |
{ |
| 522 |
push(@rlist, $_) |
| 523 |
unless defined( $self->{VGROUP}->{$_}->{parents} ); |
| 524 |
} |
| 525 |
return @rlist; |
| 526 |
} # End of Vgetmains()... |
| 527 |
|
| 528 |
sub Vcreate |
| 529 |
{ |
| 530 |
my($self, $name, $class, $where) = @_; |
| 531 |
|
| 532 |
my $id = PDL::IO::HDF::VS::_Vattach( $self->{HID}, -1, 'w' ); |
| 533 |
return( undef ) |
| 534 |
if( $id == PDL::IO::HDF->FAIL ); |
| 535 |
|
| 536 |
my $res = _Vsetname($id, $name); |
| 537 |
$res = _Vsetclass($id, $class) |
| 538 |
if defined( $class ); |
| 539 |
|
| 540 |
$self->{VGROUP}->{$name}->{ref} = '???'; |
| 541 |
$self->{VGROUP}->{$name}->{class} = $class |
| 542 |
if defined( $class ); |
| 543 |
|
| 544 |
if( defined( $where ) ) |
| 545 |
{ |
| 546 |
return( undef ) |
| 547 |
unless defined( $self->{VGROUP}->{$where} ); |
| 548 |
|
| 549 |
my $ref = $self->{VGROUP}->{$where}->{ref}; |
| 550 |
|
| 551 |
my $Pid = PDL::IO::HDF::VS::_Vattach( $self->{HID}, $ref, 'w' ); |
| 552 |
my $index = PDL::IO::HDF::VS::_Vinsert( $Pid, $id ); |
| 553 |
my ($t, $r) = (0, 0); |
| 554 |
$res = PDL::IO::HDF::VS::_Vgettagref( $Pid, $index, $t, $r ); |
| 555 |
PDL::IO::HDF::VS::_Vdetach( $Pid ); |
| 556 |
|
| 557 |
$self->{VGROUP}->{$name}->{parents}->{$where} = $ref; |
| 558 |
$self->{VGROUP}->{$where}->{children}->{$name} = $r; |
| 559 |
$self->{VGROUP}->{$name}->{ref} = $r; |
| 560 |
} |
| 561 |
return( _Vdetach( $id ) + 1 ); |
| 562 |
} # End of Vcreate()... |
| 563 |
|
| 564 |
=head2 close |
| 565 |
|
| 566 |
=for ref |
| 567 |
|
| 568 |
Close the VS interface. |
| 569 |
|
| 570 |
=for usage |
| 571 |
|
| 572 |
no arguments |
| 573 |
|
| 574 |
=for example |
| 575 |
|
| 576 |
my $result = $hdf->close(); |
| 577 |
|
| 578 |
=cut |
| 579 |
|
| 580 |
sub close |
| 581 |
{ |
| 582 |
my $self = shift; |
| 583 |
_Vend( $self->{HID} ); |
| 584 |
my $Hid = $self->{HID}; |
| 585 |
$self = undef; |
| 586 |
return( _Hclose($Hid) + 1 ); |
| 587 |
} # End of close()... |
| 588 |
|
| 589 |
sub VSisattr |
| 590 |
{ |
| 591 |
my($self, $name) = @_; |
| 592 |
|
| 593 |
return undef |
| 594 |
unless defined( $self->{VDATA}->{$name} ); |
| 595 |
|
| 596 |
return $self->{VDATA}->{$name}->{ISATTR}; |
| 597 |
} # End of VSisattr()... |
| 598 |
|
| 599 |
sub VSgetnames |
| 600 |
{ |
| 601 |
my $self = shift; |
| 602 |
return sort keys %{$self->{VDATA}}; |
| 603 |
} # End of VSgetnames()... |
| 604 |
|
| 605 |
sub VSgetfieldnames |
| 606 |
{ |
| 607 |
my ( $self, $name ) = @_; |
| 608 |
|
| 609 |
my $sub = _pkg_name( 'VSgetfieldnames' ); |
| 610 |
|
| 611 |
die "$sub: vdata name $name doesn't exist!\n" |
| 612 |
unless defined( $self->{VDATA}->{$name} ); |
| 613 |
|
| 614 |
return sort keys %{$self->{VDATA}->{$name}->{FIELDS}}; |
| 615 |
} # End of VSgetfieldnames()... |
| 616 |
# Now defunct: |
| 617 |
sub VSgetfieldsnames |
| 618 |
{ |
| 619 |
my $self = shift; |
| 620 |
return $self->VSgetfieldnames( @_ ); |
| 621 |
} # End of VSgetfieldsnames()... |
| 622 |
|
| 623 |
|
| 624 |
sub VSread |
| 625 |
{ |
| 626 |
my ( $self, $name, $field ) = @_; |
| 627 |
my $sub = _pkg_name( 'VSread' ); |
| 628 |
|
| 629 |
my $data = null; |
| 630 |
my $vdata_ref = PDL::IO::HDF::VS::_VSfind( $self->{HID}, $name ); |
| 631 |
|
| 632 |
die "$sub: vdata name $name doesn't exist!\n" |
| 633 |
unless $vdata_ref; |
| 634 |
|
| 635 |
my $vdata_id = PDL::IO::HDF::VS::_VSattach( $self->{HID}, $vdata_ref, 'r' ); |
| 636 |
my $vdata_size = 0; |
| 637 |
my $n_records = 0; |
| 638 |
my $interlace = 0; |
| 639 |
my $fields = ""; |
| 640 |
my $vdata_name = ""; |
| 641 |
PDL::IO::HDF::VS::_VSinquire( |
| 642 |
$vdata_id, $n_records, $interlace, $fields, $vdata_size, $vdata_name ); |
| 643 |
my $data_type = PDL::IO::HDF::VS::_VFfieldtype( |
| 644 |
$vdata_id, $self->{VDATA}->{$name}->{FIELDS}->{$field}->{INDEX} ); |
| 645 |
|
| 646 |
die "$sub: data_type $data_type not implemented!\n" |
| 647 |
unless defined( $PDL::IO::HDF::SDinvtypeTMAP->{$data_type} ); |
| 648 |
|
| 649 |
my $order = PDL::IO::HDF::VS::_VFfieldorder( |
| 650 |
$vdata_id, $self->{VDATA}->{$name}->{FIELDS}->{$field}->{INDEX} ); |
| 651 |
|
| 652 |
if($order == 1) |
| 653 |
{ |
| 654 |
$data = ones( $PDL::IO::HDF::SDinvtypeTMAP2->{$data_type}, $n_records ); |
| 655 |
} |
| 656 |
else |
| 657 |
{ |
| 658 |
$data = ones( $PDL::IO::HDF::SDinvtypeTMAP2->{$data_type}, $n_records, $order ); |
| 659 |
} |
| 660 |
my $status = PDL::IO::HDF::VS::_VSsetfields( $vdata_id, $field ); |
| 661 |
|
| 662 |
die "$sub: _VSsetfields\n" |
| 663 |
unless $status; |
| 664 |
|
| 665 |
$status = PDL::IO::HDF::VS::_VSread( $vdata_id, $data, $n_records, $interlace); |
| 666 |
|
| 667 |
PDL::IO::HDF::VS::_VSdetach( $vdata_id ); |
| 668 |
return $data; |
| 669 |
} # End of VSread()... |
| 670 |
|
| 671 |
sub VSwrite |
| 672 |
{ |
| 673 |
my($self, $name, $mode, $field, $value) = @_; |
| 674 |
|
| 675 |
return( undef ) |
| 676 |
if( $$value[0]->getndims > 2); #too many dims |
| 677 |
|
| 678 |
my $VD_id; |
| 679 |
my $res; |
| 680 |
my @foo = split( /:/, $name ); |
| 681 |
|
| 682 |
return( undef ) |
| 683 |
if defined( $self->{VDATA}->{$foo[0]} ); |
| 684 |
|
| 685 |
$VD_id = _VSattach( $self->{HID}, -1, 'w' ); |
| 686 |
|
| 687 |
return( undef ) |
| 688 |
if( $VD_id == PDL::IO::HDF->FAIL ); |
| 689 |
|
| 690 |
$res = _VSsetname( $VD_id, $foo[0] ); |
| 691 |
return( undef ) |
| 692 |
if( $res == PDL::IO::HDF->FAIL ); |
| 693 |
|
| 694 |
$res = _VSsetclass( $VD_id, $foo[1] ) |
| 695 |
if defined( $foo[1] ); |
| 696 |
return( undef ) |
| 697 |
if( $res == PDL::IO::HDF->FAIL ); |
| 698 |
|
| 699 |
my @listfield = split( /,/, $field ); |
| 700 |
for( my $i = 0; $i <= $#$value; $i++ ) |
| 701 |
{ |
| 702 |
my $HDFtype = $PDL::IO::HDF::SDtypeTMAP->{$$value[$i]->get_datatype()}; |
| 703 |
$res = _VSfdefine( $VD_id, $listfield[$i], $HDFtype, $$value[$i]->getdim(1) ); |
| 704 |
return( undef ) |
| 705 |
unless $res; |
| 706 |
} |
| 707 |
|
| 708 |
$res = _VSsetfields( $VD_id, $field ); |
| 709 |
return( undef ) |
| 710 |
unless $res; |
| 711 |
|
| 712 |
my @sizeofPDL; |
| 713 |
my @sdimofPDL; |
| 714 |
foreach ( @$value ) |
| 715 |
{ |
| 716 |
push(@sdimofPDL, $_->getdim(1)); |
| 717 |
push(@sizeofPDL, $TMAP->{$_->get_datatype()}); |
| 718 |
} |
| 719 |
$res = _WriteMultPDL( $VD_id, $$value[0]->getdim(0), $#$value+1, $mode, \@sizeofPDL, \@sdimofPDL, $value); |
| 720 |
|
| 721 |
return( undef ) |
| 722 |
if( _VSdetach($VD_id) == PDL::IO::HDF->FAIL ); |
| 723 |
return $res; |
| 724 |
} # End of VSwrite()... |
| 725 |
|
| 726 |
|
| 727 |
sub DESTROY |
| 728 |
{ |
| 729 |
my $self = shift; |
| 730 |
$self->close; |
| 731 |
} # End of DESTROY()... |
| 732 |
|
| 733 |
EOPM |
| 734 |
|
| 735 |
# |
| 736 |
# Add the tail of the docs: |
| 737 |
# |
| 738 |
pp_addpm(<<'EOD'); |
| 739 |
|
| 740 |
=head1 CURRENT AUTHOR & MAINTAINER |
| 741 |
|
| 742 |
Judd Taylor, Orbital Systems, Ltd. |
| 743 |
judd dot t at orbitalsystems dot com |
| 744 |
|
| 745 |
=head1 PREVIOUS AUTHORS |
| 746 |
|
| 747 |
Olivier Archer [email protected] |
| 748 |
contribs of Patrick Leilde [email protected] |
| 749 |
|
| 750 |
=head1 SEE ALSO |
| 751 |
|
| 752 |
perl(1), L<PDL>, L<PDL::IO::HDF>. |
| 753 |
|
| 754 |
=cut |
| 755 |
|
| 756 |
EOD |
| 757 |
|
| 758 |
pp_done(); |