Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gnuplot exit on window close

Tags:

gnuplot

I use the following script to print readings from a .csv file. The plot is refreshed every second to show new data when a simulation is running. This works kinda nice, although is a little ugly since the whole dataset is reread (if you have a better solution please let me know)

However, when I close the gnuplot window the script does not exit, but after 1 second pause a new window spawns, which is kinda annoying. I'd rather have my script closed once i close the window. Is there a way to archieve this?

#!/usr/bin/gnuplot
set t wxt enhanced noraise
set datafile separator ";"
plot "../build/inputLink.csv" using 1:5 title 'Input Gear' with lines ,\
     "../build/inputLink.csv" using 1:7 title 'Input Gear Ratio' with lines,\
     ;
pause 1
reread
like image 325
worenga Avatar asked Mar 15 '15 17:03

worenga


2 Answers

There isn't exactly such a functionality in gnuplot, to bind the window's close button to exit the program. However, you can use bind to define a hot-key which exits the loop:

#!/usr/bin/gnuplot
set t wxt enhanced noraise
set datafile separator ";"
set style data lines

done = 0
bind all 'd' 'done = 1'
while(!done) {
  plot "../build/inputLink.csv" using 1:5 title 'Input Gear',\
       "" using 1:7 title 'Input Gear Ratio'
  pause 1
}

And no, there is no other way to refresh the plot other than rereading the whole data set every time.

like image 55
Christoph Avatar answered Nov 02 '22 09:11

Christoph


To read/reread last 100 lines written to the file which appends whatever new data has arrived

plot "< tail -n 100 ../build/inputLink.csv" using 1:5 title \
'Input Gear' with lines , \
, "< tail -n 100"../build/inputLink.csv" using 1:7 title \
'Input Gear Ratio' with lines,\
     ;

I don't have wxt type terminal on my debian system, using an x11 terminal I can bind the key 's' and use it to exit the gnuplot window

pause 1
bind "s" "unset output ; exit gnuplot"
reread 
like image 41
Steve Avatar answered Nov 02 '22 10:11

Steve