home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.graphics.gnuplot
- Path: sparky!uunet!charon.amdahl.com!pacbell.com!decwrl!elroy.jpl.nasa.gov!sdd.hp.com!ux1.cso.uiuc.edu!news.cso.uiuc.edu!ux2.cso.uiuc.edu!ejk
- From: ejk@ux2.cso.uiuc.edu (Ed Kubaitis - CCSO)
- Subject: Re: GNUPLOT An Interactive Plotting Program v.3.2
- References: <16090.9211051705@SunLab41.essex.ac.uk>
- Message-ID: <Bx9ADF.BuK@news.cso.uiuc.edu>
- Sender: usenet@news.cso.uiuc.edu (Net Noise owner)
- Organization: University of Illinois - Urbana
- Date: Thu, 5 Nov 1992 18:36:49 GMT
- Lines: 55
-
- oakli@essex.ac.uk (Oakley I G) writes:
- |I have taken the above email address from the cover of the GNUPLOT 3.2 manual
- |in the hope that the recipiant can help me.
- |
- |As part of my final year project here at Essex University, U.K. I am intending
- |on using Gnuplot to display various data that my 'C' program will produce.
- |
- |What I would like to be able to do is execute Gnuplot from within my 'C' code
- |so that it can be used as an interactive part of the program bringing up a
- |Gnuplot window displaying any data set chosen by the user.
- |
- |I am currently not sure if this is possible although I have a few basic ideas)
- |so I would appreciate you telling me how to go about doing it (with some
- |example code maybe). I know there is a library routine system() which allows
- |commands to be executed as if they were typed from the shell. When using
- |this command and piping in a datafile, the Gnuplot window only appears
- |very briefly despite the use of 'pause -1' in the datafile.
- |
- |I am currently using SUN SPARCstations running an X-window environment with
- |the UNIX operating system.
-
- Not sure what you mean by "piping in a datafile", but attached is a very
- simple example of calling gnuplot from a c program. Perhaps it will
- help. In this example, 'pause -1' seems to work as you want.
-
- ----------------------------------
- Ed Kubaitis (ejk@ux2.cso.uiuc.edu)
- Computing & Communications Services Office - University of Illinois, Urbana
- ===============================================================================
- #include <stdio.h>
-
- FILE *commands, *data;
-
- main(argc, argv) int argc; char *argv[]; {
-
- data = fopen("/tmp/gp.data", "w");
- fprintf(data, "1 1\n");
- fprintf(data, "2 2\n");
- fprintf(data, "3 3\n");
- fprintf(data, "4 4\n");
- fclose(data);
-
- commands = fopen("/tmp/gp.commands", "w");
- fprintf(commands, "set term x11\n");
- fprintf(commands, "plot '/tmp/gp.data' with line 1\n");
- fprintf(commands, "pause -1 'Hit return'\n");
- fclose(commands);
-
- system("gnuplot /tmp/gp.commands");
-
- unlink("/tmp/gp.commands");
- unlink("/tmp/gp.data");
- exit(0);
-
- }
-