You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: loadGrainSet_hdf5.m
    path of file: ./repos/mtex/interfaces
    
    the code of the file until where you have to start completion: function grains = loadGrainSet_hdf5(fname)

%% Read EBSD
ebsd = loadEBSD_hdf5(fname);

%% Read comment
comment = h5readatt(fname, '/grains', 'comment');

%% Read matrices
A_D = loadSparse(fname, '/grains/a_d');
I_DG = loadSparse(fname, '/grains/i_dg');
A_G = loadSparse(fname, '/grains/a_g');
I_FDext = loadSparse(fname, '/grains/i_fdext');

    
function grains = loadGrainSet_hdf5(fname)

%% Read EBSD
ebsd = loadEBSD_hdf5(fname);

%% Read comment
comment = h5readatt(fname, '/grains', 'comment');

%% Read matrices
A_D = loadSparse(fname, '/grains/a_d');
I_DG = loadSparse(fname, '/grains/i_dg');
A_G = loadSparse(fname, '/grains/a_g');
I_FDext = loadSparse(fname, '/grains/i_fdext');
I_FDsub = loadSparse(fname, '/grains/i_fdsub');
F = loadSparse(fname, '/grains/f');
x_V = loadSparse(fname, '/grains/v');

%% Read phase
phase = h5read(fname, '/grains/phase');

%% Read rotations
as = h5read(fname, '/ebsd/rotations/a');
bs = h5read(fname, '/ebsd/rotations/b');
cs = h5read(fname, '/ebsd/rotations/c');
ds = h5read(fname, '/ebsd/rotations/d');

meanRotation = rotation(quaternion(as, bs, cs, ds));

%% Read options
info = h5info(fname, '/grains/options/');
options = struct();
for i = 1:numel(info.Datasets)
  name = info.Datasets(i).Name;
  location = ['/grains/options/', name];
  data = h5read(fname, location);
  options.(name) = data;
end