HDF5: a composite data type for writing a structure containing a pointer to another structure

I am trying to write in HDF5 a structure containing a pointer to another. Something like that:

typedef struct{
    int32_t  method;
    void*    methodParams;
    float    result;
}Measure;

typedef struct{
    int32_t    param1;
    int32_t    param2;
}OneMethod;

The following code to describe a composite data type does not work:

Measure value;
hid_t method_tid;
hid_t measure_tid;

method_tid = H5Tcreate(H5T_COMPOUND, sizeof(OneMethod));
H5Tinsert(method_tid, "P1", HOFFSET(OneMethod, param1), H5T_NATIVE_INT32);
H5Tinsert(method_tid, "P2", HOFFSET(OneMethod, param2), H5T_NATIVE_INT32);

measure_tid = H5Tcreate(H5T_COMPOUND, sizeof(Measure));
H5Tinsert(measure_tid, "Method", HOFFSET(Measure, method), H5T_NATIVE_INT32);
H5Tinsert(measure_tid, "Params", HOFFSET(Measure, methodParams), method_tid);
H5Tinsert(measure_tid, "Result", HOFFSET(Measure, result), H5T_NATIVE_FLOAT);

hsize_t dim[] = { 1 };
hid_t space = H5Screate_simple(1, dim, NULL);

hid_t dataset = H5Dcreate(objid, name, measure_tid, space, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
herr_t ret = H5Dwrite(dataset, measure_tid, H5S_ALL, H5S_ALL, H5P_DEFAULT, &value);

H5Tclose(method_tid);
H5Tclose(measure_tid);
H5Sclose(space);
H5Dclose(dataset);

the composite data type is written, but the field is methodParamsmissing. I think because I do not instruct the library to expect a pointer to its position. How should I do it?

EDIT

Please note that the structure is indicated with a pointer, because each method (specified by the first field of the structure) has different quantities and types of parameters. Of course, the way would be to combine all the parameters from all the methods on the first level of the structure, which I would like to avoid.

+4
source share
1 answer

H5Tinsert() , , , , , . , , int, float. , H5Tinsert(). ( , , HDF5).

, :

typedef struct{
    int32_t  method;
    int32_t  param1;
    int32_t  param2;
    float    result;
}hdf5_Measure;

, , / HDF5.

+2

Source: https://habr.com/ru/post/1686240/


All Articles