Moritz Wanzenböck 395ef4e6e5 Fix linux build | 7 rokov pred | |
---|---|---|
cmake | 7 rokov pred | |
examples | 7 rokov pred | |
include | 7 rokov pred | |
lib | 7 rokov pred | |
tests | 7 rokov pred | |
.clang-format | 7 rokov pred | |
.gitignore | 7 rokov pred | |
CMakeLists.txt | 7 rokov pred | |
Doxyfile_all.in | 7 rokov pred | |
Doxyfile_user.in | 7 rokov pred | |
LICENSE | 7 rokov pred | |
README.md | 7 rokov pred | |
format.sh | 7 rokov pred |
The HDF4CPP library is a wrapper library of the hdf4 C interfaces. The target was to create a common c++ api to read and write hdf scientific data. The only supports the reading of the data at the moment.
The idea is to use objects and their methods to do the operations. These classes are representing different kind of data, so the operation functions are separated. Only reading is supported right now.
HdfObject - the base class of all the classes
HdfFile - represents an hdf file
HdfItem - represents an item (SData, VGroup, VData)
- you can get from a file, calling its get function
HdfAttribute - represents an attribute of an item or of a file
- you can get from a file or from an item, calling its getAttribute function
You have to include a single file.
#include <hdf4cpp/hdf.h>
hdf4cpp::HdfFile file("/path/to/the/file");
hdf4cpp::HdfAttribute fileAttr = file.getAttribute("file attribute name");
hdf4cpp::HdfItem item = file.get("item name");
hdf4cpp::HdfAttribute itemAttr = item.getAttribute("item attribute name");
std::vector<hdf4cpp::HdfItem> items = file.getAll("items name");
Every kind of hdf data (SData, Vgroup, Vdata) stores different structures. These information must be read in a different way, we have to call different methods.
So we get the type of the object just to be sure that we want to read the data in a correct way.
switch(item.getType()) {
case hdf4cpp::SDATA:
// reading the sdata
case hdf4cpp::VDATA:
// reading the vdata
default:
std::cerr << "data is not readable";
// note: VGroup has no data to be read
}
The HdfItem objects have a read function but overridden for every reading procedure. The first parameter is a vector in every case, in which the data will be stored.
You have two possibilities.
You can read the entire data.
std::vector<int> vec;
item.read(vec);
You can read the data in a specific range.
std::vector<int> vec;
std::vector<hdf4cpp::Range> ranges;
// We have to specify the range for every dimension
for(size_t i = 0; i < number_of_dimensions; ++i) {
ranges.push_back(hdf4cpp::Range(begin, quantity, stride));
// begin - the first index which is included in the range
// quantity - the number of value to be read
// stride - reading pattern (1 : every element, 2 : every second element, ...)
// stride has a default value (1 : every element)
}
item.read(vec, ranges);
You have to specify:
The data can be scalar: a field has only one value for every record.
std::vector<int> vec;
item.read(vec, "field_name", number_of_records);
The data can be array: a field has multiple values for every record. For example: if a field's type is string, it is considered that every record has multiple character values (character array).
// Reading string field
std::vector<std::vector<char> > vec;
item.read(vec, "field_name"); // the number_of_records it can be eliminated if I want to read all the records
// Getting the string vector
std::vector<std::string> string_vec;
for(const auto& char_vec : vec) {
string_vec.push_back(char_vec.data());
}
Note: The library does a type size check, and throws an exception in case of mismatch.
The HdfAttribute objects have a read function which receives a vector reference. Here will be the data stored.
std::vector<short> vec;
attribute.get(vec);
Note: The library does a type size check, and throws an exception in case of mismatch.
The library throws an HdfException on any errors. This specific exception has getType and getClassType methods, just to get information about the thrower object. Has a getExceptionType which returns information about the type of the exception, and a getMessage method which returns a message as string.