diff m-toolbox/classes/+utils/@models/mainFnc.m @ 0:f0afece42f48

Import.
author Daniele Nicolodi <nicolodi@science.unitn.it>
date Wed, 23 Nov 2011 19:22:13 +0100
parents
children bc767aaa99a8
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/m-toolbox/classes/+utils/@models/mainFnc.m	Wed Nov 23 19:22:13 2011 +0100
@@ -0,0 +1,57 @@
+% 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.3 2011/04/29 14:25:14 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
+  hpl = copy(pl, 1);
+  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, hpl);
+  end
+  
+  if nargout > 0
+    varargout{1} = {out, pl};
+  else
+    error('!!! Invalid number of output')
+  end
+  
+end