Hi, Sorry if this is the wrong place to ask this, however I’m stuck on this problem of not being able to write out a string to a compound datatype: Code is:
hid_t memtype;
const int LENGTH = 2;
const int RANK = 1;
int i;
hid_t file, dataset, space, strtype; // Handles
herr_t str;
hsize_t dim[] = { LENGTH }; // Dataspace dimensions
//Create the data space.
space = H5Screate_simple(RANK, dim, NULL);
//Create variable - length string datatype.
strtype = H5Tcopy(H5T_C_S1);
str = H5Tset_size(strtype, H5T_C_S1);
H5::StrType stype(H5::PredType::C_S1, H5T_VARIABLE);
//H5::StrType(H5::PredType::C_S1, H5T_VARIABLE)
memtype = H5Tcreate(H5T_COMPOUND, sizeof(entity_data));
H5Tinsert(memtype, "name", HOFFSET(Entity, name), strtype);
H5Tinsert(memtype, "entityID", HOFFSET(Entity, entity_id), H5T_NATIVE_INT);
H5Tinsert(memtype, "parentID", HOFFSET(Entity, parent_id), H5T_NATIVE_INT);
//Create the dataset.
dataset = H5Dcreate2(mEntGrpPtr->getLocId(), "EntityData", memtype, space, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
//Wtite data to the dataset;
H5Dwrite(dataset, memtype, H5S_ALL, H5S_ALL, H5P_DEFAULT, &entity_data);
The file output is:
GROUP “Entities” {
DATASET “EntityData” {
DATATYPE H5T_COMPOUND {
H5T_STD_I32LE “entityID”;
H5T_STD_I32LE “parentID”;
}
DATASPACE SIMPLE { ( 2 ) / ( 2 ) }
DATA {
(0): {
1,
0
},
(1): {
15,
0
}
}
}
What am I missing?
All the best,
Paul