// Scilab 4+ Implementation of BinaryMatrixFile
function data = binRead(fileName)

	arch64 = part(sprintf("%li",2^32),[1]) <> '-';

	fhand = mopen(fileName,"rb");

	if arch64;
		a = mget(2,"ib",fhand);
	else;
		a = mget(2,"lb",fhand);
	end;

	rows = a(1);
	cols = a(2);
//	printf("reported: %i x %i, ",rows,cols);
	
	if exists("brows");
		rows = brows;
	else
		if rows < 0;
			mseek(0,fhand,'end');
			fsiz = mtell(fhand);
			mseek(8,fhand,'set');
			rows = int(fsiz / (cols * 8));	
		end;
//		printf("%i x %i used.\n",rows,cols);
	end	
	
	data = mget(rows*cols,"db",fhand);
	mclose(fhand);
	dlen = size(data,2);
	if dlen < rows*cols;
		printf("file says %i x %i but only got %i, using only ",rows,cols,dlen);
		rows = dlen / cols;
		printf("%i rows.\n",rows);
	end;
	data = matrix(data,cols,rows)';	
endfunction
