function err = opensb(sbfile,slfile,topblk)
%OPENSB translates ASCII SystemBuild files into SIMULINK.
%
%	OPENSB('SBFILE') opens up the SystemBuild file 'SBFILE' into
%	SIMULINK. If there are several independent subsystems
%	contained in the file then you will be prompted to indicate
%	which one(s) to open.
%
%	OPENSB('SBFILE','SLFILE') directly translates the SystemBuild 
%       file SBFILE into the SIMULINK M-file 'SLFILE.M'. If there are 
%	several independent subsystems contained in the file then you 
%	will be prompted to indicate which one(s) to open.
%
%	OPENSB('SBFILE','SLFILE','SUPERBLOCK') directly translates the
%	the SystemBuild subsystem 'SUPERBLOCK' contained in 'SBFILE' 
%	into the SIMULINK M-file 'SLFILE.M'. If the string 'SLFILE'
%	is given as an empty string, the program will simply open the
%       SIMULINK window instead of save a M-file.
%
%	ERR = OPENSB('SBFILE',...) returns a 1 if the translation produced an
%	error. A zero is returned if the translation was successful.
%
%	You may be prompted to run LOAD SLFILE to load variables into the
%	workspace if there is data saved in the SystemBuild file and/or 
%	in the translation.

%	Wes Wang 12-4-92
%	Copyright (c) 1990-94 by The MathWorks, Inc.
%	$Revision: 1.13 $  $Date: 1994/01/25 21:33:11 $

if ~exist('sb2sl121')
   tmp = version;
   if (tmp(1) < '4')
      error('Translator works on MATLAB v4.0 or higher');
   end
   tmp = computer;
   if (tmp(1:2)=='PC') | (tmp(1:2)=='MA')
      error('Translator is not in your path.');
   else
      xx = path;
      ind_sim = findstr('simulink',xx);
      if isempty(ind_sim)
         error('Must be licensed for SIMULINK to use the function')
      end
      ind_col = find(xx == ':');
      while ind_col(1) < ind_sim(1)
        xx = xx(ind_col(1)+1:length(xx));
        ind_col = find(xx == ':');
        ind_sim = findstr('simulink',xx);
      end;
      xx = [xx(1:ind_sim(1)+8) 'sb2sl'];
      yy = unix(['test -d ' xx]);
      if yy
         error([xx ' does not exist in your path yet'])
      end
      path(xx,path);
   end
end;
if exist('sb2sl121')
  if nargin <=0
    disp('USAGE: opensb SystemBuildFileName')
    return
  end;
  f_sb = exist(sbfile);
  if f_sb <= 0
    error(['Cannot Open File ''' sbfile '''. Please Check Your Filename.'])
    return;
  end;
  if nargout == 0
    if nargin == 1
      eval('readsb(sbfile);')
    elseif nargin == 2
      eval('readsb(sbfile,slfile);')
    elseif nargin == 3
      eval('readsb(sbfile,slfile,topblk);')
    end;
  else
    if nargin == 1
      eval('err=readsb(sbfile);')
    elseif nargin == 2
      eval('err=readsb(sbfile,slfile);')
    elseif nargin == 3
      eval('err=readsb(sbfile,slfile,topblk);')
    end
  end
else
  error('OPENSB function is not available in your computer yet')
end;

%--end opensb.m--

