Hello Shamkumar,
The problem is that H5::PredType::NATIVE_FLOAT should only be used with a
single float rather than with an array of floats.
The datatype in this statement
comptype.insertMember("x",HOFFSET(RandomData,values),H5::PredType::NATIVE_FLOAT);
would have to reflex the multiple values of the RandomData::values.
You would need to create an HDF5 datatype to represent the type of
RandomData::values. I would guess an ArrayType, then pass that in place of
H5::PredType::NATIVE_FLOAT. The length of the array would be 3.
I hope this helps.
Binh-Minh
________________________________
From: Hdf-forum <[email protected]> on behalf of shamkumar
rajput <[email protected]>
Sent: Tuesday, May 3, 2016 3:48 AM
To: [email protected]
Subject: [Hdf-forum] HDF5 Compatibility with STL Datatype
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
_______________________________________________
Hdf-forum is for HDF software users discussion.
[email protected]
http://lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org
Twitter: https://twitter.com/hdf5