Loading src/FileType_HDF5.f90 +44 −0 Original line number Diff line number Diff line Loading @@ -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 Loading Loading @@ -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 Loading unit_tests/testHDF5FileType/testHDF5FileType.f90 +13 −0 Original line number Diff line number Diff line Loading @@ -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 ! !------------------------------------------------------------------------------- Loading Loading
src/FileType_HDF5.f90 +44 −0 Original line number Diff line number Diff line Loading @@ -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 Loading Loading @@ -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 Loading
unit_tests/testHDF5FileType/testHDF5FileType.f90 +13 −0 Original line number Diff line number Diff line Loading @@ -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 ! !------------------------------------------------------------------------------- Loading