/* * Examples of gnuplot_i.c usage */ #include #include #include "gnuplot_i.h" #define SLEEP_LGTH 1 #define NPOINTS 50 void slow_print(char * s) ; int main ( int argc, char *argv[] ) { gnuplot_ctrl * h1, * h2, * h3, * h4 ; double d[NPOINTS] ; dpoint dp[NPOINTS] ; int i ; /* * Initialize the gnuplot handle */ slow_print("*** example of gnuplot control through C ***\n") ; h1 = gnuplot_init() ; if ( h1 == NULL ) { printf ( "\n" ); printf ( "Please make gnuplot available in your path.\n" ); return 1; } /* Slopes */ gnuplot_setstyle(h1, "lines") ; slow_print("*** plotting slopes\n") ; slow_print("y = x\n") ; gnuplot_plot_slope(h1, 1.0, 0.0, "unity slope") ; sleep(SLEEP_LGTH) ; slow_print("y = 2*x\n") ; gnuplot_plot_slope(h1, 2.0, 0.0, "y=2x") ; sleep(SLEEP_LGTH) ; slow_print("y = -x\n") ; gnuplot_plot_slope(h1, -1.0, 0.0, "y=-x") ; sleep(SLEEP_LGTH) ; /* Equations */ gnuplot_resetplot(h1) ; printf("\n\n") ; slow_print("*** various equations\n") ; slow_print("y = sin(x)\n") ; gnuplot_plot_equation(h1, "sin(x)", "sine") ; sleep(SLEEP_LGTH) ; slow_print("y = log(x)\n") ; gnuplot_plot_equation(h1, "log(x)", "logarithm") ; sleep(SLEEP_LGTH) ; slow_print("y = sin(x)*cos(2*x)\n") ; gnuplot_plot_equation(h1, "sin(x)*cos(2*x)", "sine product") ; sleep(SLEEP_LGTH) ; /* Styles */ gnuplot_resetplot(h1) ; printf("\n\n") ; slow_print("*** Showing plot style options:\n") ; slow_print("sine(x) in points\n") ; gnuplot_setstyle(h1, "points") ; gnuplot_plot_equation(h1, "sin(x)", "sine") ; sleep(SLEEP_LGTH) ; slow_print("sine(x) in impulses\n") ; gnuplot_setstyle(h1, "impulses") ; gnuplot_plot_equation(h1, "sin(x)", "sine") ; sleep(SLEEP_LGTH) ; slow_print("sine(x) in steps\n") ; gnuplot_setstyle(h1, "steps") ; gnuplot_plot_equation(h1, "sin(x)", "sine") ; sleep(SLEEP_LGTH) ; /* User defined 1d and 2d point sets */ gnuplot_resetplot(h1) ; gnuplot_setstyle(h1, "impulses") ; printf("\n\n") ; slow_print("*** user defined lists of points\n") ; slow_print("random doubles\n") ; srand48(getpid()) ; for (i=0 ; i