%
%function array = read3dfloats(fname)
%
%	Reads the array of values of type float from a file.
%	The first 3 values of the file are short (16-bit) integers
%	that specify x, y and z size of the array.  The remaining
%	values in the file are 32-bit floats.


function array = read3dfloats(fname)


fid = fopen(fname,'r','b');
s = fread(fid,3,'int16');
[array,n] = fread(fid,s(1)*s(2)*s(3),'float');
fclose(fid);

if (n < prod(s))
	tt = sprintf('Unexpected end of file after %d of %d expected values.',n,prod(s));
	disp(tt);
	disp('Filling array with zeros');
	array(prod(s))=0;
end;

array = reshape(array,[s(:)]');



