function [stat,post] = blktf(path,prop,bstr,bint,bflt,parent,name,catalog,ws,node,sbSample)
%BLKTF Defines a system specified in transfer function form.
%
% See also BLKSS, BLKZP, BLKDF.

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

   stat = 0;			   		   % Error flag
   nInputs = bint(5);
   nOutputs = bint(6);
   %
   % Add mux and demux blocks if necessary
   %
   [post,rect] = blkio('port',nInputs,nOutputs,prop,path);
   %
   % Get the transfer function coefficients as well as the initial output values
   %
   indStr = bint(17)+1;
   indInt = bint(15)+1;
   npar = 3;
   symInd = zeros(1,npar);				   % Block parameter flags
   str = cell(npar+1,1);
   str{4} = mat2char(nInputs);
   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)
      y0 = zeros(nOutputs,1);
      if (nCoeffs ~= 0)
	 indFlt = bint(16);
	 cRange = 1:nCoeffs;
	 y0(cRange) = bflt(indFlt+cRange);
      end
      str{npar} = mat2char(y0);
   end
   indInt = bint(18)+1;
   indInt = bint(indInt)+indInt;		   % Skip icon data
   indFlt = bint(19);
   rDims = [1;nOutputs];
   cDims = [bint(indInt)+1;(bint(indInt+1)+1)*nInputs];
   ub = cumsum(rDims.*cDims);
   lb = [0;ub(1:end-1)]+1;
   for (k = find(~symInd(1:npar-1)))
      coeffs = zeros(rDims(k),cDims(k));
      cRange = lb(k):ub(k);
      coeffs(:) = bflt(indFlt+cRange);
      str{k} = mat2char(coeffs);
   end
   %
   % Transfer function block (can be continuous or discrete)
   %
   if (any(sbSample))
      bh = add_block('libsb2sl/DYN/DNumDenCoeffs',path,...
		     'ForegroundColor',prop.fgColor,...
		     'BackgroundColor',prop.bgColor,...
		     'Orientation',prop.orientation,...
		     'DropShadow',prop.border,...
		     'Position',rect,...
		     'NU',str{4},...
		     'NUM',str{2},...
		     'DEN',str{1},...
		     'Y0',str{3},...
		     'TS',mat2char(sbSample));
   else
      bh = add_block('libsb2sl/DYN/CNumDenCoeffs',path,...
		     'ForegroundColor',prop.fgColor,...
		     'BackgroundColor',prop.bgColor,...
		     'Orientation',prop.orientation,...
		     'DropShadow',prop.border,...
		     'Position',rect,...
		     'NU',str{4},...
		     'NUM',str{2},...
		     'DEN',str{1},...
		     'Y0',str{3});
   end
   %
   % Connect the current transfer function block with the mux and demux blocks
   %
   blkio('line',nInputs,nOutputs,post,parent,name);
   return					   % Last card of BLKTF
