view m-toolbox/classes/@ao/fromSModel.m @ 25:79dc7091dbbc database-connection-manager

Update tests
author Daniele Nicolodi <nicolodi@science.unitn.it>
date Mon, 05 Dec 2011 16:20:06 +0100
parents f0afece42f48
children
line wrap: on
line source

% FROMSMODEL Construct a AO from an smodel.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% FUNCTION:    FROMSMODEL Construct a AO from an smodel
%
% DESCRIPTION: FROMSMODEL Construct a AO from an smodel
%
% CALL:        a = fromSModel(a, pl)
%
% PARAMETER:   pl: plist containing 'model'
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function a = fromSModel(a, pli, callerIsMethod)
  
  VERSION = '$Id: fromSModel.m,v 1.9 2011/08/15 06:13:07 hewitson Exp $';
  
  if callerIsMethod
    % do nothing
  else
    % get AO info
    ii = ao.getInfo('ao', 'From Smodel');
    
    % Set the method version string in the minfo object
    ii.setMversion([VERSION '-->' ii.mversion]);
  end
  
  if callerIsMethod
    pl = pli;
  else
    % Combine input plist with default values
    pl = applyDefaults(ii.plists, pli);
  end
  
  pl.getSetRandState();
  
  mdl = find(pl, 'model');
  
  % Build the plist needed for the smodel/eval call 
  pl_eval = plist(...
    'output x', find(pl, 'x'), ...
    'output xunits', find(pl, 'xunits'), ...
    'output type', find(pl, 'type'), ...
    't0', 0 ... 
    );
  
  % Build the object by calling smodel/eval
  a = mdl.eval(pl_eval);
  
  if isempty(pl.find('name'))
    pl.pset('name', sprintf('eval(%s)', mdl.name));
  end
  if isempty(pl.find('description'))
    pl.pset('description', mdl.description);
  end
  
  if callerIsMethod
    % do nothing
  else
    % Add history
    a.addHistory(ii, pl, [], mdl.hist);
  end
  
  % Set object properties from the plist
  a.setObjectProperties(pl);
  
end