[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [h5md-user] Strings again / parallel issue
From: |
Pierre de Buyl |
Subject: |
Re: [h5md-user] Strings again / parallel issue |
Date: |
Wed, 5 Feb 2014 14:15:05 +0100 |
User-agent: |
Mutt/1.5.21 (2010-09-15) |
On Tue, Feb 04, 2014 at 06:24:48PM +0100, Felix Höfling wrote:
> Am 04.02.2014, 16:05 Uhr, schrieb Pierre de Buyl
> <address@hidden>:
>
> I always felt uncomfortable with specialising to a certain String type. I
> suggest to drop "VL" and allow _any_ kind of HDF5 String type for the
> writer. The reader can easily handle the different cases by querying
> H5Tis_variable_str
> http://www.hdfgroup.org/HDF5/doc/RM/RM_H5T.html#Datatype-IsVariableString
Actually, I think it will avoid a lot of problems to define what kind of strings
we want. Aside from the purely practical aspect of writing less code, it also
avoids the question from a new user: "what kind of strings should I use?".
Removing this question makes it easier, in my opinion. Also, it decreases the
amount of documentation in, say, the "implementation" page of the h5md site.
I really didn't want to bring the debate back, but a solution in Fortran should
be available :-)
If, as it is discussed on the other sub-thread, you cannot use VL strings in
Fortran for the attributes (very specific case, but still), I'd prefer that we
mandate fixed-length.
Cheers,
Pierre
> For reading a string attribute, you may have a look at the code snippet
> below.
>
> Regards,
>
> Felix
>
> PS: I've resent the message since it seemingly had not arrived at
> the list the first time.
>
> std::string read_string_attribute(hid_t attr_id)
> {
> std::string value;
> hid_t type_id = H5Aget_type(attr_id));
> htri_t is_varlen_str = H5Tis_variable_str(type_id));
> if (is_varlen_str > 0) {
> // read fixed-size string, allocate space in advance and let the
> HDF5
> // library take care about NULLTERM and NULLPAD strings
> hsize_t size = H5Tget_size(type_id);
> hid_t mem_type_id = H5Tcopy(H5T_C_S1);
> H5Tset_size(mem_type_id, size);
> value.resize(size, std::string::value_type());
> H5Aread(attr_id, mem_type_id, &*value.begin());
> } else {
> // read variable-length string, memory will be allocated
> by HDF5 C
> // library and must be freed by us
> char *c_str;
> if (H5Aread(attr_id, H5T_C_S1, &c_str) >= 0) {
> value = c_str; // copy '\0'-terminated string
> free(c_str);
> }
> }
> H5Tclose(type_id);
> H5Aclose(attr_id);
> return value;
> }
- Re: [h5md-user] Strings again / parallel issue, (continued)
- Re: [h5md-user] Strings again / parallel issue, Felix Höfling, 2014/02/06
- Re: [h5md-user] Strings again / parallel issue, Peter Colberg, 2014/02/06
- Re: [h5md-user] Strings again / parallel issue, Pierre de Buyl, 2014/02/06
- Re: [h5md-user] Strings again / parallel issue, Felix Höfling, 2014/02/07
- Re: [h5md-user] Strings again / parallel issue, Pierre de Buyl, 2014/02/07
- Re: [h5md-user] Strings again / parallel issue, Peter Colberg, 2014/02/07
- Re: [h5md-user] Strings again / parallel issue, Pierre de Buyl, 2014/02/06
- Re: [h5md-user] Strings again / parallel issue, Peter Colberg, 2014/02/06
Re: [h5md-user] Strings again / parallel issue, Felix Höfling, 2014/02/04
Re: [h5md-user] Strings again / parallel issue, Felix Höfling, 2014/02/04
- Re: [h5md-user] Strings again / parallel issue,
Pierre de Buyl <=