FW: Queries

FYI

hdf5_test.cpp (3.65 KB)

matrix.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

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

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 .

  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.

  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.