summaryrefslogtreecommitdiffstats
path: root/test/extend.c
diff options
context:
space:
mode:
authorRobb Matzke <matzke@llnl.gov>1998-01-30 23:32:28 (GMT)
committerRobb Matzke <matzke@llnl.gov>1998-01-30 23:32:28 (GMT)
commit374e5ae39b6f05469c1bcbdcaf0a473f1dde1385 (patch)
tree3284232ef8b21758da14fe63347b903d3883c3c4 /test/extend.c
parentd9329a23aab4d941956ac421b11eb009a2deb32b (diff)
downloadhdf5-374e5ae39b6f05469c1bcbdcaf0a473f1dde1385.zip
hdf5-374e5ae39b6f05469c1bcbdcaf0a473f1dde1385.tar.gz
hdf5-374e5ae39b6f05469c1bcbdcaf0a473f1dde1385.tar.bz2
[svn-r209] Changes since 19980130
---------------------- ./INSTALL Added instructions for which C flags to set for debugging. ./src/H5C.c ./src/H5Cpublic.h H5Cset_chunk() takes const pointer. ./src/H5D.c ./src/H5Dprivate.h ./src/H5Dpublic.h Added H5Dextend() to extend the dimensions of a dataset. ./src/H5Osdspace.c ./src/H5P.c ./src/H5Pprivate.h ./src/H5Ppublic.h ./test/cmpd_dset.c ./test/dsets.c ./test/th5p.c Added the optional `maxdims' argument to H5Pcreate_simple() and defined constant H5P_UNLIMITED which can appear in the maxdims. Added `const' to arguments. Implemented H5Pcopy() Removed the unused file argument from H5P_modify. Added H5P_extend(). Removed the `flags' field from simple data types and we determine if the `max' or `perm' arrays are valid by looking at the pointer. Cleaned up the H5O_sdspace_debug output. ./src/H5T.c Fixed a printf format. ./MANIFEST ./test/Makefile.in ./test/extend.c [NEW] Added a test for multi-dimensional unlimited dimensions.
Diffstat (limited to 'test/extend.c')
-rw-r--r--test/extend.c131
1 files changed, 131 insertions, 0 deletions
diff --git a/test/extend.c b/test/extend.c
new file mode 100644
index 0000000..8cadd6a
--- /dev/null
+++ b/test/extend.c
@@ -0,0 +1,131 @@
+/*
+ * Copyright (C) 1998 Spizella Software
+ * All rights reserved.
+ *
+ * Programmer: Robb Matzke <matzke@llnl.gov>
+ * Friday, January 30, 1998
+ *
+ * Purpose: Tests extendable datasets.
+ */
+#include <assert.h>
+#include <hdf5.h>
+
+#define NX 100 /* USE AN EVEN NUMBER!*/
+#define NY 100 /* USE AN EVEN NUMBER!*/
+
+
+/*-------------------------------------------------------------------------
+ * Function: main
+ *
+ * Purpose: Tests extendable datasets
+ *
+ * Return: Success: exit(0)
+ *
+ * Failure: exit(non-zero)
+ *
+ * Programmer: Robb Matzke
+ * Friday, January 30, 1998
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+int
+main (void)
+{
+ hid_t file, dataset, mem_space, file_space, cparms;
+ herr_t status;
+ int i, j, k, m;
+ static int buf1[NY][NX], buf2[NX/2][NY/2];
+ static const size_t dims[2] = {NX, NY};
+ static const size_t half_dims[2] = {NX/2, NY/2};
+ static size_t maxdims[2] = {H5P_UNLIMITED, H5P_UNLIMITED};
+ static size_t size[2];
+ int offset[2];
+
+ /* Initialize buffer and space */
+ for (i=0; i<NX; i++) {
+ for (j=0; j<NY; j++) {
+ buf1[i][j] = i*NY+j;
+ }
+ }
+ mem_space = H5Pcreate_simple (2, dims, maxdims);
+ assert (mem_space>=0);
+
+ /* Create the file */
+ file = H5Fcreate ("extend.h5", H5ACC_OVERWRITE, H5C_DEFAULT, H5C_DEFAULT);
+ assert (file>=0);
+
+ /* Create the dataset which is originally NX by NY */
+ cparms = H5Ccreate (H5C_DATASET_CREATE);
+ assert (cparms>=0);
+ status = H5Cset_chunk (cparms, 2, dims);
+ assert (status>=0);
+ dataset = H5Dcreate (file, "dataset", H5T_NATIVE_INT, mem_space, cparms);
+ assert (dataset>=0);
+
+ /* Write the data */
+ for (i=0; i<5; i++) {
+ for (j=0; j<5; j++) {
+
+ /* Extend the dataset */
+ offset[0] = i * NX;
+ offset[1] = j * NY;
+ size[0] = offset[0] + NX;
+ size[1] = offset[1] + NY;
+ status = H5Dextend (dataset, size);
+ assert (status>=0);
+
+ /* Select a hyperslab */
+ file_space = H5Dget_space (dataset);
+ assert (file_space>=0);
+ status = H5Pset_hyperslab (file_space, offset, dims, NULL);
+ assert (status>=0);
+
+ /* Write to the hyperslab */
+ status = H5Dwrite (dataset, H5T_NATIVE_INT, mem_space, file_space,
+ H5C_DEFAULT, buf1);
+ assert (status>=0);
+ H5Pclose (file_space);
+ }
+ }
+ H5Pclose (mem_space);
+
+
+ /* Read the data */
+ mem_space = H5Pcreate_simple (2, half_dims, NULL);
+ for (i=0; i<10; i++) {
+ for (j=0; j<10; j++) {
+
+ /* Select a hyperslab */
+ offset[0] = i * NX/2;
+ offset[1] = j * NY/2;
+ file_space = H5Dget_space (dataset);
+ assert (file_space>=0);
+ status = H5Pset_hyperslab (file_space, offset, half_dims, NULL);
+ assert (status>=0);
+
+ /* Read */
+ status = H5Dread (dataset, H5T_NATIVE_INT, mem_space, file_space,
+ H5C_DEFAULT, buf2);
+ assert (status>=0);
+ H5Pclose (file_space);
+
+ /* Compare */
+ for (k=0; k<NX/2; k++) {
+ for (m=0; m<NY/2; m++) {
+ assert (buf2[k][m]==buf1[(i%2)*NX/2+k][(j%2)*NY/2+m]);
+ }
+ }
+ }
+ }
+
+
+ H5Dclose (dataset);
+ H5Fclose (file);
+
+ exit (0);
+}
+
+
+