我正在寻找一种在hdf5中从相同类型(整数)和长度的多个std向量中构建复合数据类型的方法,而无需形成所有已记录示例中讨论的结构。
例如 https://support.hdfgroup.org/HDF5/doc/cpplus_RM/compound_8cpp-example.html
s1_t s1[LENGTH];
for (i = 0; i< LENGTH; i++)
{
s1[i].a = i;
s1[i].b = i*i;
s1[i].c = 1./(i+1);
}
/*
* Create the data space.
*/
hsize_t dim[] = {LENGTH}; /* Dataspace dimensions */
DataSpace space( RANK, dim );
/*
* Create the file.
*/
H5File* file = new H5File( FILE_NAME, H5F_ACC_TRUNC );
/*
* Create the memory datatype.
*/
CompType mtype1( sizeof(s1_t) );
mtype1.insertMember( MEMBER1, HOFFSET(s1_t, a), PredType::NATIVE_INT);
mtype1.insertMember( MEMBER3, HOFFSET(s1_t, c), PredType::NATIVE_DOUBLE);
mtype1.insertMember( MEMBER2, HOFFSET(s1_t, b), PredType::NATIVE_FLOAT);
/*
* Create the dataset.
*/
DataSet* dataset;
dataset = new DataSet(file->createDataSet(DATASET_NAME, mtype1, space));
/*
* Write data to the dataset;
*/
dataset->write( s1, mtype1 );
非常感谢您的提前提示!