开发者

Setting Attributes on Datasets using HDF5 C++ api

I'm using HDF5 C++ API in HDF5 1.8.7 and would like to use an H5::Attribute instance to set a couple of scalar attributes in an H5::DataSet instance, but cannot find any examples. It's pretty cut and dry using the 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 a开发者_如何学Gottribute dataspace.
 */
ret = H5Sclose(aid2); 

/*
 * Close attribute.
 */
ret = H5Aclose(attr2); 

For some strange reason, the H5::Attribute and H5::DataSet classes in the C++ API seem to be missing the necessary methods. If anyone can come up with a concrete example using the C++ API, I'd be very appreciative.


if you have a Dataset object ds...

adding a string attribute...

StrType str_type(0, H5T_VARIABLE);
DataSpace att_space(H5S_SCALAR);
Attribute att = ds.createAttribute( "myAttribute", str_type, att_space );
att.write( str_type, "myString" );

adding an int attribute...

IntType int_type(PredType::STD_I32LE);
DataSpace att_space(H5S_SCALAR);
Attribute att = ds.createAttribute(" myAttribute", int_type, att_space );
int data = 77;
att.write( int_type, &data );
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜