function handle=openmodel(m,handle,visible)
%OPENMODEL opens a Simulink model

%   Copyright (c) 1997-2000 by The MathWorks, Inc.
%   $Revision: 1.3 $  $Date: 2000/03/23 19:38:27 $

if nargin<3
   visible=logical(0);
end


if isempty(find_system('SearchDepth',0,...
      'Name',handle)) & ~isempty(handle)
   try
      evalin('base',LocLoadStr(handle,visible));
   catch
      try
         evalin('base',LocLoadStr(handle,visible));
         handle='simulink';
      catch
         handle='';
      end
   end
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function lStr=LocLoadStr(mdlName,visible)

if visible
   lStr=['open_system(''' mdlName ''');'];
else
   lStr=[mdlName '('''','''','''',''load'');'];
end
