Page 1 of 1

IBM to IEEE floating point?

Posted: Fri Oct 01, 2010 11:00 pm
by bsmithyman
Hi All,

I have a SEG-Y I/O library that I wrote in Python to do some data processing, but it fails on SEG-Y files that use IBM floating point instead of IEEE. Python's struct.unpack and struct.pack don't support IBM floating point, and I'd rather stay pure Python for simplicity and cross-platform reasons.
SEG-Y on Wikipedia, Another reference

Does anyone have experience with bitwise arithmetic in Python, and particularly how to do this conversion?

Many thanks!

Edit: Still interested in a solution, but I found a way to work around the problem (by converting to a different format outside Python). Thanks for reading.

Re: IBM to IEEE floating point?

Posted: Tue Oct 05, 2010 4:44 am
by lilltroll
IBM exponents are written to the power of 16 instead of 2 as in binary IEEE !?

Check out the examples
http://en.wikipedia.org/wiki/IBM_Floati ... chitecture
vs.
http://en.wikipedia.org/wiki/Single_pre ... int_format

Or double if that's your case.

Python - no idea

Re: IBM to IEEE floating point?

Posted: Tue Oct 05, 2010 7:07 am
by bsmithyman
Yeah, it turned out that Seismic Unix files were really easy to read (a great package if you're looking for free/OS seismic processing tools). Essentially they're the traces from the SEG-Y standard, minus EBCIDIC and binary headers, and pre-converted to nice standardized IEEE floating point. It took about 5 lines of code to adapt my program to be able to read that, so I just sidestepped the whole issue.

The strange thing is that small IBM floating point values, interpreted as IEEE, still *look* a lot like the right values, just off by an order of magnitude or so...