Closed jhaiduce closed 5 months ago
Currently, you need to pass a valid character string for "buf", but it can be a length of 1 if you like. The "size" returned will be the needed length.
Just tried that. I get the correct length with a zero-length string as well.
So it seems that the implementation is working, the problem is just an omission in the documentation.
I submitted a pull request that adds a sentence to H5Fget_name.htm in the documentation to explain this.
I found a bug with H5Fget_name_f when looking into using an allocatable character string. If the buffer is the exact size needed, then the filename returned will be truncated by one character. See PR #1345 for the fix.
Everything related to this issue has been resolved, so I will close it. Thanks for your help!
The documentation of h5fget_name says: "If the length of the name, which determines the required value of size, is unknown, a preliminary H5Fget_name call can be made by setting name to NULL. The return value of this call will be the size of the filename; that value plus one (1) can then be assigned to size for a second H5Fget_name call, which will retrieve the actual name. "
However, this does not work from Fortran. Passing a null (unassociated in Fortran parlance) pointer to an ordinary (non-pointer, non allocatable) dummy argument is not allowed in the Fortran standard. If one tries to do so anyway, the current implementation does not obtain the size as expected, because h5fget_name_c allocates a new buffer for the filename anyway. As a result, there is no way to obtain the length of the filename using the Fortran API.