Error accessing attributes (FORTRAN, H5Aopen_by_idx())


#1

Hi everyone,

I use a Fortran code written by someone else which is supposed to work. I don’t know which version of HDF5 library they were using but I installed the last one (1.12.1). At some point, the code needs to extract data from HDF5 files, array and attributes. It failed when trying to extract attributes. The involved part of the code is the following :


call h5aget_num_attrs_f(gr_id, attr_num, hdferr)

if(hdferr == -1)then
hdferr=UNABLE_TO_PROCESS
LogMessage=‘ERROR - Unable to Read Number of Attributes’
call reportLog(LogMessage,LogStatus_p)
return
end if
PRINT *, '(JASON) attr_num = ', attr_num

do idx=0, attr_num - 1

PRINT *, '(JASON) gr_id, idx = ', gr_id, idx
call h5aopen_idx_f(gr_id, idx, attr_id, hdferr)
!call h5aopen_name_f(gr_id, ‘ARCHIVE_FACILITY’, attr_id, hdferr)
PRINT *, '(JASON) gr_id, idx, attr_id, hdferr = ', gr_id, idx, attr_id, hdferr
if(hdferr == -1)then
hdferr=UNABLE_TO_PROCESS
LogMessage=‘ERROR - Unable to Open Attributes’
call reportLog(LogMessage,LogStatus_p)
return
end if

call h5aget_name_f(attr_id, 80_8, name_buffer, hdferr)
if(hdferr == -1)then
hdferr=UNABLE_TO_PROCESS
LogMessage=‘ERROR - Unable to Get Attribut Name’
call reportLog(LogMessage,LogStatus_p)
return
end if

end do


Here is the output (you can see that I have put some debugging print commands):


(JASON) Filename = ./input/static/HDF5_LSASAF_USGS-IGBP_LWMASK_MSG-Disk_201610171300
(JASON) file ID = 0
(JASON) group found with id 144115188075855872
(JASON) attr_num = 52
(JASON) gr_id, idx = 144115188075855872 0
HDF5-DIAG: Error detected in HDF5 (1.12.1) thread 0:
#000: /home/hdftest/snapshots-hdf5_1_12_1/current/src/H5A.c line 583 in H5Aopen_by_idx(): no object name
major: Invalid arguments to routine
minor: Bad value
(JASON) gr_id, idx, attr_id, hdferr = 144115188075855872 0 -1 -1
ERROR - Unable to Open Attributes
Error when reading ./input/static/HDF5_LSASAF_USGS-IGBP_LWMASK_MSG-Disk_201610171300

The function to get the number of attributes works perfectly returning indeed 52 for this file. However, when I want to access these attributes by their index, I get a strange error I don’t understand. With a previous version (1.10.7), I get an error at the same point but stating that the location ID is invalid.
Can soùeone help me please? Thank you very much!

Jason


#2

Can you try H5Aopen_by_idx_f instead? H5Aopen_idx_f is deprecated and it does not have any regression tests. Something like:

 CALL H5Aopen_by_idx_f(gr_id, ".", H5_INDEX_CRT_ORDER_F, H5_ITER_INC_F, INT(idx,HSIZE_T), &
      attr_id, hdferr)

#3

After looking into the code, H5Aopen_idx_f will definitely not work as currently implemented, best not to use it.


#4

Hello brtnfld, thank you very much for your help.

The use of the H5Aopen_by_idx_f as you stated it solved this problem! In the meantime, I got the information that the HDF5 ibrary version used along with the original code was 1.8.17 at that time. This was indeed because the function has been deprecated since then.

Jason