That is of course if you don't know in advance the number of elements in the attribute and its type size (if you do know, then it's just a matter of defining a static buffer to read your data).
Like the question from your previous post, an example for this behavior is not very well documented.
It is on our TO DO list to write a user's manual for the Lite API.
I wrote an example that uses both approaches , when we do know this information and when we do not. I send it here and as an attachment
let me know if you have further questions.
thanks !
Pedro
/* make a dataset */
if ( H5LTmake_dataset( fid, "my_dset", rank, dims, H5T_NATIVE_INT, NULL ) < 0 )
goto out;
/* create and write the attribute "attr1" on the dataset "my_dset" */
if ( H5LTset_attribute_double(fid, "my_dset", "attr1", buf, ATTR_SIZE ) < 0 )
goto out;
/* get attribute rank */
if ( H5LTget_attribute_ndims(fid, "my_dset", "attr1", &rankr ) < 0 )
goto out;
printf("rank is %d\n", rankr);
dimsr = malloc( sizeof(hsize_t) * rankr );
/* get the type size and dimensions */
if ( H5LTget_attribute_info(fid, "my_dset", "attr1", dimsr, &type_class, &type_size) < 0 )
goto out;
/* calculate number of elements */
nelmts = 1;
for(i = 0; i < rankr; i++)
nelmts *= dimsr[i];
printf("number of elements is %d and its size is %d\n", nelmts, type_size);
/* allocate a buffer to read */
bufrd = malloc( type_size * nelmts );
/* get the attribute "attr1" from the dataset "my_dset" using the dynamic buffer */
if ( H5LTget_attribute_double(fid, "my_dset", "attr1", bufrd ) < 0 )
goto out;
/* get the attribute "attr1" from the dataset "my_dset" using the static buffer */
if ( H5LTget_attribute_double(fid, "my_dset", "attr1", bufr ) < 0 )
goto out;
That is of course if you don't know in advance the number of elements in
the attribute and its type size (if you do know, then it's just a matter of
defining a static buffer to read your data).
Like the question from your previous post, an example for this behavior is
not very well documented.
It is on our TO DO list to write a user's manual for the Lite API.
I wrote an example that uses both approaches , when we do know this
information and when we do not. I send it here and as an attachment
let me know if you have further questions.
thanks !
Pedro
/* make a dataset */
if ( H5LTmake_dataset( fid, "my_dset", rank, dims, H5T_NATIVE_INT,
NULL ) < 0 )
goto out;
/* create and write the attribute "attr1" on the dataset "my_dset" */
if ( H5LTset_attribute_double(fid, "my_dset", "attr1", buf, ATTR_SIZE
) < 0 )
goto out;
/* get attribute rank */
if ( H5LTget_attribute_ndims(fid, "my_dset", "attr1", &rankr ) < 0 )
goto out;
printf("rank is %d\n", rankr);
dimsr = malloc( sizeof(hsize_t) * rankr );
/* get the type size and dimensions */
if ( H5LTget_attribute_info(fid, "my_dset", "attr1", dimsr,
&type_class, &type_size) < 0 )
goto out;
/* calculate number of elements */
nelmts = 1;
for(i = 0; i < rankr; i++)
nelmts *= dimsr[i];
printf("number of elements is %d and its size is %d\n", nelmts,
type_size);
/* allocate a buffer to read */
bufrd = malloc( type_size * nelmts );
/* get the attribute "attr1" from the dataset "my_dset" using the
dynamic buffer */
if ( H5LTget_attribute_double(fid, "my_dset", "attr1", bufrd ) < 0 )
goto out;
/* get the attribute "attr1" from the dataset "my_dset" using the
static buffer */
if ( H5LTget_attribute_double(fid, "my_dset", "attr1", bufr ) < 0 )
goto out;