We have been using HDF5 packet tables (and the C++ API) for data logging purposes. I have attached a standalone program to illustrate what looks like a bug in versions of HDF5 that have come after version 1.8.14. This standalone program wrtites 5 records consisting of an int, a double and a float to a packet table, and then reads them back and prints out the values. The correct output should be
Packet 0: a=0, b=0, c=1 Packet 1: a=1, b=1, c=0.5 Packet 2: a=2, b=4, c=0.333333 Packet 3: a=3, b=9, c=0.25 Packet 4: a=4, b=16, c=0.2 Versions beyond 1.8.14 (including 1.10.0-alpha0) generate the following incorrect output Packet 0: a=0, b=0, c=1 Packet 1: a=2, b=1, c=0.5 ---> the 'a' value is incorrect Packet 2: a=2, b=4, c=0.333333 Packet 3: a=3, b=9, c=0.25 Packet 4: a=4, b=16, c=0.2 Thanks for any help with this issue. Best regards Abhi
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 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 [email protected]. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ #include <H5Cpp.h> #include <H5PacketTable.h> #include <iostream> int main() { struct s1_t { int a; float b; double c; }; const size_t length = 5; s1_t s1[length]; for (size_t i = 0; i < length; i++) { s1[i].a = i; s1[i].b = i * i; s1[i].c = 1. / (i + 1); } const hsize_t dim[] = {length}; const size_t rank = 1; H5::DataSpace space(rank, dim); const hid_t compound_type = H5Tcreate(H5T_COMPOUND, sizeof(s1_t)); H5Tinsert(compound_type, "a_name", HOFFSET(s1_t, a), H5T_NATIVE_INT); H5Tinsert(compound_type, "b_name", HOFFSET(s1_t, c), H5T_NATIVE_DOUBLE); H5Tinsert(compound_type, "c_name", HOFFSET(s1_t, b), H5T_NATIVE_FLOAT); std::cerr << "sizeof(s1_t): " << sizeof(s1_t) << "\n"; std::cerr << "sizeof(s1): " << sizeof(s1) << "\n"; std::cerr << "sizeof(s1[0]): " << sizeof(s1[0]) << "\n"; std::cerr << "sizeof(s1[0].a): " << sizeof(s1[0].a) << "\n"; std::cerr << "sizeof(s1[0].b): " << sizeof(s1[0].b) << "\n"; std::cerr << "sizeof(s1[0].c): " << sizeof(s1[0].c) << "\n"; herr_t err; const hid_t file_id = H5Fcreate("example.h5", H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); if (file_id < 0) { fprintf(stderr, "Couldn't create file.\n"); } FL_PacketTable ptable(file_id, "/examplePacketTable", compound_type, 1); if (not ptable.IsValid()) { fprintf(stderr, "Unable to create packet table."); } for (size_t i = 0; i < 5; i++) { err = ptable.AppendPacket(s1 + i); if (err < 0) { fprintf(stderr, "Error adding record."); } } const hsize_t count = ptable.GetPacketCount(err); if (err < 0) { fprintf(stderr, "Error getting packet count."); } std::cerr << "Number of packets in packet table after five appends: " << count << "\n"; ptable.ResetIndex(); for (size_t i = 0; i < 5; i++) { err = ptable.GetNextPacket(s1); if (err < 0) { fprintf(stderr, "Error reading record."); } std::cerr << "Packet " << i << ": " << "a=" << s1[i].a << ", " << "b=" << s1[i].b << ", " << "c=" << s1[i].c << "\n"; } err = H5Fclose(file_id); if (err < 0) { fprintf(stderr, "Failed to close file.\n"); } return 0; }
_______________________________________________ Hdf-forum is for HDF software users discussion. [email protected] http://lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org Twitter: https://twitter.com/hdf5
