Dear all,
I managed to solve the problem. Having fields of irregular array sizes
under one compound type is possible by inserting each arrays into the
compound type separately. For your reference, I attach my sample code
and h5dump output. Thank you all for your valuable suggestions.
Regards,
Ekin
On 03/14/2012 09:31 PM, Ekin Akoglu wrote:
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
_______________________________________________
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) :: arraydims0 = (/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
integer :: rank = 1
integer(hid_t) :: file_id, plist_id, dspace_id, dset_id, dtype_id ! Handles
integer :: hdferr
integer(hsize_t), dimension(1:1) :: ms_dims = (/ms_dim0/)
integer(hid_t) :: s1t_id, s2t_id, memtype, dt1_id, dt2_id
integer(8) :: sz1, sz2, sz, offset
real(4), target :: denarray(2), denarray0(3)
type(c_ptr) :: f_ptr
denarray = (/3.2, 4.1/)
denarray0 = (/9.8, 7.6, 5.1/)
! initialize FORTRAN interface
call h5open_f(hdferr)
! set property to preserve partially initialized fields of data
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 (H5F_ACC_TRUNC_F)
call h5fcreate_f(filename, H5F_ACC_TRUNC_F, file_id, hdferr)
! create the dataspace
call h5screate_simple_f(rank, ms_dims, dspace_id, hdferr)
! create 2 arrays "s1t_id" and "s2t_id"
call H5Tarray_create_f(H5T_NATIVE_REAL, rank, arraydims0, s1t_id, hdferr);
call H5Tarray_create_f(H5T_NATIVE_REAL, rank, arraydims1, s2t_id, hdferr);
! get size of each array
call H5Tget_size_f(s1t_id, sz1, hdferr)
call H5Tget_size_f(s2t_id, sz2, hdferr)
sz = sz1 + sz2
! create the compound datatype "memtype" includes "s1t_id" and "s2t_id"
call H5Tcreate_f(H5T_COMPOUND_F, sz, memtype, hdferr);
! insert arrays into the compound datatype
offset = 0
call H5Tinsert_f(memtype, "denarray", offset, s1t_id, hdferr)
offset = offset + sz1
call H5Tinsert_f(memtype, "denarray0", offset, s2t_id, hdferr)
! Create the dataset and write the array data to it.
call h5dcreate_f(file_id, dsetname1, memtype, dspace_id, dset_id, hdferr)
! Create memory types
call h5tcreate_f(H5T_COMPOUND_F, sz1, dt1_id, hdferr)
offset = 0
call h5tinsert_f(dt1_id, "denarray", offset, s1t_id, hdferr)
call h5tcreate_f(H5T_COMPOUND_F, sz2, dt2_id, hdferr)
offset = 0
call h5tinsert_f(dt2_id, "denarray0", offset, s2t_id, hdferr)
call h5dwrite_f(dset_id, dt1_id, denarray, ms_dims, hdferr, xfer_prp = plist_id)
call h5dwrite_f(dset_id, dt2_id, denarray0, ms_dims, hdferr, xfer_prp = plist_id)
end program complexcompound
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): {
[ 3.2, 4.1 ],
[ 9.8, 7.6, 5.1 ]
}
}
}
}
}
_______________________________________________
Hdf-forum is for HDF software users discussion.
[email protected]
http://mail.hdfgroup.org/mailman/listinfo/hdf-forum_hdfgroup.org