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 <http://www.hdfgroup.org/HDF5/Tutor/datatypes.html>,
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
_______________________________________________
Hdf-forum is for HDF software users discussion.
Hdf-forum@hdfgroup.org
http://mail.hdfgroup.org/mailman/listinfo/hdf-forum_hdfgroup.org

Reply via email to