def loadmat(filename, meta=False):
if isinstance(filename, basestring):<EOL><INDENT>fd = open(filename, '<STR_LIT:rb>')<EOL><DEDENT>else:<EOL><INDENT>fd = filename<EOL><DEDENT>fd.seek(<NUM_LIT>)<EOL>tst_str = fd.read(<NUM_LIT:4>)<EOL>little_endian = (tst_str[<NUM_LIT:2>:<NUM_LIT:4>] == b'<STR_LIT>')<EOL>endian = '<STR_LIT>'<EOL>if (sys.byteorder == '<STR_LIT>' and little_endian) or(sys.byteorder == '<STR_LIT>' and not little_endian):<EOL><INDENT>pass<EOL><DEDENT>elif sys.byteorder == '<STR_LIT>':<EOL><INDENT>endian = '<STR_LIT:>>'<EOL><DEDENT>else:<EOL><INDENT>endian = '<STR_LIT:<>'<EOL><DEDENT>maj_ind = int(little_endian)<EOL>maj_val = ord(tst_str[maj_ind]) if ispy2 else tst_str[maj_ind]<EOL>if maj_val != <NUM_LIT:1>:<EOL><INDENT>raise ParseError('<STR_LIT>')<EOL><DEDENT>mdict = {}<EOL>if meta:<EOL><INDENT>fd.seek(<NUM_LIT:0>)<EOL>mdict['<STR_LIT>'] = read_file_header(fd, endian)<EOL>mdict['<STR_LIT>'] = []<EOL><DEDENT>while not eof(fd):<EOL><INDENT>hdr, next_position, fd_var = read_var_header(fd, endian)<EOL>name = hdr['<STR_LIT:name>']<EOL>if name in mdict:<EOL><INDENT>raise ParseError('<STR_LIT>'<EOL>.format(name))<EOL><DEDENT>mdict[name] = read_var_array(fd_var, endian, hdr)<EOL>if meta and hdr['<STR_LIT>']:<EOL><INDENT>mdict['<STR_LIT>'].append(name)<EOL><DEDENT>fd.seek(next_position)<EOL><DEDENT>fd.close()<EOL>return mdict<EOL>
Load data from MAT-file:

    data = loadmat(filename, meta=False)

    The filename argument is either a string with the filename, or
    a file like object.

    The returned parameter ``data`` is a dict with the variables found
    in the MAT file.

    Call ``loadmat`` with parameter meta=True to include meta data, such
    as file header information and list of globals.

    A ``ParseError`` exception is raised if the MAT-file is corrupt or
    contains a data type that cannot be parsed.