From 3d6230629c95e9651545d0dc7d6e7de65b2ed0cc Mon Sep 17 00:00:00 2001 From: Achim Gsell Date: Fri, 22 Apr 2016 18:06:58 +0200 Subject: [PATCH] some missing query function implemented, see issue#1 in Gitlab --- src/h5core/h5_attach.c | 79 ++++++++++++++++------------------ src/h5core/h5_openclose.c | 17 +++++--- src/h5core/h5u_model.c | 19 +++++++- src/include/H5Part_io.h | 55 +++++++++++++++++++++++ src/include/H5_model.h | 18 ++++++++ src/include/h5core/h5_model.h | 8 ++++ src/include/h5core/h5_types.h | 11 +++++ src/include/h5core/h5u_model.h | 8 +++- 8 files changed, 166 insertions(+), 49 deletions(-) diff --git a/src/h5core/h5_attach.c b/src/h5core/h5_attach.c index 9247749..4beb3fb 100644 --- a/src/h5core/h5_attach.c +++ b/src/h5core/h5_attach.c @@ -127,19 +127,15 @@ h5_add_attachment ( H5_CORE_API_RETURN (H5_SUCCESS); } - - -static inline hid_t -open_attachments ( - const h5_file_p f +h5_err_t +h5_has_attachments ( + const h5_file_t f_ ) { - h5_err_t exists = hdf5_link_exists (f->file, H5_ATTACHMENT); - if (exists > 0) { - return hdf5_open_group (f->file, H5_ATTACHMENT); - } else if (exists == 0) { - return h5_warn ("No attachment group in file"); - } - return exists; + h5_file_p f = (h5_file_p)f_; + H5_CORE_API_ENTER (h5_ssize_t, "f=%p", f); + h5_err_t exists; + TRY (exists = hdf5_link_exists (f->file, H5_ATTACHMENT)); + H5_CORE_API_RETURN (exists); } h5_ssize_t @@ -148,12 +144,14 @@ h5_get_num_attachments ( ) { h5_file_p f = (h5_file_p)f_; H5_CORE_API_ENTER (h5_ssize_t, "f=%p", f); - h5_ssize_t num = 0; - hid_t group_id; - TRY (group_id = open_attachments (f)); - if (group_id < 0) { - H5_CORE_API_LEAVE (0); + h5_err_t exists; + TRY (exists = hdf5_link_exists (f->file, H5_ATTACHMENT)); + if (exists == 0) { + return 0; } + hid_t group_id; + TRY (group_id = hdf5_open_group (f->file, H5_ATTACHMENT)); + h5_ssize_t num = 0; TRY (num = hdf5_get_num_datasets (group_id)); TRY (hdf5_close_group (group_id)); H5_CORE_API_RETURN (num); @@ -170,13 +168,11 @@ h5_get_attachment_info_by_idx ( h5_file_p f = (h5_file_p)f_; H5_CORE_API_ENTER (h5_err_t, "f=%p, idx=%llu, fname=%s, len_fname=%llu, fsize=%p", - f, (unsigned long long)idx, fname, (unsigned long long)len_fname, + f, (unsigned long long)idx, + fname, (unsigned long long)len_fname, fsize); hid_t loc_id; - TRY (loc_id = open_attachments (f)); - if (loc_id < 0) { // no attachment group in file - H5_CORE_API_LEAVE (0); - } + TRY (loc_id = hdf5_open_group (f->file, H5_ATTACHMENT)); TRY (hdf5_get_name_of_dataset_by_idx ( loc_id, idx, @@ -192,6 +188,20 @@ h5_get_attachment_info_by_idx ( H5_CORE_API_RETURN (H5_SUCCESS); } +h5_err_t +h5_has_attachment ( + const h5_file_t f_, // [in] + const char* const fname // [in] + ) { + h5_file_p f = (h5_file_p)f_; + H5_CORE_API_ENTER (h5_err_t, "f=%p, fname='%s'", f, fname); + hid_t loc_id; + TRY (loc_id = hdf5_open_group (f->file, H5_ATTACHMENT)); + h5_err_t exists; + TRY (exists = hdf5_link_exists (f->file, fname)); + H5_CORE_API_RETURN (exists); +} + h5_err_t h5_get_attachment_info_by_name ( const h5_file_t f_, @@ -202,10 +212,7 @@ h5_get_attachment_info_by_name ( H5_CORE_API_ENTER (h5_err_t, "f=%p, fname='%s', fsize=%p", f, fname, fsize); hid_t loc_id; - TRY (loc_id = open_attachments (f)); - if (loc_id < 0) { - H5_CORE_API_LEAVE (H5_NOK); - } + TRY (loc_id = hdf5_open_group (f->file, H5_ATTACHMENT)); if (fsize) { // get number of elements, do not change value on error h5_ssize_t ssize; @@ -232,14 +239,6 @@ h5_get_attachment ( hid_t loc_id; TRY (loc_id = hdf5_open_group (f->file, H5_ATTACHMENT)); - h5_err_t exists; - TRY (exists = hdf5_link_exists (loc_id, fname)); - if (!exists) { - H5_PRIV_FUNC_LEAVE ( - h5_error ( - H5_ERR_H5, - "Attachment '%s' doesn't exist", fname)); - } // read dataset hid_t dataset_id, diskspace_id; @@ -320,12 +319,10 @@ h5_delete_attachment ( ) { h5_file_p f = (h5_file_p)f_; H5_CORE_API_ENTER (h5_err_t, "f=%p, fname='%s'", f, fname); - hid_t group_id; - TRY (group_id = open_attachments (f)); - if (group_id < 0) { - H5_CORE_API_LEAVE (H5_NOK); - } - TRY (hdf5_delete_link (group_id, fname, H5P_DEFAULT)); - TRY (hdf5_close_group (group_id)); + + hid_t loc_id; + TRY (loc_id = hdf5_open_group (f->file, H5_ATTACHMENT)); + TRY (hdf5_delete_link (loc_id, fname, H5P_DEFAULT)); + TRY (hdf5_close_group (loc_id)); H5_CORE_API_RETURN (H5_SUCCESS); } diff --git a/src/h5core/h5_openclose.c b/src/h5core/h5_openclose.c index dc941cb..0e0f0e5 100644 --- a/src/h5core/h5_openclose.c +++ b/src/h5core/h5_openclose.c @@ -97,7 +97,7 @@ mpi_init ( TRY (hdf5_set_dxpl_mpio_property (f->props->xfer_prop, H5FD_MPIO_INDEPENDENT) ); } else { - // default is MPI-IO colloctive mode + // default is MPI-IO collective mode h5_info("Selecting MPI-IO VFD, using collective mode"); TRY (hdf5_set_fapl_mpio_property (f->props->access_prop, f->props->comm, MPI_INFO_NULL)); @@ -117,7 +117,7 @@ mpi_init ( TRY (hdf5_set_dxpl_mpio_property (f->props->xfer_prop, H5FD_MPIO_INDEPENDENT) ); } else { - // default is MPI-IO colloctive mode + // default is MPI-IO collective mode h5_info("Selecting MPI-IO VFD, using collective mode"); TRY (hdf5_set_fapl_mpio_property (f->props->access_prop, f->props->comm, MPI_INFO_NULL)); @@ -717,7 +717,7 @@ h5_get_num_steps( /*! \ingroup h5_core_filehandling - Start traversing steps. + Start traversing steps. \return \c H5_SUCCESS or error code */ @@ -726,8 +726,15 @@ h5_start_traverse_steps ( const h5_file_t f_ /*!< file handle */ ) { h5_file_p f = (h5_file_p)f_; - UNUSED_ARGUMENT (f); - return h5_error_not_implemented (); + H5_CORE_API_ENTER (int, "f=%p", f); + + /* + fast test: Does Step#0 or Step#1 exist? + otherwise + loop over all steps and get smallest step number + */ + + H5_CORE_API_RETURN (h5_error_not_implemented ()); } /*! diff --git a/src/h5core/h5u_model.c b/src/h5core/h5u_model.c index 882cdf6..39d8661 100644 --- a/src/h5core/h5u_model.c +++ b/src/h5core/h5u_model.c @@ -600,19 +600,34 @@ h5u_get_dataset_info ( dataset_name, len_dataset_name) ); H5_CORE_API_RETURN ( - h5u_get_dataset_info_by_name(f, dataset_name, type, nelem)); + h5u_get_dataset_info_by_name(fh, dataset_name, type, nelem)); } +h5_err_t +h5u_has_dataset ( + const h5_file_t fh, + const char* const name + ) { + h5_file_p f = (h5_file_p)fh; + H5_CORE_API_ENTER (h5_err_t, + "f=%p, name='%s'", + f, name); + h5_err_t exists; + TRY (exists = hdf5_link_exists (f->step_gid, name)); + H5_CORE_API_RETURN (exists); +} + /*! Get information about dataset in current index given by its index */ h5_err_t h5u_get_dataset_info_by_name ( - const h5_file_p f, /*!< [in] Handle to open file */ + const h5_file_t fh, /*!< [in] Handle to open file */ const char* const dataset_name, /*!< [in] Name of dataset */ h5_int64_t* const type, /*!< [out] Type of data in dataset */ h5_size_t* const nelem /*!< [out] Number of elements. */ ) { + h5_file_p f = (h5_file_p)fh; H5_CORE_API_ENTER (h5_err_t, "f=%p, " "dataset_name='%s', " diff --git a/src/include/H5Part_io.h b/src/include/H5Part_io.h index 5eff1e1..4509606 100644 --- a/src/include/H5Part_io.h +++ b/src/include/H5Part_io.h @@ -88,6 +88,9 @@ H5PartGetDatasetName ( \return \c H5_SUCCESS on success \return \c H5_FAILURE on error + + \see H5PartGetNumDatasets() + \see H5PartGetDatasetInfoByName() */ static inline h5_err_t H5PartGetDatasetInfo ( @@ -110,6 +113,58 @@ H5PartGetDatasetInfo ( H5_API_RETURN (h5u_get_dataset_info ( f, idx, name, len_name, type, nelems)); } +/** + Determines whether a dataset with given name exists in current step. + + \return true (value \c >0) if step exists + \return false (\c 0) if step does not exist + \return \c H5_FAILURE on error +*/ +static inline h5_err_t +H5PartHasDataset ( + const h5_file_t f, ///< [in] file handle + const char* const name ///< [in] name of dataset + ) { + H5_API_ENTER (h5_int64_t, + "f=%p, name='%s'", + (h5_file_p)f, name); + H5_API_RETURN (h5u_has_dataset (f, name)); +} + +/** + Gets the type and number of elements of a dataset based on its + name in the current timestep. + + Type is one of the following values: + + - \c H5_FLOAT64_T (for \c h5_float64_t) + - \c H5_FLOAT32_T (for \c h5_float32_t) + - \c H5_INT64_T (for \c h5_int64_t) + - \c H5_INT32_T (for \c h5_int32_t) + + \return \c H5_SUCCESS on success + \return \c H5_FAILURE on error + + \see H5PartHasDataset() + \see H5PartGetDatasetInfo() +*/ +static inline h5_err_t +H5PartGetDatasetInfoByName ( + const h5_file_t f, ///< [in] file handle + const char* const name, ///< [in] name of dataset + h5_int64_t* type, ///< [out] type of data in dataset + h5_size_t* nelems ///< [out] number of elements + ) { + H5_API_ENTER (h5_int64_t, + "f=%p, " + "name='%s', " + "type=%p, nelems=%p", + (h5_file_p)f, + name, + type, nelems); + H5_API_RETURN (h5u_get_dataset_info_by_name ( + f, name, type, nelems)); +} /** This function returns the number of particles in this processor's view, diff --git a/src/include/H5_model.h b/src/include/H5_model.h index 40c2b36..78952ef 100644 --- a/src/include/H5_model.h +++ b/src/include/H5_model.h @@ -235,6 +235,24 @@ H5GetAttachmentInfoByIdx ( f, idx, fname, len_fname, fsize)); } +/** + Query whether a particular attachment exists in the file. + + \return true (value \c >0) if attachment exists + \return false (\c 0) if attachment does not exist + \return \c H5_FAILURE on error +*/ +static inline h5_err_t +H5HasAttachment ( + const h5_file_t f, ///< [in] file handle. + const char* const fname ///< [in] original file name. + ) { + H5_API_ENTER (h5_err_t, + "f=%p, name='%s'", + (h5_file_p)f, fname); + H5_API_RETURN (h5_has_attachment (f, fname)); +} + /** Get size of attached file with name \c fname. diff --git a/src/include/h5core/h5_model.h b/src/include/h5core/h5_model.h index b5768e4..f938e4a 100644 --- a/src/include/h5core/h5_model.h +++ b/src/include/h5core/h5_model.h @@ -26,6 +26,14 @@ h5_err_t h5_add_attachment ( const h5_file_t, const char* const); +h5_err_t +h5_has_attachments ( + const h5_file_t); + +h5_err_t +h5_has_attachment ( + const h5_file_t, const char* const); + h5_ssize_t h5_get_num_attachments ( const h5_file_t); diff --git a/src/include/h5core/h5_types.h b/src/include/h5core/h5_types.h index d227575..db5c6da 100644 --- a/src/include/h5core/h5_types.h +++ b/src/include/h5core/h5_types.h @@ -142,6 +142,17 @@ typedef struct h5_glb_idxlist { h5_glb_idx_t items[1]; } h5_glb_idxlist_t; +enum h5_iterators { + step_iterator +}; + +struct h5_iterator; +typedef struct { + enum h5_iterators it_type; + h5_file_t file; + h5_int64_t (*iter)(struct h5_iterator*); +} h5_iterator_t; + struct h5_idxmap; typedef struct h5_idxmap h5_idxmap_t; diff --git a/src/include/h5core/h5u_model.h b/src/include/h5core/h5u_model.h index 4bc9e85..a4af277 100644 --- a/src/include/h5core/h5u_model.h +++ b/src/include/h5core/h5u_model.h @@ -75,9 +75,15 @@ h5u_get_dataset_info ( const h5_id_t, char* const, const h5_size_t, h5_int64_t* const, h5_size_t* const); +h5_err_t +h5u_has_dataset ( + const h5_file_t fh, + const char* const name + ); + h5_err_t h5u_get_dataset_info_by_name ( - const h5_file_p f, + const h5_file_t f, const char* const dataset_name, h5_int64_t* const type, h5_size_t* const nelem