diff options
author | Elena Pourmal <epourmal@hdfgroup.org> | 1999-06-25 18:11:09 (GMT) |
---|---|---|
committer | Elena Pourmal <epourmal@hdfgroup.org> | 1999-06-25 18:11:09 (GMT) |
commit | debc8037fb65a9cfb7b77126f3d5ec0827e6d12c (patch) | |
tree | e37e815d7b4fd46dc870237725285999f80eac7f /examples | |
parent | 40abc593504c8f10a8e3c9935122aba7b4f3fd56 (diff) | |
download | hdf5-debc8037fb65a9cfb7b77126f3d5ec0827e6d12c.zip hdf5-debc8037fb65a9cfb7b77126f3d5ec0827e6d12c.tar.gz hdf5-debc8037fb65a9cfb7b77126f3d5ec0827e6d12c.tar.bz2 |
[svn-r1380] Two new examples h5_mount.c and h5_reference.c were added.
h5_select.c was modified to use fill values, and h5_group.c was modified
to show how H5Giterate can be used to get information about the objects in
a group.
Necessary changes were done to the Makefile.in.
Tested on Solaris 2.6 (baldric)
Diffstat (limited to 'examples')
-rw-r--r-- | examples/Makefile.in | 10 | ||||
-rw-r--r-- | examples/h5_reference.c | 146 |
2 files changed, 154 insertions, 2 deletions
diff --git a/examples/Makefile.in b/examples/Makefile.in index ae67254..171c8bd 100644 --- a/examples/Makefile.in +++ b/examples/Makefile.in @@ -17,7 +17,7 @@ LIBHDF5=../src/libhdf5.la # These are the programs that `make all' or `make tests' will build and which # `make check' will run. List them in the order they should be run. TEST_PROGS= h5_write h5_read h5_extend_write h5_chunk_read h5_compound \ - h5_group h5_select h5_attribute + h5_group h5_select h5_attribute h5_mount h5_reference # These are the files that `make clean' (and derivatives) will remove from # this directory. @@ -27,7 +27,8 @@ CLEAN=*.h5 *.o *.lo # created by replacing the `.c' with a `.o'. This list is necessary # for building automatic dependencies. TEST_SRC=h5_chunk_read.c h5_compound.c h5_extend_write.c h5_group.c \ - h5_read.c h5_write.c h5_select.c h5_attribute.c + h5_read.c h5_write.c h5_select.c h5_attribute.c h5_mount.c \ + h5_reference.c TEST_OBJ=$(PROG_SRC:.c=.lo) @@ -57,4 +58,9 @@ h5_select: h5_select.lo h5_attribute: h5_attribute.lo @$(LT_LINK_EXE) $(CFLAGS) -o $@ h5_attribute.lo $(LIBHDF5) $(LDFLAGS) $(LIBS) +h5_mount: h5_mount.lo + @$(LT_LINK_EXE) $(CFLAGS) -o $@ h5_mount.lo $(LIBHDF5) $(LDFLAGS) $(LIBS) + +h5_reference: h5_reference.lo + @$(LT_LINK_EXE) $(CFLAGS) -o $@ h5_reference.lo $(LIBHDF5) $(LDFLAGS) $(LIBS) @CONCLUDE@ diff --git a/examples/h5_reference.c b/examples/h5_reference.c new file mode 100644 index 0000000..a69afe2 --- /dev/null +++ b/examples/h5_reference.c @@ -0,0 +1,146 @@ + /* + * This program illustrates how references to the objects can be used. + * Program creates two datasets in the file. It also creates the third + * dataset, and references to the first two datasets are stored in it. + * Program reopens the file and reads dataset with the references. + * References are used to open first two datasets and read datatspace + * and datatype information about them. + * + */ + +#include<hdf5.h> + +#define FILE "refere.h5" + +int +main(void) { + hid_t fid; /* File, datasets, datatypes and */ + hid_t did_a, sid_a; /* dataspaces identifiers for three */ + hid_t did_b, tid_b, sid_b; /* datasets. */ + hid_t did_r, tid_r, sid_r; + herr_t status; + + hobj_ref_t *wbuf; /* buffer to write to disk */ + hobj_ref_t *rbuf; /* buffer to read from disk */ + + + hsize_t dim_r[1]; + hsize_t dim_a[1]; + hsize_t dim_b[2]; + + herr_t ret; /* return values */ + + /* + * Create a file using default properties. + */ + fid = H5Fcreate(FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); + + /* + * Create dataset "A" in the file. + */ + dim_a[0] = 5; + sid_a = H5Screate_simple(1, dim_a, NULL); + did_a = H5Dcreate(fid, "A", H5T_NATIVE_INT, sid_a, H5P_DEFAULT); + + /* + * Create dataset "B" in the file. + */ + dim_b[0] = 2; + dim_b[1] = 6; + sid_b = H5Screate_simple(2, dim_b, NULL); + did_b = H5Dcreate(fid, "B", H5T_NATIVE_FLOAT, sid_b, H5P_DEFAULT); + + /* + * Create dataset "R" to store references to the datasets "A" and "B". + */ + dim_r[0] = 2; + sid_r = H5Screate_simple(1, dim_r, NULL); + tid_r = H5Tcopy(H5T_STD_REF_OBJ); + did_r = H5Dcreate(fid, "R", tid_r, sid_r, H5P_DEFAULT ); + + /* + * Allocate write and read buffers. + */ + wbuf = malloc(sizeof(hobj_ref_t)*2); + rbuf = malloc(sizeof(hobj_ref_t)*2); + + /* + * Create references to the datasets "A" and "B" + * and store them in the wbuf. + */ + H5Rcreate(&wbuf[0], fid, "A", H5R_OBJECT, -1); + H5Rcreate(&wbuf[1], fid, "B", H5R_OBJECT, -1); + + /* + * Write dataset R using default transfer properties. + */ + status = H5Dwrite(did_r, H5T_STD_REF_OBJ, H5S_ALL, H5S_ALL, + H5P_DEFAULT, wbuf); + + /* + * Close all objects. + */ + H5Sclose(sid_a); + H5Dclose(did_a); + + H5Sclose(sid_b); + H5Dclose(did_b); + + H5Tclose(tid_r); + H5Sclose(sid_r); + H5Dclose(did_r); + + H5Fclose(fid); + + /* + * Reopen the file. + */ + fid = H5Fopen(FILE, H5F_ACC_RDWR, H5P_DEFAULT); + + /* + * Open and read dataset "R". + */ + did_r = H5Dopen(fid, "R"); + status = H5Dread(did_r, H5T_STD_REF_OBJ, H5S_ALL, H5S_ALL, + H5P_DEFAULT, rbuf); + + /* + * Open dataset A using reference to it. + */ + did_a = H5Rdereference(did_r, H5R_OBJECT, &rbuf[0]); + + /* + * Get rank of the dataset "A" + */ + + printf("\n"); + sid_a = H5Dget_space(did_a); + ret = H5Sget_simple_extent_ndims(sid_a); + + if(ret == 1) printf("Rank of A is %d.\n", ret); + printf("\n"); + + /* + * Get datatype of the dataset "B" + */ + did_b = H5Rdereference(did_r, H5R_OBJECT, &rbuf[1]); + tid_b = H5Dget_type(did_b); + if(H5Tequal(tid_b, H5T_NATIVE_FLOAT)) + printf("Datatype of B is H5T_NATIVE_FLOAT.\n"); + printf("\n"); + + /* + * Close all objects. + */ + H5Dclose(did_a); + H5Sclose(sid_a); + H5Dclose(did_b); + H5Tclose(tid_b); + H5Fclose(fid); + + return 0; + + } + + + |