Implement support for complex number datatypes (#4630)

* Implement support for complex number datatypes

Adds the new datatype class H5T_COMPLEX

Adds the new API function H5Tcomplex_create which creates a complex
number datatype from an ID of a base floating-point datatype

Adds the new feature check macros H5_HAVE_COMPLEX_NUMBERS and
H5_HAVE_C99_COMPLEX_NUMBERS

Adds the new datatype size macros H5_SIZEOF_FLOAT_COMPLEX,
H5_SIZEOF_DOUBLE_COMPLEX and H5_SIZEOF_LONG_DOUBLE_COMPLEX

Adds the new datatype ID macros H5T_NATIVE_FLOAT_COMPLEX,
H5T_NATIVE_DOUBLE_COMPLEX, H5T_NATIVE_LDOUBLE_COMPLEX,
H5T_CPLX_IEEE_F16LE, H5T_CPLX_IEEE_F16BE,
H5T_CPLX_IEEE_F32LE, H5T_CPLX_IEEE_F32BE,
H5T_CPLX_IEEE_F64LE and H5T_CPLX_IEEE_F64BE

Adds hard and soft datatype conversion paths between complex number
datatypes and all the integer and floating-point datatypes, as well as
between other complex number datatypes

Adds a special conversion path between complex number datatypes and
array or compound datatypes where the in-memory layout of data is the
same between the datatypes and data can be converted directly

Adds support for complex number datatypes to the h5dump, h5ls and
h5diff/ph5diff tools. Allows h5dump '-m' option to change floating-point
printing format for float complex and double complex datatypes, as well
as long double complex if it has the same size as double complex

Adds minimal support to the h5watch and h5import tools

Adds support for the predefined complex number datatypes and
H5Tcomplex_create function to the Java wrappers. Also adds initial,
untested support to the JNI for future use with HDFView

Adds support for just the H5T_COMPLEX datatype class to the Fortran
wrappers

Adds support for the predefined complex number datatypes and
H5Tcomplex_create function to the high level library H5LT interface
for use with the H5LTtext_to_dtype and H5LTdtype_to_text functions

Changes some usages of "complex" in the library since it conflicts with
the "complex" keyword from the complex.h header. Also changes various
usages of the word "complex" throughout the library to distinguish
compound datatypes from complex datatypes.
This commit is contained in:
jhendersonHDF
2024-10-31 13:54:25 -07:00
committed by GitHub
parent e8257bd2b5
commit 90429f5e7d
141 changed files with 23643 additions and 3805 deletions
+29
View File
@@ -13747,6 +13747,33 @@ public class H5 implements java.io.Serializable {
public synchronized static native void H5Tcompiler_conv(long src_id, long dst_id)
throws HDF5LibraryException;
/**
* @ingroup JH5T
*
* H5Tcomplex_create creates a new complex number datatype object.
*
* @param base_id
* IN: Datatype identifier for the complex number base datatype.
* Must be a floating-point datatype.
*
* @return a valid datatype identifier
*
* @exception HDF5LibraryException
* Error from the HDF5 Library.
**/
public static long H5Tcomplex_create(long base_id) throws HDF5LibraryException
{
long id = _H5Tcomplex_create(base_id);
if (id > 0) {
log.trace("OPEN_IDS: H5Tcomplex_create add {}", id);
OPEN_IDS.add(id);
log.trace("OPEN_IDS: {}", OPEN_IDS.size());
}
return id;
}
private synchronized static native long _H5Tcomplex_create(long base_id) throws HDF5LibraryException;
/**
* @ingroup JH5T
*
@@ -14250,6 +14277,8 @@ public class H5 implements java.io.Serializable {
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";
+40
View File
@@ -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();
@@ -1049,6 +1051,18 @@ public class HDF5Constants {
/** */
public static final int H5T_CONV_INIT = H5T_CONV_INIT();
/** */
public static final long H5T_COMPLEX_IEEE_F16BE = H5T_COMPLEX_IEEE_F16BE();
/** */
public static final long H5T_COMPLEX_IEEE_F16LE = H5T_COMPLEX_IEEE_F16LE();
/** */
public static final long H5T_COMPLEX_IEEE_F32BE = H5T_COMPLEX_IEEE_F32BE();
/** */
public static final long H5T_COMPLEX_IEEE_F32LE = H5T_COMPLEX_IEEE_F32LE();
/** */
public static final long H5T_COMPLEX_IEEE_F64BE = H5T_COMPLEX_IEEE_F64BE();
/** */
public static final long H5T_COMPLEX_IEEE_F64LE = H5T_COMPLEX_IEEE_F64LE();
/** */
public static final int H5T_CSET_ERROR = H5T_CSET_ERROR();
/** */
public static final int H5T_CSET_ASCII = H5T_CSET_ASCII();
@@ -1177,10 +1191,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();
@@ -1223,6 +1241,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();
@@ -2532,6 +2552,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();
@@ -2540,6 +2562,18 @@ public class HDF5Constants {
private static native final int H5T_CONV_INIT();
private static native final long H5T_COMPLEX_IEEE_F16BE();
private static native final long H5T_COMPLEX_IEEE_F16LE();
private static native final long H5T_COMPLEX_IEEE_F32BE();
private static native final long H5T_COMPLEX_IEEE_F32LE();
private static native final long H5T_COMPLEX_IEEE_F64BE();
private static native final long H5T_COMPLEX_IEEE_F64LE();
private static native final int H5T_CSET_ERROR();
private static native final int H5T_CSET_ASCII();
@@ -2668,10 +2702,14 @@ 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();
private static native final long H5T_NATIVE_HBOOL();
@@ -2714,6 +2752,8 @@ public class HDF5Constants {
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();
private static native final long H5T_NATIVE_SCHAR();
+50
View File
@@ -2537,6 +2537,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;
@@ -2556,6 +2561,36 @@ Java_hdf_hdf5lib_HDF5Constants_H5T_1CONV_1INIT(JNIEnv *env, jclass cls)
{
return H5T_CONV_INIT;
}
JNIEXPORT jlong JNICALL
Java_hdf_hdf5lib_HDF5Constants_H5T_1COMPLEX_1IEEE_1F16BE(JNIEnv *env, jclass cls)
{
return H5T_COMPLEX_IEEE_F16BE;
}
JNIEXPORT jlong JNICALL
Java_hdf_hdf5lib_HDF5Constants_H5T_1COMPLEX_1IEEE_1F16LE(JNIEnv *env, jclass cls)
{
return H5T_COMPLEX_IEEE_F16LE;
}
JNIEXPORT jlong JNICALL
Java_hdf_hdf5lib_HDF5Constants_H5T_1COMPLEX_1IEEE_1F32BE(JNIEnv *env, jclass cls)
{
return H5T_COMPLEX_IEEE_F32BE;
}
JNIEXPORT jlong JNICALL
Java_hdf_hdf5lib_HDF5Constants_H5T_1COMPLEX_1IEEE_1F32LE(JNIEnv *env, jclass cls)
{
return H5T_COMPLEX_IEEE_F32LE;
}
JNIEXPORT jlong JNICALL
Java_hdf_hdf5lib_HDF5Constants_H5T_1COMPLEX_1IEEE_1F64BE(JNIEnv *env, jclass cls)
{
return H5T_COMPLEX_IEEE_F64BE;
}
JNIEXPORT jlong JNICALL
Java_hdf_hdf5lib_HDF5Constants_H5T_1COMPLEX_1IEEE_1F64LE(JNIEnv *env, jclass cls)
{
return H5T_COMPLEX_IEEE_F64LE;
}
JNIEXPORT jint JNICALL
Java_hdf_hdf5lib_HDF5Constants_H5T_1CSET_1ERROR(JNIEnv *env, jclass cls)
{
@@ -2877,6 +2912,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;
@@ -2887,6 +2927,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;
@@ -2992,6 +3037,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;
+22 -20
View File
@@ -1237,12 +1237,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);
@@ -1266,13 +1267,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);
@@ -1283,7 +1284,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);
}
@@ -1441,12 +1442,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);
@@ -1470,13 +1472,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);
@@ -1487,7 +1489,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);
}
+22 -20
View File
@@ -1253,12 +1253,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);
@@ -1282,13 +1283,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);
@@ -1299,7 +1300,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);
@@ -1478,12 +1479,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);
@@ -1507,13 +1509,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);
@@ -1524,7 +1526,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);
+19
View File
@@ -1641,6 +1641,25 @@ done:
return (jint)ndims;
} /* end Java_hdf_hdf5lib_H5_H5Tget_1array_1dims2 */
/*
* Class: hdf_hdf5lib_H5
* Method: _H5Tcomplex_create
* Signature: (J)J
*/
JNIEXPORT jlong JNICALL
Java_hdf_hdf5lib_H5__1H5Tcomplex_1create(JNIEnv *env, jclass clss, jlong base_id)
{
hid_t retVal = H5I_INVALID_HID;
UNUSED(clss);
if ((retVal = H5Tcomplex_create((hid_t)base_id)) < 0)
H5_LIBRARY_ERROR(ENVONLY);
done:
return (jlong)retVal;
} /* end Java_hdf_hdf5lib_H5__1H5Tcomplex_1create */
/*
* Class: hdf_hdf5lib_H5
* Method: H5Tconvert
+7
View File
@@ -479,6 +479,13 @@ JNIEXPORT jlong JNICALL Java_hdf_hdf5lib_H5__1H5Tarray_1create2(JNIEnv *, jclass
*/
JNIEXPORT jint JNICALL Java_hdf_hdf5lib_H5_H5Tget_1array_1dims2(JNIEnv *, jclass, jlong, jlongArray);
/*
* Class: hdf_hdf5lib_H5
* Method: _H5Tcomplex_create
* Signature: (J)J
*/
JNIEXPORT jlong JNICALL Java_hdf_hdf5lib_H5__1H5Tcomplex_1create(JNIEnv *, jclass, jlong);
/*
* Class: hdf_hdf5lib_H5
* Method: H5Tconvert
+282
View File
@@ -614,6 +614,43 @@ h5str_convert(JNIEnv *env, char **in_str, hid_t container, hid_t tid, void *out_
break;
}
case H5T_COMPLEX: {
size_t baseTypeSize;
if ((mtid = H5Tget_super(tid)) < 0)
H5_LIBRARY_ERROR(ENVONLY);
if (!(baseTypeSize = H5Tget_size(mtid)))
H5_LIBRARY_ERROR(ENVONLY);
if (NULL == (cptr = calloc(1, typeSize)))
H5_OUT_OF_MEMORY_ERROR(ENVONLY, "h5str_convert: failed to allocate array buffer");
/* Convert real part */
if (!(h5str_convert(ENVONLY, &this_str, container, mtid, out_buf, 0))) {
CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
goto done;
}
/* Skip any whitespace */
while (*this_str == ' ')
this_str++;
/* Convert imaginary part */
if (!(h5str_convert(ENVONLY, &this_str, container, mtid, out_buf, baseTypeSize))) {
CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
goto done;
}
if (H5Tclose(mtid) < 0)
H5_LIBRARY_ERROR(ENVONLY);
mtid = H5I_INVALID_HID;
retVal = typeSize;
break;
}
case H5T_NCLASSES:
case H5T_NO_CLASS: {
H5_BAD_ARGUMENT_ERROR(ENVONLY, "h5str_convert: invalid datatype class");
@@ -1476,6 +1513,48 @@ h5str_sprintf(JNIEnv *env, h5str_t *out_str, hid_t container, hid_t tid, void *i
break;
}
case H5T_COMPLEX: {
h5str_t real_part, imag_part;
size_t baseSize;
h5str_new(&real_part, 128);
h5str_new(&imag_part, 128);
/* Get the base datatype for the complex number type */
if ((mtid = H5Tget_super(tid)) < 0)
H5_LIBRARY_ERROR(ENVONLY);
if (!(baseSize = H5Tget_size(mtid)))
H5_LIBRARY_ERROR(ENVONLY);
if (!h5str_sprintf(ENVONLY, &real_part, container, mtid, cptr, expand_data))
CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
if (!h5str_sprintf(ENVONLY, &imag_part, container, mtid, cptr + baseSize, expand_data))
CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
if (!h5str_append(out_str, real_part.s))
H5_ASSERTION_ERROR(ENVONLY, "Unable to append string.");
if (NULL == strstr(imag_part.s, "-"))
if (!h5str_append(out_str, "+"))
H5_ASSERTION_ERROR(ENVONLY, "Unable to append string.");
if (!h5str_append(out_str, imag_part.s))
H5_ASSERTION_ERROR(ENVONLY, "Unable to append string.");
if (!h5str_append(out_str, "i"))
H5_ASSERTION_ERROR(ENVONLY, "Unable to append string.");
if (H5Tclose(mtid) < 0)
H5_LIBRARY_ERROR(ENVONLY);
mtid = H5I_INVALID_HID;
h5str_free(&real_part);
h5str_free(&imag_part);
break;
}
case H5T_NO_CLASS:
case H5T_NCLASSES: {
H5_BAD_ARGUMENT_ERROR(ENVONLY, "h5str_sprintf: invalid datatype class");
@@ -2110,6 +2189,17 @@ h5str_get_little_endian_type(hid_t tid)
break;
}
case H5T_COMPLEX: {
if (size == 4)
p_type = H5Tcopy(H5T_COMPLEX_IEEE_F16LE);
else if (size == 8)
p_type = H5Tcopy(H5T_COMPLEX_IEEE_F32LE);
else if (size == 16)
p_type = H5Tcopy(H5T_COMPLEX_IEEE_F64LE);
break;
}
case H5T_NO_CLASS:
case H5T_NCLASSES: {
goto done;
@@ -2206,6 +2296,17 @@ h5str_get_big_endian_type(hid_t tid)
break;
}
case H5T_COMPLEX: {
if (size == 4)
p_type = H5Tcopy(H5T_COMPLEX_IEEE_F16BE);
else if (size == 8)
p_type = H5Tcopy(H5T_COMPLEX_IEEE_F32BE);
else if (size == 16)
p_type = H5Tcopy(H5T_COMPLEX_IEEE_F64BE);
break;
}
case H5T_NO_CLASS:
case H5T_NCLASSES: {
goto done;
@@ -2462,6 +2563,32 @@ h5str_render_bin_output(FILE *stream, hid_t container, hid_t tid, void *_mem, hs
break;
}
case H5T_COMPLEX: {
hid_t memb = H5I_INVALID_HID;
if ((memb = H5Tget_super(tid)) < 0) {
ret_value = FAIL;
goto done;
}
for (block_index = 0; block_index < block_nelmts; block_index++) {
mem = ((unsigned char *)_mem) + block_index * size;
/* dump the complex number element */
if (h5str_render_bin_output(stream, container, memb, mem, 2) < 0) {
ret_value = FAIL;
break;
}
}
if (H5Tclose(memb) < 0) {
ret_value = FAIL;
goto done;
}
break;
}
case H5T_NO_CLASS:
case H5T_NCLASSES: {
ret_value = FAIL;
@@ -4306,6 +4433,39 @@ translate_atomic_rbuf(JNIEnv *env, jlong mem_type_id, H5T_class_t type_class, vo
break;
} /* H5T_STRING */
case H5T_COMPLEX: {
H5T_class_t base_class;
size_t base_size, typeCount;
void *objBuf = NULL;
if (!(typeSize = H5Tget_size(mem_type_id)))
H5_LIBRARY_ERROR(ENVONLY);
if ((memb = H5Tget_super(mem_type_id)) < 0)
H5_LIBRARY_ERROR(ENVONLY);
if (!(base_size = H5Tget_size(memb)))
H5_LIBRARY_ERROR(ENVONLY);
if ((base_class = H5Tget_class(memb)) < 0)
H5_LIBRARY_ERROR(ENVONLY);
typeCount = typeSize / base_size;
if (NULL == (objBuf = malloc(typeSize)))
H5_OUT_OF_MEMORY_ERROR(ENVONLY, "translate_atomic_rbuf: failed to allocate buffer");
memcpy((char *)objBuf, char_buf, typeSize);
/* The list we're going to return */
if (NULL == (jList = (jobjectArray)ENVPTR->NewObject(ENVONLY, arrCList, arrListMethod, 0)))
H5_OUT_OF_MEMORY_ERROR(ENVONLY, "translate_atomic_rbuf: failed to allocate list read buffer");
translate_rbuf(ENVONLY, jList, memb, base_class, (jsize)typeCount, objBuf);
jobj = jList;
if (objBuf)
free(objBuf);
break;
}
case H5T_TIME:
case H5T_NO_CLASS:
case H5T_NCLASSES:
@@ -4530,6 +4690,41 @@ translate_atomic_wbuf(JNIEnv *env, jobject in_obj, jlong mem_type_id, H5T_class_
}
break;
} /* H5T_STRING */
case H5T_COMPLEX: {
H5T_class_t base_class;
size_t base_size;
void *objBuf = NULL;
if (!(typeSize = H5Tget_size(mem_type_id)))
H5_LIBRARY_ERROR(ENVONLY);
if ((memb = H5Tget_super(mem_type_id)) < 0)
H5_LIBRARY_ERROR(ENVONLY);
if (!(base_size = H5Tget_size(memb)))
H5_LIBRARY_ERROR(ENVONLY);
if ((base_class = H5Tget_class(memb)) < 0)
H5_LIBRARY_ERROR(ENVONLY);
/* Convert each array element - invoke the toArray method */
if (mToArray == NULL)
CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
jobjectArray array = (jobjectArray)ENVPTR->CallObjectMethod(ENVONLY, in_obj, mToArray);
jsize jnelmts = ENVPTR->GetArrayLength(ENVONLY, array);
if (jnelmts < 0)
H5_BAD_ARGUMENT_ERROR(ENVONLY, "translate_atomic_wbuf: number of array elements < 0");
if (NULL == (objBuf = malloc((size_t)jnelmts * base_size)))
H5_OUT_OF_MEMORY_ERROR(ENVONLY, "translate_atomic_wbuf: failed to allocate buffer");
translate_wbuf(ENVONLY, array, memb, base_class, (jsize)jnelmts, objBuf);
memcpy(char_buf, (char *)objBuf, base_size * (size_t)jnelmts);
if (objBuf)
free(objBuf);
break;
}
case H5T_TIME:
case H5T_NO_CLASS:
case H5T_NCLASSES:
@@ -4752,6 +4947,60 @@ translate_rbuf(JNIEnv *env, jobjectArray ret_buf, jlong mem_type_id, H5T_class_t
}
break;
}
case H5T_COMPLEX: {
H5T_class_t base_class;
size_t base_size, typeCount;
void *objBuf = NULL;
if (!(typeSize = H5Tget_size(mem_type_id)))
H5_LIBRARY_ERROR(ENVONLY);
if ((memb = H5Tget_super(mem_type_id)) < 0)
H5_LIBRARY_ERROR(ENVONLY);
if (!(base_size = H5Tget_size(memb)))
H5_LIBRARY_ERROR(ENVONLY);
if ((base_class = H5Tget_class(memb)) < 0)
H5_LIBRARY_ERROR(ENVONLY);
typeCount = typeSize / base_size;
if (NULL == (objBuf = malloc(typeSize)))
H5_OUT_OF_MEMORY_ERROR(ENVONLY, "translate_atomic_rbuf: failed to allocate buffer");
/* Convert each element to a list of 2 floating-point elements */
for (i = 0; i < (size_t)count; i++) {
found_jList = JNI_TRUE;
jList = NULL;
/* Get the object element */
memcpy((char *)objBuf, char_buf + i * typeSize, typeSize);
/* The list we're going to return: */
if (i < (size_t)ret_buflen) {
if (NULL ==
(jList = ENVPTR->GetObjectArrayElement(ENVONLY, (jobjectArray)ret_buf, (jsize)i)))
found_jList = JNI_FALSE;
}
if (NULL == jList) {
if (NULL ==
(jList = (jobjectArray)ENVPTR->NewObject(ENVONLY, arrCList, arrListMethod, 0)))
H5_OUT_OF_MEMORY_ERROR(ENVONLY,
"translate_rbuf: failed to allocate list read buffer");
}
translate_rbuf(ENVONLY, jList, memb, base_class, (jsize)typeCount, objBuf);
if (found_jList == JNI_FALSE)
ENVPTR->CallBooleanMethod(ENVONLY, ret_buf, arrAddMethod, jList);
else
ENVPTR->SetObjectArrayElement(ENVONLY, ret_buf, (jsize)i, jList);
CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE);
ENVPTR->DeleteLocalRef(ENVONLY, jList);
}
if (objBuf)
free(objBuf);
break;
}
case H5T_TIME:
case H5T_NO_CLASS:
case H5T_NCLASSES:
@@ -4914,6 +5163,39 @@ translate_wbuf(JNIEnv *env, jobjectArray in_buf, jlong mem_type_id, H5T_class_t
}
break;
}
case H5T_COMPLEX: {
H5T_class_t base_class;
size_t base_size;
if ((memb = H5Tget_super(mem_type_id)) < 0)
H5_LIBRARY_ERROR(ENVONLY);
if (!(base_size = H5Tget_size(memb)))
H5_LIBRARY_ERROR(ENVONLY);
if ((base_class = H5Tget_class(memb)) < 0)
H5_LIBRARY_ERROR(ENVONLY);
/* Convert each list to an array element */
for (i = 0; i < (size_t)count; i++) {
if (NULL == (jList = ENVPTR->GetObjectArrayElement(ENVONLY, (jobjectArray)in_buf, (jsize)i)))
CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
/* invoke the toArray method */
if (mToArray == NULL)
CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
jobjectArray array = (jobjectArray)ENVPTR->CallObjectMethod(ENVONLY, jList, mToArray);
jsize jnelmts = ENVPTR->GetArrayLength(ENVONLY, array);
if (jnelmts < 0)
H5_BAD_ARGUMENT_ERROR(ENVONLY, "translate_wbuf: number of array elements < 0");
translate_wbuf(ENVONLY, array, memb, base_class, jnelmts,
char_buf + i * base_size * (size_t)jnelmts);
ENVPTR->DeleteLocalRef(ENVONLY, jList);
} /* end for (i = 0; i < count; i++) */
break;
}
case H5T_TIME:
case H5T_NO_CLASS:
case H5T_NCLASSES:
+54
View File
@@ -240,6 +240,60 @@ public class TestH5T {
}
}
@Test
public void testH5Tcomplex_create()
{
String class_name;
long[] fields1 = {0, 0, 0, 0, 0};
long[] fields2 = {0, 0, 0, 0, 0};
long filetype_id = HDF5Constants.H5I_INVALID_HID;
long dt_size = -1;
int typeclass = -1;
int typeorder = HDF5Constants.H5T_ORDER_ERROR;
int prec1 = 0;
int prec2 = 0;
try {
filetype_id = H5.H5Tcomplex_create(HDF5Constants.H5T_IEEE_F32LE);
assertTrue("testH5Tcomplex_create:H5Tcomplex_create", filetype_id >= 0);
typeclass = H5.H5Tget_class(filetype_id);
assertTrue("H5.H5Tget_class", typeclass > 0);
class_name = H5.H5Tget_class_name(typeclass);
assertTrue("H5.H5Tget_class_name", class_name.compareTo("H5T_COMPLEX") == 0);
dt_size = H5.H5Tget_size(filetype_id);
assertTrue("H5.H5Tget_size", dt_size == 8);
typeorder = H5.H5Tget_order(filetype_id);
assertTrue("H5.H5Tget_order", typeorder == HDF5Constants.H5T_ORDER_LE);
prec1 = H5.H5Tget_precision(HDF5Constants.H5T_IEEE_F32LE);
prec2 = H5.H5Tget_precision(filetype_id);
assertTrue("H5.H5Tget_precision", prec1 == prec2);
H5.H5Tget_fields(HDF5Constants.H5T_IEEE_F32LE, fields1);
H5.H5Tget_fields(filetype_id, fields2);
assertTrue("H5.H5Tget_fields[spos]", fields1[0] == fields2[0]);
assertTrue("H5.H5Tget_fields[epos]", fields1[1] == fields2[1]);
assertTrue("H5.H5Tget_fields[esize]", fields1[2] == fields2[2]);
assertTrue("H5.H5Tget_fields[mpos]", fields1[3] == fields2[3]);
assertTrue("H5.H5Tget_fields[msize]", fields1[4] == fields2[4]);
}
catch (Throwable err) {
err.printStackTrace();
fail("testH5Tcomplex_create " + err);
}
finally {
if (filetype_id >= 0)
try {
H5.H5Tclose(filetype_id);
}
catch (Exception ex) {
}
}
}
@Test
public void testH5Tenum_functions()
{
+2 -1
View File
@@ -11,9 +11,10 @@ JUnit version 4.13.2
.testH5Tcompound_functions
.testH5Tget_size
.testH5Tarray_create
.testH5Tcomplex_create
.testH5Topaque_functions
Time: XXXX
OK (13 tests)
OK (14 tests)