summaryrefslogtreecommitdiffstats
path: root/hl/tools/h5watch/extend_dset.c
diff options
context:
space:
mode:
Diffstat (limited to 'hl/tools/h5watch/extend_dset.c')
-rw-r--r--hl/tools/h5watch/extend_dset.c399
1 files changed, 206 insertions, 193 deletions
diff --git a/hl/tools/h5watch/extend_dset.c b/hl/tools/h5watch/extend_dset.c
index 7efdd3b..603893e 100644
--- a/hl/tools/h5watch/extend_dset.c
+++ b/hl/tools/h5watch/extend_dset.c
@@ -15,12 +15,25 @@
#include "H5HLprivate2.h"
-#include <stdio.h>
-#include <string.h>
-#include <assert.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <time.h>
+#ifdef H5_STDC_HEADERS
+# include <assert.h>
+# include <stdio.h>
+# include <stdlib.h>
+# include <string.h>
+#endif
+
+#ifdef H5_HAVE_UNISTD_H
+# include <unistd.h>
+#endif
+
+#if defined(H5_TIME_WITH_SYS_TIME)
+# include <sys/time.h>
+# include <time.h>
+#elif defined(H5_HAVE_SYS_TIME_H)
+# include <sys/time.h>
+#else
+# include <time.h>
+#endif
/*
* Extending datasets in WATCH.h5 generated by h5watchgentest.c
@@ -43,24 +56,24 @@
/* Size of data buffer */
#define TEST_BUF_SIZE 100
-/*
+/*
* Test variations (incremental) for one-dimensional dataset:
- * Varies from 10->13->12->12->1->3
+ * Varies from 10->13->12->12->1->3
*/
-#define ONE_NTESTS 5
+#define ONE_NTESTS 5
int one_tests[ONE_NTESTS] = {3, -1, 0, -11, 2};
-/*
+/*
* Test variations (incremental) for two-dimensional dataset:
- * Varies from {4,10}->{6,12}->{8,1}->{10,1}->
- * {3,3}->{2,2}->{1,2}->
- * {1,4}->{1,3}->{1,3}
+ * Varies from {4,10}->{6,12}->{8,1}->{10,1}->
+ * {3,3}->{2,2}->{1,2}->
+ * {1,4}->{1,3}->{1,3}
*/
#define TWO_NTESTS 9
int two_tests[TWO_NTESTS][2] = { {2, 2}, {2, -11}, {2, 0},
{-7, 2}, {-1, -1}, {-1, 0},
- {0, 2}, {0, -1}, {0, 0}
- };
+ {0, 2}, {0, -1}, {0, 0}
+ };
static int extend_dset_two(const char *file, char *dname);
static int extend_dset_one(const char *file, char *dname);
@@ -145,7 +158,7 @@ done:
***********************************************************************
*
* Extending a two-dimensional dataset:
- * dims[0] dims[1]
+ * dims[0] dims[1]
* ------- -------
* case #1: increase increase
* case #2: increase decrease
@@ -157,30 +170,30 @@ done:
* case #8: same decrease (no action)
* case #9: same same (no action)
*
- * two_tests[TWO_NTESTS][2] = { {2,2}, {2,-11}, {2,0},
+ * two_tests[TWO_NTESTS][2] = { {2,2}, {2,-11}, {2,0},
* {-7,2}, {-1,-1}, {-1,0},
* {0,2}, {0,-1}, {0,0} }
- * varies from {4,10}->{6,12}->{8,1}->{10,1}->
- * {3,3}->{2,2}->{1,2}->
- * {1,4}->{1,3}->{1,3}
+ * varies from {4,10}->{6,12}->{8,1}->{10,1}->
+ * {3,3}->{2,2}->{1,2}->
+ * {1,4}->{1,3}->{1,3}
***********************************************************************
*/
static int
extend_dset_two(const char *file, char *dname)
{
- hid_t fid = -1; /* file id */
- hid_t fapl = -1; /* file access property list id */
- hid_t did = -1; /* dataset id */
- hid_t sid = -1; /* dataspace id */
- hid_t dtid = -1; /* dataset's datatype id */
- int ndims; /* # of dimension sizes */
- unsigned i, j; /* local index variable */
- hsize_t ext_dims[2]; /* new dimension sizes after extension */
- hsize_t cur_dims[2]; /* current dimension sizes */
- size_t dtype_size; /* size of the dataset's datatype */
+ hid_t fid = -1; /* file id */
+ hid_t fapl = -1; /* file access property list id */
+ hid_t did = -1; /* dataset id */
+ hid_t sid = -1; /* dataspace id */
+ hid_t dtid = -1; /* dataset's datatype id */
+ int ndims; /* # of dimension sizes */
+ unsigned i, j; /* local index variable */
+ hsize_t ext_dims[2]; /* new dimension sizes after extension */
+ hsize_t cur_dims[2]; /* current dimension sizes */
+ size_t dtype_size; /* size of the dataset's datatype */
unsigned num_elmts; /* number of elements in the dataset */
- int ibuf[TEST_BUF_SIZE]; /* buffer for storing retrieved elements (integer) */
- set_t cbuf[TEST_BUF_SIZE]; /* buffer for storing retrieved elemnets (compound) */
+ int ibuf[TEST_BUF_SIZE]; /* buffer for storing retrieved elements (integer) */
+ set_t cbuf[TEST_BUF_SIZE]; /* buffer for storing retrieved elemnets (compound) */
/* Create a copy of file access property list */
if((fapl = H5Pcreate(H5P_FILE_ACCESS)) < 0)
@@ -192,27 +205,27 @@ extend_dset_two(const char *file, char *dname)
/* Open the file and dataset with SWMR write */
if((fid = H5Fopen(file, H5F_ACC_RDWR|H5F_ACC_SWMR_WRITE, fapl)) < 0)
- goto done;
+ goto done;
if((did = H5Dopen2(fid, dname, H5P_DEFAULT)) < 0)
- goto done;
+ goto done;
/* Send message to the test script to start "h5watch" */
send_message(WRITER_MESSAGE);
if((sid = H5Dget_space(did)) < 0)
- goto done;
+ goto done;
if((ndims = H5Sget_simple_extent_ndims(sid)) < 0)
- goto done;
+ goto done;
/* Get the size of the dataset's datatype */
if((dtype_size = H5LDget_dset_type_size(did, NULL)) == 0)
- goto done;
+ goto done;
/* Get the dataset's data type */
if((dtid = H5Tget_native_type(H5Dget_type(did), H5T_DIR_DEFAULT)) < 0)
- goto done;
+ goto done;
/* Wait for message from the test script to start extending dataset */
if(wait_message(READER_MESSAGE) < 0)
@@ -221,56 +234,56 @@ extend_dset_two(const char *file, char *dname)
/* Loop through different variations of extending the dataset */
for(i = 0; i < TWO_NTESTS; i++) {
- /* sleep to emulate about 2 seconds of application operation */
- sleep(2);
+ /* sleep to emulate about 2 seconds of application operation */
+ sleep(2);
- /* Get current dimension sizes */
+ /* Get current dimension sizes */
if(H5LDget_dset_dims(did, cur_dims) < 0)
- goto done;
+ goto done;
- /* Set up the new extended dimension sizes */
+ /* Set up the new extended dimension sizes */
ext_dims[0] = cur_dims[0] + (hsize_t)two_tests[i][0];
ext_dims[1] = cur_dims[1] + (hsize_t)two_tests[i][1];
- /* Extend the dataset */
- if(H5Dset_extent(did, ext_dims) < 0)
- goto done;
-
- num_elmts = 1;
- for(j = 0; j < (unsigned)ndims; j++)
- num_elmts *= (unsigned)ext_dims[j];
-
- /* Compound type */
- if(!HDstrcmp(dname, DSET_CMPD_TWO)) {
-
- HDmemset(cbuf, 0, sizeof(cbuf));
- for(j = 0; j < num_elmts; j++) {
- cbuf[j].field1 = i + 1;
- cbuf[j].field2.a = i + 1;
- cbuf[j].field2.c = i + 1;
- cbuf[j].field2.b.a = i + 1;
- cbuf[j].field2.b.b = i + 1;
- cbuf[j].field2.b.c = i + 1;
- cbuf[j].field3 = i + 1;
- cbuf[j].field4.a = i + 1;
- cbuf[j].field4.b = i + 1;
- }
-
- /* Write to the dataset */
- if(H5Dwrite(did, dtid, H5S_ALL, H5S_ALL, H5P_DEFAULT, cbuf) < 0)
- goto done;
- } else { /* Integer type */
- HDmemset(ibuf, 0, sizeof(ibuf));
- for(j = 0; j < num_elmts; j++)
- ibuf[j] = (int)(i + 1);
-
- /* Write to the dataset */
- if(H5Dwrite(did, dtid, H5S_ALL, H5S_ALL, H5P_DEFAULT, ibuf) < 0)
- goto done;
- }
-
- if(H5Dflush(did) < 0)
- goto done;
+ /* Extend the dataset */
+ if(H5Dset_extent(did, ext_dims) < 0)
+ goto done;
+
+ num_elmts = 1;
+ for(j = 0; j < (unsigned)ndims; j++)
+ num_elmts *= (unsigned)ext_dims[j];
+
+ /* Compound type */
+ if(!HDstrcmp(dname, DSET_CMPD_TWO)) {
+
+ HDmemset(cbuf, 0, sizeof(cbuf));
+ for(j = 0; j < num_elmts; j++) {
+ cbuf[j].field1 = i + 1;
+ cbuf[j].field2.a = i + 1;
+ cbuf[j].field2.c = i + 1;
+ cbuf[j].field2.b.a = i + 1;
+ cbuf[j].field2.b.b = i + 1;
+ cbuf[j].field2.b.c = i + 1;
+ cbuf[j].field3 = i + 1;
+ cbuf[j].field4.a = i + 1;
+ cbuf[j].field4.b = i + 1;
+ }
+
+ /* Write to the dataset */
+ if(H5Dwrite(did, dtid, H5S_ALL, H5S_ALL, H5P_DEFAULT, cbuf) < 0)
+ goto done;
+ } else { /* Integer type */
+ HDmemset(ibuf, 0, sizeof(ibuf));
+ for(j = 0; j < num_elmts; j++)
+ ibuf[j] = (int)(i + 1);
+
+ /* Write to the dataset */
+ if(H5Dwrite(did, dtid, H5S_ALL, H5S_ALL, H5P_DEFAULT, ibuf) < 0)
+ goto done;
+ }
+
+ if(H5Dflush(did) < 0)
+ goto done;
} /* end for TWO_NTESTS */
@@ -286,8 +299,8 @@ done:
H5E_BEGIN_TRY
H5Tclose(dtid);
H5Dclose(did);
- H5Pclose(fapl);
- H5Fclose(fid);
+ H5Pclose(fapl);
+ H5Fclose(fid);
H5E_END_TRY
return(FAIL);
@@ -298,35 +311,35 @@ done:
***********************************************************************
*
* Extending a one-dimensional dataset
- * Test cases:
- * #1: increase
- * #2: decrease
- * #3: same
- * #4: decrease
- * #5: increase
+ * Test cases:
+ * #1: increase
+ * #2: decrease
+ * #3: same
+ * #4: decrease
+ * #5: increase
*
- * one_tests[ONE_NTESTS] = {3, -1, 0, -11, 2}
- * varies from 10->13->12->12->1->3
+ * one_tests[ONE_NTESTS] = {3, -1, 0, -11, 2}
+ * varies from 10->13->12->12->1->3
*
***********************************************************************
*/
static int
extend_dset_one(const char *file, char *dname)
{
- hid_t fid = -1; /* file id */
- hid_t fapl = -1; /* file access property list id */
- hid_t did = -1; /* dataset id */
- hid_t dtid = -1; /* dataset's datatype id */
- hid_t sid = -1; /* dataspace id */
- hid_t mid = -1; /* memory space id */
- unsigned i, j; /* local index variable */
- int ibuf[TEST_BUF_SIZE]; /* buffer for storing retrieved elements (integer) */
- set_t cbuf[TEST_BUF_SIZE]; /* buffer for storing retrieved elemnets (compound) */
- hsize_t cur_dims[1]; /* current dimension sizes */
- hsize_t ext_dims[1]; /* new dimension sizes after extension */
- hsize_t offset[1]; /* starting offsets of appended data */
- hsize_t count[1]; /* dimension sizes of appended data */
- size_t dtype_size; /* size of the dataset's datatype */
+ hid_t fid = -1; /* file id */
+ hid_t fapl = -1; /* file access property list id */
+ hid_t did = -1; /* dataset id */
+ hid_t dtid = -1; /* dataset's datatype id */
+ hid_t sid = -1; /* dataspace id */
+ hid_t mid = -1; /* memory space id */
+ unsigned i, j; /* local index variable */
+ int ibuf[TEST_BUF_SIZE]; /* buffer for storing retrieved elements (integer) */
+ set_t cbuf[TEST_BUF_SIZE]; /* buffer for storing retrieved elemnets (compound) */
+ hsize_t cur_dims[1]; /* current dimension sizes */
+ hsize_t ext_dims[1]; /* new dimension sizes after extension */
+ hsize_t offset[1]; /* starting offsets of appended data */
+ hsize_t count[1]; /* dimension sizes of appended data */
+ size_t dtype_size; /* size of the dataset's datatype */
/* Create a copy of file access property list */
if((fapl = H5Pcreate(H5P_FILE_ACCESS)) < 0)
@@ -337,21 +350,21 @@ extend_dset_one(const char *file, char *dname)
/* Open the file and dataset with SWMR write */
if((fid = H5Fopen(file, H5F_ACC_RDWR|H5F_ACC_SWMR_WRITE, fapl)) < 0)
- goto done;
+ goto done;
/* Send message to the test script to start "h5watch" */
send_message(WRITER_MESSAGE);
if((did = H5Dopen2(fid, dname, H5P_DEFAULT)) < 0)
- goto done;
+ goto done;
/* Get size of the dataset's datatype */
if((dtype_size = H5LDget_dset_type_size(did, NULL)) == 0)
- goto done;
+ goto done;
/* Get dataset's datatype */
if((dtid = H5Tget_native_type(H5Dget_type(did), H5T_DIR_DEFAULT)) < 0)
- goto done;
+ goto done;
/* Wait for message from the test script to start extending dataset */
wait_message(READER_MESSAGE);
@@ -359,72 +372,72 @@ extend_dset_one(const char *file, char *dname)
/* Loop through different variations of extending the dataset */
for(i = 0; i < ONE_NTESTS; i++) {
- /* sleep to emulate about 2 seconds of application operation */
- sleep(2);
-
- /* Get current dimension sizes */
- if(H5LDget_dset_dims(did, cur_dims) < 0)
- goto done;
-
- /* Set up the new extended dimension sizes */
- ext_dims[0] = cur_dims[0] + (hsize_t)one_tests[i];
-
- /* Extend the dataset */
- if(H5Dset_extent(did, ext_dims) < 0)
- goto done;
-
- /* Write to the new appended region of the dataset */
- if(one_tests[i] > 0) {
-
- /* Select the extended region */
- offset[0] = cur_dims[0];
- count[0] = (hsize_t)one_tests[i];
- if((sid = H5Dget_space(did)) < 0)
- goto done;
- if(H5Sselect_hyperslab(sid, H5S_SELECT_SET, offset, NULL, count, NULL) < 0)
- goto done;
-
- /* Set up memory space and get dataset's datatype */
- if((mid = H5Screate_simple(1, count, NULL)) < 0)
- goto done;
-
- /* Initialize data for the extended region of the dataset */
- /* Compound type */
- if(!HDstrcmp(dname, DSET_CMPD) || !HDstrcmp(dname, DSET_CMPD_ESC)) {
- HDmemset(cbuf, 0, sizeof(cbuf));
- for(j = 0; j < (unsigned)one_tests[i]; j++) {
- cbuf[j].field1 = j + 1;
- cbuf[j].field2.a = j + 2;
- cbuf[j].field2.b.a = j + 2;
- cbuf[j].field2.b.b = j + 2;
- cbuf[j].field2.b.c = j + 2;
- cbuf[j].field2.c = j + 2;
-
- cbuf[j].field3 = j + 3;
-
- cbuf[j].field4.a = j + 4;
- cbuf[j].field4.b = j + 4;
- } /* end for */
-
- /* Write to the extended region of the dataset */
- if(H5Dwrite(did, dtid, mid, sid, H5P_DEFAULT, cbuf) < 0)
- goto done;
- } else { /* Integer type */
- for(j = 0; j < (unsigned)one_tests[i]; j++)
- ibuf[j] = (int)j;
-
- /* Write to the extended region of the dataset */
- if(H5Dwrite(did, dtid, mid, sid, H5P_DEFAULT, ibuf) < 0)
- goto done;
- }
-
- /* Closing */
- if(H5Sclose(sid) < 0) goto done;
- if(H5Sclose(mid) < 0) goto done;
- } /* end if */
-
- if(H5Dflush(did) < 0)
- goto done;
+ /* sleep to emulate about 2 seconds of application operation */
+ sleep(2);
+
+ /* Get current dimension sizes */
+ if(H5LDget_dset_dims(did, cur_dims) < 0)
+ goto done;
+
+ /* Set up the new extended dimension sizes */
+ ext_dims[0] = cur_dims[0] + (hsize_t)one_tests[i];
+
+ /* Extend the dataset */
+ if(H5Dset_extent(did, ext_dims) < 0)
+ goto done;
+
+ /* Write to the new appended region of the dataset */
+ if(one_tests[i] > 0) {
+
+ /* Select the extended region */
+ offset[0] = cur_dims[0];
+ count[0] = (hsize_t)one_tests[i];
+ if((sid = H5Dget_space(did)) < 0)
+ goto done;
+ if(H5Sselect_hyperslab(sid, H5S_SELECT_SET, offset, NULL, count, NULL) < 0)
+ goto done;
+
+ /* Set up memory space and get dataset's datatype */
+ if((mid = H5Screate_simple(1, count, NULL)) < 0)
+ goto done;
+
+ /* Initialize data for the extended region of the dataset */
+ /* Compound type */
+ if(!HDstrcmp(dname, DSET_CMPD) || !HDstrcmp(dname, DSET_CMPD_ESC)) {
+ HDmemset(cbuf, 0, sizeof(cbuf));
+ for(j = 0; j < (unsigned)one_tests[i]; j++) {
+ cbuf[j].field1 = j + 1;
+ cbuf[j].field2.a = j + 2;
+ cbuf[j].field2.b.a = j + 2;
+ cbuf[j].field2.b.b = j + 2;
+ cbuf[j].field2.b.c = j + 2;
+ cbuf[j].field2.c = j + 2;
+
+ cbuf[j].field3 = j + 3;
+
+ cbuf[j].field4.a = j + 4;
+ cbuf[j].field4.b = j + 4;
+ } /* end for */
+
+ /* Write to the extended region of the dataset */
+ if(H5Dwrite(did, dtid, mid, sid, H5P_DEFAULT, cbuf) < 0)
+ goto done;
+ } else { /* Integer type */
+ for(j = 0; j < (unsigned)one_tests[i]; j++)
+ ibuf[j] = (int)j;
+
+ /* Write to the extended region of the dataset */
+ if(H5Dwrite(did, dtid, mid, sid, H5P_DEFAULT, ibuf) < 0)
+ goto done;
+ }
+
+ /* Closing */
+ if(H5Sclose(sid) < 0) goto done;
+ if(H5Sclose(mid) < 0) goto done;
+ } /* end if */
+
+ if(H5Dflush(did) < 0)
+ goto done;
} /* end for ONE_NTESTS */
@@ -438,12 +451,12 @@ extend_dset_one(const char *file, char *dname)
done:
H5E_BEGIN_TRY
- H5Sclose(sid);
- H5Sclose(mid);
+ H5Sclose(sid);
+ H5Sclose(mid);
H5Tclose(dtid);
H5Dclose(did);
- H5Pclose(fapl);
- H5Fclose(fid);
+ H5Pclose(fapl);
+ H5Fclose(fid);
H5E_END_TRY
return(FAIL);
@@ -457,8 +470,8 @@ main(int argc, const char *argv[])
char *fname = NULL;
if(argc != 3) {
- fprintf(stderr, "Should have file name and dataset name to be extended...\n");
- goto done;
+ fprintf(stderr, "Should have file name and dataset name to be extended...\n");
+ goto done;
}
/* Get the dataset name to be extended */
@@ -466,19 +479,19 @@ main(int argc, const char *argv[])
dname = strdup(argv[2]);
if(!HDstrcmp(dname, DSET_CMPD) || !HDstrcmp(dname, DSET_CMPD_ESC)) {
- if(extend_dset_one(fname, dname) < 0)
- goto done;
- } else if(!HDstrcmp(dname, DSET_ONE) ||
- !HDstrcmp(dname, DSET_ALLOC_LATE) ||
- !HDstrcmp(dname, DSET_ALLOC_EARLY)) {
- if(extend_dset_one(fname, dname) < 0)
- goto done;
+ if(extend_dset_one(fname, dname) < 0)
+ goto done;
+ } else if(!HDstrcmp(dname, DSET_ONE) ||
+ !HDstrcmp(dname, DSET_ALLOC_LATE) ||
+ !HDstrcmp(dname, DSET_ALLOC_EARLY)) {
+ if(extend_dset_one(fname, dname) < 0)
+ goto done;
} else if(!HDstrcmp(dname, DSET_TWO) || !HDstrcmp(dname, DSET_CMPD_TWO)) {
- if(extend_dset_two(fname, dname) < 0)
- goto done;
+ if(extend_dset_two(fname, dname) < 0)
+ goto done;
} else {
- fprintf(stdout, "Dataset cannot be extended...\n");
- goto done;
+ fprintf(stdout, "Dataset cannot be extended...\n");
+ goto done;
}
exit(EXIT_SUCCESS);