octave: fix in h5readattr for ancient hdf5 shipped with Octave 3.6.x
Signed-off-by: Thorsten Liebig <Thorsten.Liebig@gmx.de>pull/12/head
parent
b12f1b4687
commit
e95efd8481
|
@ -2,6 +2,18 @@
|
||||||
#include <octave/ov-struct.h>
|
#include <octave/ov-struct.h>
|
||||||
#include "hdf5.h"
|
#include "hdf5.h"
|
||||||
|
|
||||||
|
// this special treatment is necessary because Win32-Octave ships with a very old hdf5 version (1.6.10)
|
||||||
|
void CloseH5Object(hid_t obj)
|
||||||
|
{
|
||||||
|
#if ((H5_VERS_MAJOR == 1) && (H5_VERS_MINOR == 6))
|
||||||
|
// try group close, than Dataset close
|
||||||
|
if (H5Gclose(obj)<0)
|
||||||
|
H5Dclose(obj);
|
||||||
|
#else
|
||||||
|
H5Oclose(obj);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
DEFUN_DLD (h5readatt_octave, args, nargout, "h5readatt_octave(<File_Name>,<DataSet_Name>,<Attribute_Name>)")
|
DEFUN_DLD (h5readatt_octave, args, nargout, "h5readatt_octave(<File_Name>,<DataSet_Name>,<Attribute_Name>)")
|
||||||
{
|
{
|
||||||
octave_value retval;
|
octave_value retval;
|
||||||
|
@ -27,7 +39,7 @@ DEFUN_DLD (h5readatt_octave, args, nargout, "h5readatt_octave(<File_Name>,<DataS
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef WIN32
|
#if ((H5_VERS_MAJOR == 1) && (H5_VERS_MINOR == 6))
|
||||||
// this special treatment is necessary because Win32-Octave ships with a very old hdf5 version (1.6.10)
|
// this special treatment is necessary because Win32-Octave ships with a very old hdf5 version (1.6.10)
|
||||||
hid_t obj = -1;
|
hid_t obj = -1;
|
||||||
//try opening the group
|
//try opening the group
|
||||||
|
@ -41,7 +53,7 @@ DEFUN_DLD (h5readatt_octave, args, nargout, "h5readatt_octave(<File_Name>,<DataS
|
||||||
|
|
||||||
if (obj==-1)
|
if (obj==-1)
|
||||||
{
|
{
|
||||||
H5Oclose(obj);
|
CloseH5Object(obj);
|
||||||
H5Fclose(file);
|
H5Fclose(file);
|
||||||
error("h5readatt_octave: opening the given Object failed");
|
error("h5readatt_octave: opening the given Object failed");
|
||||||
return retval;
|
return retval;
|
||||||
|
@ -50,7 +62,7 @@ DEFUN_DLD (h5readatt_octave, args, nargout, "h5readatt_octave(<File_Name>,<DataS
|
||||||
hid_t attr = H5Aopen_name(obj, args(2).string_value().c_str());
|
hid_t attr = H5Aopen_name(obj, args(2).string_value().c_str());
|
||||||
if (attr==-1)
|
if (attr==-1)
|
||||||
{
|
{
|
||||||
H5Oclose(obj);
|
CloseH5Object(obj);
|
||||||
H5Fclose(file);
|
H5Fclose(file);
|
||||||
error("h5readatt_octave: opening the given Attribute failed");
|
error("h5readatt_octave: opening the given Attribute failed");
|
||||||
return retval;
|
return retval;
|
||||||
|
@ -60,7 +72,7 @@ DEFUN_DLD (h5readatt_octave, args, nargout, "h5readatt_octave(<File_Name>,<DataS
|
||||||
if (type<0)
|
if (type<0)
|
||||||
{
|
{
|
||||||
H5Aclose(attr);
|
H5Aclose(attr);
|
||||||
H5Oclose(obj);
|
CloseH5Object(obj);
|
||||||
H5Fclose(file);
|
H5Fclose(file);
|
||||||
error("h5readatt_octave: dataset type error");
|
error("h5readatt_octave: dataset type error");
|
||||||
return retval;
|
return retval;
|
||||||
|
@ -69,7 +81,7 @@ DEFUN_DLD (h5readatt_octave, args, nargout, "h5readatt_octave(<File_Name>,<DataS
|
||||||
if (H5Tget_class(type)!=H5T_FLOAT)
|
if (H5Tget_class(type)!=H5T_FLOAT)
|
||||||
{
|
{
|
||||||
H5Aclose(attr);
|
H5Aclose(attr);
|
||||||
H5Oclose(obj);
|
CloseH5Object(obj);
|
||||||
H5Fclose(file);
|
H5Fclose(file);
|
||||||
error("h5readatt_octave: attribute type not supported");
|
error("h5readatt_octave: attribute type not supported");
|
||||||
return retval;
|
return retval;
|
||||||
|
@ -83,7 +95,7 @@ DEFUN_DLD (h5readatt_octave, args, nargout, "h5readatt_octave(<File_Name>,<DataS
|
||||||
if (H5Aread(attr, H5T_NATIVE_FLOAT, f_value)<0)
|
if (H5Aread(attr, H5T_NATIVE_FLOAT, f_value)<0)
|
||||||
{
|
{
|
||||||
H5Aclose(attr);
|
H5Aclose(attr);
|
||||||
H5Oclose(obj);
|
CloseH5Object(obj);
|
||||||
H5Fclose(file);
|
H5Fclose(file);
|
||||||
error("h5readatt_octave: reading the given Attribute failed");
|
error("h5readatt_octave: reading the given Attribute failed");
|
||||||
return retval;
|
return retval;
|
||||||
|
@ -96,7 +108,7 @@ DEFUN_DLD (h5readatt_octave, args, nargout, "h5readatt_octave(<File_Name>,<DataS
|
||||||
if (H5Aread(attr, H5T_NATIVE_DOUBLE, value)<0)
|
if (H5Aread(attr, H5T_NATIVE_DOUBLE, value)<0)
|
||||||
{
|
{
|
||||||
H5Aclose(attr);
|
H5Aclose(attr);
|
||||||
H5Oclose(obj);
|
CloseH5Object(obj);
|
||||||
H5Fclose(file);
|
H5Fclose(file);
|
||||||
error("h5readatt_octave: reading the given Attribute failed");
|
error("h5readatt_octave: reading the given Attribute failed");
|
||||||
return retval;
|
return retval;
|
||||||
|
@ -105,20 +117,14 @@ DEFUN_DLD (h5readatt_octave, args, nargout, "h5readatt_octave(<File_Name>,<DataS
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
H5Aclose(attr);
|
H5Aclose(attr);
|
||||||
H5Oclose(obj);
|
CloseH5Object(obj);
|
||||||
H5Fclose(file);
|
H5Fclose(file);
|
||||||
error("h5readatt_octave: reading the given Attribute failed: unknown type");
|
error("h5readatt_octave: reading the given Attribute failed: unknown type");
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
H5Aclose(attr);
|
H5Aclose(attr);
|
||||||
#ifdef WIN32
|
CloseH5Object(obj);
|
||||||
// try group close, than Dataset close
|
|
||||||
if (H5Gclose(obj)<0)
|
|
||||||
H5Dclose(obj);
|
|
||||||
#else
|
|
||||||
H5Oclose(obj);
|
|
||||||
#endif
|
|
||||||
H5Fclose(file);
|
H5Fclose(file);
|
||||||
Matrix mat(numVal,1);
|
Matrix mat(numVal,1);
|
||||||
for (size_t n=0;n<numVal;++n)
|
for (size_t n=0;n<numVal;++n)
|
||||||
|
|
Loading…
Reference in New Issue