(Low level) write hdf5 file in Matlab for use in Octave

Hi,

[update]
Nevermind, I found the error: Writing the ‘matrix’ data type entry string, because it is null-terminated, this null char needs to be explicitly created in the Matlab string using sprintf.
Giving a shorter string will result in an error in the Matlab hdf5 low-level function because of the length mismatch.
Error using hdf5lib2 The number of elements expected by the memory space identifier (7) was not equal to the number of elements provided in the MATLAB array (6).

Giving a string that has a padding character at the end, the matlab hdf5 low-level functions will not null-terminate the string and write the padding character (a space in my case) instead, which causes octave to fail to recognize the type.
The key in understanding this was using
.\h5dump.exe -n -x.\test_matlab_h5write.hdf5 > .\test_matlab_h5write.hdf5.txt
and comparing the output to
.\h5dump.exe -n -x.\test_octave_h5write.hdf5 > .\test_octave_h5write.hdf5.txt
I’m leaving this post here as reference for anyone trying to accomplish the same thing.
[/update]

I’m trying to write a hdf5 file in Matlab (R2020a, Win 10 x64) that replicates Octave’s native hdf5 format (Octave 6.1.0, Win 10, ‘x86_64-w64-mingw32’ ), so that I can open it in Octave with e.g. load(filename, “-hdf5”, “data”);

To this end I’ve exported an example matrix in octave, analyzed it in Matlab with h5info, and used Matlabs low-level hdf5 functions to export the same data from Matlab into Octave’s hdf5 format structure.
h5info shows that I have exactly replicated the format, and HDFView (3.1.2 with HDF5 1.10.7) confirms this (only the refs are different, all groups, data, types and attributes are the same).

However, Octave gives me an "error: octave_base_value::load_binary(): wrong type argument '<unknown type>' " when I try to load my hdf5 file exported from Matlab , while the original test file from Octave loads just fine.

I have no idea what to look for, so I hope someone who knows Octave’s inner workings can give me a hint where the issue is and how I might be able to resolve it.

I know I could use .mat files in the old <v7.3 format, but I’m trying to establish a more open data format, so I would prefer hdf5.

I have attached a script that creates the datafile, as well as the hdf5 data file exported by Matlab, in case Matlab is not available for testing.

Any help and suggestions are very much appreciated.

Kind regards,
Chris

update, corrected:
test_hdf5_standalone.m (4.8 KB)
test_matlab_h5write.hdf5 (4.7 KB)

original, erroneous:
test_hdf5_standalone.m (4.8 KB)
test_matlab_h5write.hdf5 (4.7 KB)

I tried to load “bad” hdf file on octave 6.1.1 and it failed and then octave segfault at exit. That should not happen. I will fill a bug report.

Dmitri.