www.gusucode.com > mbctools 工具箱 matlab 源码程序 > mbctools/@modeldev/Export2CAGE.m

    function [pCAGE,doReplace] = Export2CAGE(mdev,CGP,name,doReplace,doReplaceVars,pInputs,ExtraInfo,DoConstraints)
%Export2CAGE Export model to CAGE.
%
% Throws an error in the event of failure.  Return value is always true
%
% Export2CAGE(mdev,CGP);
% Export2CAGE(mdev,CGP,name);
% Export2CAGE(mdev,CGP,name,replace,doUpdateVars,pInputs,ExtraInfo);
%  mdev        : modeldev node 
%  CGP         : CAGE project (pointer to cgproject or file name)
%  name        : Name of model node to create.  If a model with this name
%                exists in the CAGE project it can be replaced (depending
%                on the value of the next parameter).  However, if
%                a node of any other type exists with this name, or if the
%                existing model node has the wrong number of inputs, and error
%                will be thrown.
%  replace     : true if any existing model of the same name should be replaced.
%                The default is false, in which case an error is thrown if a
%                model of the same name already exists.
%  doReplaceVars: update variable ranges in CAGE
%  pInputs     : supplied list of inputs to CAGE model. These inputs are
%                only used if a new model is created
%  ExtraInfo   : Cell array of additional information to attach to the
%                exportmodel.  Each cell should contain a structure with
%                fields Title and Description.
%  DoConstraints: include boundary model
%

%  Copyright 2000-2011 The MathWorks, Inc. and Ford Global Technologies, Inc.



if nargin<8 
    DoConstraints = true;
end
if nargin<7 
    ExtraInfo = {};
end
if nargin<6
    pInputs = [];
end
if nargin<5
    doReplaceVars=false;
end


m = getBestExportModel(mdev);

if isempty(m)
    error(message('mbc:modeldev:UnknownError'));
end

% Add additional export info to the model
if ~isempty(ExtraInfo)
    stInfo = getinfo(m);
    stInfo.new = [stInfo.new, ExtraInfo];
    m = setinfo(m, stInfo);
end
if ~DoConstraints
    m = setconstraints(m,[]);
end

if ~isempty(pInputs)
    pInputs = iSelectInputs(m,pInputs);
end

% export done by cgproject method
[pCAGE,doReplace] = ImportMBCModel(info(CGP),m,name,doReplace,doReplaceVars,pInputs);


function pInputs = iSelectInputs(m,pInputs)
% pInputs can be supplied by the test plan for all inputs

nf = nfactors(m);
if nf<length(pInputs)
   if isa(model(m),'localmod')
       pInputs = pInputs(1:nf);
   else
       pInputs = pInputs(end-nf+1:end);
   end       
end