HDF5:检查创建组
hdf5: Check to create group
我想自动创建一个组,如果一个组还不存在。但是,我没有成功检查该组是否存在。
失败尝试1
#include <iostream>
#include <string>
#include "H5Cpp.h"
int main(void)
{
H5::H5File file("test.h5",H5F_ACC_TRUNC);
std::string group_name = "/test";
H5::Group group = file.createGroup(group_name.c_str());
if ( !file.attrExists(group_name.c_str()) )
H5::Group group = file.createGroup(group_name.c_str());
return 0;
}
用
汇编$ h5c++ -o test test.cpp
失败,因为file.attrExists(name)
总是返回false
。作为参考,错误发生在createGroup
:
...
#006: H5L.c line 1733 in H5L_link_cb(): name already exists
major: Symbol table
minor: Object already exists
失败尝试2
#include <iostream>
#include <string>
#include "H5Cpp.h"
int main(void)
{
H5::H5File file("test.h5",H5F_ACC_TRUNC);
std::string group_name = "/test";
try { H5::Group group = file.openGroup (group_name.c_str()); }
catch (...) { H5::Group group = file.createGroup(group_name.c_str()); }
return 0;
}
用
汇编$ h5c++ -o test test.cpp
以某种方式,catch
不成功,当openGroup
失败时会产生错误:
...
#005: H5Gloc.c line 385 in H5G_loc_find_cb(): object 'test' doesn't exist
major: Symbol table
minor: Object not found
您的尝试1 ,由于 H5::Group
不是属性而失败,所以
if ( !file.attrExists(group_name.c_str()) )
不是您认为的。Afaik,没有比试图打开该组的简单方法来检查组的存在。这导致我们
您的尝试2 实际上是没有失败,但是有效(不幸的是,您为什么认为?一个例外(,但是您可以抑制
int main(void)
{
H5::Exception::dontPrint(); // suppress error messages
H5::H5File file("test.h5",H5F_ACC_TRUNC);
std::string group_name = "/test";
try {
H5::Group group = file.openGroup (group_name.c_str());
std::cerr<<" TEST: opened groupn"; // for debugging
} catch (...) {
std::cerr<<" TEST: caught somethingn"; // for debugging
H5::Group group = file.createGroup(group_name.c_str());
std::cerr<<" TEST: created groupn"; // for debugging
}
H5::Group group = file.openGroup (group_name.c_str()); // for debugging
std::cerr<<" TEST: opened groupn"; // for debugging
}
生成
测试:捕获的东西
测试:创建组
测试:打开组
相关文章:
- 试图让变量检查数组中的某些内容
- 如何在C++中检查2D数组中负值的输入验证
- 使用for循环检查数组中的重复项
- 如何创建长度由常量参数指定的数组
- 讨论 - 创建矩阵时的数组与向量的向量 - 什么是最实用的选择
- C++LDAP检查用户是否是特定组的成员
- 检查TCHAR数组输入是否为带符号整数C++
- 创建结构的数组时遇到分段错误
- 在c++中为double类型的数组创建一个unique_ptr
- 检查彩虹数组(检查数组的反向样式是否与自身匹配)
- 如何创建一个带锁的指针数组并检查指针是否空闲?
- HDF5:检查创建组
- 有没有办法创建一个花哨的迭代器和相应的新数组,以便检查每个索引的索引值的条件?
- 使用数组检查连续性
- c++ 根据随机生成的数组检查用户输入的值
- 将在一行中声明的成员记录在一起,而不创建组
- 使用字符串数组检查用户输入
- 使用数组和无指针创建回文字符串检查器C++
- 我需要检查一个接一个地知道哪个单选按钮在Qt组检查
- 创建一个函数,检查一个数组是否有两个相反的元素,复杂度小于n^2.(c++)