summaryrefslogtreecommitdiffstats
path: root/fortran/test
diff options
context:
space:
mode:
authorScot Breitenfeld <brtnfld@hdfgroup.org>2013-02-18 02:01:18 (GMT)
committerScot Breitenfeld <brtnfld@hdfgroup.org>2013-02-18 02:01:18 (GMT)
commita976ca99a9de1fbe2496c23fa941b7c3e8af3967 (patch)
treeb00f06e247a8c61c8a53d09a3d4201948b703c70 /fortran/test
parent32da9c96aed341fa67670e84b82ca9292bd1506c (diff)
downloadhdf5-a976ca99a9de1fbe2496c23fa941b7c3e8af3967.zip
hdf5-a976ca99a9de1fbe2496c23fa941b7c3e8af3967.tar.gz
hdf5-a976ca99a9de1fbe2496c23fa941b7c3e8af3967.tar.bz2
[svn-r23293] Fix for HDFFV-8268: Fortran wrapper for H5Fget_file_image function.
Tested: (jam, gnu,intel compilers)
Diffstat (limited to 'fortran/test')
-rw-r--r--fortran/test/CMakeLists.txt1
-rw-r--r--fortran/test/Makefile.am2
-rw-r--r--fortran/test/Makefile.in7
-rw-r--r--fortran/test/fortranlib_test_F03.f905
-rw-r--r--fortran/test/tH5F_F03.f90171
5 files changed, 182 insertions, 4 deletions
diff --git a/fortran/test/CMakeLists.txt b/fortran/test/CMakeLists.txt
index 5b41a32..5b9ca11 100644
--- a/fortran/test/CMakeLists.txt
+++ b/fortran/test/CMakeLists.txt
@@ -105,6 +105,7 @@ IF (HDF5_ENABLE_F2003)
fortranlib_test_F03.f90
tH5F.f90
tH5E_F03.f90
+ tH5F_F03.f90
tH5L_F03.f90
tH5O_F03.f90
tH5P_F03.f90
diff --git a/fortran/test/Makefile.am b/fortran/test/Makefile.am
index 42dd127..84f55e5 100644
--- a/fortran/test/Makefile.am
+++ b/fortran/test/Makefile.am
@@ -68,7 +68,7 @@ fortranlib_test_1_8_SOURCES = fortranlib_test_1_8.f90 \
if FORTRAN_2003_CONDITIONAL_F
fortranlib_test_F03_SOURCES = fortranlib_test_F03.f90 \
- tH5F.f90 tH5E_F03.f90 tH5L_F03.f90 tH5O_F03.f90 tH5P_F03.f90 tH5T_F03.f90
+ tH5F.f90 tH5E_F03.f90 tH5F_F03.f90 tH5L_F03.f90 tH5O_F03.f90 tH5P_F03.f90 tH5T_F03.f90
endif
diff --git a/fortran/test/Makefile.in b/fortran/test/Makefile.in
index b9f05e3..7476160 100644
--- a/fortran/test/Makefile.in
+++ b/fortran/test/Makefile.in
@@ -136,11 +136,12 @@ fortranlib_test_1_8_LDADD = $(LDADD)
fortranlib_test_1_8_DEPENDENCIES = libh5test_fortran.la $(LIBH5TEST) \
$(LIBH5F) $(LIBHDF5)
am__fortranlib_test_F03_SOURCES_DIST = fortranlib_test_F03.f90 \
- tH5F.f90 tH5E_F03.f90 tH5L_F03.f90 tH5O_F03.f90 tH5P_F03.f90 \
- tH5T_F03.f90
+ tH5F.f90 tH5E_F03.f90 tH5F_F03.f90 tH5L_F03.f90 tH5O_F03.f90 \
+ tH5P_F03.f90 tH5T_F03.f90
@FORTRAN_2003_CONDITIONAL_F_TRUE@am_fortranlib_test_F03_OBJECTS = fortranlib_test_F03.$(OBJEXT) \
@FORTRAN_2003_CONDITIONAL_F_TRUE@ tH5F.$(OBJEXT) \
@FORTRAN_2003_CONDITIONAL_F_TRUE@ tH5E_F03.$(OBJEXT) \
+@FORTRAN_2003_CONDITIONAL_F_TRUE@ tH5F_F03.$(OBJEXT) \
@FORTRAN_2003_CONDITIONAL_F_TRUE@ tH5L_F03.$(OBJEXT) \
@FORTRAN_2003_CONDITIONAL_F_TRUE@ tH5O_F03.$(OBJEXT) \
@FORTRAN_2003_CONDITIONAL_F_TRUE@ tH5P_F03.$(OBJEXT) \
@@ -527,7 +528,7 @@ fortranlib_test_1_8_SOURCES = fortranlib_test_1_8.f90 \
tH5F.f90 tH5O.f90 tH5A_1_8.f90 tH5G_1_8.f90
@FORTRAN_2003_CONDITIONAL_F_TRUE@fortranlib_test_F03_SOURCES = fortranlib_test_F03.f90 \
-@FORTRAN_2003_CONDITIONAL_F_TRUE@ tH5F.f90 tH5E_F03.f90 tH5L_F03.f90 tH5O_F03.f90 tH5P_F03.f90 tH5T_F03.f90
+@FORTRAN_2003_CONDITIONAL_F_TRUE@ tH5F.f90 tH5E_F03.f90 tH5F_F03.f90 tH5L_F03.f90 tH5O_F03.f90 tH5P_F03.f90 tH5T_F03.f90
fflush1_SOURCES = fflush1.f90
fflush2_SOURCES = fflush2.f90
diff --git a/fortran/test/fortranlib_test_F03.f90 b/fortran/test/fortranlib_test_F03.f90
index 606b050..111d35e 100644
--- a/fortran/test/fortranlib_test_F03.f90
+++ b/fortran/test/fortranlib_test_F03.f90
@@ -163,6 +163,11 @@ PROGRAM fortranlibtest_F03
CALL obj_info(ret_total_error)
CALL write_test_status(ret_total_error, ' Testing object info functions ', total_error)
+ ret_total_error = 0
+ CALL test_get_file_image(ret_total_error)
+ CALL write_test_status(ret_total_error, ' Testing get file image ', total_error)
+
+
WRITE(*,*)
WRITE(*,*) ' ============================================ '
diff --git a/fortran/test/tH5F_F03.f90 b/fortran/test/tH5F_F03.f90
new file mode 100644
index 0000000..4484144
--- /dev/null
+++ b/fortran/test/tH5F_F03.f90
@@ -0,0 +1,171 @@
+!****h* root/fortran/test/tH5F_F03.f90
+!
+! NAME
+! tH5F_F03.f90
+!
+! FUNCTION
+! Test FORTRAN HDF5 H5F APIs which are dependent on FORTRAN 2003
+! features.
+!
+! COPYRIGHT
+! * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+! 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 help@hdfgroup.org. *
+! * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+!
+! NOTES
+! Tests the H5F APIs functionalities of:
+! h5fget_file_image_f
+!
+! CONTAINS SUBROUTINES
+! test_get_file_image
+!
+!*****
+
+! *****************************************
+! *** H 5 F T E S T S
+! *****************************************
+
+SUBROUTINE test_get_file_image(total_error)
+ !
+ ! Tests the wrapper for h5fget_file_image
+ !
+ USE HDF5
+ USE ISO_C_BINDING
+
+ IMPLICIT NONE
+
+ INTEGER, INTENT(INOUT) :: total_error ! returns error
+
+ CHARACTER(kind=c_char), ALLOCATABLE, DIMENSION(:), TARGET :: file_image_ptr ! Image from file
+ CHARACTER(kind=c_char), ALLOCATABLE, DIMENSION(:), TARGET :: image_ptr ! Image from h5fget_file_image_f
+
+ INTEGER, DIMENSION(1:100), TARGET :: data ! Write data
+ INTEGER :: i, file_sz
+ INTEGER(hid_t) :: file_id = -1 ! File identifier
+ INTEGER(hid_t) :: dset_id = -1 ! Dataset identifier
+ INTEGER(hid_t) :: space_id = -1 ! Dataspace identifier
+ INTEGER(hsize_t), DIMENSION(1:2) :: dims ! Dataset dimensions
+ INTEGER(size_t) :: itmp_a, itmp_b ! General purpose integers
+ INTEGER(size_t) :: image_size ! Size of image
+ TYPE(C_PTR) :: f_ptr ! Pointer
+ INTEGER(hid_t) :: fapl ! File access property
+ INTEGER :: error ! Error flag
+
+ ! Create new properties for file access
+ CALL h5pcreate_f(H5P_FILE_ACCESS_F, fapl, error)
+ CALL check("h5pcreate_f", error, total_error)
+
+ ! Set standard I/O driver
+ CALL h5pset_fapl_stdio_f(fapl, error)
+ CALL check("h5pset_fapl_stdio_f", error, total_error)
+
+ ! Create the file
+ CALL h5fcreate_f("tget_file_image.h5", H5F_ACC_TRUNC_F, file_id, error, H5P_DEFAULT_F, fapl)
+ CALL check("h5fcreate_f", error, total_error)
+
+ ! Set up data space for new data set
+ dims(1:2) = (/10,10/)
+
+ CALL h5screate_simple_f(2, dims, space_id, error)
+ CALL check("h5screate_simple_f", error, total_error)
+
+ ! Create a dataset
+ CALL h5dcreate_f(file_id, "dset 0", H5T_NATIVE_INTEGER, space_id, dset_id, error)
+ CALL check("h5dcreate_f", error, total_error)
+
+ ! Write some data to the data set
+ DO i = 1, 100
+ data(i) = i
+ ENDDO
+
+ f_ptr = C_LOC(data(1))
+ CALL h5dwrite_f(dset_id, H5T_NATIVE_INTEGER, f_ptr, error)
+ CALL check("h5dwrite_f",error, total_error)
+
+ ! Flush the file
+ CALL h5fflush_f(file_id, H5F_SCOPE_GLOBAL_F, error)
+ CALL check("h5fflush_f",error, total_error)
+
+ ! Open the test file using standard I/O calls
+ OPEN(UNIT=10,FILE='tget_file_image.h5', ACCESS='STREAM')
+ ! Get the size of the test file
+ !
+ ! Since we use the eoa to calculate the image size, the file size
+ ! may be larger. This is OK, as long as (in this specialized instance)
+ ! the remainder of the file is all '\0's.
+ !
+ ! With latest mods to truncate call in core file drive,
+ ! file size should match image size; get the file size
+ INQUIRE(UNIT=10, SIZE=file_sz)
+ CLOSE(UNIT=10)
+
+ ! I. Get buffer size needed to hold the buffer
+
+ ! A. Preferred way to get the size
+ f_ptr = C_NULL_PTR
+ CALL h5fget_file_image_f(file_id, f_ptr, INT(0, size_t), error, image_size)
+ CALL check("h5fget_file_image_f",error, total_error)
+ CALL verify("h5fget_file_image_f", file_sz, INT(image_size), total_error)
+
+ ! B. f_ptr set to point to an incorrect buffer, should pass anyway
+ f_ptr = C_LOC(data(1))
+ itmp_a = 1
+ CALL h5fget_file_image_f(file_id, f_ptr, itmp_a, error, image_size)
+ CALL check("h5fget_file_image_f",error, total_error)
+ CALL VERIFY("h5fget_file_image_f", INT(itmp_a), 1, total_error) ! Routine should not change the value
+ CALL VERIFY("h5fget_file_image_f", file_sz, INT(image_size), total_error)
+
+ ! Allocate a buffer of the appropriate size
+ ALLOCATE(image_ptr(1:image_size))
+
+ ! Load the image of the file into the buffer
+ f_ptr = C_LOC(image_ptr(1)(1:1))
+ CALL h5fget_file_image_f(file_id, f_ptr, image_size, error)
+ CALL check("h5fget_file_image_f",error, total_error)
+
+ ! Close dset and space
+ CALL h5dclose_f(dset_id, error)
+ CALL check("h5dclose_f", error, total_error)
+ CALL h5sclose_f(space_id, error)
+ CALL check("h5sclose_f", error, total_error)
+ ! Close the test file
+ CALL h5fclose_f(file_id, error)
+ CALL check("h5fclose_f",error, total_error)
+
+ ! Allocate a buffer for the test file image
+ ALLOCATE(file_image_ptr(1:image_size))
+
+ ! Open the test file using standard I/O calls
+ OPEN(UNIT=10,FILE='tget_file_image.h5', ACCESS='STREAM')
+
+ ! Read the test file from disk into the buffer
+ DO i = 1, image_size
+ READ(10) file_image_ptr(i)
+ ENDDO
+
+ CLOSE(10)
+
+ ! verify the file and the image contain the same data
+ DO i = 1, image_size
+ ! convert one byte to an unsigned integer
+ IF( ICHAR(file_image_ptr(i)) .NE. ICHAR(image_ptr(i)))THEN
+ total_error = total_error + 1
+ EXIT
+ ENDIF
+ ENDDO
+
+ ! release resources
+ DEALLOCATE(file_image_ptr,image_ptr)
+
+END SUBROUTINE test_get_file_image