summaryrefslogtreecommitdiffstats
path: root/test/ntypes.c
diff options
context:
space:
mode:
Diffstat (limited to 'test/ntypes.c')
-rw-r--r--test/ntypes.c121
1 files changed, 121 insertions, 0 deletions
diff --git a/test/ntypes.c b/test/ntypes.c
index f36a600..5d6b371 100644
--- a/test/ntypes.c
+++ b/test/ntypes.c
@@ -40,6 +40,9 @@ static const char *FILENAME[] = {"ntypes", NULL};
#define DSET_OPAQUE_NAME "opaque_type"
#define DSET1_BITFIELD_NAME "bitfield_type_1"
#define DSET2_BITFIELD_NAME "bitfield_type_2"
+#ifdef H5_HAVE__FLOAT16
+#define DSET_FLOAT16_NAME "_Float16_type"
+#endif
#define SPACE1_DIM1 4
#define SPACE1_RANK 1
@@ -3051,6 +3054,120 @@ error:
return -1;
} /* end test_ninteger() */
+#ifdef H5_HAVE__FLOAT16
+static herr_t
+test__Float16(hid_t file)
+{
+ hsize_t dims[2];
+ hid_t dataset = H5I_INVALID_HID;
+ hid_t space = H5I_INVALID_HID;
+ hid_t dtype = H5I_INVALID_HID;
+ hid_t native_type = H5I_INVALID_HID;
+ struct {
+ H5__Float16 arr[DIM0][DIM1];
+ } *ipoints = NULL;
+ struct {
+ H5__Float16 arr[DIM0][DIM1];
+ } *icheck = NULL;
+
+ TESTING("_Float16 datatype");
+
+ if (NULL == (ipoints = calloc(1, sizeof(*ipoints))))
+ TEST_ERROR;
+ if (NULL == (icheck = calloc(1, sizeof(*icheck))))
+ TEST_ERROR;
+
+ /* Initialize the data */
+ for (size_t i = 0; i < DIM0; i++)
+ for (size_t j = 0; j < DIM1; j++)
+ ipoints->arr[i][j] = (H5__Float16)(HDrand() / (double)RAND_MAX);
+
+ /* Create the data space */
+ dims[0] = DIM0;
+ dims[1] = DIM1;
+ if ((space = H5Screate_simple(2, dims, NULL)) < 0)
+ TEST_ERROR;
+
+ if ((dataset = H5Dcreate2(file, DSET_FLOAT16_NAME, H5T_IEEE_F16BE, space, H5P_DEFAULT, H5P_DEFAULT,
+ H5P_DEFAULT)) < 0)
+ TEST_ERROR;
+
+ /* Write the data to the dataset */
+ if (H5Dwrite(dataset, H5T_NATIVE_FLOAT16, H5S_ALL, H5S_ALL, H5P_DEFAULT, ipoints) < 0)
+ TEST_ERROR;
+
+ /* Close dataset */
+ if (H5Dclose(dataset) < 0)
+ TEST_ERROR;
+
+ /* Open dataset again to check H5Tget_native_type */
+ if ((dataset = H5Dopen2(file, DSET_FLOAT16_NAME, H5P_DEFAULT)) < 0)
+ TEST_ERROR;
+
+ if ((dtype = H5Dget_type(dataset)) < 0)
+ TEST_ERROR;
+
+ if ((native_type = H5Tget_native_type(dtype, H5T_DIR_DEFAULT)) < 0)
+ TEST_ERROR;
+
+ /* Verify the datatype retrieved and converted */
+ if (H5Tget_order(native_type) != H5Tget_order(H5T_NATIVE_FLOAT16))
+ TEST_ERROR;
+ if (H5Tget_size(native_type) != H5Tget_size(H5T_IEEE_F16BE))
+ TEST_ERROR;
+ if (H5T_FLOAT != H5Tget_class(native_type))
+ TEST_ERROR;
+
+ /* Read the dataset back */
+ if (H5Dread(dataset, native_type, H5S_ALL, H5S_ALL, H5P_DEFAULT, icheck) < 0)
+ TEST_ERROR;
+
+ /* Check that the values read are the same as the values written */
+ for (size_t i = 0; i < DIM0; i++)
+ for (size_t j = 0; j < DIM1; j++) {
+ if (!H5_FLT16_ABS_EQUAL(ipoints->arr[i][j], icheck->arr[i][j])) {
+ H5_FAILED();
+ printf(" Read different values than written.\n");
+ printf(" At index %zu,%zu\n", i, j);
+ goto error;
+ } /* end if */
+ }
+
+ if (H5Sclose(space) < 0)
+ TEST_ERROR;
+ if (H5Dclose(dataset) < 0)
+ TEST_ERROR;
+ if (H5Tclose(native_type) < 0)
+ TEST_ERROR;
+ if (H5Tclose(dtype) < 0)
+ TEST_ERROR;
+
+ free(ipoints);
+ ipoints = NULL;
+ free(icheck);
+ icheck = NULL;
+
+ PASSED();
+
+ return 0;
+
+error:
+ H5E_BEGIN_TRY
+ {
+ H5Dclose(dataset);
+ H5Tclose(native_type);
+ H5Tclose(dtype);
+ H5Sclose(space);
+ }
+ H5E_END_TRY
+
+ free(ipoints);
+ free(icheck);
+
+ return -1;
+}
+#endif
+
/*-------------------------------------------------------------------------
* Function: main
*
@@ -3101,6 +3218,10 @@ main(void)
nerrors += test_bitfield_dtype(file) < 0 ? 1 : 0;
nerrors += test_ninteger() < 0 ? 1 : 0;
+#ifdef H5_HAVE__FLOAT16
+ nerrors += test__Float16(file) < 0 ? 1 : 0;
+#endif
+
if (H5Fclose(file) < 0)
goto error;