www.gusucode.com > mbctools 工具箱 matlab 源码程序 > mbctools/@sweepsetfilter/loadobj.m
function obj = loadobj(obj) %LOADOBJ Load filter for sweepsetfilter objects and version control % % SSF = LOADOBJ(SSF) is called by LOAD when a sweepsetfilter object is % loaded from a .MAT file. The main role of this file is to upgrade old % versions of the object to the latest version. % % See also LOAD, SWEEPSETFILTER/SAVEOBJ. % Copyright 2000-2014 The MathWorks, Inc. and Ford Global Technologies, Inc. % Enter current version number of object CurrentVersion = 6; % Check that the object has a version number that we know about if ~any( obj.version == 1:CurrentVersion ) warning(message('mbc:sweepsetfilter:InvalidVersion', sprintf( '%3.1f', obj.version ))); % Need to return since a call to class on an invalid object would be bad return end % Update from old version to current version (as required) if obj.version<2 obj = i_V1toV2(obj); end if obj.version<3 obj = i_V2toV3(obj); end if obj.version<4 obj = i_V3toV4( obj ); end if obj.version<5 obj = i_V4toV5( obj ); end if obj.version<6 obj.displayLayout = []; obj.version = 6; for i=1:length(obj.sweepFilters) f = obj.sweepFilters(i).filterResult; if ~isempty(f) && (~iscell(f) || numel(f)~=2) % change to two element sweep filters result store obj.sweepFilters(i).filterResult = {[],f}; end end end % Might need to recreate the actual object class if isstruct(obj) % Ensure that the fieldnames are in the correct order obj = i_sortFields(obj); % Recreate the class obj = sweepsetfilter(obj); end % -------------------------------------------------------------------- % Convert version 1 sweepsetfilters to version 2 % -------------------------------------------------------------------- function obj = i_V1toV2(obj) obj.version = 2; % Rename sweepsetToAppend to variableSweepset obj.variableSweepset = obj.sweepsetToAppend; obj = rmfield(obj, 'sweepsetToAppend'); % Cacheing info - to be used in the future? obj.cachedSweepset = sweepset; obj.allowsCacheing = false; % Structure to hold changes to underlying data obj.modifiedData = i_sortFields(struct('dataValues', sparse(0,0),... 'dataPosition', sparse(false(0)),... 'rowGuid', guidarray,... 'columnName', {{}},... 'validRows', 0,... 'validCols', 0,... 'fullPosition', sparse(0,0))); % Filter on guid and sweep obj.filterGuid = guidarray; obj.sweepFilters = i_sortFields(struct('filterExp',{},'result',{}, ... 'inlineExp',{},'filterResult',{},'OK',{})); % Ensure that filters and variables have inline expression fields if isempty(obj.filters) obj.filters = struct('filterExp',{},'result',{},'inlineExp',{}, ... 'filterResult',{},'OK',{}); else % Generate the filter result logical array - for compatibility this is % scalar expanded to false filterResult = false; for i = 1:length(obj.filters) % Add the mbcinline object to the internal storage obj.filters(i).inlineExp = vectorize(mbcinline(obj.filters(i).filterExp)); obj.filters(i).filterResult = filterResult; obj.filters(i).OK = ~strncmp('Error', obj.filters(i).result, 5); end end % Sort the filters array obj.filters = i_sortFields(obj.filters); if isempty(obj.variables) obj.variables = struct('varName',{},'varExp',{},'varUnit',{}, ... 'varString',{},'result',{},'inlineExp',{},'OK',{}); else for i = 1:length(obj.variables) obj.variables(i).inlineExp = vectorize(mbcinline(obj.variables(i).varExp)); obj.variables(i).varUnit = ''; obj.variables(i).OK = ~strncmp('Error', obj.variables(i).result, 5); end end % Sort the variables array obj.variables = i_sortFields(obj.variables); % Add sweep note structure obj.sweepNotes = i_sortFields(struct('noteExp',{},'noteString',{},'lAppliesTo',{}, ... 'isMultiNote',{},'result',{},'OK',{},'inlineExp',{})); % Add the data message service field obj.dataMessageService = []; % Ensure that defineTests contains the testnumAlias field and old % reordering is flagged for maintaining compatibility if ~isempty(obj.defineTests) if ~isfield(obj.defineTests, 'testnumAlias') obj.defineTests.testnumAlias = 0; end if obj.defineTests.reorder obj.defineTests.reorder = 'OldReorder-ThisFieldShouldBeLogical'; end % Convert previous zero tolerance settings to eps. This will make % sure that, for example, LOGNO will continue to group sweeps % correctly. obj.defineTests.tolerance(obj.defineTests.tolerance==0) = eps; end % -------------------------------------------------------------------- % Convert version 2 sweepsetfilters to version 3 % -------------------------------------------------------------------- function obj = i_V2toV3(obj) obj.version = 3; % Need to add the note color to the note structure if ~isfield(obj.sweepNotes, 'noteColor') if isempty(obj.sweepNotes) obj.sweepNotes = struct('OK',{},'inlineExp',{},'isMultiNote',{}, ... 'lAppliesTo',{},'noteColor',{},'noteExp',{},'noteString',{},'result',{}); else for i = 1:length(obj.sweepNotes) obj.sweepNotes(i).noteColor = [1 0 0]; end % Sort the sweep notes structure obj.sweepNotes = i_sortFields(obj.sweepNotes); end end % -------------------------------------------------------------------- % Convert version 3 sweepsetfilters to version 4 % -------------------------------------------------------------------- function obj = i_V3toV4(obj) obj.version = 4; % Need to add userdata fields to variables, filters, sweep filters etc. % Do variables obj.filters = iAddFieldToSortedStruct(obj.filters, 'userdata'); obj.variables = iAddFieldToSortedStruct(obj.variables, 'userdata'); obj.sweepFilters = iAddFieldToSortedStruct(obj.sweepFilters, 'userdata'); obj.sweepNotes = iAddFieldToSortedStruct(obj.sweepNotes, 'userdata'); % Add the new sweepVariables, sweepVariableSweepset and resampling fields obj.sweepVariables = struct('OK',{},'inlineExp',{},'result',{},'userdata',{}, ... 'varExp',{},'varName',{},'varString',{},'varUnit',{}); obj.sweepVariableSweepset = sweepset; obj.resampling = struct( 'OK', true, 'resampleExp', {{}}, 'resampledSweepset', [], ... 'result', '', 'userdata', [], 'varNames', {{}} ); % Finally ensure that the fields are in alphabetic order obj = i_sortFields(obj); % -------------------------------------------------------------------- % Convert version 3 sweepsetfilters to version 4 % -------------------------------------------------------------------- function obj = i_V4toV5( obj ) obj.version = 5; % Upgrade flags to a uint64. This method guarantees that the flag bits % will be preserved: casting might preserve value but not bit pattern. flgs = bitget(obj.allowsFlag, 1:52); FlagVar = uint64(0); for n = find(flgs) FlagVar = bitset(FlagVar,n,1); end obj.allowsFlag = FlagVar; % ------------------------------------------------------------------------- function obj = i_sortFields(obj) % Convert the structure to a cell array cells = struct2cell(obj); % Sort the fieldnames [sortedFieldnames, i] = sort(fieldnames(obj)); % Recreate the structure in the correct order obj = cell2struct(cells(i,:,:), sortedFieldnames); % ------------------------------------------------------------------------- function s = iAddFieldToSortedStruct(s, newFieldname) if numel(s) == 0 % Add the new fieldname to the list of existing ones - sorted cFieldNames = sort([fieldnames(s); {newFieldname}]); % Reshape to an n x 0 x 0 to produce a 0 x 0 structure data = reshape(struct2cell(s), length(cFieldNames), 0, 0); % Recreate the structure s = cell2struct(data, cFieldNames); else % Any data in the structure this fills the new field with [] [s.(newFieldname)] = deal([]); % And sort s = i_sortFields(s); end