我創建了3個雙打和一個boolen使用numpy
數組和書面他們使用h5py
到文件:如何閱讀h5py用C
import numpy as np
import h5py
data = np.zeros(10, dtype=[("THETA",np.double),("PHI",np.double),("PSI",np. double),("FLAG",np.bool)])
with h5py.File("testout.h5") as f:
f.create_dataset("data", data=data)
h5py
爲創建一個枚舉類型布爾字段:
HDF5 "testout.h5" {
GROUP "/" {
DATASET "data" {
DATATYPE H5T_COMPOUND {
H5T_IEEE_F64LE "THETA";
H5T_IEEE_F64LE "PHI";
H5T_IEEE_F64LE "PSI";
H5T_ENUM {
H5T_STD_I8LE;
"FALSE" 0;
"TRUE" 1;
} "FLAG";
}
DATASPACE SIMPLE { (10)/(10) }
}
}
}
現在我需要閱讀用C這個文件,事情就變得複雜:
typedef enum {
false = 0;
true
} bool;
typedef struct {
double THETA, PHI, PSI;
bool FLAG;
} pointing_t;
我不知道如何定義一個擁有枚舉類型:
hid_t memtype = H5Tcreate (H5T_COMPOUND, sizeof(pointing_t));
H5Tinsert (memtype, "THETA", HOFFSET (pointing_t, THETA), H5T_NATIVE_DOUBLE);
H5Tinsert (memtype, "PHI", HOFFSET (pointing_t, PHI), H5T_NATIVE_DOUBLE);
H5Tinsert (memtype, "PSI", HOFFSET (pointing_t, PSI), H5T_NATIVE_DOUBLE);
# this should be an ENUM!!
H5Tinsert (memtype, "FLAG", HOFFSET (pointing_t, FLAG), H5T_NATIVE_DOUBLE);
我粘貼要點一個完整的「不工作」的例子,試圖讀取與以往的Python代碼片段創建HDF5文件:
http://gist.github.com/3168909
有人有建議嗎? 謝謝!