/core/utils_parsing/SplitSequenceMarkerEntry.m
http://brainstream.googlecode.com/ · MATLAB · 82 lines · 54 code · 0 blank · 28 comment · 11 complexity · 346beb6e6f7a6cdef1fc2e10e5c9da1f MD5 · raw file
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- % The BrainStream software is free but copyrighted software, distributed %
- % under the terms of the GNU General Public Licence as published by %
- % the Free Software Foundation (either version 2, or at your option %
- % any later version). See the file COPYING.txt in the main BrainStream %
- % folder for more details. %
- % %
- % Copyright (C) 2009, Philip van den Broek %
- % Donders Institute for Brain, Cognition and Behaviour %
- % Radboud University Nijmegen, The Netherlands %
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- function [mrkseq,mrks,sqm,to] = SplitSequenceMarkerEntry(s)
- %s={'[mrk1 ?parm1 1?parm2 ;0.05]' , '[mrk2 5?parm3 ?parm4 7?parm5 ;0.099]','[mrk3 *parm6 mrk4 ;0.11]'}
- if ischar(s), s = cellstr(s); end
- [mrksq,rem] = strtok(s,{'[',';',']'});
- to = strtok(rem,{'[',';',']'});
- % find first position of parameter section (right after marker name)
- % '\d*\?' : start with any number (0 or more) and then a question mark
- % '*\S' : start with an asterisk and at least 1 non-space character
- mrks = cell(1,length(mrksq));
- sqmrem = cell(1,length(mrksq));
- sqm = cell(1,length(mrksq));
- for n = 1 : length(mrksq)
- idx=regexp(mrksq{n},{'\d*\?','*\S'});
- idx = sort([idx{:}]);
- if isempty(idx)
- error('wrong marker sequence input detected, missing items');
- end
- mrks{n} = regexp(mrksq{n}(1:idx(1)-1),'\S.*\S','match'); % remove leading and tailing spaces
- sqmrem{n} = mrksq{n}(idx(1):end);
- % (1) to capture the ?-items
- % \d* means: arbitrary number of digits (0 times or more)
- % \? means: one question mark '?'
- % \S* means: arbitrary number of non-whitespace characters (0 times or more)
- % (2) to capture the *-items
- % * means: start with asterisk (*)
- % .* means: arbitrary number of non-white space characters
- % \S means: ends with a non-whitespace character
- sqm{n} = regexp(sqmrem{n},{'\d*\?\S*','*.*\S'},'match');
- sqm{n} = [sqm{n}{:}];
- end
- % Note: If one of the sqm items contains an asterisk-item, it still needs
- % to seperate the name of the end marker (also with allowed spaces in the marker name)
- mrkseq = cell(1,length(sqm));
- for n = 1 : length(sqm)
- mrkseq{n}.parms = [];
- if ~isempty(regexp([sqm{n}{:}],'*','match'))
- % find name, start and end position of *-parameter
- [name,startidx,endidx] = regexp(sqm{n},'*\S*','match','start','end');
- if isempty(isempty(name) || isequal(endidx,length(sqm{n})))
- error('wrong marker sequence input detected, *-parmameter or end marker for *-parameter not found');
- end
- if length(name)~=1 || length(startidx)~=1 || length(endidx)~=1
- error('wrong marker sequence input detected, multiple *-parmameter items found');
- end
- mrkseq{n}.marker = char(mrks{n});
- [unit,timeout] = get_unitvalue(to{n});
- if isempty(timeout), error(['Marker sequence timeout read failure, please check following entry: ' char(s)]); end
- mrkseq{n}.timeout = timeout;
- mrkseq{n}.parms(end+1).name = sqm{n}{1}(startidx{1}+1:endidx{1});
- mrkseq{n}.parms(end).numtocollect= sqm{n}{1}(endidx{1}+1:end);
- % remove leading and trailing spaces
- %mrkseq{n}.parms(end).numtocollect= regexp(mrkseq{n}.parms(end).numtocollect,'\S.*\S','match');
- mrkseq{n}.parms(end).numtocollect= {strtrim(mrkseq{n}.parms(end).numtocollect)};
- else
- mrkseq{n}.parms = repmat(struct('name',[],'numtocollect',[]),1,0);
- for num = 1 : length(sqm{n})
- mrkseq{n}.marker = char(mrks{n});
- [unit,timeout] = get_unitvalue(to{n});
- if isempty(timeout), error(['Marker sequence timeout read failure, please check following entry: ' char(s)]); end
- mrkseq{n}.timeout = timeout;
- parmidx = regexp(sqm{n}{num},'\?'); % get num to collect (ntc)
- mrkseq{n}.parms(end+1).name = sqm{n}{num}(parmidx+1:end);
- ntc = regexp(sqm{n}{num}(1:parmidx-1),'\d*','match'); % get num to collect (ntc)
- if isempty(ntc)
- mrkseq{n}.parms(end).numtocollect = 1;
- else
- mrkseq{n}.parms(end).numtocollect = str2double(char(ntc));
- end
- end
- end
- end