diff --git a/src/h5core/h5_attribs.c b/src/h5core/h5_attribs.c index 37a961a..a8446f7 100644 --- a/src/h5core/h5_attribs.c +++ b/src/h5core/h5_attribs.c @@ -180,7 +180,7 @@ h5_write_file_attrib ( attrib_type, attrib_value, attrib_nelem, - 1)); + !is_appendonly (f))); } h5_err_t @@ -209,11 +209,62 @@ h5_write_step_attrib ( attrib_type, attrib_value, attrib_nelem, - 1)); + !is_appendonly (f))); +} + +static inline h5_err_t +get_attrib_info ( + hid_t attrib_id, + h5_int64_t* attrib_type, /*!< OUT: H5 type of attribute */ + h5_size_t* attrib_nelem /*!< OUT: number of elements */ + ) { + H5_INLINE_FUNC_ENTER (h5_err_t); + hid_t mytype; + TRY (mytype = hdf5_get_attribute_type (attrib_id)); + + H5T_class_t type_class; + TRY (type_class = hdf5_get_class_type (mytype)); + + if (attrib_nelem) { + if (type_class == H5T_STRING) { + *attrib_nelem = H5Tget_size(mytype); + } else { + hid_t space_id; + TRY (space_id = hdf5_get_attribute_dataspace (attrib_id)); + TRY (*attrib_nelem = hdf5_get_npoints_of_dataspace (space_id)); + TRY (hdf5_close_dataspace (space_id)); + } + } + if (attrib_type) { + TRY (*attrib_type = h5priv_normalize_h5_type (mytype)); + } + TRY (hdf5_close_type (mytype)); + TRY (hdf5_close_attribute (attrib_id)); + H5_INLINE_FUNC_RETURN (H5_SUCCESS); } h5_err_t -h5priv_get_attrib_info ( +h5priv_get_attrib_info_by_name ( + const hid_t id, /*!< IN: HDF5 object ID */ + const char* const attrib_name, /*!< IN: name of attribute */ + h5_int64_t* attrib_type, /*!< OUT: H5 type of attribute */ + h5_size_t* attrib_nelem /*!< OUT: number of elements */ + ) { + H5_PRIV_API_ENTER (h5_err_t, + "id=%d, " + "attrib_name=%s," + "attrib_type=%p, attrib_nelem=%p", + id, + attrib_name, + attrib_type, + attrib_nelem); + hid_t attrib_id; + TRY (attrib_id = hdf5_open_attribute (id, attrib_name)); + H5_PRIV_API_RETURN (get_attrib_info (attrib_id, attrib_type, attrib_nelem)); +} + +h5_err_t +h5priv_get_attrib_info_by_idx ( const hid_t id, /*!< HDF5 object ID */ const h5_size_t attrib_idx, /*!< index of attribute */ char* attrib_name, /*!< OUT: name of attribute */ @@ -233,30 +284,17 @@ h5priv_get_attrib_info ( attrib_type, attrib_nelem); hid_t attrib_id; - hid_t mytype; - hid_t space_id; TRY (attrib_id = hdf5_open_attribute_idx ( id, (unsigned int)attrib_idx)); - if (attrib_nelem) { - TRY (space_id = hdf5_get_attribute_dataspace (attrib_id)); - TRY (*attrib_nelem = hdf5_get_npoints_of_dataspace (space_id)); - TRY (hdf5_close_dataspace (space_id)); - } if (attrib_name) { TRY (hdf5_get_attribute_name ( attrib_id, (size_t)len_attrib_name, attrib_name)); } - if (attrib_type) { - TRY (mytype = hdf5_get_attribute_type (attrib_id)); - TRY (*attrib_type = h5priv_normalize_h5_type (mytype)); - TRY (hdf5_close_type (mytype)); - } - TRY (hdf5_close_attribute (attrib_id)); - H5_PRIV_API_RETURN (H5_SUCCESS); + H5_PRIV_API_RETURN (get_attrib_info (attrib_id, attrib_type, attrib_nelem)); } /*! @@ -267,7 +305,30 @@ h5priv_get_attrib_info ( \return \c H5_SUCCESS or error code. */ h5_err_t -h5_get_file_attrib_info ( +h5_get_file_attrib_info_by_name ( + const h5_file_t f_, /*!< IN: handle to open file */ + char* attrib_name, /*!< IN: name of attribute */ + h5_int64_t* attrib_type, /*!< OUT: H5 type of attribute */ + h5_size_t* attrib_nelem /*!< OUT: number of elements */ + ) { + h5_file_p f = (h5_file_p)f_; + H5_CORE_API_ENTER (h5_err_t, + "f=%p, " + "attrib_name=%s, " + "attrib_type=%p, attrib_nelem=%p", + f, + attrib_name, + attrib_type, + attrib_nelem); + CHECK_FILEHANDLE (f); + TRY (h5priv_get_attrib_info_by_name ( + f->root_gid, attrib_name, + attrib_type, attrib_nelem)); + H5_CORE_API_RETURN (H5_SUCCESS); +} + +h5_err_t +h5_get_file_attrib_info_by_idx ( const h5_file_t f_, /*!< handle to open file */ const h5_size_t attrib_idx, /*!< index of attribute */ char* attrib_name, /*!< OUT: name of attribute */ @@ -278,23 +339,46 @@ h5_get_file_attrib_info ( h5_file_p f = (h5_file_p)f_; H5_CORE_API_ENTER (h5_err_t, "f=%p, " - "attrib_idx=%llu, attrib_name=%p, len_attrib_name=%llu, " + "attrib_idx=%llu, " + "attrib_name=%p, len_attrib_name=%llu, " "attrib_type=%p, attrib_nelem=%p", f, (long long unsigned)attrib_idx, - attrib_name, - (long long unsigned)len_attrib_name, - attrib_type, - attrib_nelem); + attrib_name, (long long unsigned)len_attrib_name, + attrib_type, attrib_nelem); CHECK_FILEHANDLE (f); - TRY (h5priv_get_attrib_info ( + TRY (h5priv_get_attrib_info_by_idx ( f->root_gid, attrib_idx, attrib_name, len_attrib_name, attrib_type, attrib_nelem)); H5_CORE_API_RETURN (H5_SUCCESS); } h5_err_t -h5_get_step_attrib_info ( +h5_get_step_attrib_info_by_name ( + const h5_file_t f_, /*!< handle to open file */ + char* attrib_name, /*!< OUT: name of attribute */ + h5_int64_t* attrib_type, /*!< OUT: H5 type of attribute */ + h5_size_t* attrib_nelem /*!< OUT: number of elements */ + ) { + h5_file_p f = (h5_file_p)f_; + H5_CORE_API_ENTER (h5_err_t, + "f=%p, " + "attrib_name=%p, " + "attrib_type=%p, attrib_nelem=%p", + f, + attrib_name, + attrib_type, attrib_nelem); + CHECK_FILEHANDLE (f); + CHECK_TIMEGROUP (f); + TRY (h5priv_get_attrib_info_by_name ( + f->step_gid, + attrib_name, + attrib_type, attrib_nelem)); + H5_CORE_API_RETURN (H5_SUCCESS); +} + +h5_err_t +h5_get_step_attrib_info_by_idx ( const h5_file_t f_, /*!< handle to open file */ const h5_size_t attrib_idx, /*!< index of attribute */ char* attrib_name, /*!< OUT: name of attribute */ @@ -315,7 +399,7 @@ h5_get_step_attrib_info ( attrib_nelem); CHECK_FILEHANDLE (f); CHECK_TIMEGROUP (f); - TRY (h5priv_get_attrib_info ( + TRY (h5priv_get_attrib_info_by_idx ( f->step_gid, attrib_idx, attrib_name, len_attrib_name, attrib_type, attrib_nelem)); H5_CORE_API_RETURN (H5_SUCCESS); diff --git a/src/h5core/h5_attribs_private.h b/src/h5core/h5_attribs_private.h index b990fb5..ba7bd2c 100644 --- a/src/h5core/h5_attribs_private.h +++ b/src/h5core/h5_attribs_private.h @@ -31,7 +31,15 @@ h5priv_write_attrib ( ); h5_err_t -h5priv_get_attrib_info ( +h5priv_get_attrib_info_by_name ( + const hid_t id, + const char* const attrib_name, + h5_int64_t* attrib_type, + h5_size_t* attrib_nelem + ); + +h5_err_t +h5priv_get_attrib_info_by_idx ( const hid_t id, const h5_size_t attrib_idx, char* attrib_name, diff --git a/src/h5core/h5_hdf5_private.h b/src/h5core/h5_hdf5_private.h index f50aab0..a069d67 100644 --- a/src/h5core/h5_hdf5_private.h +++ b/src/h5core/h5_hdf5_private.h @@ -853,6 +853,38 @@ hdf5_insert_type ( HDF5_WRAPPER_RETURN (H5_SUCCESS); } +static inline H5T_class_t +hdf5_get_class_type ( + hid_t dtype_id + ) { + HDF5_WRAPPER_ENTER (h5_err_t, "dtype_id=%d", dtype_id); + H5T_class_t class = H5Tget_class (dtype_id); + if (class < 0) + HDF5_WRAPPER_LEAVE ( + h5_error( + H5_ERR_HDF5, + "Can't determine class of type %d.", + dtype_id)); + HDF5_WRAPPER_RETURN (class); +} + +static inline h5_ssize_t +hdf5_get_sizeof_type ( + hid_t dtype_id + ) { + HDF5_WRAPPER_ENTER (h5_ssize_t, "dtype_id=%d", dtype_id); + h5_ssize_t size = H5Tget_size (dtype_id); + if (size == 0) { + HDF5_WRAPPER_LEAVE ( + h5_error( + H5_ERR_HDF5, + "Can't determine size of type %d.", + dtype_id)); + } + HDF5_WRAPPER_RETURN (size); +} + + static inline h5_err_t hdf5_close_type ( hid_t dtype_id diff --git a/src/h5core/h5b_attribs.c b/src/h5core/h5b_attribs.c index d4a1243..68de185 100644 --- a/src/h5core/h5b_attribs.c +++ b/src/h5core/h5b_attribs.c @@ -50,7 +50,7 @@ h5b_write_field_attrib ( attrib_type, attrib_value, attrib_nelem, - 1) ); + !is_appendonly (f)) ); H5_CORE_API_RETURN (H5_SUCCESS); } @@ -103,7 +103,7 @@ h5b_get_num_field_attribs ( } h5_err_t -h5b_get_field_attrib_info ( +h5b_get_field_attrib_info_by_idx ( const h5_file_t fh, /*!< IN: file handle */ const char *field_name, /*!< IN: field name */ const h5_size_t attrib_idx, /*!< IN: attribute index */ @@ -132,7 +132,7 @@ h5b_get_field_attrib_info ( TRY (h5bpriv_open_field_group(f, field_name)); H5_CORE_API_RETURN ( - h5priv_get_attrib_info ( + h5priv_get_attrib_info_by_idx ( f->b->field_gid, attrib_idx, attrib_name, diff --git a/src/include/H5Block_attribs.h b/src/include/H5Block_attribs.h index 7581798..5c2818c 100644 --- a/src/include/H5Block_attribs.h +++ b/src/include/H5Block_attribs.h @@ -77,7 +77,7 @@ H5BlockGetFieldAttribInfo ( attrib_type, attrib_nelem); H5_API_RETURN ( - h5b_get_field_attrib_info ( + h5b_get_field_attrib_info_by_idx ( f, field_name, attrib_idx, diff --git a/src/include/H5_attribs.h b/src/include/H5_attribs.h index 8e76b58..bb82a4a 100644 --- a/src/include/H5_attribs.h +++ b/src/include/H5_attribs.h @@ -317,7 +317,7 @@ H5ReadFileAttribString ( */ static inline h5_err_t H5ReadStepAttribString ( - const h5_file_t f, ///< [in] file handle. + const h5_file_t f, ///< [in] file handle. const char *name, ///< [in] name of attribute to create. char *buffer ///< [out] value of attribute. ) { @@ -560,6 +560,34 @@ H5GetNumStepAttribs ( H5_API_RETURN (h5_get_num_step_attribs (f)); } +/*! + \ingroup h5hut_attrib + + Get the type and number of elements of the file attribute + specified by its name. + + \return \c H5_SUCCESS or \c H5_FAILURE. +*/ + +static inline h5_err_t +H5GetFileAttribInfoByName ( + const h5_file_t f, ///< [in] file handle. + const char* const name, ///< [in] name of attribute. + h5_int64_t* type, ///< [out] type of value.. + h5_size_t* nelems ///< [out] number of elements. + ) { + H5_API_ENTER (h5_err_t, + "f=%p, " + "name=%s, " + "type=%p, nelems=%p", + (h5_file_p)f, + name, + type, nelems); + H5_API_RETURN (h5_get_file_attrib_info_by_name ( + f, + name, + type, nelems)); +} /*! \ingroup h5hut_attrib @@ -594,7 +622,7 @@ H5GetFileAttribInfo ( (long long unsigned)len_name, type, nelems); - H5_API_RETURN (h5_get_file_attrib_info ( + H5_API_RETURN (h5_get_file_attrib_info_by_idx ( f, idx, name, len_name, @@ -602,6 +630,34 @@ H5GetFileAttribInfo ( nelems)); } +/*! + \ingroup h5hut_attrib + + Gets the type and number of elements of the step attribute + specified by its name. + + \return \c H5_SUCCESS or \c H5_FAILURE. +*/ +static inline h5_err_t +H5GetStepAttribInfoByName ( + const h5_file_t f, ///< [in] file handle. + const char* const name, ///< [in] name of attribute. + h5_int64_t* type, ///< [out] type of value.. + h5_size_t* nelems ///< [out] number of elements. + ) { + H5_API_ENTER (h5_err_t, + "f=%p, " + "name=%s, " + "type=%p, nelems=%p", + (h5_file_p)f, + name, + type, nelems); + H5_API_RETURN (h5_get_step_attrib_info_by_name ( + f, + name, + type, nelems)); +} + /*! \ingroup h5hut_attrib @@ -634,7 +690,7 @@ H5GetStepAttribInfo ( (long long unsigned)len_name, type, nelems); - H5_API_RETURN (h5_get_step_attrib_info ( + H5_API_RETURN (h5_get_step_attrib_info_by_idx ( f, idx, name, diff --git a/src/include/h5core/h5_attribs.h b/src/include/h5core/h5_attribs.h index 8fd752c..8d5b1cd 100644 --- a/src/include/h5core/h5_attribs.h +++ b/src/include/h5core/h5_attribs.h @@ -33,12 +33,20 @@ h5_write_step_attrib ( const h5_file_t, const char*, const hid_t, const void*, const hsize_t); h5_err_t -h5_get_file_attrib_info ( +h5_get_file_attrib_info_by_name ( + const h5_file_t, const char* const, h5_int64_t* const, h5_size_t*); + +h5_err_t +h5_get_file_attrib_info_by_idx ( const h5_file_t, const h5_size_t, char*, const h5_size_t, h5_int64_t* const, h5_size_t*); h5_err_t -h5_get_step_attrib_info ( +h5_get_step_attrib_info_by_name ( + const h5_file_t, const char* const, h5_int64_t*, h5_size_t*); + +h5_err_t +h5_get_step_attrib_info_by_idx ( const h5_file_t, const h5_size_t, char*, const h5_size_t, h5_int64_t*, h5_size_t*); diff --git a/src/include/h5core/h5b_attribs.h b/src/include/h5core/h5b_attribs.h index d9dc6e3..c47feb4 100644 --- a/src/include/h5core/h5b_attribs.h +++ b/src/include/h5core/h5b_attribs.h @@ -32,7 +32,7 @@ h5b_get_num_field_attribs ( const char*); h5_err_t -h5b_get_field_attrib_info ( +h5b_get_field_attrib_info_by_idx ( const h5_file_t, const char*, const h5_size_t, char* const, const h5_size_t, h5_int64_t* const, h5_size_t*);