2010-01-30 12:29:13 +08:00
|
|
|
! * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
2007-02-08 01:55:01 +08:00
|
|
|
! Copyright by The HDF Group. *
|
2003-04-16 06:28:05 +08:00
|
|
|
! 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 *
|
2007-02-08 01:55:01 +08:00
|
|
|
! http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have *
|
|
|
|
! access to either file, you may request a copy from help@hdfgroup.org. *
|
2010-01-30 12:29:13 +08:00
|
|
|
! * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
2003-04-16 06:28:05 +08:00
|
|
|
!
|
2000-09-20 04:06:49 +08:00
|
|
|
!
|
2010-01-30 12:29:13 +08:00
|
|
|
! This example shows how to write and read a hyperslab.
|
2000-09-20 04:06:49 +08:00
|
|
|
!
|
|
|
|
|
|
|
|
PROGRAM SELECTEXAMPLE
|
|
|
|
|
2010-01-30 12:29:13 +08:00
|
|
|
USE HDF5 ! This module contains all necessary modules
|
|
|
|
|
2000-09-20 04:06:49 +08:00
|
|
|
IMPLICIT NONE
|
|
|
|
|
|
|
|
CHARACTER(LEN=7), PARAMETER :: filename = "sdsf.h5" ! File name
|
|
|
|
CHARACTER(LEN=8), PARAMETER :: dsetname = "IntArray" ! Dataset name
|
|
|
|
|
2010-01-30 12:29:13 +08:00
|
|
|
INTEGER(HID_T) :: file_id ! File identifier
|
|
|
|
INTEGER(HID_T) :: dset_id ! Dataset identifier
|
|
|
|
INTEGER(HID_T) :: dataspace ! Dataspace identifier
|
|
|
|
INTEGER(HID_T) :: memspace ! memspace identifier
|
2000-09-20 04:06:49 +08:00
|
|
|
|
|
|
|
INTEGER(HSIZE_T), DIMENSION(3) :: dimsm = (/7,7,3/) ! Dataset dimensions
|
|
|
|
! in memory
|
|
|
|
INTEGER(HSIZE_T), DIMENSION(2) :: dimsf = (/5,6/) ! Dataset dimensions.
|
|
|
|
|
2010-01-30 12:29:13 +08:00
|
|
|
INTEGER(HSIZE_T), DIMENSION(2) :: count = (/3,4/)
|
2000-09-20 04:06:49 +08:00
|
|
|
! Size of the hyperslab in the file
|
|
|
|
INTEGER(HSIZE_T), DIMENSION(2) :: offset = (/1,2/)
|
2010-01-30 12:29:13 +08:00
|
|
|
!hyperslab offset in the file
|
2000-09-20 04:06:49 +08:00
|
|
|
INTEGER(HSIZE_T), DIMENSION(3) :: count_out = (/3,4,1/)
|
2010-01-30 12:29:13 +08:00
|
|
|
!Size of the hyperslab in memory
|
2000-09-20 04:06:49 +08:00
|
|
|
INTEGER(HSIZE_T), DIMENSION(3) :: offset_out = (/3,0,0/)
|
2010-01-30 12:29:13 +08:00
|
|
|
!hyperslab offset in memory
|
2000-09-20 04:06:49 +08:00
|
|
|
INTEGER, DIMENSION(5,6) :: data ! Data to write
|
|
|
|
INTEGER, DIMENSION(7,7,3) :: data_out ! Output buffer
|
|
|
|
INTEGER :: dsetrank = 2 ! Dataset rank ( in file )
|
|
|
|
INTEGER :: memrank = 3 ! Dataset rank ( in memory )
|
2010-01-30 12:29:13 +08:00
|
|
|
INTEGER :: i, j, k
|
2000-09-20 04:06:49 +08:00
|
|
|
|
2014-04-06 23:56:21 +08:00
|
|
|
INTEGER :: error ! Error flag
|
2004-05-21 05:38:28 +08:00
|
|
|
INTEGER(HSIZE_T), DIMENSION(3) :: data_dims
|
2000-09-20 04:06:49 +08:00
|
|
|
|
|
|
|
|
2014-04-06 23:56:21 +08:00
|
|
|
!
|
|
|
|
! Write data to the HDF5 file.
|
|
|
|
!
|
2000-09-20 04:06:49 +08:00
|
|
|
|
|
|
|
!
|
2010-01-30 12:29:13 +08:00
|
|
|
! Data initialization.
|
2000-09-20 04:06:49 +08:00
|
|
|
!
|
|
|
|
do i = 1, 5
|
|
|
|
do j = 1, 6
|
|
|
|
data(i,j) = (i-1) + (j-1);
|
|
|
|
end do
|
|
|
|
end do
|
|
|
|
!
|
|
|
|
! 0, 1, 2, 3, 4, 5
|
|
|
|
! 1, 2, 3, 4, 5, 6
|
|
|
|
! 2, 3, 4, 5, 6, 7
|
|
|
|
! 3, 4, 5, 6, 7, 8
|
|
|
|
! 4, 5, 6, 7, 8, 9
|
|
|
|
!
|
2010-01-30 12:29:13 +08:00
|
|
|
|
2000-09-20 04:06:49 +08:00
|
|
|
!
|
2010-01-30 12:29:13 +08:00
|
|
|
! Initialize FORTRAN interface.
|
2000-09-20 04:06:49 +08:00
|
|
|
!
|
2010-01-30 12:29:13 +08:00
|
|
|
CALL h5open_f(error)
|
2000-09-20 04:06:49 +08:00
|
|
|
|
|
|
|
!
|
|
|
|
! Create a new file using default properties.
|
2010-01-30 12:29:13 +08:00
|
|
|
!
|
2000-09-20 04:06:49 +08:00
|
|
|
CALL h5fcreate_f(filename, H5F_ACC_TRUNC_F, file_id, error)
|
|
|
|
|
|
|
|
!
|
2010-01-30 12:29:13 +08:00
|
|
|
! Create the data space for the dataset.
|
2000-09-20 04:06:49 +08:00
|
|
|
!
|
|
|
|
CALL h5screate_simple_f(dsetrank, dimsf, dataspace, error)
|
|
|
|
|
|
|
|
!
|
|
|
|
! Create the dataset with default properties.
|
|
|
|
!
|
|
|
|
CALL h5dcreate_f(file_id, dsetname, H5T_NATIVE_INTEGER, dataspace, &
|
|
|
|
dset_id, error)
|
|
|
|
|
|
|
|
!
|
|
|
|
! Write the dataset.
|
|
|
|
!
|
2001-04-27 11:52:24 +08:00
|
|
|
data_dims(1) = 5
|
2010-01-30 12:29:13 +08:00
|
|
|
data_dims(2) = 6
|
2001-04-27 11:52:24 +08:00
|
|
|
CALL h5dwrite_f(dset_id, H5T_NATIVE_INTEGER, data, data_dims, error)
|
2000-09-20 04:06:49 +08:00
|
|
|
|
|
|
|
!
|
|
|
|
! Close the dataspace for the dataset.
|
|
|
|
!
|
|
|
|
CALL h5sclose_f(dataspace, error)
|
|
|
|
|
|
|
|
!
|
|
|
|
! Close the dataset.
|
|
|
|
!
|
|
|
|
CALL h5dclose_f(dset_id, error)
|
|
|
|
|
|
|
|
!
|
|
|
|
! Close the file.
|
|
|
|
!
|
|
|
|
CALL h5fclose_f(file_id, error)
|
|
|
|
|
|
|
|
!
|
2010-01-30 12:29:13 +08:00
|
|
|
! This part of the code reads the hyperslab from the sds.h5 file just
|
2000-09-20 04:06:49 +08:00
|
|
|
! created, into a 2-dimensional plane of the 3-dimensional dataset.
|
|
|
|
!
|
|
|
|
|
|
|
|
!
|
|
|
|
! Initialize data_out array.
|
|
|
|
!
|
2010-01-30 12:29:13 +08:00
|
|
|
do k = 1, 3
|
2000-09-20 04:06:49 +08:00
|
|
|
do j = 1, 7
|
2001-04-27 11:52:24 +08:00
|
|
|
do i = 1, 7
|
2000-09-20 04:06:49 +08:00
|
|
|
data_out(i,j,k) = 0;
|
|
|
|
end do
|
|
|
|
end do
|
|
|
|
end do
|
|
|
|
|
|
|
|
!
|
|
|
|
! Open the file.
|
|
|
|
!
|
2000-11-04 03:49:59 +08:00
|
|
|
! CALL h5fopen_f (filename, H5F_ACC_RDONLY_F, file_id, error)
|
|
|
|
CALL h5fopen_f (filename, H5F_ACC_RDWR_F, file_id, error)
|
|
|
|
write(*,*) error
|
2010-01-30 12:29:13 +08:00
|
|
|
|
2000-09-20 04:06:49 +08:00
|
|
|
!
|
|
|
|
! Open the dataset.
|
|
|
|
!
|
|
|
|
CALL h5dopen_f(file_id, dsetname, dset_id, error)
|
|
|
|
|
|
|
|
!
|
|
|
|
! Get dataset's dataspace identifier.
|
|
|
|
!
|
|
|
|
CALL h5dget_space_f(dset_id, dataspace, error)
|
|
|
|
|
|
|
|
!
|
|
|
|
! Select hyperslab in the dataset.
|
|
|
|
!
|
|
|
|
CALL h5sselect_hyperslab_f(dataspace, H5S_SELECT_SET_F, &
|
2010-01-30 12:29:13 +08:00
|
|
|
offset, count, error)
|
2000-09-20 04:06:49 +08:00
|
|
|
!
|
|
|
|
! Create memory dataspace.
|
|
|
|
!
|
|
|
|
CALL h5screate_simple_f(memrank, dimsm, memspace, error)
|
|
|
|
|
|
|
|
!
|
|
|
|
! Select hyperslab in memory.
|
|
|
|
!
|
|
|
|
CALL h5sselect_hyperslab_f(memspace, H5S_SELECT_SET_F, &
|
2010-01-30 12:29:13 +08:00
|
|
|
offset_out, count_out, error)
|
2000-09-20 04:06:49 +08:00
|
|
|
|
|
|
|
!
|
2010-01-30 12:29:13 +08:00
|
|
|
! Read data from hyperslab in the file into the hyperslab in
|
2000-09-20 04:06:49 +08:00
|
|
|
! memory and display.
|
|
|
|
!
|
2001-04-27 11:52:24 +08:00
|
|
|
data_dims(1) = 7
|
|
|
|
data_dims(2) = 7
|
2010-01-30 12:29:13 +08:00
|
|
|
data_dims(3) = 3
|
2001-04-27 11:52:24 +08:00
|
|
|
CALL H5dread_f(dset_id, H5T_NATIVE_INTEGER, data_out, data_dims, error, &
|
2000-09-20 04:06:49 +08:00
|
|
|
memspace, dataspace)
|
2010-01-30 12:29:13 +08:00
|
|
|
|
2000-09-20 04:06:49 +08:00
|
|
|
!
|
|
|
|
! Display data_out array
|
|
|
|
!
|
|
|
|
do i = 1, 7
|
|
|
|
print *, (data_out(i,j,1), j = 1,7)
|
|
|
|
end do
|
|
|
|
|
|
|
|
! 0 0 0 0 0 0 0
|
|
|
|
! 0 0 0 0 0 0 0
|
|
|
|
! 0 0 0 0 0 0 0
|
2010-01-30 12:29:13 +08:00
|
|
|
! 3 4 5 6 0 0 0
|
2000-09-20 04:06:49 +08:00
|
|
|
! 4 5 6 7 0 0 0
|
|
|
|
! 5 6 7 8 0 0 0
|
|
|
|
! 0 0 0 0 0 0 0
|
|
|
|
!
|
|
|
|
|
|
|
|
!
|
|
|
|
! Close the dataspace for the dataset.
|
|
|
|
!
|
|
|
|
CALL h5sclose_f(dataspace, error)
|
|
|
|
|
|
|
|
!
|
|
|
|
! Close the memoryspace.
|
|
|
|
!
|
|
|
|
CALL h5sclose_f(memspace, error)
|
|
|
|
|
|
|
|
!
|
|
|
|
! Close the dataset.
|
|
|
|
!
|
|
|
|
CALL h5dclose_f(dset_id, error)
|
|
|
|
|
|
|
|
!
|
|
|
|
! Close the file.
|
|
|
|
!
|
|
|
|
CALL h5fclose_f(file_id, error)
|
|
|
|
|
|
|
|
!
|
2000-11-04 03:49:59 +08:00
|
|
|
! Close FORTRAN interface.
|
2000-09-20 04:06:49 +08:00
|
|
|
!
|
2000-11-18 06:45:34 +08:00
|
|
|
CALL h5close_f(error)
|
2000-09-20 04:06:49 +08:00
|
|
|
|
2010-01-30 12:29:13 +08:00
|
|
|
END PROGRAM SELECTEXAMPLE
|