fixed octave hdf5 attribute reading: read float array from Dataset OR group

This commit is contained in:
Thorsten Liebig 2012-02-02 11:39:35 +01:00
parent 807786b2d2
commit fe35f550af

View File

@ -27,10 +27,10 @@ DEFUN_DLD (h5readatt_octave, args, nargout, "h5readatt_octave(<File_Name>,<DataS
return retval; return retval;
} }
hid_t ds = H5Dopen(file, args(1).string_value().c_str()); hid_t ds = H5Oopen(file, args(1).string_value().c_str(), H5P_DEFAULT);
if (ds==-1) if (ds==-1)
{ {
error("h5readatt_octave: opening the given DataSet failed"); error("h5readatt_octave: opening the given Object failed");
return retval; return retval;
} }
@ -41,8 +41,22 @@ DEFUN_DLD (h5readatt_octave, args, nargout, "h5readatt_octave(<File_Name>,<DataS
return retval; return retval;
} }
float value; hid_t type = H5Aget_type(attr);
if (H5Aread(attr, H5T_NATIVE_FLOAT, &value)<0) if (type<0)
{
error("h5readatt_octave: dataset type error");
return retval;
}
if (H5Tget_class(type)!=H5T_FLOAT)
{
error("h5readatt_octave: attribute type not supported");
return retval;
}
size_t numVal = H5Aget_storage_size(attr)/sizeof(float);
float value[numVal];
if (H5Aread(attr, H5T_NATIVE_FLOAT, value)<0)
{ {
error("h5readatt_octave: reading the given Attribute failed"); error("h5readatt_octave: reading the given Attribute failed");
return retval; return retval;
@ -51,7 +65,10 @@ DEFUN_DLD (h5readatt_octave, args, nargout, "h5readatt_octave(<File_Name>,<DataS
H5Aclose(attr); H5Aclose(attr);
H5Dclose(ds); H5Dclose(ds);
H5Fclose(file); H5Fclose(file);
retval = octave_value(value); Matrix mat(numVal,1);
for (size_t n=0;n<numVal;++n)
mat(n)=value[n];
retval = octave_value(mat);
return retval; return retval;
} }