diff --git a/examples/hdfgroup/H5G/CMakeLists.txt b/examples/hdfgroup/H5G/CMakeLists.txt index 139597f9cb..b44a7618ed 100644 --- a/examples/hdfgroup/H5G/CMakeLists.txt +++ b/examples/hdfgroup/H5G/CMakeLists.txt @@ -1,2 +1,28 @@ +add_executable(h5ex_g_compact h5ex_g_compact.cpp) +target_link_libraries(h5ex_g_compact h5cpp) +add_executable(h5ex_g_corder h5ex_g_corder.cpp) +target_link_libraries(h5ex_g_corder h5cpp) + +add_executable(h5ex_g_create h5ex_g_create.cpp) +target_link_libraries(h5ex_g_create h5cpp) + +add_executable(h5ex_g_intermediate h5ex_g_intermediate.cpp) +target_link_libraries(h5ex_g_intermediate h5cpp) + +add_executable(h5ex_g_phase h5ex_g_phase.cpp) +target_link_libraries(h5ex_g_phase h5cpp) + +configure_file(h5ex_g_iterate.h5 h5ex_g_iterate.h5 COPYONLY) +configure_file(h5ex_g_traverse.h5 h5ex_g_traverse.h5 COPYONLY) +configure_file(h5ex_g_visit.h5 h5ex_g_visit.h5 COPYONLY) + +add_executable(h5ex_g_iterate h5ex_g_iterate.cpp) +target_link_libraries(h5ex_g_iterate h5cpp) + +add_executable(h5ex_g_traverse h5ex_g_traverse.cpp) +target_link_libraries(h5ex_g_traverse h5cpp) + +add_executable(h5ex_g_visit h5ex_g_visit.cpp) +target_link_libraries(h5ex_g_visit h5cpp) \ No newline at end of file diff --git a/examples/hdfgroup/H5G/h5ex_g_compact.cpp b/examples/hdfgroup/H5G/h5ex_g_compact.cpp new file mode 100644 index 0000000000..d3290f0873 --- /dev/null +++ b/examples/hdfgroup/H5G/h5ex_g_compact.cpp @@ -0,0 +1,79 @@ +/************************************************************ + + This example shows how to create "compact-or-indexed" + format groups, new to 1.8. This example also illustrates + the space savings of compact groups by creating 2 files + which are identical except for the group format, and + displaying the file size of each. Both files have one + empty group in the root group. + + This file is intended for use with HDF5 Library version 1.8 + + ************************************************************/ + +#include + +#define FILE1 "h5ex_g_compact1.h5" +#define FILE2 "h5ex_g_compact2.h5" +#define GROUP "G1" + +using namespace hdf5; + +void create_default_file() +{ + // Create file 1. This file will use original format groups. + file::File file = file::create (FILE1, file::AccessFlags::TRUNCATE); + node::Group group (file.root(), GROUP); + + // Obtain the group info and print the group storage type. + node::GroupInfo info = group.info(); + std::cout<<"Group storage type for "< + +#define FILE "h5ex_g_corder.h5" + +using namespace hdf5; + +int main (void) +{ + // Create a new file using the default properties. + file::File file = file::create (FILE, file::AccessFlags::TRUNCATE); + + // Create group creation property list and enable link creation + // order tracking. Attempting to track by creation order in a + // group that does not have this property set will result in an + // error. + property::LinkCreationList lcpl; + property::GroupCreationList gcpl; + gcpl.link_creation_order ( + property::CreationOrder ().enable_tracked ().enable_indexed ()); + + // Create primary group using the property list. + node::Group group (file.root (), "index_group", lcpl, gcpl); + + // Create subgroups in the primary group. These will be tracked + // by creation order. Note that these groups do not have to have + // the creation order tracking property set. + node::Group (group, "H"); + node::Group (group, "D"); + node::Group (group, "F"); + node::Group (group, "5"); + + // Traverse links in the primary group using alphabetical indices + // (H5_INDEX_NAME). + std::cout << "Traversing group using alphabetical indices:" << std::endl + << std::endl; + group.iterator_config ().index (IterationIndex::NAME); + group.iterator_config ().order (IterationOrder::INCREASING); + size_t index = 0; + for (node::Node node : group.nodes) + { + std::cout << "Index " << index++ << ": " << node.link ().path ().name () + << std::endl; + } + + // Traverse links in the primary group by creation order + // (H5_INDEX_CRT_ORDER). + std::cout << std::endl << "Traversing group using creation order indices:" + << std::endl << std::endl; + group.iterator_config ().index (IterationIndex::CREATION_ORDER); + index = 0; + for (node::Node node : group.nodes) + { + std::cout << "Index " << index++ << ": " << node.link ().path ().name () + << std::endl; + } + + return 0; +} diff --git a/examples/hdfgroup/H5G/h5ex_g_create.cpp b/examples/hdfgroup/H5G/h5ex_g_create.cpp new file mode 100644 index 0000000000..60eac6dee3 --- /dev/null +++ b/examples/hdfgroup/H5G/h5ex_g_create.cpp @@ -0,0 +1,30 @@ +/************************************************************ + + This example shows how to create, open, and close a group. + + This file is intended for use with HDF5 Library version 1.8 + + ************************************************************/ + +#include + +#define FILE "h5ex_g_create.h5" + +using namespace hdf5; + +int main(void) +{ + // Create a new file using the default properties. + file::File file = file::create (FILE, file::AccessFlags::TRUNCATE); + + // Create a group named "G1" in the file. + node::Group group (file.root(), "/G1"); + + // Close the group. The handle "group" can no longer be used. + group.close (); + + // Re-open the group, obtaining a new handle. + group = node::get_node (file.root (), "/G1"); + + return 0; +} diff --git a/examples/hdfgroup/H5G/h5ex_g_intermediate.cpp b/examples/hdfgroup/H5G/h5ex_g_intermediate.cpp new file mode 100644 index 0000000000..0133cef53c --- /dev/null +++ b/examples/hdfgroup/H5G/h5ex_g_intermediate.cpp @@ -0,0 +1,49 @@ +/************************************************************ + + This example shows how to create intermediate groups with + a single call to H5Gcreate. + + This file is intended for use with HDF5 Library version 1.8 + + ************************************************************/ + +#include + +#define FILE "h5ex_g_intermediate.h5" + +using namespace hdf5; + +int main(void) +{ + // Create a new file using the default properties. + file::File file = file::create (FILE, file::AccessFlags::TRUNCATE); + + // Create group creation property list and set it to allow creation + // of intermediate groups. + property::LinkCreationList lcpl; + lcpl.enable_intermediate_group_creation (); + + // Create the group /G1/G2/G3. Note that /G1 and /G1/G2 do not + // exist yet. This call would cause an error if we did not use the + // previously created property list. + node::Group group (file.root (), "/G1/G2/G3", lcpl); + + // Print all the objects in the files to show that intermediate + // groups have been created. See h5ex_g_visit for more information + // on how to use H5Ovisit. + std::cout << "Objects in the file:" << std::endl; + node::Group root_group = file.root (); + root_group.iterator_config ().index (IterationIndex::NAME); + root_group.iterator_config ().order (IterationOrder::NATIVE); + std::for_each (node::RecursiveNodeIterator::begin (root_group), + node::RecursiveNodeIterator::end (root_group), + [](const node::Node &node) + { + std::cout< +#include + +#define FILE "h5ex_g_iterate.h5" + +using namespace hdf5; + +int main (void) +{ + // Open file. + file::File file = file::open (FILE, file::AccessFlags::READONLY); + node::Group root_group = file.root (); + + // Begin iteration. + std::cout << "Objects in root group:" << std::endl; + std::for_each (root_group.nodes.begin (), root_group.nodes.end (), + [](const node::Node &node) + { + std::cout< +#include + +#define FILE "h5ex_g_phase.h5" +#define MAX_GROUPS 7 +#define MAX_COMPACT 5 +#define MIN_DENSE 3 + +using namespace hdf5; + +void print_group_info(const node::GroupInfo &info) +{ + std::string group = "Group"; + + group += info.number_of_links () == 1 ? " " : "s"; + std::cout << info.number_of_links () << group << ": Storage type is " + << info.storage_type () << std::endl; +} + +int main (void) +{ + char name[3] = "G0"; /* Name of subgroup */ + + // Set file access property list to allow the latest file format. + // This will allow the library to create new format groups. + property::FileCreationList fcpl; + property::FileAccessList fapl; + fapl.library_version_bounds (property::LibVersion::LATEST, + property::LibVersion::LATEST); + + // Create group access property list and set the phase change + // conditions. In this example we lowered the conversion threshold + // to simplify the output, though this may not be optimal. + property::LinkCreationList lcpl; + property::GroupCreationList gcpl; + gcpl.link_storage_thresholds (MAX_COMPACT, MIN_DENSE); + + // Create a new file using the default properties. + file::File file = file::create (FILE, file::AccessFlags::TRUNCATE, fcpl, + fapl); + + // Create primary group. + node::Group group (file.root(), "G0", lcpl, gcpl); + + // Add subgroups to "group" one at a time, print the storage type + // for "group" after each subgroup is created. + for (size_t i = 1; i <= MAX_GROUPS; i++) + { + + { + std::stringstream ss; + ss << "G0_" << i; + node::Group (group, ss.str ()); + } + + // Obtain the group info and print the group storage type + print_group_info (group.info ()); + } + std::cout<= 1; i--) + { + // Define the subgroup name and delete the subgroup. + std::stringstream ss; + ss << "G0_" << i; + node::remove (group, ss.str ()); + + // Obtain the group info and print the group storage type + print_group_info (group.info ()); + } + + return 0; +} diff --git a/examples/hdfgroup/H5G/h5ex_g_traverse.cpp b/examples/hdfgroup/H5G/h5ex_g_traverse.cpp new file mode 100644 index 0000000000..8591e1d74d --- /dev/null +++ b/examples/hdfgroup/H5G/h5ex_g_traverse.cpp @@ -0,0 +1,45 @@ +/************************************************************ + + This example shows a way to recursively traverse the file + using H5Literate. The method shown here guarantees that + the recursion will not enter an infinite loop, but does + not prevent objects from being visited more than once. + The program prints the directory structure of the file + specified in FILE. The default file used by this example + implements the structure described in the User's Guide, + chapter 4, figure 26. + + This file is intended for use with HDF5 Library version 1.8 + + ************************************************************/ + +#include +#include + +#define FILE "h5ex_g_traverse.h5" +using namespace hdf5; + +int +main (void) +{ + // Open file and initialize the operator data structure. + file::File file = file::open (FILE, file::AccessFlags::READONLY); + node::Group root_group = file.root (); + + // Print the root group and formatting, begin iteration. + std::cout << "/" << std::endl; + std::for_each (node::RecursiveNodeIterator::begin (root_group), + node::RecursiveNodeIterator::end (root_group), + [](const node::Node &node) + { + std::cout< +#include + +#define FILE "h5ex_g_visit.h5" +using namespace hdf5; + +int main (void) +{ + + // Open file + file::File file = file::open (FILE, file::AccessFlags::READONLY); + node::Group root_group = file.root (); + + /* + * Begin iteration using H5Ovisit + */ + std::cout << "Objects in the file:" << std::endl; + std::for_each (node::RecursiveNodeIterator::begin (root_group), + node::RecursiveNodeIterator::end (root_group), + [](const node::Node &node) + { + std::cout<