Part Six - Using gnuplot from a C++ Program
These instructions have not been fully tested yet
- Download this ZIP File
- Unzip this to C:\Cygwin\Home\UserName\gnuplot_i where UserName is your Windows User Name.
- Run the "Start X Windows" shortcut (created in Part Four)
- Type the following command to change to this directory:
cd gnuplot_i
- Type the following command to list the contents of the directory:
ls
- This should list the following files:
- Makefile
- example.cpp
- gnuplot_i.cpp
- gnuplot_i.hpp
- Type the following command to compile the example program (uses the instructions found in the Makefile):
make
- Your screen should now look like this:
- Again, type the following command to list the contents of the directory:
ls
- This should list the following files:
- Makefile
- example.cpp
- example.exe (the new program)
- example.o (temporary object file)
- gnuplot_i.cpp
- gnuplot_i.hpp
- gnuplos_o.o (temporary object file)
- Your screen should now look like this:
- Now try running the example program we have just compiled by typing:
./example
or
./example.exe
- It should print text messages in the command prompt window, and draw assorted graphs in additional gnuplot windows, e.g.
(Click here for full sized image) - The example program will finish and close all the gnuplot windows on its own
- Close Cygwin
P.S. - Using the Windows Command Prompt
As long as the X Windows server is running (its started when you run the "Start X Windows" shortcut) you can compile and run C++ programs that use gnuplot from the Windows Command Prompt (instead of the Cygwin prompt). You can tell if the X Windows server is running by looking for its icon in the Windows System Tray (bottom right of screen):
Credits
The example here uses a C++ interface to gnuplot written by Rajarshi Guha (a graduate student in the department of chemistry at the Pennsylvania State University).
The code (in my ZIP file) is identical to that provided by Rajarshi Guha (in this tarball, which seems to have moved server to here) except I renamed the .cc files to .cpp, and provided it as a ZIP file because they are easier to use on Windows than tarballs.
This code was based on the C interface to gnuplot written by Nicolas Devillard.
Both interfaces talk to gnuplot using "POSIX pipes" which are supported on Unix and Linux. We can use this code under Windows XP with Cygwin to talk to the (Cgywin provided) gnuplot.
Nicolas' page also has information on ways of controlling gnuplot from other programming languages, for example gnuplot with Python, gnuplot with Perl and gnuplot with Fortran.
Next up, Part Seven - Remote Computing.