I’ve created an array with 3 doubles and one boolen using numpy and written them to file using h5py:
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 creates an enum type for the boolean field:
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 ) }
}
}
}
now I need to read this file using C, and things get complicated:
typedef enum {
false = 0;
true
} bool;
typedef struct {
double THETA, PHI, PSI;
bool FLAG;
} pointing_t;
I do not understand how to define a type that has an enum:
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);
I pasted a complete “not working” example on gist that tries to read the hdf5 files created with the previous python snippet:
http://gist.github.com/3168909
anybody has suggestions?
thanks!
Found the solution, you need to create an enum type in hdf5:
and then add it to the memtype:
the example on github is now working.