function varargout=loadmat(file,varargin)
% loadmat - hygienic loading from mat files
%
% The point of this function is to load certain named variables
% from a Mat file without polluting the current environment with
% other objects from the Mat file or having name clashes.
%
% loadmat :: text ~'filename', text~'variable name' -> object~'something'.
% loadmat :: 
%    text          ~'filename', 
%    {[N]->text}   ~'list of variable names' 
% -> {[N]->object} ~'list of things'.
%
% Vararg form (not well typed)
%
% [X,Y,Z,...]=loadmat(Filename,var1,var2,var,...);

load(file);   
for j=1:length(varargin)
	var=varargin{j};
	if iscell(var), 
		X__=cell(1,length(var));
		for k=1:length(var)
			eval(sprintf('X__{%d}=%s;',k,var{k}));
		end
		varargout{j}=X__;
	else 
		eval(['varargout{j}=' var ';']);
	end
end
		
