[Nexus] nullpad vs. nullterm strings
Paul Kienzle
paul.kienzle at nist.gov
Wed Mar 20 16:28:09 GMT 2013
Hi,
I'm trying to use h5py to create NeXus files at the NCNR, but I'm running into the problem that h5py creates strings using
H5T_STR_NULLPAD
but napi expects strings created using
H5T_STR_NULLTERM
The effect is that the strings I create in h5py have the final character chopped off when I view them using napi.
I spent some time trying to get h5py to produce NULLTERM strings from the high level interface, but no luck so far.
There are a couple of workarounds, like making string fields one character longer or making them variable width, but that's just wrong.
Easiest would be to fix napi5.c so that it respects the stored string format. Right now the code looks like:
else if (tclass==H5T_STRING)
{
len = H5Tget_size(pFile->iCurrentT);
memtype_id = H5Tcopy(H5T_C_S1);
H5Tset_size(memtype_id, len);
status = H5Dread (pFile->iCurrentD, memtype_id,
H5S_ALL, H5S_ALL,H5P_DEFAULT, data);
H5Tclose(memtype_id);
}
else
{
memtype_id = h5MemType(pFile->iCurrentT);
status = H5Dread (pFile->iCurrentD, memtype_id,
H5S_ALL, H5S_ALL,H5P_DEFAULT, data);
}
NX5getattr doesn't have this problem because it uses H5Aget_type. Since pFile->iCurrentT already contains H5Dget_type, we can just use it directly. This simplifies the code to:
…
else if (tclass==H5T_STRING)
{
status = H5Dread (pFile->iCurrentD, pFile->iCurrentT,
H5S_ALL, H5S_ALL,H5P_DEFAULT, data);
}
…
A similar change is needed for getslab, though it's looks like napi doesn't support getslab on n-d string arrays, so it doesn't matter.
Any objections to pushing this change?
- Paul
More information about the NeXus
mailing list