function fhndls = dtfparse
%DTFPARSE  Parser for DTF filter objects.
%   FHNDLS = DTFPARSE returns a 3 element vector of function handles, 
%   FHNDLS, that point to the three functions required by DFILTPARSE
%   when called form any DFILT constructor.
%
%   For more information on what the 3 functions do, see the help for
%   DFILTPARSE.

%   Author(s): R. Losada
%   Copyright 1988-2000 The MathWorks, Inc.
%   $Revision: 1.3 $  $Date: 2000/06/13 21:22:47 $ 

fhndls = [@dtfdefaultfilt,@formcelldtf,@checkdtf];

%----------------------------------------------------------------------------------
function coeffs = dtfdefaultfilt
%DTFDEFAULTFILT  Default filter to use in dtf objects.

coeffs = {{1,1}};

%-----------------------------------------------------------------------------------
function [coeffs,msg] = formcelldtf(varargin)
%FORMCELLDTF  Form cell array of coefficients of dtf object.

msg = '';

if rem(nargin,2),
    % Odd number of coefficients vectors given, last pair is FIR
    varargin{end+1} = 1;
end

% Form cell of cells of pairs of coefficients: {{B1,A1},{B2,A2},...}
for n = 1:2:length(varargin), % Don't use nargin, varargin may have changed
    coeffs{(n+1)./2} = {varargin{n},varargin{n+1}};
end

%----------------------------------------------------------------------------------
function [c,msg] = checkdtf(c)
%CHECKDTF  Check if input argument is a cell of vectors.

msg = '';
b = c{1};
a = c{2};

if isempty(b),
    b = 0;
end

if isempty(a),
    a = 1;
end

if (prod(size(b)) ~= max(size(b))) | (prod(size(a)) ~= max(size(a))),
    msg = 'Numerators and denominators must be vectors.';
    return
end

b = b(:).'; % Always store polynomial coeffs as a row
a = a(:).'; % Always store polynomial coeffs as a row

c = {b,a};

