Ticket #24 (closed defect: fixed)

Opened 12 years ago

Last modified 12 years ago

readAttribute cannot cope with MATLAB C-strings any more

Reported by: tschmidt Owned by: tschmidt
Priority: major Milestone:
Component: libBlitzHDF5 Version:
Keywords: Cc:

Description (last modified by tschmidt) (diff)

Since this silly change from the good old C-strings to those ugly char-Arrays, normal string data cannot be read any more, as for example MATLAB writes them to the file. At least reading support must be guaranteed, and I'd like to select the way of writing a string out if possible, maybe with some global switch.

For now only reading is necessary, because the code promises it, but doesn't keep the promise.

Change History

Changed 12 years ago by emmenlau

The subject says "readAttribute", but Attributes are AFAIK not stored as char-Arrays. The char-Array is only for writeDataSetSimple(std::string) (which is probably not used anywhere by LMB code?). Writing string attributes has changed a long time ago, due to Imaris compatibility. Imaris writes attributes as a vector (dim 1) of chars, not as a string datatype. This is consistent with some HowTos? for good HDF5 style from around the web, but I dont recall details.

However, AFAIK the readAttribute should still support old attributes (full backward compatibility). If it does not, checking the debug output should help. I.e., check for "reading old string data" vs "reading new string data".

Changed 12 years ago by tschmidt

  • owner changed from somebody to tschmidt

Changed 12 years ago by tschmidt

  • status changed from new to closed
  • resolution set to fixed
  • description modified (diff)

OK, my post was not clear enough. with char array I meant a vector of char's, sorry for the misunderstanding. The old style saving I would name string.

I know the style guide, and I can cope with the new style especially with respect to Imaris compatibility, although the h5dump output is almost not readable with the vectorial character data. The code nevertheless looks as if it should still support the old style strings for reading.

I changed the _readAttribute-Method drastically to enable reading of both types of strings. The checks run fine, although there is still no check for exactly that problem, because I cannot write a hdf5-File with the old style string format. Nevertheless the format is important to support, because MATLAB writes out string attributes as one single string not as vector of characters.

Probably the changes are bigger than they need to be, but it was easier for me to rewrite the string reader from scratch than finding the problem in the old routine. The new function now first checks whether it finds a string dataset. If so it reads it and returns. If not the usual readAttribute code is executed (at the moment the old code for string attributes is only commented out, but if everything works out well it can be removed after some testing phase).

I'm not 100% sure about the size of the string, I set it to vectorlength + 1 to assure a 0-value at the end, maybe that should be rechecked if there are any problems, but it is essentially the same behaviour as before.

I hope MATLAB can read char-Vectors and interpret them as strings, otherwise the writeAttribute-Method must sooner or later support old style strings for writing either.

I don't know why, but this fix also seems to resolve the make check problem, at least make check runs error free now.

Note: See TracTickets for help on using tickets.