0

I have an hdf5 file containing a group with an attribute of the following format (h5dump):

ATTRIBUTE "PrioInfo" {
    DATATYPE  H5T_COMPOUND {
        H5T_STRING {
            STRSIZE 128;
            STRPAD H5T_STR_NULLTERM;
            CSET H5T_CSET_ASCII;
            CTYPE H5T_C_S1;
    } "FuncName";
        H5T_STD_I32LE "FuncPrio";
    }

Now i read this attribute, modify it and close the hdf5 file

>>> f =h5py.File("ooa_pop-Sapiens_ooa__500000.qdf", "r+")
>>> ooa = f['Populations']['Sapiens_ooa']
>>> ooa.attrs['PrioInfo']
array([('ConfinedMove', 8), ('Fertility', 2), ('GetOld', 8),
       ('MultiEvaluator', 5), ('NPPCapacity', 1), ('RandomPair', 3),
       ('Verhulst', 6), ('WeightedMove', 7)], 
      dtype=[('FuncName', 'S128'), ('FuncPrio', '<i4')])
>>> prios = ooa.attrs['PrioInfo']  
>>> prios[6] = ('Verhulst2', 8)
>>> del ooa.attrs['PrioInfo']  
>>> ooa.attrs['PrioInfo'] = prios
>>> f.flush()
>>> f.close()

In the h5dump of the modified hdf5 file the attibute's type has changed:

 ATTRIBUTE "PrioInfo" {
    DATATYPE  H5T_COMPOUND {
       H5T_STRING {
          STRSIZE 128;
          STRPAD H5T_STR_NULLPAD;
          CSET H5T_CSET_ASCII;
          CTYPE H5T_C_S1;
       } "FuncName";
       H5T_STD_I32LE "FuncPrio";
    }

And all the strings are displayed by h5dump with over a hundred zeros of padding:

"ConfinedMove\000\000\000\000\000\000\000\000...\000\000\000"

How can i force the type of the string to have "STRPAD H5T_STR_NULLTERM" instead of "STRPAD H5T_STR_NULLPAD"?

Moses Koledoye
  • 77,341
  • 8
  • 133
  • 139
user1479670
  • 1,145
  • 3
  • 10
  • 22
  • Strings in `numpy` arrays must be `nullpad`. So the round trip of `prios` through `numpy` must be changing it. I'd have to study `h5py` to see if there's a way of changing the array on the file without passing through `numpy`, or to force a conversion to `term` upon write. – hpaulj Jul 13 '16 at 16:11
  • Try this http://docs.h5py.org/en/latest/special.html#variable-length-strings section on variable length strings. `numpy` strings are fixed length. – hpaulj Jul 13 '16 at 16:13

0 Answers0