www.gusucode.com > mbcview 工具箱matlab源码程序 > mbcview/@cgtradeoffgui/@mmeditor/load.m

    function [ok, msg] = load(obj, file)
%LOAD Load a point-by-point model tradeoff file
%
%  [OK, MSG] = LOAD(OBJ, FILE) loads information from the specified
%  point-by-point model tradeoff file or from structure.  If the load is
%  successful, OK will be true.  If the load fails, OK will be false and a
%  non-empty message will be returned in MSG.

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


ok = true;
msg = '';

if ischar(file)
    try
        % MAT file contains a structure with GlobalMap and OpPoints
        s = load(file,'-mat');
    catch ME
        ok = false;
        msg = ME.message;
        return
    end
elseif isstruct(file)
    % directly imported from structure with GlobalMap and OpPoints
    s = file;
else
    % invalid format
    s = [];
end


if isfield(s, 'GlobalMap') && isfield(s, 'OpPoints')
    if isfield(s, 'LocalMap')
        % These are older multimodel files  The local maps need to be
        % amalgamated with the global models to form global switch models
        for n = 1:length(s.GlobalMap);
            % get global model info
            G = s.GlobalMap{n};
            xiG = xinfo( model(G) );
            xiG.Names = xiG.Names(end-1:end);
            xiG.Symbols = xiG.Symbols(end-1:end);
            xiG.Units = xiG.Units(end-1:end);
            m = mbcPointByPointModel(s.LocalMap(:,n), s.OpPoints, xiG);
            m = setname(m,getname(G));
            m = setinfo(m,getinfo(G));
            s.GlobalMap{n} = m;
        end
    end    
    if isfield(s,'pModels')
       obj.CageModels = s.pModels; 
    end
else
    % The file does not contain valid multimodel data
    ok = false;
    msg = 'File does not contain point-by-point model tradeoff data.';
    return
end

mdllist =  s.GlobalMap;
obj.FullSwitchModels = mdllist;
SampleModel = mdllist{1};
obj.SampleTakenModel = SampleModel;
obj.SampleRejectedModel = selectModels(SampleModel, []);
obj.IsSiteIncluded = true(size(getSwitchPoints(SampleModel), 1), 1);

% Re-initialise breakpoints and tolerances to the default set from the model
obj.Breakpoints = getOptimalGrid(SampleModel);
obj.Tolerance = getTolerance(SampleModel);

nSwitch = length(getSwitchFactors(SampleModel));
% Reset axis order to match order of switch variables
obj.AxisOrder = 1:nSwitch;

% Generate list of all tables that might be created - one for each model
% and one for each non-switching input
modelnames = cell(size(mdllist));
inputnames = {};
inputranges = zeros(0,2);
for n = 1:length(modelnames)
    mdl = mdllist{n};
    modelnames{n} = getname(mdl);
    [unused, syms] = nfactors(mdl);
    syms = syms(1:end-nSwitch);
    r = range(mdl)';
    inputnames = [inputnames, syms(:)'];
    inputranges = [inputranges; r(1:end-nSwitch, :)];
end

[inputnames, idx] =  unique(inputnames);
obj.TableNames = [modelnames(:)', inputnames];
obj.TableWillBeCreated = true(size(obj.TableNames));

% Save all input names and ranges.  This includes the switching inputs
mdl = mdllist{1};
[unused, names] = nfactors(mdl);
names = names(:)';
r = range(mdl)';
obj.SwitchInputs = names(end-nSwitch+1:end);
obj.InputNames = [inputnames, names(end-nSwitch+1:end)];
obj.InputRanges = [inputranges(idx, :); r(end-nSwitch+1:end, :)];

% Send a general data changed event
obj.send('DataChanged', handle.EventData(obj, 'DataChanged'));