fix in h5readatt_octave handling float or double attributes

pull/1/head
Thorsten Liebig 2012-09-21 14:12:16 +02:00
parent 52889f71cb
commit ccdb47a4cb
1 changed files with 24 additions and 5 deletions

View File

@ -65,12 +65,31 @@ DEFUN_DLD (h5readatt_octave, args, nargout, "h5readatt_octave(<File_Name>,<DataS
return retval; return retval;
} }
size_t numVal = H5Aget_storage_size(attr)/sizeof(float); size_t numVal = H5Aget_storage_size(attr)/H5Tget_size(type);
float value[numVal]; double value[numVal];
if (H5Aread(attr, H5T_NATIVE_FLOAT, value)<0) if (H5Tget_size(type)==sizeof(float))
{ {
error("h5readatt_octave: reading the given Attribute failed"); float f_value[numVal];
return retval; if (H5Aread(attr, H5T_NATIVE_FLOAT, f_value)<0)
{
error("h5readatt_octave: reading the given Attribute failed");
return retval;
}
for (size_t n=0;n<numVal;++n)
value[n] = f_value[n];
}
else if (H5Tget_size(type)==sizeof(double))
{
if (H5Aread(attr, H5T_NATIVE_DOUBLE, value)<0)
{
error("h5readatt_octave: reading the given Attribute failed");
return retval;
}
}
else
{
error("h5readatt_octave: reading the given Attribute failed: unknown type");
return retval;
} }
H5Aclose(attr); H5Aclose(attr);