Reading data from an unknown source

During the course of development, there are multiple versions of our file. I need to be able to read any form of the files. I can do this via the naming conventions, which have basically remained the same. I’m stuck. I cannot figure out how to read in the Type of a table (we have changed types on some of the variable data over the life of the project). I have tried various things. A snippet of what I’m attempting to do follows:


pid = [open group]
did =  H5Dopen(pid, name);
type = H5Tget_class(H5Dget_type(did));
switch (type){
        case H5T_COMPOUND:
                if ((H5Tget_table_info(pid, name, &fields, &records))<0){
                        // handle error
                }
                
                if ((H5Tget_field_info(pid, name, fnames, fsizes, foofsets, &size))<0){
                        // handle error
                }

Up through this, everything works and I know (at least) the data size for each field – which is good, but doesn’t tell me what data type it is. And, that is where I’m stuck.

I have attempted various things. The one that I really expected to be the “right thing” is:


                for (i=0; i<fields; ++i){
                        H5Tget_memeber_type(did, i);


Though the H5TBget_table_info() and H5TBget_field_info() calls succeed, the call into H5Tget_member_type() fails with:


HDF5-DIAG: Error detected in HDF5 (1.10.3) thread 0:
  #000: H5Tcompound.c line 224 in H5Tget_member_type(): not a compound datatype
    major: Invalid arguments to routine
    minor: Inappropriate type

Though, I cannot figure how this isn’t a compound datatype when the class returned to type put me in the case H5T_COMPOUND.

Please point me in the right direction.

Thanks,
Andy

Edit: Corrected code blocks.

Hi Andy,
Try using the ’type’ variable in the call to H5Tget_member_type().

	Quincey

Hi Quincey!

Thanks for the reply. The “type” variable is what gives me the “H5T_COMPOUND” response that I’m using to switch() on. I have things like fields = { “Name”, “Temperature”, … } where Name turns into a char name[32], Temperature could be either float, double, or long double. I need to know which it is to bring it to our current type. I cannot figure out how to get the type of Name and Temperature – both of which are fields in a table. I need the type of the fields in the table.

Thanks,
Andy

Bump. I have also asked this to the help contact. I have yet to get a response there either. Does anyone understand why, when I get a type == H5T_COMPOUND, and then I ask for the type of a field, I get back:


HDF5-DIAG: Error detected in HDF5 (1.10.3) thread 0:
  #000: H5Tcompound.c line 224 in H5Tget_member_type(): not a compound datatype
    major: Invalid arguments to routine
    minor: Inappropriate type

Did you want to attach a short self contained compilable example? Much easier for others to look at the problem.

I had tried just about everything. I saw that I had not attempted one hid_t return value. The return value for H5Dget_type() was one that I didn’t attempt. So, now, I have it and that is the correct value to put in.

So, if you are looking through this post attempting to get the Native data types, you’ll need this:

pid = [open group]
did =  H5Dopen(pid, name);
type = H5Tget_class((tdid = H5Dget_type(did)));
switch (type){
        case H5T_COMPOUND:
                if ((H5Tget_table_info(pid, name, &fields, &records))<0){
                        // handle error
                }
                
                if ((H5Tget_field_info(pid, name, fnames, fsizes, foofsets, &size))<0){
                        // handle error
                }
                for (i=0; i<fields; ++i){
                        native_hid = H5Tget_memeber_type(tdid, i);
                        // From here, you have to use H5Tequal(native_hid, H5T_NATIVE_)