% FROMDATA
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% FUNCTION:    fromData
%
% DESCRIPTION: Construct a statistical test with the give data
%
% CALL:        st = fromData(a, pl)
%
% PARAMETER:   pl   - plist
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function st = fromData(st, pli)
  
  VERSION = '$Id: fromData.m,v 1.1 2010/12/20 12:50:15 hewitson Exp $';
  
  % get smodel info
  ii = stattest.getInfo('stattest', 'From Data');
  
  % Set the method version string in the minfo object
  ii.setMversion([VERSION '-->' ii.mversion]);
  
  % Combine input plist with default values
  pl = combine(pli, ii.plists);
  
  % Set fields
  indata  = pl.find('data');
  if ~iscell(indata)
    data = {};
    for kk = 1:numel(indata)
      data = [data {indata(kk)}];
    end
  end
  
  % Check the contents of data
  for kk=1:numel(data)
    if ~isa(data{kk}, 'ltpda_uoh')
      error('### Statistical tests need data in the form of LTPDA user objects. Cell entry %d is a %s', kk, class(data{kk}));
    end
  end
  
  % Set the data
  st.data = data;
  
  % Add history
  st.addHistory(ii, pl, [], []);
  
  % Set other properties
  warning('off', utils.const.warnings.METHOD_NOT_FOUND);
  % remove parameters we already used
  pl_set = copy(pl,1);
  if pl_set.isparam('data')
    pl_set.remove('data');
  end
  st.setProperties(pl_set);
  warning('on', utils.const.warnings.METHOD_NOT_FOUND);
  
end
