function [stat,post] = blkhyst(path,prop,bstr,bint,bflt,parent,name,catalog,ws,node,sbSample)
%BLKHYST This block defines a nonlinear dynamic system that models hysteresis.
%
% See also BLKINTEG, BLKDEADBAND.

% Initial coding by A S Bozin, 6-30-97
% Copyright 1997-2000 The MathWorks, Inc.
% $Revision: 1.6 $ $Date: 2000/06/14 16:09:27 $

   stat = 0;			   		   % Error flag
   nInputs = bint(5);
   nOutputs = bint(6);
   nStates = bint(7);
   %
   % Add mux and demux blocks if necessary
   %
   [post,rect] = blkio('port',nInputs,nOutputs,prop,path);
   %
   % Get the backlash width, slope, initial conditions and cutoff frequency
   %
   indStr = bint(17)+1;
   indInt = bint(15)+1;
   npar = 3;					   % Number of parameters
   symInd = zeros(1,npar);
   str = cell(npar+1,1);
   mode = bint(indInt);
   if (bitand(mode,8))
      ind = mfindstr(bstr,indStr,'|');
      symInd(npar) = 1;
      str{npar} = bstr(indStr:ind-1);
      indStr = ind+1;
   end
   indInt = indInt+1;
   nCoeffs = bint(indInt);
   indInt = indInt+2*nCoeffs+1;
   if (bitand(mode,16))
      iRange = 1:bint(indInt);
      kRange = bint(indInt+iRange);
      symInd(kRange) = 1;
      for (k = kRange)
	 ind = mfindstr(bstr,indStr,'|');
	 str{k} = bstr(indStr:ind-1);
	 indStr = ind+1;
      end
   end
   %
   % Get the block parameter variables
   %
   [symInd,str] = mgetscope(symInd,str,catalog,ws,node);
   if (symInd(npar) == 0)
      x0 = zeros(nStates,1);
      if (nCoeffs ~= 0)
	 indInt = bint(15)+2+nCoeffs;
	 cRange = 1:nCoeffs;
	 indFlt = bint(16);
	 x0(bint(indInt+cRange)) = bflt(indFlt+cRange);
      end
      str{npar} = mat2char(x0);
   end
   indFlt = bint(19)+1;
   str{npar+1} = mat2char(bflt(indFlt));
   indFlt = indFlt+1;
   pLen = zeros(npar-1,1)+nStates;
   ub = cumsum(pLen);
   lb = [0;ub(1:end-1)]+1;
   for (k = find(~symInd(1:npar-1)))
      params = zeros(1,pLen(k));
      bRange = lb(k):ub(k);
      params(:) = bflt(indFlt+bRange);
      if (k == 1)				   % If backlash width parameter
	 str{k} = mat2char(2*params);
      else
	 str{k} = mat2char(params);
      end
   end
   %
   % Hysteresis (backlash) block (can be continuous or discrete)
   %
   if (any(sbSample))
      bh = add_block('libsb2sl/DYN/DBacklash',path,...
		     'ForegroundColor',prop.fgColor,...
		     'BackgroundColor',prop.bgColor,...
		     'Orientation',prop.orientation,...
		     'DropShadow',prop.border,...
		     'Position',rect,...
		     'W',str{1},...
		     'N',str{2},...
		     'X0',str{3},...
		     'TS',mat2char(sbSample));
   else
      bh = add_block('libsb2sl/DYN/CBacklash',path,...
		     'ForegroundColor',prop.fgColor,...
		     'BackgroundColor',prop.bgColor,...
		     'Orientation',prop.orientation,...
		     'DropShadow',prop.border,...
		     'Position',rect,...
		     'W',str{1},...
		     'N',str{2},...
		     'X0',str{3},...
		     'Wc',str{4});
   end
   %
   % Connect the current hysteresis block with the mux and demux blocks
   %
   blkio('line',nInputs,nOutputs,post,parent,name);
   return					   % Last card of BLKHYST
