[feedgnuplot] 05/10: Simplified data parsing.

Dima Kogan dima at secretsauce.net
Wed Feb 5 22:05:24 UTC 2014


This is an automated email from the git hooks/post-receive script.

dkogan-guest pushed a commit to branch debian
in repository feedgnuplot.

commit 4163e24956a012d3578ea3a1ca090f9841339499
Author: Dima Kogan <dima at secretsauce.net>
Date:   Wed Feb 5 02:52:02 2014 -0800

    Simplified data parsing.
    
    Instead of complicated regexes, I now simply do splits and joins. This paves the
    way for per-curve extraValuesPerPoint
---
 bin/feedgnuplot | 71 +++++++++++++++++++++++++++++++++++----------------------
 1 file changed, 44 insertions(+), 27 deletions(-)

diff --git a/bin/feedgnuplot b/bin/feedgnuplot
index 601c145..ac2288e 100755
--- a/bin/feedgnuplot
+++ b/bin/feedgnuplot
@@ -347,8 +347,6 @@ sub interpretCommandline
 
     my $Nfields = scalar split( ' ', $options{timefmt});
     $options{timefmt_Ncols} = $Nfields;
-    my $regex_str = join( '\s+', ('\S+') x $Nfields );
-    $options{timefmt_regex} = qr/$regex_str/;
 
     # make sure --xlen is an integer. With a timefmt xlen goes through strptime
     # and strftime, and those are integer-only
@@ -573,16 +571,6 @@ sub mainThread
 
     setCurveAsHistogram( $_ ) foreach (@{$options{histogram}});
 
-    # regexp for a possibly floating point, possibly scientific notation number
-    my $numRE   = '-?\d*\.?\d+(?:[Ee][-+]?\d+)?';
-    my $domainRE = $options{timefmt_regex} || $numRE;
-
-
-    # a point may be preceded by an id
-    my $pointRE = $options{dataid} ? '(\S+)\s+' : '()';
-    $pointRE .= '(' . join('\s+', ($numRE) x $valuesPerPoint) . ')';
-    $pointRE = qr/$pointRE/;
-
 # set all the axis ranges
     # If a bound isn't given I want to set it to the empty string, so I can communicate it simply to
     # gnuplot
@@ -651,18 +639,37 @@ sub mainThread
         # line is used)
         # 3d plots require $options{domain}, and dictate "x y" for the domain instead of just "x"
 
+        my @fields = split;
+
         if($options{domain})
         {
-          /($domainRE)/go or next;
-          $domain[0] = $1;
-          $domain0_numeric = makeDomainNumeric( $domain[0] );
+          if( $options{timefmt} )
+          {
+              # no point if doing anything unless I have at least the domain and
+              # 1 piece of data
+              next if @fields < $options{timefmt_Ncols}+1;
 
-          if($options{'3d'})
+              $domain[0] = join (' ', splice( @fields, 0, $options{timefmt_Ncols}) );
+              $domain0_numeric = makeDomainNumeric( $domain[0] );
+          }
+          elsif(!$options{'3d'})
+          {
+              # no point if doing anything unless I have at least the domain and
+              # 1 piece of data
+              next if @fields < 1+1;
+
+              $domain[0] = $domain0_numeric = shift @fields;
+          }
+          else
           {
-            /($numRE)/go or next;
-            $domain[1] = $1;
+              # no point if doing anything unless I have at least the domain and
+              # 1 piece of data
+              next if @fields < 2+1;
+
+              @domain = splice(@fields, 0, 2);
           }
-          elsif( $options{monotonic} )
+
+          if( $options{monotonic} )
           {
             if( defined $latestX && $domain0_numeric < $latestX )
             {
@@ -676,7 +683,6 @@ sub mainThread
             else
             { $latestX = $domain0_numeric; }
           }
-
         }
         else
         {
@@ -684,8 +690,7 @@ sub mainThread
           # $. on the data queue in that case
           if(defined $dataQueue)
           {
-            s/ ([\d]+)$//o;
-            $domain[0] = $1;
+            $domain[0] = pop @fields;
           }
           else
           {
@@ -695,13 +700,25 @@ sub mainThread
         }
 
         my $id = -1;
-        while (/$pointRE/go)
+
+        while(@fields)
         {
-          if($1 ne '') {$id = $1;}
-          else         {$id++;   }
+            if($options{dataid})
+            {
+                last if @fields < 1 + $valuesPerPoint;
+                $id = shift @fields;
+            }
+            else
+            {
+                last if @fields < $valuesPerPoint;
+                $id++;
+            }
 
-          pushPoint(getCurve($id),
-                    "@domain $2\n", $domain0_numeric);
+            pushPoint(getCurve($id),
+                      join(' ',
+                           @domain,
+                           splice( @fields, 0, $valuesPerPoint ) ) . "\n",
+                      $domain0_numeric);
         }
       }
     }

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/feedgnuplot.git



More information about the debian-science-commits mailing list