Commit bdcc8f20 authored by gsell's avatar gsell
Browse files

this commits includes several changes which should have been done in

multiple steps:
- the functions for inquiring datasets and attributes do not return
  an HDF5 type any more but an enum of type h5_types_t. This change
  was required for the Python module.
- bugfix in reading attributes: See https://git.psi.ch/H5hut/src/issues/4
- several consts and macros have been moved from the public C-API to
  the core API
- more consitent file naming
- several 'private' function have been moved to their 'private' header
  files as 'static inline'.
- minor formatting changes
parent bbbaa6a2
Pipeline #7 skipped
......@@ -13,7 +13,7 @@ include_HEADERS = \
$(top_srcdir)/src/include/H5Part_model.h \
$(top_srcdir)/src/include/H5_attachments.h \
$(top_srcdir)/src/include/H5_debug.h \
$(top_srcdir)/src/include/H5_error.h \
$(top_srcdir)/src/include/H5_err.h \
$(top_srcdir)/src/include/H5_file.h \
$(top_srcdir)/src/include/H5_file_attribs.h \
$(top_srcdir)/src/include/H5_log.h \
......
......@@ -9,7 +9,6 @@
#include "h5_private.h"
#include "h5core/h5_init.h"
#include "h5core/h5_debug.h"
#include "h5core/h5_file.h"
......
......@@ -11,10 +11,10 @@
#include "h5core/h5_debug.h"
#include "h5core/h5b_attribs.h"
#define H5_R8_T H5_FLOAT64_T
#define H5_R4_T H5_FLOAT32_T
#define H5_I8_T H5_INT64_T
#define H5_I4_T H5_INT32_T
#define H5_R8_T H5_FLOAT64
#define H5_R4_T H5_FLOAT32
#define H5_I8_T H5_INT64
#define H5_I4_T H5_INT32
/*
__ _ _ _ ___ _ __ _ _
......@@ -163,7 +163,7 @@ h5bl_writefieldattrib_string (
f,
field_name, l_field_name,
attrib_name, l_attrib_name,
H5_STRING_T,
H5_STRING,
attrib_value2, strlen(attrib_value2)+1 );
free (attrib_value2);
H5_API_RETURN (h5err);
......@@ -193,7 +193,7 @@ h5bl_readfieldattrib_string (
f,
field_name, l_field_name,
attrib_name, l_attrib_name,
H5_STRING_T, attrib_value);
H5_STRING, attrib_value);
h5_strc2for (attrib_value, l_attrib_value);
H5_API_RETURN (h5err);
......
......@@ -189,7 +189,7 @@ h5pt_getdatasetname (
H5_API_ENTER (h5_int64_t,
"fh=%p, index=%lld, name='%s', l_name=%d",
(h5_file_p)f, (long long)*index, name, l_name);
h5_int64_t herr = h5u_get_dataset_info (
h5_int64_t herr = h5u_get_dataset_info_by_idx (
f, *index - 1, name, l_name, NULL, NULL );
h5_strc2for (name, l_name);
H5_API_RETURN (herr);
......@@ -217,7 +217,7 @@ h5pt_getdatasetinfo (
(h5_file_p)f,
(long long)*dataset_idx,
dataset_name, dataset_type, dataset_nelem);
h5_int64_t h5err = h5u_get_dataset_info (
h5_int64_t h5err = h5u_get_dataset_info_by_idx (
f,
*dataset_idx - 1,
dataset_name, l_dataset_name,
......
......@@ -160,7 +160,7 @@ h5_writefileattrib_string (
(h5_file_p)f, l_name, name, l_buffer, buffer);
char *buffer2 = h5_strdupfor2c (buffer, l_buffer);
h5_int64_t herr = write_file_attrib (
f, name, l_name, H5_STRING_T, buffer2, strlen(buffer2)+1 );
f, name, l_name, H5_STRING, buffer2, strlen(buffer2)+1 );
free (buffer2);
H5_API_RETURN (herr);
}
......@@ -180,7 +180,7 @@ h5_readfileattrib_string (
H5_API_ENTER (h5_int64_t,
"fh=%p, name='%.*s', buffer='%.*s'",
(h5_file_p)f, l_name, name, l_buffer, buffer);
h5_int64_t herr = read_file_attrib (f, name, l_name, H5_STRING_T, buffer);
h5_int64_t herr = read_file_attrib (f, name, l_name, H5_STRING, buffer);
h5_strc2for (buffer, l_buffer);
H5_API_RETURN (herr);
}
......@@ -203,7 +203,7 @@ h5_writefileattrib_r8 (
H5_API_RETURN (write_file_attrib(
f,
name, l_name,
H5_FLOAT64_T,
H5_FLOAT64,
buffer, (hsize_t)*nelem));
}
......@@ -224,7 +224,7 @@ h5_readfileattrib_r8 (
H5_API_RETURN (read_file_attrib(
f,
name, l_name,
H5_FLOAT64_T,
H5_FLOAT64,
(void*)buffer));
}
......@@ -246,7 +246,7 @@ h5_writefileattrib_r4 (
H5_API_RETURN (write_file_attrib(
f,
name, l_name,
H5_FLOAT32_T,
H5_FLOAT32,
buffer, (hsize_t)*nelem));
}
......@@ -267,7 +267,7 @@ h5_readfileattrib_r4 (
H5_API_RETURN (read_file_attrib(
f,
name, l_name,
H5_FLOAT32_T,
H5_FLOAT32,
buffer));
}
......@@ -289,7 +289,7 @@ h5_writefileattrib_i8 (
H5_API_RETURN (write_file_attrib(
f,
name, l_name,
H5_INT64_T,
H5T_NATIVE_INT64,
buffer, (hsize_t)*nelem));
}
......@@ -310,7 +310,7 @@ h5_readfileattrib_i8 (
H5_API_RETURN (read_file_attrib(
f,
name, l_name,
H5_INT64_T,
H5T_NATIVE_INT64,
buffer));
}
......@@ -332,7 +332,7 @@ h5_writefileattrib_i4 (
H5_API_RETURN (write_file_attrib(
f,
name, l_name,
H5_INT32_T,
H5T_NATIVE_INT32,
buffer, (hsize_t)*nelem));
}
......@@ -353,7 +353,7 @@ h5_readfileattrib_i4 (
H5_API_RETURN (read_file_attrib(
f,
name, l_name,
H5_INT32_T,
H5T_NATIVE_INT32,
buffer));
}
......@@ -508,7 +508,7 @@ h5_writestepattrib_string (
(h5_file_p)f, l_name, name, l_buffer, buffer);
char *buffer2 = h5_strdupfor2c (buffer, l_buffer);
h5_int64_t herr = write_step_attrib (
f, name, l_name, H5_STRING_T, buffer2, strlen(buffer2)+1 );
f, name, l_name, H5_STRING, buffer2, strlen(buffer2)+1 );
free (buffer2);
H5_API_RETURN (herr);
}
......@@ -528,7 +528,7 @@ h5_readstepattrib_string (
H5_API_ENTER (h5_int64_t,
"f=%p, name='%.*s', buffer='%.*s'",
(h5_file_p)f, l_name, name, l_buffer, buffer);
h5_int64_t herr = read_step_attrib (f, name, l_name, H5_STRING_T, buffer);
h5_int64_t herr = read_step_attrib (f, name, l_name, H5_STRING, buffer);
h5_strc2for (buffer, l_buffer);
H5_API_RETURN (herr);
}
......@@ -551,7 +551,7 @@ h5_writestepattrib_r8 (
H5_API_RETURN (write_step_attrib(
f,
name, l_name,
H5_FLOAT64_T,
H5_FLOAT64,
buffer, (hsize_t)*nelem));
}
......@@ -572,7 +572,7 @@ h5_readstepattrib_r8 (
H5_API_RETURN (read_step_attrib(
f,
name, l_name,
H5_FLOAT64_T,
H5_FLOAT64,
(void*)buffer));
}
......@@ -594,7 +594,7 @@ h5_writestepattrib_r4 (
H5_API_RETURN (write_step_attrib(
f,
name, l_name,
H5_FLOAT32_T,
H5_FLOAT32,
buffer, (hsize_t)*nelem));
}
......@@ -615,7 +615,7 @@ h5_readstepattrib_r4 (
H5_API_RETURN (read_step_attrib(
f,
name, l_name,
H5_FLOAT32_T,
H5_FLOAT32,
buffer));
}
......@@ -637,7 +637,7 @@ h5_writestepattrib_i8 (
H5_API_RETURN (write_step_attrib(
f,
name, l_name,
H5_INT64_T,
H5T_NATIVE_INT64,
buffer, (hsize_t)*nelem));
}
......@@ -658,7 +658,7 @@ h5_readstepattrib_i8 (
H5_API_RETURN (read_step_attrib(
f,
name, l_name,
H5_INT64_T,
H5T_NATIVE_INT64,
buffer));
}
......@@ -680,7 +680,7 @@ h5_writestepattrib_i4 (
H5_API_RETURN (write_step_attrib(
f,
name, l_name,
H5_INT32_T,
H5T_NATIVE_INT32,
buffer, (hsize_t)*nelem));
}
......@@ -701,6 +701,6 @@ h5_readstepattrib_i4 (
H5_API_RETURN (read_step_attrib(
f,
name, l_name,
H5_INT32_T,
H5T_NATIVE_INT32,
buffer));
}
......@@ -9,7 +9,6 @@
#include "h5_private.h"
#include "h5core/h5_init.h"
#include "h5core/h5_debug.h"
#include "h5core/h5_model.h"
......
......@@ -10,7 +10,7 @@ F90_FILES = \
$(top_srcdir)/src/include/H5_file_attribs.f90 \
$(top_srcdir)/src/include/H5_step_attribs.f90 \
$(top_srcdir)/src/include/H5_debug.f90 \
$(top_srcdir)/src/include/H5_error.f90 \
$(top_srcdir)/src/include/H5_err.f90 \
$(top_srcdir)/src/include/H5_log.f90 \
$(top_srcdir)/src/include/H5Part_model.f90 \
$(top_srcdir)/src/include/H5Part_io.f90 \
......
/*
Copyright (c) 2006-2015, The Regents of the University of California,
Copyright (c) 2006-2016, The Regents of the University of California,
through Lawrence Berkeley National Laboratory (subject to receipt of any
required approvals from the U.S. Dept. of Energy) and the Paul Scherrer
Institut (Switzerland). All rights reserved.
......@@ -13,7 +13,7 @@
#include <stdlib.h>
#include <string.h>
#include "h5core/h5_init.h"
#include "h5core/h5_types.h"
#if defined(FC_MANGLING_LOWERCASE_NO_UNDERSCORE)
# define FC_MANGLING(a,b) a
......@@ -31,23 +31,23 @@
# error "Unknown Fortran symbol mangling"
#endif
#define convert_type2for(type) \
if (*type == H5_STRING_T) { \
*type = 1; \
} else if (*type == H5_INT16_T) { \
*type = 2; \
} else if (*type == H5_INT32_T) { \
*type = 3; \
} else if (*type == H5_INT64_T) { \
*type = 4; \
} else if (*type == H5_FLOAT32_T) { \
*type = 5; \
} else if (*type == H5_FLOAT64_T) { \
*type = 6; \
} else { \
H5_API_LEAVE ( \
h5_error ( \
H5_ERR_H5, \
#define convert_type2for(type) \
if (*type == H5_STRING) { \
*type = 1; \
} else if (*type == H5_INT16) { \
*type = 2; \
} else if (*type == H5_INT32) { \
*type = 3; \
} else if (*type == H5_INT64) { \
*type = 4; \
} else if (*type == H5_FLOAT32) { \
*type = 5; \
} else if (*type == H5_FLOAT64) { \
*type = 6; \
} else { \
H5_API_LEAVE ( \
h5_error ( \
H5_ERR_H5, \
"Unknown attribute type")); \
}
......
......@@ -3,6 +3,7 @@ AUTOMAKE_OPTIONS = subdir-objects
AM_CPPFLAGS = -I$(top_srcdir)/src/include @AM_CPPFLAGS@
EXTRA_HEADERS = \
private/h5_file.h \
private/h5_hdf5.h \
private/h5_hsearch.h \
private/h5_init.h \
......@@ -10,7 +11,6 @@ EXTRA_HEADERS = \
private/h5_maps.h \
private/h5_model.h \
private/h5_mpi.h \
private/h5.h \
private/h5_qsort.h \
private/h5_io.h \
private/h5_types.h \
......@@ -21,7 +21,7 @@ EXTRA_HEADERS = \
private/h5t_access.h \
private/h5t_adjacencies.h \
private/h5t_core.h \
private/h5t_errorhandling.h \
private/h5t_err.h \
private/h5t_map.h \
private/h5t_model.h \
private/h5t_octree.h \
......@@ -35,7 +35,7 @@ EXTRA_HEADERS = \
private/h5u_types.h \
private/h5_attribs.h \
private/h5_debug.h \
private/h5_errorhandling.h \
private/h5_err.h \
private/h5_fcmp.h
# Extra files that I wish to include in the dist tar ball.
......
......@@ -7,15 +7,16 @@
License: see file COPYING in top level of source distribution.
*/
#include "h5core/h5_init.h"
#include "private/h5_types.h"
#include "private/h5_errorhandling.h"
#include "private/h5_err.h"
#include "private/h5_hdf5.h"
#include "private/h5_model.h"
#include "h5core/h5_syscall.h"
#include "private/h5_va_macros.h"
#include "h5core/h5_file.h"
#include <string.h>
#include <sys/stat.h>
#include <unistd.h>
......@@ -133,9 +134,8 @@ h5_has_attachments (
) {
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);
TRY (ret_value = hdf5_link_exists (f->file, H5_ATTACHMENT));
H5_CORE_API_RETURN (ret_value);
}
h5_ssize_t
......@@ -151,10 +151,9 @@ h5_get_num_attachments (
}
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 (ret_value = hdf5_get_num_datasets (group_id));
TRY (hdf5_close_group (group_id));
H5_CORE_API_RETURN (num);
H5_CORE_API_RETURN (ret_value);
}
h5_err_t
......@@ -197,9 +196,8 @@ h5_has_attachment (
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);
TRY (ret_value = hdf5_link_exists (f->file, fname));
H5_CORE_API_RETURN (ret_value);
}
h5_err_t
......@@ -243,7 +241,7 @@ h5_get_attachment (
// read dataset
hid_t dataset_id, diskspace_id;
h5_ssize_t fsize;
TRY (dataset_id = hdf5_open_dataset (loc_id, fname));
TRY (dataset_id = hdf5_open_dataset_by_name (loc_id, fname));
TRY (diskspace_id = hdf5_get_dataset_space (dataset_id));
TRY (fsize = hdf5_get_npoints_of_dataspace (diskspace_id));
......
......@@ -7,145 +7,12 @@
License: see file COPYING in top level of source distribution.
*/
#include "h5core/h5_init.h"
#include "h5core/h5_debug.h"
#include "private/h5_types.h"
#include "private/h5.h"
#include "private/h5_io.h"
#include "private/h5_hdf5.h"
#include "private/h5_attribs.h"
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 */
const h5_size_t len_attrib_name,/*!< buffer length */
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=%lld, "
"attrib_idx=%llu, "
"attrib_name=%p, len_attrib_name=%llu, "
"attrib_type=%p, attrib_nelem=%p",
(long long int)id,
(long long unsigned)attrib_idx,
attrib_name,
(long long unsigned)len_attrib_name,
attrib_type,
attrib_nelem);
hid_t attrib_id;
TRY (attrib_id = hdf5_open_attribute_idx (
id,
(unsigned int)attrib_idx));
if (attrib_name) {
TRY (hdf5_get_attribute_name (
attrib_id,
(size_t)len_attrib_name,
attrib_name));
}
H5_PRIV_API_RETURN (get_attrib_info (attrib_id, attrib_type, attrib_nelem));
}
h5_err_t
h5priv_read_attrib (
const hid_t id, /*!< HDF5 object ID */
const char* attrib_name, /*!< name of HDF5 attribute to read */
const hid_t attrib_type, /*!< HDF5 type of attribute */
void* const attrib_value /*!< OUT: attribute value */
) {
H5_PRIV_API_ENTER (h5_err_t,
"id=%lld, attrib_name='%s', attrib_type=%lld, attrib_value=%p",
(long long int)id,
attrib_name,
(long long int)attrib_type,
attrib_value);
hid_t attrib_id;
hid_t type_id;
hid_t space_id;
TRY (attrib_id = hdf5_open_attribute (id, attrib_name));
TRY (type_id = hdf5_get_attribute_type (attrib_id));
hid_t h5type_id;
TRY (h5type_id = h5priv_normalize_h5_type (type_id));
if (h5type_id != attrib_type)
H5_PRIV_API_LEAVE (
h5_error (
H5_ERR_HDF5,
"Attribute '%s' has type '%s' but was requested as '%s'.",
attrib_name,
hdf5_get_type_name (h5type_id),
hdf5_get_type_name (attrib_type)));
TRY (space_id = hdf5_get_attribute_dataspace (attrib_id));
TRY (hdf5_read_attribute (attrib_id, type_id, attrib_value));
TRY (hdf5_close_dataspace(space_id));
TRY (hdf5_close_type (type_id));
TRY (hdf5_close_attribute (attrib_id));
H5_PRIV_API_RETURN (H5_SUCCESS);
}
h5_err_t
h5priv_write_attrib (
const hid_t id, /*!< HDF5 object ID */
const char* attrib_name, /*!< name of HDF5 attribute to write */
const hid_t attrib_type, /*!< HDF5 type of attribute */
const void* attrib_value, /*!< value of attribute */
const hsize_t attrib_nelem, /*!< number of elements (dimension) */
const int overwrite
) {
H5_PRIV_API_ENTER (h5_err_t,
"id=%lld, attrib_name='%s', attrib_type=%lld, "
"attrib_value=%p, attrib_nelem=%llu, overwrite=%d",
(long long int)id,
attrib_name,
(long long int)attrib_type,
attrib_value,
attrib_nelem,
overwrite);
hid_t space_id;
hid_t attrib_id;
hid_t type_id;
if ( attrib_type == H5T_NATIVE_CHAR ) {
TRY (type_id = hdf5_create_string_type (attrib_nelem));
TRY (space_id = hdf5_create_dataspace_scalar ());
} else {
type_id = attrib_type;
TRY (space_id = hdf5_create_dataspace (1, &attrib_nelem, NULL));
}
h5_err_t exists;
TRY (exists = hdf5_attribute_exists (id, attrib_name));
if (exists) {
if (overwrite) {
TRY (hdf5_delete_attribute (id, attrib_name));
} else {
H5_PRIV_API_LEAVE (
h5_error (H5_ERR_H5, "Cannot overwrite attribute %s/%s",
hdf5_get_objname (id), attrib_name));
}
}
TRY (attrib_id = hdf5_create_attribute (
id,
attrib_name,
type_id,
space_id,
H5P_DEFAULT, H5P_DEFAULT));
TRY (hdf5_write_attribute (attrib_id, type_id, attrib_value));
TRY (hdf5_close_attribute (attrib_id));
TRY (hdf5_close_dataspace (space_id));
if (attrib_type == H5T_NATIVE_CHAR)
TRY (hdf5_close_type (type_id));
H5_PRIV_API_RETURN (H5_SUCCESS);
}
h5_err_t
h5_has_file_attrib (
const h5_file_t f_,
......@@ -158,7 +25,8 @@ h5_has_file_attrib (
f,
attrib_name);
CHECK_FILEHANDLE (f);
H5_CORE_API_RETURN (hdf5_attribute_exists(f->root_gid, attrib_name));
TRY (ret_value = hdf5_attribute_exists(f->root_gid, attrib_name));
H5_CORE_API_RETURN (ret_value);
}
h5_err_t
......@@ -173,79 +41,87 @@ h5_has_step_attrib (
f,
attrib_name);
CHECK_FILEHANDLE (f);
H5_CORE_API_RETURN (hdf5_attribute_exists(f->step_gid, attrib_name));
TRY (ret_value = hdf5_attribute_exists (f->step_gid, attrib_name));
H5_CORE_API_RETURN (ret_value);
}
h5_ssize_t
h5_get_num_file_attribs (
const h5_file_t f_ /*!< handle to open file */
) {
h5_file_p f = (h5_file_p)f_;
H5_CORE_API_ENTER (h5_ssize_t, "f=%p", f);
CHECK_FILEHANDLE (f);
TRY (ret_value = hdf5_get_num_attribute (f->root_gid));
H5_CORE_API_RETURN (ret_value);
}
h5_ssize_t
h5_get_num_step_attribs (
const h5_file_t f_ /*!< handle to open file */
) {
h5_file_p f = (h5_file_p)f_;
H5_CORE_API_ENTER (h5_ssize_t, "f=%p", f);
CHECK_FILEHANDLE (f);
CHECK_TIMEGROUP (f);
TRY (ret_value = hdf5_get_num_attribute (f->step_gid));
H5_CORE_API_RETURN (ret_value);
}
h5_err_t
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_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 */
const h5_size_t len_attrib_name, /*!< buffer length */
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_idx=%llu, "
"attrib_name=%p, len_attrib_name=%llu, "
"attrib_type=%p, attrib_nelem=%p",
f,
attrib_name,
attrib_type,
attrib_nelem);
(long long unsigned)attrib_idx,
attrib_name, (long long unsigned)len_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);
TRY (ret_value = h5priv_get_attrib_info_by_idx (
f->root_gid,
attrib_idx,