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 14, 2024
1 parent 667b607 commit 8b4d394
Show file tree
Hide file tree
Showing 42 changed files with 753 additions and 232 deletions.
3 changes: 2 additions & 1 deletion HDF5Examples/JAVA/H5T/H5Ex_T_Commit.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ enum H5T_class {
H5T_ENUM(HDF5Constants.H5T_ENUM), // enumeration types
H5T_VLEN(HDF5Constants.H5T_VLEN), // Variable-Length types
H5T_ARRAY(HDF5Constants.H5T_ARRAY), // Array types
H5T_NCLASSES(11); // this must be last
H5T_COMPLEX(HDF5Constants.H5T_COMPLEX), // Complex number types
H5T_NCLASSES(12); // this must be last

private static final Map<Long, H5T_class> lookup = new HashMap<Long, H5T_class>();

Expand Down
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
2 changes: 1 addition & 1 deletion doxygen/aliases
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ ALIASES += ref_rfc20040811="<a href=\"https://\RFCURL/text-dtype.htm.pdf\">Conve

ALIASES += click4more="(Click on a enumerator, field, or type for more information.)"
ALIASES += csets="<table><tr><td>#H5T_CSET_ASCII</td><td>US ASCII</td></tr><tr><td>#H5T_CSET_UTF8</td><td>UTF-8 Unicode encoding</td></tr></table>"
ALIASES += datatype_class=" \li #H5T_INTEGER \li #H5T_FLOAT \li #H5T_STRING \li #H5T_BITFIELD \li #H5T_OPAQUE \li #H5T_COMPOUND \li #H5T_REFERENCE \li #H5T_ENUM \li #H5T_VLEN \li #H5T_ARRAY"
ALIASES += datatype_class=" \li #H5T_INTEGER \li #H5T_FLOAT \li #H5T_STRING \li #H5T_BITFIELD \li #H5T_OPAQUE \li #H5T_COMPOUND \li #H5T_REFERENCE \li #H5T_ENUM \li #H5T_VLEN \li #H5T_ARRAY \li #H5T_COMPLEX"
ALIASES += file_access="<table><tr><td>#H5F_ACC_RDWR</td><td>File was opened with read/write access.</td></tr><tr><td>#H5F_ACC_RDONLY</td><td>File was opened with read-only access.</td></tr><tr><td>#H5F_ACC_SWMR_WRITE</td><td>File was opened with read/write access for a single-writer/multiple-reader (SWMR) scenario. Note that the writer process must also open the file with the #H5F_ACC_RDWR flag.</td></tr><tr><td>#H5F_ACC_SWMR_READ</td><td>File was opened with read-only access for a single-writer/multiple-reader (SWMR) scenario. Note that the reader process must also open the file with the #H5F_ACC_RDONLY flag.</td></tr></table>"
ALIASES += id_types="<table><tr><td>#H5I_FILE</td><td>File</td></tr><tr><td>#H5I_GROUP</td><td>Group</td></tr><tr><td>#H5I_DATATYPE</td><td>Datatype</td></tr><tr><td>#H5I_DATASPACE</td><td>Dataspace</td></tr><tr><td>#H5I_DATASET</td><td>Dataset</td></tr><tr><td>#H5I_ATTR</td><td>Attribute</td></tr></table>"
ALIASES += indexes="<table><tr><td>#H5_INDEX_NAME</td><td>Lexicographic order on name</td></tr><tr><td>#H5_INDEX_CRT_ORDER</td><td>Index on creation order</td></tr></table>"
Expand Down
12 changes: 10 additions & 2 deletions doxygen/dox/DDLBNF114.dox
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/** \page DDLBNF114 DDL in BNF for HDF5 1.14.4 and above
/** \page DDLBNF114 DDL in BNF for HDF5 1.14.5 and above

\todo Revise this & break it up!

Expand Down Expand Up @@ -74,7 +74,8 @@ This section contains a brief explanation of the symbols used in the DDL.
of the type

<atomic_type> ::= <integer> | <float> | <time> | <string> |
<bitfield> | <opaque> | <reference> | <enum>
<bitfield> | <opaque> | <reference> | <enum> |
<complex_type>

<boolean_value> ::= FALSE | TRUE

Expand Down Expand Up @@ -169,6 +170,13 @@ This section contains a brief explanation of the symbols used in the DDL.

<enum_val> ::= <int_value>

<complex_type> ::= H5T_COMPLEX { <complex_base_type> }

<complex_base_type> ::= <float>
// Currently complex number datatypes can only hold homogeneous floating-point
// type data, but they may be expanded in the future to hold heterogeneous
// floating-point type data

<path_name> ::= <path_part>+

<path_part> ::= /<identifier>
Expand Down
12 changes: 12 additions & 0 deletions doxygen/examples/tables/predefinedDatatypes.dox
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,18 @@
<td>C-style long double</td>
</tr>
<tr>
<td>#H5T_NATIVE_FLOAT_COMPLEX</td>
<td>C-style float _Complex (May be H5I_INVALID_HID if platform doesn't support float _Complex type)</td>
</tr>
<tr>
<td>#H5T_NATIVE_DOUBLE_COMPLEX</td>
<td>C-style double _Complex (May be H5I_INVALID_HID if platform doesn't support double _Complex type)</td>
</tr>
<tr>
<td>#H5T_NATIVE_LDOUBLE_COMPLEX</td>
<td>C-style long double _Complex (May be H5I_INVALID_HID if platform doesn't support long double _Complex type)</td>
</tr>
<tr>
<td>#H5T_NATIVE_B8</td>
<td>8-bit bitfield based on native types</td>
</tr>
Expand Down
15 changes: 3 additions & 12 deletions fortran/src/H5Tf.c
Original file line number Diff line number Diff line change
Expand Up @@ -212,11 +212,12 @@ h5tequal_c(hid_t_f *type1_id, hid_t_f *type2_id, int_f *c_flag)
* H5T_STRING_F (3)
* H5T_BITFIELD_F (4)
* H5T_OPAQUE_F (5)
* H5T_COMPOUNDF (6)
* H5T_COMPOUND_F (6)
* H5T_REFERENCE_F (7)
* H5T_ENUM_F (8)
* H5T_VLEN_F (9)
* H5T_ARRAY_F (10)
* H5T_COMPLEX_F (11)
* RETURNS
* 0 on success, -1 on failure
* SOURCE
Expand All @@ -239,17 +240,7 @@ h5tget_class_c(hid_t_f *type_id, int_f *classtype)
return ret_value;
}
*classtype = c_classtype;
/*
if (c_classtype == H5T_INTEGER) *classtype = H5T_INTEGER_F;
if (c_classtype == H5T_FLOAT) *classtype = H5T_FLOAT_F;
if (c_classtype == H5T_TIME) *classtype = H5T_TIME_F;
if (c_classtype == H5T_STRING) *classtype = H5T_STRING_F;
if (c_classtype == H5T_BITFIELD) *classtype = H5T_BITFIELD_F;
if (c_classtype == H5T_OPAQUE) *classtype = H5T_OPAQUE_F;
if (c_classtype == H5T_COMPOUND) *classtype = H5T_COMPOUND_F;
if (c_classtype == H5T_REFERENCE) *classtype = H5T_REFERENCE_F;
if (c_classtype == H5T_ENUM) *classtype = H5T_ENUM_F;
*/

return ret_value;
}

Expand Down
6 changes: 4 additions & 2 deletions fortran/src/H5Tff.F90
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ END SUBROUTINE h5tclose_f
!! \li H5T_ENUM_F
!! \li H5T_VLEN_F
!! \li H5T_ARRAY_F
!! \li H5T_COMPLEX_F
!! \param hdferr \fortran_error
!!
!! See C API: @ref H5Tget_class()
Expand Down Expand Up @@ -1726,9 +1727,9 @@ END SUBROUTINE h5tis_variable_str_f
!!
!! \brief Returns datatype class of compound datatype member.
!!
!! \param type_id Datartpe identifier.
!! \param type_id Datatype identifier.
!! \param member_no Index of compound datatype member.
!! \param class Class type for compound dadtype member. Valid classes:
!! \param class Class type for compound datatype member. Valid classes:
!! \li H5T_NO_CLASS_F (error)
!! \li H5T_INTEGER_F
!! \li H5T_FLOAT_F
Expand All @@ -1741,6 +1742,7 @@ END SUBROUTINE h5tis_variable_str_f
!! \li H5T_ENUM_F
!! \li H5T_VLEN_F
!! \li H5T_ARRAY_F
!! \li H5T_COMPLEX_F
!! \param hdferr \fortran_error
!!
!! See C API: @ref H5Tget_member_class()
Expand Down
1 change: 1 addition & 0 deletions fortran/src/H5_f.c
Original file line number Diff line number Diff line change
Expand Up @@ -839,6 +839,7 @@ h5init_flags_c(int_f *h5d_flags, size_t_f *h5d_size_flags, int_f *h5e_flags, hid
h5t_flags[32] = (int_f)H5T_ARRAY;
h5t_flags[33] = (int_f)H5T_DIR_ASCEND;
h5t_flags[34] = (int_f)H5T_DIR_DESCEND;
h5t_flags[35] = (int_f)H5T_COMPLEX;

/*
* H5VL flags
Expand Down
3 changes: 2 additions & 1 deletion fortran/src/H5_ff.F90
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ MODULE H5LIB
!
! H5T flags declaration
!
INTEGER, PARAMETER :: H5T_FLAGS_LEN = 35
INTEGER, PARAMETER :: H5T_FLAGS_LEN = 36
INTEGER, DIMENSION(1:H5T_FLAGS_LEN) :: H5T_flags
!
! H5VL flags declaration
Expand Down Expand Up @@ -696,6 +696,7 @@ END FUNCTION h5init1_flags_c
H5T_ARRAY_F = H5T_flags(33)
H5T_DIR_ASCEND_F = H5T_flags(34)
H5T_DIR_DESCEND_F = H5T_flags(35)
H5T_COMPLEX_F = H5T_flags(36)
!
! H5VL flags
!
Expand Down
2 changes: 2 additions & 0 deletions fortran/src/H5f90global.F90
Original file line number Diff line number Diff line change
Expand Up @@ -844,6 +844,7 @@ MODULE H5GLOBAL
!DEC$ATTRIBUTES DLLEXPORT :: H5T_ENUM_F
!DEC$ATTRIBUTES DLLEXPORT :: H5T_VLEN_F
!DEC$ATTRIBUTES DLLEXPORT :: H5T_ARRAY_F
!DEC$ATTRIBUTES DLLEXPORT :: H5T_COMPLEX_F
!DEC$ATTRIBUTES DLLEXPORT :: H5T_ORDER_LE_F
!DEC$ATTRIBUTES DLLEXPORT :: H5T_ORDER_BE_F
!DEC$ATTRIBUTES DLLEXPORT :: H5T_ORDER_VAX_F
Expand Down Expand Up @@ -882,6 +883,7 @@ MODULE H5GLOBAL
INTEGER :: H5T_ENUM_F !< H5T_ENUM
INTEGER :: H5T_VLEN_F !< H5T_VLEN
INTEGER :: H5T_ARRAY_F !< H5T_ARRAY
INTEGER :: H5T_COMPLEX_F !< H5T_COMPLEX
INTEGER :: H5T_ORDER_LE_F !< H5T_ORDER_LE
INTEGER :: H5T_ORDER_BE_F !< H5T_ORDER_BE
INTEGER :: H5T_ORDER_VAX_F !< H5T_ORDER_VAX
Expand Down
7 changes: 7 additions & 0 deletions hl/src/H5LT.c
Original file line number Diff line number Diff line change
Expand Up @@ -2753,6 +2753,13 @@ H5LT_dtype_to_text(hid_t dtype, char *dt_str, H5LT_lang_t lang, size_t *slen, bo

break;
}
case H5T_COMPLEX:
snprintf(dt_str, *slen, "H5T_COMPLEX {");

/* TODO */

break;

case H5T_TIME:
snprintf(dt_str, *slen, "H5T_TIME: not yet implemented");
break;
Expand Down
5 changes: 5 additions & 0 deletions hl/src/H5LTanalyze.l
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ H5T_NATIVE_FLOAT {return hid(H5T_NATIVE_FLOAT_TOKEN);}
H5T_NATIVE_DOUBLE {return hid(H5T_NATIVE_DOUBLE_TOKEN);}
H5T_NATIVE_LDOUBLE {return hid(H5T_NATIVE_LDOUBLE_TOKEN);}

H5T_NATIVE_FLOAT_COMPLEX {return hid(H5T_NATIVE_FLOAT_COMPLEX_TOKEN);}
H5T_NATIVE_DOUBLE_COMPLEX {return hid(H5T_NATIVE_DOUBLE_COMPLEX_TOKEN);}
H5T_NATIVE_LDOUBLE_COMPLEX {return hid(H5T_NATIVE_LDOUBLE_COMPLEX_TOKEN);}

H5T_STRING {return token(H5T_STRING_TOKEN);}
STRSIZE {return token(STRSIZE_TOKEN);}
STRPAD {return token(STRPAD_TOKEN);}
Expand All @@ -111,6 +115,7 @@ H5T_COMPOUND {return token(H5T_COMPOUND_TOKEN);}
H5T_ENUM {return token(H5T_ENUM_TOKEN);}
H5T_ARRAY {return token(H5T_ARRAY_TOKEN);}
H5T_VLEN {return token(H5T_VLEN_TOKEN);}
H5T_COMPLEX {return token(H5T_COMPLEX_TOKEN);}

H5T_OPAQUE {return token(H5T_OPAQUE_TOKEN);}
OPQ_SIZE {return token(OPQ_SIZE_TOKEN);}
Expand Down
4 changes: 4 additions & 0 deletions hl/src/H5LTparse.y
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ static char* enum_memb_symbol; /*enum member symbol string*/
%token <hid> H5T_IEEE_F32BE_TOKEN H5T_IEEE_F32LE_TOKEN H5T_IEEE_F64BE_TOKEN H5T_IEEE_F64LE_TOKEN
%token <hid> H5T_NATIVE_FLOAT16_TOKEN H5T_NATIVE_FLOAT_TOKEN H5T_NATIVE_DOUBLE_TOKEN H5T_NATIVE_LDOUBLE_TOKEN

%token <hid> H5T_NATIVE_FLOAT_COMPLEX_TOKEN H5T_NATIVE_DOUBLE_COMPLEX_TOKEN H5T_NATIVE_LDOUBLE_COMPLEX_TOKEN

%token <ival> H5T_STRING_TOKEN STRSIZE_TOKEN STRPAD_TOKEN CSET_TOKEN CTYPE_TOKEN H5T_VARIABLE_TOKEN
%token <ival> H5T_STR_NULLTERM_TOKEN H5T_STR_NULLPAD_TOKEN H5T_STR_SPACEPAD_TOKEN
%token <ival> H5T_CSET_ASCII_TOKEN H5T_CSET_UTF8_TOKEN H5T_C_S1_TOKEN H5T_FORTRAN_S1_TOKEN
Expand All @@ -93,6 +95,7 @@ static char* enum_memb_symbol; /*enum member symbol string*/
%token <ival> H5T_ENUM_TOKEN
%token <ival> H5T_ARRAY_TOKEN
%token <ival> H5T_VLEN_TOKEN
%token <ival> H5T_COMPLEX_TOKEN

%token <sval> STRING
%token <ival> NUMBER
Expand All @@ -112,6 +115,7 @@ atomic_type : integer_type
| string_type
| enum_type
| opaque_type
| complex_type
;

integer_type : H5T_STD_I8BE_TOKEN { $<hid>$ = H5Tcopy(H5T_STD_I8BE); }
Expand Down
2 changes: 2 additions & 0 deletions java/src/hdf/hdf5lib/H5.java
Original file line number Diff line number Diff line change
Expand Up @@ -14250,6 +14250,8 @@ else if (HDF5Constants.H5T_VLEN == class_id) /* Variable-Length types */
retValue = "H5T_VLEN";
else if (HDF5Constants.H5T_ARRAY == class_id) /* Array types */
retValue = "H5T_ARRAY";
else if (HDF5Constants.H5T_COMPLEX == class_id) /* Complex number types */
retValue = "H5T_COMPLEX";
else
retValue = "H5T_NO_CLASS";

Expand Down
16 changes: 16 additions & 0 deletions java/src/hdf/hdf5lib/HDF5Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -1041,6 +1041,8 @@ public class HDF5Constants {
/** */
public static final long H5T_C_S1 = H5T_C_S1();
/** */
public static final int H5T_COMPLEX = H5T_COMPLEX();
/** */
public static final int H5T_COMPOUND = H5T_COMPOUND();
/** */
public static final int H5T_CONV_CONV = H5T_CONV_CONV();
Expand Down Expand Up @@ -1177,10 +1179,14 @@ public class HDF5Constants {
/** */
public static final long H5T_NATIVE_DOUBLE = H5T_NATIVE_DOUBLE();
/** */
public static final long H5T_NATIVE_DOUBLE_COMPLEX = H5T_NATIVE_DOUBLE_COMPLEX();
/** */
public static final long H5T_NATIVE_FLOAT = H5T_NATIVE_FLOAT();
/** */
public static final long H5T_NATIVE_FLOAT16 = H5T_NATIVE_FLOAT16();
/** */
public static final long H5T_NATIVE_FLOAT_COMPLEX = H5T_NATIVE_FLOAT_COMPLEX();
/** */
public static final long H5T_NATIVE_HADDR = H5T_NATIVE_HADDR();
/** */
public static final long H5T_NATIVE_HBOOL = H5T_NATIVE_HBOOL();
Expand Down Expand Up @@ -1223,6 +1229,8 @@ public class HDF5Constants {
/** */
public static final long H5T_NATIVE_LONG = H5T_NATIVE_LONG();
/** */
public static final long H5T_NATIVE_LDOUBLE_COMPLEX = H5T_NATIVE_LDOUBLE_COMPLEX();
/** */
public static final long H5T_NATIVE_OPAQUE = H5T_NATIVE_OPAQUE();
/** */
public static final long H5T_NATIVE_SCHAR = H5T_NATIVE_SCHAR();
Expand Down Expand Up @@ -2532,6 +2540,8 @@ public class HDF5Constants {

private static native final long H5T_C_S1();

private static native final int H5T_COMPLEX();

private static native final int H5T_COMPOUND();

private static native final int H5T_CONV_CONV();
Expand Down Expand Up @@ -2668,9 +2678,13 @@ public class HDF5Constants {

private static native final long H5T_NATIVE_DOUBLE();

private static native final long H5T_NATIVE_DOUBLE_COMPLEX();

private static native final long H5T_NATIVE_FLOAT();

private static native final long H5T_NATIVE_FLOAT16();

private static native final long H5T_NATIVE_FLOAT_COMPLEX();

private static native final long H5T_NATIVE_HADDR();

Expand Down Expand Up @@ -2713,6 +2727,8 @@ public class HDF5Constants {
private static native final long H5T_NATIVE_LLONG();

private static native final long H5T_NATIVE_LONG();

private static native final long H5T_NATIVE_LDOUBLE_COMPLEX();

private static native final long H5T_NATIVE_OPAQUE();

Expand Down
20 changes: 20 additions & 0 deletions java/src/jni/h5Constants.c
Original file line number Diff line number Diff line change
Expand Up @@ -2543,6 +2543,11 @@ Java_hdf_hdf5lib_HDF5Constants_H5T_1C_1S1(JNIEnv *env, jclass cls)
return H5T_C_S1;
}
JNIEXPORT jint JNICALL
Java_hdf_hdf5lib_HDF5Constants_H5T_1COMPLEX(JNIEnv *env, jclass cls)
{
return H5T_COMPLEX;
}
JNIEXPORT jint JNICALL
Java_hdf_hdf5lib_HDF5Constants_H5T_1COMPOUND(JNIEnv *env, jclass cls)
{
return H5T_COMPOUND;
Expand Down Expand Up @@ -2883,6 +2888,11 @@ Java_hdf_hdf5lib_HDF5Constants_H5T_1NATIVE_1DOUBLE(JNIEnv *env, jclass cls)
return H5T_NATIVE_DOUBLE;
}
JNIEXPORT jlong JNICALL
Java_hdf_hdf5lib_HDF5Constants_H5T_1NATIVE_1DOUBLE_1COMPLEX(JNIEnv *env, jclass cls)
{
return H5T_NATIVE_DOUBLE_COMPLEX;
}
JNIEXPORT jlong JNICALL
Java_hdf_hdf5lib_HDF5Constants_H5T_1NATIVE_1FLOAT(JNIEnv *env, jclass cls)
{
return H5T_NATIVE_FLOAT;
Expand All @@ -2893,6 +2903,11 @@ Java_hdf_hdf5lib_HDF5Constants_H5T_1NATIVE_1FLOAT16(JNIEnv *env, jclass cls)
return H5T_NATIVE_FLOAT16;
}
JNIEXPORT jlong JNICALL
Java_hdf_hdf5lib_HDF5Constants_H5T_1NATIVE_1FLOAT_1COMPLEX(JNIEnv *env, jclass cls)
{
return H5T_NATIVE_FLOAT_COMPLEX;
}
JNIEXPORT jlong JNICALL
Java_hdf_hdf5lib_HDF5Constants_H5T_1NATIVE_1HADDR(JNIEnv *env, jclass cls)
{
return H5T_NATIVE_HADDR;
Expand Down Expand Up @@ -2998,6 +3013,11 @@ Java_hdf_hdf5lib_HDF5Constants_H5T_1NATIVE_1LONG(JNIEnv *env, jclass cls)
return H5T_NATIVE_LONG;
}
JNIEXPORT jlong JNICALL
Java_hdf_hdf5lib_HDF5Constants_H5T_1NATIVE_1LDOUBLE_1COMPLEX(JNIEnv *env, jclass cls)
{
return H5T_NATIVE_LDOUBLE_COMPLEX;
}
JNIEXPORT jlong JNICALL
Java_hdf_hdf5lib_HDF5Constants_H5T_1NATIVE_1OPAQUE(JNIEnv *env, jclass cls)
{
return H5T_NATIVE_OPAQUE;
Expand Down
Loading

0 comments on commit 8b4d394

Please sign in to comment.