% DOS/MSwindows simple floating point image file reader:
% J. Tumblin 12/8/97
%
% Expects a file format that:
%	-begins with 2 16-bit integers: xsize,ysize
%	-followed immediately with a 2D array of pixels; each
%	 pixel is a set of three 32-bit floats in R,G,B order.
% Returns an 3D array of size [xsize,ysize,3]
%
% CAREFUL! MSDOS/WINDOWS files use byte ordering that is REVERSED 
% 	from the UNIX point of view;
%  	Usual complaint is '
%
%	??? Error using ==> zeros
%	Product of dimensions is greater than maximum integer.
%
%=====================================
function out = layfileread(filename);
%=====================================
%
	pFile = fopen(filename,'r');	% open for read;
	[siz,cnt] = fread(pFile,2,'uint16');	% get xsize,ysize;
	img_strt = ftell(pFile);	% note where file begins,
	if(max(siz)>=4097)
		echo on;
		errjt = 'xsize,ysize too large-is the file byte-swapped?';
		errjt			% report error
		out = siz;
		siz			% report size
		echo off;
		return;
		end;
	out1 = zeros([siz',3]);		% make an empty array 
					% (siz' pixels & 3 samples/pixel)
	out1(:,:,1) = fread(pFile,siz','float32',8); % fill it from file: 
	fseek(pFile,img_strt,'bof');	% rewind,
	fread(pFile,1,'float32');	% (skip X value; go to Y;
	out1(:,:,2) = fread(pFile,siz','float32',8); % fill Y values;
	fseek(pFile,img_strt,'bof');	% rewind,
	fread(pFile,2,'float32');	% go to Z;
	out1(:,:,3) = fread(pFile,siz','float32',8);	% read Z values.
	fclose(pFile);
	out = zeros(siz(2),siz(1),3);	% make rotated output file;
	tmp = rot90(out1(:,:,1));	% right side up!
	out(:,:,1) = flipud(tmp);
	tmp = rot90(out1(:,:,2));
	out(:,:,2) = flipud(tmp);
	tmp = rot90(out1(:,:,3));
	out(:,:,3) = flipud(tmp);
