Dear all,

I cannot read compound data from HDF file. I created the data and wrote it to a HDF file with a FORTRAN subroutine and now trying to read it within another FORTRAN program. Attached are my script, HDF file and its h5dump output. My script halts with an error like:

HDF5-DIAG: Error detected in HDF5 (1.8.8) thread 0:
#000: H5Tarray.c line 142 in H5Tarray_create2(): not an valid base datatype
    major: Invalid arguments to routine
    minor: Inappropriate type
....
....
HDF5-DIAG: Error detected in HDF5 (1.8.8) thread 0:
  #000: H5S.c line 365 in H5Sclose(): not a dataspace
    major: Invalid arguments to routine
    minor: Inappropriate type

I would be glad if you can help me on the issue. Thank you all for your concerns.

Best regards,

--
*Ekin Akoglu*

Research Assistant

Institute of Marine Sciences
Middle East Technical University
P.O. Box 28, 33731
Erdemli, Mersin
Turkey

Web: www.ims.metu.edu.tr
Email: [email protected] <mailto:[email protected]>
Phone: +90 324 521 34 34
GSM: +90 506 554 03 90
Fax: +90 324 521 23 27

Attachment: cc_res.h5
Description: Binary data

HDF5 "cc_res.h5" {
GROUP "/" {
   DATASET "ms_data" {
      DATATYPE  H5T_COMPOUND {
         H5T_ARRAY { [2] H5T_IEEE_F32LE } "a";
         H5T_ARRAY { [3] H5T_IEEE_F64LE } "b";
         H5T_STD_I32LE "c";
      }
      DATASPACE  SIMPLE { ( 4 ) / ( 4 ) }
      DATA {
      (0): {
            [ 1.2, 2.2 ],
            [ 3.2, 4.2, 5.2 ],
            6
         },
      (1): {
            [ 7.2, 8.2 ],
            [ 9.2, 10.2, 11.2 ],
            12
         },
      (2): {
            [ 13.2, 14.2 ],
            [ 15.2, 16.2, 17.2 ],
            18
         },
      (3): {
            [ 19.2, 20.2 ],
            [ 21.2, 22.2, 23.2 ],
            24
         }
      }
   }
}
}
program read_complexcompound

use hdf5

implicit none

type data
 real(4) :: a(2)
 real(8) :: b(3)
 integer :: c
end type data

type(data), dimension(4), target :: wdata

! This is the name of the data file we will read. 
character (len = 9), parameter :: filename  = "cc_res.h5"
character (len = 7), parameter :: dsetname1 = "ms_data"

integer, parameter                :: arraydim0   = 2
integer(hsize_t), DIMENSION(1)    :: arraydims   = (/arraydim0/)
integer, parameter                :: arraydim1   = 3
integer(hsize_t), DIMENSION(1)    :: arraydims1  = (/arraydim1/)

integer(hid_t)  :: file_id, dspace_id, dset_id, memtype ! Handles
integer         :: hdferr
integer(hid_t)  :: s1_tid, s2_tid, s3_tid
type(c_ptr)     :: f_ptr_ms

 ! open file
 call h5fopen_f(filename, H5F_ACC_RDONLY_F, file_id, hdferr)

 ! open dataset
 call h5dopen_f(file_id, dsetname1, dset_id, hdferr)

 call h5tcreate_f(H5T_COMPOUND_F, H5OFFSETOF(C_LOC(wdata(1)), C_LOC(wdata(2))), memtype, hdferr)
 
 call H5Tarray_create_f(H5T_NATIVE_REAL, 1, arraydims, s1_tid, hdferr)
 call H5Tarray_create_f(H5T_NATIVE_DOUBLE, 1, arraydims1, s2_tid, hdferr)
 call H5Tcopy_f(H5T_NATIVE_INTEGER, s3_tid, hdferr)

 call H5Tinsert_f(memtype, "a", H5OFFSETOF(C_LOC(wdata(1)), C_LOC(wdata(1)%a)), s1_tid, hdferr)
 call H5Tinsert_f(memtype, "b", H5OFFSETOF(C_LOC(wdata(1)), C_LOC(wdata(1)%b)), s2_tid, hdferr)
 call H5Tinsert_f(memtype, "c", H5OFFSETOF(C_LOC(wdata(1)), C_LOC(wdata(1)%c)), s3_tid, hdferr)

 ! read the data
 f_ptr_ms = c_loc(wdata(1))
 call h5dread_f(dset_id, memtype, f_ptr_ms, hdferr)

 ! ! close and release resources
 call h5dclose_f(dset_id, hdferr)
 call h5sclose_f(dspace_id, hdferr)
 call h5tclose_f(memtype, hdferr)
 call h5fclose_f(file_id, hdferr)

end program read_complexcompound
_______________________________________________
Hdf-forum is for HDF software users discussion.
[email protected]
http://mail.hdfgroup.org/mailman/listinfo/hdf-forum_hdfgroup.org

Reply via email to