Commit f0bfa33b authored by aarograh's avatar aarograh Committed by Henderson, Shane
Browse files

Remove hdf5 group

Squash branch 'remove_hdf5_group' into 'master'

* Fix unused variables

* Add rmdir test

* Implement rmdir on HDF5 file type

<!-- Replace this a detailed description of changes -->
Implements HDF5FileType%rmdir() and test

**Developer Checklist:**
- [x] Have you done a self-review after creating the merge request?
- [x] Have you filled in the Merge Request information (title, description) thoroughly?
- [x] Have you updated the relevant tickets (if this MR is linked to any VERA-dev tickets)?
- [x] Have you addressed all suggested feedback and commented on it to let the reviewer know? (Do not resolve discussions that the reviewer started)

**Reviewer Checklist:**
- [x] Have you confirmed all discussions were adequately addressed and resolved them all?
- [x] Does it conform to formatting guidelines?
- [x] Are there adequate and clear comments?
- [x] Is the design clean and sensible?
- [x] Are the changes optimal/efficient?
- [x] Were sufficient DBC checks added?
- [x] Are there unit tests? (if necessary)
- [x] Is the MR description clear, including a link to the VERA-Dev issue if appropriate?

**PSM Checklist**
- [x] Have you confirmed that all discussions were addressed, or that follow-on issues have been created for them?
- [x] Have you confirmed sufficient testing was conducted?
- [x] Does this impact other repositories?
- [x] Does the MR have an adequate description?
- [x] If the MR has multiple commits, did you set the MR to squash merge?

See merge request https://code.ornl.gov/futility/Futility/-/merge_requests/408
parent b846ca04
Loading
Loading
Loading
Loading
+44 −0
Original line number Diff line number Diff line
@@ -126,6 +126,9 @@ TYPE,EXTENDS(BaseFileType) :: HDF5FileType
    !> @copybrief FileType_HDF5::mkdir_HDF5FileType
    !> @copydetails FileType_HDF5::mkdir_HDF5FileType
    PROCEDURE,PASS :: mkdir => mkdir_HDF5FileType
    !> @copybrief FileType_HDF5::rmdir_HDF5FileType
    !> @copydetails FileType_HDF5::rmdir_HDF5FileType
    PROCEDURE,PASS :: rmdir => rmdir_HDF5FileType
    !> @copybrief FileType_HDF5::mkalldir_HDF5FileType
    !> @copydetails FileType_HDF5::mkalldir_HDF5FileType
    PROCEDURE,PASS :: mkalldir => mkalldir_HDF5FileType
@@ -1093,6 +1096,47 @@ RECURSIVE SUBROUTINE mkdir_HDF5FileType(thisHDF5File,path)
ENDSUBROUTINE mkdir_HDF5FileType
!
!-------------------------------------------------------------------------------
!> @brief Removes a group in the HDF file.
!> @param thisHDF5File the HDF5FileType object to operate on
!> @param path the path to the group to be removed
!>
!> This routine is used to remove a group in an HDF5 file. It can only be
!> called if the file has write access.
!>
RECURSIVE SUBROUTINE rmdir_HDF5FileType(thisHDF5File,path)
  CLASS(HDF5FileType),INTENT(INOUT) :: thisHDF5File
  CHARACTER(LEN=*),INTENT(IN) :: path
#ifdef FUTILITY_HAVE_HDF5
  CHARACTER(LEN=*),PARAMETER :: myName='mkdir_HDF5FileType'
  TYPE(StringType) :: path2
  LOGICAL :: dset_exists

  REQUIRE(thisHDF5File%isinit)
  REQUIRE(thisHDF5File%isWrite())

  IF(.NOT.thisHDF5File%isOpen()) CALL thisHDF5File%fopen()
  ! Convert the path to use slashes
  path2=convertPath(path)
  CALL h5lexists_f(thisHDF5File%file_id,CHAR(path2),dset_exists,error)
  IF(error /= 0) CALL thisHDF5File%e%raiseError(modName//'::'//myName// &
      ' - invalid group path: '//path)

  IF(.NOT.dset_exists) THEN
    ! If group exists, do nothing, but only if overwrites are allowed
    RETURN
  ENDIF

  ! Create the group
  CALL h5ldelete_f(thisHDF5File%file_id,CHAR(path2),error)

  IF(error /= 0) THEN
    CALL thisHDF5File%e%raiseDebug(modName//'::'//myName// &
        ' - Failed to delete HDF5 group.')
  ENDIF
#endif
ENDSUBROUTINE rmdir_HDF5FileType
!
!-------------------------------------------------------------------------------
!> @brief Creates a new group in the HDF file.
!> @param thisHDF5File the HDF5FileType object to operate on
!> @param path the path to the group to be created
+13 −0
Original line number Diff line number Diff line
@@ -367,6 +367,19 @@ SUBROUTINE testHDF5FileTypeCreateDelete()
  INQUIRE(FILE='createdeletetest.h5',EXIST=exists)
  ASSERT(.NOT.exists,'HDF5 object not properly deleted after begin cleared.')

  CALL h5%init('rmdirtest.h5','NEW')
  CALL h5%fopen()
  IF(h5%isInit) exists=.TRUE.
  CALL h5%mkdir('testGroup')
  exists = h5%pathExists('testGroup')
  ASSERT(exists,'HDF5 object properly created.')
  CALL h5%rmdir('testGroup')
  exists = h5%pathExists('testGroup')
  ASSERT(.NOT.exists,'HDF5 object not properly deleted.')
  CALL h5%clear(LDEL=.TRUE.)
  INQUIRE(FILE='rmdirtest.h5',EXIST=exists)
  ASSERT(.NOT.exists,'HDF5 object not properly deleted after begin cleared.')

ENDSUBROUTINE testHDF5FileTypeCreateDelete
!
!-------------------------------------------------------------------------------