% FROMXYFCN Construct an ao from a function f(x) string
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% FUNCTION:    fromXYfcn
%
% DESCRIPTION: Construct an ao from a function f(x) string
%
% CALL:        a = fromXYfcn(pl)
%
% PARAMETER:   pl: Parameter list object
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function a = fromXYFcn(a, pli)
  
  VERSION = '$Id: fromXYFcn.m,v 1.9 2011/08/16 06:06:17 hewitson Exp $';
  
  % get AO info
  ii = ao.getInfo('ao', 'From XY Function');
  
  % Set the method version string in the minfo object
  ii.setMversion([VERSION '-->' ii.mversion]);
  
  % Add default values
  pl = applyDefaults(ii.plists, pli);
  pl.getSetRandState();
  
  % Get parameters
  fcn = find(pl, 'xyfcn');
  x   = find(pl, 'X');
  
  % Make data
  ts = xydata(x,eval([fcn ';']));
  
  % Make an analysis object
  a.data = ts;
  
  % Add history
  a.addHistory(ii, pl, [], []);
  
  % Set xunits
  a.setXunits(pl.find('xunits'));
  
  % Set yunits
  a.setYunits(pl.find('yunits'));
  
  % Set object properties from the plist
  a.setObjectProperties(pl);
  
end


