summaryrefslogtreecommitdiffstats
path: root/tools/test/h5dump/h5dumpgentest.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/test/h5dump/h5dumpgentest.c')
-rw-r--r--tools/test/h5dump/h5dumpgentest.c158
1 files changed, 158 insertions, 0 deletions
diff --git a/tools/test/h5dump/h5dumpgentest.c b/tools/test/h5dump/h5dumpgentest.c
index a4ad058..7894a4b 100644
--- a/tools/test/h5dump/h5dumpgentest.c
+++ b/tools/test/h5dump/h5dumpgentest.c
@@ -115,6 +115,7 @@
#define FILE85 "tgrpnullspace.h5"
#define FILE87 "tintsnodata.h5"
#define FILE88 "tldouble_scalar.h5"
+#define FILE89 "tfloatsattrs.h5"
/*-------------------------------------------------------------------------
* prototypes
@@ -395,6 +396,15 @@ typedef struct s1_t {
#define F83_RANK 1
#define F83_ARRAYDIM 3
+/* "FILE89" macros */
+#define F89_XDIM 8
+#define F89_DATASETF32 "DS32BITS"
+#define F89_YDIM32 32
+#define F89_DATASETF64 "DS64BITS"
+#define F89_YDIM64 64
+#define F89_DATASETF128 "DS128BITS"
+#define F89_YDIM128 128
+
static void
gent_group(void)
{
@@ -10172,6 +10182,152 @@ gent_intsattrs(void)
HDfree(asetdbl);
}
+/*-------------------------------------------------------------------------
+ * Function: gent_floatsattrs
+ *
+ * Purpose: Generate a file to be used in the h5dump tests.
+ * Three datasets of 4, 8 and 16 bytes of float types are created.
+ * Fill them with raw data such that no bit will be all zero in a dataset.
+ *-------------------------------------------------------------------------
+ */
+static void
+gent_floatsattrs(void)
+{
+ hid_t fid = H5I_INVALID_HID;
+ hid_t tid = H5I_INVALID_HID;
+ hid_t attr = H5I_INVALID_HID;
+ hid_t dataset = H5I_INVALID_HID;
+ hid_t space = H5I_INVALID_HID;
+ hid_t aspace = H5I_INVALID_HID;
+ hsize_t dims[2], adims[1];
+
+ float ** dset32 = NULL;
+ double ** dset64 = NULL;
+ long double **dset128 = NULL;
+
+ float * aset32 = NULL;
+ double * aset64 = NULL;
+ long double *aset128 = NULL;
+
+ float val32bits;
+ double val64bits;
+ long double val128bits;
+
+ unsigned int i, j;
+
+ /* Create arrays */
+ H5TEST_ALLOCATE_2D_ARRAY(dset32, float, F89_XDIM, F89_YDIM32);
+ H5TEST_ALLOCATE_2D_ARRAY(dset64, double, F89_XDIM, F89_YDIM64);
+ H5TEST_ALLOCATE_2D_ARRAY(dset128, long double, F89_XDIM, F89_YDIM128);
+
+ aset32 = HDcalloc(F89_XDIM * F89_YDIM32, sizeof(float));
+ aset64 = HDcalloc(F89_XDIM * F89_YDIM64, sizeof(double));
+ aset128 = HDcalloc(F89_XDIM * F89_YDIM128, sizeof(long double));
+
+ fid = H5Fcreate(FILE89, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
+
+ if ((tid = H5Tcopy(H5T_NATIVE_LDOUBLE)) < 0)
+ goto error;
+
+ if (H5Tget_size(tid) == 0)
+ goto error;
+
+ /* Dataset of 32 bits float */
+ dims[0] = F89_XDIM;
+ dims[1] = F89_YDIM32;
+ space = H5Screate_simple(2, dims, NULL);
+ dataset = H5Dcreate2(fid, F89_DATASETF32, H5T_IEEE_F32LE, space, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
+
+ val32bits = (float)F89_YDIM32;
+ for (i = 0; i < dims[0]; i++) {
+ dset32[i][0] = val32bits;
+ aset32[i * dims[1]] = dset32[i][0];
+ for (j = 1; j < dims[1]; j++) {
+ dset32[i][j] = (float)(j * dims[0] + i) / (float)F89_YDIM32;
+ aset32[i * dims[1] + j] = dset32[i][j];
+ }
+ val32bits -= (float)1;
+ }
+
+ H5Dwrite(dataset, H5T_IEEE_F32LE, H5S_ALL, H5S_ALL, H5P_DEFAULT, dset32[0]);
+ /* Attribute of 32 bits float */
+ adims[0] = F89_XDIM * F89_YDIM32;
+ aspace = H5Screate_simple(1, adims, NULL);
+ attr = H5Acreate2(dataset, F89_DATASETF32, H5T_IEEE_F32LE, aspace, H5P_DEFAULT, H5P_DEFAULT);
+ H5Awrite(attr, H5T_IEEE_F32LE, aset32);
+ H5Aclose(attr);
+ H5Sclose(aspace);
+ H5Sclose(space);
+ H5Dclose(dataset);
+
+ /* Dataset of 64 bits double */
+ dims[0] = F89_XDIM;
+ dims[1] = F89_YDIM64;
+ space = H5Screate_simple(2, dims, NULL);
+ dataset = H5Dcreate2(fid, F89_DATASETF64, H5T_IEEE_F64LE, space, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
+
+ val64bits = (double)F89_YDIM64;
+ for (i = 0; i < dims[0]; i++) {
+ dset64[i][0] = val64bits;
+ aset64[i * dims[1]] = dset64[i][0];
+ for (j = 1; j < dims[1]; j++) {
+ dset64[i][j] = (double)(j * dims[0] + i) / (double)F89_YDIM64;
+ aset64[i * dims[1] + j] = dset64[i][j];
+ }
+ val64bits -= (double)1;
+ }
+
+ H5Dwrite(dataset, H5T_IEEE_F64LE, H5S_ALL, H5S_ALL, H5P_DEFAULT, dset64[0]);
+ /* Attribute of 64 bits double */
+ adims[0] = F89_XDIM * F89_YDIM64;
+ aspace = H5Screate_simple(1, adims, NULL);
+ attr = H5Acreate2(dataset, F89_DATASETF64, H5T_IEEE_F64LE, aspace, H5P_DEFAULT, H5P_DEFAULT);
+ H5Awrite(attr, H5T_IEEE_F64LE, aset64);
+ H5Aclose(attr);
+ H5Sclose(aspace);
+ H5Sclose(space);
+ H5Dclose(dataset);
+
+ /* Dataset of 128 bits long double */
+ dims[0] = F89_XDIM;
+ dims[1] = F89_YDIM128;
+ space = H5Screate_simple(2, dims, NULL);
+ dataset = H5Dcreate2(fid, F89_DATASETF128, tid, space, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
+
+ val128bits = (long double)F89_YDIM128;
+ for (i = 0; i < dims[0]; i++) {
+ dset128[i][0] = val128bits;
+ aset128[i * dims[1]] = dset128[i][0];
+ for (j = 1; j < dims[1]; j++) {
+ dset128[i][j] = (long double)(j * dims[0] + i) / (long double)F89_YDIM128;
+ aset128[i * dims[1] + j] = dset128[i][j];
+ }
+ val128bits -= (long double)1;
+ }
+
+ H5Dwrite(dataset, tid, H5S_ALL, H5S_ALL, H5P_DEFAULT, dset128[0]);
+ /* Attribute of 128 bits long double */
+ adims[0] = F89_XDIM * F89_YDIM128;
+ aspace = H5Screate_simple(1, adims, NULL);
+ attr = H5Acreate2(dataset, F89_DATASETF128, tid, aspace, H5P_DEFAULT, H5P_DEFAULT);
+ H5Awrite(attr, tid, aset128);
+ H5Aclose(attr);
+ H5Sclose(aspace);
+ H5Sclose(space);
+ H5Dclose(dataset);
+
+error:
+ H5Fclose(fid);
+
+ HDfree(dset32);
+ HDfree(dset64);
+ HDfree(dset128);
+
+ HDfree(aset32);
+ HDfree(aset64);
+ HDfree(aset128);
+}
+
static void
gent_bitnopaquefields(void)
{
@@ -11016,6 +11172,7 @@ main(void)
gent_aindices();
gent_longlinks();
gent_ldouble();
+ gent_ldouble_scalar();
gent_binary();
gent_bigdims();
gent_hyperslab();
@@ -11039,6 +11196,7 @@ main(void)
gent_compound_ints();
gent_intattrscalars();
gent_intsattrs();
+ gent_floatsattrs();
gent_bitnopaquefields();
gent_nodata();