'Read and return header for variable'

def read_header(self):

    data = read_dtype(self.mat_stream, self.dtypes['header'])
    name = self.mat_stream.read(int(data['namlen'])).strip('\x00')
    if ((data['mopt'] < 0) or (data['mopt'] > 5000)):
        raise ValueError('Mat    4    mopt    wrong    format,    byteswapping    problem?')
    (M, rest) = divmod(data['mopt'], 1000)
    if (M not in (0, 1)):
        warnings.warn(("We    do    not    support    byte    ordering    '%s';    returned    data    may    be    corrupt" % order_codes[M]), UserWarning)
    (O, rest) = divmod(rest, 100)
    if (O != 0):
        raise ValueError('O    in    MOPT    integer    should    be    0,    wrong    format?')
    (P, rest) = divmod(rest, 10)
    T = rest
    dims = (data['mrows'], data['ncols'])
    is_complex = (data['imagf'] == 1)
    dtype = self.dtypes[P]
    return VarHeader4(name, dtype, T, dims, is_complex)
