14
我在HDF5 1.8.7中使用HDF5 C++ API,並且希望使用H5 :: Attribute實例在H5 :: DataSet實例中設置幾個標量屬性,但找不到任何例子。這是很添油加醋使用C API:使用HDF5設置數據集上的屬性C++ api
/* Value of the scalar attribute */
int point = 1;
/*
* Create scalar attribute for the dataset, my_dataset.
*/
aid2 = H5Screate(H5S_SCALAR);
attr2 = H5Acreate(my_dataset, "Integer attribute", H5T_NATIVE_INT, aid2,H5P_DEFAULT);
/*
* Write scalar attribute to my_dataset.
*/
ret = H5Awrite(attr2, H5T_NATIVE_INT, &point);
/*
* Close attribute dataspace.
*/
ret = H5Sclose(aid2);
/*
* Close attribute.
*/
ret = H5Aclose(attr2);
一些奇怪的原因,H5 ::屬性和C++ API中的H5 :: DataSet中的類似乎缺少必要的方法。如果任何人都能用C++ API想出一個具體的例子,我會非常感激。
字符串類型應該真的是'StrType strtype(PredType :: C_S1,H5T_VARIABLE);' – Simon 2011-07-15 02:13:54
createAttribute方法是爲H5 :: Object-s定義的,因此您可以使用相同的習慣用法將屬性附加到H5 :: Group -s,例如。 – 2013-10-26 09:11:18
@Simon:[無論哪種方式工作得很好](http://www.hdfgroup.org/HDF5/doc/cpplus_RM/classH5_1_1StrType.html#a502e6a4895bf51314204179e3f093a7f) – 2013-12-10 06:12:58