我需要使用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);
非常感谢任何其他图书馆的帮助或指示!
答案 0 :(得分:2)
使用foo = 1
-> {
bar = 2
foo + bar
}.()
# => 3
bar
# NameError
代替H5T.H5Type.STD_REF_OBJ
。
此测试代码,
H5T.H5Type.NATIVE_DOUBLE
将生成此输出:
static void Main(string[] args) { SampleH5Modified sh5 = new SampleH5Modified("TestFile01.h5", 5); sh5.Run(); }
Creating H5 file TestFile01.h5...
H5 file TestFile01.h5 created successfully!
Reading H5 file TestFile01.h5...
chamberId=1 humid=100 temp=80
chamberId=2 humid=101 temp=81
chamberId=3 humid=102 temp=82
chamberId=4 humid=103 temp=83
chamberId=5 humid=104 temp=84
Processing complete!