Quantcast

Reading only H5T_STRING entry from COMPOUND dataset

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Reading only H5T_STRING entry from COMPOUND dataset

Arthur Muller
Hello,

I have a compound dataset where h5dump generates the following information:

               DATASET "SUBCASE" {
                  DATATYPE  H5T_COMPOUND {
                     ...
                     H5T_STRING {
                        STRSIZE 128;
                        STRPAD H5T_STR_NULLTERM;
                        CSET H5T_CSET_ASCII;
                        CTYPE H5T_C_S1;
                     } "TITLE";

The other entries in this COMPOUND dataset consists of arrays of integers and floats; I have no problem reading any of them.

But I am trying to read ONLY the "TITLE" entry. So I do the following:

hid_t memtype;
hid_t native;

memtype = H5Tcreate (h5T_COMPOUND,128);
native = H5Tcopy (H5T_C_S1);
H5Tinsert (memtype,"TITLE",128,native);

My dataset is opened under hid_t did. I then do

hid_t space;
char data[200];

space = H5Dget_space (did);
H5Dread (did,memtype,H5S_ALL,H5S_ALL,H5P_DEFAULT,data);

The problem is that "data" comes back with all blanks. But h5dump and HDFView show that the title has a real, non-blank string there.

This is my first time reading H5T_STRINGs. Clearly, I'm doing something wrong. Can somebody point me towards the solution to this so that "data" will contain the string I'm looking for?

Thanks.

-Arthur

_______________________________________________
Hdf-forum is for HDF software users discussion.
[hidden email]
http://lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org
Twitter: https://twitter.com/hdf5
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Reading only H5T_STRING entry from COMPOUND dataset

Gerd Heber
Arthur, how about this?

hid_t memtype;
hid_t native;

memtype = H5Tcreate (H5T_COMPOUND,128);
native = H5Tcopy (H5T_C_S1);
H5Tset_size(native, 128);
H5Tinsert(memtype,"TITLE",0,native);

You have to make sure that your string type has 128 bytes.
Also, the third parameter in H5Tinsert is the field offset not its size.

Does that work for you?

G.



From: Hdf-forum [mailto:[hidden email]] On Behalf Of [hidden email]
Sent: Monday, November 28, 2016 2:06 PM
To: [hidden email]
Subject: [Hdf-forum] Reading only H5T_STRING entry from COMPOUND dataset

Hello,

I have a compound dataset where h5dump generates the following information:

               DATASET "SUBCASE" {
                  DATATYPE  H5T_COMPOUND {
                     ...
                     H5T_STRING {
                        STRSIZE 128;
                        STRPAD H5T_STR_NULLTERM;
                        CSET H5T_CSET_ASCII;
                        CTYPE H5T_C_S1;
                     } "TITLE";

The other entries in this COMPOUND dataset consists of arrays of integers and floats; I have no problem reading any of them.

But I am trying to read ONLY the "TITLE" entry. So I do the following:

hid_t memtype;
hid_t native;

memtype = H5Tcreate (h5T_COMPOUND,128);
native = H5Tcopy (H5T_C_S1);
H5Tinsert (memtype,"TITLE",128,native);

My dataset is opened under hid_t did. I then do

hid_t space;
char data[200];

space = H5Dget_space (did);
H5Dread (did,memtype,H5S_ALL,H5S_ALL,H5P_DEFAULT,data);

The problem is that "data" comes back with all blanks. But h5dump and HDFView show that the title has a real, non-blank string there.

This is my first time reading H5T_STRINGs. Clearly, I'm doing something wrong. Can somebody point me towards the solution to this so that "data" will contain the string I'm looking for?

Thanks.

-Arthur
_______________________________________________
Hdf-forum is for HDF software users discussion.
[hidden email]
http://lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org
Twitter: https://twitter.com/hdf5
Loading...