0

I have the following script called tmp.plt for gnuplot:

plot \
"n300_50int/ini-ene.his" using 1:2, \ 
"n500_100int/ini-ene.his" using 1:2, \ 
"n500_1ooint_0.65e3/ini-ene.his" using 1:2, \ 
"n500_50int/ini-ene.his" using 1:2

But it gives me the error

samuel@samuel-P5Wx6:~/Documents/Fisica/19-20/Radiactividad/Prácticas/Practicas-MontCarlo/PET/Simulaciones$ gnuplot -p tmp.plt 

plot "n300_50int/ini-ene.his" using 1:2, \ 
                                         ^
"tmp.plt", line 2: invalid character \

I've created this script with the following .sh (edited from the one in Gnuplot: Plot several in files in different folders ) :

#!/bin/bash

## truncate tmp.plt and set line style
echo -e "plot \\" > tmp.plt

cnt=0   ## flag for adding ', \' line ending

## loop over each file
for i in */ini-ene.his; do
    if ((cnt == 0)); then       
        cnt=1                   
    else
        printf ", \\ \n" >> tmp.plt             
    fi
    printf "\"$i\" using 1:2" >> tmp.plt 
done
echo "" >> tmp.plt              

And I don't understand why it doesn't work when the next test.plt file does

f(x)=x
g(x)=2*x
plot \
f(x) , \
g(x)

Thank you!

1 Answers1

1

It is erroring because of the backslash (\) in the tmp.plt file. The reason is that \ needs to be the last character on the line as per the gnuplot instructions. There is a space after your \ in the nonworking example. If you add a space after the \ in the working example it will error, too. As shown here:

plot f(x) , \ 
            ^
"test.plt" line 4: invalid character \

So try: printf ",\\\n" >> tmp.plt (or just printf ",\n" >> tmp.plt)

instead of: printf ", \\ \n" >> tmp.plt

seanpue
  • 313
  • 1
  • 7