function values = fnval(f,varargin)
%FNVAL Evaluate a function.
%
%   FNVAL(F,X)  or  FNVAL(X,F)  evaluates the function  f  in F at the 
%   points in X . 
%
%   FNVAL(F,X,'l<anything>')  or  FNVAL(X,F,'l<anything>')  takes the 
%   function to be left-continuous.  
%   If the function in F is m-variate and the third argument is actually an
%   m-cell, LEFT say, then, continuity from the left is enforced in the i-th 
%   variable if  LEFT{i}(1) = 'l'.  
%
%   The output is a matrix of size [d*m,n] if the function in F is
%   univariate, d-vector valued and [m,n] = size(X) .
%
%   If the function in F is d-vector valued and m-variate with m>1, then
%
%                         [d,n],         if X is of size [m,n]
%   the output is of size [d,n1,...,nm], if d>1  and X is {X1,...,Xm} 
%                         [n1,...,nm],   if d==1 and X is {X1,...,Xm} 
%
%
%   See also SPVAL, PPUAL, RSVAL, PPVAL.

%   Carl de Boor 23 feb 89
%   cb : 05 nov 94 (extend to tensor products) 29aug96 (add BB-form)
%   cb : 14mar97 (add newton form)
%   cb : 18oct97 (go over to structures, and also handle multidimensional f)
%   cb : 05may98 (standardize the help; accept older version of the forms)
%   cb : 03sep99 (optional third argument passed to spval and ppual)
%   cb : 05sep99 (add r.form and tpform; correct help)
%   cb : 23jun00 (improve the help re left continuity)
%   Copyright 1987-2000 by C. de Boor and The MathWorks, Inc.
%   $Revision: 1.13 $

if ~isstruct(f)
   if isstruct(varargin{1})
      temp = f; f = varargin{1}; varargin{1} = temp;
   else
      f = fn2fm(f);
   end
end

if isstruct(f)
   switch f.form(1)
   case 'B',  ff = 'spval';
   case 'p',  ff = 'ppual';
   case 'r',  ff = 'rsval';
   case 't',  ff = 'tpval';
   otherwise
      error('Unknown function type encountered.')
   end
   values = eval([ff,'(f,varargin{:})']);
else
   if f(1)==15  values=npval(f,varargin{1});
   else  % unknown representation
      error('Unknown function type encountered.')
   end
end
