view m-toolbox/classes/+utils/@models/mainFnc.m @ 43:bc767aaa99a8

CVS Update
author Daniele Nicolodi <nicolodi@science.unitn.it>
date Tue, 06 Dec 2011 11:09:25 +0100
parents f0afece42f48
children
line wrap: on
line source

% MAINFNC is the main function call for all built-in models.
% 
% CALL:
%     varargout = mainFnc(inputs, modelFilename, getModelDescription, getModelDocumentation, getVersion, versionTable)
% 
% A typical call from the built-in model main function will look like:
% 
%   varargout = utils.models.mainFnc(varargin(:), ...
%     mfilename, ...
%     @getModelDescription, ...
%     @getModelDocumentation, ...
%     @getVersion, ...
%     @versionTable);
% 
% INPUTS:
%                 inputs - cell-array of inputs to the built-in model
%          modelFilename - the full filename of the model (typically you use mfilename)
%    getModelDescription - a function handle to the getModelDescription function
%  getModelDocumentation - a function handle to the getModelDocumentation function
%             getVersion - a function handle to the getVersion function
%           versionTable - a function handle to the versionTable function
% 
% VERSION: $Id: mainFnc.m,v 1.4 2011/12/02 09:03:20 hewitson Exp $
% 
% 
function varargout = mainFnc(inputs, modelFilename, getModelDescription, getModelDocumentation, getVersion, versionTable)
  
  % Process inputs
  [info, pl, constructorInfo, fcn] = utils.models.processModelInputs(inputs, ...
    modelFilename, ...
    getModelDescription, ...
    getModelDocumentation, ...
    getVersion, ...
    versionTable);
  
  if ~isempty(info)
    varargout{1} = {info};
    return;
  end
  
  % Build the object
  out = fcn(pl);
  
  % Set the method version string in the minfo object
  if ~isempty(constructorInfo) && utils.helper.isSubclassOf(class(out), 'ltpda_uoh')
    % If this is a user-call via a constructor, then we add history
    out = addHistoryStep(out, constructorInfo, pl);
  end
  
  if nargout > 0
    varargout{1} = {out, pl};
  else
    error('!!! Invalid number of output')
  end
  
end