⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bvqxinifile.m

📁 toolbox of BVQX, This is the access between BV and matlab. It will help you to analysis data from BV
💻 M
📖 第 1 页 / 共 5 页
字号:
            error( ...
                'BVQXinifile:CallingConvention', ...
                'SetFileHead needs a CHAR head option.' ...
            );
        end

        % set header
        newhead = varargin{3}(:)';
        newhok = find(newhead == '[');
        while ~isempty(newhok)
            newhead = newhead(newhok(1) + 1:end);
            newhok = find(newhead == ']');
            if ~isempty(newhok)
                newhead = newhead(newhok(1) + 1:end);
            end
            newhok = find(newhead == '[');
        end
        bvqxinic(cfid).prefile = newhead;


    % set a complete IniFile structure
    case {'setcomplete'}

        % test complete field
        if nargin < 3 || ...
           ~isstruct(varargin{3}) || ...
            numel(varargin{3}) ~= 1
            error( ...
                'BVQXinifile:CallingConvention', ...
                'SetIniComplete needs a 1x1 STRUCT argument.' ...
            );
        end

        % get shortcut
        cmpl = varargin{3};

        % iterate over sections
        sects = fieldnames(cmpl);
        for sc = 1:numel(sects)
            csection = cmpl.(sects{sc});
            if ~isstruct(csection)
                if ~iscell(csection)
                    csection = struct('Value', csection);
                else
                    csection = struct('Value', {csection});
                end
                cmpl.(sects{sc}) = csection;
                continue;
            elseif numel(csection) ~= 1
                error( ...
                    'BVQXinifile:CallingConvention', ...
                    'Fields in complete struct must be 1x1 structs.' ...
                );
            end

            % if we need to check content, iterate over fields
            if cfile.convert == 0
                sfields = fieldnames(csection);
                for fc = 1:length(sfields)
                    ftest = csection.(sfields{fc});

                    % reject every non-char, illegal chars and bad dim'ed chars
                    if ~ischar(ftest) || ...
                        any(ftest(:) < 32 | ftest(:) > 127) || ...
                       (~isempty(ftest) && ...
                        numel(ftest) ~= size(ftest, 2))
                        error( ...
                            'BVQXinifile:InvalidSetting', ...
                            'Illegal value for %s.%s (no conversion).', ...
                            sects{sc}, ...
                            sfields{fc} ...
                        );
                    end
                end
            end
        end

        % set new contents
        bvqxinic(cfid).icontent = cmpl;


    % set an entire section
    case {'setinisection'}

        % test for section and inisection fields
        if nargin < 4 || ...
           ~ischar(varargin{3}) || ...
            isempty(varargin{3}) || ...
           ~isrealvarname(varargin{3}(:)') || ...
           ~isstruct(varargin{4}) || ...
            numel(varargin{4}) ~= 1
            error( ...
                'BVQXinifile:CallingConvention', ...
                'SetIniSection needs CHAR section and a 1x1 struct.' ...
            );
        end

        % if no conversion iterate over fields
        csection = varargin{4};
        if cfile.convert == 0
            sfields = fieldnames(csection);
            for fc = 1:length(sfields)
                ftest = csection.(sfields{fc});

                % reject every non-char, illegal chars and bad dim'ed chars
                if ~ischar(ftest) || ...
                    any(ftest(:) < 32 | ftest(:) > 127) || ...
                   (~isempty(ftest) && ...
                    numel(ftest) ~= size(ftest, 2))
                    error( ...
                        'BVQXinifile:InvalidSetting', ...
                        'Illegal value for %s.%s (no conversion).', ...
                        varargin{3}(:)', ...
                        sfields{fc} ...
                    );
                end
            end
        end

        % set section in matrix
        bvqxinic(cfid).icontent.(varargin{3}(:)') = csection;


    % add/change an IniFile setting
    case {'setinisetting'}

        % test for section, setting, and value fields
        if nargin < 5 || ...
           ~ischar(varargin{3}) || ...
            isempty(varargin{3}) || ...
           ~isrealvarname(varargin{3}(:)') || ...
           ~ischar(varargin{4}) || ...
            isempty(varargin{4}) || ...
           ~isrealvarname(varargin{4}(:)')
            error( ...
                'BVQXinifile:CallingConvention', ...
                'SetIniSetting needs a CHAR section and setting option.' ...
            );
        end

        % if no conversion, reject invalid content
        fval = varargin{5};
        if cfile.convert == 0 && ...
           (~ischar(fval) || ...
             any(fval(:) < 32 | fval(:) > 127) || ...
             (~isempty(fval) && ...
              numel(fval) ~= size(fval, 2)))
            error( ...
                'BVQXinifile:InvalidSetting', ...
                'Illegal value for %s.%s (no conversion).', ...
                varargin{3}(:)', ...
                varargin{4}(:)' ...
            );
        end

        % add new section first?
        if ~isfield(cfile.icontent, varargin{3}(:)')
            bvqxinic(cfid).icontent.(varargin{3}(:)') = struct;
        end

        % set value
        bvqxinic(cfid).icontent.(varargin{3}(:)').(varargin{4}(:)') = fval;


    % set IniFile's parent object id
    case {'setparent'}

        % test for parent field
        if nargin < 3 || ...
            numel(varargin{3}) > 1 || ...
           ~any(strcmpi(class(varargin{3}), {'double', 'BVQXinifile'}))
            error( ...
                'BVQXinifile:CallingConvention', ...
                'SetParent needs a valid object as parent option.' ...
            );
        end

        % get parent object's ID and locate matrix position
        try
            % try to get requested FileID
            pobj = varargin{3};
            if isa(pobj, 'BVQXinifile') && ...
                numel(pobj) == 1
                pobj = pobj.L;
            elseif isempty(pobj) == 0
                pobj = [];
            end

            % locate ID in matrix
            if ~isempty(pobj)
                pobj = pobj(1);
                pobjid = find(bvqxinif.matrix == pobj);

                % handle disappeared parent
                if numel(pobjid) ~= 1
                    error('INVADID_FILE_ID');
                end
            end
        catch
            error( ...
                'BVQXinifile:InvalidFileID', ...
                'The requested file ID doesn''t exist. Glitch?' ...
            );
        end

        % parent object already set
        if ~isempty(cfile.parent)
            ofid = find(bvqxinif.matrix == cfile.parent(1));

            % unset parent object reference
            bvqxinic(cfid).parent = [];

            % valid File-ID
            if ~isempty(ofid)

                % clear parent's child reference to this
                ifid = hIniFile.L;
                bvqxinic(ofid).children(bvqxinic(ofid).children == ifid) = [];

            % invalid File-ID
            else
                warning( ...
                    'BVQXinifile:InvalidFileID', ...
                    'The former parent object is gone. Glitch?' ...
                );
            end
        end

        % no more parent...
        if isempty(pobj)
            return;
        end

        % self being parent is illegal
        if pobjid == cfid
            error( ...
                'BVQXinifile:InvalidParentID', ...
                'The object can''t be it''s own parent.' ...
            );
        end

        % try to detect loop
        pparents = BVQXinifile(class(struct('L', pobj), 'BVQXinifile'), ...
            'getparents');
        if any(pparents == hIniFile.L)
            error( ...
                'BVQXinifile:InvalidParentID', ...
                'Parent loop detected.' ...
            );
        end

        % set parent references
        bvqxinic(cfid).parent = pobj;
        bvqxinic(pobjid).children(end + 1) = hIniFile.L;


    % set protection scheme
    case {'setprotection'}

        % check for protection field in call
        if nargin < 3 || ...
           ~ischar(varargin{3}) || ...
            numel(varargin{3}) ~= 1 || ...
           ~any('acmn' == varargin{3})
            error( ...
                'BVQXinifile:CallingConvention', ...
                'SetProtection needs a valid 1x1 CHAR protection tag.' ...
            );
        end

        % re-set protection scheme
        bvqxinic(cfid).readwrite = strCmd.protection(1);


    % otherwise log invalid action
    otherwise

        % error or not
        error( ...
            'BVQXinifile:InvalidMethod', ...
            'Method %s unknown.', ...
            action(:)' ...
        );
end


% % % internal functions


function xldispout = i_dispxl(xlname, xlcont, xlind, xllo, xleq, xlconv)
    
    % test what size the struct has (indexing needed)
    xlsize = size(xlcont);
    if all(xlsize == 1)
        
        % start with section name and line feed
        xldispout = ['[' xlname ']' xllo];
        
        % iterate over fieldnames
        xlxl = {};
        xlfields = fieldnames(xlcont);
        for numf = 1:length(xlfields)
            
            % get and check content
            xlvalue = xlcont.(xlfields{numf});
            
            % simple string
            if ischar(xlvalue) && ...
               ~any(xlvalue < 32 | xlvalue > 127) && ...
                ndims(xlvalue) < 3 && ...
                size(xlvalue, 1) < 2
                
                % if conversion activated and [...] or {...}
                if xlconv && ...
                   ~isempty(xlvalue) && ...
                   ((xlvalue(1) == '[' && ...
                     xlvalue(end) == ']') || ...
                    (xlvalue(1) == '{' && ...
                     xlvalue(end) == '}'))
                    xlvalue = any2ascii(xlvalue);
                end
                
                % add to output
                xldispout = [xldispout xlind xlfields{numf} xleq xlvalue xllo];
            
            % complex variable (conv is always at least 1!)
            else
                
                % add structs to list
                if isstruct(xlvalue)
                    xlxl{end + 1} = xlfields{numf};
                    
                    % print cell2struct line
                    xlvalfields = fieldnames(xlvalue);
                    xldispout = [xldispout xlind xlfields{numf} xleq ...
                        sprintf('[cell2struct(cell(%.0f,0,0),%s,1)]', ...
                        length(xlvalfields), any2ascii(xlvalfields)) xllo];
                    continue;
                end
                
                % if 'exact' conversion, treat non-empty, non-integer doubles
                if xlconv == 2 && ...
                   ~isempty(xlvalue) && ...
                    isa(xlvalue, 'double') && ...
                    isreal(xlvalue) && ...
                    any(floor(xlvalue(:)) ~= xlvalue(:))
                    xldispout = [xldispout xlind ...
                        xlfields{numf} xleq any2ascii(xlvalue,'exact') xllo];
                
                % otherwise simply any2ascii
                else
                    xldispout = [xldispout xlind ...
                        xlfields{numf} xleq any2ascii(xlvalue) xllo];
                end
            end
        end
        
        % add substructs to dispout
        for numf = 1:length(xlxl)
            xldispout = [xldispout xllo ...
                i_dispxl([xlname '.' xlxl{numf}], ...
                         xlcont.(xlxl{numf}), xlind, xllo, xleq, xlconv)];
        end
    
    % multi-dim structs
    else
        
        % initialize output
        xldispout = '';
        
        % get number of dims (N-D), number of elements and start with (1,1,...)
        xlmsize = size(xlsize, 2);
        xlpsize = prod(xlsize);
        xlisize = ones(1,xlmsize);
        
        % iterate over struct elements
        for xlpcount = 1:xlpsize
            
            % format indexing string
            xlpindex = strrep(['(' sprintf('%.0f,',xlisize) ')'],',)',')');
            
            % add substruct to dispout
            xldispout = [xldispout xllo ...
                i_dispxl([xlname xlpindex], ...
                         xlcont(xlpcount), xlind, xllo, xleq, xlconv)];
            
            % get new index info
            for uc = xl

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -