From 2064ed80fd46e3db3040e413c5a145f20037d871 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Tue, 9 Oct 2018 15:15:08 +0200 Subject: [PATCH] more flexible file open routine --- src/HDF5_utilities.f90 | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/src/HDF5_utilities.f90 b/src/HDF5_utilities.f90 index f650ba850..9fdcc6f44 100644 --- a/src/HDF5_utilities.f90 +++ b/src/HDF5_utilities.f90 @@ -174,21 +174,37 @@ subroutine HDF5_closeJobFile() end subroutine HDF5_closeJobFile + !-------------------------------------------------------------------------------------------------- !> @brief open and initializes HDF5 output file !-------------------------------------------------------------------------------------------------- -integer(HID_T) function HDF5_openFile(filePath) - use hdf5 +integer(HID_T) function HDF5_openFile(filePath,mode) implicit none + character(len=*), intent(in) :: filePath + character, intent(in), optional :: mode + character :: m integer :: hdferr - character(len=*), intent(in) :: filePath - call h5fopen_f(filePath,H5F_ACC_RDONLY_F,HDF5_openFile,hdferr) - if (hdferr < 0) call IO_error(1_pInt,ext_msg='HDF5_openFile: h5fopen_f',el=hdferr) + if (present(mode)) then + m = mode + else + m = 'r' + endif + + if (m == 'w' .or. m == 'a') then + call h5fopen_f(filePath,H5F_ACC_RDWR_F,HDF5_openFile,hdferr) + if (hdferr < 0) call IO_error(1_pInt,ext_msg='HDF5_openFile: h5fopen_f (w/a)',el=hdferr) + elseif(m == 'r') then + call h5fopen_f(filePath,H5F_ACC_RDONLY_F,HDF5_openFile,hdferr) + if (hdferr < 0) call IO_error(1_pInt,ext_msg='HDF5_openFile: h5fopen_f (r)',el=hdferr) + else + call IO_error(1_pInt,ext_msg='HDF5_openFile: h5fopen_f unknown access mode',el=hdferr) + endif end function HDF5_openFile + !-------------------------------------------------------------------------------------------------- !> @brief close the opened HDF5 output file !--------------------------------------------------------------------------------------------------