From: Vijay Kumar <vijayk@ph...>  20070202 13:13:13

Hi, I want to import binary files generated from C/FORTRAN into matplotlib for plotting. Can this be done using 'load'? Thanks Vijay  View this message in context: http://www.nabble.com/ImportingBinaryfilestf3160763.html#a8766615 Sent from the matplotlib  users mailing list archive at Nabble.com. 
From: Vijay Kumar <vijayk@ph...>  20070202 13:14:51

Hi, I want to import binary files generated from C/FORTRAN into matplotlib for plotting. Can this be done using 'load'? Thanks Vijay  View this message in context: http://www.nabble.com/ImportingBinaryfilestf3160765.html#a8766617 Sent from the matplotlib  users mailing list archive at Nabble.com. 
From: <humufr@ya...>  20070205 16:21:22

Le Friday 02 February 2007 08:14:37 Vijay Kumar, vous avez =E9crit=A0: > Hi, > > I want to import binary files generated from C/FORTRAN into matplotlib for > plotting. > Can this be done using 'load'? > > Thanks > Vijay no load can read only text file. 
From: Kumar Appaiah <akumar@ii...>  20070205 16:28:14

On Fri, Feb 02, 2007 at 05:14:37AM 0800, Vijay Kumar wrote: > > Hi, > > I want to import binary files generated from C/FORTRAN into matplotlib for > plotting. > Can this be done using 'load'? If you are using SciPy, scipy.io has a few functions which may help. scipy.io.fromfile, for example. HTH. Kumar  Kumar Appaiah, 462, Jamuna Hostel, Indian Institute of Technology Madras, Chennai  600 036 
From: Steve Schmerler <elcorto@gm...>  20070205 17:04:54

Kumar Appaiah wrote: > On Fri, Feb 02, 2007 at 05:14:37AM 0800, Vijay Kumar wrote: >> Hi, >> >> I want to import binary files generated from C/FORTRAN into matplotlib for >> plotting. >> Can this be done using 'load'? > > If you are using SciPy, scipy.io has a few functions which may > help. scipy.io.fromfile, for example. > Or, if you have to pay attention to endianess, you could use something like this. import numpy as N def load_binary_data(filename, dtype=float): """ We assume that the data was written with write_binary_data() (little endian). """ f = open(filename, "rb") data = f.read() f.close() _data = N.fromstring(data, dtype) # data has been written by write_binary_data() in little endian if sys.byteorder == 'big': _data = _data.byteswap() return _data def write_binary_data(filename, data, dtype=float): """ Write binary data to a file and make sure it is always in little endian format. """ f = open(filename, "wb") _data = N.asarray(data, dtype) # check byteorder of the system, convert to little endian if needed if sys.byteorder == 'big': _data = _data.byteswap() f.write(_data) f.close() hth  cheers, steve Random number generation is the art of producing pure gibberish as quickly as possible. 
From: Christopher Barker <Chris.B<arker@no...>  20070205 17:31:07

>>> I want to import binary files generated from C/FORTRAN into matplotlib for >>> plotting. if it's just a block of bytes in a standard type from and nd array, you can use numpy.fromfile() If not, then you may have to read through the file in chunks, with various calls to file.read(), to get to the right point, then use numpy.fromfile(). If the data is in records with mixed types, then you'll need to use the struct module to read them, or possibly numpy record arrays and fromfile. Note that FORTRAN "unformatted" records pad the data with 4 bytes before and after (at least with the compiler that produces some recent data I needed). Chris  Christopher Barker, Ph.D. Oceanographer Emergency Response Division NOAA/NOS/OR&R (206) 5266959 voice 7600 Sand Point Way NE (206) 5266329 fax Seattle, WA 98115 (206) 5266317 main reception Chris.Barker@... 
From: Matthew Brett <matthew.brett@gm...>  20070207 12:29:28

Hi, > if it's just a block of bytes in a standard type from and nd array, you > can use numpy.fromfile() I should also say that I have just committed a rewrite of the binary file reading stuff to scipy, so if you have the latest scipy SVN (as of a few minutes ago), you can do something like: from StringIO import StringIO import numpy as N from scipy.io import npfile arr = N.arange(10).reshape(5,2) # write in Fortran order, Big endian, read back in C, system endian my_file = StringIO() npf = npfile(my_file, order='F', endian='>') npf.write_array(arr) npf.rewind() npf.read_array((5,2), arr.dtype) Best, Matthew 
From: Matthew Brett <matthew.brett@gm...>  20070208 17:01:13

Hi, > > I want to import binary files generated from C/FORTRAN into matplotlib for > > plotting. > > Can this be done using 'load'? > > If you are using SciPy, scipy.io has a few functions which may > help. scipy.io.fromfile, for example. Ah  just to be clear, for scipy 0.5.2, scipy.io.fromfile is in fact numpy.fromfile  that was just a goofy import error on my part when writing the matlab file loading routines. For clarity, I think it is best to pull this from the scipy.io namespace for the next release, so please use numpy.fromfile for this. Best, Matthew 