Hi Mark,
On Jun 2, 2010, at 9:36 PM, Mark Miller wrote:
> Yes. But the procedure you'd use depends a bit on what kind of object
> you are talking about (dataset or attribute) and how you chose to define
> the object. Did you use H5T_C_S1 as the datatype for the string? Did you
> maybe just define a dataset/attribute of type H5T_NATIVE_CHAR and then
> an 1D dataspace of some size? I think those choices effect how you'd go
> about obtaining length.
>
> A general algorithm might look like...
>
> 1. whether its a dataset or attribute, you need to open it first
> (H5Dopen/H5Aopen)
> 2. then get its datatype (H5Dget_type/H5Aget_type)
> 3. then get the size of that datatype (H5Tget_size)
> 4. Then get the size of the dataspace
> 5. Use results from steps 3 and 4 to determine total size.
Actually, I think that Ken is trying to determine the actual string
length for an individual element of a dataset or attribute, and he's correct
that there's no way to retrieve the length before reading it in. The method
you describe above is correct for determining the size of the array an
application will need to allocate for reading the strings, but the size
returned from H5Tget_size() should be the same as sizeof(char *) (for
variable-length strings - for variable-length sequences of another datatype, it
should be sizeof(hvl_t)). The memory for the actual strings themselves will be
allocated at read time (and the malloc/free routines used can be controlled
with H5Pset_vlen_mem_manager).
Quincey
> Mark
>
> On Wed, 2010-06-02 at 18:55, Ken Sullivan wrote:
>> Quick question, is there a way to find the length of a variable length
>> string without first reading it?
>>
>> Thanks,
>> Ken
> --
> Mark C. Miller, Lawrence Livermore National Laboratory
> ================!!LLNL BUSINESS ONLY!!================
> [email protected] urgent: [email protected]
> T:8-6 (925)-423-5901 M/W/Th:7-12,2-7 (530)-753-851
>
>
> _______________________________________________
> Hdf-forum is for HDF software users discussion.
> [email protected]
> http://mail.hdfgroup.org/mailman/listinfo/hdf-forum_hdfgroup.org
_______________________________________________
Hdf-forum is for HDF software users discussion.
[email protected]
http://mail.hdfgroup.org/mailman/listinfo/hdf-forum_hdfgroup.org