Hi Quincey,

On Thu, 03 Jun 2010 06:39:27 -0500, Quincey Koziol <[email protected]> wrote:

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

Is the H5Dread() routing robust against H5Pset_vlen_mem_manager's allocate 
function returning NULL?

If so, it might be possible to provide an allocation function

     typedef void *(*H5MM_allocate_t)(size_t  size, void *alloc_info) ;

that divides the size parameter by  H5Tget_size( H5Dget_type()  ) to get
the number of elements that would be allocated for a specific element
(if that one is sufficiently simple).
This function would also need to count which element within the dataspace
it is just reading, so needs to be one allocate-function per dataspace
to be in sync.

But, would only work if the H5Dread() deals with null pointers by just
skipping the reading, but not exiting with an error. Didn't try this yet.

        Werner



        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




--
___________________________________________________________________________
Dr. Werner Benger                Visualization Research
Laboratory for Creative Arts and Technology (LCAT)
Center for Computation & Technology at Louisiana State University (CCT/LSU)
211 Johnston Hall, Baton Rouge, Louisiana 70803
Tel.: +1 225 578 4809                        Fax.: +1 225 578-5362

_______________________________________________
Hdf-forum is for HDF software users discussion.
[email protected]
http://mail.hdfgroup.org/mailman/listinfo/hdf-forum_hdfgroup.org

Reply via email to