From 7155aa6f1dbf1d01765f5a61dbbeb13098f548f6 Mon Sep 17 00:00:00 2001 From: Scot Breitenfeld Date: Tue, 11 Dec 2012 23:00:34 -0500 Subject: [svn-r23091] Changed C examples to reflect changes in documentation via Barbara; mainly program additions from tutorial. Tested: jam (gnu compilers) --- MANIFEST | 9 +++ examples/CMakeLists.txt | 14 +++++ examples/Makefile.am | 22 ++++++- examples/Makefile.in | 22 ++++++- examples/h5_cmprss.c | 125 +++++++++++++++++++++++++++++++++++++++ examples/h5_crtatt.c | 63 ++++++++++++++++++++ examples/h5_crtdat.c | 51 ++++++++++++++++ examples/h5_crtgrp.c | 40 +++++++++++++ examples/h5_crtgrpar.c | 48 +++++++++++++++ examples/h5_crtgrpd.c | 91 ++++++++++++++++++++++++++++ examples/h5_extend.c | 146 +++++++++++++++++++++++++++++++++++++++++++++ examples/h5_rdwt.c | 53 +++++++++++++++++ examples/h5_subset.c | 153 ++++++++++++++++++++++++++++++++++++++++++++++++ examples/run-c-ex.sh.in | 20 ++++++- 14 files changed, 852 insertions(+), 5 deletions(-) create mode 100644 examples/h5_cmprss.c create mode 100644 examples/h5_crtatt.c create mode 100644 examples/h5_crtdat.c create mode 100644 examples/h5_crtgrp.c create mode 100644 examples/h5_crtgrpar.c create mode 100644 examples/h5_crtgrpd.c create mode 100644 examples/h5_extend.c create mode 100644 examples/h5_rdwt.c create mode 100644 examples/h5_subset.c diff --git a/MANIFEST b/MANIFEST index 6eb1110..297635d 100644 --- a/MANIFEST +++ b/MANIFEST @@ -121,6 +121,15 @@ ./examples/Makefile.in ./examples/h5_chunk_read.c ./examples/h5_compound.c +./examples/h5_crtgrpd.c +./examples/h5_subset.c +./examples/h5_cmprss.c +./examples/h5_rdwt.c +./examples/h5_crtgrpar.c +./examples/h5_extend.c +./examples/h5_crtatt.c +./examples/h5_crtgrp.c +./examples/h5_crtdat.c ./examples/h5_drivers.c ./examples/h5_dtransform.c ./examples/h5_elink_unix2win.c diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index b23c6f8..d7fc67a 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -10,6 +10,15 @@ ADD_DEFINITIONS (${HDF5_EXTRA_C_FLAGS}) # Define Sources #----------------------------------------------------------------------------- SET (examples + h5_crtdat + h5_rdwt + h5_crtatt + h5_crtgrp + h5_crtgrpar + h5_crtgrpd + h5_cmprss + h5_extend + h5_subset h5_write h5_read h5_extend_write @@ -51,11 +60,15 @@ IF (BUILD_TESTING) -E remove Attributes.h5 btrees_file.h5 + cmprss.h5 default_file.h5 + dset.h5 + extend.h5 extlink_prefix_source.h5 extlink_source.h5 extlink_target.h5 group.h5 + groups.h5 hard_link.h5 mount1.h5 mount2.h5 @@ -71,6 +84,7 @@ IF (BUILD_TESTING) separate_indexes_file.h5 small_lists_file.h5 soft_link.h5 + subset.h5 unix2win.h5 ) IF (NOT "${last_test}" STREQUAL "") diff --git a/examples/Makefile.am b/examples/Makefile.am index 58f50e7..d8eac95 100644 --- a/examples/Makefile.am +++ b/examples/Makefile.am @@ -29,7 +29,9 @@ endif # Don't tell automake about them, because if it knew they were programs, # it would try to compile them instead of using the h5cc script. # Use the boilerplate in config/examples.am instead. -EXAMPLE_PROG = h5_write h5_read h5_extend_write h5_chunk_read h5_compound \ +EXAMPLE_PROG = h5_write h5_read h5_extend_write h5_chunk_read h5_compound \ + h5_crtgrpd h5_subset h5_cmprss h5_rdwt h5_crtgrpar h5_extend \ + h5_crtatt h5_crtgrp h5_crtdat \ h5_group h5_select h5_attribute h5_mount h5_reference h5_drivers \ h5_ref2reg h5_extlink h5_elink_unix2win h5_shared_mesg TEST_SCRIPT=testh5cc.sh @@ -37,6 +39,8 @@ TEST_SCRIPT=testh5cc.sh # Install files # List all file that should be installed in examples directory INSTALL_FILES = h5_write.c h5_read.c h5_extend_write.c h5_chunk_read.c \ + h5_crtgrpd.c h5_subset.c h5_cmprss.c h5_rdwt.c h5_crtgrpar.c \ + h5_extend.c h5_crtatt.c h5_crtgrp.c h5_crtdat.c \ h5_compound.c h5_group.c h5_select.c h5_attribute.c h5_mount.c \ h5_reference.c h5_drivers.c h5_extlink.c h5_elink_unix2win.c \ h5_ref2reg.c h5_shared_mesg.c ph5example.c @@ -55,9 +59,14 @@ $(EXTRA_PROG): $(H5CC) $(H5CC) $(H5CCFLAGS) $(CFLAGS) -o $@ $(srcdir)/$@.c; endif -# Two of the examples depend on files created by other examples. +# Some examples depend on files created by other examples. h5_read.chkexe_: h5_write.chkexe_ h5_chunk_read.chkexe_: h5_extend_write.chkexe_ +h5_crtgrpd.chkexe_: h5_crtgrpar.chkexe_ +# h5_rdwt and h5_crtatt both modify the same file created by +# h5_crtdat. Serialize them. +h5_rdwt.chkexe_: h5_crtdat.chkexe_ +h5_crtatt.chkexe_: h5_rdwt.chkexe_ # The external link examples demonstrate how to use paths; they need # directories to be created to do this. @@ -82,6 +91,15 @@ EXAMPLETOPDIR=${DESTDIR}$(exec_prefix)/share/hdf5_examples # library above. h5_chunk_read: $(srcdir)/h5_chunk_read.c h5_compound: $(srcdir)/h5_compound.c +h5_crtgrpd: $(srcdir)/h5_crtgrpd.c +h5_subset: $(srcdir)/h5_subset.c +h5_cmprss: $(srcdir)/h5_cmprss.c +h5_rdwt: $(srcdir)/h5_rdwt.c +h5_crtgrpar: $(srcdir)/h5_crtgrpar.c +h5_extend: $(srcdir)/h5_extend.c +h5_crtatt: $(srcdir)/h5_crtatt.c +h5_crtgrp: $(srcdir)/h5_crtgrp.c +h5_crtdat: $(srcdir)/h5_crtdat.c h5_extend_write: $(srcdir)/h5_extend_write.c h5_group: $(srcdir)/h5_group.c h5_write: $(srcdir)/h5_write.c diff --git a/examples/Makefile.in b/examples/Makefile.in index 04c010d..b6dfab5 100644 --- a/examples/Makefile.in +++ b/examples/Makefile.in @@ -394,7 +394,9 @@ CHECK_CLEANFILES = *.chkexe *.chklog *.clog $(EXTLINK_DIRS) *.h5 # Don't tell automake about them, because if it knew they were programs, # it would try to compile them instead of using the h5cc script. # Use the boilerplate in config/examples.am instead. -EXAMPLE_PROG = h5_write h5_read h5_extend_write h5_chunk_read h5_compound \ +EXAMPLE_PROG = h5_write h5_read h5_extend_write h5_chunk_read h5_compound \ + h5_crtgrpd h5_subset h5_cmprss h5_rdwt h5_crtgrpar h5_extend \ + h5_crtatt h5_crtgrp h5_crtdat \ h5_group h5_select h5_attribute h5_mount h5_reference h5_drivers \ h5_ref2reg h5_extlink h5_elink_unix2win h5_shared_mesg @@ -403,6 +405,8 @@ TEST_SCRIPT = testh5cc.sh # Install files # List all file that should be installed in examples directory INSTALL_FILES = h5_write.c h5_read.c h5_extend_write.c h5_chunk_read.c \ + h5_crtgrpd.c h5_subset.c h5_cmprss.c h5_rdwt.c h5_crtgrpar.c \ + h5_extend.c h5_crtatt.c h5_crtgrp.c h5_crtdat.c \ h5_compound.c h5_group.c h5_select.c h5_attribute.c h5_mount.c \ h5_reference.c h5_drivers.c h5_extlink.c h5_elink_unix2win.c \ h5_ref2reg.c h5_shared_mesg.c ph5example.c @@ -668,9 +672,14 @@ help: @BUILD_PARALLEL_CONDITIONAL_FALSE@$(EXTRA_PROG): $(H5CC) @BUILD_PARALLEL_CONDITIONAL_FALSE@ $(H5CC) $(H5CCFLAGS) $(CFLAGS) -o $@ $(srcdir)/$@.c; -# Two of the examples depend on files created by other examples. +# Some examples depend on files created by other examples. h5_read.chkexe_: h5_write.chkexe_ h5_chunk_read.chkexe_: h5_extend_write.chkexe_ +h5_crtgrpd.chkexe_: h5_crtgrpar.chkexe_ +# h5_rdwt and h5_crtatt both modify the same file created by +# h5_crtdat. Serialize them. +h5_rdwt.chkexe_: h5_crtdat.chkexe_ +h5_crtatt.chkexe_: h5_rdwt.chkexe_ $(EXTLINK_DIRS): echo $(mkdir_p) $@ @@ -684,6 +693,15 @@ $(EXTLINK_DIRS): # library above. h5_chunk_read: $(srcdir)/h5_chunk_read.c h5_compound: $(srcdir)/h5_compound.c +h5_crtgrpd: $(srcdir)/h5_crtgrpd.c +h5_subset: $(srcdir)/h5_subset.c +h5_cmprss: $(srcdir)/h5_cmprss.c +h5_rdwt: $(srcdir)/h5_rdwt.c +h5_crtgrpar: $(srcdir)/h5_crtgrpar.c +h5_extend: $(srcdir)/h5_extend.c +h5_crtatt: $(srcdir)/h5_crtatt.c +h5_crtgrp: $(srcdir)/h5_crtgrp.c +h5_crtdat: $(srcdir)/h5_crtdat.c h5_extend_write: $(srcdir)/h5_extend_write.c h5_group: $(srcdir)/h5_group.c h5_write: $(srcdir)/h5_write.c diff --git a/examples/h5_cmprss.c b/examples/h5_cmprss.c new file mode 100644 index 0000000..efaf953 --- /dev/null +++ b/examples/h5_cmprss.c @@ -0,0 +1,125 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * Copyright by The HDF Group. * + * Copyright by the Board of Trustees of the University of Illinois. * + * All rights reserved. * + * * + * This file is part of HDF5. The full HDF5 copyright notice, including * + * terms governing use, modification, and redistribution, is contained in * + * the files COPYING and Copyright.html. COPYING can be found at the root * + * of the source code distribution tree; Copyright.html can be found at the * + * root level of an installed copy of the electronic HDF5 document set and * + * is linked from the top-level documents page. It can also be found at * + * http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have * + * access to either file, you may request a copy from help@hdfgroup.org. * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +/* + * This example illustrates how to create a compressed dataset. + * It is used in the HDF5 Tutorial. + */ + +#include "hdf5.h" + +#define FILE "cmprss.h5" +#define RANK 2 +#define DIM0 100 +#define DIM1 20 + +int main () { + + hid_t file_id, dataset_id, dataspace_id; /* identifiers */ + hid_t plist_id; + + size_t nelmts; + unsigned flags, filter_info; + H5Z_filter_t filter_type; + + herr_t status; + hsize_t dims[2]; + hsize_t cdims[2]; + + int idx; + int i,j, numfilt; + int buf[DIM0][DIM1]; + int rbuf [DIM0][DIM1]; + + /* Uncomment these variables to use SZIP compression + unsigned szip_options_mask; + unsigned szip_pixels_per_block; + */ + + /* Create a file. */ + file_id = H5Fcreate (FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); + + + /* Create dataset "Compressed Data" in the group using absolute name. */ + dims[0] = DIM0; + dims[1] = DIM1; + dataspace_id = H5Screate_simple (RANK, dims, NULL); + + plist_id = H5Pcreate (H5P_DATASET_CREATE); + + /* Dataset must be chunked for compression */ + cdims[0] = 20; + cdims[1] = 20; + status = H5Pset_chunk (plist_id, 2, cdims); + + /* Set ZLIB / DEFLATE Compression using compression level 6. + * To use SZIP Compression comment out these lines. + */ + status = H5Pset_deflate (plist_id, 6); + + /* Uncomment these lines to set SZIP Compression + szip_options_mask = H5_SZIP_NN_OPTION_MASK; + szip_pixels_per_block = 16; + status = H5Pset_szip (plist_id, szip_options_mask, szip_pixels_per_block); + */ + + dataset_id = H5Dcreate (file_id, "Compressed_Data", H5T_STD_I32BE, + dataspace_id, H5P_DEFAULT, plist_id, H5P_DEFAULT); + + for (i = 0; i< DIM0; i++) + for (j=0; j