HighFive icon indicating copy to clipboard operation
HighFive copied to clipboard

Reading a string attribute fails

Open cbehren opened this issue 7 years ago • 2 comments

Hi, I have the following code:

HighFive::File f("test.hdf5");
HighFive::DataSet ds = f.getDataSet("mass");
HighFive::Attribute att = ds.getAttribute("unit");
std::string unit;
att.read(unit);

which fails with

HDF5-DIAG: Error detected in HDF5 (1.10.1) thread 4634400192:
  #000: H5A.c line 693 in H5Aread(): unable to read attribute
    major: Attribute
    minor: Read failed
  #001: H5Aint.c line 527 in H5A__read(): unable to convert between src and dst datatypes
    major: Attribute
    minor: Feature is unsupported
  #002: H5T.c line 4560 in H5T_path_find(): no appropriate function for conversion path
    major: Datatype
    minor: Unable to initialize object

Here is what h5dump says:

GROUP "/" {
   DATASET "mass" {
      DATATYPE  H5T_IEEE_F64LE
      DATASPACE  SIMPLE { ( 10 ) / ( 10 ) }
      DATA {
      (0): 0, 111.111, 222.222, 333.333, 444.444, 555.556, 666.667, 777.778,
      (8): 888.889, 1000
      }
      ATTRIBUTE "description" {
         DATATYPE  H5T_STRING {
            STRSIZE 16;
            STRPAD H5T_STR_NULLPAD;
            CSET H5T_CSET_ASCII;
            CTYPE H5T_C_S1;
         }
         DATASPACE  SCALAR
         DATA {
         (0): "some description"
         }
      }
      ATTRIBUTE "unit" {
         DATATYPE  H5T_STRING {
            STRSIZE 4;
            STRPAD H5T_STR_NULLPAD;
            CSET H5T_CSET_ASCII;
            CTYPE H5T_C_S1;
         }
         DATASPACE  SCALAR
         DATA {
         (0): "Msol"
         }
      }[...]

Am I doing something wrong there? I guess it has to do with the conversion from the internal hdf5 string format to the STL string. I have created the hdf5 file using h5py.

cbehren avatar Nov 09 '19 06:11 cbehren

Upon further investigation, I could figure out that if I write a string attribute with HighFive, it is stored as

STRSIZE H5T_VARIABLE;
            STRPAD H5T_STR_NULLTERM;
            CSET H5T_CSET_UTF8;
            CTYPE H5T_C_S1;

compared to what h5py generated, namely

STRSIZE 4;
            STRPAD H5T_STR_NULLPAD;
            CSET H5T_CSET_ASCII;
            CTYPE H5T_C_S1;

I figured out I can also generate NULLTERM/UTF8 strings of variables size with h5py, and I can read those with HighFive. However, this is a rather surprising behavior. Are fixed-length strings not supported in HighFive? The problem is that in my use case, people will provide their own HDF5 files, and they will run into this problem.

cbehren avatar Nov 09 '19 14:11 cbehren

The problem is well known, see #94 If you can get time to make a proposition, it would be greatly appreciated.

alkino avatar Nov 09 '19 17:11 alkino