Reading integer attribute

Dear Forum members,

I am trying to read an integer attribute in an hdf5 file. H5aread_f shows following error:

HDF5-DIAG: Error detected in HDF5 (1.8.8) thread 0:
   #000: ../../hdf5-1.8.8/src/H5A.c line 1079 in H5Aread(): not a datatype
     major: Invalid arguments to routine
     minor: Inappropriate type

Source code is:

c#######################################################################
       subroutine read_hdf5(h5filename)
c#######################################################################

       use hdf5
       implicit none

       integer :: hdferror
       integer(hid_t) :: file_id,attr_id,grp_id,atype_id
       integer(hsize_t), dimension(1) :: adims
       integer, dimension(1):: attr_data
       character(len=*) :: h5filename

c--- open hdf5 - file
       call h5fopen_f(h5filename,H5F_ACC_RDWR_F,file_id,
& hdferror)

       call h5gopen_f(file_id,'/Mesh/Elements',grp_id,hdferror)

       call h5aopen_f(grp_id,'Num2DElems',attr_id,hdferror)

       adims(1) = 1
       call h5aread_f(attr_id,H5T_NATIVE_INTEGER,attr_data,
& adims,hdferror)

       write(*,*) 'Num2DElems: ', attr_data(1)

       call h5aclose_f(attr_id,hdferror)

       call h5gclose_f(grp_id,hdferror)

       call h5fclose_f(file_id,hdferror)

       end subroutine read_hdf5

It seems to be an easy error, sorry. I hope anyone can help. I am stuck with this problem ...

Best regards,
Matthias

···

--
Dipl.-Ing. Matthias Springer
Fluid System Dynamics and Aeroacoustics
Institute of Process Machinery and Systems Engineering
University of Erlangen-Nuremberg
Cauerstrasse 4
91058 Erlangen, Germany
Tel.: +49 9131 85-29596
Fax.: +49 9131 85-29449
E-Mail: sp@ipat.uni-erlangen.de

Matthias,

All HDF5 fortran programs require h5open_f call to initialize the Fortran interface before calling any HDF5 Fortran subroutines:

CALL h5open_f(error)

Please see Fortran examples we provide at http://www.hdfgroup.org/HDF5/examples

Elena

···

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Elena Pourmal The HDF Group http://hdfgroup.org
1800 So. Oak St., Suite 203, Champaign IL 61820
217.531.6112
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

On Oct 1, 2013, at 5:36 AM, Matthias Springer <sp@ipat.uni-erlangen.de> wrote:

Dear Forum members,

I am trying to read an integer attribute in an hdf5 file. H5aread_f shows following error:

HDF5-DIAG: Error detected in HDF5 (1.8.8) thread 0:
#000: ../../hdf5-1.8.8/src/H5A.c line 1079 in H5Aread(): not a datatype
   major: Invalid arguments to routine
   minor: Inappropriate type

Source code is:

c#######################################################################
     subroutine read_hdf5(h5filename)
c#######################################################################

     use hdf5
     implicit none

     integer :: hdferror
     integer(hid_t) :: file_id,attr_id,grp_id,atype_id
     integer(hsize_t), dimension(1) :: adims
     integer, dimension(1):: attr_data
     character(len=*) :: h5filename

c--- open hdf5 - file
     call h5fopen_f(h5filename,H5F_ACC_RDWR_F,file_id,
& hdferror)

     call h5gopen_f(file_id,'/Mesh/Elements',grp_id,hdferror)

     call h5aopen_f(grp_id,'Num2DElems',attr_id,hdferror)

     adims(1) = 1
     call h5aread_f(attr_id,H5T_NATIVE_INTEGER,attr_data,
& adims,hdferror)

     write(*,*) 'Num2DElems: ', attr_data(1)

     call h5aclose_f(attr_id,hdferror)

     call h5gclose_f(grp_id,hdferror)

     call h5fclose_f(file_id,hdferror)

     end subroutine read_hdf5

It seems to be an easy error, sorry. I hope anyone can help. I am stuck with this problem ...

Best regards,
Matthias

--
Dipl.-Ing. Matthias Springer
Fluid System Dynamics and Aeroacoustics
Institute of Process Machinery and Systems Engineering
University of Erlangen-Nuremberg
Cauerstrasse 4
91058 Erlangen, Germany
Tel.: +49 9131 85-29596
Fax.: +49 9131 85-29449
E-Mail: sp@ipat.uni-erlangen.de

_______________________________________________
Hdf-forum is for HDF software users discussion.
Hdf-forum@lists.hdfgroup.org
http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org