From 36555723f57064fb8be79aefe43e8de024d6b58f Mon Sep 17 00:00:00 2001 From: Tony Theodore Date: Sat, 9 Feb 2013 15:20:20 +1100 Subject: package hdf5: rename test program and re-style test invocation --- src/hdf5-test.c | 96 ------------------------------------------------------- src/hdf5-test.cpp | 96 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/hdf5.mk | 6 ++-- 3 files changed, 100 insertions(+), 98 deletions(-) delete mode 100644 src/hdf5-test.c create mode 100644 src/hdf5-test.cpp diff --git a/src/hdf5-test.c b/src/hdf5-test.c deleted file mode 100644 index b412c9e..0000000 --- a/src/hdf5-test.c +++ /dev/null @@ -1,96 +0,0 @@ -/* - * This file is part of MXE. - * See index.html for further information. - */ - -#include -#include -#include -#if H5_VERS_MINOR > 6 - #include -#else - #include -#endif - -/* -#include -*/ -#include -/* -#include -*/ - -const static unsigned int DATELEN = 128; -const static unsigned int TIMELEN = 128; -const static unsigned int UNITLEN = 16; - - -int main(int argc, char *argv[]) -{ - (void)argc; - (void)argv; - -typedef struct rt { - int channels; - char date[DATELEN]; - char time[TIMELEN]; -} rt; - -// H5Fis_hdf5("/dev/null"); - -/* -* Create a new file using H5ACC_TRUNC access, -* default file creation properties, and default file -* access properties. -* Then close the file. -*/ - - const int NRECORDS = 1; - const int NFIELDS = 3; - char fName[] = "tmp.h5"; - - /* Calculate the size and the offsets of our struct members in memory */ - size_t rt_offset[NFIELDS] = { HOFFSET( rt, channels ), - HOFFSET( rt, date ), - HOFFSET( rt, time )}; - - rt p_data; - p_data.channels = 1; - strcpy( p_data.date, "1234-Dec-31"); - strcpy( p_data.time, "12:34:56"); - - - hid_t file_id = H5Fcreate(fName, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); - - - /* Define field information */ - const char *field_names[NFIELDS] = { "channels", "date", "time" }; - hid_t field_type[NFIELDS]; - - /* Initialize the field field_type */ - hid_t string_type1 = H5Tcopy( H5T_C_S1 ); - hid_t string_type2 = H5Tcopy( H5T_C_S1 ); - H5Tset_size( string_type1, strlen(p_data.date)); - H5Tset_size( string_type2, strlen(p_data.time)); - field_type[0] = H5T_NATIVE_INT; - field_type[1] = string_type1; - field_type[2] = string_type2; - - std::ostringstream desc; - desc << "Description of " << fName; - - herr_t status = H5TBmake_table( desc.str().c_str(), file_id, "description", (hsize_t)NFIELDS, (hsize_t)NRECORDS, sizeof(rt), - field_names, rt_offset, field_type, 10, NULL, 0, &p_data ); - - if (status < 0) { - perror("Exception while writing description in stfio::exportHDF5File"); - H5Fclose(file_id); - H5close(); - exit(-1); - } - - H5Fclose(file_id); - - return(0); -} - diff --git a/src/hdf5-test.cpp b/src/hdf5-test.cpp new file mode 100644 index 0000000..b412c9e --- /dev/null +++ b/src/hdf5-test.cpp @@ -0,0 +1,96 @@ +/* + * This file is part of MXE. + * See index.html for further information. + */ + +#include +#include +#include +#if H5_VERS_MINOR > 6 + #include +#else + #include +#endif + +/* +#include +*/ +#include +/* +#include +*/ + +const static unsigned int DATELEN = 128; +const static unsigned int TIMELEN = 128; +const static unsigned int UNITLEN = 16; + + +int main(int argc, char *argv[]) +{ + (void)argc; + (void)argv; + +typedef struct rt { + int channels; + char date[DATELEN]; + char time[TIMELEN]; +} rt; + +// H5Fis_hdf5("/dev/null"); + +/* +* Create a new file using H5ACC_TRUNC access, +* default file creation properties, and default file +* access properties. +* Then close the file. +*/ + + const int NRECORDS = 1; + const int NFIELDS = 3; + char fName[] = "tmp.h5"; + + /* Calculate the size and the offsets of our struct members in memory */ + size_t rt_offset[NFIELDS] = { HOFFSET( rt, channels ), + HOFFSET( rt, date ), + HOFFSET( rt, time )}; + + rt p_data; + p_data.channels = 1; + strcpy( p_data.date, "1234-Dec-31"); + strcpy( p_data.time, "12:34:56"); + + + hid_t file_id = H5Fcreate(fName, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); + + + /* Define field information */ + const char *field_names[NFIELDS] = { "channels", "date", "time" }; + hid_t field_type[NFIELDS]; + + /* Initialize the field field_type */ + hid_t string_type1 = H5Tcopy( H5T_C_S1 ); + hid_t string_type2 = H5Tcopy( H5T_C_S1 ); + H5Tset_size( string_type1, strlen(p_data.date)); + H5Tset_size( string_type2, strlen(p_data.time)); + field_type[0] = H5T_NATIVE_INT; + field_type[1] = string_type1; + field_type[2] = string_type2; + + std::ostringstream desc; + desc << "Description of " << fName; + + herr_t status = H5TBmake_table( desc.str().c_str(), file_id, "description", (hsize_t)NFIELDS, (hsize_t)NRECORDS, sizeof(rt), + field_names, rt_offset, field_type, 10, NULL, 0, &p_data ); + + if (status < 0) { + perror("Exception while writing description in stfio::exportHDF5File"); + H5Fclose(file_id); + H5close(); + exit(-1); + } + + H5Fclose(file_id); + + return(0); +} + diff --git a/src/hdf5.mk b/src/hdf5.mk index 00c5545..8deab17 100644 --- a/src/hdf5.mk +++ b/src/hdf5.mk @@ -36,6 +36,8 @@ define $(PKG)_BUILD $(MAKE) -C '$(1)'/hl/c++/src -j 1 install ## test hdf5 - '$(TARGET)-g++' -W -Wall -ansi '$(2).c' -o '$(PREFIX)/$(TARGET)/bin/test-hdf5.exe' -lhdf5_hl -lhdf5 -lz - + '$(TARGET)-g++' \ + -W -Wall -Werror -ansi -pedantic \ + '$(2).cpp' -o '$(PREFIX)/$(TARGET)/bin/test-hdf5.exe' \ + -lhdf5_hl -lhdf5 -lz endef -- cgit v0.12