HDF5 - C - Read unknown H5T_COMPOUND

Dear all,

I would like to read the content of an unknown H5T_COMPOUND variable from a
C program.

I would like to retrieve:
- the number of elements
- the type of each elements
- the name of each element

Obviously, I know it is possible, since h5dump manages to do it.

Below is the h5 file content I would like to read, justing knowing that
there is a dataset population and that it is a H5T_COMPOUND.

In my example presented below, I would like to return
- the number of elements : 3
- the type of each elements : {H5T_ARRAY;H5T_ARRAY;H5T_ARRAY}
- the name of each element : {"xReal","obj","con"}

Any advise?

HDF5 "d:/population.h5" {
GROUP "/" {
   DATASET "population" {
      DATATYPE H5T_COMPOUND {
         H5T_ARRAY { [4] H5T_IEEE_F64LE } "xReal";
         H5T_ARRAY { [3] H5T_IEEE_F64LE } "obj";
         H5T_ARRAY { [2] H5T_IEEE_F64LE } "con";
      }
      DATASPACE SIMPLE { ( 3 ) / ( 3 ) }
      DATA {
      (0): {
            [ 0, 0, 0, 0 ],
            [ 0, 0, 0 ],
            [ 0, 0 ]
         },
      (1): {
            [ 0, 0, 0, 0 ],
            [ 0, 0, 0 ],
            [ 0, 0 ]
         },
      (2): {
            [ 0, 0, 0, 0 ],
            [ 0, 0, 0 ],
            [ 0, 0 ]
         }
      }
   }
}
}

Below is the function I started to write

Bool h5_read_population(
        char const * const fileName,
        char const * const dataSetName,
        Population * const population)
{
    hsize_t dims[1] = {0};
    int ndims = 0;
    hid_t file = 0, space = 0, dset = 0;
    size_t nInd = 0;
    if ((file = H5Fopen(fileName, H5F_ACC_RDONLY, H5P_DEFAULT))<0)
    {
        return False;
    }
    if ((dset = H5Dopen(file, dataSetName, H5P_DEFAULT))<0)
    {
        H5Fclose(file);
        return False;
    }
    if ((space = H5Dget_space(dset))<0)
    {
        H5Dclose(dset);
        H5Fclose(file);
        return False;
    }
    ndims = H5Sget_simple_extent_dims(space, dims, NULL);
    if (ndims!=1)
    {
        fprintf(stderr,"%s : Number of dimensions should be one, not
anything else",__FILE__);
    }
    nInd = (size_t)dims[0];
    fprintf(stdout,"%u\n",(unsigned int)nInd);
    return True;
}

I don't do this often so I don't have a good example for you but
you'll need these routines:

        Compound Datatype Properties
  H5Tget_nmembers
  H5Tget_member_class
  H5Tget_member_name
  H5Tget_member_index
  H5Tget_member_offset
  H5Tget_member_type

(http://www.hdfgroup.org/HDF5/doc/RM/RM_H5T.html)

···

On Wed, Jun 26, 2013 at 12:22:23PM +0200, Guillaume Jacquenot wrote:

Dear all,

I would like to read the content of an unknown H5T_COMPOUND variable from a
C program.

I would like to retrieve:
- the number of elements
- the type of each elements
- the name of each element

--
Rob Latham
Mathematics and Computer Science Division
Argonne National Lab, IL USA