diff options
Diffstat (limited to 'fortran/test/tH5D.F90')
-rw-r--r-- | fortran/test/tH5D.F90 | 170 |
1 files changed, 169 insertions, 1 deletions
diff --git a/fortran/test/tH5D.F90 b/fortran/test/tH5D.F90 index b5ad6e8..4005c78 100644 --- a/fortran/test/tH5D.F90 +++ b/fortran/test/tH5D.F90 @@ -990,8 +990,176 @@ CONTAINS ENDIF ENDDO - END SUBROUTINE test_dset_fill + SUBROUTINE test_direct_chunk_io(cleanup, total_error) + + USE ISO_C_BINDING + + IMPLICIT NONE + + LOGICAL, INTENT(IN) :: cleanup + INTEGER, INTENT(OUT) :: total_error + CHARACTER(LEN=4), PARAMETER :: filename = "doIO" + CHARACTER(LEN=80) :: fix_filename + + CHARACTER(LEN=15), PARAMETER :: dsetname = "dset" + + INTEGER :: RANK = 2 + + INTEGER(HID_T) :: file_id ! File identifier + INTEGER(HID_T) :: dset_id ! Dataset identifier + INTEGER(HID_T) :: dataspace ! Dataspace identifier + INTEGER(HID_T) :: dcpl ! dataset creation property identifier + + ! + !dataset dimensions at creation time + ! + INTEGER, PARAMETER :: DIM0 = 4 + INTEGER, PARAMETER :: DIM1 = 32 + INTEGER(SIZE_T), PARAMETER :: CHUNK0 = DIM0 + INTEGER(SIZE_T), PARAMETER :: CHUNK1 = DIM1/2 + INTEGER(HSIZE_T), DIMENSION(2) :: offset + INTEGER(HSIZE_T), DIMENSION(2) :: dims = (/DIM0,DIM1/) + INTEGER(C_INT), DIMENSION(CHUNK0,CHUNK1), TARGET :: wdata1, rdata1, wdata2, rdata2 + INTEGER(HSIZE_T), DIMENSION(2) :: chunk = (/CHUNK0, CHUNK1/) + INTEGER :: i, j, n + INTEGER :: error + TYPE(C_PTR) :: f_ptr + INTEGER(C_int32_t) :: filters + INTEGER(SIZE_T) :: sizeINT + INTEGER(HID_T) :: dxpl + + ! + !Create a new file using default properties. + ! + CALL h5_fixname_f(filename, fix_filename, H5P_DEFAULT_F, error) + IF (error .NE. 0) THEN + WRITE(*,*) "Cannot modify filename" + STOP + ENDIF + + CALL h5pcreate_f(H5P_DATASET_XFER_F, dxpl, error) + CALL check("h5pcreate_f",error,total_error) + + CALL h5fcreate_f(fix_filename, H5F_ACC_TRUNC_F, file_id, error) + CALL check("h5fcreate_f",error,total_error) + + ! Dataset Fortran + + CALL h5screate_simple_f(RANK, dims, dataspace, error) + CALL check("h5screate_simple_f",error,total_error) + + CALL h5pcreate_f(H5P_DATASET_CREATE_F, dcpl, error) + CALL check("h5pcreate_f",error,total_error) + + CALL h5pset_chunk_f(dcpl, RANK, chunk, error) + CALL check("h5pset_chunk_f",error,total_error) + + CALL h5dcreate_f(file_id, dsetname, H5T_NATIVE_INTEGER, dataspace, dset_id, error, dcpl ) + CALL check("h5dcreate_f",error,total_error) + + CALL h5sclose_f(dataspace, error) + CALL check("h5sclose_f",error,total_error) + CALL h5pclose_f(dcpl, error) + CALL check("h5pclose_f",error,total_error) + + n = 0 + DO i = 1, CHUNK0 + DO j = 1, CHUNK1 + n = n + 1 + wdata1(i,j) = n + wdata2(i,j) = n*10 + END DO + END DO + +#ifdef H5_FORTRAN_HAVE_STORAGE_SIZE + sizeINT = storage_size(i, KIND=size_t)/storage_size(c_char_'a',c_size_t) +#else + sizeINT = SIZEOF(i) +#endif + + f_ptr = C_LOC(wdata1) + offset(1:2) = (/0, 0/) + CALL H5Dwrite_chunk_f(dset_id, 0_C_INT32_T, offset, CHUNK0 * CHUNK1 * sizeINT, f_ptr, error) + CALL check("h5dwrite_f",error,total_error) + + f_ptr = C_LOC(wdata2) + offset(1:2) = (/0, 16/) + CALL H5Dwrite_chunk_f(dset_id, 0_C_INT32_T, offset, CHUNK0 * CHUNK1 * sizeINT, f_ptr, error, dxpl) + CALL check("h5dwrite_f",error,total_error) + + CALL h5dclose_f(dset_id, error) + CALL check("h5dclose_f",error,total_error) + + ! + !Close the file. + ! + CALL h5fclose_f(file_id, error) + CALL check("h5fclose_f",error,total_error) + + ! + !read the data back + ! + !Open the file. + ! + CALL h5fopen_f(fix_filename, H5F_ACC_RDONLY_F, file_id, error) + CALL check("hfopen_f",error,total_error) + + ! + !Open the dataset. + ! + CALL h5dopen_f(file_id, dsetname, dset_id, error) + CALL check("h5dopen_f",error,total_error) + + f_ptr = C_LOC(rdata1) + filters = 99 + offset(1:2) = (/0, 0/) + CALL H5Dread_chunk_f(dset_id, offset, filters, f_ptr, error) + CALL check("H5Dread_chunk_f",error,total_error) + + ! Verify that the data read was correct. + DO i = 1, CHUNK0 + DO j = 1, CHUNK1 + CALL VERIFY("H5Dread_chunk_f", rdata1(i,j), wdata1(i,j), total_error) + IF(total_error.NE.0) EXIT + ENDDO + ENDDO + + CALL VERIFY("H5Dread_chunk_f",filters, 0_C_INT32_T, total_error) + + f_ptr = C_LOC(rdata2) + offset(1:2) = (/0, 16/) + CALL H5Dread_chunk_f(dset_id, offset, filters, f_ptr, error, dxpl) + CALL check("H5Dread_chunk_f",error,total_error) + + ! Verify that the data read was correct. + DO i = 1, CHUNK0 + DO j = 1, CHUNK1 + CALL VERIFY("H5Dread_chunk_f", rdata2(i,j), wdata2(i,j), total_error) + IF(total_error.NE.0) EXIT + ENDDO + ENDDO + + CALL VERIFY("H5Dread_chunk_f",filters, 0_C_INT32_T, total_error) + + CALL h5dclose_f(dset_id, error) + CALL check("h5dclose_f",error,total_error) + + ! + !Close the file. + ! + CALL h5fclose_f(file_id, error) + CALL check("h5fclose_f",error,total_error) + + CALL h5pclose_f(dxpl, error) + CALL check("h5pclose_f",error,total_error) + + IF(cleanup) CALL h5_cleanup_f(filename, H5P_DEFAULT_F, error) + CALL check("h5_cleanup_f", error, total_error) + + RETURN + END SUBROUTINE test_direct_chunk_io + END MODULE TH5D |