annotate aim-mat/tools/ReadIEEE2.m @ 4:537f939baef0 tip

various bug fixes and changed copyright message
author Stefan Bleeck <bleeck@gmail.com>
date Tue, 16 Aug 2011 14:37:17 +0100
parents 20ada0af3d7d
children
rev   line source
tomwalters@0 1 % support file for 'aim-mat'
tomwalters@0 2 %
tomwalters@0 3 % This external file is included as part of the 'aim-mat' distribution package
bleeck@3 4 % (c) 2011, University of Southampton
bleeck@3 5 % Maintained by Stefan Bleeck (bleeck@gmail.com)
bleeck@3 6 % download of current version is on the soundsoftware site:
bleeck@3 7 % http://code.soundsoftware.ac.uk/projects/aimmat
bleeck@3 8 % documentation and everything is on http://www.acousticscale.org
tomwalters@0 9
tomwalters@0 10 %%%%%%%%%%%%%%%%%%%%%%%%%%%
tomwalters@0 11 %
tomwalters@0 12 % File: ReadIEEE.m
tomwalters@0 13 % Purpose: Reads an IEEE float from a file.
tomwalters@0 14 % Comments: The calculation is for big-endian format, so little-endian must
tomwalters@0 15 % be converted to big-endian format.
tomwalters@0 16 % Author: L. P. O'Mard
tomwalters@0 17 % Revised by:
tomwalters@0 18 % Created:
tomwalters@0 19 % Updated:
tomwalters@0 20 % Copyright: (c) 2000, University of Essex
tomwalters@0 21 %
tomwalters@0 22 %%%%%%%%%%%%%%%%%%%%%%%%%%%
tomwalters@0 23
tomwalters@0 24 function value = ReadIEEE(fid, littleEndian);
tomwalters@0 25
tomwalters@0 26 if littleEndian == 0
tomwalters@0 27 swapBytes = 0;
tomwalters@0 28 else
tomwalters@0 29 swapBytes = 1;
tomwalters@0 30 end;
tomwalters@0 31 bytes = ReadBytes(fid, 10, swapBytes);
tomwalters@0 32
tomwalters@0 33 expon = bitand(bytes(1), 127) * 2^8 + bytes(2);
tomwalters@0 34 hiMant = bytes(3) * 2^24 + bytes(4) * 2^16 + bytes(5) * 2^8 + bytes(6);
tomwalters@0 35 loMant = bytes(7) * 2^24 + bytes(8) * 2^16 + bytes(9) * 2^8 + bytes(10);
tomwalters@0 36 expon = expon - 16383;
tomwalters@0 37 value = hiMant * 2^(expon - 31);
tomwalters@0 38 expon = expon - 31;
tomwalters@0 39 value = value + (loMant * 2^(expon - 32));
tomwalters@0 40
tomwalters@0 41 if bitand(bytes(1), 128) ~= 0
tomwalters@0 42 value = -value;
tomwalters@0 43 end;