From 162ff16eb12827a901d8cec6fa54c29d6d149b60 Mon Sep 17 00:00:00 2001 From: Elisabeth Hoppe Date: Tue, 26 Apr 2016 12:00:53 +0200 Subject: [PATCH 1/2] Added first example for reading the contents of HDF5 files --- messaging/hdf_reader/.gitignore | 1 + messaging/hdf_reader/Readme.md | 12 + messaging/hdf_reader/src/CMakeLists.txt | 14 ++ .../hdf_reader/src/HDFFileReaderExample.cpp | 211 ++++++++++++++++++ 4 files changed, 238 insertions(+) create mode 100644 messaging/hdf_reader/.gitignore create mode 100644 messaging/hdf_reader/Readme.md create mode 100644 messaging/hdf_reader/src/CMakeLists.txt create mode 100644 messaging/hdf_reader/src/HDFFileReaderExample.cpp diff --git a/messaging/hdf_reader/.gitignore b/messaging/hdf_reader/.gitignore new file mode 100644 index 0000000..f36ca87 --- /dev/null +++ b/messaging/hdf_reader/.gitignore @@ -0,0 +1 @@ +.cproject diff --git a/messaging/hdf_reader/Readme.md b/messaging/hdf_reader/Readme.md new file mode 100644 index 0000000..ac9ca13 --- /dev/null +++ b/messaging/hdf_reader/Readme.md @@ -0,0 +1,12 @@ +1. Download and install CMake: + ▪ https://cmake.org/download/ + ▪ https://cmake.org/install
 +2. Build HDF5 library with CMake: + ▪ https://www.hdfgroup.org/HDF5/release/cmakebuild.html#build + +3. Build and run example: + + $ cd src + $ cmake CMakeLists.txt + $ make + $ ./HDFFileReaderExample \ No newline at end of file diff --git a/messaging/hdf_reader/src/CMakeLists.txt b/messaging/hdf_reader/src/CMakeLists.txt new file mode 100644 index 0000000..940c8e9 --- /dev/null +++ b/messaging/hdf_reader/src/CMakeLists.txt @@ -0,0 +1,14 @@ +cmake_minimum_required (VERSION 3.1.0) +project (HDF5FileReaderExample) + +find_package (HDF5 NAMES hdf5 COMPONENTS CXX static) +#find_package (HDF5) +#include_directories(${HDF5_INCLUDE_DIR}) + +set (LINK_LIBS ${LINK_LIBS} ${HDF5_C_STATIC_LIBRARY}) + +set (example HDFFileReaderExample) + +add_executable (${example} ${PROJECT_SOURCE_DIR}/${example}.cpp) + +target_link_libraries (${example} ${LINK_LIBS}) diff --git a/messaging/hdf_reader/src/HDFFileReaderExample.cpp b/messaging/hdf_reader/src/HDFFileReaderExample.cpp new file mode 100644 index 0000000..a1c3072 --- /dev/null +++ b/messaging/hdf_reader/src/HDFFileReaderExample.cpp @@ -0,0 +1,211 @@ +// +// HDFFileReaderExample.cpp +// Projectname: amos-ss16-proj5 +// +// Created by Elisabeth Hoppe on 24.04.16. +// Copyright (c) 2016 de.fau.cs.osr.amos2016.gruppe5 +// +// This file is part of the AMOS Project 2016 @ FAU +// (Friedrich-Alexander University Erlangen-Nürnberg) +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public +// License along with this program. If not, see +// . +// + +#ifdef OLD_HEADER_FILENAME +#include +#else +#include +#endif +#include +#include + +#ifndef H5_NO_NAMESPACE +#ifndef H5_NO_STD + using std::cout; + using std::endl; +#endif // H5_NO_STD +#endif + +#include "H5Cpp.h" + +#ifndef H5_NO_NAMESPACE + using namespace H5; +#endif + +const H5std_string FILE_NAME( "measurement_2016-04-08-13-27-15-507.hdf5" ); +const H5std_string DATASET_NAME( "MFCImageRight" ); + + +int main(void) +{ + + // Try block to detect exceptions raised by any of the calls inside it + try + { + + // Turn off the auto-printing when failure occurs so that we can + // handle the errors appropriately + Exception::dontPrint(); + + // create the file and open it with read-only access. + H5File * file = new H5File( FILE_NAME, H5F_ACC_RDONLY ); + DataSet dataSet = file->openDataSet(DATASET_NAME); + + // get the class of the datatype that is used by the dataset. + H5T_class_t typeClass = dataSet.getTypeClass(); + + + // get the data space of the dataset for obtaining information about dimension, sizes, etc. + DataSpace dataSpace = dataSet.getSpace(); + + // get info about dataspace + int dimNumber = dataSpace.getSimpleExtentNdims(); + hssize_t elemsNumber = dataSpace.getSimpleExtentNpoints(); + bool isSimple = dataSpace.isSimple(); + + // get dimension size of each dimension + hsize_t dimsOut[2]; + int nDims = dataSpace.getSimpleExtentDims(dimsOut, NULL); + + if(dimsOut[1] != 2) + { + //TODO exception handling + } + + if(typeClass == H5T_INTEGER) + { + IntType intType = dataSet.getIntType(); + + // get order of the int type + H5std_string order_string; + H5T_order_t order = intType.getOrder(order_string); + + // get size of int type + size_t size = intType.getSize(); + + } + + // read raw data (timestamp + imageid) + // go to dataset with the imageid + // read the dataset behind image id + // = protobuf file + + // create buffer for reading the data + int64_t buffer[dimsOut[0]][dimsOut[1]]; + + // initialize + for(int i = 0; i without input for memory data space the whole data space will be read + + dataSet.read(buffer, PredType::NATIVE_INT64); + + // read the image ids from the buffer + + // vector which holds all the image ids + std::vector vecImages; + for(int i = 0; iopenDataSet(sId); + + // get the class of the datatype that is used by the dataset. + H5T_class_t typeClass = dataSet.getTypeClass(); + + // get the data space of the dataset for obtaining information about dimension, sizes, etc. + DataSpace dataSpace = dataSet.getSpace(); + + // get info about dataspace + int dimNumber = dataSpace.getSimpleExtentNdims(); + hssize_t elemsNumber = dataSpace.getSimpleExtentNpoints(); + bool isSimple = dataSpace.isSimple(); + + // get dimension size of each dimension + hsize_t dimsOut[1]; + int nDims = dataSpace.getSimpleExtentDims(dimsOut, NULL); + + if(typeClass != H5T_INTEGER) + { + // TODO exception handling + } + + + // create buffer for reading the image data + int64_t imageBuffer[dimsOut[0]]; + + // initialize + for(int i = 0; i without input for memory data space the whole data space will be read + + dataSet.read(imageBuffer, PredType::NATIVE_INT64); + + // TODO give this data to protobuf deserializer + + } + + //close file + file->close(); + + } // end of try block + + // catch failure caused by the H5File operations + catch( FileIException error ) + { + error.printError(); + return -1; + } + + // catch failure caused by the DataSet operations + catch( DataSetIException error ) + { + error.printError(); + return -1; + } + + // catch failure caused by the DataSpace operations + catch( DataSpaceIException error ) + { + error.printError(); + return -1; + } + + // catch failure caused by the DataSpace operations + catch( DataTypeIException error ) + { + error.printError(); + return -1; + } + + return 0; +} From 66b6646698a4d80b536d72eb7aae55d30cfecb27 Mon Sep 17 00:00:00 2001 From: Elisabeth Hoppe Date: Tue, 26 Apr 2016 12:08:17 +0200 Subject: [PATCH 2/2] Deleted .gitignore from messaging/hdf-reader as we already have .gitignore --- messaging/hdf_reader/.gitignore | 1 - 1 file changed, 1 deletion(-) delete mode 100644 messaging/hdf_reader/.gitignore diff --git a/messaging/hdf_reader/.gitignore b/messaging/hdf_reader/.gitignore deleted file mode 100644 index f36ca87..0000000 --- a/messaging/hdf_reader/.gitignore +++ /dev/null @@ -1 +0,0 @@ -.cproject