function fhndls = ssdparse
%SSDPARSE  Parser for SSD filter objects.
%   FHNDLS = SSDPARSE 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:23:55 $ 

fhndls = [@ssddefaultfilt,@formcellssd,@checkssd];

%----------------------------------------------------------------------------------
function coeffs = ssddefaultfilt
%SSDDEFAULTFILT  Default filter to use in ssd objects.

% Create a 1/1 filter (same as dtf)
a = [];  b = [];  c = [];  d = 1;
coeffs = {{a,b,c,d}};


%-----------------------------------------------------------------------------------
function [coeffs,msg] = formcellssd(varargin)
%FORMCELLSSD  Form cell array of coefficients of ssd object.

% Dummy initialization
coeffs = {};
msg = '';

if rem(nargin,4),
    msg = 'You must specify A,B,C and D matrices per section.';
    return
end

% Form cell of cells of coefficients: {{A1,B1,C1,D1},{A2,B2,C2,D2},...}
for n = 1:4:nargin, 
    coeffs{fix(n./4)+1} = {varargin{n},varargin{n+1},varargin{n+2},varargin{n+3}};
end

%----------------------------------------------------------------------------------
function [coeffs,msg] = checkssd(coeffs)
%CHECKSSD Check if input argument is a cell with valid a,b,c,d.

[a,b,c,d] = deal(coeffs{:});
coeffchanged = 0; % Flag to indicate whether we have replaced coefficients

[msg,a,b,c,d] = abcdchk(a,b,c,d);
if ~isempty(msg),
    return
end

% SSD objects must be SISO
if size(b,2) > 1 | prod(size(d)) > 1 | size(c,1) > 1,
    msg = 'SSD objects can only have single inputs and outputs.';
    return
end

if isempty(d),
    d = 0;
    coeffchanged = 1;
end  % Default for d is zero

if coeffchanged,
    coeffs = {a,b,c,d};
end

    
