diff options
author | Allen Byrne <byrn@hdfgroup.org> | 2020-09-30 14:27:10 (GMT) |
---|---|---|
committer | Allen Byrne <byrn@hdfgroup.org> | 2020-09-30 14:27:10 (GMT) |
commit | b2d661b508a7fc7a2592c13bc6bdc175551f075d (patch) | |
tree | 13baeb0d83a7c2a4c6299993c182b1227c2f6114 /test/extend.c | |
parent | 29ab58b58dce556639ea3154e262895773a8a8df (diff) | |
download | hdf5-b2d661b508a7fc7a2592c13bc6bdc175551f075d.zip hdf5-b2d661b508a7fc7a2592c13bc6bdc175551f075d.tar.gz hdf5-b2d661b508a7fc7a2592c13bc6bdc175551f075d.tar.bz2 |
Clang-format of source files
Diffstat (limited to 'test/extend.c')
-rw-r--r-- | test/extend.c | 261 |
1 files changed, 150 insertions, 111 deletions
diff --git a/test/extend.c b/test/extend.c index 369ad32..6658253 100644 --- a/test/extend.c +++ b/test/extend.c @@ -20,23 +20,19 @@ #include "h5test.h" -const char *FILENAME[] = { - "extend", - NULL -}; +const char *FILENAME[] = {"extend", NULL}; -#define N1X 100 /* USE AN EVEN NUMBER! */ -#define N1Y 100 /* USE AN EVEN NUMBER! */ -#define N2X (N1X / 2) -#define N2Y (N1Y / 2) +#define N1X 100 /* USE AN EVEN NUMBER! */ +#define N1Y 100 /* USE AN EVEN NUMBER! */ +#define N2X (N1X / 2) +#define N2Y (N1Y / 2) /* Data buffers */ -static int **buf1 = NULL; -static int *buf1_data = NULL; -static int **buf2 = NULL; -static int *buf2_data = NULL; +static int **buf1 = NULL; +static int * buf1_data = NULL; +static int **buf2 = NULL; +static int * buf2_data = NULL; - /*------------------------------------------------------------------------- * Function: write_data * @@ -53,75 +49,89 @@ static int *buf2_data = NULL; static int write_data(const char *msg, hid_t file, const char *name, hid_t cparms, hid_t mem_space) { - hid_t dataset, file_space, half_space; - static const hsize_t dims[2] = {N1X, N1Y}; - static const hsize_t half_dims[2] = {N2X, N2Y}; - hsize_t size[2]; - hsize_t max_size[2] = {0, 0}; - hsize_t offset[2]; - int i, j, k, m; + hid_t dataset, file_space, half_space; + static const hsize_t dims[2] = {N1X, N1Y}; + static const hsize_t half_dims[2] = {N2X, N2Y}; + hsize_t size[2]; + hsize_t max_size[2] = {0, 0}; + hsize_t offset[2]; + int i, j, k, m; TESTING(msg); /* Create the dataset */ - if((dataset = H5Dcreate2(file, name, H5T_NATIVE_INT, mem_space, H5P_DEFAULT, cparms, H5P_DEFAULT)) < 0) TEST_ERROR; + if ((dataset = H5Dcreate2(file, name, H5T_NATIVE_INT, mem_space, H5P_DEFAULT, cparms, H5P_DEFAULT)) < 0) + TEST_ERROR; /* Write the data */ - for(i = 0; i < 5; i++) - for(j = 0; j < 5; j++) { + for (i = 0; i < 5; i++) + for (j = 0; j < 5; j++) { /* Extend the dataset */ offset[0] = (hsize_t)(i * N1X); offset[1] = (hsize_t)(j * N1Y); - size[0] = offset[0] + N1X; - size[1] = offset[1] + N1Y; - if(size[0] > max_size[0] || size[1] > max_size[1]) { - if(size[0] > max_size[0]) + size[0] = offset[0] + N1X; + size[1] = offset[1] + N1Y; + if (size[0] > max_size[0] || size[1] > max_size[1]) { + if (size[0] > max_size[0]) max_size[0] = size[0]; - if(size[1] > max_size[1]) + if (size[1] > max_size[1]) max_size[1] = size[1]; - if(H5Dset_extent(dataset, max_size) < 0) TEST_ERROR; + if (H5Dset_extent(dataset, max_size) < 0) + TEST_ERROR; } /* end if */ /* Select a hyperslab */ - if((file_space = H5Dget_space(dataset)) < 0) TEST_ERROR; - if(H5Sselect_hyperslab(file_space, H5S_SELECT_SET, offset, NULL, dims, NULL) < 0) TEST_ERROR; + if ((file_space = H5Dget_space(dataset)) < 0) + TEST_ERROR; + if (H5Sselect_hyperslab(file_space, H5S_SELECT_SET, offset, NULL, dims, NULL) < 0) + TEST_ERROR; /* Write to the hyperslab */ - if(H5Dwrite(dataset, H5T_NATIVE_INT, mem_space, file_space, H5P_DEFAULT, buf1_data) < 0) TEST_ERROR; - if(H5Sclose(file_space) < 0) TEST_ERROR; + if (H5Dwrite(dataset, H5T_NATIVE_INT, mem_space, file_space, H5P_DEFAULT, buf1_data) < 0) + TEST_ERROR; + if (H5Sclose(file_space) < 0) + TEST_ERROR; } /* end for */ /* Read the data */ - if((half_space = H5Screate_simple(2, half_dims, NULL)) < 0) TEST_ERROR; - if((file_space = H5Dget_space(dataset)) < 0) TEST_ERROR; - for(i = 0; i < 10; i++) { - for(j = 0; j < 10; j++) { + if ((half_space = H5Screate_simple(2, half_dims, NULL)) < 0) + TEST_ERROR; + if ((file_space = H5Dget_space(dataset)) < 0) + TEST_ERROR; + for (i = 0; i < 10; i++) { + for (j = 0; j < 10; j++) { /* Select a hyperslab */ offset[0] = (hsize_t)(i * N2X); offset[1] = (hsize_t)(j * N2Y); - if(H5Sselect_hyperslab(file_space, H5S_SELECT_SET, offset, NULL, half_dims, NULL) < 0) TEST_ERROR; + if (H5Sselect_hyperslab(file_space, H5S_SELECT_SET, offset, NULL, half_dims, NULL) < 0) + TEST_ERROR; /* Read */ - if(H5Dread(dataset, H5T_NATIVE_INT, half_space, file_space, H5P_DEFAULT, buf2_data) < 0) TEST_ERROR; + if (H5Dread(dataset, H5T_NATIVE_INT, half_space, file_space, H5P_DEFAULT, buf2_data) < 0) + TEST_ERROR; /* Compare */ - for(k = 0; k < N2X; k++) - for(m = 0; m < N2Y; m++) - if(buf2[k][m] != buf1[(i % 2) * N2X + k][(j % 2) * N2Y + m]) { + for (k = 0; k < N2X; k++) + for (m = 0; m < N2Y; m++) + if (buf2[k][m] != buf1[(i % 2) * N2X + k][(j % 2) * N2Y + m]) { HDprintf(" i=%d, j=%d, k=%d, m=%d\n", i, j, k, m); HDprintf(" buf2[%d][%d]=%d\n", k, m, buf2[k][m]); - HDprintf(" buf1[%d][%d]=%d\n", (i % 2) * N2X + k, (j % 2) * N2Y + m, buf1[(i % 2) * N2X + k][(j % 2) * N2Y + m]); + HDprintf(" buf1[%d][%d]=%d\n", (i % 2) * N2X + k, (j % 2) * N2Y + m, + buf1[(i % 2) * N2X + k][(j % 2) * N2Y + m]); TEST_ERROR; } /* end if */ - } /* end for */ - } /* end for */ + } /* end for */ + } /* end for */ /* Cleanup */ - if(H5Dclose(dataset) < 0) TEST_ERROR; - if(H5Sclose(file_space) < 0) TEST_ERROR; - if(H5Sclose(half_space) < 0) TEST_ERROR; + if (H5Dclose(dataset) < 0) + TEST_ERROR; + if (H5Sclose(file_space) < 0) + TEST_ERROR; + if (H5Sclose(half_space) < 0) + TEST_ERROR; PASSED(); return 0; @@ -131,7 +141,7 @@ error: } /* end write_data() */ #ifndef H5_NO_DEPRECATED_SYMBOLS - + /*------------------------------------------------------------------------- * Function: write_data_deprec * @@ -149,69 +159,82 @@ error: static int write_data_deprec(const char *msg, hid_t file, const char *name, hid_t cparms, hid_t mem_space) { - hid_t dataset, file_space, half_space; - static const hsize_t dims[2] = {N1X, N1Y}; - static const hsize_t half_dims[2] = {N2X, N2Y}; - static hsize_t size[2]; - hsize_t offset[2]; - int i, j, k, m; + hid_t dataset, file_space, half_space; + static const hsize_t dims[2] = {N1X, N1Y}; + static const hsize_t half_dims[2] = {N2X, N2Y}; + static hsize_t size[2]; + hsize_t offset[2]; + int i, j, k, m; TESTING(msg); /* Create the dataset */ - if((dataset = H5Dcreate2(file, name, H5T_NATIVE_INT, mem_space, H5P_DEFAULT, cparms, H5P_DEFAULT)) < 0) TEST_ERROR; + if ((dataset = H5Dcreate2(file, name, H5T_NATIVE_INT, mem_space, H5P_DEFAULT, cparms, H5P_DEFAULT)) < 0) + TEST_ERROR; /* Write the data */ - for(i = 0; i < 5; i++) - for(j = 0; j < 5; j++) { + for (i = 0; i < 5; i++) + for (j = 0; j < 5; j++) { /* Extend the dataset */ offset[0] = (hsize_t)(i * N1X); offset[1] = (hsize_t)(j * N1Y); - size[0] = offset[0] + N1X; - size[1] = offset[1] + N1Y; - if(H5Dextend(dataset, size) < 0) TEST_ERROR; + size[0] = offset[0] + N1X; + size[1] = offset[1] + N1Y; + if (H5Dextend(dataset, size) < 0) + TEST_ERROR; /* Select a hyperslab */ - if((file_space = H5Dget_space(dataset)) < 0) TEST_ERROR; - if(H5Sselect_hyperslab(file_space, H5S_SELECT_SET, offset, NULL, dims, NULL) < 0) TEST_ERROR; + if ((file_space = H5Dget_space(dataset)) < 0) + TEST_ERROR; + if (H5Sselect_hyperslab(file_space, H5S_SELECT_SET, offset, NULL, dims, NULL) < 0) + TEST_ERROR; /* Write to the hyperslab */ - if(H5Dwrite(dataset, H5T_NATIVE_INT, mem_space, file_space, H5P_DEFAULT, buf1_data) < 0) TEST_ERROR; - if(H5Sclose(file_space) < 0) TEST_ERROR; + if (H5Dwrite(dataset, H5T_NATIVE_INT, mem_space, file_space, H5P_DEFAULT, buf1_data) < 0) + TEST_ERROR; + if (H5Sclose(file_space) < 0) + TEST_ERROR; } /* end for */ /* Read the data */ - if((half_space = H5Screate_simple(2, half_dims, NULL)) < 0) TEST_ERROR; - if((file_space = H5Dget_space(dataset)) < 0) TEST_ERROR; - for(i = 0; i < 10; i++) { - for(j = 0; j < 10; j++) { + if ((half_space = H5Screate_simple(2, half_dims, NULL)) < 0) + TEST_ERROR; + if ((file_space = H5Dget_space(dataset)) < 0) + TEST_ERROR; + for (i = 0; i < 10; i++) { + for (j = 0; j < 10; j++) { /* Select a hyperslab */ offset[0] = (hsize_t)(i * N2X); offset[1] = (hsize_t)(j * N2Y); - if(H5Sselect_hyperslab(file_space, H5S_SELECT_SET, offset, NULL, half_dims, NULL) < 0) TEST_ERROR; + if (H5Sselect_hyperslab(file_space, H5S_SELECT_SET, offset, NULL, half_dims, NULL) < 0) + TEST_ERROR; /* Read */ - if(H5Dread(dataset, H5T_NATIVE_INT, half_space, file_space, H5P_DEFAULT, buf2_data) < 0) TEST_ERROR; + if (H5Dread(dataset, H5T_NATIVE_INT, half_space, file_space, H5P_DEFAULT, buf2_data) < 0) + TEST_ERROR; /* Compare */ - for(k = 0; k < N2X; k++) - for(m = 0; m < N2Y; m++) - if(buf2[k][m] != buf1[(i % 2) * N2X + k][(j % 2) * N2Y + m]) { + for (k = 0; k < N2X; k++) + for (m = 0; m < N2Y; m++) + if (buf2[k][m] != buf1[(i % 2) * N2X + k][(j % 2) * N2Y + m]) { HDprintf(" i=%d, j=%d, k=%d, m=%d\n", i, j, k, m); HDprintf(" buf2[%d][%d]=%d\n", k, m, buf2[k][m]); - HDprintf(" buf1[%d][%d]=%d\n", (i % 2) * N2X + k, (j % 2) * N2Y + m, buf1[(i % 2) * N2X + k][(j % 2) * N2Y + m]); + HDprintf(" buf1[%d][%d]=%d\n", (i % 2) * N2X + k, (j % 2) * N2Y + m, + buf1[(i % 2) * N2X + k][(j % 2) * N2Y + m]); TEST_ERROR; } /* end if */ - } /* end for */ - } /* end for */ - + } /* end for */ + } /* end for */ /* Cleanup */ - if(H5Dclose(dataset) < 0) TEST_ERROR; - if(H5Sclose(file_space) < 0) TEST_ERROR; - if(H5Sclose(half_space) < 0) TEST_ERROR; + if (H5Dclose(dataset) < 0) + TEST_ERROR; + if (H5Sclose(file_space) < 0) + TEST_ERROR; + if (H5Sclose(half_space) < 0) + TEST_ERROR; PASSED(); return 0; @@ -221,7 +244,6 @@ error: } /* end write_data_deprec() */ #endif /* H5_NO_DEPRECATED_SYMBOLS */ - /*------------------------------------------------------------------------- * Function: main * @@ -235,70 +257,88 @@ error: *------------------------------------------------------------------------- */ int -main (void) +main(void) { - hid_t file, mem_space, cparms; - hid_t fapl; - int nerrors = 0; - static const hsize_t dims[2] = {N1X, N1Y}; - static const hsize_t chunk_dims[2] = {N2X, N2Y}; - static hsize_t maxdims[2] = {H5S_UNLIMITED, H5S_UNLIMITED}; - char filename[1024]; - int i, j; + hid_t file, mem_space, cparms; + hid_t fapl; + int nerrors = 0; + static const hsize_t dims[2] = {N1X, N1Y}; + static const hsize_t chunk_dims[2] = {N2X, N2Y}; + static hsize_t maxdims[2] = {H5S_UNLIMITED, H5S_UNLIMITED}; + char filename[1024]; + int i, j; h5_reset(); fapl = h5_fileaccess(); /* Initialize buffer and space */ - if(NULL == (buf1_data = (int *)HDcalloc(N1X * N1Y, sizeof(int)))) + if (NULL == (buf1_data = (int *)HDcalloc(N1X * N1Y, sizeof(int)))) TEST_ERROR; - if(NULL == (buf1 = (int **)HDcalloc(N1X, sizeof(buf1_data)))) + if (NULL == (buf1 = (int **)HDcalloc(N1X, sizeof(buf1_data)))) TEST_ERROR; for (i = 0; i < N1X; i++) buf1[i] = buf1_data + (i * N1Y); - if(NULL == (buf2_data = (int *)HDcalloc(N2X * N2Y, sizeof(int)))) + if (NULL == (buf2_data = (int *)HDcalloc(N2X * N2Y, sizeof(int)))) TEST_ERROR; - if(NULL == (buf2 = (int **)HDcalloc(N2X, sizeof(buf2_data)))) + if (NULL == (buf2 = (int **)HDcalloc(N2X, sizeof(buf2_data)))) TEST_ERROR; for (i = 0; i < N2X; i++) buf2[i] = buf2_data + (i * N2Y); - for(i = 0; i < N1X; i++) - for(j = 0; j < N1Y; j++) + for (i = 0; i < N1X; i++) + for (j = 0; j < N1Y; j++) buf1[i][j] = i * N1Y + j; - if((mem_space = H5Screate_simple(2, dims, maxdims)) < 0) TEST_ERROR; + if ((mem_space = H5Screate_simple(2, dims, maxdims)) < 0) + TEST_ERROR; /* Create the file */ h5_fixname(FILENAME[0], fapl, filename, sizeof filename); - if((file = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0) TEST_ERROR; + if ((file = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0) + TEST_ERROR; /* Create the dataset creation property list */ - if((cparms = H5Pcreate(H5P_DATASET_CREATE)) < 0) TEST_ERROR; - if(H5Pset_chunk(cparms, 2, chunk_dims) < 0) TEST_ERROR; + if ((cparms = H5Pcreate(H5P_DATASET_CREATE)) < 0) + TEST_ERROR; + if (H5Pset_chunk(cparms, 2, chunk_dims) < 0) + TEST_ERROR; /* Test with incremental allocation */ - nerrors += write_data("extendible dataset with incr. allocation", file, "dataset1a", cparms, mem_space) < 0 ? 1 : 0; + nerrors += + write_data("extendible dataset with incr. allocation", file, "dataset1a", cparms, mem_space) < 0 ? 1 + : 0; #ifndef H5_NO_DEPRECATED_SYMBOLS - nerrors += write_data_deprec("extendible dataset with incr. allocation w/deprec. symbols", file, "dataset1b", cparms, mem_space) < 0 ? 1 : 0; + nerrors += write_data_deprec("extendible dataset with incr. allocation w/deprec. symbols", file, + "dataset1b", cparms, mem_space) < 0 + ? 1 + : 0; #endif /* H5_NO_DEPRECATED_SYMBOLS */ /* Test with early allocation */ - if(H5Pset_alloc_time(cparms, H5D_ALLOC_TIME_EARLY) < 0) TEST_ERROR; - nerrors += write_data("extendible dataset with early allocation", file, "dataset2a", cparms, mem_space) < 0 ? 1 : 0; + if (H5Pset_alloc_time(cparms, H5D_ALLOC_TIME_EARLY) < 0) + TEST_ERROR; + nerrors += + write_data("extendible dataset with early allocation", file, "dataset2a", cparms, mem_space) < 0 ? 1 + : 0; #ifndef H5_NO_DEPRECATED_SYMBOLS - nerrors += write_data_deprec("extendible dataset with early allocation w/deprec. symbols", file, "dataset2b", cparms, mem_space) < 0 ? 1 : 0; + nerrors += write_data_deprec("extendible dataset with early allocation w/deprec. symbols", file, + "dataset2b", cparms, mem_space) < 0 + ? 1 + : 0; #endif /* H5_NO_DEPRECATED_SYMBOLS */ - if(H5Pclose(cparms) < 0) TEST_ERROR; - if(H5Sclose(mem_space) < 0) TEST_ERROR; - if(H5Fclose(file) < 0) TEST_ERROR; + if (H5Pclose(cparms) < 0) + TEST_ERROR; + if (H5Sclose(mem_space) < 0) + TEST_ERROR; + if (H5Fclose(file) < 0) + TEST_ERROR; /* Verify symbol table messages are cached */ nerrors += (h5_verify_cached_stabs(FILENAME, fapl) < 0 ? 1 : 0); - if(nerrors) { + if (nerrors) { HDprintf("***** %d FAILURE%s! *****\n", nerrors, (1 == nerrors) ? "" : "S"); HDexit(EXIT_FAILURE); } /* end if */ @@ -323,4 +363,3 @@ error: HDprintf("*** One or more extend tests failed ***\n"); HDexit(EXIT_FAILURE); } /* end main() */ - |