function h = convert(h,newstruct)
%CONVERT Convert structure of DFILT object.
%  CONVERT(H,NEWSTRUCT) converts DFILT object H to the structure defined by
%  string NEWSTRUCT.
%
%  Example:
%    h1 = df2t;
%    h2 = convert(h1,'df1');
%  returns h2 as a DF1 object.  This is equivalent to
%    h1 = df2t;
%    h2 = df1(h1);

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

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

if ~isa(h,'dfilt'),
  error('Filter to convert must be a valid DFILT object.');
end

errmsg = ['Second input argument to CONVERT ',...
        'must be a valid DFILT object constructor.']; 

% Create a dummy dfilt object to check that newstruct is a valid string
try,
    dummy = feval(newstruct); % This creates a default filter of the given structure
    if ~isa(dummy,'dfilt'),
        error(errmsg);
    end
catch
    error(errmsg);
end

% Now try to do the conversion
h = feval(newstruct,h);
