Tomas Aschan
Tomas Aschan

Reputation: 60564

Plot data from from a file named in another file

I'm trying to write a gnuplot script that plots data from a file (no issues there), with the file name given in another file (this I need help with). I currently have the following:

set terminal pngcairo
set output 'interpolation.png'

plot 'output.txt' u 2:3 w lines, \
     'data_1.txt' w points

which works as expected. However, I generate the output.txt datafile that takes values from data_X.txt (and interpolates the data). My program reads the data file name from stdin, so I have an input file with all the data needed for one run. The first line of this input file is the file name of the data file for that run.

Is there any way I can get the file name from the same input file? How?

In other words, given a plotting script interpolation.gpt, a number of data files data_X.txt and an input file input.txt in which the first line names one of the data_X.txt files, can I make interpolation.gpt use the data file named in input.txt without having to manually edit both files?

Upvotes: 0

Views: 317

Answers (2)

mgilson
mgilson

Reputation: 309881

You can also do this from within gnuplot:

datafile = system("head -1 output.txt")
plot 'output.txt' u 2:3 w lines, \
      datafile w points

Backquote substitution would have worked as well I think:

datafile = "`head -1 output.txt`"

Upvotes: 1

andyras
andyras

Reputation: 15910

The simplest way might be to call gnuplot from another script, e.g.

#!/bin/bash

datafile=$(head -1 output.txt)

gnuplot << EOF
set terminal ...
set output ...
plot 'output.txt' u 2:3 w lines, \
     '$datafile' w points
EOF

Upvotes: 0

Related Questions