By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,908 Members | 1,850 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,908 IT Pros & Developers. It's quick & easy.

Reading IEEE 754 format strings directly into a floating point array

P: n/a
I am querying an instrument in a measurement application.

The values are returned as IEEE format binary floating point numbers. There
are 4 bytes per point. Multiple points are not separated by any delimiter.

Is it possible to read these directly into a floating point array of the
size of the string ?

Alternatively, I could write a routine to do it, but wanted to find out if
there was a simpler solution.
Oct 15 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Madhusudan Singh wrote:
I am querying an instrument in a measurement application.

The values are returned as IEEE format binary floating point numbers. There
are 4 bytes per point. Multiple points are not separated by any delimiter.

Is it possible to read these directly into a floating point array of the
size of the string ?

Alternatively, I could write a routine to do it, but wanted to find out if
there was a simpler solution.


http://docs.python.org/lib/module-array.html
http://numeric.scipy.org

--
Robert Kern
rk***@ucsd.edu

"In the fields of hell where the grass grows high
Are the graves of dreams allowed to die."
-- Richard Harter

Oct 15 '05 #2

P: n/a
Madhusudan Singh wrote:
The values are returned as IEEE format binary floating point numbers. There
are 4 bytes per point. Multiple points are not separated by any delimiter.
Is it possible to read these directly into a floating point array of the
size of the string ?


Consider using the struct module from the standard library, with format
"f". It also allows you to specify endianness in a platform-independent
manner, and for mixed formats, supports standard and native alignment.

http://docs.python.org/lib/module-struct.html

You have a string of length 4*n, so make a format with (for example)
">"+"f"*n, and struct.unpack will return a tuple of length n.

For large volumes of data, the array module may be more useful (as
someone else has already noted).

--
Ben Caradoc-Davies <be*@wintersun.org>
http://wintersun.org/
"Those who deny freedom to others deserve it not for themselves."
- Abraham Lincoln
Oct 15 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.