diff options
author | Scot Breitenfeld <brtnfld@hdfgroup.org> | 2023-09-07 22:25:07 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-07 22:25:07 (GMT) |
commit | 08e115b7d8f95551be8bede824847997d95d0cf1 (patch) | |
tree | a377c6607419278eaafc8cf3043608f93afe1ad7 /fortran/test/tH5D.F90 | |
parent | 8253ab9ebf6a082dc07eb931f27b169d6a45d577 (diff) | |
download | hdf5-08e115b7d8f95551be8bede824847997d95d0cf1.zip hdf5-08e115b7d8f95551be8bede824847997d95d0cf1.tar.gz hdf5-08e115b7d8f95551be8bede824847997d95d0cf1.tar.bz2 |
Added new Fortran API wrappers (#3511)
* Added new wrappers for
h5get_free_list_sizes_f
H5Sselect_intersect_block_f
H5Sselect_shape_same_f
h5pget_no_selection_io_cause_f
h5pget_mpio_no_collective_cause_f
H5Lvisit_by_name_f
H5Lvisit_f
H5Fget_info_f
h5dwrite_chunk_f
h5dread_chunk_f
* added h5pget_file_space_page_size_f, h5pset_file_space_page_size_f, h5pget_file_space_strategy_f, h5pset_file_space_strategy_f, h5info tests
* added fortran tests
* Update tH5F.F90
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 |