diff --git a/Changes b/Changes index b5badc952..a29906cb4 100644 --- a/Changes +++ b/Changes @@ -9,6 +9,7 @@ - t_linear stores iunit ounit itype otype - IO::FITS no longer writes COMMENT header with "HASH(0x...)" - add IO::GD::write_gif_anim for better GIF animation in Demos/harness +- IO::HDF remove VNAMELENMAX and Vinquire as obsoleted by recent HDF4 (#500) - thanks @a-shahba for report 2.093 2024-09-29 - PDL.set_datatype now doesn't physicalise input, PDL.convert_type does diff --git a/IO/HDF/HDF.pm b/IO/HDF/HDF.pm index 8f70f95d2..e235fc783 100644 --- a/IO/HDF/HDF.pm +++ b/IO/HDF/HDF.pm @@ -186,10 +186,6 @@ This is the max name length for SDS variables, attribtues, and just about anythi This is the max number of dims a HDF variable can have. -=item VNAMELENMAX - -Max length of V interface names. - =back =cut @@ -203,9 +199,6 @@ use constant MAX_NC_NAME => 256; # Maximum variable dims (use for alloc'ing mem for the low level calls that return dims: use constant MAX_VAR_DIMS => 32; -# Max name len for VS interface: -use constant VNAMELENMAX => 64; - use constant FAIL => -1; # Declaration of the different 'typemap' globals diff --git a/IO/HDF/VS/VS.pd b/IO/HDF/VS/VS.pd index 0cc4f8b8c..733a5021a 100644 --- a/IO/HDF/VS/VS.pd +++ b/IO/HDF/VS/VS.pd @@ -5,7 +5,7 @@ pp_addpm({At => 'Top'}, <<'EOD'); use strict; use warnings; -=head1 NAME +=head1 NAME PDL::IO::HDF::VS - An interface library for HDF4 files. @@ -13,7 +13,7 @@ PDL::IO::HDF::VS - An interface library for HDF4 files. use PDL; use PDL::IO::HDF::VS; - + #### no doc for now #### =head1 DESCRIPTION @@ -83,7 +83,6 @@ int Vdetach(int vgroup_id); int Vntagrefs(int vgroup_id); int Vgettagref(int vgroup_id, int index, int *tag, int *ref); -int Vinquire(int vgroup_id, int *n_entries, char *vgroup_name); int Vsetname(int vgroup_id, const char *vgroup_name); int Vsetclass(int vgroup_id, const char *vgroup_class); @@ -142,19 +141,15 @@ _WriteMultPDL(VID, nb_records, nb_fields, interlace_mode, sizeofPDL, sdimofPDL, { SV **SvTmp1 = av_fetch(sizeofPDL, i, 0); int curvalue = SvIV( *SvTmp1 ); - SV **SvTmp3 = av_fetch(sdimofPDL, i, 0); int cursdim = SvIV( *SvTmp3 ); - total_size += curvalue * cursdim; } - total_size *= nb_records; unsigned char *databuff = (unsigned char *)malloc( total_size ); if(databuff==NULL) croak("memory allocation error"); unsigned char *ptrbuff = databuff; - if(interlace_mode == 0) { for(i=0; iSvPDLV( *SvTmp2 ); - SV **SvTmp3 = av_fetch(sdimofPDL, j, 0); int cursdim = SvIV( *SvTmp3 ); - SV **SvTmp1 = av_fetch(sizeofPDL, j, 0); int curvalue = SvIV( *SvTmp1 ); - for(k=0; kdata + curvalue*i + curvalue*k*nb_records)); memcpy( ptrbuff, (unsigned char *)(curPDL->data + curvalue*i + curvalue*k*nb_records), curvalue ); - - #printf("Value %d=%d\n", k, *(int *)(curPDL->data + curvalue*i*cursdim + curvalue*k)); - #memcpy( ptrbuff, (unsigned char *)(curPDL->data + curvalue*i*cursdim + curvalue*k), curvalue ); - - #printf("buffer %d= %d\n", k, *(int *)ptrbuff); ptrbuff += curvalue; } } } } else - { + { for(j=0; jSvPDLV( *SvTmp2 ); - SV **SvTmp3 = av_fetch(sdimofPDL, j, 0); int cursdim = SvIV( *SvTmp3 ); - SV **SvTmp1 = av_fetch(sizeofPDL, j, 0); int curvalue = SvIV( *SvTmp1 ); - memcpy( ptrbuff, (unsigned char *)(curPDL->data), curvalue*nb_records*cursdim ); ptrbuff += curvalue*nb_records*cursdim; #printf("buffer %d= %d\n", k, curvalue*nb_records*cursdim); } interlace_mode = 1; } - fprintf(stderr, "Calling VSwrite(VID=%d, databuff=%p, nb_records=%d, interlace_mode=%d)...\n", + fprintf(stderr, "Calling VSwrite(VID=%d, databuff=%p, nb_records=%d, interlace_mode=%d)...\n", VID, databuff, nb_records, interlace_mode); RETVAL = VSwrite(VID, databuff, nb_records, interlace_mode); free(databuff); @@ -300,7 +283,7 @@ OUTPUT: n_records interlace fields - vdata_size + vdata_size vdata_name ENDOFXS @@ -313,15 +296,15 @@ use PDL::Basic; use PDL::IO::HDF; my $TMAP = { - PDL::byte->[0] => 1, + PDL::byte->[0] => 1, PDL::short->[0] => 2, PDL::ushort->[0] => 2, PDL::long->[0] => 4, - PDL::float->[0] => 4, - PDL::double->[0] => 8 + PDL::float->[0] => 4, + PDL::double->[0] => 8 }; -sub _pkg_name +sub _pkg_name { return "PDL::IO::HDF::VS::" . shift() . "()"; } =head2 new @@ -337,7 +320,7 @@ sub _pkg_name If you want to write to it, prepend the name with the '+' character : "+name.hdf" If you want to create it, prepend the name with the '-' character : "-name.hdf" Otherwise the file will be opened in read only mode. - + Returns the hdf object (die on error) =for example @@ -353,27 +336,27 @@ sub new my $filename = shift; my $self = {}; - - if (substr($filename, 0, 1) eq '+') + + if (substr($filename, 0, 1) eq '+') { # open for writing $filename = substr ($filename, 1); # chop off + $self->{ACCESS_MODE} = PDL::IO::HDF->DFACC_WRITE + PDL::IO::HDF->DFACC_READ; } - if (substr($filename, 0, 1) eq '-') + if (substr($filename, 0, 1) eq '-') { # Creating $filename = substr ($filename, 1); # chop off - $self->{ACCESS_MODE} = PDL::IO::HDF->DFACC_CREATE; } - - unless( defined($self->{ACCESS_MODE}) ) - { - $self->{ACCESS_MODE} = PDL::IO::HDF->DFACC_READ; - } + + unless( defined($self->{ACCESS_MODE}) ) + { + $self->{ACCESS_MODE} = PDL::IO::HDF->DFACC_READ; + } $self->{FILE_NAME} = $filename; $self->{HID} = PDL::IO::HDF::VS::_Hopen( $self->{FILE_NAME}, $self->{ACCESS_MODE}, 20 ); - if ($self->{HID}) + if ($self->{HID}) { PDL::IO::HDF::VS::_Vstart( $self->{HID} ); @@ -386,26 +369,18 @@ sub new while( ($vg_ref = PDL::IO::HDF::VS::_Vgetid( $self->{HID}, $vg_ref )) != PDL::IO::HDF->FAIL) { my $vg_id = PDL::IO::HDF::VS::_Vattach( $self->{HID}, $vg_ref, 'r' ); - - my $n_entries = 0; - - my $vg_name = " "x(PDL::IO::HDF->VNAMELENMAX+1); - my $res = PDL::IO::HDF::VS::_Vinquire( $vg_id, $n_entries, $vg_name ); - - $vgroup->{$vg_name}->{ref} = $vg_ref; - $vgroup->{$vg_name}->{class} = PDL::IO::HDF::VS::_Vgetclass( $vg_id ); - + my $vg_name = PDL::IO::HDF::VS::_Vgetname($vg_id); + $vgroup->{$vg_name}{ref} = $vg_ref; + $vgroup->{$vg_name}{class} = PDL::IO::HDF::VS::_Vgetclass($vg_id); my $n_pairs = PDL::IO::HDF::VS::_Vntagrefs( $vg_id ); - for ( 0 .. $n_pairs-1 ) { my ($tag, $ref); - $res = PDL::IO::HDF::VS::_Vgettagref( $vg_id, $_, $tag = 0, $ref = 0 ); + my $res = PDL::IO::HDF::VS::_Vgettagref( $vg_id, $_, $tag = 0, $ref = 0 ); if($tag == 1965) { # Vgroup my $id = PDL::IO::HDF::VS::_Vattach( $self->{HID}, $ref, 'r' ); - my $name = " "x(PDL::IO::HDF->VNAMELENMAX+1); - my $res = PDL::IO::HDF::VS::_Vgetname( $id, $name ); + my $name = PDL::IO::HDF::VS::_Vgetname($id); PDL::IO::HDF::VS::_Vdetach( $id ); $vgroup->{$vg_name}->{children}->{$name} = $ref; $vgroup->{$name}->{parents}->{$vg_name} = $vg_ref; @@ -418,30 +393,27 @@ sub new PDL::IO::HDF::VS::_VSdetach( $id ); $vgroup->{$vg_name}->{attach}->{$name}->{type} = 'VData'; $vgroup->{$vg_name}->{attach}->{$name}->{ref} = $ref; - $vgroup->{$vg_name}->{attach}->{$name}->{class} = $class + $vgroup->{$vg_name}->{attach}->{$name}->{class} = $class if( $class ne '' ); } if( ($SDID != PDL::IO::HDF->FAIL) && ($tag == 720)) #tag for SDS tag/ref (see 702) { my $i = _SDreftoindex( $SDID, $ref ); my $sds_ID = _SDselect( $SDID, $i ); - my $name = " "x(PDL::IO::HDF->MAX_NC_NAME+1); my $rank = 0; my $dimsize = " "x( (4 * PDL::IO::HDF->MAX_VAR_DIMS) + 1 ); my $numtype = 0; my $nattrs = 0; - - $res = _SDgetinfo( $sds_ID, $name, $rank, $dimsize , $numtype, $nattrs ); + $res = _SDgetinfo( $sds_ID, $name, $rank, $dimsize , $numtype, $nattrs ); $vgroup->{$vg_name}->{attach}->{$name}->{type} = 'SDS_Data'; $vgroup->{$vg_name}->{attach}->{$name}->{ref} = $ref; } } # for each pair... - PDL::IO::HDF::VS::_Vdetach( $vg_id ); } # while vg_ref... - + PDL::IO::HDF::VS::_SDend( $SDID ); $self->{VGROUP} = $vgroup; @@ -457,8 +429,8 @@ sub new while ( $vdata_ref = shift @$lone ) { my $mode="r"; - if ( $self->{ACCESS_MODE} != PDL::IO::HDF->DFACC_READ ) - { + if ( $self->{ACCESS_MODE} != PDL::IO::HDF->DFACC_READ ) + { $mode="w"; } $vdata_id = PDL::IO::HDF::VS::_VSattach( $self->{HID}, $vdata_ref, $mode ); @@ -467,7 +439,7 @@ sub new my $fields = ""; my $vdata_size = 0; my $vdata_name = ""; - + PDL::IO::HDF::VS::_VSinquire( $vdata_id, $n_records, $interlace, $fields, $vdata_size, $vdata_name ); $vdata->{$vdata_name}->{REF} = $vdata_ref; @@ -475,13 +447,13 @@ sub new $vdata->{$vdata_name}->{INTERLACE} = $interlace; $vdata->{$vdata_name}->{ISATTR} = PDL::IO::HDF::VS::_VSisattr( $vdata_id ); - + my $field_index = 0; - foreach my $onefield ( split( ",", $fields ) ) + foreach my $onefield ( split( ",", $fields ) ) { - $vdata->{$vdata_name}->{FIELDS}->{$onefield}->{TYPE} = + $vdata->{$vdata_name}->{FIELDS}->{$onefield}->{TYPE} = PDL::IO::HDF::VS::_VFfieldtype( $vdata_id, $field_index ); - $vdata->{$vdata_name}->{FIELDS}->{$onefield}->{INDEX} = $field_index; + $vdata->{$vdata_name}->{FIELDS}->{$onefield}->{INDEX} = $field_index; $field_index++; } @@ -499,7 +471,7 @@ sub Vgetchildren my ($self, $name) = @_; return( undef ) unless defined( $self->{VGROUP}->{$name}->{children} ); - + return sort keys %{$self->{VGROUP}->{$name}->{children}}; } # End of Vgetchildren()... # Now defunct: @@ -523,9 +495,9 @@ sub Vgetparents my ($self, $name) = @_; return( undef ) unless defined( $self->{VGROUP}->{$name}->{parents} ); - + return sort keys %{$self->{VGROUP}->{$name}->{parents}}; -} # End of Vgetparents()... +} # End of Vgetparents()... sub Vgetmains { @@ -533,26 +505,26 @@ sub Vgetmains my @rlist; foreach( sort keys %{$self->{VGROUP}} ) { - push(@rlist, $_) + push(@rlist, $_) unless defined( $self->{VGROUP}->{$_}->{parents} ); } return @rlist; -} # End of Vgetmains()... +} # End of Vgetmains()... sub Vcreate { my($self, $name, $class, $where) = @_; - + my $id = PDL::IO::HDF::VS::_Vattach( $self->{HID}, -1, 'w' ); return( undef ) if( $id == PDL::IO::HDF->FAIL ); my $res = _Vsetname($id, $name); - $res = _Vsetclass($id, $class) + $res = _Vsetclass($id, $class) if defined( $class ); $self->{VGROUP}->{$name}->{ref} = '???'; - $self->{VGROUP}->{$name}->{class} = $class + $self->{VGROUP}->{$name}->{class} = $class if defined( $class ); if( defined( $where ) ) @@ -561,7 +533,7 @@ sub Vcreate unless defined( $self->{VGROUP}->{$where} ); my $ref = $self->{VGROUP}->{$where}->{ref}; - + my $Pid = PDL::IO::HDF::VS::_Vattach( $self->{HID}, $ref, 'w' ); my $index = PDL::IO::HDF::VS::_Vinsert( $Pid, $id ); my ($t, $r) = (0, 0); @@ -591,7 +563,7 @@ sub Vcreate =cut -sub close +sub close { my $self = shift; _Vend( $self->{HID} ); @@ -603,14 +575,14 @@ sub close sub VSisattr { my($self, $name) = @_; - + return undef unless defined( $self->{VDATA}->{$name} ); - + return $self->{VDATA}->{$name}->{ISATTR}; -} # End of VSisattr()... +} # End of VSisattr()... -sub VSgetnames +sub VSgetnames { my $self = shift; return sort keys %{$self->{VDATA}}; @@ -619,10 +591,10 @@ sub VSgetnames sub VSgetfieldnames { my ( $self, $name ) = @_; - + my $sub = _pkg_name( 'VSgetfieldnames' ); - - die "$sub: vdata name $name doesn't exist!\n" + + die "$sub: vdata name $name doesn't exist!\n" unless defined( $self->{VDATA}->{$name} ); return sort keys %{$self->{VDATA}->{$name}->{FIELDS}}; @@ -635,17 +607,17 @@ sub VSgetfieldsnames } # End of VSgetfieldsnames()... -sub VSread +sub VSread { my ( $self, $name, $field ) = @_; my $sub = _pkg_name( 'VSread' ); my $data = null; my $vdata_ref = PDL::IO::HDF::VS::_VSfind( $self->{HID}, $name ); - - die "$sub: vdata name $name doesn't exist!\n" + + die "$sub: vdata name $name doesn't exist!\n" unless $vdata_ref; - + my $vdata_id = PDL::IO::HDF::VS::_VSattach( $self->{HID}, $vdata_ref, 'r' ); my $vdata_size = 0; my $n_records = 0; @@ -659,20 +631,20 @@ sub VSread die "$sub: data_type $data_type not implemented!\n" unless defined( $PDL::IO::HDF::SDinvtypeTMAP->{$data_type} ); - + my $order = PDL::IO::HDF::VS::_VFfieldorder( $vdata_id, $self->{VDATA}->{$name}->{FIELDS}->{$field}->{INDEX} ); - - if($order == 1) + + if($order == 1) { $data = ones( $PDL::IO::HDF::SDinvtypeTMAP2->{$data_type}, $n_records ); - } - else + } + else { $data = ones( $PDL::IO::HDF::SDinvtypeTMAP2->{$data_type}, $n_records, $order ); } my $status = PDL::IO::HDF::VS::_VSsetfields( $vdata_id, $field ); - + die "$sub: _VSsetfields\n" unless $status; @@ -697,15 +669,15 @@ sub VSwrite if defined( $self->{VDATA}->{$foo[0]} ); $VD_id = _VSattach( $self->{HID}, -1, 'w' ); - + return( undef ) if( $VD_id == PDL::IO::HDF->FAIL ); $res = _VSsetname( $VD_id, $foo[0] ); return( undef ) if( $res == PDL::IO::HDF->FAIL ); - - $res = _VSsetclass( $VD_id, $foo[1] ) + + $res = _VSsetclass( $VD_id, $foo[1] ) if defined( $foo[1] ); return( undef ) if( $res == PDL::IO::HDF->FAIL ); @@ -720,9 +692,9 @@ sub VSwrite } $res = _VSsetfields( $VD_id, $field ); - return( undef ) + return( undef ) unless $res; - + my @sizeofPDL; my @sdimofPDL; foreach ( @$value ) @@ -731,14 +703,14 @@ sub VSwrite push(@sizeofPDL, $TMAP->{$_->get_datatype()}); } $res = _WriteMultPDL( $VD_id, $$value[0]->getdim(0), $#$value+1, $mode, \@sizeofPDL, \@sdimofPDL, $value); - + return( undef ) if( _VSdetach($VD_id) == PDL::IO::HDF->FAIL ); return $res; } # End of VSwrite()... -sub DESTROY +sub DESTROY { my $self = shift; $self->close; @@ -760,14 +732,13 @@ judd dot t at orbitalsystems dot com Olivier Archer olivier.archer@ifremer.fr contribs of Patrick Leilde patrick.leilde@ifremer.fr - + =head1 SEE ALSO -perl(1), PDL(1), PDL::IO::HDF(1). +perl(1), L, L. =cut - EOD pp_done();