function isrealflag = isreal(f,sec)
%ISREAL  Determine if filter has real coefficients.
%   FLAG = ISREAL(F) determines if the filter object F has 
%   real coefficients and returns 1 if true and 0 if false.
%
%   FLAG = ISREAL(F,I) determines if the I-th section of the
%   filter object F has real coefficients and returns 1 if true
%   and 0 if false.
%
%   See also DFILT/ISSTABLE, DFILT/COEFFICIENTS, DFILT/ORDER.

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

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

if nargin == 2,
    f = section(f,sec);
end

isrealflag = 1; % Initialized assuming real coeffs.
n = 1;

while isrealflag & n <= nsections(f),
    fsec = section(f,n);

    c = coefficients(fsec);
    
    isrealflag = checkifreal(c);
            
    n = n + 1;
end
    
%-----------------------------------------------------------------------------------
function isrealflag = checkifreal(c)

isrealflag = 1; % Initialize at 1

% Extract coefficients from "outer" cell array
coeffs = c{1};

for m = 1:length(coeffs),
    if ~isreal(coeffs{m}),
        isrealflag = 0;
    end
end

