diff options
author | Albert Cheng <acheng@hdfgroup.org> | 2001-09-18 05:55:14 (GMT) |
---|---|---|
committer | Albert Cheng <acheng@hdfgroup.org> | 2001-09-18 05:55:14 (GMT) |
commit | 93fd360fb1d2c8f7350350dbaa142b5def9c5da5 (patch) | |
tree | e342344af4fd6bb7944dbeff422c4bbe8ce0d0f0 /examples | |
parent | 5921ab6be1f8f96109587d4ea799f931e8372fca (diff) | |
download | hdf5-93fd360fb1d2c8f7350350dbaa142b5def9c5da5.zip hdf5-93fd360fb1d2c8f7350350dbaa142b5def9c5da5.tar.gz hdf5-93fd360fb1d2c8f7350350dbaa142b5def9c5da5.tar.bz2 |
[svn-r4449] Purpose:
Feature
Description:
Added an example program showing how to use different virtual
file drivers. First example is to show the Split File driver.
Platforms tested:
eirene.
Diffstat (limited to 'examples')
-rw-r--r-- | examples/Makefile.in | 9 | ||||
-rw-r--r-- | examples/h5_drivers.c | 89 |
2 files changed, 95 insertions, 3 deletions
diff --git a/examples/Makefile.in b/examples/Makefile.in index 8ec891c..fe5f296 100644 --- a/examples/Makefile.in +++ b/examples/Makefile.in @@ -17,12 +17,12 @@ LIBHDF5=../src/libhdf5.la ## `make check' will run. List them in the order they should be run. TEST_PROGS_PARA=ph5example TEST_PROGS=h5_write h5_read h5_extend_write h5_chunk_read h5_compound \ - h5_group h5_select h5_attribute h5_mount h5_reference \ + h5_group h5_select h5_attribute h5_mount h5_reference h5_drivers \ $(TEST_PROGS_PARA) ## These are the files that `make clean' (and derivatives) will remove from ## this directory. -CLEAN=*.h5 +CLEAN=*.h5 *.raw *.meta ## List all source files here. The list of object files will be ## created by replacing the `.c' with a `.o'. This list is necessary @@ -30,7 +30,7 @@ CLEAN=*.h5 TEST_SRC_PARA=ph5example.c 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_mount.c \ - h5_reference.c \ + h5_reference.c h5_drivers.c \ $(TEST_SRC_PARA) TEST_OBJ=$(TEST_SRC:.c=.lo) @@ -66,6 +66,9 @@ h5_mount: h5_mount.lo h5_reference: h5_reference.lo @$(LT_LINK_EXE) $(CFLAGS) -o $@ h5_reference.lo $(LIBHDF5) $(LDFLAGS) $(LIBS) +h5_drivers: h5_drivers.lo + @$(LT_LINK_EXE) $(CFLAGS) -o $@ h5_drivers.lo $(LIBHDF5) $(LDFLAGS) $(LIBS) + ph5example: ph5example.lo @$(LT_LINK_EXE) $(CFLAGS) -o $@ $@.lo $(LIBHDF5) $(LDFLAGS) $(LIBS) diff --git a/examples/h5_drivers.c b/examples/h5_drivers.c new file mode 100644 index 0000000..4c4d6d9 --- /dev/null +++ b/examples/h5_drivers.c @@ -0,0 +1,89 @@ +/* + * This shows how to use the hdf5 virtual file drivers. + * The example codes here do not check return values for the + * sake of simplicity. As in all proper programs, return codes + * should be checked. + */ + +#include "hdf5.h" +#include "stdlib.h" + +/* global variables */ +int cleanup_g = -1; /* whether to clean. Init to not set. */ + +/* prototypes */ +void cleanup(const char *); +void split_file(void); + + +/* + * Cleanup a file unless $HDF5_NOCLEANUP is set. + */ +void +cleanup(const char *filename) +{ + if (cleanup_g == -1) + cleanup_g = getenv("HDF5_NOCLEANUP") ? 0 : 1; + if (cleanup_g) + remove(filename); +} + + +/* + * This shows how to use the split file driver. + */ +void +split_file(void) +{ + hid_t fapl, fid; + + /* Example 1: Both metadata and rawdata files are in the same */ + /* directory. Use Station1-m.h5 and Station1-r.h5 as */ + /* the metadata and rawdata files. */ + fapl = H5Pcreate(H5P_FILE_ACCESS); + H5Pset_fapl_split(fapl, "-m.h5", H5P_DEFAULT, "-r.h5", H5P_DEFAULT); + fid=H5Fcreate("Station1",H5F_ACC_TRUNC,H5P_DEFAULT,fapl); + /* using the file ... */ + H5Fclose(fid); + H5Pclose(fapl); + /* Remove files created */ + cleanup("Station1-m.h5"); + cleanup("Station1-r.h5"); + + /* Example 2: metadata and rawdata files are in different */ + /* directories. Use PointA-m.h5 and /tmp/PointA-r.h5 as */ + /* the metadata and rawdata files. */ + fapl = H5Pcreate(H5P_FILE_ACCESS); + H5Pset_fapl_split(fapl, "-m.h5", H5P_DEFAULT, "/tmp/%s-r.h5", H5P_DEFAULT); + fid=H5Fcreate("PointA",H5F_ACC_TRUNC,H5P_DEFAULT,fapl); + /* using the file ... */ + H5Fclose(fid); + H5Pclose(fapl); + /* Remove files created */ + cleanup("PointA-m.h5"); + cleanup("/tmp/PointA-r.h5"); + + /* Example 3: Using default extension names for the metadata */ + /* and rawdata files. Use Measure.meta and Measure.raw as */ + /* the metadata and rawdata files. */ + fapl = H5Pcreate(H5P_FILE_ACCESS); + H5Pset_fapl_split(fapl, NULL, H5P_DEFAULT, NULL, H5P_DEFAULT); + fid=H5Fcreate("Measure",H5F_ACC_TRUNC,H5P_DEFAULT,fapl); + /* using the file ... */ + H5Fclose(fid); + H5Pclose(fapl); + /* Remove files created */ + cleanup("Measure.meta"); + cleanup("Measure.raw"); +} + + +/* Main Body */ +int +main (void) +{ + + split_file(); + + return(0); +} |