/* * plot.c * Build: gcc -lm -oplot plot.c * Usage: just run :-) ^C to terminate. */ #include #include #include void update_data(FILE* f) { static double phase = 0.; double t; for (t = 0.; t < 10.; t += 0.1) fprintf(f, "%f %f\n", t, sin(t + phase)); phase += 0.1; } int main(void) { FILE* cmdpipe = popen("gnuplot -", "w"); for (;;) { FILE* datafile = fopen("plot.dat", "w"); update_data(datafile); fclose(datafile); fputs("plot 'plot.dat' with lines\n", cmdpipe); fflush(cmdpipe); usleep(100 * 1000); /* Wait for 0.1s */ } }