1 #include <stdlib.h>
2 #include <stdio.h>
3 #include <unistd.h>
4 #include "grace_np.h"
5 
6 #ifndef EXIT_SUCCESS
7 #  define EXIT_SUCCESS 0
8 #endif
9 
10 #ifndef EXIT_FAILURE
11 #  define EXIT_FAILURE -1
12 #endif
13 
my_error_function(const char * msg)14 void my_error_function(const char *msg)
15 {
16     fprintf(stderr, "library message : \"%s\"\n", msg);
17 }
18 
19 int
main(int argc,char * argv[])20 main (int argc, char* argv[])
21 {
22     int i;
23 
24     GraceRegisterErrorFunction (my_error_function);
25 
26     /* Start Grace with a buffer size of 2048 and open the pipe */
27     if (GraceOpen(2048) == -1) {
28         fprintf (stderr, "Can't run Grace. \n");
29         exit (EXIT_FAILURE);
30     }
31 
32     /* Send some initialization commands to Grace */
33     GracePrintf ("world xmax 100");
34     GracePrintf ("world ymax 10000");
35     GracePrintf ("xaxis tick major 20");
36     GracePrintf ("xaxis tick minor 10");
37     GracePrintf ("yaxis tick major 2000");
38     GracePrintf ("yaxis tick minor 1000");
39     GracePrintf ("s0 on");
40     GracePrintf ("s0 symbol 1");
41     GracePrintf ("s0 symbol size 0.3");
42     GracePrintf ("s0 symbol fill pattern 1");
43     GracePrintf ("s1 on");
44     GracePrintf ("s1 symbol 1");
45     GracePrintf ("s1 symbol size 0.3");
46     GracePrintf ("s1 symbol fill pattern 1");
47 
48     /* Display sample data */
49     for (i = 1; i <= 100 && GraceIsOpen(); i++) {
50         GracePrintf ("g0.s0 point %d, %d", i, i);
51         GracePrintf ("g0.s1 point %d, %d", i, i * i);
52         /* Update the Grace display after every ten steps */
53         if (i % 10 == 0) {
54             GracePrintf ("redraw");
55             /* Wait a second, just to simulate some time needed for
56                calculations. Your real application shouldn't wait. */
57             sleep (1);
58         }
59     }
60 
61     if (GraceIsOpen()) {
62         /* Tell Grace to save the data */
63         GracePrintf ("saveall \"sample.agr\"");
64 
65         /* Flush the output buffer and close Grace */
66         GraceClose();
67 
68         /* We are done */
69         exit (EXIT_SUCCESS);
70     } else {
71         exit (EXIT_FAILURE);
72     }
73 
74 }
75 
76