Is it possible to read seismic data or convert IBM float32 to IEEE float 32 in MATLAB 7.8 (R2009a)?

3 views (last 30 days)
I work with seismic data files formated according to the Society of Exploration Geophysicists's standards, equivalent to IBM 360 float 32.
I want to a function in MATLAB that converts IBM float32 format to IEEE float 32 or reads the IBM float 32 from files.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 26 Aug 2009
MATLAB 7.8 (R2009a) does not have a function that converts the IBM float32 format to IEEE float 32 format or reads the IBM float32 from files.
As a workaround, use the MATLAB code below that converts the IBM float32 format to the IEEE float 32 format. This MATLAB code is not officially supported by MathWorks, Inc. Use it as is, or modify it to your specific needs.
------------------- START: ibm2ieee.m -------------------------
function d = ibm2ieee (ibmf)
% Name: ibm2ieee
% Abstract: convert a matrix of IBM/360 32-bit floats
% to IEEE doubles.
%
% IBMF is the matrix of IBM/360 32-bit floats each
% stored as a 32 bit unsigned big-endian integer
% in a MATLAB double.
%
% The format of a IBM/360 32-bit float is:
%
% sign 7-bit exponent 24 bit fraction
% The base is 16. The decimal point is to
% the left of the fraction. The exponent is
% biased by +64.
%
% The basic idea is that you use floating point on
% the various fields.
%
% ieee = sign * 16 ^ (exponent - 64) * fraction / 16 ^ 6
%
% By: Martin Knapp-Cordes
% MathWorks, Inc.
%
% Date(s): Jun 95 - 28, 29
% $Revision: 1.2 $ $Date: 1995/06/29 14:50:03 $
%----------------------------------------------------------------------------
%
if (nargin ~= 1)
error ('Wrong number of arguments.');
elseif (isempty(ibmf))
error ('Argument is an empty matrix');
end
%
aibmf = sprintf('%08x',ibmf);
%
% hexd(1) - 1st hex digit - first bit is sign, next 3 bits high order exponent
% hexd(2) - 2nd hex digit - bits of low order exponent
% hexd(3) - 3rd-8th hex digit - bits of fraction
%
hexd = sscanf(aibmf,'%1x%1x%6x',[3,inf]);
d = (1 - (hexd(1,:) >= 8) .* 2) .* ...
16 .^ ((hexd(1,:) - (hexd(1,:) >= 8) .* 8) .* 16 + hexd(2,:) ...
- 70).* hexd(3,:);
d = reshape(d,size(ibmf));
------------------------ END : ibm2ieee.m ----------------------------
Here is an example on how to use the ibm2ieee.m file above.
Assuming you have a file, which contains IBM float 32 format binary data, called 5702.seg, then you must use the following FOPEN and FREAD call to read the file:
fid = fopen('5702.seg','r','b');
%
% Read first data record - IBM/360 32-bit floating format
% Read them as unsigned (32-bit) integers.
% Convert to IEEE doubles using ibm2ieee.
%
% size - number of elements to read
ibm1 = fread(fid,size,'uint');
ieee1 = ibm2ieee(ibm1);

More Answers (0)

Categories

Find more on Programming Utilities in Help Center and File Exchange

Products


Release

R2009a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!