tomwalters@0: % support file for 'aim-mat' tomwalters@0: % tomwalters@0: % This external file is included as part of the 'aim-mat' distribution package bleeck@3: % (c) 2011, University of Southampton bleeck@3: % Maintained by Stefan Bleeck (bleeck@gmail.com) bleeck@3: % download of current version is on the soundsoftware site: bleeck@3: % http://code.soundsoftware.ac.uk/projects/aimmat bleeck@3: % documentation and everything is on http://www.acousticscale.org tomwalters@0: tomwalters@0: %%%%%%%%%%%%%%%%%%%%%%%%%%% tomwalters@0: % tomwalters@0: % File: ReadIEEE.m tomwalters@0: % Purpose: Reads an IEEE float from a file. tomwalters@0: % Comments: The calculation is for big-endian format, so little-endian must tomwalters@0: % be converted to big-endian format. tomwalters@0: % Author: L. P. O'Mard tomwalters@0: % Revised by: tomwalters@0: % Created: tomwalters@0: % Updated: tomwalters@0: % Copyright: (c) 2000, University of Essex tomwalters@0: % tomwalters@0: %%%%%%%%%%%%%%%%%%%%%%%%%%% tomwalters@0: tomwalters@0: function value = ReadIEEE(fid, littleEndian); tomwalters@0: tomwalters@0: if littleEndian == 0 tomwalters@0: swapBytes = 0; tomwalters@0: else tomwalters@0: swapBytes = 1; tomwalters@0: end; tomwalters@0: bytes = ReadBytes(fid, 10, swapBytes); tomwalters@0: tomwalters@0: expon = bitand(bytes(1), 127) * 2^8 + bytes(2); tomwalters@0: hiMant = bytes(3) * 2^24 + bytes(4) * 2^16 + bytes(5) * 2^8 + bytes(6); tomwalters@0: loMant = bytes(7) * 2^24 + bytes(8) * 2^16 + bytes(9) * 2^8 + bytes(10); tomwalters@0: expon = expon - 16383; tomwalters@0: value = hiMant * 2^(expon - 31); tomwalters@0: expon = expon - 31; tomwalters@0: value = value + (loMant * 2^(expon - 32)); tomwalters@0: tomwalters@0: if bitand(bytes(1), 128) ~= 0 tomwalters@0: value = -value; tomwalters@0: end;