Dear all,

I am trying to write a compound data type in hdf5 format into a file. However, when it is time to insert the data to the data space, gfortran gives the error during the compilation:

gfortran -c -I/usr/local/hdf5-1.8.7/include -L/usr/local/hdf5-1.8.7/lib -lhdf5_fortran h5write.f95
h5write.f95:159.51:

    call h5dwrite_f(dset_id, memtype, f_ptr, hdferr)
                                                    1
Error: There is no specific subroutine for the generic 'h5dwrite_f' at (1)

When I comment out the last hd5write_f, the code correctly compiles and when run, it creates the data in the file and populate it with zeros. But when writing actual data, it fails at h5write_f step during compilation. My code is attached. I would be glad if you could help me on the matter.

Regards,

Ekin Akoglu

subroutine h5write(nvars, nstanzas, drows, dcols, ep_data, ms_data, ep_diet)

use statevartypesEcopath_mod
use iso_c_binding
use hdf5

implicit none

! This is the name of the data file we will read. 
character (len = 9), parameter :: filename  = "ep_res.h5"
character (len = 7), parameter :: dsetname0 = "es_data"     ! name of the Ecopath base dataset
character (len = 7), parameter :: dsetname1 = "ms_data"     ! name of the Ecopath multistanza dataset

type dummy
real(4) :: biomass = 3
real(4) :: pob = 5
real(4) :: qob = 4
real(4) :: ee = 8
real(4) :: poq = 2
real(4) :: unass_q = 1
real(4) :: detritus_import = 3
real(4) :: immig  = 8
real(4) :: emig = 3
real(4) :: emig_rate = 2
real(4) :: ba = 1
real(4) :: ba_rate  = 0
real(4) :: landings = 0
integer(4) :: org_type = 1
integer(4) :: stanza = 1
integer(4) :: stanza_no = 2
integer(4) :: age_start = 2
integer(4) :: leading = 1
real(4) :: production = 3
real(4) :: consumption = 3
real(4) :: respiration = 3
real(4) :: assimilation = 3
real(4) :: eatenof = 3
real(4) :: eatenby = 3  
end type dummy



! variables inherited from Ecopath model
integer(HSIZE_T), intent(in)           :: nvars, nstanzas, drows, dcols
type(dummy), target                    :: es_data
type(ecopath_data), intent(in), target :: ep_data
type(multi_stanza), intent(in), target :: ms_data(nstanzas)
real(4), intent(in), target            :: ep_diet(drows,dcols)

! in-subroutine variable declarations
integer(8), parameter             :: dim0   = 1            ! dimension of ep_data(0)%
integer         :: hdferr                                   ! variable to handle errors
integer(hid_t)  :: file_id,plist_id                                  ! file identifier of the output file
integer(hid_t)  :: dset_id                                  ! dataset identifier
integer(hid_t)  :: dtype_id, dt1_id                                 ! dataset type identifier
integer(4)      :: dspace_id                                ! dataspace identifier
integer(hid_t)  :: memtype
integer(8)      :: type_size, offset
integer(8)      :: type_sizei, type_sizer
INTEGER(HSIZE_T), DIMENSION(1)   :: dims = (/dim0/)
 TYPE(C_PTR) :: f_ptr


   ! initialize FORTRAN interface
   call h5open_f(hdferr)

     CALL h5pcreate_f(H5P_DATASET_XFER_F, plist_id, hdferr)
     CALL h5pset_preserve_f(plist_id, .TRUE., hdferr)

   ! create file, if it already exists overwrite (H%F_ACC_TRUNC_F)
   call h5fcreate_f(filename, H5F_ACC_TRUNC_F, file_id, hdferr)
  
   ! get size of each member in the compound datatype
   call h5tget_size_f(H5T_NATIVE_INTEGER, type_sizei, hdferr)
   call h5tget_size_f(H5T_NATIVE_REAL, type_sizer, hdferr)
   type_size = (20 * type_sizer) + (5 *  type_sizei)

   ! create the compound datatype for memory
   call h5tcreate_f(H5T_COMPOUND_F, type_size, memtype, hdferr)

   ! insert members
   offset = 0
   call h5tinsert_f(memtype, "biomass", offset, H5T_NATIVE_REAL, hdferr)
   
   offset = offset + type_sizer
   call h5tinsert_f(memtype, "pob", offset, H5T_NATIVE_REAL, hdferr)

   offset = offset + type_sizer
   call h5tinsert_f(memtype, "qob", offset, H5T_NATIVE_REAL, hdferr)

   offset = offset + type_sizer
   call h5tinsert_f(memtype, "ee", offset, H5T_NATIVE_REAL, hdferr)

   offset = offset + type_sizer
   call h5tinsert_f(memtype, "poq", offset, H5T_NATIVE_REAL, hdferr)

   offset = offset + type_sizer
   call h5tinsert_f(memtype, "unass_q", offset, H5T_NATIVE_REAL, hdferr)

   offset = offset + type_sizer
   call h5tinsert_f(memtype, "detritus_import", offset, H5T_NATIVE_REAL, hdferr)

   offset = offset + type_sizer
   call h5tinsert_f(memtype, "immig", offset, H5T_NATIVE_REAL, hdferr)

   offset = offset + type_sizer
   call h5tinsert_f(memtype, "emig", offset, H5T_NATIVE_REAL, hdferr)

   offset = offset + type_sizer
   call h5tinsert_f(memtype, "emig_rate", offset, H5T_NATIVE_REAL, hdferr)

   offset = offset + type_sizer
   call h5tinsert_f(memtype, "ba", offset, H5T_NATIVE_REAL, hdferr)

   offset = offset + type_sizer
   call h5tinsert_f(memtype, "ba_rate", offset, H5T_NATIVE_REAL, hdferr) 

   offset = offset + type_sizer
   call h5tinsert_f(memtype, "landings", offset, H5T_NATIVE_REAL, hdferr)

   offset = offset + type_sizei
   call h5tinsert_f(memtype, "org_type", offset, H5T_NATIVE_INTEGER, hdferr)

   offset = offset + type_sizei
   call h5tinsert_f(memtype, "stanza", offset, H5T_NATIVE_INTEGER, hdferr)

   offset = offset + type_sizei
   call h5tinsert_f(memtype, "stanza_no", offset, H5T_NATIVE_INTEGER, hdferr)

   offset = offset + type_sizei
   call h5tinsert_f(memtype, "age_start", offset, H5T_NATIVE_INTEGER, hdferr)

   offset = offset + type_sizei
   call h5tinsert_f(memtype, "leading", offset, H5T_NATIVE_INTEGER, hdferr)

   offset = offset + type_sizer
   call h5tinsert_f(memtype, "production", offset, H5T_NATIVE_REAL, hdferr)

   offset = offset + type_sizer
   call h5tinsert_f(memtype, "consumption", offset, H5T_NATIVE_REAL, hdferr)

   offset = offset + type_sizer
   call h5tinsert_f(memtype, "respiration", offset, H5T_NATIVE_REAL, hdferr)

   offset = offset + type_sizer
   call h5tinsert_f(memtype, "assimilation", offset, H5T_NATIVE_REAL, hdferr)

   offset = offset + type_sizer
   call h5tinsert_f(memtype, "eatenof", offset, H5T_NATIVE_REAL, hdferr)

   offset = offset + type_sizer
   call h5tinsert_f(memtype, "eatenby", offset, H5T_NATIVE_REAL, hdferr)


   call h5screate_simple_f(1, dims, dspace_id, hdferr)
   call h5dcreate_f(file_id, dsetname0, memtype, dspace_id, dset_id, hdferr)
   
   f_ptr = C_LOC(es_data)
   call h5dwrite_f(dset_id, memtype, f_ptr, hdferr)


   

end subroutine h5write

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

Reply via email to