1 /*
2  * Copyright (C) 1995 by Rob McMullen
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the Free
16  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17  *
18  *
19  * Author: Rob McMullen <rwmcm@orion.ae.utexas.edu>
20  *         http://www.ae.utexas.edu/~rwmcm
21  */
22 
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <X11/Intrinsic.h>
26 #include <X11/StringDefs.h>
27 #include "SciPlot.h"
28 #include "SciPlotUtil.h"
29 
30 XtAppContext app_con;
31 int line;
32 float xdata[10];
33 float ydata[10];
34 
35 /* ARGSUSED */
36 static void
Update(XtPointer client_data,XtIntervalId * idp)37 Update(XtPointer client_data, XtIntervalId * idp)
38 {
39   Widget plot = (Widget) client_data;
40   int index;
41 
42   index=rand()%10;
43   if (index>0) ydata[index]+=1.0;
44   SciPlotListUpdateFromFloat(plot, line, 10, xdata, ydata);
45   if (SciPlotQuickUpdate(plot)) {
46       SciPlotUpdate(plot);
47   }
48 
49   XtAppAddTimeOut(app_con,500,Update,plot);
50 }
51 
52 int
main(int argc,char * argv[])53 main(int argc, char *argv[])
54 {
55   Widget toplevel, dummy, plot;
56   int i;
57 
58   toplevel = XtAppInitialize(&app_con, "SciPlot",
59     NULL, 0, &argc, argv, NULL, NULL, 0);
60   dummy = XtVaCreateManagedWidget("dummy",
61     coreWidgetClass, toplevel,
62                                   XtNwidth,10,
63                                   XtNheight,10,
64     NULL);
65   XtSetMappedWhenManaged(toplevel, False);
66 
67   plot=SciPlotDialog(toplevel,"Real Time Test");
68   for (i=0; i<10; i++) {
69       xdata[i]=i+1.0;
70       ydata[i]=i/2.0;
71   }
72   line = SciPlotListCreateFromFloat(plot, 10, xdata, ydata, "race");
73 
74   XtRealizeWidget(toplevel);
75 
76   SciPlotUpdate(plot);
77 
78   srand((unsigned int) getpid()); /* Initialize it with a fairly random seed */
79   XtAppAddTimeOut(app_con,500,Update,plot);
80 
81   XtAppMainLoop(app_con);
82 
83   return 0;
84 }
85