#! /bin/bash

awk 'BEGIN {
   d = 4;
   m = 500;
   a[d,m] = 0.0;
   i = 0;
   k = 0;
   u = l = 0;
}
{  if (NR==1) {
      a[d,0] = $1;
      print "set term wxt dashed";
      print "set title \"Wurst muss hüpfen\" offset 0, 0";
      print "set yrange [0:]";
     #print "set logscale y";
   } else {
      if (u) t=u-1; else t=m-1;
      a[d,u] = 0.9*a[d,t] + 0.1*$1;
   }

   for (b = 0; b < d; b++) a[b,u] = $(b+1);
   u = ++i % m;

   if (k == u) {
      k++;
      l -= m - 2
   } else l = 0;

   k %= m;
   l1 = l;

#   print "set style data linespoints";
#   print "set style fill solid 1.0 border lt -1";
    print "plot \"-\" using 1:2 ls 1 with linespoints title \"icmp\", \"-\" using 1:2 ls 2 with linespoints title \"http\", \"-\" using 1:2 ls 3 with linespoints title \"dns\", \"-\" using 1:2 ls 4 with linespoints title \"nudel\", \"-\" using 1:2 ls 5 with linespoints title \"iir(icmp)\" ";

   for (b = 0; b <= d; b++) {
      j = k;
      l = l1;

      while (j%m != u) {
         printf "%d %f\n",l++,a[b,j%m];
         j++;
      }

      print "e";
      fflush();
   }

}' -
