; hssize_t nblocks; herr_t ret; /* Generic return value */ /* Output message about test being performed */ MESSAGE(5, ("Testing Dataspace Encoding and Decoding\n")); /*------------------------------------------------------------------------- * Test encoding and decoding of simple dataspace and hyperslab selection. *------------------------------------------------------------------------- */ sid1 = H5Screate_simple(SPACE1_RANK, dims1, NULL); CHECK(sid1, FAIL, "H5Screate_simple"); ret = H5Sselect_hyperslab(sid1, H5S_SELECT_SET, start, stride, count, block); CHECK(ret, FAIL, "H5Sselect_hyperslab"); /* Encode simple data space in a buffer */ ret = H5Sencode(sid1, NULL, &sbuf_size); CHECK(ret, FAIL, "H5Sencode"); if(sbuf_size>0) sbuf = (unsigned char*)HDcalloc((size_t)1, sbuf_size); /* Try decoding bogus buffer */ H5E_BEGIN_TRY { ret = H5Sdecode(sbuf); } H5E_END_TRY; VERIFY(ret, FAIL, "H5Sdecode"); ret = H5Sencode(sid1, sbuf, &sbuf_size); CHECK(ret, FAIL, "H5Sencode"); /* Decode from the dataspace buffer and return an object handle */ decoded_sid1=H5Sdecode(sbuf); CHECK(decoded_sid1, FAIL, "H5Sdecode"); /* Verify the decoded dataspace */ n = H5Sget_simple_extent_npoints(decoded_sid1); CHECK(n, FAIL, "H5Sget_simple_extent_npoints"); VERIFY(n, SPACE1_DIM1 * SPACE1_DIM2 * SPACE1_DIM3, "H5Sget_simple_extent_npoints"); rank = H5Sget_simple_extent_ndims(decoded_sid1); CHECK(rank, FAIL, "H5Sget_simple_extent_ndims"); VERIFY(rank, SPACE1_RANK, "H5Sget_simple_extent_ndims"); rank = H5Sget_simple_extent_dims(decoded_sid1, tdims, NULL); CHECK(rank, FAIL, "H5Sget_simple_extent_dims"); VERIFY(HDmemcmp(tdims, dims1, SPACE1_RANK * sizeof(hsize_t)), 0, "H5Sget_simple_extent_dims"); /* Verify hyperslabe selection */ sel_type = H5Sget_select_type(decoded_sid1); VERIFY(sel_type, H5S_SEL_HYPERSLABS, "H5Sget_select_type"); nblocks = H5Sget_select_hyper_nblocks(decoded_sid1); VERIFY(nblocks, 2*2*2, "H5Sget_select_hyper_nblocks"); ret = H5Sclose(sid1); CHECK(ret, FAIL, "H5Sclose"); ret = H5Sclose(decoded_sid1); CHECK(ret, FAIL, "H5Sclose"); /*------------------------------------------------------------------------- * Test encoding and decoding of null dataspace. *------------------------------------------------------------------------- */ sid2 = H5Screate(H5S_NULL); CHECK(sid2, FAIL, "H5Screate"); /* Encode null data space in a buffer */ ret = H5Sencode(sid2, NULL, &null_size); CHECK(ret, FAIL, "H5Sencode"); if(null_size>0) null_sbuf = (unsigned char*)HDcalloc((size_t)1, null_size); ret = H5Sencode(sid2, null_sbuf, &null_size); CHECK(ret, FAIL, "H5Sencode"); /* Decode from the dataspace buffer and return an object handle */ decoded_sid2=H5Sdecode(null_sbuf); CHECK(decoded_sid2, FAIL, "H5Sdecode"); /* Verify decoded dataspace */ space_type = H5Sget_simple_extent_type(decoded_sid2); VERIFY(space_type, H5S_NULL, "H5Sget_simple_extent_type"); ret = H5Sclose(sid2); CHECK(ret, FAIL, "H5Sclose"); ret = H5Sclose(decoded_sid2); CHECK(ret, FAIL, "H5Sclose"); /*------------------------------------------------------------------------- * Test encoding and decoding of scalar dataspace. *------------------------------------------------------------------------- */ /* Create scalar dataspace */ sid3 = H5Screate(H5S_SCALAR); CHECK(sid3, FAIL, "H5Screate_simple"); /* Encode scalar data space in a buffer */ ret = H5Sencode(sid3, NULL, &scalar_size); CHECK(ret, FAIL, "H5Sencode"); if(scalar_size>0) scalar_buf = (unsigned char*)HDcalloc((size_t)1, scalar_size); ret = H5Sencode(sid3, scalar_buf, &scalar_size); CHECK(ret, FAIL, "H5Sencode"); /* Decode from the dataspace buffer and return an object handle */ decoded_sid3=H5Sdecode(scalar_buf); CHECK(decoded_sid3, FAIL, "H5Sdecode"); /* Verify extent type */ space_type = H5Sget_simple_extent_type(decoded_sid3); VERIFY(space_type, H5S_SCALAR, "H5Sget_simple_extent_type"); /* Verify decoded dataspace */ n = H5Sget_simple_extent_npoints(decoded_sid3); CHECK(n, FAIL, "H5Sget_simple_extent_npoints"); VERIFY(n, 1, "H5Sget_simple_extent_npoints"); rank = H5Sget_simple_extent_ndims(decoded_sid3); CHECK(rank, FAIL, "H5Sget_simple_extent_ndims"); VERIFY(rank, 0, "H5Sget_simple_extent_ndims"); ret = H5Sclose(sid3); CHECK(ret, FAIL, "H5Sclose"); ret = H5Sclose(decoded_sid3); CHECK(ret, FAIL, "H5Sclose"); HDfree(sbuf); HDfree(null_sbuf); HDfree(scalar_buf); } /* test_h5s_encode() */ /**************************************************************** ** ** test_h5s_scalar_write(): Test scalar H5S (dataspace) writing code. ** ****************************************************************/ static void test_h5s_scalar_write(void) { hid_t fid1; /* HDF5 File IDs */ hid_t dataset; /* Dataset ID */ hid_t sid1; /* Dataspace ID */ int rank; /* Logical rank of dataspace */ hsize_t tdims[4]; /* Dimension array to test with */ hssize_t n; /* Number of dataspace elements */ H5S_class_t ext_type; /* Extent type */ herr_t ret; /* Generic return value */ /* Output message about test being performed */ MESSAGE(5, ("Testing Scalar Dataspace Manipulation during Writing\n")); /* Create file */ fid1 = H5Fcreate(DATAFILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); CHECK(fid1, FAIL, "H5Fcreate"); /* Verify a non-zero rank fails with a NULL dimension. */ H5E_BEGIN_TRY { sid1 = H5Screate_simple(SPACE1_RANK, NULL, NULL); } H5E_END_TRY VERIFY(sid1, FAIL, "H5Screate_simple"); /* Create scalar dataspace */ sid1 = H5Screate_simple(SPACE3_RANK, NULL, NULL); CHECK(sid1, FAIL, "H5Screate_simple"); n = H5Sget_simple_extent_npoints(sid1); CHECK(n, FAIL, "H5Sget_simple_extent_npoints"); VERIFY(n, 1, "H5Sget_simple_extent_npoints"); rank = H5Sget_simple_extent_ndims(sid1); CHECK(rank, FAIL, "H5Sget_simple_extent_ndims"); VERIFY(rank, SPACE3_RANK, "H5Sget_simple_extent_ndims"); rank = H5Sget_simple_extent_dims(sid1, tdims, NULL); VERIFY(rank, 0, "H5Sget_simple_extent_dims"); /* Verify extent type */ ext_type = H5Sget_simple_extent_type(sid1); VERIFY(ext_type, H5S_SCALAR, "H5Sget_simple_extent_type"); /* Create a dataset */ dataset = H5Dcreate2(fid1, "Dataset1", H5T_NATIVE_UINT, sid1, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); CHECK(dataset, FAIL, "H5Dcreate2"); ret = H5Dwrite(dataset, H5T_NATIVE_UINT, H5S_ALL, H5S_ALL, H5P_DEFAULT, &space3_data); CHECK(ret, FAIL, "H5Dwrite"); /* Close Dataset */ ret = H5Dclose(dataset); CHECK(ret, FAIL, "H5Dclose"); /* Close scalar dataspace */ ret = H5Sclose(sid1); CHECK(ret, FAIL, "H5Sclose"); /* Close file */ ret = H5Fclose(fid1); CHECK(ret, FAIL, "H5Fclose"); } /* test_h5s_scalar_write() */ /**************************************************************** ** ** test_h5s_scalar_read(): Test scalar H5S (dataspace) reading code. ** ****************************************************************/ static void test_h5s_scalar_read(void) { hid_t fid1; /* HDF5 File IDs */ hid_t dataset; /* Dataset ID */ hid_t sid1; /* Dataspace ID */ int rank; /* Logical rank of dataspace */ hsize_t tdims[4]; /* Dimension array to test with */ hssize_t n; /* Number of dataspace elements */ unsigned rdata; /* Scalar data read in */ herr_t ret; /* Generic return value */ H5S_class_t ext_type; /* Extent type */ /* Output message about test being performed */ MESSAGE(5, ("Testing Scalar Dataspace Manipulation during Reading\n")); /* Create file */ fid1 = H5Fopen(DATAFILE, H5F_ACC_RDWR, H5P_DEFAULT); CHECK(fid1, FAIL, "H5Fopen"); /* Create a dataset */ dataset = H5Dopen2(fid1, "Dataset1", H5P_DEFAULT); CHECK(dataset, FAIL, "H5Dopen2"); sid1 = H5Dget_space(dataset); CHECK(sid1, FAIL, "H5Dget_space"); n = H5Sget_simple_extent_npoints(sid1); CHECK(n, FAIL, "H5Sget_simple_extent_npoints"); VERIFY(n, 1, "H5Sget_simple_extent_npoints"); rank = H5Sget_simple_extent_ndims(sid1); CHECK(rank, FAIL, "H5Sget_simple_extent_ndims"); VERIFY(rank, SPACE3_RANK, "H5Sget_simple_exte