Sending Live Data to XGRAPH
(Driving XGRAPH Interactively)


To drive XGRAPH interactively from another program:
(IE. "Live-Plots")
  1. In the global-area of your program:
    	#include "utilities/soc_lib.c"
    	int soc;
       
  2. In the initialization section of your program, open the socket with:
    	soc = makeConnect( "localhost", socno );
    Where socno is an integer socket number, such as 13330 .
    (Suggestion: Use socket numbers from 1000 to 16383.)

  3. Everywhere that you want to write data to XGRAPH, where you normally wrote to a graph-file with:
    . . . fprintf(plotfile,"%f %f\n",x,y);
    Replace with:
    	sprintf(message,"%f %f", x, y );
    	send_soc( soc, message );
    
    (You can also write to the file at the same time by adding:
    		fprintf(plotfile,"%s\n",message);
    )
    
    (Note that you can send any XGRAPH command through the socket
     that you would normally write to a plot-file, such as:
    	color=8
    	next_line
            annotation 3.0 5.6  Any text you want
     etc..
    )

  4. Make sure your program closes the socket after it is done writing everything to XGRAPH, by:
    	close_soc( soc );

  5. Compile your application by adding the link-libs:
    	-lsocket -lnsl 
    to the end of your compile command. For example:
    	cc test.c -lsocket -lnsl -o test.exe
    (On Linux, -lnsl is not needed.)


Usage:

  1. Invoke XGRAPH, telling the x-and-y ranges and the socket number to use. Run it in background.
    For example:
    	xgraph -x_range 0 20  -y_range 1 10  -soc 13330 &
    	
  2. Invoke your user-application that connects to the given socket. For example:
    	sim.exe
    	


Notes: