Hello Pradeep,
I looked at the example. However, it is opening an existing dataset.
Does your dataset just contain one element?
I attached a program that creates a one element dataset (dset1.f90), and
then your code to read it back (code_using_hdf5-blj.f90) (but changed
data_dims=1).
See the attached examples. Is this what you want to do?
-Barbara
====================
Barbara Jones
The HDF Helpdesk
The HDF Group
[email protected]
====================
Hello,
I just started learning about hdf5 today.
I wrote a very basic program to read a number in the HFD5 format and then
print it out. The program is doing as expected but is giving me a
segmentation fault at the end. Any idea why? I have attached the code.
I am using "h5fc" to compile the code.
I have another question. I want to store the output of an already existing
code in the hdf5 format. Right now the code is being compiled using
"gfortran". After I make the necessary changes in the files which output
the data in the main code, can I simply change the compiler to "h5fc" and
expect things to work or it is more complicated than that?
Thank you,
Pradeep
--
Barbara L. Jones
[email protected]
! * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
! Copyright by The HDF Group. *
! Copyright by the Board of Trustees of the University of Illinois. *
! All rights reserved. *
! *
! This file is part of HDF5. The full HDF5 copyright notice, including *
! terms governing use, modification, and redistribution, is contained in *
! the files COPYING and Copyright.html. COPYING can be found at the root *
! of the source code distribution tree; Copyright.html can be found at the *
! root level of an installed copy of the electronic HDF5 document set and *
! is linked from the top-level documents page. It can also be found at *
! http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have *
! access to either file, you may request a copy from [email protected]. *
! * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
!
!
! The following example shows how to create an empty dataset.
! It creates a file called 'dsetf.h5', defines the
! dataset dataspace, creates a dataset which is a 4x6 integer array,
! and then closes the dataspace, the dataset, and the file.
!
PROGRAM DSETEXAMPLE
USE HDF5 ! This module contains all necessary modules
IMPLICIT NONE
CHARACTER(LEN=8), PARAMETER :: filename = "dsetf.h5" ! File name
CHARACTER(LEN=4), PARAMETER :: dsetname = "dset" ! Dataset name
INTEGER(HID_T) :: file_id ! File identifier
INTEGER(HID_T) :: dset_id ! Dataset identifier
INTEGER(HID_T) :: dspace_id ! Dataspace identifier
INTEGER(HSIZE_T), DIMENSION(1) :: dims = (/1/) ! Dataset dimensions
INTEGER :: rank = 1 ! Dataset rank
INTEGER :: error ! Error flag
!
! Initialize FORTRAN interface.
!
CALL h5open_f(error)
!
! Create a new file using default properties.
!
CALL h5fcreate_f(filename, H5F_ACC_TRUNC_F, file_id, error)
!
! Create the dataspace.
!
CALL h5screate_simple_f(rank, dims, dspace_id, error)
!
! Create the dataset with default properties.
!
CALL h5dcreate_f(file_id, dsetname, H5T_NATIVE_INTEGER, dspace_id, &
dset_id, error)
!
! End access to the dataset and release resources used by it.
!
CALL h5dclose_f(dset_id, error)
!
! Terminate access to the data space.
!
CALL h5sclose_f(dspace_id, error)
!
! Close the file.
!
CALL h5fclose_f(file_id, error)
!
! Close FORTRAN interface.
!
CALL h5close_f(error)
END PROGRAM DSETEXAMPLE
program print_using_hdf5
USE HDF5 ! This module contains all necessary modules
implicit none
CHARACTER(LEN=8), PARAMETER :: filename = "dsetf.h5" ! File name
CHARACTER(LEN=4), PARAMETER :: dsetname = "dset" ! Dataset name
INTEGER(HID_T) :: file_id ! File identifier
INTEGER(HID_T) :: dset_id ! Dataset identifier
INTEGER :: error ! Error flag
INTEGER, DIMENSION(1) :: dset_data, data_out ! Data buffers
INTEGER(HSIZE_T), DIMENSION(1) :: data_dims
dset_data(1) = 8
!
! Initialize FORTRAN interface.
!
CALL h5open_f(error)
!
! Open an existing file.
!
CALL h5fopen_f (filename, H5F_ACC_RDWR_F, file_id, error)
!
! Open an existing dataset.
!
CALL h5dopen_f(file_id, dsetname, dset_id, error)
!
! Write the dataset.
!
data_dims(1) = 1
CALL h5dwrite_f(dset_id, H5T_NATIVE_INTEGER, dset_data, data_dims, error)
!
! Read the dataset.
!
CALL h5dread_f(dset_id, H5T_NATIVE_INTEGER, data_out, data_dims, error)
write (*,*) "The number was: ", data_out(1)
!
! Close the dataset.
!
CALL h5dclose_f(dset_id, error)
!
! Close the file.
!
CALL h5fclose_f(file_id, error)
!
! Close FORTRAN interface.
!
CALL h5close_f(error)
end program print_using_hdf5
_______________________________________________
Hdf-forum is for HDF software users discussion.
[email protected]
http://mail.hdfgroup.org/mailman/listinfo/hdf-forum_hdfgroup.org