ReadingVData.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /// \copyright Copyright (c) Catalysts GmbH
  2. /// \author Patrik Kovacs, Catalysts GmbH
  3. #include <hdf4cpp/hdf.h>
  4. #include <iostream>
  5. using namespace hdf4cpp;
  6. // NOLINTNEXTLINE(bugprone-exception-escape)
  7. int main() {
  8. // Open the file
  9. HdfFile file(TEST_DATA_PATH "small_test.hdf");
  10. // Get the item
  11. HdfItem item = file.get("Vdata");
  12. // Reading scalar field
  13. {
  14. std::vector<int32> vec;
  15. item.read(vec, "age");
  16. std::cout << "Age field values: ";
  17. for (const auto &value : vec) {
  18. std::cout << value << ' ';
  19. }
  20. std::cout << std::endl;
  21. }
  22. // Reading array field (string)
  23. {
  24. std::vector<std::vector<char> > vec;
  25. item.read(vec, "name");
  26. std::cout << "Name field values: ";
  27. for(const auto& char_vec : vec) {
  28. std::string string(char_vec.data());
  29. std::cout << '\'' << string << "' ";
  30. }
  31. std::cout << std::endl;
  32. }
  33. // Reading attribute
  34. {
  35. HdfAttribute attribute = item.getAttribute("attribute");
  36. std::vector<int32> vec;
  37. attribute.get(vec);
  38. std::cout << "Attribute values: ";
  39. for(const auto& value : vec) {
  40. std::cout << value << ' ';
  41. }
  42. std::cout << std::endl;
  43. }
  44. }