/* Adapted from cpgdemo.c to demonstrate crash */ #include "cpgplot.h" #include #include #include #ifndef EXIT_FAILURE #define EXIT_FAILURE 1 #endif #ifndef EXIT_SUCCESS #define EXIT_SUCCESS 0 #endif static void demo1(); /* --------------------------------------------------------------------- * Demonstration program for PGPLOT called from C. * (Note that conventions for calling Fortran from C and C from FORTRAN * are system-dependent). * Usage: * cc -c cpgdemo.c * f77 -o cpgdemo cpgdemo.o -lcpgplot -lpgplot -lX11 *---------------------------------------------------------------------- */ int main() { /* * Call ppgbeg to initiate PGPLOT and open the output device; cpgbeg * will prompt the user to supply the device name and type. */ if(cpgbeg(0, "?", 1, 1) != 1) exit(EXIT_FAILURE); cpgask(1); /* * Call each demo. */ demo1(); /* * Finally, call cpgend to terminate things properly. */ cpgend(); return EXIT_SUCCESS; } static void demo1() { int i; static float xs[] = {1.0, 2.0, 3.0, 4.0, 5.0 }; static float ys[] = {1.0, 4.0, 9.0, 16.0, 25.0 }; float xr[60], yr[60]; int n = sizeof(xr) / sizeof(xr[0]); /* * Call cpgenv to specify the range of the axes and to draw a box, and * cpglab to label it. The x-axis runs from 0 to 10, and y from 0 to 20. */ cpgenv(0.0, 10.0, 0.0, 20.0, 0, 1); cpglab("(x)", "(y)", "PGPLOT Example 1: y = x\\u2\\d"); /* * Mark five points (coordinates in arrays XS and YS), using symbol * number 9. */ cpgpt(5, xs, ys, 9); /* * Compute the function at 'n=60' points, and use cpgline to draw it. */ for(i=0; i