下面的代码打印出我的168MB输入.h5文件的错误。但适用于我的10MB大小的文件。
/*
* hdf5write.cpp
*/
#include <iostream>
#include <string>
#include "H5Cpp.h"
#include "hdf5write.h"
using namespace std;
const H5std_string DATASET_NAME("geom_data");
const int RANK = 2;
int Hdf5Write(float** & data, size_t & NX, size_t & NY, char* & OutFileName)
{
H5std_string FILE_NAME(OutFileName);
/* Create a new file using H5F_ACC_TRUNC access,
* default file creation properties, and default file
* access properties.
*/
// H5F: file interface
H5::H5File file( FILE_NAME, H5F_ACC_TRUNC ); // make a file
/*
* Define the size of the array and create the data space for fixed
* size dataset.
*/
// unsigned long long dimsf[2]; // dataset dimensions
hsize_t dimsf[2];
dimsf[0] = NX;
dimsf[1] = NY;
// H5D: datasets interface
H5::DataSpace dataspace( RANK, dimsf ); // need to know dimensions and size to allocate dataspace
/*
* Define datatype for the data in the file.
* We will store little endian INT numbers.
*/
// H5::IntType datatype( H5::PredType::NATIVE_INT ); // Class IntType operates on HDF5 integer datatype
// create a integer type called "datatype", which is
// H5F: define a float type
// H5::FloatType datatype( H5::PredType::NATIVE_FLOAT );
H5::DataSet dataset = file.createDataSet( DATASET_NAME, H5::PredType::NATIVE_FLOAT, dataspace );
dataset.write( data, H5::PredType::NATIVE_FLOAT );
return 0; // successfully terminated
}
发现错误位于dataset.write( data, H5::PredType::NATIVE_FLOAT, dataspace, dataspace );
HDF5-DIAG: Error detected in HDF5 (1.8.11) thread 140007692102656:
#000: ../../../src/H5Dio.c line 234 in H5Dwrite(): can't prepare for writing data
major: Dataset
minor: Write failed
以前我总是使用HDF5 fortran API并且始终运行良好。这次我使用c ++ api。