我需要使用 C# 将一些数据写入 HDF5 文件。我没有绑定到任何特定的库,但我能找到的唯一可访问的库是 HDF5DotNet ( http://hdf5.net/ )。我有一个包含一些数据的简单类(只需使用默认值初始化即可轻松测试它,通常从传感器读取数据):
public class mData
{
public double temp = 123.456789;
public double humid = 223.456789;
public int chamberId = 5;
}
如何将数组或列表写入 HDF5 文件?HDF5 似乎太棒了,不能成为特例,但我找不到任何合适的文档。这是我尝试过的,下面的例子:
List<mData> mdl = new List<mData>();
mdl.Add(new mData()); // create some dummy data
mdl.Add(new mData());
mdl.Add(new mData());
string filename = "test.h5";
const int DATA_ARRAY_LENGTH = 3;
const int RANK = 1; // <- unsure about this one
H5FileId fileId = H5F.create(filename, H5F.CreateMode.ACC_TRUNC);
H5GroupId groupId = H5G.create(fileId, "/myGroup");
long[] dims = new long[RANK]; // <- unsure, extrapolated from example
dims[0] = DATA_ARRAY_LENGTH;
H5DataSpaceId spaceId = H5S.create_simple(RANK, dims);
H5DataTypeId typeId = H5T.copy(H5T.H5Type.NATIVE_DOUBLE); // <- NATIVE_DOUBLE is definitely wrong but I dont know which type to use in this case
int typeSize = H5T.getSize(typeId);
H5DataSetId dataSetId = H5D.create(fileId, "/myDataset", typeId, spaceId);
H5D.write(dataSetId, new H5DataTypeId(H5T.H5Type.NATIVE_DOUBLE),
new H5Array<double>(mdl)); // <- NATIVE_DOUBLE and H5Array<double> are definitely wrong but again unsure which type to use in both cases
H5G.close(groupId);
H5F.close(fileId);
非常感谢对其他图书馆的任何帮助或指导!