summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorElena Pourmal <epourmal@hdfgroup.org>1998-02-13 22:04:07 (GMT)
committerElena Pourmal <epourmal@hdfgroup.org>1998-02-13 22:04:07 (GMT)
commite15281db5c9b46f0f41aecb58767733fd7b5cff3 (patch)
tree2678e4d45deb0049cc51a8bc5574cbf95f7b758c
parent75c8d0278f96a7004269a8dcd9d89e81a5c81fa9 (diff)
downloadhdf5-e15281db5c9b46f0f41aecb58767733fd7b5cff3.zip
hdf5-e15281db5c9b46f0f41aecb58767733fd7b5cff3.tar.gz
hdf5-e15281db5c9b46f0f41aecb58767733fd7b5cff3.tar.bz2
[svn-r272] Example has been modified to show how to create datasets within the file and
groups. The same name is used for one of the datasets in the different groups.
-rw-r--r--examples/h5_group.c59
1 files changed, 46 insertions, 13 deletions
diff --git a/examples/h5_group.c b/examples/h5_group.c
index 662d24c..7b2dbe9 100644
--- a/examples/h5_group.c
+++ b/examples/h5_group.c
@@ -1,3 +1,9 @@
+/*
+ * This example shows how to create groups within the file and
+ * datasets within the file and groups.
+ */
+
+
#include "hdf5.h"
@@ -12,6 +18,7 @@ main()
herr_t status;
size_t dims[2];
+ size_t size[1];
/*
* Create a file.
@@ -27,24 +34,51 @@ status = H5Gclose(dir);
dir = H5Gcreate(file,"/FloatData", 0);
status = H5Gclose(dir);
+/*
+ * Create dataspace for the character string
+ */
+size[0] = 80;
+dataspace = H5Pcreate_simple(1, size, NULL);
+
+/*
+ * Create dataset "String" in the root group.
+ */
+dataset = H5Dcreate(file, "String", H5T_NATIVE_CHAR, dataspace, H5C_DEFAULT);
+H5Dclose(dataset);
+
+/*
+ * Create dataset "String" in the /IntData group.
+ */
+dataset = H5Dcreate(file, "/IntData/String", H5T_NATIVE_CHAR, dataspace,
+ H5C_DEFAULT);
+H5Dclose(dataset);
+
/*
- * Create dataset in the /IntData group by specifying full path.
+ * Create dataset "String" in the /FloatData group.
+ */
+dataset = H5Dcreate(file, "/FloatData/String", H5T_NATIVE_CHAR, dataspace,
+ H5C_DEFAULT);
+H5Pclose(dataspace);
+H5Dclose(dataset);
+
+/*
+ * Create IntArray dataset in the /IntData group by specifying full path.
*/
dims[0] = 2;
dims[1] = 3;
dataspace = H5Pcreate_simple(RANK, dims, NULL);
-dataset = H5Dcreate(file, "/IntData/IntArray", H5T_NATIVE_INT, dataspace, H5C_DEFAULT);
-
+dataset = H5Dcreate(file, "/IntData/IntArray", H5T_NATIVE_INT, dataspace,
+ H5C_DEFAULT);
H5Pclose(dataspace);
H5Dclose(dataset);
/*
- * Set current group to /IntData and attach to the dataset IntArray.
+ * Set current group to /IntData and attach to the dataset String.
*/
status = H5Gset (file, "/IntData");
-dataset = H5Dopen(file, "IntArray");
-if (dataset > 0) printf("IntArray dataset in /IntData group is found\n");
+dataset = H5Dopen(file, "String");
+if (dataset > 0) printf("String dataset in /IntData group is found\n");
H5Dclose(dataset);
/*
@@ -53,31 +87,30 @@ H5Dclose(dataset);
status = H5Gset (file, "/FloatData");
/*
- * Create two datasets
+ * Create two datasets FlatArray and DoubleArray.
*/
dims[0] = 5;
dims[1] = 10;
dataspace = H5Pcreate_simple(RANK, dims, NULL);
dataset = H5Dcreate(file, "FloatArray", H5T_NATIVE_FLOAT, dataspace, H5C_DEFAULT);
-
H5Pclose(dataspace);
H5Dclose(dataset);
dims[0] = 4;
dims[1] = 6;
dataspace = H5Pcreate_simple(RANK, dims, NULL);
-dataset = H5Dcreate(file, "DoubleArray", H5T_NATIVE_DOUBLE, dataspace, H5C_DEFAULT);
-
+dataset = H5Dcreate(file, "DoubleArray", H5T_NATIVE_DOUBLE, dataspace,
+ H5C_DEFAULT);
H5Pclose(dataspace);
H5Dclose(dataset);
/*
- * Attach to /FloatData/DoubleArray dataset
+ * Attach to /FloatData/String dataset.
*/
-dataset = H5Dopen(file, "/FloatData/DoubleArray");
-if (dataset > 0) printf("/FloatData/DoubleArray dataset is found\n");
+dataset = H5Dopen(file, "/FloatData/String");
+if (dataset > 0) printf("/FloatData/String dataset is found\n");
H5Dclose(dataset);
H5Fclose(file);