dkogan / feedgnuplot

Tool to plot realtime and stored data from the commandline, using gnuplot.
Other
707 stars 37 forks source link

Not printing data out in real time just printing out all at once at the end of loop. #36

Closed stillpointx closed 5 years ago

stillpointx commented 5 years ago

Greetings

I'm testing out Feedgnuplot and I'm having some issues.

I can execute a program ./rtauto-usb2001tc that gets real time temperature from a thermocouple and displays it on the screen. The data in the columns represent the timestamp, temperature in Celsius, and temperature in Fahrenheit.
See First_animation.gif of what the program ./rtauto-usb2001tc does when executed.

first_animation

The command I tried to plot real time data is below. ./rtauto-usb2001tc | tee output.csv | awk '{print $1 $3}' | feedgnuplot --stream --with linespoints

1) It writes data to a file called output.csv (working) 2) The x data is the 1st column (timestamp) and the y data (temperature) is the 3rd column (issues with x and y axis are not matching along with it's not plotting in real time, it plots all at once at the end) See Second_animation.gif of what the commands with feedgnuplot does when executed below.

second_animation

Thanks for a great app!!

dkogan commented 5 years ago

Hi.

Almost certainly your pipeline is being buffered, so the data isn't being sent to feedgnuplot as it comes in, but all at once at the end. This isn't something feedgnuplot can fix, since the issue is outside of its control.

The buffering could be happening at every stage in the pipeline, and you need to make sure to turn off the buffering at every step:

  1. I don't know what rtauto-usb2001tc is. If, for example, it's a C application that writes data with printf(), you need to fflush(stdout) after printing every record. If it isn't using printf(), you need to do something similar

  2. I don't know how tee works internally, and you may need to run it under 'unbuffer', or after an 'stdbuf' command

  3. awk: if this is GNU awk, you can so '{print $1,$3; fflush();}'

This is a very well known feature of pipes, and a very common source of confusion. Look up: stdbuf unbuffer expect

stillpointx commented 5 years ago

Thanks so much for your suggestions it helped me a lot and I got my old thermocouple plotting in real time. It's a long command to use and it looks crazy but it works for my needs.

./rtauto-usb2001tc 1200 | tee output_temp.csv | unbuffer tail -f output_temp.csv | stdbuf -o0 awk -W interactive '{print substr($2, 9, length($2)),$4;fflush();}' | feedgnuplot --stream --domain --title "Plasma water Temperature vs Time\n <process to run for 1200 seconds>" --set timestamp --ylabel 'Temperature' --xlabel 'Time' --set 'xtics rotate' --with linespoints

stillpointx commented 5 years ago

Thanks so much for your suggestions it helped me a lot and I got my old thermocouple plotting in real time. It's a long command to use and it looks crazy but it works for my needs.

./rtauto-usb2001tc 1200 | tee output_temp.csv | unbuffer tail -f output_temp.csv | stdbuf -o0 awk -W interactive '{print substr($2, 9, length($2)),$4;fflush();}' | feedgnuplot --stream --domain --title "Plasma water Temperature vs Time\n <process to run for 1200 seconds>" --set timestamp --ylabel 'Temperature' --xlabel 'Time' --set 'xtics rotate' --with linespoints

Rick

real_time_working