Skip to content

Commit

Permalink
Implement support for Complex number datatypes
Browse files Browse the repository at this point in the history
replace usages of word "complex" to distinguish from complex datatypes
  • Loading branch information
jhendersonHDF committed May 3, 2024
1 parent 667b607 commit a700653
Show file tree
Hide file tree
Showing 10 changed files with 76 additions and 72 deletions.
8 changes: 4 additions & 4 deletions c++/test/tattr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@ test_attr_compound_write(FileAccPropList &fapl)
hsize_t dims2[] = {ATTR4_DIM1, ATTR4_DIM2};
DataSpace sid2(ATTR4_RANK, dims2);

// Create complex attribute for the dataset
// Create compound attribute for the dataset
Attribute attr = dataset.createAttribute(ATTR4_NAME, comp_type, sid2);

// Try to create the same attribute again (should fail)
Expand All @@ -643,7 +643,7 @@ test_attr_compound_write(FileAccPropList &fapl)
{
} // do nothing, exception expected

// Write complex attribute data
// Write compound attribute data
attr.write(comp_type, attr_data4);

PASSED();
Expand Down Expand Up @@ -2001,8 +2001,8 @@ test_attr()
test_attr_rename(curr_fapl); // Test renaming attribute
test_attr_basic_read(curr_fapl); // Test basic H5A reading code

test_attr_compound_write(curr_fapl); // Test complex datatype H5A writing code
test_attr_compound_read(curr_fapl); // Test complex datatype H5A reading code
test_attr_compound_write(curr_fapl); // Test compound datatype H5A writing code
test_attr_compound_read(curr_fapl); // Test compound datatype H5A reading code

test_attr_scalar_write(curr_fapl); // Test scalar dataspace H5A writing code
test_attr_scalar_read(curr_fapl); // Test scalar dataspace H5A reading code
Expand Down
42 changes: 22 additions & 20 deletions java/src/jni/h5aImp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1243,12 +1243,13 @@ Java_hdf_hdf5lib_H5_H5Aread_1VLStrings(JNIEnv *env, jclass clss, jlong attr_id,
jobjectArray buf)
{
H5T_class_t type_class;
htri_t isStr = 0;
htri_t isVlenStr = 0;
htri_t isComplex = 0;
htri_t isComplex2 = 0;
hid_t nested_tid = H5I_INVALID_HID;
herr_t status = FAIL;
htri_t isStr = 0;
htri_t isVlenStr = 0;
htri_t isCompound = 0;
htri_t isVlen = 0;
hid_t nested_tid = H5I_INVALID_HID;
bool isComposite = false;
herr_t status = FAIL;

UNUSED(clss);

Expand All @@ -1272,13 +1273,13 @@ Java_hdf_hdf5lib_H5_H5Aread_1VLStrings(JNIEnv *env, jclass clss, jlong attr_id,
if ((nested_tid = H5Tget_member_type((hid_t)mem_type_id, i)) < 0)
H5_LIBRARY_ERROR(ENVONLY);

if ((isComplex = H5Tdetect_class((hid_t)nested_tid, H5T_COMPOUND)) < 0)
if ((isCompound = H5Tdetect_class((hid_t)nested_tid, H5T_COMPOUND)) < 0)
H5_LIBRARY_ERROR(ENVONLY);

if ((isComplex2 = H5Tdetect_class((hid_t)nested_tid, H5T_VLEN)) < 0)
if ((isVlen = H5Tdetect_class((hid_t)nested_tid, H5T_VLEN)) < 0)
H5_LIBRARY_ERROR(ENVONLY);

isComplex = isComplex || isComplex2;
isComposite = isCompound || isVlen;

if (H5Tclose(nested_tid) < 0)
H5_LIBRARY_ERROR(ENVONLY);
Expand All @@ -1289,7 +1290,7 @@ Java_hdf_hdf5lib_H5_H5Aread_1VLStrings(JNIEnv *env, jclass clss, jlong attr_id,
isVlenStr = 1; /* Strings created by H5Tvlen_create(H5T_C_S1) */
}

if (!isStr || isComplex || isVlenStr) {
if (!isStr || isComposite || isVlenStr) {
if ((status = H5AreadVL_asstr(env, (hid_t)attr_id, (hid_t)mem_type_id, buf)) < 0)
CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
}
Expand Down Expand Up @@ -1447,12 +1448,13 @@ Java_hdf_hdf5lib_H5_H5Awrite_1VLStrings(JNIEnv *env, jclass clss, jlong attr_id,
jobjectArray buf)
{
H5T_class_t type_class;
htri_t isStr = 0;
htri_t isVlenStr = 0;
htri_t isComplex = 0;
htri_t isComplex2 = 0;
hid_t nested_tid = H5I_INVALID_HID;
herr_t status = FAIL;
htri_t isStr = 0;
htri_t isVlenStr = 0;
htri_t isCompound = 0;
htri_t isVlen = 0;
hid_t nested_tid = H5I_INVALID_HID;
bool isComposite = false;
herr_t status = FAIL;

UNUSED(clss);

Expand All @@ -1476,13 +1478,13 @@ Java_hdf_hdf5lib_H5_H5Awrite_1VLStrings(JNIEnv *env, jclass clss, jlong attr_id,
if ((nested_tid = H5Tget_member_type((hid_t)mem_type_id, i)) < 0)
H5_LIBRARY_ERROR(ENVONLY);

if ((isComplex = H5Tdetect_class((hid_t)nested_tid, H5T_COMPOUND)) < 0)
if ((isCompound = H5Tdetect_class((hid_t)nested_tid, H5T_COMPOUND)) < 0)
H5_LIBRARY_ERROR(ENVONLY);

if ((isComplex2 = H5Tdetect_class((hid_t)nested_tid, H5T_VLEN)) < 0)
if ((isVlen = H5Tdetect_class((hid_t)nested_tid, H5T_VLEN)) < 0)
H5_LIBRARY_ERROR(ENVONLY);

isComplex = isComplex || isComplex2;
isComposite = isCompound || isVlen;

if (H5Tclose(nested_tid) < 0)
H5_LIBRARY_ERROR(ENVONLY);
Expand All @@ -1493,7 +1495,7 @@ Java_hdf_hdf5lib_H5_H5Awrite_1VLStrings(JNIEnv *env, jclass clss, jlong attr_id,
isVlenStr = 1; /* Strings created by H5Tvlen_create(H5T_C_S1) */
}

if (!isStr || isComplex || isVlenStr) {
if (!isStr || isComposite || isVlenStr) {
if ((status = H5AwriteVL_asstr(env, (hid_t)attr_id, (hid_t)mem_type_id, buf)) < 0)
CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
}
Expand Down
42 changes: 22 additions & 20 deletions java/src/jni/h5dImp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1259,12 +1259,13 @@ Java_hdf_hdf5lib_H5_H5Dread_1VLStrings(JNIEnv *env, jclass clss, jlong dataset_i
jobjectArray buf)
{
H5T_class_t type_class;
htri_t isStr = 0;
htri_t isVlenStr = 0;
htri_t isComplex = 0;
htri_t isComplex2 = 0;
hid_t nested_tid = H5I_INVALID_HID;
herr_t status = FAIL;
htri_t isStr = 0;
htri_t isVlenStr = 0;
htri_t isCompound = 0;
htri_t isVlen = 0;
hid_t nested_tid = H5I_INVALID_HID;
bool isComposite = false;
herr_t status = FAIL;

UNUSED(clss);

Expand All @@ -1288,13 +1289,13 @@ Java_hdf_hdf5lib_H5_H5Dread_1VLStrings(JNIEnv *env, jclass clss, jlong dataset_i
if ((nested_tid = H5Tget_member_type((hid_t)mem_type_id, i)) < 0)
H5_LIBRARY_ERROR(ENVONLY);

if ((isComplex = H5Tdetect_class((hid_t)nested_tid, H5T_COMPOUND)) < 0)
if ((isCompound = H5Tdetect_class((hid_t)nested_tid, H5T_COMPOUND)) < 0)
H5_LIBRARY_ERROR(ENVONLY);

if ((isComplex2 = H5Tdetect_class((hid_t)nested_tid, H5T_VLEN)) < 0)
if ((isVlen = H5Tdetect_class((hid_t)nested_tid, H5T_VLEN)) < 0)
H5_LIBRARY_ERROR(ENVONLY);

isComplex = isComplex || isComplex2;
isComposite = isCompound || isVlen;

if (H5Tclose(nested_tid) < 0)
H5_LIBRARY_ERROR(ENVONLY);
Expand All @@ -1305,7 +1306,7 @@ Java_hdf_hdf5lib_H5_H5Dread_1VLStrings(JNIEnv *env, jclass clss, jlong dataset_i
isVlenStr = 1; /* Strings created by H5Tvlen_create(H5T_C_S1) */
}

if (!isStr || isComplex || isVlenStr) {
if (!isStr || isComposite || isVlenStr) {
if ((status = H5DreadVL_asstr(env, (hid_t)dataset_id, (hid_t)mem_type_id, (hid_t)mem_space_id,
(hid_t)file_space_id, (hid_t)xfer_plist_id, buf)) < 0)
CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
Expand Down Expand Up @@ -1484,12 +1485,13 @@ Java_hdf_hdf5lib_H5_H5Dwrite_1VLStrings(JNIEnv *env, jclass clss, jlong dataset_
jobjectArray buf)
{
H5T_class_t type_class;
htri_t isStr = 0;
htri_t isVlenStr = 0;
htri_t isComplex = 0;
htri_t isComplex2 = 0;
hid_t nested_tid = H5I_INVALID_HID;
herr_t status = FAIL;
htri_t isStr = 0;
htri_t isVlenStr = 0;
htri_t isCompound = 0;
htri_t isVlen = 0;
hid_t nested_tid = H5I_INVALID_HID;
bool isComposite = false;
herr_t status = FAIL;

UNUSED(clss);

Expand All @@ -1513,13 +1515,13 @@ Java_hdf_hdf5lib_H5_H5Dwrite_1VLStrings(JNIEnv *env, jclass clss, jlong dataset_
if ((nested_tid = H5Tget_member_type((hid_t)mem_type_id, i)) < 0)
H5_LIBRARY_ERROR(ENVONLY);

if ((isComplex = H5Tdetect_class((hid_t)nested_tid, H5T_COMPOUND)) < 0)
if ((isCompound = H5Tdetect_class((hid_t)nested_tid, H5T_COMPOUND)) < 0)
H5_LIBRARY_ERROR(ENVONLY);

if ((isComplex2 = H5Tdetect_class((hid_t)nested_tid, H5T_VLEN)) < 0)
if ((isVlen = H5Tdetect_class((hid_t)nested_tid, H5T_VLEN)) < 0)
H5_LIBRARY_ERROR(ENVONLY);

isComplex = isComplex || isComplex2;
isComposite = isCompound || isVlen;

if (H5Tclose(nested_tid) < 0)
H5_LIBRARY_ERROR(ENVONLY);
Expand All @@ -1530,7 +1532,7 @@ Java_hdf_hdf5lib_H5_H5Dwrite_1VLStrings(JNIEnv *env, jclass clss, jlong dataset_
isVlenStr = 1; /* Strings created by H5Tvlen_create(H5T_C_S1) */
}

if (!isStr || isComplex || isVlenStr) {
if (!isStr || isComposite || isVlenStr) {
if ((status = H5DwriteVL_asstr(env, (hid_t)dataset_id, (hid_t)mem_type_id, (hid_t)mem_space_id,
(hid_t)file_space_id, (hid_t)xfer_plist_id, buf)) < 0)
CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
Expand Down
4 changes: 2 additions & 2 deletions src/H5Spublic.h
Original file line number Diff line number Diff line change
Expand Up @@ -251,10 +251,10 @@ H5_DLL hid_t H5Scopy(hid_t space_id);
* Further dataspace types may be added later.
*
* A scalar dataspace, #H5S_SCALAR, has a single element, though that
* element may be of a complex datatype, such as a compound or array
* element may be of a composite datatype, such as a compound or array
* datatype. By convention, the rank of a scalar dataspace is always \p 0
* (zero); think of it geometrically as a single, dimensionless point,
* though that point can be complex.
* though that point can be composite.
*
* A simple dataspace, #H5S_SIMPLE, consists of a regular array of elements.
*
Expand Down
10 changes: 5 additions & 5 deletions src/H5T.c
Original file line number Diff line number Diff line change
Expand Up @@ -2342,7 +2342,7 @@ H5T_detect_class(const H5T_t *dt, H5T_class_t cls, bool from_api)
HGOTO_DONE(true);

/* Recurse if it's VL, compound, enum or array */
if (H5T_IS_COMPLEX(dt->shared->u.compnd.memb[i].type->shared->type))
if (H5T_IS_COMPOSITE(dt->shared->u.compnd.memb[i].type->shared->type))
if ((nested_ret = H5T_detect_class(dt->shared->u.compnd.memb[i].type, cls, from_api)) !=
false)
HGOTO_DONE(nested_ret);
Expand Down Expand Up @@ -6242,7 +6242,7 @@ H5T_set_loc(H5T_t *dt, H5VL_object_t *file, H5T_loc_t loc)
/* Recurse if it's VL, compound, enum or array */
/* (If the force_conv flag is _not_ set, the type cannot change in size, so don't recurse) */
if (dt->shared->parent->shared->force_conv &&
H5T_IS_COMPLEX(dt->shared->parent->shared->type)) {
H5T_IS_COMPOSITE(dt->shared->parent->shared->type)) {
/* Keep the old base element size for later */
old_size = dt->shared->parent->shared->size;

Expand Down Expand Up @@ -6283,7 +6283,7 @@ H5T_set_loc(H5T_t *dt, H5VL_object_t *file, H5T_loc_t loc)
/* Recurse if it's VL, compound, enum or array */
/* (If the force_conv flag is _not_ set, the type cannot change in size, so don't recurse)
*/
if (memb_type->shared->force_conv && H5T_IS_COMPLEX(memb_type->shared->type)) {
if (memb_type->shared->force_conv && H5T_IS_COMPOSITE(memb_type->shared->type)) {
/* Keep the old field size for later */
old_size = memb_type->shared->size;

Expand Down Expand Up @@ -6325,7 +6325,7 @@ H5T_set_loc(H5T_t *dt, H5VL_object_t *file, H5T_loc_t loc)
* them as part of the same blob)*/
/* (If the force_conv flag is _not_ set, the type cannot change in size, so don't recurse) */
if (dt->shared->parent->shared->force_conv &&
H5T_IS_COMPLEX(dt->shared->parent->shared->type) &&
H5T_IS_COMPOSITE(dt->shared->parent->shared->type) &&
(dt->shared->parent->shared->type != H5T_REFERENCE)) {
if ((changed = H5T_set_loc(dt->shared->parent, file, loc)) < 0)
HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "Unable to set VL location");
Expand Down Expand Up @@ -6571,7 +6571,7 @@ H5T__upgrade_version(H5T_t *dt, unsigned new_version)
assert(dt);

/* Iterate over entire datatype, upgrading the version of components, if it's useful */
if (H5T__visit(dt, (H5T_VISIT_SIMPLE | H5T_VISIT_COMPLEX_LAST), H5T__upgrade_version_cb, &new_version) <
if (H5T__visit(dt, (H5T_VISIT_SIMPLE | H5T_VISIT_COMPOSITE_LAST), H5T__upgrade_version_cb, &new_version) <
0)
HGOTO_ERROR(H5E_DATATYPE, H5E_BADITER, FAIL, "iteration to upgrade datatype encoding version failed");

Expand Down
2 changes: 1 addition & 1 deletion src/H5Tconv_vlen.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ H5FL_BLK_DEFINE_STATIC(vlen_seq);
* Function: H5T__conv_vlen_nested_free
*
* Purpose: Recursively locates and frees any nested VLEN components of
* complex data types (including COMPOUND).
* composite data types (including COMPOUND).
*
* Return: Non-negative on success/Negative on failure.
*
Expand Down
16 changes: 8 additions & 8 deletions src/H5Tpkg.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@
/* Other public headers needed by this file */
#include "H5Spublic.h" /* Dataspace functions */

/* Macro to ease detecting "complex" datatypes (i.e. those with base types or fields) */
#define H5T_IS_COMPLEX(t) \
/* Macro to ease detecting composite datatypes (i.e. those with base types or fields) */
#define H5T_IS_COMPOSITE(t) \
((t) == H5T_COMPOUND || (t) == H5T_ENUM || (t) == H5T_VLEN || (t) == H5T_ARRAY || (t) == H5T_REFERENCE)

/* Macro to ease detecting fixed "string" datatypes */
Expand All @@ -55,7 +55,7 @@
#define H5T_IS_STRING(dt) (H5T_IS_FIXED_STRING(dt) || H5T_IS_VL_STRING(dt))

/* Macro to ease detecting atomic datatypes */
#define H5T_IS_ATOMIC(dt) (!(H5T_IS_COMPLEX((dt)->type) || (dt)->type == H5T_OPAQUE))
#define H5T_IS_ATOMIC(dt) (!(H5T_IS_COMPOSITE((dt)->type) || (dt)->type == H5T_OPAQUE))

/* Macro to ease retrieving class of shared datatype */
/* (Externally, a VL string is a string; internally, a VL string is a VL. Lie
Expand Down Expand Up @@ -100,13 +100,13 @@
#define H5O_DTYPE_VERSION_LATEST H5O_DTYPE_VERSION_4

/* Flags for visiting datatype */
#define H5T_VISIT_COMPLEX_FIRST 0x01 /* Visit complex datatype before visiting member/parent datatypes */
#define H5T_VISIT_COMPLEX_LAST 0x02 /* Visit complex datatype after visiting member/parent datatypes */
/* (setting both flags will mean visiting complex type twice) */
#define H5T_VISIT_COMPOSITE_FIRST 0x01 /* Visit composite datatype before visiting member/parent datatypes */
#define H5T_VISIT_COMPOSITE_LAST 0x02 /* Visit composite datatype after visiting member/parent datatypes */
/* (setting both flags will mean visiting composite type twice) */
#define H5T_VISIT_SIMPLE 0x04 /* Visit simple datatypes (at all) */
/* (setting H5T_VISIT_SIMPLE and _not_ setting either H5T_VISIT_COMPLEX_FIRST or H5T_VISIT_COMPLEX_LAST will
/* (setting H5T_VISIT_SIMPLE and _not_ setting either H5T_VISIT_COMPOSITE_FIRST or H5T_VISIT_COMPOSITE_LAST will
* mean visiting _only_ "simple" "leafs" in the "tree" */
/* (_not_ setting H5T_VISIT_SIMPLE and setting either H5T_VISIT_COMPLEX_FIRST or H5T_VISIT_COMPLEX_LAST will
/* (_not_ setting H5T_VISIT_SIMPLE and setting either H5T_VISIT_COMPOSITE_FIRST or H5T_VISIT_COMPOSITE_LAST will
* mean visiting all nodes _except_ "simple" "leafs" in the "tree" */

/* Define an internal macro for converting long long to long double. Mac OS 10.4 gives some
Expand Down
10 changes: 5 additions & 5 deletions src/H5Tvisit.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
herr_t
H5T__visit(H5T_t *dt, unsigned visit_flags, H5T_operator_t op, void *op_value)
{
bool is_complex; /* Flag indicating current datatype is "complex" */
bool is_composite; /* Flag indicating current datatype is composite */
herr_t ret_value = SUCCEED; /* Return value */

FUNC_ENTER_PACKAGE
Expand All @@ -89,11 +89,11 @@ H5T__visit(H5T_t *dt, unsigned visit_flags, H5T_operator_t op, void *op_value)
assert(dt);
assert(op);

/* Check for complex datatype */
is_complex = H5T_IS_COMPLEX(dt->shared->type);
/* Check for composite datatype */
is_composite = H5T_IS_COMPOSITE(dt->shared->type);

/* If the callback is to be made on the datatype first, do that */
if (is_complex && (visit_flags & H5T_VISIT_COMPLEX_FIRST))
if (is_composite && (visit_flags & H5T_VISIT_COMPOSITE_FIRST))
if (op(dt, op_value) < 0)
HGOTO_ERROR(H5E_DATATYPE, H5E_BADITER, FAIL, "operator callback failed");

Expand Down Expand Up @@ -139,7 +139,7 @@ H5T__visit(H5T_t *dt, unsigned visit_flags, H5T_operator_t op, void *op_value)
} /* end switch */

/* If the callback is to be made on the datatype last, do that */
if (is_complex && (visit_flags & H5T_VISIT_COMPLEX_LAST))
if (is_composite && (visit_flags & H5T_VISIT_COMPOSITE_LAST))
if (op(dt, op_value) < 0)
HGOTO_ERROR(H5E_DATATYPE, H5E_BADITER, FAIL, "operator callback failed");

Expand Down
6 changes: 3 additions & 3 deletions src/H5Tvlen.c
Original file line number Diff line number Diff line change
Expand Up @@ -948,7 +948,7 @@ H5T__vlen_reclaim(void *elem, const H5T_t *dt, H5T_vlen_alloc_info_t *alloc_info
switch (dt->shared->type) {
case H5T_ARRAY:
/* Recurse on each element, if the array's base type is array, VL, enum or compound */
if (H5T_IS_COMPLEX(dt->shared->parent->shared->type)) {
if (H5T_IS_COMPOSITE(dt->shared->parent->shared->type)) {
void *off; /* offset of field */

/* Calculate the offset member and recurse on it */
Expand All @@ -964,7 +964,7 @@ H5T__vlen_reclaim(void *elem, const H5T_t *dt, H5T_vlen_alloc_info_t *alloc_info
/* Check each field and recurse on VL, compound, enum or array ones */
for (u = 0; u < dt->shared->u.compnd.nmembs; u++) {
/* Recurse if it's VL, compound, enum or array */
if (H5T_IS_COMPLEX(dt->shared->u.compnd.memb[u].type->shared->type)) {
if (H5T_IS_COMPOSITE(dt->shared->u.compnd.memb[u].type->shared->type)) {
void *off; /* offset of field */

/* Calculate the offset member and recurse on it */
Expand All @@ -983,7 +983,7 @@ H5T__vlen_reclaim(void *elem, const H5T_t *dt, H5T_vlen_alloc_info_t *alloc_info
/* Check if there is anything actually in this sequence */
if (vl->len != 0) {
/* Recurse if it's VL, array, enum or compound */
if (H5T_IS_COMPLEX(dt->shared->parent->shared->type)) {
if (H5T_IS_COMPOSITE(dt->shared->parent->shared->type)) {
void *off; /* offset of field */

/* Calculate the offset of each array element and recurse on it */
Expand Down
Loading

0 comments on commit a700653

Please sign in to comment.