For me it is enough to be able to traverse the datasets in a group (and possibly its subgroups) in the same order they were created. To achieve this, (like embert said above) the groups within the file must be created using the H5P_CRT_ORDER_TRACKED | H5P_CRT_ORDER_INDEXED flags set. That is, call:
hid_t group_creation_plist;
group_creation_plist = H5Pcreate(H5P_GROUP_CREATE);
status = H5Pset_link_creation_order(group_creation_plist,
H5P_CRT_ORDER_TRACKED | H5P_CRT_ORDER_INDEXED);
And then create groups using:
hid_t group_id;
group_id = H5Gcreate(id_file,
"/mydata",
H5P_DEFAULT,
group_creation_plist,
H5P_DEFAULT);
Add all your data to your new group. To traverse the group in sorted creation order you must use the H5Literate
function, making sure to set the index_type
argument to H5_INDEX_CRT_ORDER
.
status = H5Literate (group_id,
H5_INDEX_CRT_ORDER, // Note this argument
H5_ITER_INC,
NULL,
op_func,
(void *) &od);
It is important to start the iteration from the group, and not from root. I have not been able to make the root group maintain the order of creation of links. The solution to this is just to make a group at the root with the appropriate flags.
Using H5Literate
is a bit tricky, specially if one wants to do recursive traversal of subgroups. A good example is found here and in the documentation.