function [f,msg] = todtf(tfstruct,varargin)
%TODTF   Convert a DFILT object to a DTF object.

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

error(nargchk(2,3,nargin));

msg = '';

% Create a dummy dtf object to check that tfstruct is a valid string
errormsg = 'Invalid structure specified.';

try,
    dummy = feval(tfstruct); % This creates a default filter of the given structure
    if ~isa(dummy,'dtf'),
        msg = errormsg;
        return
    end
catch
    msg = errormsg;
    return
end

h = varargin{1};

% Make h a single-section dfilt if the conversion is wanted for a particular section
if nargin == 3,
    h = section(h,varargin{2});
end

for n = 1:nsections(h),
    [num{n},den{n}] = tf(section(h,n));
    newsection{n} = {num{n},den{n}};
end

connect = connection(h);

f = feval(tfstruct,newsection,connect);

