[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: problem loading hdf5 file
From: |
Paul Kienzle |
Subject: |
Re: problem loading hdf5 file |
Date: |
Thu, 6 May 2004 00:18:50 -0400 |
On May 5, 2004, at 4:30 AM, David Bateman wrote:
According to W.J. Atsma <address@hidden> (on 05/04/04):
Why not export all the data in a single struct if the file is not an
octave-created one, replacing the file-like structure "/" with ".".
Then you
can look at the complete structure in octave and reinterpret them as
you
like.
HDF5 doesn't have the concept of a structure. The implementation of a
structure that octave expects in files to import is as an HDF5 GROUP.
The problem is the example given uses an HDF5 DATASET with a compound
datatype used to contain the structure. This is much harder to
interpret
if you don't know the form of the structure a-priori as you have to
construct an HDF5 compound type internally to hold the structure
before
you can import the values. It is also more limiting as all members of
the structure must have the same size.
The matlab function hdfinfo seems to load in a complete
description of the dataset using a tree of structures, with
structure arrays for the repeating parts. It doesn't read
in the actual data which is good because the datasets can
be very large and the user may only want to read in a part
of one. The function hdfread takes one of the nodes of
the structure tree and reads it in. With the appropriate
options, it can read only part of the dataset. A similar
interface could be set up for writing to an HDF file.
Matlab also provides a direct mapping of the hdf C APIs.
It's my belief that higher level languages should hide
the details whenever they can, so I wouldn't bother with
this except if I needed it for compatibility.
Paul Kienzle
address@hidden
PS, I didn't see a simple way to examine the tree
structure returned by hdfinfo from the matlab
command line, so I wrote my own. Something similar
should work for octave, but with deblank(argn(1,:))
instead of inputname(1).
%SHOWSTRUCT display structure tree
% showstruct(S[,n]) displays the contents of structure S as
% well as any substructures. The first bit of the data is displayed
% for each field. If n is supplied, only print the first n levels.
function showstruct(s,maxlevel,indent,name)
if nargin<2, maxlevel=inf; end
if nargin<3, indent=0; end
if nargin<4, name=inputname(1); end
fields=fieldnames(s);
n = prod(size(s));
if n==1
fprintf(1,'%s--- %s ---\n',blanks(indent),name);
for i=1:length(fields)
fprintf(1,'%s%s: \t', blanks(indent), fields{i});
showfield(s.(fields{i}),maxlevel-1,indent+2,[name,'.',fields{i}]);
end
else
for j=1:n
fprintf(1,'%s--- %s(%d) ---\n',blanks(indent),name,j);
for i=1:length(fields)
fprintf(1,'%s%s: \t', blanks(indent), fields{i});
showfield(s(j).(fields{i}),maxlevel-1,indent+2,[name,'.',fields{i}]);
end
end
end
function showfield(f,maxlevel,indent,name)
fprintf(1,'%s ',class(f));
showdims(size(f));
if isstruct(f)
fprintf(1,'\n');
if maxlevel>0, showstruct(f,maxlevel,indent,name); end
elseif isstr(f)
fprintf(' ''%.30s''\n',f(1,:));
elseif isreal(f)
if isempty(f)
t='';
elseif prod(size(f))<8
t=sprintf('%g, ',double(f(1:end-1)));
t=[t,sprintf('%g',double(f(end)))];
else
t=sprintf('%g, ',double(f(1:4)));
t=[t,'...'];
end
fprintf(1,' [%s]\n',t);
else
fprintf(1,'\n');
end
function showdims(d)
fprintf(1,'%d',d(1));
fprintf(1,'x%d',d(2:end));
-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.
Octave's home on the web: http://www.octave.org
How to fund new projects: http://www.octave.org/funding.html
Subscription information: http://www.octave.org/archive.html
-------------------------------------------------------------