boyfarrell.com

2 November 2005

Xcode and gnuplot

I am new to programming and I’m new to the MacOS X platform. As such I am indebted to those clever people at MacOSX.com and Cprogramming.com for the time spent answering my questions on, how to get gnuplot and working with macOS applications.

We want to installing gnuplot and make it work from inside Xcode (or any MacOS App).

1) Install gnuplot and AquaTerm!

gnuplot for MacOS is available on this page from Sourceforge at the time of writing; be sure to get the Macintosh disk image file .dmg. I’d also get the pdf help file.

Get AquaTerm by navigating to the download section of the site. This again is a simple drag-to-applications install process.

2) Configure .gnuplot file (optional)

gnuplot, being unix based looks for a file in you home directory called ‘.gnuplot’, this is like it’s preferences if you will. However ‘.filename’ files are invisible on MacOS because they are reserved for the system. The best way to proceed here is to use nano text editor; this is already installed with MacOS. Open Terminal and type:

cd ~
nano .gnuplot

This will make new file in your home directory called ‘.gnuplot’ and enter into the nano text editor. Now, enter the following the .gnuplot file:

#
# aquaterm terminal
#
set term aqua size '400' '400' font 'Garamond, 11'

#
# postscript terminal
#
#set term postscript enhanced monochrome size 7, 7 "Garamond" 10
#set size square
#set output 'graph.ps'

Exit nano by hitting ctrl-X and choosing Yes to save the file.

Now every-time gnuplot starts up it will look in the .gnuplot file and load aquaterm to display your data. In gnuplot the hash symbol is a comment. If I also have commented out options for using the postscript terminal. This is nice when you only want gray-scale plots.

3) Update PATH variable

We need to change the path variable to make the ‘system’ know where gnuplot is. (If you typegnuplot int the terminal and get a ‘can’t find’ type error you need to do this.)

We will now edit you .profile, becareful here because if you change certain things, stuff might screw-up. In terminal change to your home directory then type:
nano .profile
PATH=/usr/local/bin:$PATH; export PATH

This will preserve your original path value and add the location of the gnuplot binary. If you installed it with darwinports (now macports) the path you have to add is probably /opt/local/bin.

Open a new terminal and type ‘gnuplot‘. gnuplot should now open!

Inside gnuplot terminal type ‘plot sin(x)‘. AquaTerm should open and display your plot. If not make sure that AquaTerm is open and try again. The next time you launch gnuplot from the terminal in will open AquaTerm automatically.

4) Update the environment.plist

This is the bit that makes Xcode use AquaTerm to display plots generated by gnuplot and it’s very simple.

Using the mv and mkdir terminal commands (or otherwise) make a folder in you home directory called “.MacOSX” the case and dot are important. Inside this folder place the file environment.plist. NB – this is my PATH variable, please enter yours.

This step has prepped the system to know where to find
AquaTerm and gnuplot from inside Xcode.

However, how are you going to interface with gnuplot … ?
This is what we will discuss next time.

NB – Thank you to Viro from MacOSX.com for his help on
getting this to work.

No Comments currently posted.

Post a comment on this entry: