DaveL17
DaveL17

Reputation: 2015

Gnuplot: Load String From File

I have many charts, each generated by individual Gnuplot (5.0) files and individual data files. They all share common display characteristics such as background, font, etc. Occasionally, there is a call to change the look of all the charts--for example, change the background color of all charts from "#000000" to "#333333".

To continue with the example, what I would like do is place the color value into a textfile called "backgroundColor.txt" and then pull that value into each file as it's plotted. Even better would be to have background color preference on the first line, font on the second, etc.

Example textfile.txt:

"#000000"
"Arial,10"

Gnuplot psuedo-code:

backgroundColor_var = file[1]
font_var = file[2]

set terminal pngcairo enhanced background backgroundColor_var font font_var size 600,200

Then I need make only one change, rather than many, many changes. Thanks in advance,

Dave

Upvotes: 1

Views: 1053

Answers (2)

Christoph
Christoph

Reputation: 48390

Why don't you simply put the whole variable declaration in the config file?

File textfile.txt:

backgroundColor_var = "#FFFFFF"
font_var = "Arial,10"

And then use it with

load 'textfile.txt'
set terminal ...

This solution works on any OS and you can put everything inside, line style definitions, terminal settings, fonts and so on

Upvotes: 2

vagoberto
vagoberto

Reputation: 2442

I would use the system command. In linux, the following should work:

config = "config.cfg"
backgroundColor_var = system( sprintf("sed -n '1p' %s", config) )
font_var = system( sprintf("sed -n '2p' %s", config) )

The sed -n 'Np' command selects the Nth line of the config file. In windows, you would need to install gnuwin32 to use this answer.

Upvotes: 1

Related Questions