4

I have a data file with an undefined number of entries that looks like this:

A B C D E..
1 0 2 5 4
7 4 3 4 1
8   7 4 0
7     1 1

First row represents working time, than pause and so on in alternating fashion. To visualise this, I plot a columnstacked histograms from it by defining two linestyles with different colours and plotting it via:

plot for [i=1:10] 'data.log' using i notitle

But the problem is: I have to guess the max value of i. How can I get the number of columns the data file has? And when defining the alternating linestyles I need to estimate the max number of lines in order to overwrite the default linestyles for what i use a similar for-loop:

set for [j = 1:1000:2] style line i lc rgb "white"
set for [j = 2:1000:2] style line i lc rgb "red"

Here I need to set the max number lines a column in my data has as the max value for j.

Is there a way to grab these values? Possibly by using built-in features of gnuplot only (for I am not familiar with awk scripting).

Thanks for reading, best regards

PS: I'm using Windows

1 Answers1

4

You can determine the number of columns and rows of your datafile like this:

rows = `awk 'END {print NR}' data.log`
columns = `awk '{if(NR == 1) print NF}' data.log`
print "The maximum number of rows is ", rows, " and the maximum number of columns is ", columns
plot for [i=1:columns] 'data.log' using i notitle

You can achieve the same result without using awk with this approach

rows = `cat data.log | wc -l`
columns = `head data.log -n1 | wc -w`
arekolek
  • 9,128
  • 3
  • 58
  • 79
Woltan
  • 13,723
  • 15
  • 78
  • 104
  • 1
    Thanks, updated the post. Is there a solution without awk scripting? Don't want to dig in awk additionaly if I can avoid it. –  Feb 16 '12 at 10:29
  • Alright, I see. You suggest to leave the gnuplot script and run some linux commands. My bad I didn't mention I'm on a Windows machine. Any ideas how to achieve this within gnuplot functionality? –  Feb 16 '12 at 13:48
  • Sorry AFAIK gnuplot does not support this functionality. – Woltan Feb 16 '12 at 13:54