Skip to content

Commit

Permalink
Merge pull request #3170 from GEOS-ESM/feature/tclune/#3169-allow-dup…
Browse files Browse the repository at this point in the history
…licate-dimensions

Fixes #3169 - handle duplicate dimensions
  • Loading branch information
tclune authored Nov 11, 2024
2 parents 67074f4 + 37be22d commit d2f9b63
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
13 changes: 11 additions & 2 deletions pfio/FileMetadata.F90
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,20 @@ subroutine add_dimension(this, dim_name, extent, unusable, rc)
class (FileMetadata), target, intent(inout) :: this
character(len=*), intent(in) :: dim_name
integer, intent(in) :: extent

class (KeywordEnforcer), optional, intent(in) :: unusable
integer, optional, intent(out) :: rc

call this%dimensions%insert(dim_name, extent)
integer :: existing_extent

if (.not. this%has_dimension(dim_name)) then
call this%dimensions%insert(dim_name, extent)
_RETURN(_SUCCESS)
end if

! Otherwise verify consistency
existing_extent = this%get_dimension(dim_name)
_ASSERT(extent == existing_extent,'FileMetadata::add_dimension() - dimension already exists with different extent.')

_RETURN(_SUCCESS)
_UNUSED_DUMMY(unusable)
end subroutine add_dimension
Expand Down
20 changes: 20 additions & 0 deletions pfio/tests/Test_FileMetadata.pf
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,26 @@ contains

end subroutine test_get_dimension

@test
subroutine test_fail_add_existing_dim_with_mismatch()
type (FileMetadata) :: cf

call cf%add_dimension('x', 10)
call cf%add_dimension('x', 11)

@assertExceptionRaised('FileMetadata::add_dimension() - dimension already exists with different extent.')

end subroutine test_fail_add_existing_dim_with_mismatch

@test
subroutine test_add_duplicate_dimension()
type (FileMetadata) :: cf

call cf%add_dimension('x', 10)
call cf%add_dimension('x', 10)

end subroutine test_add_duplicate_dimension

@test
subroutine test_get_dimensions()
type (FileMetadata), target :: cf
Expand Down

0 comments on commit d2f9b63

Please sign in to comment.