% input:
% filename: String
% pathname: String

% Output:
% verargout: cell array
% filename: String

% Description
% Helper method to open a stateflow file

function [varargout,filename] = sfopen_config(filename, pathname)

if isempty(filename)
    [filename, pathname] = uigetfile('*.mdl');
end;

if filename,
    [~,filename,ext] = fileparts(filename);
    
    if ~strcmp(ext,'.mdl') && ~strcmp(ext, '.slx')
       errordlg(sprintf('Cannot open a model without .mdl or .slx extension: %s%s',filename,ext),'Stateflow');
       filename = '';
    end
    
    if (~isempty(filename)), 
    	sf('Version');
    	pwDir = pwd;
    	cd(pathname);
    	open_system(filename); 
    	cd(pwDir);
    	if nargout>0
    		varargout{1} = get_param(filename,'handle');
    	end
    elseif nargout>0
    		varargout{1} = -1;
    end;
elseif nargout>0
		varargout{1} = -1;
end;
