2

I have a gnuplot script like this (simplified)

reset session

set terminal pngcairo enhanced font "Times,25" size 800,400

filename = ifilename

stats filename nooutput

N = STATS_columns
M = STATS_records

set angles degrees
set size square 1.25,1

set output ofilename

# does some stuff
...
...
...

set parametric  

plot \ 
    for [i=2:N] filename u (posX($0, column(i))):(posY($0, column(i))) w p ps 1.2 pt 7 lc rgb lcolor(i-2)

What I want to do is define ifilename (input file) and ofilename (output file) via a shell script.

So I thought the -e command might just be the one for the job.

So for the gnuploat part of the script I wroth this

gnuplot -e "ifilename='data/points_data1.dat'; ofilename='plot1'" chart.gp

but it threw the error

"chart.gp" line 8: undefined variable: ifilename

which refers to this line

filename = ifilename

I thought maybe that's because it's having some trouble parsing two = signs so I removed that line and rewrote my shell script like this

gnuplot -e "filename='data/points_data1.dat'; ofilename='plot1'" chart.gp

but this time it threw the following error

"chart.gp" line 8: undefined variable: filename

What actually worked was this

echo "data/points_data$i.dat" | gnuplot chart.gp

where I replaced the line filename = ifilename with

FILE = system("read filename; echo $filename") 

and every instance of filename with FILE in .gp script.

But I'm not sure how to use that syntax to also define the output file.


So I was wondering, is there a better way of piping shell input into gnuplot script?

2 Answers 2

1

Your original command almost worked. The invocation

gnuplot -e "ifilename='data/points_data1.dat'; ofilename='plot1'" chart.gp

correctly defined the input and output file names. But then you clobbered them inside the chart.gp script by issuing the command

  reset session

which clears all variable definitions including the ones you specifically wanted. Remove that line from the script and you should be fine. If the intent of the "reset session" command was to make sure that no system-wide or private initialization file is used, then replace it with a "-d" on the command line:

  gnuplot -d -e "ifilename='data/points_data1.dat'; ofilename='plot1'" chart.gp
Sign up to request clarification or add additional context in comments.

Comments

0
FILE = system("read filename; echo $filename") 

is actually fine.

If you want to pipe the output to some file you can just omit set output "something.png"

and instead you could just send the .png output directly to stdout by running a script like this

#!/usr/bin/env gnuplot

reset session

set terminal pngcairo enhanced font "Times,25" size 800,400
...

then you can pipe that output to a .png file like this

./chart.gp > mypng.png

So the final command would look something like this

echo "data/points_data$i.dat" | gnuplot chart.gp > plot$i.png

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.