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/c++/examples/ptExampleFL.cpp | |
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/c++/examples/ptExampleFL.cpp')
-rw-r--r-- | hl/c++/examples/ptExampleFL.cpp | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/hl/c++/examples/ptExampleFL.cpp b/hl/c++/examples/ptExampleFL.cpp new file mode 100644 index 0000000..aa05f4e --- /dev/null +++ b/hl/c++/examples/ptExampleFL.cpp @@ -0,0 +1,89 @@ + /* 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://hdf.ncsa.uiuc.edu/HDF5/doc/Copyright.html. If you do not have * + * access to either file, you may request a copy from hdfhelp@ncsa.uiuc.edu. * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#include "H5PacketTable.h" + +/*------------------------------------------------------------------------- + * Packet Table Fixed-Length Example + * + * Example program that creates a packet table and performs + * writes and reads. + * + *------------------------------------------------------------------------- + */ + +int main(void) +{ + herr_t err; /* Return value from function calls */ + hid_t fileID; /* HDF5 identifier for file */ + hsize_t count; /* Number of records in table */ + + /* Buffers to hold data */ + int readBuffer[5]; + int writeBuffer[5]; + + /* Initialize buffers */ + for(int x=0; x<5; x++) + { + writeBuffer[x]=x; + readBuffer[x] = -1; + } + + /* Create a new HDF5 file */ + fileID = H5Fcreate("PTcppexampleFL.h5", H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); + if(fileID <0) + fprintf(stderr, "Couldn't create file.\n"); + + /* Create a fixed-length packet table. */ + FL_PacketTable ptable(fileID, "/examplePacketTable", H5T_NATIVE_INT, 1); + if(! ptable.IsValid()) + fprintf(stderr, "Unable to create packet table."); + + /* Append five packets to the packet table, one at a time */ + for(int x=0; x<5; x++) + { + err = ptable.AppendPacket( &(writeBuffer[x]) ); + if(err<0) + fprintf(stderr, "Error adding record."); + } + + /* Get the number of packets in the packet table. This should be five. */ + count = ptable.GetPacketCount(err); + if(err < 0) + fprintf(stderr, "Error getting packet count."); + + printf("Number of packets in packet table after five appends: %d\n", count); + + /* Initialize packet table's "current record" */ + ptable.ResetIndex(); + + /* Iterate through packets, read each one back */ + for(int x=0; x<5; x++) + { + err = ptable.GetNextPacket( &(readBuffer[x]) ); + if(err < 0) + fprintf(stderr, "Error reading record."); + + printf("Packet %d's value is %d.\n", x, readBuffer[x]); + } + + /* The packet table will close automatically when its object goes */ + /* out of scope. */ + + err = H5Fclose(fileID); + if( err < 0 ) + fprintf(stderr, "Failed to close file.\n"); + + return 0; +} + |