Question

I am creating an h5 files with 5 datasets ['a160'],['a1214']

How can I make it so that the datasets will be sorted by the dataset name..

For example when I do h5dump on my file I get:

HDF5 "jjjj.h5" {
GROUP "/" {
   DATASET "a1214" {
      DATATYPE  H5T_IEEE_F32BE
      DATASPACE  SIMPLE { ( 1, 19 ) / ( H5S_UNLIMITED, 19 ) }
      DATA {
      (0,0): 160, 0, 165, 4, 2.29761, 264, 4, 1.74368, 1, 0, 17, 193, 0, 0,
      (0,14): 0, 0, 0, 0, 0
      }
   }
   DATASET "a160" {
      DATATYPE  H5T_IEEE_F32BE
      DATASPACE  SIMPLE { ( 3, 19 ) / ( H5S_UNLIMITED, 19 ) }
      DATA {
      (0,0): 263, 0, 262, 7, 4.90241, 201, 34, 0.348432, 1, 0, 29, 11, 0, 0,
      (0,14): 0, 0, 0, 0, 0,
      }
   }

But I want it to be ordered by the dataset name, I need h5dump to output

HDF5 "jjjj.h5" {
GROUP "/" {
   DATASET "a160" {
      DATATYPE  H5T_IEEE_F32BE
      DATASPACE  SIMPLE { ( 3, 19 ) / ( H5S_UNLIMITED, 19 ) }
      DATA {
      (0,0): 263, 0, 262, 7, 4.90241, 201, 34, 0.348432, 1, 0, 29, 11, 0, 0,
      (0,14): 0, 0, 0, 0, 0,
      }
   }

   DATASET "a1214" {
      DATATYPE  H5T_IEEE_F32BE
      DATASPACE  SIMPLE { ( 1, 19 ) / ( H5S_UNLIMITED, 19 ) }
      DATA {
      (0,0): 160, 0, 165, 4, 2.29761, 264, 4, 1.74368, 1, 0, 17, 193, 0, 0,
      (0,14): 0, 0, 0, 0, 0
      }
   }
}
Was it helpful?

Solution

By default h5dump sorts HDF5 files' groups and attributes by their names in ascending order:

-q Q, --sort_by=Q    Sort groups and attributes by index Q
-z Z, --sort_order=Z Sort groups and attributes by order Z

Q - is the sort index type. It can be "creation_order" or "name" (default)
Z - is the sort order type. It can be "descending" or "ascending" (default)

The problem in this case is that "a160" is considered greater than "a1214" because that's how dictionary sorting works ('a12' < 'a16').

There's no change you can make to the internal structure of the HDF5 file to force h5dump to sort these data structures in a different order. However, you could zero-pad your names like so:

a0040
a0160
a1214

and then the standard dictionary sort will output the file the way you want.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top