-
-
Notifications
You must be signed in to change notification settings - Fork 244
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
H5fget_name_f len_trim fix #826
Closed
Closed
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
0f07e8b
Use LEN() rather than LEN_TRIM() to determine buffer length (prevents…
jhaiduce 4b5838b
Update reopentest to populate the buffer passed to h5fget_name_f with…
jhaiduce d7a9c29
Correct variable name (filename=>file_name)
jhaiduce 8c4bf97
Check length of returned filename
jhaiduce bae6643
Add calls to check() so that that reopentest fails if the wrong filen…
jhaiduce fcafa75
Revert changes to reopentest, and add a new test that focuses on h5fg…
jhaiduce 4ed79b8
Removed operations and variables copied from reopentest that are not …
jhaiduce bc27305
Change "dataset id" to "object id" since we also call this subroutine…
jhaiduce File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -580,6 +580,155 @@ SUBROUTINE reopentest(cleanup, total_error) | |
|
||
END SUBROUTINE reopentest | ||
|
||
! The following subroutine checks that h5fget_name_f produces | ||
! correct output for a given obj_id and filename. | ||
! | ||
|
||
SUBROUTINE check_get_name(obj_id, fix_filename, total_error) | ||
USE HDF5 ! This module contains all necessary modules | ||
USE TH5_MISC | ||
IMPLICIT NONE | ||
INTEGER(HID_T) :: obj_id ! Object identifier | ||
CHARACTER(LEN=80), INTENT(IN) :: fix_filename ! Expected filename | ||
INTEGER, INTENT(INOUT) :: total_error ! Error count | ||
|
||
CHARACTER(LEN=80) ::file_name ! Filename buffer | ||
INTEGER::error ! HDF5 error code | ||
INTEGER(SIZE_T)::name_size ! Filename length | ||
! | ||
!Get file name from the dataset identifier | ||
! | ||
|
||
! Use an uninitialized buffer | ||
CALL h5fget_name_f(obj_id, file_name, name_size, error) | ||
CALL check("h5fget_name_f",error,total_error) | ||
IF(name_size .NE. LEN_TRIM(fix_filename))THEN | ||
WRITE(*,*) " file name size obtained from the dataset id is incorrect" | ||
total_error = total_error + 1 | ||
ENDIF | ||
IF(file_name(1:name_size) .NE. TRIM(fix_filename)) THEN | ||
WRITE(*,*) " file name obtained from the object id is incorrect" | ||
total_error = total_error + 1 | ||
END IF | ||
|
||
! Use a buffer initialized with spaces | ||
file_name(:) = " " | ||
CALL h5fget_name_f(obj_id, file_name, name_size, error) | ||
CALL check("h5fget_name_f",error,total_error) | ||
IF(name_size .NE. LEN_TRIM(fix_filename))THEN | ||
WRITE(*,*) " file name size obtained from the object id is incorrect" | ||
total_error = total_error + 1 | ||
ENDIF | ||
IF(file_name(1:name_size) .NE. TRIM(fix_filename)) THEN | ||
WRITE(*,*) " file name obtained from the dataset id is incorrect" | ||
total_error = total_error + 1 | ||
END IF | ||
|
||
! Use a buffer initialized with non-whitespace characters | ||
file_name(:) = "a" | ||
CALL h5fget_name_f(obj_id, file_name, name_size, error) | ||
CALL check("h5fget_name_f",error,total_error) | ||
IF(name_size .NE. LEN_TRIM(fix_filename))THEN | ||
WRITE(*,*) " file name size obtained from the object id is incorrect" | ||
total_error = total_error + 1 | ||
ENDIF | ||
IF(file_name(1:name_size) .NE. TRIM(fix_filename)) THEN | ||
WRITE(*,*) " file name obtained from the object id is incorrect" | ||
total_error = total_error + 1 | ||
END IF | ||
|
||
END SUBROUTINE check_get_name | ||
|
||
! The following subroutine tests h5fget_name_f. | ||
! It creates the file which has name "filename.h5" and | ||
! tests that h5fget_name_f also returns the name "filename.h5" | ||
! | ||
|
||
SUBROUTINE get_name_test(cleanup, total_error) | ||
USE HDF5 ! This module contains all necessary modules | ||
USE TH5_MISC | ||
IMPLICIT NONE | ||
LOGICAL, INTENT(IN) :: cleanup | ||
INTEGER, INTENT(INOUT) :: total_error | ||
|
||
! | ||
CHARACTER(LEN=*), PARAMETER :: filename = "filename" | ||
CHARACTER(LEN=80) :: fix_filename | ||
|
||
INTEGER(HID_T) :: file_id ! File identifier | ||
INTEGER(HID_T) :: dset_id ! Dataset identifier | ||
|
||
! | ||
!dataset name is "dset" | ||
! | ||
CHARACTER(LEN=4), PARAMETER :: dsetname = "dset" | ||
|
||
! | ||
!data space rank and dimensions | ||
! | ||
INTEGER, PARAMETER :: RANK = 2 | ||
INTEGER, PARAMETER :: NX = 4 | ||
INTEGER, PARAMETER :: NY = 6 | ||
|
||
! | ||
! data space identifier | ||
! | ||
INTEGER(HID_T) :: dataspace | ||
|
||
! | ||
!The dimensions for the dataset. | ||
! | ||
INTEGER(HSIZE_T), DIMENSION(2) :: dims = (/NX,NY/) | ||
|
||
! | ||
!flag to check operation success | ||
! | ||
INTEGER :: error | ||
|
||
! | ||
!Create file "filename.h5" 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 h5fcreate_f(fix_filename, H5F_ACC_TRUNC_F, file_id, error) | ||
CALL check("h5fcreate_f",error,total_error) | ||
|
||
! | ||
!Create data space for the dataset. | ||
! | ||
CALL h5screate_simple_f(RANK, dims, dataspace, error) | ||
CALL check("h5screate_simple_f",error,total_error) | ||
|
||
! | ||
!Create dataset "/dset" inside the file . | ||
! | ||
CALL h5dcreate_f(file_id, dsetname, H5T_NATIVE_INTEGER, dataspace, & | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would suggest simplifying this by just opening the root group "/" and using the group id instead of going through the trouble of creating a dataset. |
||
dset_id, error) | ||
CALL check("h5dcreate_f",error,total_error) | ||
|
||
CALL check_get_name(file_id, fix_filename, total_error) | ||
CALL check_get_name(dset_id, fix_filename, total_error) | ||
|
||
!Close the dataset. | ||
! | ||
CALL h5dclose_f(dset_id, error) | ||
CALL check("h5dclose_f",error,total_error) | ||
|
||
! | ||
!Close the file identifiers. | ||
! | ||
CALL h5fclose_f(file_id, error) | ||
CALL check("h5fclose_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 get_name_test | ||
|
||
! | ||
! The following example demonstrates how to get creation property list, | ||
! and access property list. | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, change the declaration (line 827):
CHARACTER(LEN=*), INTENT(OUT) :: buf
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed in new PR.