Dear all,

I found out to use a complex compound type circumvent my problem. However, I could not figure it out what is wrong with my implementation attached to this mail. It creates the complex compound structure but does not write the data into it. The h5dump is:

HDF5 "ep_res.h5" {
GROUP "/" {
   DATASET "ms_data" {
      DATATYPE  H5T_COMPOUND {
         H5T_ARRAY { [2] H5T_IEEE_F32LE } "denarray";
         H5T_ARRAY { [3] H5T_IEEE_F32LE } "denarray0";
      }
      DATASPACE  SIMPLE { ( 1 ) / ( 1 ) }
      DATA {
      (0): {
            [ 0, 0 ],
            [ 0, 0, 0 ]
         }
      }
   }
}
}

There are zeros where should be data instead. I would be happy if you spare some time to help me on this. Thank you in advance for your time and patience.

Regards,

Ekin



On 03/14/2012 02:18 PM, Ekin Akoglu wrote:
Hi,

I missed to add a very important detail to my previous e-mail. As the sizes of ms_data(1)%biomass(:) and ms_data(1)%mortality(:) are not equal; also the sizes of ms_data(1)%biomass(:) and ms_data(2)%biomass(:) are not equal.

Regards,

Ekin


On 03/14/2012 01:49 PM, Ekin Akoglu wrote:
Hi,

Please let me put it this way. I have a user-defined type in FORTRAN called "ep_data" of dimension 4, i.e. ep_data(4). It has fields named biomass, pob, qob, ... etc. and so on. Each field holds a scalar value. For instance, if you print "ep_data(1)%biomass", it will give you, let's say, "4". In other words, fields of "ep_data" are not arrays. I succeeded to write this "ep_data" to HDF5 by using compound datatype. So no problem up till here. However, I have another user-defined type called "ms_data" in FORTRAN of size 7, i.e. , "ms_data(7)" and just like "ep_data", it also has fields named biomass, mortality, qob, ... etc. and so on. Differently from "ep_data" type, "ms_data" fields are arrays of different size. For instance, if you print "ms_data(1)%biomass(:)"|, you will get an array of real numbers. And if you print "ms_data(1)%mortality(:)", you also get an array of real numbers of different length that of "biomass" field. So, how can I store "ms_data" in HDF5 format?

For your reference, my FORTRAN implementation of storing "ep_data" is attached.

Regards,

Ekin





On 03/14/2012 10:00 AM, Ekin Akoglu wrote:
Hello,

I am sorry that I could not make myself clear. What I meant to say is that I aim to form a compound datatype which comprises VL (variable length) and fixed-length array fields/datatypes. In the example for creating VL datatype, using a user-defined datatype which includes a pointer is suggested (Example 27 on page 227 in the HDF user manual). That is what I want to avoid but it seems it is the only way. What I want to achieve is summarized in Figure 18 on page 238 in the HDF user manual; a compound datatype built up of numerous VL and atomic datatypes.

Ekin



On 03/14/2012 07:16 AM, [email protected] wrote:
Hi,

suggestions about storing this data as a compound type with variable
length fields without using pointers as explained in
h5ex_t_vlen_F03.f90 [1] example script on HDF GROUP web site. Thank
you in advance for your concerns.

I don't understand what you mean by "not using pointers", do you mean you don't want to use C_LOC and/or F2003 and still do the same thing as h5ex_t_vlen_F03.f90? Can you explain further what in h5ex_t_vlen_F03.f90 you want to avoid doing?

Scot



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



--
*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


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


--
*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


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


--
*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


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


--
*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
program complexcompound

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 = "ep_data"     ! name of the Ecopath base dataset
character (len = 7), parameter :: dsetname1 = "ms_data"     ! name of the Ecopath multistanza dataset

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

! in-subroutine variable declarations for ms_data
integer          , parameter       :: ms_dim0      = 1               ! number of stanzas
integer(hid_t)                     :: file_id, plist_id, space, dset ! Handles
integer                            :: hdferr
integer(hsize_t), dimension(1:1)   :: ms_dims = (/ms_dim0/)
integer(hsize_t), dimension(1:2)   :: maxdims

integer(hid_t)  :: s1_tid, s2_tid, s3_tid, dt1_id, dt2_id
integer(8)      :: sz1, sz2, sz, offset

real(4), target :: denarray(2), denarray0(3)

  
 denarray = (/3.2, 4.1/)
 denarray0 = (/9.8, 7.6, 5.1/)

 ! 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)

 call h5screate_simple_f(1, ms_dims, space, hdferr)

 ! create 2 arrays "s1_tid" and "s2_tid"
 call H5Tarray_create_f(H5T_NATIVE_REAL, 1, arraydims, s1_tid, hdferr);
 call H5Tarray_create_f(H5T_NATIVE_REAL, 1, arraydims1, s2_tid, hdferr);

 ! get size of each array
 call H5Tget_size_f(s1_tid, sz1, hdferr)
 call H5Tget_size_f(s2_tid, sz2, hdferr)
 sz = sz1 + sz2

 ! create the compound datatype "s3_tid"  which will embrace the "s1_tid" and "s2_tid" arrays
 call H5Tcreate_f(H5T_COMPOUND_F, sz, s3_tid, hdferr);

 ! insert arrays into the compound datatype
 offset = 0
 call H5Tinsert_f(s3_tid, "denarray", offset, s1_tid, hdferr)
 offset = offset + sizeof(denarray)
 call H5Tinsert_f(s3_tid, "denarray0", offset, s2_tid, hdferr)

 ! Create the dataset and write the array data to it.

 call h5dcreate_f(file_id, dsetname1, s3_tid, space, dset, hdferr)

 call h5tcreate_f(H5T_COMPOUND_F, sz1, dt1_id, hdferr)
 offset = 0
 call h5tinsert_f(dt1_id, "denarray", offset, H5T_NATIVE_REAL, hdferr)
     
 call h5tcreate_f(H5T_COMPOUND_F, sz2, dt2_id, hdferr)
 offset = offset + sz1
 call h5tinsert_f(dt2_id, "denarray0", offset, H5T_NATIVE_REAL, hdferr)

 call h5dwrite_f(dset, dt1_id, "denarray", ms_dims, hdferr, xfer_prp = plist_id)
 call h5dwrite_f(dset, dt2_id, "denarray0", ms_dims, hdferr, xfer_prp = plist_id)


 call h5dclose_f(dset, hdferr)
 call h5dclose_f(dset, hdferr)
 call h5sclose_f(space, hdferr)
 call h5fclose_f(file_id, hdferr)



end program 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