'get variables from stream as dictionary
variable_names   - optional list of variable names to get
If variable_names is None, then get all variables in file'

def get_variables(self, variable_names=None):

    if isinstance(variable_names, string_types):
        variable_names = [variable_names]
    elif (variable_names is not None):
        variable_names = list(variable_names)
    self.mat_stream.seek(0)
    self.initialize_read()
    mdict = self.read_file_header()
    mdict['__globals__'] = []
    while (not self.end_of_stream()):
        (hdr, next_position) = self.read_var_header()
        name = asstr(hdr.name)
        if (name in mdict):
            warnings.warn(('Duplicate    variable    name    "%s"    in    stream    -    replacing    previous    with    new\nConsider    mio5.varmats_from_mat    to    split    file    into    single    variable    files' % name), MatReadWarning, stacklevel=2)
        if (name == ''):
            name = '__function_workspace__'
            process = False
        else:
            process = True
        if ((variable_names is not None) and (name not in variable_names)):
            self.mat_stream.seek(next_position)
            continue
        try:
            res = self.read_var_array(hdr, process)
        except MatReadError as err:
            warnings.warn(('Unreadable    variable    "%s",    because    "%s"' % (name, err)), Warning, stacklevel=2)
            res = ('Read    error:    %s' % err)
        self.mat_stream.seek(next_position)
        mdict[name] = res
        if hdr.is_global:
            mdict['__globals__'].append(name)
        if (variable_names is not None):
            variable_names.remove(name)
            if (len(variable_names) == 0):
                break
    return mdict
