Mercurial > hg > aimmat
view aim-mat/tools/ReadIEEE2.m @ 0:74dedb26614d
Initial checkin of AIM-MAT version 1.5 (6.4.2011).
author | tomwalters |
---|---|
date | Fri, 20 May 2011 12:32:31 +0100 |
parents | |
children | 20ada0af3d7d |
line wrap: on
line source
% support file for 'aim-mat' % % This external file is included as part of the 'aim-mat' distribution package % http://www.pdn.cam.ac.uk/cnbh/aim2006 % $Date: 2008-06-10 18:00:16 +0100 (Tue, 10 Jun 2008) $ % $Revision: 585 $ %%%%%%%%%%%%%%%%%%%%%%%%%%% % % File: ReadIEEE.m % Purpose: Reads an IEEE float from a file. % Comments: The calculation is for big-endian format, so little-endian must % be converted to big-endian format. % Author: L. P. O'Mard % Revised by: % Created: % Updated: % Copyright: (c) 2000, University of Essex % %%%%%%%%%%%%%%%%%%%%%%%%%%% function value = ReadIEEE(fid, littleEndian); if littleEndian == 0 swapBytes = 0; else swapBytes = 1; end; bytes = ReadBytes(fid, 10, swapBytes); expon = bitand(bytes(1), 127) * 2^8 + bytes(2); hiMant = bytes(3) * 2^24 + bytes(4) * 2^16 + bytes(5) * 2^8 + bytes(6); loMant = bytes(7) * 2^24 + bytes(8) * 2^16 + bytes(9) * 2^8 + bytes(10); expon = expon - 16383; value = hiMant * 2^(expon - 31); expon = expon - 31; value = value + (loMant * 2^(expon - 32)); if bitand(bytes(1), 128) ~= 0 value = -value; end;