From: <sch...@pr...> - 2004-02-01 18:42:46
|
Update of /cvsroot/octave/octave-forge/main/strings In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17850 Modified Files: str2double.m Log Message: performance improvement - replace strtok by Index: str2double.m =================================================================== RCS file: /cvsroot/octave/octave-forge/main/strings/str2double.m,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- str2double.m 25 Jan 2004 14:56:31 -0000 1.3 +++ str2double.m 1 Feb 2004 18:40:52 -0000 1.4 @@ -50,8 +50,10 @@ ## along with this program; if not, write to the Free Software ## Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -## Copyright (C) 2004 by Alois Schloegl -## a.s...@ie... +## $Revision$ +## $Id$ +## Copyright (C) 2004 by Alois Schloegl <a.s...@ie...> + %%valid_char='0123456789eE+-.nNaAiIfF'; % digits, sign, exponent,NaN,Inf @@ -67,40 +69,58 @@ status = 0; strarray = {}; - k1 = 0; % current row + k1 = 1; % current row + k2 = 0; % current row + k3 = 0; % current cell nc = 0; % number of columns - while ~isempty(s), - [u,s] = strtok(s,rdelim); %% get next row - if ~isempty(u), - k1 = k1 + 1; - end; - k2 = 0; - while ~isempty(u), - [t,u] = strtok(u,cdelim); %% get next token - if ~isempty(t), - k2 = k2 + 1; - if k2 > nc, %% add column if neccessary - nc = k2; - end; - strarray{k1,k2} = t; + + s(length(s)+1)=rdelim(1); + sl = length(s); + ix = 1; + while any(s(ix)==[rdelim,cdelim]) & (ix < sl), + ix = ix + 1; + end; + ta = ix; + while ix <= sl; + if any(s(ix)==[cdelim,rdelim]), + te = ix - 1; + k2 = k2 + 1; + k3 = k3 + 1; + strarray{k1,k2} = s(ta:te); + %strarray{k1,k2} = [ta,te]; + + sw = 0; + while any(s(ix)==[cdelim,rdelim]) & (ix < sl), + sw = sw | any(s(ix)==rdelim); + ix = ix + 1; end; - end; + + if sw, + k2 = 0; + k1 = k1 + 1; + end; + ta = ix; + end; + ix = ix + 1; end; - else error('invalid input argument'); end; - + [nr,nc]= size(strarray); status = zeros(nr,nc); num = repmat(NaN,nr,nc); -for k1=1:nr, -for k2=1:nc, +for k1 = 1:nr, +for k2 = 1:nc, t = strarray{k1,k2}; - epos=find((t=='e') | (t=='E')); %% positon of E - if (length(epos)>1), %% if more than one E is found + epos = find((t=='e') | (t=='E')); %% positon of E + if (length(t)==0), %% if more than one E is found status(k1,k2) = -1; %% return error code + num(k1,k2) = NaN; + elseif (length(epos)>1), %% if more than one E is found + status(k1,k2) = -1; %% return error code + num(k1,k2) = NaN; else if length(epos)==0, %% no E found e = 0; |