From 497bf2c6455c6370041f69c22dbb973fe29d2e24 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Sat, 14 Aug 2021 20:44:59 +0200 Subject: [PATCH] avoid errors for empty datasets empty dataset cannot be chunked, but filters can only be applied to chunked datasets --- src/HDF5_utilities.f90 | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/HDF5_utilities.f90 b/src/HDF5_utilities.f90 index 30b877216..540ce6781 100644 --- a/src/HDF5_utilities.f90 +++ b/src/HDF5_utilities.f90 @@ -1970,20 +1970,22 @@ subroutine initialize_write(dset_id, filespace_id, memspace_id, plist_id, & call h5pcreate_f(H5P_DATASET_CREATE_F, dcpl, hdferr) if (hdferr < 0) error stop 'HDF5 error' - call h5pset_shuffle_f(dcpl, hdferr) - if (hdferr < 0) error stop 'HDF5 error' - call h5pset_Fletcher32_f(dcpl,hdferr) - if (hdferr < 0) error stop 'HDF5 error' - - if (product(totalShape) >= chunkSize*2_HSIZE_T) then - call h5pset_chunk_f(dcpl, size(totalShape), getChunks(totalShape,chunkSize), hdferr) + if (product(totalShape) > 0) then + call h5pset_shuffle_f(dcpl, hdferr) + if (hdferr < 0) error stop 'HDF5 error' + call h5pset_Fletcher32_f(dcpl,hdferr) if (hdferr < 0) error stop 'HDF5 error' - if (compression_possible) call h5pset_deflate_f(dcpl, 6, hdferr) - else - call h5pset_chunk_f(dcpl, size(totalShape), totalShape, hdferr) - endif - if (hdferr < 0) error stop 'HDF5 error' + if (product(totalShape) >= chunkSize*2_HSIZE_T) then + call h5pset_chunk_f(dcpl, size(totalShape), getChunks(totalShape,chunkSize), hdferr) + if (hdferr < 0) error stop 'HDF5 error' + if (compression_possible) call h5pset_deflate_f(dcpl, 6, hdferr) + else + call h5pset_chunk_f(dcpl, size(totalShape), totalShape, hdferr) + endif + if (hdferr < 0) error stop 'HDF5 error' + endif + !-------------------------------------------------------------------------------------------------- ! create dataspace in memory (local shape) and in file (global shape) call h5screate_simple_f(size(myShape), myShape, memspace_id, hdferr, myShape)