Dereferencing variable-length object references using Java API


#1

As the title says, how do I correctly dereference a variable-length object reference? Specifically, I would like to dereference the “DIMENSION_LIST” attribute data shown below.

I’m using the HDF Java API.

Dataset (printed using h5dump):

GROUP "moment_confidence_intervals" {
DATASET "c" {
 DATATYPE  H5T_IEEE_F64LE
 DATASPACE  SIMPLE { ( 2, 2 ) / ( 2, 2 ) }
 DATA {
 (0,0): -0.0814753, 0.263157,
 (1,0): 0.242424, 0.50541
 }
 ATTRIBUTE "DIMENSION_LIST" {
	DATATYPE  H5T_VLEN { H5T_REFERENCE { H5T_STD_REF_OBJECT }}
	DATASPACE  SIMPLE { ( 2 ) / ( 2 ) }
	DATA {
	(0): (DATASET 22096 /_scales/methods/sampling/execution:1/increment:1/moment_confidence_intervals/c/bounds ),
	(1): (DATASET 22640 /_scales/methods/sampling/execution:1/increment:1/moment_confidence_intervals/c/moments )
	}
 }
}
DATASET "f" {
 DATATYPE  H5T_IEEE_F64LE
 DATASPACE  SIMPLE { ( 2, 2 ) / ( 2, 2 ) }
 DATA {
 (0,0): 1.23183, 0.292459,
 (1,0): 1.59179, 0.561687
 }
 ATTRIBUTE "DIMENSION_LIST" {
	DATATYPE  H5T_VLEN { H5T_REFERENCE { H5T_STD_REF_OBJECT }}
	DATASPACE  SIMPLE { ( 2 ) / ( 2 ) }
	DATA {
	(0): (DATASET 19952 /_scales/methods/sampling/execution:1/increment:1/moment_confidence_intervals/f/bounds ),
	(1): (DATASET 20496 /_scales/methods/sampling/execution:1/increment:1/moment_confidence_intervals/f/moments )
	}
 }
}

Java Code:

if(theDataObject instanceof Dataset) {
    Dataset ds = (Dataset) theDataObject;
    long dataset_id = ds.open();
    if(ds.hasAttribute()) {
        List<?> metadata = ds.getMetadata();
        for(Object metadatum : metadata) {
            if(metadatum instanceof Attribute) {
                Attribute attr = (Attribute) metadatum;
                long attribute_id = attr.open();
                if(attr.getName().equals("DIMENSION_LIST") && attr.getData() instanceof String[]) {
                    String[] dset_data = new String[2];
                    H5.H5AreadVL(attribute_id, HDF5Constants.H5T_STD_REF_OBJ, dset_data);

                    // dereference the first of the two references	                					
                    long object_id   = H5.H5Rdereference(dataset_id, HDF5Constants.H5P_DEFAULT, HDF5Constants.H5R_OBJECT, dset_data[0].getBytes());
                    long object_type = H5.H5Rget_obj_type(dataset_id, HDF5Constants.H5R_OBJECT, dset_data[0].getBytes());
                }
            }
        }
    }
}

I was initially following the example at H5ObjectEx_T_ObjectReferenceAttribute.java, but it uses H5.H5Aread, whereas I think I need to use H5.H5AreadVL (as far as I can tell), which takes a different parameter list.

The code shown above throws an exception on the call to H5AreadVL, with an error of “java.lang.InternalError: H5AreadVL_asstr: failed to read data”