2006-01-09 23:41:38 +08:00
|
|
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
2007-02-07 22:56:24 +08:00
|
|
|
* Copyright by The HDF Group. *
|
2006-01-09 23:41:38 +08:00
|
|
|
* 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 *
|
2007-02-07 22:56:24 +08:00
|
|
|
* 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. *
|
2006-01-09 23:41:38 +08:00
|
|
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
2005-12-10 04:59:11 +08:00
|
|
|
|
2006-04-20 12:49:06 +08:00
|
|
|
#include "hdf5_hl.h"
|
2005-12-10 04:59:11 +08:00
|
|
|
#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 */
|
2006-09-27 02:25:03 +08:00
|
|
|
/* This table's "packets" will be simple integers and it will use compression
|
|
|
|
* level 5. */
|
|
|
|
ptable = H5PTcreate_fl(fid, "Packet Test Dataset", H5T_NATIVE_INT, (hsize_t)100, 5);
|
2005-12-10 04:59:11 +08:00
|
|
|
if(ptable == H5I_INVALID_HID)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
/* Write one packet to the packet table */
|
2006-04-30 01:10:29 +08:00
|
|
|
err = H5PTappend(ptable, (hsize_t)1, &(writeBuffer[0]) );
|
2005-12-10 04:59:11 +08:00
|
|
|
if(err < 0)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
/* Write several packets to the packet table */
|
2006-04-30 01:10:29 +08:00
|
|
|
err = H5PTappend(ptable, (hsize_t)4, &(writeBuffer[1]) );
|
2005-12-10 04:59:11 +08:00
|
|
|
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;
|
|
|
|
|
2007-04-04 03:51:14 +08:00
|
|
|
printf("Number of packets in packet table after five appends: %d\n", (int)count);
|
2005-12-10 04:59:11 +08:00
|
|
|
|
|
|
|
/* 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++)
|
|
|
|
{
|
2006-04-30 01:10:29 +08:00
|
|
|
err = H5PTget_next(ptable, (hsize_t)1, &(readBuffer[x]) );
|
2005-12-10 04:59:11 +08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|