diff options
author | Elena Pourmal <epourmal@hdfgroup.org> | 1998-02-10 15:22:51 (GMT) |
---|---|---|
committer | Elena Pourmal <epourmal@hdfgroup.org> | 1998-02-10 15:22:51 (GMT) |
commit | 66d18e9bf2fc9bf96f8a3fed4807385d8cbee5fd (patch) | |
tree | 7317b1ff1e59403b8e90ca3f25c11a432f392928 /examples | |
parent | 32029aa6484842cd134b206bf5d4477f226298f4 (diff) | |
download | hdf5-66d18e9bf2fc9bf96f8a3fed4807385d8cbee5fd.zip hdf5-66d18e9bf2fc9bf96f8a3fed4807385d8cbee5fd.tar.gz hdf5-66d18e9bf2fc9bf96f8a3fed4807385d8cbee5fd.tar.bz2 |
[svn-r236] Example showing how to group objects in the HDF5 file is added.
Diffstat (limited to 'examples')
-rw-r--r-- | examples/h5_group.c | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/examples/h5_group.c b/examples/h5_group.c new file mode 100644 index 0000000..662d24c --- /dev/null +++ b/examples/h5_group.c @@ -0,0 +1,84 @@ +#include "hdf5.h" + + +#define FILE "DIR.h5" +#define RANK 2 + +main() +{ + + hid_t file, dir; + hid_t dataset, dataspace; + + herr_t status; + size_t dims[2]; + +/* + * Create a file. + */ +file = H5Fcreate(FILE, H5ACC_OVERWRITE, H5C_DEFAULT, H5C_DEFAULT); + +/* + * Create two groups in a file. + */ +dir = H5Gcreate(file, "/IntData", 0); +status = H5Gclose(dir); + +dir = H5Gcreate(file,"/FloatData", 0); +status = H5Gclose(dir); + +/* + * Create 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); + +H5Pclose(dataspace); +H5Dclose(dataset); + +/* + * Set current group to /IntData and attach to the dataset IntArray. + */ + +status = H5Gset (file, "/IntData"); +dataset = H5Dopen(file, "IntArray"); +if (dataset > 0) printf("IntArray dataset in /IntData group is found\n"); +H5Dclose(dataset); + +/* + * Set current group to /FloatData. + */ +status = H5Gset (file, "/FloatData"); + +/* + * Create two datasets + */ + +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); + +H5Pclose(dataspace); +H5Dclose(dataset); + +/* + * Attach to /FloatData/DoubleArray dataset + */ + +dataset = H5Dopen(file, "/FloatData/DoubleArray"); +if (dataset > 0) printf("/FloatData/DoubleArray dataset is found\n"); +H5Dclose(dataset); +H5Fclose(file); + +} |