www.gusucode.com > mbcdata 工具箱 matlab 源码程序 > mbcdata/@calibrationdata/@minterface/pRead.m
function calibration = pRead(obj, calibration, filename) %PREAD Private method. % PREAD reads a calibration from a MATLAB file. % % See also ROLLBACK, PWRITE. % Copyright 2000-2011 The MathWorks, Inc. narginchk(3,3); nargoutchk(1,1); pm = obj.ProgressManager; pm.reset; % Read calibration from file by running file [pathname, filename, ~] = fileparts(filename); % Change to file directory to ensure it is top of the MATLAB path if ~isempty(pathname) oldDir = cd(pathname); % store former directory else oldDir = pwd; end % Disable warnings oldWarningState = warning('off','all'); % Keep track of whether read was successful fileLoadSuccess = true; % initialize try % Read dataStructure = feval(filename); catch ME % Error fileLoadSuccess = false; end % Clean up operations required regardless of success of read cd(oldDir); warning(oldWarningState); % Rethrow error if read was unsuccessful if ~fileLoadSuccess rethrow(ME); end % Store lengths for convenience nValues = numel(dataStructure.Values); nAxes = numel(dataStructure.Axes); nCurves = numel(dataStructure.Curves); nMaps = numel(dataStructure.Maps); % Process values if nValues > 0 pm.notify(sprintf('Processing %d values', nValues)); value = mbcutils.handleArray(nValues, 1); % preallocate for i = 1:nValues, thisS = dataStructure.Values(i); thisO = feval(thisS.ClassName); setMemento(thisO, thisS); value(i) = thisO; pm.update(i/(nValues+nAxes+nCurves+nMaps)); end % Add to calibration pm.notify(sprintf('Storing %d values', nValues)); calibration.addValue(value); end % Process axes (part 1) if nAxes > 0 pm.notify(sprintf('Processing %d axes', nAxes)); axis = mbcutils.handleArray(nAxes, 1); % preallocate for i = 1:nAxes, thisS = dataStructure.Axes(i); thisO = feval(thisS.ClassName); setMemento(thisO, thisS); axis(i) = thisO; pm.update((i+nValues)/(nValues+nAxes+nCurves+nMaps)); end % Add public axes to calibration axisIdentifier = get(axis, {'Identifier'}); axisIdentifierType = calibration.pGetAxisIdentifierType(axisIdentifier); publicAxis = axis(strcmp(axisIdentifierType,'public')); % only public nPublicAxes = numel(publicAxis); if nPublicAxes > 0 pm.notify(sprintf('Storing %d axes', nPublicAxes)); calibration.addAxis(publicAxis); end end % Process curves if nCurves > 0 pm.notify(sprintf('Processing %d curves', nCurves)); curve = mbcutils.handleArray(nCurves, 1); % preallocate for i = 1:nCurves, thisS = dataStructure.Curves(i); thisO = feval(thisS.ClassName); setMemento(thisO, thisS); curve(i) = thisO; pm.update((i+nValues+nAxes)/(nValues+nAxes+nCurves+nMaps)); end % Add to calibration pm.notify(sprintf('Storing %d curves', nCurves)); calibration.addCurve(curve); end % Process maps if nMaps > 0 pm.notify(sprintf('Processing %d maps', nMaps)); map = mbcutils.handleArray(nMaps, 1); % preallocate for i = 1:nMaps, thisS = dataStructure.Maps(i); thisO = feval(thisS.ClassName); setMemento(thisO, thisS); map(i) = thisO; pm.update((i+nValues+nAxes+nCurves)/(nValues+nAxes+nCurves+nMaps)); end % Add to calibration pm.notify(sprintf('Storing %d maps', nMaps)); calibration.addMap(map); end % Process axes (part 2) if nAxes > 0 % Add private axes to calibration privateAxis = axis(strcmp(axisIdentifierType,'private')); % only private nPrivateAxes = numel(privateAxis); if nPrivateAxes > 0 pm.notify(sprintf('Storing %d axes', nPrivateAxes)); calibration.setAxis(privateAxis); end end pm.update(1); pm.notify('Cleaning up');