diff options
-rwxr-xr-x | configure | 2 | ||||
-rw-r--r-- | hl/c++/examples/ptExampleFL.cpp | 4 | ||||
-rw-r--r-- | hl/c++/src/H5PacketTable.cpp | 6 | ||||
-rw-r--r-- | hl/c++/src/H5PacketTable.h | 9 | ||||
-rw-r--r-- | hl/c++/test/Makefile.am | 6 | ||||
-rw-r--r-- | hl/c++/test/Makefile.in | 11 | ||||
-rw-r--r-- | hl/c++/test/ptableTest.cpp | 60 | ||||
-rw-r--r-- | hl/c++/test/ptableTest.h | 6 | ||||
-rw-r--r-- | hl/examples/ptExampleFL.c | 5 | ||||
-rw-r--r-- | hl/src/H5PT.c | 12 | ||||
-rw-r--r-- | hl/src/H5PTpublic.h | 3 | ||||
-rw-r--r-- | hl/test/Makefile.am | 6 | ||||
-rw-r--r-- | hl/test/Makefile.in | 24 | ||||
-rw-r--r-- | hl/test/h5hltest.h | 10 | ||||
-rw-r--r-- | hl/test/test_packet.c | 199 | ||||
-rw-r--r-- | src/H5O.c | 1 |
16 files changed, 274 insertions, 90 deletions
@@ -1,5 +1,5 @@ #! /bin/sh -# From configure.in Id: configure.in 12669 2006-09-15 20:20:39Z koziol . +# From configure.in Id: configure.in 12670 2006-09-16 20:38:42Z hdfadmin . # Guess values for system-dependent variables and create Makefiles. # Generated by GNU Autoconf 2.59 for HDF5 1.8.0-alpha6. # diff --git a/hl/c++/examples/ptExampleFL.cpp b/hl/c++/examples/ptExampleFL.cpp index 4f9c167..93fc58e 100644 --- a/hl/c++/examples/ptExampleFL.cpp +++ b/hl/c++/examples/ptExampleFL.cpp @@ -46,8 +46,8 @@ int main(void) 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); + /* Create a fixed-length packet table with compression level 5. */ + FL_PacketTable ptable(fileID, "/examplePacketTable", H5T_NATIVE_INT, 100, 5); if(! ptable.IsValid()) fprintf(stderr, "Unable to create packet table."); diff --git a/hl/c++/src/H5PacketTable.cpp b/hl/c++/src/H5PacketTable.cpp index 6a16807..dc34995 100644 --- a/hl/c++/src/H5PacketTable.cpp +++ b/hl/c++/src/H5PacketTable.cpp @@ -124,9 +124,9 @@ * the packet table, the ID of the datatype of the set, and the size * of a memory chunk used in chunking. */ - FL_PacketTable::FL_PacketTable(hid_t fileID, char* name, hid_t dtypeID, int chunkSize) + FL_PacketTable::FL_PacketTable(hid_t fileID, char* name, hid_t dtypeID, hsize_t chunkSize, int compression) { - table_id = H5PTcreate_fl ( fileID, name, dtypeID, chunkSize); + table_id = H5PTcreate_fl ( fileID, name, dtypeID, chunkSize, compression); } /* "Open" Constructor @@ -220,7 +220,7 @@ * Takes the ID of the file the packet table will be created in, the name of * the packet table, and the size of a memory chunk used in chunking. */ - VL_PacketTable::VL_PacketTable(hid_t fileID, char* name, int chunkSize) + VL_PacketTable::VL_PacketTable(hid_t fileID, char* name, hsize_t chunkSize) { table_id = H5PTcreate_vl ( fileID, name, chunkSize); } diff --git a/hl/c++/src/H5PacketTable.h b/hl/c++/src/H5PacketTable.h index 3ba4e5e..cdfb3ee 100644 --- a/hl/c++/src/H5PacketTable.h +++ b/hl/c++/src/H5PacketTable.h @@ -103,10 +103,11 @@ public: /* Constructor * Creates a packet table in which to store fixed length packets. * Takes the ID of the file the packet table will be created in, the name of - * the packet table, the ID of the datatype of the set, and the size - * of a memory chunk used in chunking. + * the packet table, the ID of the datatype of the set, the size + * of a memory chunk used in chunking, and the desired compression level + * (0-9, or -1 for no compression). */ - FL_PacketTable(hid_t fileID, char* name, hid_t dtypeID, int chunkSize); + FL_PacketTable(hid_t fileID, char* name, hid_t dtypeID, hsize_t chunkSize, int compression = -1); /* "Open" Constructor * Opens an existing fixed-length packet table. @@ -169,7 +170,7 @@ public: * Takes the ID of the file the packet table will be created in, the name of * the packet table, and the size of a memory chunk used in chunking. */ - VL_PacketTable(hid_t fileID, char* name, int chunkSize); + VL_PacketTable(hid_t fileID, char* name, hsize_t chunkSize); /* "Open" Constructor * Opens an existing variable-length packet table. diff --git a/hl/c++/test/Makefile.am b/hl/c++/test/Makefile.am index 95917f0..dc543f6 100644 --- a/hl/c++/test/Makefile.am +++ b/hl/c++/test/Makefile.am @@ -20,7 +20,7 @@ include $(top_srcdir)/config/commence.am # Include directories -INCLUDES=-I$(top_srcdir)/src -I$(top_srcdir)/hl/src -I$(top_srcdir)/hl/c++/src -I$(top_srcdir)/test +INCLUDES=-I$(top_srcdir)/src -I$(top_srcdir)/c++/src -I$(top_srcdir)/hl/src -I$(top_srcdir)/hl/c++/src -I$(top_srcdir)/test -I$(top_builddir)/hl/test -I$(top_srcdir)/hl/test # Shared C++ libraries aren't universally supported. if CXX_SHARED_CONDITIONAL @@ -33,8 +33,8 @@ endif TEST_PROG=ptableTest check_PROGRAMS=$(TEST_PROG) -# The tests depend on the hdf5 library and the hdf5_hl library -LDADD=$(LIBH5CPP_HL) $(LIBH5_HL) $(LIBHDF5) +# The tests depend on the hdf5, hdf5 C++, and hdf5_hl libraries +LDADD=$(LIBH5CPP_HL) $(LIBH5_HL) $(LIBH5CPP) $(LIBHDF5) ptableTest_SOURCES=ptableTest.cpp include $(top_srcdir)/config/conclude.am diff --git a/hl/c++/test/Makefile.in b/hl/c++/test/Makefile.in index d8b2de2..b99ca34 100644 --- a/hl/c++/test/Makefile.in +++ b/hl/c++/test/Makefile.in @@ -71,9 +71,10 @@ ptableTest_OBJECTS = $(am_ptableTest_OBJECTS) ptableTest_LDADD = $(LDADD) am__DEPENDENCIES_1 = $(top_builddir)/hl/c++/src/libhdf5_hl_cpp.la am__DEPENDENCIES_2 = $(top_builddir)/hl/src/libhdf5_hl.la -am__DEPENDENCIES_3 = $(top_builddir)/src/libhdf5.la +am__DEPENDENCIES_3 = $(top_builddir)/c++/src/libhdf5_cpp.la +am__DEPENDENCIES_4 = $(top_builddir)/src/libhdf5.la ptableTest_DEPENDENCIES = $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_2) \ - $(am__DEPENDENCIES_3) + $(am__DEPENDENCIES_3) $(am__DEPENDENCIES_4) DEFAULT_INCLUDES = -I. -I$(srcdir) -I$(top_builddir)/src depcomp = $(SHELL) $(top_srcdir)/bin/depcomp am__depfiles_maybe = depfiles @@ -322,7 +323,7 @@ TRACE = perl $(top_srcdir)/bin/trace CHECK_CLEANFILES = *.chkexe *.chklog *.clog # Include directories -INCLUDES = -I$(top_srcdir)/src -I$(top_srcdir)/hl/src -I$(top_srcdir)/hl/c++/src -I$(top_srcdir)/test +INCLUDES = -I$(top_srcdir)/src -I$(top_srcdir)/c++/src -I$(top_srcdir)/hl/src -I$(top_srcdir)/hl/c++/src -I$(top_srcdir)/test -I$(top_builddir)/hl/test -I$(top_srcdir)/hl/test # Shared C++ libraries aren't universally supported. @CXX_SHARED_CONDITIONAL_FALSE@AM_LDFLAGS = -static @@ -331,8 +332,8 @@ INCLUDES = -I$(top_srcdir)/src -I$(top_srcdir)/hl/src -I$(top_srcdir)/hl/c++/src # executed, generally most specific tests to least specific tests. TEST_PROG = ptableTest -# The tests depend on the hdf5 library and the hdf5_hl library -LDADD = $(LIBH5CPP_HL) $(LIBH5_HL) $(LIBHDF5) +# The tests depend on the hdf5, hdf5 C++, and hdf5_hl libraries +LDADD = $(LIBH5CPP_HL) $(LIBH5_HL) $(LIBH5CPP) $(LIBHDF5) ptableTest_SOURCES = ptableTest.cpp # Automake needs to be taught how to build lib, progs, and tests targets. diff --git a/hl/c++/test/ptableTest.cpp b/hl/c++/test/ptableTest.cpp index 3b97d3e..d25c2ba 100644 --- a/hl/c++/test/ptableTest.cpp +++ b/hl/c++/test/ptableTest.cpp @@ -16,6 +16,8 @@ #include "ptableTest.h" +using namespace H5; + #define TEST_FILE "packettest.h5" /* Main test function */ @@ -41,6 +43,8 @@ int main(void) num_errors += TestGetNext(); + num_errors += TestCompress(); + num_errors += TestErrors(); num_errors += SystemTest(); @@ -146,8 +150,8 @@ int TestCompoundDatatype() H5Tinsert(dtypeID, "charlie", HOFFSET( compoundType, c ), H5T_NATIVE_SHORT); H5Tinsert(dtypeID, "ebert", HOFFSET( compoundType, e ), H5T_NATIVE_INT); - /* Create packet table */ - FL_PacketTable wrapper(fileID, "/compoundTest", dtypeID, 1); + /* Create packet table. Explicitly specify no compression */ + FL_PacketTable wrapper(fileID, "/compoundTest", dtypeID, 1, -1); if(! wrapper.IsValid()) goto out; @@ -193,7 +197,7 @@ int TestGetNext() TESTING("GetNextPacket") /* Create a dataset */ - FL_PacketTable wrapper(fileID, "/TestGetNext", H5T_NATIVE_INT, 1); + FL_PacketTable wrapper(fileID, "/TestGetNext", H5T_NATIVE_INT, 500); if(! wrapper.IsValid()) goto out; @@ -245,6 +249,38 @@ out: return 1; } +int TestCompress() +{ + unsigned int flags = 0; + unsigned int config = 0; + size_t cd_nelemts = 0; + + TESTING("compression") + + try { + /* Create packet table with compression. */ + FL_PacketTable wrapper(fileID, "/compressTest", H5T_NATIVE_CHAR, 100, 8); + + /* Create an HDF5 C++ file object */ + H5File file; + file.setId(fileID); + + /* Make sure that the deflate filter is set by opening the packet table + * as a dataset and getting its creation property list */ + DataSet dsetID = file.openDataSet("/compressTest"); + + DSetCreatPropList dcplID = dsetID.getCreatePlist(); + + dcplID.getFilterById(H5Z_FILTER_DEFLATE, flags, cd_nelemts, NULL, 0, NULL, config); + } catch (Exception e) { + H5_FAILED(); + return 1; + } + + PASSED(); + return 0; +} + int TestGetPacket() { int record; @@ -252,8 +288,8 @@ int TestGetPacket() int i; TESTING("GetPacket") - /* Create a dataset */ - FL_PacketTable wrapper(fileID, "/TestGetPacket", H5T_NATIVE_INT, 1); + /* Create a dataset. Explicitly specify no compression */ + FL_PacketTable wrapper(fileID, "/TestGetPacket", H5T_NATIVE_INT, 1, -1); if(! wrapper.IsValid()) goto out; @@ -302,13 +338,13 @@ int TestErrors() wrapper.AppendPacket(&record); /* Try to confuse functions with bad indexes */ - error = wrapper.GetPacket(-1, &record); + error = wrapper.GetPacket( (unsigned) -1, &record); if(error >= 0) goto out; error = wrapper.GetPacket(4, &record); if(error >= 0) goto out; - error = wrapper.GetPacket(-250, &record); + error = wrapper.GetPacket((unsigned) -250, &record); if(error >= 0) goto out; error = wrapper.GetPacket(3000, &record); @@ -318,13 +354,13 @@ int TestErrors() if(error < 0) goto out; - error = wrapper.GetPackets(-1, 1, records); + error = wrapper.GetPackets((unsigned) -1, 1, records); if(error >= 0) goto out; error = wrapper.GetPackets(2, 4, records); if(error >= 0) goto out; - error = wrapper.GetPackets(-60, -62, records); + error = wrapper.GetPackets((unsigned) -60, (unsigned) -62, records); if(error >= 0) goto out; error = wrapper.GetPackets(10, 12, records); @@ -344,7 +380,7 @@ int TestErrors() goto out; wrapper.ResetIndex(); - error = wrapper.SetIndex(-1); + error = wrapper.SetIndex((unsigned) -1); if(error >= 0) goto out; if(wrapper.GetIndex(error) != 0) goto out; @@ -433,9 +469,9 @@ int SystemTest() ct2[0].g.c = 0; ct2[0].g.e = 3000; - /* Create the packet table datasets */ + /* Create the packet table datasets. Make one of them compressed. */ FL_PacketTable wrapper1(fileID, "/SystemTest1", dtypeID1, 1); - FL_PacketTable wrapper2(fileID, "/SystemTest2", dtypeID2, 1); + FL_PacketTable wrapper2(fileID, "/SystemTest2", dtypeID2, 1, 5); if(! wrapper1.IsValid()) goto out; diff --git a/hl/c++/test/ptableTest.h b/hl/c++/test/ptableTest.h index 119b1e4..d51f39e 100644 --- a/hl/c++/test/ptableTest.h +++ b/hl/c++/test/ptableTest.h @@ -23,7 +23,8 @@ #define PTABLETEST #include "H5PacketTable.h" -#include "h5test.h" +#include "H5Cpp.h" +#include "h5hltest.h" static hid_t fileID; @@ -36,6 +37,9 @@ int TestCompoundDatatype(void); /* Test the GetNext functions and their indexes */ int TestGetNext(void); +/* Make sure that setting compression through the C++ API works. */ +int TestCompress(void); + /* Ensure that the functions return the correct errors in * response to invalid indexes */ int TestErrors(void); diff --git a/hl/examples/ptExampleFL.c b/hl/examples/ptExampleFL.c index 87c0f59..f5c1323 100644 --- a/hl/examples/ptExampleFL.c +++ b/hl/examples/ptExampleFL.c @@ -50,8 +50,9 @@ int main(void) 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, (hsize_t)1); + /* 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); if(ptable == H5I_INVALID_HID) goto out; diff --git a/hl/src/H5PT.c b/hl/src/H5PT.c index da9bde6..ee03a1b 100644 --- a/hl/src/H5PT.c +++ b/hl/src/H5PT.c @@ -57,7 +57,7 @@ herr_t H5PT_get_index(htbl_t *table_id, hsize_t *pt_index); * * Date: March 12, 2004 * - * Comments: This function does not handle compression or fill data + * Comments: This function does not handle fill data * currently. Fill data is not necessary because the * table is initially of size 0. * @@ -69,7 +69,8 @@ herr_t H5PT_get_index(htbl_t *table_id, hsize_t *pt_index); hid_t H5PTcreate_fl ( hid_t loc_id, const char *dset_name, hid_t dtype_id, - hsize_t chunk_size ) + hsize_t chunk_size, + int compression ) { htbl_t * table = NULL; hid_t dset_id = H5I_BADID; @@ -99,6 +100,11 @@ hid_t H5PTcreate_fl ( hid_t loc_id, plist_id = H5Pcreate (H5P_DATASET_CREATE); if ( H5Pset_chunk ( plist_id, 1, dims_chunk ) < 0 ) goto out; + if(compression >= 0 && compression <= 9) + { + if( H5Pset_deflate(plist_id, compression) < 0) + goto out; + } /* Create the dataset. */ if ( (dset_id=H5Dcreate( loc_id, dset_name, dtype_id, space_id, plist_id))<0 ) @@ -175,7 +181,7 @@ hid_t H5PTcreate_vl ( hid_t loc_id, if (vltype < 0) goto out; - if((ret_value=H5PTcreate_fl(loc_id, dset_name, vltype, chunk_size)) <0) + if((ret_value=H5PTcreate_fl(loc_id, dset_name, vltype, chunk_size, 0)) <0) goto out; /* close the vltype */ diff --git a/hl/src/H5PTpublic.h b/hl/src/H5PTpublic.h index 43520d4..b0388e0 100644 --- a/hl/src/H5PTpublic.h +++ b/hl/src/H5PTpublic.h @@ -30,7 +30,8 @@ extern "C" { H5_HLDLL hid_t H5PTcreate_fl ( hid_t loc_id, const char *dset_name, hid_t dtype_id, - hsize_t chunk_size ); + hsize_t chunk_size, + int compression ); H5_HLDLL hid_t H5PTcreate_vl ( hid_t loc_id, const char *dset_name, diff --git a/hl/test/Makefile.am b/hl/test/Makefile.am index 43ee1ac..97dd398 100644 --- a/hl/test/Makefile.am +++ b/hl/test/Makefile.am @@ -21,10 +21,10 @@ include $(top_srcdir)/config/commence.am # Add include directories to C preprocessor flags -AM_CPPFLAGS=-I. -I$(srcdir) -I$(top_builddir)/src -I$(top_srcdir)/src -I$(top_srcdir)/hl/src +AM_CPPFLAGS=-I. -I$(srcdir) -I$(top_builddir)/src -I$(top_srcdir)/src -I$(top_builddir)/test -I$(top_srcdir)/test -I$(top_srcdir)/hl/src -# The tests depend on the hdf5 and hdf5_hl libraries -LDADD=$(LIBH5_HL) $(LIBHDF5) +# The tests depend on the hdf5, hdf5 test, and hdf5_hl libraries +LDADD=$(LIBH5_HL) $(LIBH5TEST) $(LIBHDF5) # Test programs. These are our main targets. They should be listed in the # order to be executed, generally most specific tests to least specific tests. diff --git a/hl/test/Makefile.in b/hl/test/Makefile.in index 33219d8..7db3176 100644 --- a/hl/test/Makefile.in +++ b/hl/test/Makefile.in @@ -73,24 +73,30 @@ test_ds_SOURCES = test_ds.c test_ds_OBJECTS = test_ds.$(OBJEXT) test_ds_LDADD = $(LDADD) am__DEPENDENCIES_1 = $(top_builddir)/hl/src/libhdf5_hl.la -am__DEPENDENCIES_2 = $(top_builddir)/src/libhdf5.la -test_ds_DEPENDENCIES = $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_2) +am__DEPENDENCIES_2 = $(top_builddir)/test/libh5test.la +am__DEPENDENCIES_3 = $(top_builddir)/src/libhdf5.la +test_ds_DEPENDENCIES = $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_2) \ + $(am__DEPENDENCIES_3) test_image_SOURCES = test_image.c test_image_OBJECTS = test_image.$(OBJEXT) test_image_LDADD = $(LDADD) -test_image_DEPENDENCIES = $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_2) +test_image_DEPENDENCIES = $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_2) \ + $(am__DEPENDENCIES_3) test_lite_SOURCES = test_lite.c test_lite_OBJECTS = test_lite.$(OBJEXT) test_lite_LDADD = $(LDADD) -test_lite_DEPENDENCIES = $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_2) +test_lite_DEPENDENCIES = $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_2) \ + $(am__DEPENDENCIES_3) test_packet_SOURCES = test_packet.c test_packet_OBJECTS = test_packet.$(OBJEXT) test_packet_LDADD = $(LDADD) -test_packet_DEPENDENCIES = $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_2) +test_packet_DEPENDENCIES = $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_2) \ + $(am__DEPENDENCIES_3) test_table_SOURCES = test_table.c test_table_OBJECTS = test_table.$(OBJEXT) test_table_LDADD = $(LDADD) -test_table_DEPENDENCIES = $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_2) +test_table_DEPENDENCIES = $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_2) \ + $(am__DEPENDENCIES_3) DEFAULT_INCLUDES = -I. -I$(srcdir) -I$(top_builddir)/src depcomp = $(SHELL) $(top_srcdir)/bin/depcomp am__depfiles_maybe = depfiles @@ -345,10 +351,10 @@ CHECK_CLEANFILES = *.chkexe *.chklog *.clog combine_tables[1-2].h5 \ test_table.h5 test_packet_table.h5 # Add include directories to C preprocessor flags -AM_CPPFLAGS = -I. -I$(srcdir) -I$(top_builddir)/src -I$(top_srcdir)/src -I$(top_srcdir)/hl/src +AM_CPPFLAGS = -I. -I$(srcdir) -I$(top_builddir)/src -I$(top_srcdir)/src -I$(top_builddir)/test -I$(top_srcdir)/test -I$(top_srcdir)/hl/src -# The tests depend on the hdf5 and hdf5_hl libraries -LDADD = $(LIBH5_HL) $(LIBHDF5) +# The tests depend on the hdf5, hdf5 test, and hdf5_hl libraries +LDADD = $(LIBH5_HL) $(LIBH5TEST) $(LIBHDF5) # Test programs. These are our main targets. They should be listed in the # order to be executed, generally most specific tests to least specific tests. diff --git a/hl/test/h5hltest.h b/hl/test/h5hltest.h index 2776204..e6c2614 100644 --- a/hl/test/h5hltest.h +++ b/hl/test/h5hltest.h @@ -25,17 +25,15 @@ /* Get the HDF5 public header */ #include "hdf5.h" +/* Get the HDF5 test header */ +#include "h5test.h" + /* Include the High-Level private header */ #include "H5HLprivate2.h" -/* These are copied from the test/h5test.h header */ -#define TESTING(WHAT) {printf("%-70s", "Testing " WHAT); fflush(stdout);} +/* Macros used in HL tests */ #define TESTING2(WHAT) {printf("%-70s", "Testing " WHAT); fflush(stdout);} #define TESTING3(WHAT) {printf("%-70s", "" WHAT); fflush(stdout);} -#define PASSED() {puts(" PASSED");fflush(stdout);} -#define H5_FAILED() {puts("*FAILED*");fflush(stdout);} -#define SKIPPED() {puts(" -SKIP-");fflush(stdout);} -#define EXAMPLE(WHAT) {printf("%-70s", "Example " WHAT); fflush(stdout);} #endif /* _H5HLTEST_H */ diff --git a/hl/test/test_packet.c b/hl/test/test_packet.c index 375763b..fe72040 100644 --- a/hl/test/test_packet.c +++ b/hl/test/test_packet.c @@ -29,12 +29,11 @@ #define BIG_TABLE_SIZE 8000 #define NFIELDS 5 #define TEST_FILE_NAME "test_packet_table.h5" +#define TEST_COMPRESS_FILE1 "test_packet_compress1.h5" +#define TEST_COMPRESS_FILE2 "test_packet_compress2.h5" #define PT_NAME "Test Packet Table" #define VL_TABLE_NAME "Varlen Test Table" #define H5TB_TABLE_NAME "Table1" -#define TESTING(WHAT) {printf("%-70s", "Testing " WHAT); fflush(stdout);} -#define PASSED() {puts(" PASSED");fflush(stdout);} -#define H5_FAILED() {puts("*FAILED*");fflush(stdout);} /*------------------------------------------------------------------------- * structure used for some tests, a particle @@ -183,7 +182,7 @@ static int test_create_close(hid_t fid) assert(part_t != -1); /* Create the table */ - table = H5PTcreate_fl(fid, PT_NAME, part_t, (hsize_t)100); + table = H5PTcreate_fl(fid, PT_NAME, part_t, 100, -1); H5Tclose(part_t); if( H5PTis_valid(table) < 0) goto out; @@ -266,17 +265,17 @@ static int test_append(hid_t fid) goto out; /* Append one particle */ - err = H5PTappend(table, (hsize_t)1, &(testPart[0])); + err = H5PTappend(table, 1, &(testPart[0])); if( err < 0) goto out; /* Append several particles */ - err = H5PTappend(table, (hsize_t)6, &(testPart[1])); + err = H5PTappend(table, 6, &(testPart[1])); if( err < 0) goto out; /* Append one more particle */ - err = H5PTappend(table, (hsize_t)1, &(testPart[7])); + err = H5PTappend(table, 1, &(testPart[7])); if( err < 0) goto out; @@ -325,17 +324,17 @@ static int test_read(hid_t fid) goto out; /* Read several particles */ - err = H5PTread_packets(table, (hsize_t)0, (hsize_t)3, &(readBuf[0])); + err = H5PTread_packets(table, 0, 3, &(readBuf[0])); if( err < 0) goto out; /* Read one particle */ - err = H5PTread_packets(table, (hsize_t)3, (hsize_t)1, &(readBuf[3])); + err = H5PTread_packets(table, 3, 1, &(readBuf[3])); if( err < 0) goto out; /* Read several particles */ - err = H5PTread_packets(table, (hsize_t)4, (hsize_t)(NRECORDS - 4 ), &(readBuf[4])); + err = H5PTread_packets(table, 4, (NRECORDS - 4 ), &(readBuf[4])); if( err < 0) goto out; @@ -388,7 +387,7 @@ static int test_get_next(hid_t fid) /* Read several particles consecutively */ for(c=0; c < NRECORDS; c++) { - err = H5PTget_next(table, (hsize_t)1, &readBuf[c]); + err = H5PTget_next(table, 1, &readBuf[c]); if(err < 0) goto out; } @@ -405,7 +404,7 @@ static int test_get_next(hid_t fid) /* Read particles two by two */ for(c=0; c < NRECORDS / 2; c++) { - err = H5PTget_next(table, (hsize_t)2, &readBuf2[c * 2]); + err = H5PTget_next(table, 2, &readBuf2[c * 2]); if(err < 0) goto out; } @@ -457,7 +456,7 @@ static int test_big_table(hid_t fid) assert(part_t != -1); /* Create a new table */ - table = H5PTcreate_fl(fid, "Packet Test Dataset2", part_t, (hsize_t)33); + table = H5PTcreate_fl(fid, "Packet Test Dataset2", part_t, 33, -1); H5Tclose(part_t); if( H5PTis_valid(table) < 0) goto out; @@ -466,7 +465,7 @@ static int test_big_table(hid_t fid) for(c = 0; c < BIG_TABLE_SIZE ; c+=8) { /* Append eight particles at once*/ - err = H5PTappend(table, (hsize_t)8, &(testPart[0])); + err = H5PTappend(table, 8, &(testPart[0])); if( err < 0) goto out; } @@ -483,12 +482,12 @@ static int test_big_table(hid_t fid) /* the first packet in the table */ for(c = 0; c < BIG_TABLE_SIZE; c++) { - err = H5PTget_next(table, (hsize_t)1, &readPart); + err = H5PTget_next(table, 1, &readPart); if(err < 0) goto out; /* Ensure that particles were read correctly */ - if( cmp_par(c % 8, (hsize_t)0, testPart, &readPart) != 0) + if( cmp_par(c % 8, 0, testPart, &readPart) != 0) goto out; } @@ -553,7 +552,7 @@ static int test_varlen(hid_t fid) } /* Create the table */ - table = H5PTcreate_vl(fid, VL_TABLE_NAME, (hsize_t)1001); + table = H5PTcreate_vl(fid, VL_TABLE_NAME, 1001); if( H5PTis_valid(table) < 0) goto out; if( H5PTis_varlen(table) != 1) @@ -586,18 +585,18 @@ static int test_varlen(hid_t fid) goto out; /* Add several variable-length packets */ - err = H5PTappend(table, (hsize_t)8, writeBuffer ); + err = H5PTappend(table, 8, writeBuffer ); if(err < 0) goto out; /* Read them back */ - err = H5PTread_packets(table, (hsize_t)0, (hsize_t)4, &(readBuffer[0])); + err = H5PTread_packets(table, 0, 4, &(readBuffer[0])); if( err < 0) goto out; - err = H5PTread_packets(table, (hsize_t)4, (hsize_t)1, &(readBuffer[4])); + err = H5PTread_packets(table, 4, 1, &(readBuffer[4])); if( err < 0) goto out; - err = H5PTread_packets(table, (hsize_t)5, (hsize_t)(NRECORDS - 5 ), &(readBuffer[5])); + err = H5PTread_packets(table, 5, (NRECORDS - 5 ), &(readBuffer[5])); if( err < 0) goto out; @@ -618,7 +617,7 @@ static int test_varlen(hid_t fid) goto out; break; case 3: - if( cmp_par((hsize_t)0, (hsize_t)0, readBuffer[x].p, writeBuffer[x].p) < 0) + if( cmp_par(0, 0, readBuffer[x].p, writeBuffer[x].p) < 0) goto out; break; default: @@ -627,13 +626,13 @@ static int test_varlen(hid_t fid) } /* Free memory used by read buffer */ - if(H5PTfree_vlen_readbuff(table, (hsize_t)NRECORDS, readBuffer) <0) + if(H5PTfree_vlen_readbuff(table, NRECORDS, readBuffer) <0) goto out; /* Read packets back using get_next */ for(x=0; x < NRECORDS; x++) { - err = H5PTget_next(table, (hsize_t)1, &readBuffer[x]); + err = H5PTget_next(table, 1, &readBuffer[x]); if(err < 0) goto out; } @@ -655,7 +654,7 @@ static int test_varlen(hid_t fid) goto out; break; case 3: - if( cmp_par((hsize_t)0, (hsize_t)0, readBuffer[x].p, writeBuffer[x].p) < 0) + if( cmp_par(0, 0, readBuffer[x].p, writeBuffer[x].p) < 0) goto out; break; default: @@ -664,7 +663,7 @@ static int test_varlen(hid_t fid) } /* Free memory used by read buffer */ - if(H5PTfree_vlen_readbuff(table, (hsize_t)NRECORDS, readBuffer) <0) + if(H5PTfree_vlen_readbuff(table, NRECORDS, readBuffer) <0) goto out; /* Close the table */ @@ -710,18 +709,18 @@ static int test_opaque(hid_t fid) return -1; /* Create a new table */ - table = H5PTcreate_fl(fid, "Packet Test Dataset3", part_t, (hsize_t)1); + table = H5PTcreate_fl(fid, "Packet Test Dataset3", part_t, 100, -1); H5Tclose(part_t); if( H5PTis_valid(table) < 0) goto out; /* Append several particles, starting at particle 1 */ - err = H5PTappend(table, (hsize_t)(NRECORDS - 1), &(testPart[1])); + err = H5PTappend(table, (NRECORDS - 1), &(testPart[1])); if( err < 0) goto out; /* Read the particles back */ - err = H5PTread_packets(table, (hsize_t)0, (hsize_t)7, &(readBuf[0])); + err = H5PTread_packets(table, 0, 7, &(readBuf[0])); if( err < 0) goto out; @@ -748,6 +747,135 @@ static int test_opaque(hid_t fid) } /*------------------------------------------------------------------------- + * test_compress + * + * Ensures that a FL packet table can be compressed. + * This test creates two new files, TEST_COMPRESS_FILE1 and TEST_COMPRESS_FILE2 + * + *------------------------------------------------------------------------- + */ +static int test_compress() +{ + hid_t fid1 = -1; + hid_t fid2 = -1; + h5_stat_size_t size1, size2; + herr_t err; + hid_t table = -1; + hid_t part_t = -1; + hsize_t c; + particle_t readPart; + hsize_t count; + hid_t plist_id = -1; + + TESTING("packet table compression"); + + /* Create two empty files. */ + if((fid1 = H5Fcreate(TEST_COMPRESS_FILE1, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR; + if((fid2 = H5Fcreate(TEST_COMPRESS_FILE2, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR; + + /* Make sure that the two files are the same size (both should be empty) */ + err = H5Fclose(fid1); + if(err < 0) TEST_ERROR; + err = H5Fclose(fid2); + if(err < 0) TEST_ERROR; + size1 = h5_get_file_size(TEST_COMPRESS_FILE1); + size2 = h5_get_file_size(TEST_COMPRESS_FILE2); + if(size1 != size2) TEST_ERROR; + + /* Re-open file1 and create a compressed packet table in it */ + if((fid1 = H5Fopen(TEST_COMPRESS_FILE1, H5F_ACC_RDWR, H5P_DEFAULT)) < 0) TEST_ERROR; + + /* Create a datatype for the particle struct */ + part_t = make_particle_type(); + + assert(part_t != -1); + + /* Create a new table with compression level 1 */ + table = H5PTcreate_fl(fid1, "Packet Compress Test Dataset", part_t, 80, 1); + if( H5PTis_valid(table) < 0) TEST_ERROR; + + /* We can now use this table exactly the same way we use a normal uncompressed + * packet table, and it should pass the same tests. */ + /* Add many particles */ + for(c = 0; c < BIG_TABLE_SIZE ; c+=8) + { + /* Append eight particles at once*/ + err = H5PTappend(table, 8, &(testPart[0])); + if( err < 0) TEST_ERROR; + } + + /* Count the number of packets in the table */ + err = H5PTget_num_packets(table, &count); + if( err < 0) TEST_ERROR; + if( count != BIG_TABLE_SIZE ) TEST_ERROR; + + /* Read particles to ensure that all of them were written correctly */ + for(c = 0; c < BIG_TABLE_SIZE; c++) + { + err = H5PTget_next(table, 1, &readPart); + if(err < 0) TEST_ERROR; + + /* Ensure that particles were read correctly */ + if( cmp_par(c % 8, 0, testPart, &readPart) != 0) TEST_ERROR; + } + + /* Close the table and the file */ + err = H5PTclose(table); + if( err < 0) TEST_ERROR; + err = H5Fclose(fid1); + if( err < 0) TEST_ERROR; + + /* Open the second file and create a new table with compression level 9. */ + if((fid2 = H5Fopen(TEST_COMPRESS_FILE2, H5F_ACC_RDWR, H5P_DEFAULT)) < 0) TEST_ERROR; + table = H5PTcreate_fl(fid2, "Packet Compress Test Dataset", part_t, 80, 9); + if(table < 0) TEST_ERROR; + + for(c = 0; c < BIG_TABLE_SIZE ; c+=8) + { + /* Append eight particles at once*/ + err = H5PTappend(table, 8, &(testPart[0])); + if( err < 0) TEST_ERROR; + } + /* Read particles to ensure that all of them were written correctly */ + for(c = 0; c < BIG_TABLE_SIZE; c++) + { + err = H5PTget_next(table, 1, &readPart); + if(err < 0) TEST_ERROR; + + /* Ensure that particles were read correctly */ + if( cmp_par(c % 8, 0, testPart, &readPart) != 0) TEST_ERROR; + } + + /* Close the datatype, the table, and the file */ + err = H5Tclose(part_t); + if( err < 0) TEST_ERROR; + err = H5PTclose(table); + if( err < 0) TEST_ERROR; + err = H5Fclose(fid2); + if( err < 0) TEST_ERROR; + + /* Since the table in file2 used a higher compression level than the one in + * file1, file2 should be smaller. */ + size1 = h5_get_file_size(TEST_COMPRESS_FILE1); + size2 = h5_get_file_size(TEST_COMPRESS_FILE2); + if(size1 <= size2) TEST_ERROR; + + PASSED(); + return 0; + +error: + H5E_BEGIN_TRY { + H5Tclose(part_t); + H5PTclose(table); + H5Fclose(fid1); + H5Fclose(fid2); + } H5E_END_TRY + H5_FAILED(); + return -1; +} + + +/*------------------------------------------------------------------------- * test_error * * ensures that the packet table API throws the correct errors used on @@ -783,9 +911,9 @@ static int test_error(hid_t fid) goto out; if(H5PTclose(id) >= 0) goto out; - if(H5PTappend(id, (hsize_t)1, testPart) >= 0) + if(H5PTappend(id, 1, testPart) >= 0) goto out; - if(H5PTread_packets(id, (hsize_t)0, (hsize_t)1, readBuf) >= 0) + if(H5PTread_packets(id, 0, 1, readBuf) >= 0) goto out; if(H5PTcreate_index(id) >= 0) goto out; @@ -808,9 +936,9 @@ static int test_error(hid_t fid) goto out; if(H5PTclose(id) >= 0) goto out; - if(H5PTappend(id, (hsize_t)1, testPart) >= 0) + if(H5PTappend(id, 1, testPart) >= 0) goto out; - if(H5PTread_packets(id, (hsize_t)0, (hsize_t)1, readBuf) >= 0) + if(H5PTread_packets(id, 0, 1, readBuf) >= 0) goto out; if(H5PTcreate_index(id) >= 0) goto out; @@ -838,9 +966,9 @@ static int test_error(hid_t fid) goto out; if(H5PTclose(id) >= 0) goto out; - if(H5PTappend(id, (hsize_t)1, testPart) >= 0) + if(H5PTappend(id, 1, testPart) >= 0) goto out; - if(H5PTread_packets(id, (hsize_t)0, (hsize_t)1, readBuf) >= 0) + if(H5PTread_packets(id, 0, 1, readBuf) >= 0) goto out; if(H5PTcreate_index(id) >= 0) goto out; @@ -882,6 +1010,7 @@ static int test_packet_table(hid_t fid) test_big_table(fid); test_varlen(fid); test_opaque(fid); + test_compress(); test_error(fid); return 0; @@ -498,6 +498,7 @@ H5Odecr_refcount(hid_t object_id) int ret_value; FUNC_ENTER_API(H5Odecr_refcount, FAIL) + H5TRACE1("Is","i",object_id); /* Get the object's oloc so we can adjust its link count */ if((oloc = H5O_get_oloc(object_id)) == NULL) |