Esempio n. 1
0
 def guess_byte_order(self):
     self.mat_stream.seek(0)
     mopt = read_dtype(self.mat_stream, np.dtype('i4'))
     self.mat_stream.seek(0)
     if mopt < 0 or mopt > 5000:
         return SYS_LITTLE_ENDIAN and '>' or '<'
     return SYS_LITTLE_ENDIAN and '<' or '>'
Esempio n. 2
0
 def guess_byte_order(self):
     self.mat_stream.seek(0)
     mopt = read_dtype(self.mat_stream, np.dtype('i4'))
     self.mat_stream.seek(0)
     if mopt < 0 or mopt > 5000:
         return SYS_LITTLE_ENDIAN and '>' or '<'
     return SYS_LITTLE_ENDIAN and '<' or '>'
Esempio n. 3
0
 def read_header(self):
     ''' Read and return header for variable '''
     data = read_dtype(self.mat_stream, self.dtypes['header'])
     name = self.mat_stream.read(int(data['namlen'])).strip(asbytes('\x00'))
     if data['mopt'] < 0 or data['mopt'] > 5000:
         raise ValueError('Mat 4 mopt wrong format, byteswapping problem?')
     M, rest = divmod(data['mopt'], 1000) # order code
     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) # unused, should be 0
     if O != 0:
         raise ValueError('O in MOPT integer should be 0, wrong format?')
     P, rest = divmod(rest, 10) # data type code e.g miDOUBLE (see above)
     T = rest # matrix type code e.g. mxFULL_CLASS (see above)
     dims = (data['mrows'], data['ncols'])
     is_complex = data['imagf'] == 1
     dtype = self.dtypes[P]
     return VarHeader4(
         name,
         dtype,
         T,
         dims,
         is_complex)
Esempio n. 4
0
 def guess_byte_order(self):
     self.mat_stream.seek(0)
     mopt = read_dtype(self.mat_stream, np.dtype("i4"))
     self.mat_stream.seek(0)
     if mopt < 0 or mopt > 5000:
         return SYS_LITTLE_ENDIAN and ">" or "<"
     return SYS_LITTLE_ENDIAN and "<" or ">"
Esempio n. 5
0
 def read_file_header(self):
     ''' Read in mat 5 file header '''
     hdict = {}
     hdr = read_dtype(self.mat_stream, self.dtypes['file_header'])
     hdict['__header__'] = hdr['description'].item().strip(asbytes(' \t\n\000'))
     v_major = hdr['version'] >> 8
     v_minor = hdr['version'] & 0xFF
     hdict['__version__'] = '%d.%d' % (v_major, v_minor)
     return hdict
Esempio n. 6
0
 def read_file_header(self):
     ''' Read in mat 5 file header '''
     hdict = {}
     hdr = read_dtype(self.mat_stream, self.dtypes['file_header'])
     hdict['__header__'] = hdr['description'].item().strip(' \t\n\000')
     v_major = hdr['version'] >> 8
     v_minor = hdr['version'] & 0xFF
     hdict['__version__'] = '%d.%d' % (v_major, v_minor)
     return hdict
Esempio n. 7
0
 def read_file_header(self):
     """ Read in mat 5 file header """
     hdict = {}
     hdr_dtype = MDTYPES[self.byte_order]["dtypes"]["file_header"]
     hdr = read_dtype(self.mat_stream, hdr_dtype)
     hdict["__header__"] = hdr["description"].item().strip(asbytes(" \t\n\000"))
     v_major = hdr["version"] >> 8
     v_minor = hdr["version"] & 0xFF
     hdict["__version__"] = "%d.%d" % (v_major, v_minor)
     return hdict
Esempio n. 8
0
 def read_file_header(self):
     ''' Read in mat 5 file header '''
     hdict = {}
     hdr_dtype = MDTYPES[self.byte_order]['dtypes']['file_header']
     hdr = read_dtype(self.mat_stream, hdr_dtype)
     hdict['__header__'] = hdr['description'].item().strip(asbytes(' \t\n\000'))
     v_major = hdr['version'] >> 8
     v_minor = hdr['version'] & 0xFF
     hdict['__version__'] = '%d.%d' % (v_major, v_minor)
     return hdict
Esempio n. 9
0
 def guess_byte_order(self):
     self.mat_stream.seek(0)
     mopt = read_dtype(self.mat_stream, np.dtype('i4'))
     self.mat_stream.seek(0)
     if mopt == 0:
         return '<'
     if mopt < 0 or mopt > 5000:
         # Number must have been byteswapped
         return SYS_LITTLE_ENDIAN and '>' or '<'
     # Not byteswapped
     return SYS_LITTLE_ENDIAN and '<' or '>'
Esempio n. 10
0
 def guess_byte_order(self):
     self.mat_stream.seek(0)
     mopt = read_dtype(self.mat_stream, np.dtype('i4'))
     self.mat_stream.seek(0)
     if mopt == 0:
         return '<'
     if mopt < 0 or mopt > 5000:
         # Number must have been byteswapped
         return SYS_LITTLE_ENDIAN and '>' or '<'
     # Not byteswapped
     return SYS_LITTLE_ENDIAN and '<' or '>'
Esempio n. 11
0
 def read_header(self):
     ''' Reads and return header for variable '''
     data = read_dtype(self.mat_stream, self.dtypes['header'])
     name = self.mat_stream.read(int(data['namlen'])).strip(asbytes('\x00'))
     if data['mopt'] < 0 or data['mopt'] > 5000:
         ValueError, 'Mat 4 mopt wrong format, byteswapping problem?'
     M, rest = divmod(data['mopt'], 1000)
     O, rest = divmod(rest, 100)
     P, rest = divmod(rest, 10)
     T = rest
     if O != 0:
         raise ValueError('O in MOPT integer should be 0, wrong format?')
     dims = (data['mrows'], data['ncols'])
     is_complex = data['imagf'] == 1
     dtype = self.dtypes[P]
     return VarHeader4(name, dtype, T, dims, is_complex)
Esempio n. 12
0
 def read_header(self):
     """ Reads and return header for variable """
     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:
         ValueError, "Mat 4 mopt wrong format, byteswapping problem?"
     M, rest = divmod(data["mopt"], 1000)
     O, rest = divmod(rest, 100)
     P, rest = divmod(rest, 10)
     T = rest
     if O != 0:
         raise ValueError, "O in MOPT integer should be 0, wrong format?"
     dims = (data["mrows"], data["ncols"])
     is_complex = data["imagf"] == 1
     dtype = self.dtypes[P]
     return VarHeader4(name, dtype, T, dims, is_complex)
Esempio n. 13
0
 def read_header(self):
     ''' Reads and return header for variable '''
     data = read_dtype(self.mat_stream, self.dtypes['header'])
     name = self.mat_stream.read(int(data['namlen'])).strip(asbytes('\x00'))
     if data['mopt'] < 0 or  data['mopt'] > 5000:
         ValueError, 'Mat 4 mopt wrong format, byteswapping problem?'
     M,rest = divmod(data['mopt'], 1000)
     O,rest = divmod(rest,100)
     P,rest = divmod(rest,10)
     T = rest
     if O != 0:
         raise ValueError('O in MOPT integer should be 0, wrong format?')
     dims = (data['mrows'], data['ncols'])
     is_complex = data['imagf'] == 1
     dtype = self.dtypes[P]
     return VarHeader4(
         name,
         dtype,
         T,
         dims,
         is_complex)