Thanks for the example. That helps.
2013/3/4 <[email protected]> > The following similar example might help you, can you check if you obtain > a similar output. > > PROGRAM main > > USE HDF5 > > INTEGER, PARAMETER :: nx=2 > INTEGER :: error > INTEGER(HID_T) :: out_file, out_file_id,dspace_id > INTEGER(HID_T) :: dset_id_r, dset_id_d > INTEGER, PARAMETER :: rank=1 > INTEGER(HSIZE_T), DIMENSION(1) :: dims = (/2/) > > REAL*4, DIMENSION(1:nx) :: buff_r > REAL*8, DIMENSION(1:nx) :: buff_d > > buff_r = 3.14 > buff_d = 2.44 > > > ! Initialize FORTRAN interface of HDF5. > CALL h5open_f(error) > > ! Create a new file. > CALL h5fcreate_f("out.h5", H5F_ACC_TRUNC_F, out_file_id, error) > > > ! Create the dataspace. > CALL h5screate_simple_f(rank, dims, dspace_id, error) > > ! IF (sizeofreal.EQ.8) THEN > > > ! Create the dataset with default properties. > CALL h5dcreate_f(out_file_id, "DS_DOUBLE", H5T_NATIVE_DOUBLE, dspace_id, > & > dset_id_r, error) > > ! Write the dataset. > CALL h5dwrite_f(dset_id_r, H5T_NATIVE_DOUBLE, buff_d, dims, error) > > ! else > > > ! Create the dataset with default properties. > CALL h5dcreate_f(out_file_id, "DS_REAL", H5T_NATIVE_REAL, dspace_id, & > dset_id_d, error) > > ! Write the dataset. > CALL h5dwrite_f(dset_id_d, H5T_NATIVE_REAL, buff_r, dims, error) > > > ! end if > CALL h5sclose_f(dspace_id, error) > CALL h5fclose_f(out_file_id,error) > > END PROGRAM main > > h5dump: > > HDF5 "out.h5" { > GROUP "/" { > DATASET "DS_DOUBLE" { > DATATYPE H5T_IEEE_F64LE > DATASPACE SIMPLE { ( 2 ) / ( 2 ) } > DATA { > (0): 2.44, 2.44 > } > } > DATASET "DS_REAL" { > DATATYPE H5T_IEEE_F32LE > DATASPACE SIMPLE { ( 2 ) / ( 2 ) } > DATA { > (0): 3.14, 3.14 > > } > } > } > } > > > > On 2013-02-28 04:42, Pradeep Jha wrote: > >> Hello, >> >> I have a fortran file of size Nx*Ny*Nz which can contain either >> single or double precision data. I store the data type information in >> a variable called "sizeofreal" (which can either have the value 4 or >> 8). >> >> After reading this page [1], I wrote a fortran file for creating h5 >> >> files, so that it can automatically write the final h5 file with the >> correct Datatype. Here is a gist of the code I wrote: >> >> ------------------------------**---------------------------- >> >> ********** code for initialization *************** >> ! Read the input data. >> open >> >> (in_file_id,FILE=in_file,form=**'unformatted',access='direct',** >> recl=sizeofreal*nx*ny*nz) >> >> read (in_file_id,rec=1) buff >> >> ! Initialize FORTRAN interface of HDF5. >> >> CALL h5open_f(error) >> >> ! Create a new file. >> >> CALL h5fcreate_f (out_file, H5F_ACC_TRUNC_F, out_file_id, error) >> >> ! Create the dataspace. >> >> CALL h5screate_simple_f(rank, dims, dspace_id, error) >> >> if (sizeofreal.eq.8) then >> >> ! Create the dataset with default properties. >> >> CALL h5dcreate_f(out_file_id, dsetname, H5T_NATIVE_DOUBLE, >> dspace_id, & >> >> dset_id, error) >> >> ! Write the dataset. >> >> CALL h5dwrite_f(dset_id, H5T_NATIVE_DOUBLE, buff, dims, error) >> >> else >> >> ! Create the dataset with default properties. >> >> CALL h5dcreate_f(out_file_id, dsetname, H5T_NATIVE_REAL, >> dspace_id, & >> >> dset_id, error) >> >> ! Write the dataset. >> >> CALL h5dwrite_f(dset_id, H5T_NATIVE_REAL, buff, dims, error) >> >> end if >> >> ********** code for termination *************** >> >> >> ------------------------------**------------------------------** >> -------------- >> >> This is not working for double-precision data. For single precision >> data it works fine. If I remove the "if" statement in between, then no >> matter if I have double or single precision data in my original data >> file, when I do the "h5dump -H" on the final h5 file, the final >> Datatype is always DATATYPE H5T_IEEE_F32LE. This cannot be correct. >> >> Please help me in this regard, >> Thank you, >> Pradeep >> >> Links: >> ------ >> [1] >> http://www.hdfgroup.org/HDF5/**Tutor/datatypes.html<http://www.hdfgroup.org/HDF5/Tutor/datatypes.html> >> >> ______________________________**_________________ >> Hdf-forum is for HDF software users discussion. >> [email protected] >> http://mail.hdfgroup.org/**mailman/listinfo/hdf-forum_**hdfgroup.org<http://mail.hdfgroup.org/mailman/listinfo/hdf-forum_hdfgroup.org> >> > > ______________________________**_________________ > Hdf-forum is for HDF software users discussion. > [email protected] > http://mail.hdfgroup.org/**mailman/listinfo/hdf-forum_**hdfgroup.org<http://mail.hdfgroup.org/mailman/listinfo/hdf-forum_hdfgroup.org> >
_______________________________________________ Hdf-forum is for HDF software users discussion. [email protected] http://mail.hdfgroup.org/mailman/listinfo/hdf-forum_hdfgroup.org
