Hi Guys,
I am able write STL datatype using .data() function. Example vector.data().
But, That datatype is part of some compound datatype then I am not able to
write exact values(It writes some Garbage Values)
I have simplified my problem can anyone please take look on that …
Here Is my Data Structure
struct RandomData
{
std::vector<float> values;
};
I am using HDF5 CPP library for writing above data structure to HDF file. I
am able write file but It’s writes some “Garbage Values”.
Here Is code …
#include "H5Cpp.h"
#include <vector>
using namespace std;
using namespace H5;
void main()
{
try
{
struct RandomData
{
std::vector<float> values;
};
RandomData d;
d.values.push_back(10);
d.values.push_back(20);
d.values.push_back(30);
//write Dataset to File
H5File file("file.h5",H5F_ACC_TRUNC);
Group group = file.createGroup("group");
int rank = 1;
hsize_t dimesion [] = {1};
DataSpace space(rank,dimesion);
CompType comptype(sizeof(RandomData));
comptype.insertMember("x"
,HOFFSET(RandomData,values),H5::PredType::NATIVE_FLOAT);
DataSet dataset = group.createDataSet("r1",comptype,space);
dataset.write(&d,comptype);
space.close();
dataset.close();
group.close();
file.close();
}
catch(FileIException error)
{
error.printError();
}
}
Am I missing something over here? If not then please guide me on
alternative solution .It’s very helpful for me.
Regards,
Shamkumar