宮崎大学 >>
工学部 >>
情報システム工学科 >>
伊達 >>
Last modified: Sat May 14 18:09:06 JST 2011
#include <stdio.h> #include <math.h> int main(void) { int i; double x; for(i=0; i<100; i++){ x = (double)i/25.0*3.1415; printf("%.5lf %.5lf %.5lf\n", x, sin(x), sin(x) + cos(2.0*x) ); } }
% gcc foo.c -lm % ./a.out > test.dat % cat test.dat | more 0.00000 0.00000 1.00000 0.12566 0.12533 1.09391 0.25132 0.24868 1.12500 0.37698 0.36811 1.09710 0.50264 0.48174 1.01759 0.62830 0.58777 0.89682 0.75396 0.68453 0.74737 0.87962 0.77050 0.58317 1.00528 0.84431 0.41859 .....................
% gnuplot Terminal type set to 'x11' gnuplot> plot [-2:15][-2.5:2.5] "test.dat" using 1:2 with points 1,"test.dat" using 1:3 with linesで画面に表示される.
gnuplot> set terminal postscript "Helvetica" 20 color eps enhanced gnuplot> set output "foo.eps" gnuplot> set xlabel "t" gnuplot > set ylabel "X,Y" gnuplot> plot [-2:15][-2.5:2.5] "test.dat" using 1:2 with points 1,"test.dat" using 1:3 with lines
set terminal postscript "Helvetica" 20 color eps enhanced set xlabel "t" set ylabel "X,Y" plot [-2:15][-2.5:2.5] "test.dat" using 1:2 with points 1,\ "test.dat" using 1:3 with linesこのファイルを用意し,
% gnuplot gpscript1 > hoge.epsとすると,eps ファイルが作成される.
% evince foo.eps
データファイルを介在させなくても gnuplot に 標準入力からデータを入力できる
#include <stdio.h> #include <math.h> 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); }
宮崎大学 >> 工学部 >> 情報システム工学科 >> 伊達 >>