ReadingVData.cpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. int main() {
  7. // Open the file
  8. HdfFile file(TEST_DATA_PATH "small_test.hdf");
  9. // Get the item
  10. HdfItem item = file.get("Vdata");
  11. // Reading scalar field
  12. {
  13. std::vector<int32> vec;
  14. item.read(vec, "age");
  15. std::cout << "Age field values: ";
  16. for (const auto &value : vec) {
  17. std::cout << value << ' ';
  18. }
  19. std::cout << std::endl;
  20. }
  21. // Reading array field (string)
  22. {
  23. std::vector<std::vector<char> > vec;
  24. item.read(vec, "name");
  25. std::cout << "Name field values: ";
  26. for(const auto& char_vec : vec) {
  27. std::string string(char_vec.data());
  28. std::cout << '\'' << string << "' ";
  29. }
  30. std::cout << std::endl;
  31. }
  32. // Reading attribute
  33. {
  34. HdfAttribute attribute = item.getAttribute("attribute");
  35. std::vector<int32> vec;
  36. attribute.get(vec);
  37. std::cout << "Attribute values: ";
  38. for(const auto& value : vec) {
  39. std::cout << value << ' ';
  40. }
  41. std::cout << std::endl;
  42. }
  43. }