[Scipy-tickets] [SciPy] #1173: mio4: guess_byte_order results in '>' while actual order is 'little'

SciPy Trac scipy-tickets@scipy....
Mon May 10 17:17:02 CDT 2010

#1173: mio4: guess_byte_order results in '>' while actual order is 'little'
 Reporter:  yarikoptic  |       Owner:  somebody
     Type:  defect      |      Status:  new     
 Priority:  normal      |   Milestone:  0.8.0   
Component:  Other       |     Version:  0.7.0   
 Keywords:              |  
 Please don't hit me hard if I am mistaken, but I think the logic is
 incorrect in guess_byte_order:

 While troubleshooting
 I've ran into a situation that .mat file which had little-endian byte
 order, was opened as big-endian (I guess), so completely screwed up and I
 had to explicitly state that byte_order='little' to proceed further.

 Then I looked into actual code in mio4.py which was used to see:

     def guess_byte_order(self):
         mopt = self.read_dtype(np.dtype('i4'))
         if mopt < 0 or mopt > 5000:
             return SYS_LITTLE_ENDIAN and '>' or '<'
         return SYS_LITTLE_ENDIAN and '<' or '>'

 which seems to depend on the fact that number stored is not 0, so it could
 swap little/big thing depending on that.  BUT I had "0"s in first 4 bytes,
 system was 'BIG' so it guess I ended up with '>' (i.e. big endian).  So I
 asked on what that value is actually could be, found description of mat
 file format: http://maxwell.me.gu.edu.au/spl/matlab-
 page/matfile_format.pdf (see page 32), which says that value 0 is actually
 for little endian!  So file is correct but logic above assigns 'big
 endian' to it, which screws things up later on.

Ticket URL: <http://projects.scipy.org/scipy/ticket/1173>
SciPy <http://www.scipy.org>
SciPy is open-source software for mathematics, science, and engineering.

More information about the Scipy-tickets mailing list