# FW: Queries

**URL:** <https://forum.hdfgroup.org/t/fw-queries/1014>\
**Category:** Hdf-forum archives\
**Created:** [June 4, 2008, 12:18pm UTC](https://forum.hdfgroup.org/t/fw-queries/1014 "2008-06-04T12:18:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ramakrishnan.iyer](https://forum.hdfgroup.org/letter_avatar_proxy/v4/letter/r/3e96dc/32.png) [@ramakrishnan.iyer](https://forum.hdfgroup.org/u/ramakrishnan.iyer)\
**Post date:** [June 4, 2008, 12:18pm UTC](https://forum.hdfgroup.org/t/fw-queries/1014/1 "2008-06-04T12:18:26Z")

</div>

FYI

[hdf5\_test.cpp](https://hdf-discourse-1.s3.amazonaws.com/original/1X/92d64d07b9125608e59c24d3914ac27df7cdb15e.cpp) (3.65 KB)

[matrix.h5](https://hdf-discourse-1.s3.amazonaws.com/original/1X/c15ef3615407deb94f2524457fd3c32b33e013ff.h5) (4.07 KB)

> **···**
>
> -----Original Message-----  
> From: Ramakrishnan Iyer  
> Sent: Wednesday, June 04, 2008 5:25 PM  
> To: 'hdf-forum-help@hdfgroup.org'  
> Subject: Queries
> 
> Hi,
> 
> I have the following issues/queries ( am using HDF1.6.5 ).
> 
> 1. I store a dataset which has a datatype of the following nature
> 
> struct data {
> 
> char \*name[1];
> 
> unsigned int id ;
> 
> hdset\_reg\_ref\_t ref;
> 
> }
> 
> I need to access this dataset every now and then to check whether an  
> object with the given id is already written . I store an attribute for  
> the dataset which indicates the number of elements written into the  
> dataset . For every check I start from the first element to the last  
> written element and read the contents into a local variable ( of type  
> struct data defined above ) . The string name has a variable length .
> 
> If there are 5 elements in the dataset I read all the elements in a for  
> loop one by one into the same local variable .
> 
> Do I need to use the H5Dvlen\_reclaim function after I have read each  
> element into the local variable and checked for its existence ? What  
> will happen if I do not use H5Dvlen\_reclaim ? If I use it I get a crash  
> when this called .
> 
> 2. As a part of one of the objects , I need to store a 4X4 matrix . The  
> data structure for the element is defined as follows
> 
> struct obj
> 
> {
> 
> double mat[4][4];
> 
> int id;
> 
> };
> 
> The type for this is created as follows .
> 
> unsigned int dtsize=sizeof(obj);
> 
> hsize\_t arr\_dims[]={4,4}; //!2 dimensional array
> 
> hid\_t matrix= H5Tarray\_create (H5T\_STD\_U32LE, 2, arr\_dims, NULL);
> 
> objtype=H5Tcreate(H5T\_COMPOUND,dtsize);
> 
> H5Tinsert(objtype,"Trans-Matrix",HOFFSET(obj,mat),matrix);
> 
> H5Tinsert(objtype,"IdHOFFSET(obj,id),H5T\_NATIVE\_UINT);
> 
> I declare a variable of type struct obj and populate the matix and id .  
> I do the selection of the dataspace and then call H5Dwrite on the  
> dataset . When I check the output from h5dump this is what is written in  
> the matrix
> 
> 0,1072693248,0,0,0,0,0,0,0,0,0,1072693248,0,0,0,0 ( I had an identity  
> matrix as input ) . Why do yiou think this might have occurred . The id  
> portion was written properly .
> 
> Find attached the sample program and the output file .
> 
> Regards
> 
> Ramakrishnan

---

<div class="post-metadata">

**Author:** ![ramakrishnan.iyer](https://forum.hdfgroup.org/letter_avatar_proxy/v4/letter/r/3e96dc/32.png) [@ramakrishnan.iyer](https://forum.hdfgroup.org/u/ramakrishnan.iyer)\
**Post date:** [June 6, 2008, 6:05am UTC](https://forum.hdfgroup.org/t/fw-queries/1014/2 "2008-06-06T06:05:50Z")

</div>

I found the mistakes . I had to use H5T\_NATIVE\_DOUBLE instead of  
H5T\_STD\_U32LE for writing the matrix .

For the first problem , I was doing memcpy with wrong type . My question  
regarding when to use H5Dvlen\_reclaim still stays though .

> **···**
>
> -----Original Message-----  
> From: Ramakrishnan Iyer  
> Sent: Wednesday, June 04, 2008 5:25 PM  
> To: 'hdf-forum-help@hdfgroup.org'  
> Subject: Queries
> 
> Hi,
> 
> I have the following issues/queries ( am using HDF1.6.5 ).
> 
> 1. I store a dataset which has a datatype of the following nature
> 
> struct data {
> 
> char \*name[1];
> 
> unsigned int id ;
> 
> hdset\_reg\_ref\_t ref;
> 
> }
> 
> I need to access this dataset every now and then to check whether an  
> object with the given id is already written . I store an attribute for  
> the dataset which indicates the number of elements written into the  
> dataset . For every check I start from the first element to the last  
> written element and read the contents into a local variable ( of type  
> struct data defined above ) . The string name has a variable length .
> 
> If there are 5 elements in the dataset I read all the elements in a for  
> loop one by one into the same local variable .
> 
> Do I need to use the H5Dvlen\_reclaim function after I have read each  
> element into the local variable and checked for its existence ? What  
> will happen if I do not use H5Dvlen\_reclaim ? If I use it I get a crash  
> when this called .
> 
> 2. As a part of one of the objects , I need to store a 4X4 matrix . The  
> data structure for the element is defined as follows
> 
> struct obj
> 
> {
> 
> double mat[4][4];
> 
> int id;
> 
> };
> 
> The type for this is created as follows .
> 
> unsigned int dtsize=sizeof(obj);
> 
> hsize\_t arr\_dims[]={4,4}; //!2 dimensional array
> 
> hid\_t matrix= H5Tarray\_create (H5T\_STD\_U32LE, 2, arr\_dims, NULL);
> 
> objtype=H5Tcreate(H5T\_COMPOUND,dtsize);
> 
> H5Tinsert(objtype,"Trans-Matrix",HOFFSET(obj,mat),matrix);
> 
> H5Tinsert(objtype,"IdHOFFSET(obj,id),H5T\_NATIVE\_UINT);
> 
> I declare a variable of type struct obj and populate the matix and id .  
> I do the selection of the dataspace and then call H5Dwrite on the  
> dataset . When I check the output from h5dump this is what is written in  
> the matrix
> 
> 0,1072693248,0,0,0,0,0,0,0,0,0,1072693248,0,0,0,0 ( I had an identity  
> matrix as input ) . Why do yiou think this might have occurred . The id  
> portion was written properly .
> 
> Find attached the sample program and the output file .
> 
> Regards
> 
> Ramakrishnan

---

<div class="post-metadata">

**Author:** ![Quincey\_Koziol](https://forum.hdfgroup.org/letter_avatar_proxy/v4/letter/q/dbc845/32.png) [@Quincey\_Koziol](https://forum.hdfgroup.org/u/Quincey_Koziol)\
**Post date:** [June 6, 2008, 2:37pm UTC](https://forum.hdfgroup.org/t/fw-queries/1014/3 "2008-06-06T14:37:18Z")

</div>

Hi Ramakrishnan,

> I found the mistakes . I had to use H5T\_NATIVE\_DOUBLE instead of H5T\_STD\_U32LE for writing the matrix .
> 
> For the first problem , I was doing memcpy with wrong type . My question regarding when to use H5Dvlen\_reclaim still stays though .

&nbsp;&nbsp;Yes, you should release the memory that the HDF5 library allocates to store the variable  
length data read from disk. Calling HDvlen\_reclaim is a convenient way to do that, but other ways may work also. You may want to use the H5Pset\_vlen\_mem\_manager, if you'd like more control over the memory allocation & release process.

&nbsp;&nbsp;Quincey

> **···**
>
> On Jun 6, 2008, at 1:05 AM, Ramakrishnan Iyer wrote:
> 
> > -----Original Message-----  
> > From: Ramakrishnan Iyer  
> > Sent: Wednesday, June 04, 2008 5:25 PM  
> > To: 'hdf-forum-help@hdfgroup.org'  
> > Subject: Queries
> > 
> > Hi,
> > 
> > I have the following issues/queries ( am using HDF1.6.5 ).
> > 
> > 1. I store a dataset which has a datatype of the following nature
> > 
> > struct data {
> > 
> > char \*name[1];
> > 
> > unsigned int id ;
> > 
> > hdset\_reg\_ref\_t ref;
> > 
> > }
> > 
> > I need to access this dataset every now and then to check whether an object with the given id is already written . I store an attribute for the dataset which indicates the number of elements written into the dataset . For every check I start from the first element to the last written element and read the contents into a local variable ( of type struct data defined above ) . The string name has a variable length .
> > 
> > If there are 5 elements in the dataset I read all the elements in a for loop one by one into the same local variable .
> > 
> > Do I need to use the H5Dvlen\_reclaim function after I have read each element into the local variable and checked for its existence ? What will happen if I do not use H5Dvlen\_reclaim ? If I use it I get a crash when this called .
> > 
> > 2. As a part of one of the objects , I need to store a 4X4 matrix . The data structure for the element is defined as follows
> > 
> > struct obj
> > 
> > {
> > 
> > double mat[4][4];
> > 
> > int id;
> > 
> > };
> > 
> > The type for this is created as follows .
> > 
> > unsigned int dtsize=sizeof(obj);
> > 
> > hsize\_t arr\_dims={4,4}; //!2 dimensional array
> > 
> > hid\_t matrix= H5Tarray\_create (H5T\_STD\_U32LE, 2, arr\_dims, NULL);
> > 
> > objtype=H5Tcreate(H5T\_COMPOUND,dtsize);  
> > H5Tinsert(objtype,"Trans-Matrix",HOFFSET(obj,mat),matrix);  
> > H5Tinsert(objtype,"IdHOFFSET(obj,id),H5T\_NATIVE\_UINT);
> > 
> > I declare a variable of type struct obj and populate the matix and id . I do the selection of the dataspace and then call H5Dwrite on the dataset . When I check the output from h5dump this is what is written in the matrix
> > 
> > 0,1072693248,0,0,0,0,0,0,0,0,0,1072693248,0,0,0,0 ( I had an identity matrix as input ) . Why do yiou think this might have occurred . The id portion was written properly .
> > 
> > Find attached the sample program and the output file .
> > 
> > Regards
> > 
> > Ramakrishnan
> 
> ----------------------------------------------------------------------  
> This mailing list is for HDF software users discussion.  
> To subscribe to this list, send a message to hdf-forum-subscribe@hdfgroup.org.  
> To unsubscribe, send a message to hdf-forum-unsubscribe@hdfgroup.org.
