0
votes

Here's the deal - I have a file that looks like this:

n_blocks n_rows
title1
data1 data2 data3 data4 data5 data6 data7 data8 data9
data1 data2 data3 data4 data5 data6 data7 data8 data9
data1 data2 data3 data4 data5 data6 data7 data8 data9
.
.
.
title2
data1 data2 data3 data4 data5 data6 data7 data8 data9
data1 data2 data3 data4 data5 data6 data7 data8 data9
data1 data2 data3 data4 data5 data6 data7 data8 data9
.
.
.
END OF THE DATA

The first line contains two numbers - the number of blocks, and the number of rows within each block. Before each block is a line that says the title of the block, and then each block consists of n_rows rows, each row consisting of 9 data points. The file then ends with "END OF THE FILE".

The first thing I'd like to do is plot, for each block, column 1 against column 8, with the appropriate title. I have worked out how to plot the data for a specific number of blocks, with the command plot "data.txt" every :::::n_blocks using 1:8, but not how to automatically extract the number of blocks from the first line of the text file, nor how to extract the title from before each block.

The second thing I need to be able to do is plot the sum of all the blocks together, so for each point in the first column, I plot the sum of the corresponding data points in column 8 in every block. E.g., the first data point plotted will be the sum of all the entries in the 8th column of the first row of each block, and the second data point plotted will be the sum of the entries in the 8th column of the second row of each block, and so on.

How much of what I'm asking for is possible? If necessary, I can see about reformatting the data file, but I'd prefer not to, since I didn't write the program that generates them.

1

1 Answers

0
votes

I assume that your "blocks of data" are separated by two blank lines as required by gnuplot. In that case the following command will extract and plot one block at a time, using the initial line of the block as a title:

 plot for [i=0:*] 'blocks.dat' skip 1 index i using 1:5 title columnhead

For this particular task it is better to use the "index" selector rather than the "every" selector. There is no easy way to extract information from the first line. On the other hand, you don't need this information for the plot. The command shown above ignores it via "skip 1".

The summation may be possible also, but I don't understand your description of the terms to be summed or the plot to be produced so I cannot provide an example.