Main Content

Reference (H5R)

HDF5 references

Description

Use the MATLAB® HDF5 reference interface, H5R, to create and access information about references to HDF5 objects.

Functions

H5R.create

Create reference

ref = H5R.create(locID,objname,reftype,spaceID) creates a reference ref of the type specified in reftype pointing to the object specified by objname and locID.

 Details

H5R.dereference

Open object specified by reference

output = H5R.dereference(dsID,reftype,ref) returns an identifier to the object specified by ref in the dataset specified by dsID. This syntax corresponds to the H5Rdereference interface in version 1.8 of the HDF5 C library.

output = H5R.dereference(dsID,plistID,reftype,ref) returns an identifier to the object specified by ref in the dataset specified by dsID and with addition property list plistID. This syntax corresponds to the H5Rdereference interface in version 1.10 of the HDF5 C library.

 Details

H5R.get_name

Name of referenced object

name = H5R.get_name(locID,reftype,ref) returns the name of the object identified by ref of type reftype located in a dataset or group locID.

name = H5R.get_name(locID,reftype,ref,'TextEncoding',encoding) specifies the text encoding to use to interpret the reference name.

 Details

H5R.get_obj_type

Type of referenced object

objtype = H5R.get_obj_type(locID,reftype,ref) returns the type of object that an object reference points to. This syntax corresponds to the H5Rget_obj_type interface in version 1.8 of the HDF5 C library.

 Details

H5R.get_region

Copy of dataspace of specified region

spaceID = H5R.get_region(fileID,reftype,ref) returns a dataspace with the specified region selected. fileID is used to identify the file containing the referenced region and can be any identifier for any object in the file.

Examples

expand all

Create a double-precision dataset and a reference dataset.

fid = H5F.create('myfile.h5');
type1_id = H5T.copy('H5T_NATIVE_DOUBLE');
dims = [10 5];
h5_dims = fliplr(dims);
h5_maxdims = h5_dims;
space1_id = H5S.create_simple(2,h5_dims,h5_maxdims);
dcpl = 'H5P_DEFAULT';
dset1_id = H5D.create(fid,'my_double',type1_id,space1_id,dcpl);
type2_id = 'H5T_STD_REF_OBJ';
space2_id = H5S.create('H5S_SCALAR');
dset2_id = H5D.create(fid,'my_ref',type2_id,space2_id,dcpl);
ref_data = H5R.create(fid,'my_double','H5R_OBJECT',-1);
dxpl = 'H5P_DEFAULT';
H5D.write(dset2_id,'H5ML_DEFAULT','H5S_ALL','H5S_ALL',dxpl,ref_data);
H5D.close(dset1_id);
H5D.close(dset2_id);
H5F.close(fid);

Use the H5R.dereference to return an object identifier using the object reference.

plist = 'H5P_DEFAULT';
space = 'H5S_ALL';
fid = H5F.open('example.h5');
dset_id = H5D.open(fid,'/g3/reference');
ref_data = H5D.read(dset_id,'H5T_STD_REF_OBJ',space,space,plist);
deref_dset_id = H5R.dereference(dset_id,'H5R_OBJECT',ref_data(:,1));
H5D.close(dset_id);
H5D.close(deref_dset_id);
H5F.close(fid);
Introduced before R2006a