0
votes

I got stuck with a gnuplot experiment. I am new to gnuplot and am trying to explore the gnuplot options and variety.

First, here is what I am trying to do: from a c program I want to plot 5 data files. Nonetheless, I use a .gplt file, a makefile, and a.c file( working with geany on lubuntu).

Here is what the files look like:

===================simulation.gplt====================

plot 'result1.data' using 2:3 title "F" w lines
plot 'result2.data' using 2:3 title "F" w lines
plot 'result3.data' using 2:3 title "F" w lines
plot 'result4.data' using 2:3 title "F" w lines
plot 'result5.data' using 2:3 title "F" w lines

set ouput "simulation.ps"
replot

=================Makefile==============================enter code here

all:run plot

plot: result1.data
      result2.data
      result3.data
      result4.data 
      result5.data
    gnuplot simulation.gplt
    ps2pdf simulation.ps
    rm -f simulation.ps
    evince simulation.pdf

run:program
    ./program

program: program.c
    gcc -Wall -o program -O3 program.c -lm -g

clean:
      rm -f program
      rm -f result1.data
      rm -f result2.data
      rm -f result3.data
      rm -f result4.data
      rm -f result5.data
      rm -f simulation.pdf
      rm -f simulation.ps

.......................................................

what I can type make clean in the terminal, eveything seems ok. Yet, when I type "make", I see those 2 messages:

make:result2.data: unknown command make ****[plot] error 127

The point: can anybody help? I feel that the mistake in the Makefile, I tried to fix it at several times, but the same messages still appear.

1

1 Answers

0
votes

First of all, I edited your question and added four spaces at the beginning of each line of code. This way, you get a nice formatting.

Now, I see several problems in the make file and in the gnuplot code:

gnuplot

Your code generates four plots on the screen, each overwriting the last one. Then, you open a file and do replot . This command repeats the last plot command, i.e. only result5.data will be written into a file. Next, simply setting an output file is not enough. You have to specify the terminal (file type) first.

This will generate a 5-page PS file, one plot on each page:

set terminal postscript
set output "simulation.ps"
plot 'result1.data' using 2:3 title "F" w lines
plot 'result2.data' using 2:3 title "F" w lines
plot 'result3.data' using 2:3 title "F" w lines
plot 'result4.data' using 2:3 title "F" w lines
plot 'result5.data' using 2:3 title "F" w lines
unset output

Or, if you want all data within a singe diagram, use this:

set terminal postscript
set output "simulation.ps"
plot 'result1.data' using 2:3 title "F" w lines,\
     'result2.data' using 2:3 title "F" w lines,\
     'result3.data' using 2:3 title "F" w lines,\
     'result4.data' using 2:3 title "F" w lines,\
     'result5.data' using 2:3 title "F" w lines
unset output

Note: The five plot objects are separated by a comma. And the backslash \ allows to proceed in the next line (so, there is in fact only a single line with a large plot command)

However, it is not necessary to generate a postscript file with gnuplot and later convert it to PDF. gnuplot can directly generate PDF:

set terminal pdfcairo mono dashed size 8in, 11in
set output "foo.pdf"
plot sin(x), cos(x)
unset output

Here, I added options to generate a plot of DIN A4 paper size, in black/white instead of color, and with dashed lines. There are plenty of options, check it in gnuplot with help pdfcairo

makefile

The list of prerequisites has to be given in a single line. But like in gnuplot, you can use \ to span it over multible lines:

plot: result1.data \
      result2.data \
      result3.data \
      result4.data \
      result5.data
    gnuplot simulation.gplt
    ps2pdf simulation.ps
    rm -f simulation.ps
    evince simulation.pdf    

This is exactly what the error message tells you: It wants to process the rule "plot". the results1.data is already there, and then, it tries to run the command in the second line, which is results2.data. As this isn't a command, you get the error.

Another problem is that make definitively needs a tabulator in front of each command line, not just spaces. Make sure your editor does insert tabs, many like to insert four spaces instead! (This error can not be checked here, as tabs are not visible here.)