【发布时间】:2017-12-01 00:46:05
【问题描述】:
我想使用我的 HDF5 数据集的维度来创建一个数组。我正在使用以下代码来查找我的数据集的维度。
#include <iostream>
#include <string>
#include <vector>
#include <iomanip>
#include <typeinfo>
#include "H5cpp.h"
using namespace H5;
int main() {
std::string sFileName;
sFileName = "test.h5";
const H5std_string FILE_NAME(sFileName);
const H5std_string DATASET_NAME("timestep:5.0");
H5File file(FILE_NAME.c_str(), H5F_ACC_RDONLY);
DataSet dataset = file.openDataSet(DATASET_NAME.c_str());
DataSpace dataspace = dataset.getSpace();
int rank = dataspace.getSimpleExtentNdims();
// Get the dimension size of each dimension in the dataspace and display them.
hsize_t dims_out[2];
int ndims = dataspace.getSimpleExtentDims(dims_out, NULL);
std::cout << "rank " << rank << ", dimensions " <<
(unsigned long)(dims_out[0]) << " x " <<
(unsigned long)(dims_out[1]) << std::endl;
const int xrows = static_cast<int>(dims_out[0]); //120
const int yrows = static_cast<int>(dims_out[1]); //100
std::cout << xrows * yrows << std::endl; //12000
double myArr[xrows] // this also produces an error saying xrows is not a constant value
}
但是,当我尝试使用
创建数组时double myArr[xrows*yrows];
我收到一条错误消息,指出 xrows 和 yrows 不是常量值。我该如何解决这个问题?
【问题讨论】: