From: <cde...@us...> - 2012-03-29 15:09:35
|
Revision: 10095 http://octave.svn.sourceforge.net/octave/?rev=10095&view=rev Author: cdemills Date: 2012-03-29 15:09:25 +0000 (Thu, 29 Mar 2012) Log Message: ----------- - If the datefmt contains spaces, then concatenate more than one field. Modified Paths: -------------- trunk/octave-forge/extra/dataframe/inst/@dataframe/dataframe.m Modified: trunk/octave-forge/extra/dataframe/inst/@dataframe/dataframe.m =================================================================== --- trunk/octave-forge/extra/dataframe/inst/@dataframe/dataframe.m 2012-03-29 15:08:03 UTC (rev 10094) +++ trunk/octave-forge/extra/dataframe/inst/@dataframe/dataframe.m 2012-03-29 15:09:25 UTC (rev 10095) @@ -159,6 +159,14 @@ endwhile endif +if (~isempty (datefmt)) + %# replace consecutive spaces by one + datefmt = regexprep (datefmt, '[ ]+', ' '); + datefields = 1 + length (regexp (datefmt, ' ')); +else + datefields = 1; +endif + if (~isempty (seeked) && ~isempty (trigger)) error ('seeked and trigger are mutuallly incompatible arguments'); endif @@ -283,45 +291,62 @@ 'UniformOutput', false); endif - for indk = (1:size (the_line, 2)) + indk = 1; indm = 1; + while (indk <= size (the_line, 2)) if (isempty (the_line{indk}) || any (size (the_line{indk}) > 1)) %#if indi > 1 && indk > 1, disp('line 117 '); keyboard; %#endif if (unquot) try %# remove quotes and leading space(s) - x(indj, indk) = regexp (dummy{indk}, '[^'' ].*[^'']', 'match'){1}; + x(indj, indm) = regexp (dummy{indk}, '[^'' ].*[^'']', 'match'){1}; catch %# if the previous test fails, try a simpler one in = regexp (dummy{indk}, '[^'' ]+', 'match'); if (~isempty (in)) - x(indj, indk) = in{1}; + x(indj, indm) = in{1}; %# else %# x(indj, indk) = []; endif end_try_catch else %# no conversion possible, store and remove leading space(s) - x(indj, indk) = regexp (dummy{indk}, '[^ ].*', 'match'); + x(indj, indm) = regexp (dummy{indk}, '[^ ].*', 'match'); endif elseif (~isempty (regexp (dummy{indk}, '[/:-]')) && ... ~isempty (datefmt)) + %# does it look like a date ? + datetime = dummy{indk}; + + if (datefields > 1) + %# concatenate the required number of fields + indc = 1; + for indc = (2:datefields) + datetime = cstrcat(datetime, ' ', dummy{indk+indc-1}); + endfor + endif + try - datetime = datevec (dummy{indk}, datefmt); + datetime = datevec (datetime, datefmt); timeval = struct ("usec", 0, "sec", floor (datetime (6)), "min", datetime(5), "hour", datetime(4), "mday", datetime(3), "mon", datetime(2)-1, "year", datetime(1)-1900); - timeval.usec = 1e6*(datetime(6)-timeval.sec); - x(indj, indk) = str2num (strftime ([char(37) 's'], timeval)) + ... + timeval.usec = 1e6*(datetime(6) - timeval.sec); + x(indj, indm) = str2num (strftime ([char(37) 's'], timeval)) + ... timeval.usec * 1e-6; + if (datefields > 1) + %# skip fields successfully converted + indk = indk + (datefields - 1); + endif catch %# store it as is - x(indj, indk) = the_line{indk}; + x(indj, indm) = the_line{indk}; end_try_catch else - x(indj, indk) = the_line{indk}; + x(indj, indm) = the_line{indk}; endif - endfor + indk = indk + 1; indm = indm + 1; + endwhile indl = indl + 1; indj = indj + 1; endwhile @@ -336,12 +361,12 @@ endif clear UTF8_BOM fid in lines indl the_line content empty_lines - clear timeval timestr nfields idx + clear datetime timeval idx endif end_try_catch endif - + %# fallback, avoiding a recursive call idx.type = '()'; if (~isa (x, 'char')) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |