Groups | Search | Server Info | Login | Register


Groups > comp.lang.awk > #151

Re: gnuplot algorithm help

From Janis Papanagnou <janis_papanagnou@hotmail.com>
Newsgroups comp.lang.awk
Subject Re: gnuplot algorithm help
Date 2011-04-11 10:30 +0200
Organization Aioe.org NNTP Server
Message-ID <inue7l$oa7$1@speranza.aioe.org> (permalink)
References <4da27014$0$669$c3e8da3$b280bf18@news.astraweb.com>

Show all headers | View raw


Am 11.04.2011 05:05, schrieb Mike Rhodes:
> Hello fellow AWKers,
>
> I'm trying to use output from nfdump to plot total throughput in gnuplot
> but I am having trouble coming up with the correct algorithm.
>
> Given a datafile organized this way...
>
> # START_TIME   MBPS     DUR
> 1302350771.016 0.003040 1.752
> 1302350788.681 0.047432 4.548
> 1302350792.845 0.032472 1.120
> 1302350792.901 0.021536 0.172
> 1302350793.217 0.023680 0.420
> 1302350800.717 0.025024 0.492
> 1302350814.777 0.001248 0.000
> 1302350814.781 0.001248 0.020
> 1302350823.701 0.019568 0.228
> 1302350830.432 0.000832 0.096
>
> ...I'm trying to keep a running total of Mbps when two times overlap. In
> other words, when $1 is less than any previous $1+$3 then $2 should be
> added to the $2 of all of the the records with the larger $1+$3.

IIUC, here's one way (without introducing getline)...

/^#/ { next }
$1 < s { f2 += $2 }
s && $1 >= s { print f1, f2, f3 }
{ f1 = $1; f2 = $2; f3 = $3; s = $1 + $3 }
END { print f1, f2, f3 }


>
> Here's what I've come up with so far:
>
> {
>      print
>      longest = $1 + $3
>      tput = $2
>      getline

This getline interfers with normal builtin looping.

>      while ($1<  longest) {
>          tput += $2
>          print $1, tput, $3
>          getline
>      }
>      print
> }

What you seem to be trying to do is re-implementing awk's builtin
looping. You probably wanted to do something like

BEGIN { ...
    while (getline...) {
       ...
       while (...) {
         getline...
       ...
       }
    }
    ...
}

But I suggest to not use getline.

>
> The obvious flaw here is that two lines are printed in a row without any
> tests being applied when the while loop is broken. I've been unable to
> come up with an algorithm that allows me to do the comparison I need but
> doesn't swallow any output via unprinted getlines. I know that getline
> is considered an "advanced" function, but I'm hoping someone here has
> enough experience with it to help me on this.

Getline is not an advanced function, it's a standard function that
has some caveats to consider. What you probably need is not someone
who has experience with getline. Just try to use awk's normal looping
and save intermediate results as necessary.

Janis

>
> Thank you,
> Mike

Back to comp.lang.awk | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

gnuplot algorithm help Mike Rhodes <M8R-1cd059@mailinator.com> - 2011-04-10 23:05 -0400
  Re: gnuplot algorithm help Janis Papanagnou <janis_papanagnou@hotmail.com> - 2011-04-11 10:30 +0200
    Re: gnuplot algorithm help Janis Papanagnou <janis_papanagnou@hotmail.com> - 2011-04-11 12:06 +0200
    Re: gnuplot algorithm help Mike Rhodes <M8R-1cd059@mailinator.com> - 2011-04-11 06:11 -0400
      Re: gnuplot algorithm help Janis Papanagnou <janis_papanagnou@hotmail.com> - 2011-04-11 14:40 +0200
        Re: gnuplot algorithm help Mike Rhodes <M8R-1cd059@mailinator.com> - 2011-04-11 12:29 -0400
          Re: gnuplot algorithm help Janis Papanagnou <janis_papanagnou@hotmail.com> - 2011-04-11 19:51 +0200
            Re: gnuplot algorithm help Mike Rhodes <M8R-1cd059@mailinator.com> - 2011-04-11 19:42 -0400

csiph-web