Hi Guys,

Thanks you for quick reply.

Both solution are working fine for me.


Regards,
Shamkumar



On Tue, May 3, 2016 at 10:21 PM, David <[email protected]> wrote:

> A std::vector<float> will look something like this in memory:
>
> vector<float> {
>    float* buf;
>    size_t size;
>    size_t capactiy;
> };
>
> So that's what is getting written by your code. The data you actually want
> to write is where the 'buf' pointer points (which is what vector::data()
> returns).
>
> If you want to put an array of data into a struct you can use
> std::array<float> but that will have fixed size. There is no way to put a
> dynamically sized array into a struct.
>
>
>
>
>
> On Tue, May 3, 2016 at 12:48 AM, shamkumar rajput <
> [email protected]> wrote:
>
>> 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
>>
>
>
> _______________________________________________
> 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
>
_______________________________________________
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

Reply via email to