diff options
author | Neil Fortner <nfortne2@hdfgroup.org> | 2017-03-16 21:22:46 (GMT) |
---|---|---|
committer | Neil Fortner <nfortne2@hdfgroup.org> | 2017-03-16 21:22:46 (GMT) |
commit | 3943452ff3cc26938fd69c1d75380bb7d0edb8ef (patch) | |
tree | b4dde897e7fb27446c0ab17a4bbb75cf908de358 /examples/h5dsm_ttconv.c | |
parent | 89d1b13319bc7790333236fb607d7d7f18d088b8 (diff) | |
download | hdf5-3943452ff3cc26938fd69c1d75380bb7d0edb8ef.zip hdf5-3943452ff3cc26938fd69c1d75380bb7d0edb8ef.tar.gz hdf5-3943452ff3cc26938fd69c1d75380bb7d0edb8ef.tar.bz2 |
Add support for datatype conversion with datasets, including with
partial I/O. Add test cases covering this to h5dsm_ttconv.c. Other
fixes to general type conversion code. Other minor fixes/cleanup.
Diffstat (limited to 'examples/h5dsm_ttconv.c')
-rw-r--r-- | examples/h5dsm_ttconv.c | 1103 |
1 files changed, 1097 insertions, 6 deletions
diff --git a/examples/h5dsm_ttconv.c b/examples/h5dsm_ttconv.c index ddfa847..9f07c31 100644 --- a/examples/h5dsm_ttconv.c +++ b/examples/h5dsm_ttconv.c @@ -20,16 +20,20 @@ hbool_t verbose_g = 1; int main(int argc, char *argv[]) { uuid_t pool_uuid; char *pool_grp = NULL; - hid_t file = -1, dset = -1, dset_a = -1, dset_b = -1, dset_c = -1, attr = -1, attr_a = -1, attr_b = -1 , attr_c = -1, space = -1, fapl = -1; + hid_t file = -1, dset = -1, dset_a = -1, dset_b = -1, dset_c = -1, dset2 = -1, attr = -1, attr_a = -1, attr_b = -1 , attr_c = -1, space = -1, space2 = -1, space2_contig, fapl = -1; hid_t file_type = -1, file_type_a = -1, file_type_b = -1, file_type_c = -1; hid_t mem_type = -1, mem_type_conv = -1, mem_type_a = -1, mem_type_b = -1, mem_type_c = -1; - hsize_t dims[1] = {4}; + hsize_t dims[2] = {4, 2}; + hsize_t start[2], count[2]; type_all buf[4]; type_all file_buf[4]; + type_all file_buf2[4][2]; type_convall buf_conv[4]; + type_convall buf2[4][2]; const type_all buf_init[4] = {{-1, 'a', (double)-1.}, {-2, 'b', (double)-2.}, {-3, 'c', (double)-3.}, {-4, 'd', (double)-4.}}; const type_convall buf_conv_init[4] = {{(long long)-5, 'e', (float)-5.}, {(long long)-6, 'f', (float)-6.}, {(long long)-7, 'g', (float)-7.}, {(long long)-8, 'h', (float)-8.}}; - int i; + const type_convall buf2_init[4][2] = {{{(long long)-1, 'a', (float)-1.}, {(long long)-2, 'b', (float)-2.}}, {{(long long)-3, 'c', (float)-3.}, {(long long)-4, 'd', (float)-4.}}, {{(long long)-5, 'e', (float)-5.}, {(long long)-6, 'f', (float)-6.}}, {{(long long)-7, 'g', (float)-7.}, {(long long)-8, 'h', (float)-8.}}}; + int i, j, i2; (void)MPI_Init(&argc, &argv); @@ -61,6 +65,14 @@ int main(int argc, char *argv[]) { if((space = H5Screate_simple(1, dims, NULL)) < 0) ERROR; + /* Set up 2-D dataspace */ + if((space2 = H5Screate_simple(2, dims, NULL)) < 0) + ERROR; + + /* Set up second 2-D dataspace */ + if((space2_contig = H5Screate_simple(2, dims, NULL)) < 0) + ERROR; + /* * Set up types */ @@ -130,6 +142,9 @@ int main(int argc, char *argv[]) { if(H5Tinsert(mem_type_c, "c", HOFFSET(type_convall, c), H5T_NATIVE_FLOAT) < 0) ERROR; + /* + * Create objects + */ /* Create dataset */ if((dset = H5Dcreate2(file, "dset", file_type, space, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) ERROR; @@ -146,6 +161,10 @@ int main(int argc, char *argv[]) { if((dset_c = H5Dcreate2(file, "dset_c", file_type_c, space, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) ERROR; + /* Create 2-D dataset */ + if((dset2 = H5Dcreate2(file, "dset2", file_type, space2, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) + ERROR; + /* Create attribute */ if((attr = H5Acreate2(dset, "attr", file_type, space, H5P_DEFAULT, H5P_DEFAULT)) < 0) ERROR; @@ -163,6 +182,25 @@ int main(int argc, char *argv[]) { ERROR; /* + * Create selections + */ + /* Create non-contiguous 2-D selection */ + start[0] = 0; + start[1] = 1; + count[0] = 4; + count[1] = 1; + if(H5Sselect_hyperslab(space2, H5S_SELECT_SET, start, NULL, count, NULL) < 0) + ERROR; + + /* Create contiguous 2-D selection */ + start[0] = 1; + start[1] = 0; + count[0] = 2; + count[1] = 2; + if(H5Sselect_hyperslab(space2_contig, H5S_SELECT_SET, start, NULL, count, NULL) < 0) + ERROR; + + /* * Test attribute */ /* @@ -329,7 +367,7 @@ int main(int argc, char *argv[]) { /* Check buffer */ for(i = 0; i< dims[0]; i++) { - if(file_buf[i].a != (int)buf_conv[i].a) + if((long long)file_buf[i].a != buf_conv[i].a) PRINTF_ERROR("Member a at location %d does not match", i); if(file_buf[i].b != buf_conv[i].b) PRINTF_ERROR("Member b at location %d does not match", i); @@ -564,7 +602,7 @@ int main(int argc, char *argv[]) { /* Check buffer */ for(i = 0; i< dims[0]; i++) { - if(file_buf[i].a != (int)buf_conv[i].a) + if((long long)file_buf[i].a != buf_conv[i].a) PRINTF_ERROR("Member a at location %d does not match", i); if(buf_conv_init[i].b != buf_conv[i].b) PRINTF_ERROR("Member b at location %d does not match", i); @@ -705,7 +743,7 @@ int main(int argc, char *argv[]) { /* Check buffer */ for(i = 0; i< dims[0]; i++) { - if(file_buf[i].a != (int)buf_conv[i].a) + if((long long)file_buf[i].a != buf_conv[i].a) PRINTF_ERROR("Member a at location %d does not match", i); if(buf_conv_init[i].b != buf_conv[i].b) PRINTF_ERROR("Member b at location %d does not match", i); @@ -845,6 +883,1050 @@ int main(int argc, char *argv[]) { printf("\n"); /* + * Test dataset + */ + /* + * Full write/read, no member conversion + */ + /* Fill buffer */ + for(i = 0; i < dims[0]; i++) { + buf[i].a = rand() % 10; + buf[i].b = 'A' + (char)(rand() % 26); + buf[i].c = (double)(rand() % 100) / (double)10; + } /* end for */ + + /* Print message */ + if(verbose_g) { + printf("Writing dataset with no member conversion\n"); + printf("buf = {"); + for(i = 0; i < dims[0]; i++) { + if(i > 0) + printf(", "); + printf("{%d, %c, %.1f}", buf[i].a, buf[i].b, buf[i].c); + } /* end for */ + printf("}\n"); + } /* end if */ + + /* Write data */ + if(H5Dwrite(dset, mem_type, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf) < 0) + ERROR; + + /* Update file_buf */ + for(i = 0; i < dims[0]; i++) { + file_buf[i].a = buf[i].a; + file_buf[i].b = buf[i].b; + file_buf[i].c = buf[i].c; + } /* end for */ + + /* Read data */ + memcpy(buf, buf_init, sizeof(buf)); + if(H5Dread(dset, mem_type, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf) < 0) + ERROR; + + /* Print message */ + if(verbose_g) { + printf("Read dataset with no member conversion\n"); + printf("exp = {"); + for(i = 0; i < dims[0]; i++) { + if(i > 0) + printf(", "); + printf("{%d, %c, %.1f}", file_buf[i].a, file_buf[i].b, file_buf[i].c); + } /* end for */ + printf("}\n"); + printf("buf = {"); + for(i = 0; i < dims[0]; i++) { + if(i > 0) + printf(", "); + printf("{%d, %c, %.1f}", buf[i].a, buf[i].b, buf[i].c); + } /* end for */ + printf("}\n"); + } /* end if */ + + /* Check buffer */ + for(i = 0; i< dims[0]; i++) { + if(file_buf[i].a != buf[i].a) + PRINTF_ERROR("Member a at location %d does not match", i); + if(file_buf[i].b != buf[i].b) + PRINTF_ERROR("Member b at location %d does not match", i); + if(((file_buf[i].c - buf[i].c) > (double)0.01) + || ((file_buf[i].c - buf[i].c) < (double)-0.01)) + PRINTF_ERROR("Member c at location %d does not match", i); + } /* end for */ + + printf("\n"); + + /* + * Full write/read, with member conversion + */ + /* Fill buffer */ + for(i = 0; i < dims[0]; i++) { + buf_conv[i].a = (long long)(rand() % 10); + buf_conv[i].b = 'A' + (char)(rand() % 26); + buf_conv[i].c = (float)(rand() % 100) / (float)10; + } /* end for */ + + /* Print message */ + if(verbose_g) { + printf("Writing dataset with member conversion\n"); + printf("buf = {"); + for(i = 0; i < dims[0]; i++) { + if(i > 0) + printf(", "); + printf("{%lld, %c, %.1f}", buf_conv[i].a, buf_conv[i].b, (double)buf_conv[i].c); + } /* end for */ + printf("}\n"); + } /* end if */ + + /* Write data */ + if(H5Dwrite(dset, mem_type_conv, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf_conv) < 0) + ERROR; + + /* Update file_buf */ + for(i = 0; i < dims[0]; i++) { + file_buf[i].a = (int)buf_conv[i].a; + file_buf[i].b = buf_conv[i].b; + file_buf[i].c = (double)buf_conv[i].c; + } /* end for */ + + /* Read data */ + memcpy(buf, buf_init, sizeof(buf)); + if(H5Dread(dset, mem_type, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf) < 0) + ERROR; + + /* Print message */ + if(verbose_g) { + printf("Read dataset with no member conversion\n"); + printf("exp = {"); + for(i = 0; i < dims[0]; i++) { + if(i > 0) + printf(", "); + printf("{%d, %c, %.1f}", file_buf[i].a, file_buf[i].b, file_buf[i].c); + } /* end for */ + printf("}\n"); + printf("buf = {"); + for(i = 0; i < dims[0]; i++) { + if(i > 0) + printf(", "); + printf("{%d, %c, %.1f}", buf[i].a, buf[i].b, buf[i].c); + } /* end for */ + printf("}\n"); + } /* end if */ + + /* Check buffer */ + for(i = 0; i< dims[0]; i++) { + if(file_buf[i].a != buf[i].a) + PRINTF_ERROR("Member a at location %d does not match", i); + if(file_buf[i].b != buf[i].b) + PRINTF_ERROR("Member b at location %d does not match", i); + if(((file_buf[i].c - buf[i].c) > (double)0.01) + || ((file_buf[i].c - buf[i].c) < (double)-0.01)) + PRINTF_ERROR("Member c at location %d does not match", i); + } /* end for */ + + /* Read data */ + memcpy(buf_conv, buf_conv_init, sizeof(buf_conv)); + if(H5Dread(dset, mem_type_conv, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf_conv) < 0) + ERROR; + + /* Print message */ + if(verbose_g) { + printf("Read dataset with member conversion\n"); + printf("exp = {"); + for(i = 0; i < dims[0]; i++) { + if(i > 0) + printf(", "); + printf("{%d, %c, %.1f}", file_buf[i].a, file_buf[i].b, file_buf[i].c); + } /* end for */ + printf("}\n"); + printf("buf = {"); + for(i = 0; i < dims[0]; i++) { + if(i > 0) + printf(", "); + printf("{%lld, %c, %.1f}", buf_conv[i].a, buf_conv[i].b, (double)buf_conv[i].c); + } /* end for */ + printf("}\n"); + } /* end if */ + + /* Check buffer */ + for(i = 0; i< dims[0]; i++) { + if((long long)file_buf[i].a != buf_conv[i].a) + PRINTF_ERROR("Member a at location %d does not match", i); + if(file_buf[i].b != buf_conv[i].b) + PRINTF_ERROR("Member b at location %d does not match", i); + if(((file_buf[i].c - (double)buf_conv[i].c) > (double)0.01) + || ((file_buf[i].c - (double)buf_conv[i].c) < (double)-0.01)) + PRINTF_ERROR("Member c at location %d does not match", i); + } /* end for */ + + printf("\n"); + + /* + * Write by parts + */ + /* Fill buffer */ + for(i = 0; i < dims[0]; i++) { + buf_conv[i].a = (long long)(rand() % 10); + buf_conv[i].b = 'A' + (char)(rand() % 26); + buf_conv[i].c = (float)(rand() % 100) / (float)10; + } /* end for */ + + /* Print message */ + if(verbose_g) { + printf("Writing dataset compound member \'a\'\n"); + printf("buf = {"); + for(i = 0; i < dims[0]; i++) { + if(i > 0) + printf(", "); + printf("{%lld, %c, %.1f}", buf_conv[i].a, buf_conv[i].b, (double)buf_conv[i].c); + } /* end for */ + printf("}\n"); + } /* end if */ + + /* Write data */ + if(H5Dwrite(dset, mem_type_a, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf_conv) < 0) + ERROR; + + /* Update file_buf */ + for(i = 0; i < dims[0]; i++) + file_buf[i].a = (int)buf_conv[i].a; + + /* Read data */ + memcpy(buf, buf_init, sizeof(buf)); + if(H5Dread(dset, mem_type, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf) < 0) + ERROR; + + /* Print message */ + if(verbose_g) { + printf("Read dataset with no member conversion\n"); + printf("exp = {"); + for(i = 0; i < dims[0]; i++) { + if(i > 0) + printf(", "); + printf("{%d, %c, %.1f}", file_buf[i].a, file_buf[i].b, file_buf[i].c); + } /* end for */ + printf("}\n"); + printf("buf = {"); + for(i = 0; i < dims[0]; i++) { + if(i > 0) + printf(", "); + printf("{%d, %c, %.1f}", buf[i].a, buf[i].b, buf[i].c); + } /* end for */ + printf("}\n"); + } /* end if */ + + /* Check buffer */ + for(i = 0; i< dims[0]; i++) { + if(file_buf[i].a != buf[i].a) + PRINTF_ERROR("Member a at location %d does not match", i); + if(file_buf[i].b != buf[i].b) + PRINTF_ERROR("Member b at location %d does not match", i); + if(((file_buf[i].c - buf[i].c) > (double)0.01) + || ((file_buf[i].c - buf[i].c) < (double)-0.01)) + PRINTF_ERROR("Member c at location %d does not match", i); + } /* end for */ + + printf("\n"); + + /* Fill buffer */ + for(i = 0; i < dims[0]; i++) { + buf_conv[i].a = (long long)(rand() % 10); + buf_conv[i].b = 'A' + (char)(rand() % 26); + buf_conv[i].c = (float)(rand() % 100) / (float)10; + } /* end for */ + + /* Print message */ + if(verbose_g) { + printf("Writing dataset compound member \'b\'\n"); + printf("buf = {"); + for(i = 0; i < dims[0]; i++) { + if(i > 0) + printf(", "); + printf("{%lld, %c, %.1f}", buf_conv[i].a, buf_conv[i].b, (double)buf_conv[i].c); + } /* end for */ + printf("}\n"); + } /* end if */ + + /* Write data */ + if(H5Dwrite(dset, mem_type_b, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf_conv) < 0) + ERROR; + + /* Update file_buf */ + for(i = 0; i < dims[0]; i++) + file_buf[i].b = buf_conv[i].b; + + /* Read data */ + memcpy(buf, buf_init, sizeof(buf)); + if(H5Dread(dset, mem_type, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf) < 0) + ERROR; + + /* Print message */ + if(verbose_g) { + printf("Read dataset with no member conversion\n"); + printf("exp = {"); + for(i = 0; i < dims[0]; i++) { + if(i > 0) + printf(", "); + printf("{%d, %c, %.1f}", file_buf[i].a, file_buf[i].b, file_buf[i].c); + } /* end for */ + printf("}\n"); + printf("buf = {"); + for(i = 0; i < dims[0]; i++) { + if(i > 0) + printf(", "); + printf("{%d, %c, %.1f}", buf[i].a, buf[i].b, buf[i].c); + } /* end for */ + printf("}\n"); + } /* end if */ + + /* Check buffer */ + for(i = 0; i< dims[0]; i++) { + if(file_buf[i].a != buf[i].a) + PRINTF_ERROR("Member a at location %d does not match", i); + if(file_buf[i].b != buf[i].b) + PRINTF_ERROR("Member b at location %d does not match", i); + if(((file_buf[i].c - buf[i].c) > (double)0.01) + || ((file_buf[i].c - buf[i].c) < (double)-0.01)) + PRINTF_ERROR("Member c at location %d does not match", i); + } /* end for */ + + printf("\n"); + + /* Fill buffer */ + for(i = 0; i < dims[0]; i++) { + buf_conv[i].a = (long long)(rand() % 10); + buf_conv[i].b = 'A' + (char)(rand() % 26); + buf_conv[i].c = (float)(rand() % 100) / (float)10; + } /* end for */ + + /* Print message */ + if(verbose_g) { + printf("Writing dataset compound member \'c\'\n"); + printf("buf = {"); + for(i = 0; i < dims[0]; i++) { + if(i > 0) + printf(", "); + printf("{%lld, %c, %.1f}", buf_conv[i].a, buf_conv[i].b, (double)buf_conv[i].c); + } /* end for */ + printf("}\n"); + } /* end if */ + + /* Write data */ + if(H5Dwrite(dset, mem_type_c, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf_conv) < 0) + ERROR; + + /* Update file_buf */ + for(i = 0; i < dims[0]; i++) + file_buf[i].c = (double)buf_conv[i].c; + + /* Read data */ + memcpy(buf, buf_init, sizeof(buf)); + if(H5Dread(dset, mem_type, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf) < 0) + ERROR; + + /* Print message */ + if(verbose_g) { + printf("Read dataset with no member conversion\n"); + printf("exp = {"); + for(i = 0; i < dims[0]; i++) { + if(i > 0) + printf(", "); + printf("{%d, %c, %.1f}", file_buf[i].a, file_buf[i].b, file_buf[i].c); + } /* end for */ + printf("}\n"); + printf("buf = {"); + for(i = 0; i < dims[0]; i++) { + if(i > 0) + printf(", "); + printf("{%d, %c, %.1f}", buf[i].a, buf[i].b, buf[i].c); + } /* end for */ + printf("}\n"); + } /* end if */ + + /* Check buffer */ + for(i = 0; i< dims[0]; i++) { + if(file_buf[i].a != buf[i].a) + PRINTF_ERROR("Member a at location %d does not match", i); + if(file_buf[i].b != buf[i].b) + PRINTF_ERROR("Member b at location %d does not match", i); + if(((file_buf[i].c - buf[i].c) > (double)0.01) + || ((file_buf[i].c - buf[i].c) < (double)-0.01)) + PRINTF_ERROR("Member c at location %d does not match", i); + } /* end for */ + + printf("\n"); + + /* + * Read by parts + */ + /* Read member a */ + memcpy(buf_conv, buf_conv_init, sizeof(buf_conv)); + if(H5Dread(dset, mem_type_a, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf_conv) < 0) + ERROR; + + /* Print message */ + if(verbose_g) { + printf("Read full dataset compound member \'a\'\n"); + printf("exp = {"); + for(i = 0; i < dims[0]; i++) { + if(i > 0) + printf(", "); + printf("{%d, %c, %.1f}", file_buf[i].a, buf_conv_init[i].b, (double)buf_conv_init[i].c); + } /* end for */ + printf("}\n"); + printf("buf = {"); + for(i = 0; i < dims[0]; i++) { + if(i > 0) + printf(", "); + printf("{%lld, %c, %.1f}", buf_conv[i].a, buf_conv[i].b, (double)buf_conv[i].c); + } /* end for */ + printf("}\n"); + } /* end if */ + + /* Check buffer */ + for(i = 0; i< dims[0]; i++) { + if((long long)file_buf[i].a != buf_conv[i].a) + PRINTF_ERROR("Member a at location %d does not match", i); + if(buf_conv_init[i].b != buf_conv[i].b) + PRINTF_ERROR("Member b at location %d does not match", i); + if(((buf_conv_init[i].c - buf_conv[i].c) > 0.01f) + || ((buf_conv_init[i].c - buf_conv[i].c) < -0.01f)) + PRINTF_ERROR("Member c at location %d does not match", i); + } /* end for */ + + printf("\n"); + + /* Read member b */ + memcpy(buf_conv, buf_conv_init, sizeof(buf_conv)); + if(H5Dread(dset, mem_type_b, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf_conv) < 0) + ERROR; + + /* Print message */ + if(verbose_g) { + printf("Read full dataset compound member \'b\'\n"); + printf("exp = {"); + for(i = 0; i < dims[0]; i++) { + if(i > 0) + printf(", "); + printf("{%lld, %c, %.1f}", buf_conv_init[i].a, file_buf[i].b, (double)buf_conv_init[i].c); + } /* end for */ + printf("}\n"); + printf("buf = {"); + for(i = 0; i < dims[0]; i++) { + if(i > 0) + printf(", "); + printf("{%lld, %c, %.1f}", buf_conv[i].a, buf_conv[i].b, (double)buf_conv[i].c); + } /* end for */ + printf("}\n"); + } /* end if */ + + /* Check buffer */ + for(i = 0; i< dims[0]; i++) { + if(buf_conv_init[i].a != buf_conv[i].a) + PRINTF_ERROR("Member a at location %d does not match", i); + if(file_buf[i].b != buf_conv[i].b) + PRINTF_ERROR("Member b at location %d does not match", i); + if(((buf_conv_init[i].c - buf_conv[i].c) > 0.01f) + || ((buf_conv_init[i].c - buf_conv[i].c) < -0.01f)) + PRINTF_ERROR("Member c at location %d does not match", i); + } /* end for */ + + printf("\n"); + + /* Read member c */ + memcpy(buf_conv, buf_conv_init, sizeof(buf_conv)); + if(H5Dread(dset, mem_type_c, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf_conv) < 0) + ERROR; + + /* Print message */ + if(verbose_g) { + printf("Read full dataset compound member \'c\'\n"); + printf("exp = {"); + for(i = 0; i < dims[0]; i++) { + if(i > 0) + printf(", "); + printf("{%lld, %c, %.1f}", buf_conv_init[i].a, buf_conv_init[i].b, file_buf[i].c); + } /* end for */ + printf("}\n"); + printf("buf = {"); + for(i = 0; i < dims[0]; i++) { + if(i > 0) + printf(", "); + printf("{%lld, %c, %.1f}", buf_conv[i].a, buf_conv[i].b, (double)buf_conv[i].c); + } /* end for */ + printf("}\n"); + } /* end if */ + + /* Check buffer */ + for(i = 0; i< dims[0]; i++) { + if(buf_conv_init[i].a != buf_conv[i].a) + PRINTF_ERROR("Member a at location %d does not match", i); + if(buf_conv_init[i].b != buf_conv[i].b) + PRINTF_ERROR("Member b at location %d does not match", i); + if(((file_buf[i].c - (double)buf_conv[i].c) > (double)0.01) + || ((file_buf[i].c - (double)buf_conv[i].c) < (double)-0.01)) + PRINTF_ERROR("Member c at location %d does not match", i); + } /* end for */ + + printf("\n"); + + /* + * Write/read partial datasets + */ + /* Fill buffer */ + for(i = 0; i < dims[0]; i++) { + buf_conv[i].a = (long long)(rand() % 10); + buf_conv[i].b = 'A' + (char)(rand() % 26); + buf_conv[i].c = (float)(rand() % 100) / (float)10; + } /* end for */ + + /* Print message */ + if(verbose_g) { + printf("Writing full memory type to dataset containing only member \'a\'\n"); + printf("buf = {"); + for(i = 0; i < dims[0]; i++) { + if(i > 0) + printf(", "); + printf("{%lld, %c, %.1f}", buf_conv[i].a, buf_conv[i].b, (double)buf_conv[i].c); + } /* end for */ + printf("}\n"); + } /* end if */ + + /* Write data */ + if(H5Dwrite(dset_a, mem_type_conv, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf_conv) < 0) + ERROR; + + /* Update file_buf */ + for(i = 0; i < dims[0]; i++) + file_buf[i].a = (int)buf_conv[i].a; + + /* Read data */ + memcpy(buf_conv, buf_conv_init, sizeof(buf_conv)); + if(H5Dread(dset_a, mem_type_conv, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf_conv) < 0) + ERROR; + + /* Print message */ + if(verbose_g) { + printf("Read dataset containing only member \'a\'\n"); + printf("exp = {"); + for(i = 0; i < dims[0]; i++) { + if(i > 0) + printf(", "); + printf("{%d, %c, %.1f}", file_buf[i].a, buf_conv_init[i].b, (double)buf_conv_init[i].c); + } /* end for */ + printf("}\n"); + printf("buf = {"); + for(i = 0; i < dims[0]; i++) { + if(i > 0) + printf(", "); + printf("{%lld, %c, %.1f}", buf_conv[i].a, buf_conv[i].b, (double)buf_conv[i].c); + } /* end for */ + printf("}\n"); + } /* end if */ + + /* Check buffer */ + for(i = 0; i< dims[0]; i++) { + if((long long)file_buf[i].a != buf_conv[i].a) + PRINTF_ERROR("Member a at location %d does not match", i); + if(buf_conv_init[i].b != buf_conv[i].b) + PRINTF_ERROR("Member b at location %d does not match", i); + if(((buf_conv_init[i].c - buf_conv[i].c) > 0.01f) + || ((buf_conv_init[i].c - buf_conv[i].c) < -0.01f)) + PRINTF_ERROR("Member c at location %d does not match", i); + } /* end for */ + + printf("\n"); + + /* Fill buffer */ + for(i = 0; i < dims[0]; i++) { + buf_conv[i].a = (long long)(rand() % 10); + buf_conv[i].b = 'A' + (char)(rand() % 26); + buf_conv[i].c = (float)(rand() % 100) / (float)10; + } /* end for */ + + /* Print message */ + if(verbose_g) { + printf("Writing full memory type to dataset containing only member \'b\'\n"); + printf("buf = {"); + for(i = 0; i < dims[0]; i++) { + if(i > 0) + printf(", "); + printf("{%lld, %c, %.1f}", buf_conv[i].a, buf_conv[i].b, (double)buf_conv[i].c); + } /* end for */ + printf("}\n"); + } /* end if */ + + /* Write data */ + if(H5Dwrite(dset_b, mem_type_conv, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf_conv) < 0) + ERROR; + + /* Update file_buf */ + for(i = 0; i < dims[0]; i++) + file_buf[i].b = buf_conv[i].b; + + /* Read data */ + memcpy(buf_conv, buf_conv_init, sizeof(buf_conv)); + if(H5Dread(dset_b, mem_type_conv, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf_conv) < 0) + ERROR; + + /* Print message */ + if(verbose_g) { + printf("Read dataset containing only member \'b\'\n"); + printf("exp = {"); + for(i = 0; i < dims[0]; i++) { + if(i > 0) + printf(", "); + printf("{%lld, %c, %.1f}", buf_conv_init[i].a, file_buf[i].b, (double)buf_conv_init[i].c); + } /* end for */ + printf("}\n"); + printf("buf = {"); + for(i = 0; i < dims[0]; i++) { + if(i > 0) + printf(", "); + printf("{%lld, %c, %.1f}", buf_conv[i].a, buf_conv[i].b, (double)buf_conv[i].c); + } /* end for */ + printf("}\n"); + } /* end if */ + + /* Check buffer */ + for(i = 0; i< dims[0]; i++) { + if(buf_conv_init[i].a != buf_conv[i].a) + PRINTF_ERROR("Member a at location %d does not match", i); + if(file_buf[i].b != buf_conv[i].b) + PRINTF_ERROR("Member b at location %d does not match", i); + if(((buf_conv_init[i].c - buf_conv[i].c) > 0.01f) + || ((buf_conv_init[i].c - buf_conv[i].c) < -0.01f)) + PRINTF_ERROR("Member c at location %d does not match", i); + } /* end for */ + + printf("\n"); + + /* Fill buffer */ + for(i = 0; i < dims[0]; i++) { + buf_conv[i].a = (long long)(rand() % 10); + buf_conv[i].b = 'A' + (char)(rand() % 26); + buf_conv[i].c = (float)(rand() % 100) / (float)10; + } /* end for */ + + /* Print message */ + if(verbose_g) { + printf("Writing full memory type to dataset containing only member \'c\'\n"); + printf("buf = {"); + for(i = 0; i < dims[0]; i++) { + if(i > 0) + printf(", "); + printf("{%lld, %c, %.1f}", buf_conv[i].a, buf_conv[i].b, (double)buf_conv[i].c); + } /* end for */ + printf("}\n"); + } /* end if */ + + /* Write data */ + if(H5Dwrite(dset_c, mem_type_conv, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf_conv) < 0) + ERROR; + + /* Update file_buf */ + for(i = 0; i < dims[0]; i++) + file_buf[i].c = (double)buf_conv[i].c; + + /* Read data */ + memcpy(buf_conv, buf_conv_init, sizeof(buf_conv)); + if(H5Dread(dset_c, mem_type_conv, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf_conv) < 0) + ERROR; + + /* Print message */ + if(verbose_g) { + printf("Read dataset containing only member \'c\'\n"); + printf("exp = {"); + for(i = 0; i < dims[0]; i++) { + if(i > 0) + printf(", "); + printf("{%lld, %c, %.1f}", buf_conv_init[i].a, buf_conv_init[i].b, file_buf[i].c); + } /* end for */ + printf("}\n"); + printf("buf = {"); + for(i = 0; i < dims[0]; i++) { + if(i > 0) + printf(", "); + printf("{%lld, %c, %.1f}", buf_conv[i].a, buf_conv[i].b, (double)buf_conv[i].c); + } /* end for */ + printf("}\n"); + } /* end if */ + + /* Check buffer */ + for(i = 0; i< dims[0]; i++) { + if(buf_conv_init[i].a != buf_conv[i].a) + PRINTF_ERROR("Member a at location %d does not match", i); + if(buf_conv_init[i].b != buf_conv[i].b) + PRINTF_ERROR("Member b at location %d does not match", i); + if(((file_buf[i].c - (double)buf_conv[i].c) > (double)0.01) + || ((file_buf[i].c - (double)buf_conv[i].c) < (double)-0.01)) + PRINTF_ERROR("Member c at location %d does not match", i); + } /* end for */ + + printf("\n"); + + /* + * Test dataset with selections + */ + /* + * Full write/read, member conversion + */ + /* Fill buffer */ + for(i = 0; i < dims[0]; i++) + for(j = 0; j < dims[1]; j++) { + buf2[i][j].a = rand() % 10; + buf2[i][j].b = 'A' + (char)(rand() % 26); + buf2[i][j].c = (double)(rand() % 100) / (double)10; + } /* end for */ + + /* Print message */ + if(verbose_g) { + printf("Writing full 2-D dataset with member conversion\n"); + printf("buf = {"); + for(i = 0; i < dims[0]; i++) { + if(i > 0) + printf("\n "); + for(j = 0; j < dims[1]; j++) { + if(j > 0) + printf(", "); + printf("{%lld, %c, %.1f}", buf2[i][j].a, buf2[i][j].b, (double)buf2[i][j].c); + } /* end for */ + } /* end for */ + printf("}\n"); + } /* end if */ + + /* Write data */ + if(H5Dwrite(dset2, mem_type_conv, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf2) < 0) + ERROR; + + /* Update file_buf */ + for(i = 0; i < dims[0]; i++) + for(j = 0; j < dims[1]; j++) { + file_buf2[i][j].a = (int)buf2[i][j].a; + file_buf2[i][j].b = buf2[i][j].b; + file_buf2[i][j].c = (double)buf2[i][j].c; + } /* end for */ + + /* Read data */ + memcpy(buf2, buf2_init, sizeof(buf2)); + if(H5Dread(dset2, mem_type_conv, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf2) < 0) + ERROR; + + /* Print message */ + if(verbose_g) { + printf("Read full 2-D dataset with member conversion\n"); + printf("exp = {"); + for(i = 0; i < dims[0]; i++) { + if(i > 0) + printf("\n "); + for(j = 0; j < dims[1]; j++) { + if(j > 0) + printf(", "); + printf("{%d, %c, %.1f}", file_buf2[i][j].a, file_buf2[i][j].b, file_buf2[i][j].c); + } /* end for */ + } /* end for */ + printf("}\n"); + printf("buf = {"); + for(i = 0; i < dims[0]; i++) { + if(i > 0) + printf("\n "); + for(j = 0; j < dims[1]; j++) { + if(j > 0) + printf(", "); + printf("{%lld, %c, %.1f}", buf2[i][j].a, buf2[i][j].b, (double)buf2[i][j].c); + } /* end for */ + } /* end for */ + printf("}\n"); + } /* end if */ + + /* Check buffer */ + for(i = 0; i< dims[0]; i++) + for(j = 0; j < dims[1]; j++) { + if((long long)file_buf2[i][j].a != buf2[i][j].a) + PRINTF_ERROR("Member a at location %d does not match", i); + if(file_buf2[i][j].b != buf2[i][j].b) + PRINTF_ERROR("Member b at location %d does not match", i); + if(((file_buf2[i][j].c - (double)buf2[i][j].c) > (double)0.01) + || ((file_buf2[i][j].c - (double)buf2[i][j].c) < (double)-0.01)) + PRINTF_ERROR("Member c at location %d does not match", i); + } /* end for */ + + printf("\n"); + + /* + * Partial write with full type/full read to full type + */ + /* Fill buffer */ + for(i = 0; i < dims[0]; i++) + for(j = 0; j < dims[1]; j++) { + buf2[i][j].a = rand() % 10; + buf2[i][j].b = 'A' + (char)(rand() % 26); + buf2[i][j].c = (double)(rand() % 100) / (double)10; + } /* end for */ + + /* Print message */ + if(verbose_g) { + printf("Writing partial 2-D dataset with member conversion\n"); + printf("buf = {"); + for(i = 0; i < dims[0]; i++) { + if(i > 0) + printf("\n "); + for(j = 0; j < dims[1]; j++) { + if(j > 0) + printf(", "); + printf("{%lld, %c, %.1f}", buf2[i][j].a, buf2[i][j].b, (double)buf2[i][j].c); + } /* end for */ + } /* end for */ + printf("}\n"); + } /* end if */ + + /* Write data */ + if(H5Dwrite(dset2, mem_type_conv, space2_contig, space2, H5P_DEFAULT, buf2) < 0) + ERROR; + + /* Update file_buf */ + i2 = 0; + for(i = 1; i < 3; i++) + for(j = 0; j < 2; j++) { + file_buf2[i2][1].a = (int)buf2[i][j].a; + file_buf2[i2][1].b = buf2[i][j].b; + file_buf2[i2][1].c = (double)buf2[i][j].c; + i2++; + } /* end for */ + + /* Read data */ + memcpy(buf2, buf2_init, sizeof(buf2)); + if(H5Dread(dset2, mem_type_conv, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf2) < 0) + ERROR; + + /* Print message */ + if(verbose_g) { + printf("Read full 2-D dataset with member conversion\n"); + printf("exp = {"); + for(i = 0; i < dims[0]; i++) { + if(i > 0) + printf("\n "); + for(j = 0; j < dims[1]; j++) { + if(j > 0) + printf(", "); + printf("{%d, %c, %.1f}", file_buf2[i][j].a, file_buf2[i][j].b, file_buf2[i][j].c); + } /* end for */ + } /* end for */ + printf("}\n"); + printf("buf = {"); + for(i = 0; i < dims[0]; i++) { + if(i > 0) + printf("\n "); + for(j = 0; j < dims[1]; j++) { + if(j > 0) + printf(", "); + printf("{%lld, %c, %.1f}", buf2[i][j].a, buf2[i][j].b, (double)buf2[i][j].c); + } /* end for */ + } /* end for */ + printf("}\n"); + } /* end if */ + + /* Check buffer */ + for(i = 0; i< dims[0]; i++) + for(j = 0; j < dims[1]; j++) { + if((long long)file_buf2[i][j].a != buf2[i][j].a) + PRINTF_ERROR("Member a at location %d, %d does not match", i, j); + if(file_buf2[i][j].b != buf2[i][j].b) + PRINTF_ERROR("Member b at location %d, %d does not match", i, j); + if(((file_buf2[i][j].c - (double)buf2[i][j].c) > (double)0.01) + || ((file_buf2[i][j].c - (double)buf2[i][j].c) < (double)-0.01)) + PRINTF_ERROR("Member c at location %d, %d does not match", i, j); + } /* end for */ + + printf("\n"); + + /* + * Partial write with member a/full read to full type + */ + /* Fill buffer */ + for(i = 0; i < dims[0]; i++) + for(j = 0; j < dims[1]; j++) { + buf2[i][j].a = rand() % 10; + buf2[i][j].b = 'A' + (char)(rand() % 26); + buf2[i][j].c = (double)(rand() % 100) / (double)10; + } /* end for */ + + /* Print message */ + if(verbose_g) { + printf("Writing partial 2-D dataset with member conversion to member \'a\'\n"); + printf("buf = {"); + for(i = 0; i < dims[0]; i++) { + if(i > 0) + printf("\n "); + for(j = 0; j < dims[1]; j++) { + if(j > 0) + printf(", "); + printf("{%lld, %c, %.1f}", buf2[i][j].a, buf2[i][j].b, (double)buf2[i][j].c); + } /* end for */ + } /* end for */ + printf("}\n"); + } /* end if */ + + /* Write data */ + if(H5Dwrite(dset2, mem_type_a, space2_contig, space2, H5P_DEFAULT, buf2) < 0) + ERROR; + + /* Update file_buf */ + i2 = 0; + for(i = 1; i < 3; i++) + for(j = 0; j < 2; j++) { + file_buf2[i2][1].a = (int)buf2[i][j].a; + i2++; + } /* end for */ + + /* Read data */ + memcpy(buf2, buf2_init, sizeof(buf2)); + if(H5Dread(dset2, mem_type_conv, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf2) < 0) + ERROR; + + /* Print message */ + if(verbose_g) { + printf("Read full 2-D dataset with member conversion\n"); + printf("exp = {"); + for(i = 0; i < dims[0]; i++) { + if(i > 0) + printf("\n "); + for(j = 0; j < dims[1]; j++) { + if(j > 0) + printf(", "); + printf("{%d, %c, %.1f}", file_buf2[i][j].a, file_buf2[i][j].b, file_buf2[i][j].c); + } /* end for */ + } /* end for */ + printf("}\n"); + printf("buf = {"); + for(i = 0; i < dims[0]; i++) { + if(i > 0) + printf("\n "); + for(j = 0; j < dims[1]; j++) { + if(j > 0) + printf(", "); + printf("{%lld, %c, %.1f}", buf2[i][j].a, buf2[i][j].b, (double)buf2[i][j].c); + } /* end for */ + } /* end for */ + printf("}\n"); + } /* end if */ + + /* Check buffer */ + for(i = 0; i< dims[0]; i++) + for(j = 0; j < dims[1]; j++) { + if((long long)file_buf2[i][j].a != buf2[i][j].a) + PRINTF_ERROR("Member a at location %d, %d does not match", i, j); + if(file_buf2[i][j].b != buf2[i][j].b) + PRINTF_ERROR("Member b at location %d, %d does not match", i, j); + if(((file_buf2[i][j].c - (double)buf2[i][j].c) > (double)0.01) + || ((file_buf2[i][j].c - (double)buf2[i][j].c) < (double)-0.01)) + PRINTF_ERROR("Member c at location %d, %d does not match", i, j); + } /* end for */ + + printf("\n"); + + /* + * Partial read to contiguous buffer, member conversion to type "a" + */ + /* Read data */ + memcpy(buf2, buf2_init, sizeof(buf2)); + if(H5Dread(dset2, mem_type_a, H5S_ALL, space2_contig, H5P_DEFAULT, buf2) < 0) + ERROR; + + /* Print message */ + if(verbose_g) { + printf("Read partial 2-D dataset to contiguous buffer with member conversion to member \'a\'\n"); + printf("exp = {"); + for(i = 0; i < dims[0]; i++) { + if(i > 0) + printf("\n "); + for(j = 0; j < dims[1]; j++) { + if(j > 0) + printf(", "); + printf("{%lld, %c, %.1f}", (i == 1 || i == 2) ? (long long)file_buf2[i][j].a : buf2_init[i][j].a, buf2_init[i][j].b, (double)buf2_init[i][j].c); + } /* end for */ + } /* end for */ + printf("}\n"); + printf("buf = {"); + for(i = 0; i < dims[0]; i++) { + if(i > 0) + printf("\n "); + for(j = 0; j < dims[1]; j++) { + if(j > 0) + printf(", "); + printf("{%lld, %c, %.1f}", buf2[i][j].a, buf2[i][j].b, (double)buf2[i][j].c); + } /* end for */ + } /* end for */ + printf("}\n"); + } /* end if */ + + /* Check buffer */ + for(i = 0; i< dims[0]; i++) + for(j = 0; j < dims[1]; j++) { + if(((i == 1 || i == 2) + ? (long long)file_buf2[i][j].a : buf2_init[i][j].a) + != buf2[i][j].a) + PRINTF_ERROR("Member a at location %d, %d does not match", i, j); + if(buf2_init[i][j].b != buf2[i][j].b) + PRINTF_ERROR("Member b at location %d, %d does not match", i, j); + if(((buf2_init[i][j].c - buf2[i][j].c) > 0.01f) + || ((buf2_init[i][j].c - buf2[i][j].c) < -0.01f)) + PRINTF_ERROR("Member c at location %d, %d does not match", i, j); + } /* end for */ + + printf("\n"); + + /* + * Partial read to non-contiguous buffer, member conversion to type "a" + */ + /* Read data */ + memcpy(buf2, buf2_init, sizeof(buf2)); + if(H5Dread(dset2, mem_type_a, space2, space2_contig, H5P_DEFAULT, buf2) < 0) + ERROR; + + /* Print message */ + if(verbose_g) { + printf("Read partial 2-D dataset to non-contiguous buffer with member conversion to member \'a\'\n"); + printf("exp = {"); + for(i = 0; i < dims[0]; i++) { + if(i > 0) + printf("\n "); + for(j = 0; j < dims[1]; j++) { + if(j > 0) + printf(", "); + printf("{%lld, %c, %.1f}", (j == 1) ? (long long)file_buf2[i / 2 + 1][i % 2].a : buf2_init[i][j].a, buf2_init[i][j].b, (double)buf2_init[i][j].c); + } /* end for */ + } /* end for */ + printf("}\n"); + printf("buf = {"); + for(i = 0; i < dims[0]; i++) { + if(i > 0) + printf("\n "); + for(j = 0; j < dims[1]; j++) { + if(j > 0) + printf(", "); + printf("{%lld, %c, %.1f}", buf2[i][j].a, buf2[i][j].b, (double)buf2[i][j].c); + } /* end for */ + } /* end for */ + printf("}\n"); + } /* end if */ + + /* Check buffer */ + for(i = 0; i< dims[0]; i++) + for(j = 0; j < dims[1]; j++) { + if(((j == 1) ? (long long)file_buf2[i / 2 + 1][i % 2].a + : buf2_init[i][j].a) + != buf2[i][j].a) + PRINTF_ERROR("Member a at location %d, %d does not match", i, j); + if(buf2_init[i][j].b != buf2[i][j].b) + PRINTF_ERROR("Member b at location %d, %d does not match", i, j); + if(((buf2_init[i][j].c - buf2[i][j].c) > 0.01f) + || ((buf2_init[i][j].c - buf2[i][j].c) < -0.01f)) + PRINTF_ERROR("Member c at location %d, %d does not match", i, j); + } /* end for */ + + printf("\n"); + + /* * Close */ if(H5Aclose(attr) < 0) @@ -863,6 +1945,8 @@ int main(int argc, char *argv[]) { ERROR; if(H5Dclose(dset_c) < 0) ERROR; + if(H5Dclose(dset2) < 0) + ERROR; if(H5Fclose(file) < 0) ERROR; if(H5Tclose(file_type) < 0) @@ -885,6 +1969,10 @@ int main(int argc, char *argv[]) { ERROR; if(H5Sclose(space) < 0) ERROR; + if(H5Sclose(space2) < 0) + ERROR; + if(H5Sclose(space2_contig) < 0) + ERROR; if(H5Pclose(fapl) < 0) ERROR; @@ -903,6 +1991,7 @@ error: H5Dclose(dset_a); H5Dclose(dset_b); H5Dclose(dset_c); + H5Dclose(dset2); H5Fclose(file); H5Tclose(file_type); H5Tclose(file_type_a); @@ -914,6 +2003,8 @@ error: H5Tclose(mem_type_b); H5Tclose(mem_type_c); H5Sclose(space); + H5Sclose(space2); + H5Sclose(space2_contig); H5Pclose(fapl); } H5E_END_TRY; |