diff options
author | James Laird <jlaird@hdfgroup.org> | 2005-12-09 20:59:11 (GMT) |
---|---|---|
committer | James Laird <jlaird@hdfgroup.org> | 2005-12-09 20:59:11 (GMT) |
commit | b1fd3f565750a18246239cdac50e433d6d668524 (patch) | |
tree | f09179e1fb2a04e01983c85f9a3873c159fefda7 /hl/examples/ptExampleFL.c | |
parent | 9124030f911f002bd49ec8bccd4c051df410cc72 (diff) | |
download | hdf5-b1fd3f565750a18246239cdac50e433d6d668524.zip hdf5-b1fd3f565750a18246239cdac50e433d6d668524.tar.gz hdf5-b1fd3f565750a18246239cdac50e433d6d668524.tar.bz2 |
[svn-r11780] Purpose:
Added high-level example directories
Description:
Refactored common code out of examples Makefiles.am, added high-level
example directories, added packet table examples.
Solution:
Examples now draw from a common config/examples.am file, which
contains rules for installing, uninstalling, and cleaning examples.
High-level example directories are mostly empty, except for the
C and C++ packet table tests.
Platforms tested:
mir, sleipnir, copper, shanti
Diffstat (limited to 'hl/examples/ptExampleFL.c')
-rw-r--r-- | hl/examples/ptExampleFL.c | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/hl/examples/ptExampleFL.c b/hl/examples/ptExampleFL.c new file mode 100644 index 0000000..fb93d01 --- /dev/null +++ b/hl/examples/ptExampleFL.c @@ -0,0 +1,102 @@ +/**************************************************************************** + * NCSA HDF * + * Scientific Data Technologies * + * National Center for Supercomputing Applications * + * University of Illinois at Urbana-Champaign * + * 605 E. Springfield, Champaign IL 61820 * + * * + * For conditions of distribution and use, see the accompanying * + * hdf/COPYING f. * + * * + ****************************************************************************/ + +#include "H5PT.h" +#include <stdlib.h> + +/*------------------------------------------------------------------------- + * Packet Table Fixed-Length Example + * + * Example program that creates a packet table and performs + * writes and reads. + * + *------------------------------------------------------------------------- + */ + +int main(void) +{ + hid_t fid; /* File identifier */ + hid_t ptable; /* Packet table identifier */ + + herr_t err; /* Function return status */ + hsize_t count; /* Number of records in the table */ + + int x; /* Loop variable */ + + /* Buffers to hold data */ + int writeBuffer[5]; + int readBuffer[5]; + + /* Initialize buffers */ + for(x=0; x<5; x++) + { + writeBuffer[x]=x; + readBuffer[x] = -1; + } + + /* Create a file using default properties */ + fid=H5Fcreate("packet_table_FLexample.h5",H5F_ACC_TRUNC,H5P_DEFAULT,H5P_DEFAULT); + + /* Create a fixed-length packet table within the file */ + /* This table's "packets" will be simple integers. */ + ptable = H5PTcreate_fl(fid, "Packet Test Dataset", H5T_NATIVE_INT, 1); + if(ptable == H5I_INVALID_HID) + goto out; + + /* Write one packet to the packet table */ + err = H5PTappend(ptable, 1, &(writeBuffer[0]) ); + if(err < 0) + goto out; + + /* Write several packets to the packet table */ + err = H5PTappend(ptable, 4, &(writeBuffer[1]) ); + if(err < 0) + goto out; + + /* Get the number of packets in the packet table. This should be five. */ + err = H5PTget_num_packets(ptable, &count); + if(err < 0) + goto out; + + printf("Number of packets in packet table after five appends: %d\n", count); + + /* Initialize packet table's "current record" */ + err = H5PTcreate_index(ptable); + if(err < 0) + goto out; + + /* Iterate through packets, read each one back */ + for(x=0; x<5; x++) + { + err = H5PTget_next(ptable, 1, &(readBuffer[x]) ); + if(err < 0) + goto out; + + printf("Packet %d's value is %d\n", x, readBuffer[x]); + } + + /* Close the packet table */ + err = H5PTclose(ptable); + if(err < 0) + goto out; + + /* Close the file */ + H5Fclose(fid); + + return 0; + + out: /* An error has occurred. Clean up and exit. */ + H5PTclose(ptable); + H5Fclose(fid); + return -1; +} + |