www.gusucode.com > mbcview 工具箱matlab源码程序 > mbcview/@cgsurfview/@app/calculate.m

    function data = calculate(obj,nodeptr)
%CALCULATE  Calculates output for one node at a time.
%
%  This function calls the evaluation function in the node.

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


datasel=obj.hDataSel.selection;
datasetnames = obj.hDataSel.datasets;

outputlist=nodeptr.getoutputs;
vars=obj.hInputList.variables;

% Create the data object
data = cgsurfview.svdata(nodeptr.locationname,numel(datasel));

% Set the value of all inputs to those listed in the input list.
% If evaluategrid failed earlier, the values of the inputs may have
% been changed behind the scenes.
obj.hInputList.syncValues;

% Remove any inputs on which this node does not depend
inputs = nodeptr.getinputs;
[ignore,varindices] = intersect(vars,inputs); % the first output parameter is sorted, annoyingly
% sorting "varindices" is the same as keeping the elements of "vars"
% in their current order.
vars = vars(sort(varindices));

setVariables(data,vars);

for k=1:numel(datasel)
    if datasel(k)>0
        % find the evaluation function
        func=outputlist{datasel(k),2};
        % do the evaluation
        try
            result = feval(func,nodeptr.info, vars);
            msg = [];
        catch ME
            result = [];
            msg = ME.message;
        end

        % if it has failed by returning empty, or a matrix with too few dimensions, give up now.
        if isempty(result) 
            setErrorMessage(data,['Calculation failed: ' msg]);
            return
        elseif ischar(result)
            setErrorMessage(data,result);
            return
        else
            setValues(data,k,result,datasetnames{datasel(k)});
        end
    end
end

setConstraintOptions(data,obj.hDataSel.checkstates);
if any(obj.hDataSel.checkstates~=0)
    % we should calculate constraints
    func = nodeptr.getconstraintfcn;
    if ~isempty(func)
        try
            setConstraints(data,feval(func,nodeptr.info, vars));
        catch
            disp(['Failed to calculate constraints for node ' nodeptr.locationname]);
        end
    end
end