/* * データファイルを介在させなくても gnuplot に標準入力からデータを入力できる */ #include #include int main(void) { int i,j,k; double x,theta1, theta2; FILE *gp; gp = popen("gnuplot -geometry 640x480","w"); fprintf(gp, "set xlabel \"t\"\n"); fprintf(gp, "set ylabel \"X,Y\"\n"); fprintf(gp, "set xrange[-2:15]\n"); fprintf(gp, "set yrange[-2.5:2.5]\n"); fflush(gp); for(k=0; k<10; k++){ for(j=0;j<100;j++){ fprintf(gp, "plot '-' using 1:2 with points 1,\\\n'-' using 1:3 with lines lt 2\n"); fflush(gp); theta1 = (double)j/25.0*3.1415; theta2 = (double)j*2.0/25.0*3.1415; for(i=0;i<100;i++){ x = (double)i/25.0*3.1415; fprintf(gp, "%.5lf %.5lf %.5lf\n", x, sin(x+theta1), sin(x+theta2) + cos(2.0*(x+theta2)) ); } fprintf(gp,"e\n"); /* 文字 'e' でデータの終了 */ fflush(gp); usleep(100000); } } fclose(gp); }