Gnuplot And Xcode

p_j_s_watson

Registered
Has anyone got gnuplot to work successfully with Xcode? I've downloaded the gnuplot_i interface from Nick Devillard's website
http://ndevilla.free.fr/gnuplot/index.html
Using the example files and Xcode, a Carbon app builds successfully, but then will only open a results window
Peter Watson
 
This is an interesting question for all us science types that use macs to program. I will need to know how to do this myself in a few months but I haven't got a mac yet so I can't help you!

If you have matlab, I guess you could call it's plotting functions from XCode? Matlab has C and C++ librarys of various functions, plot is one of them, I believe.

If you find out how to do this please post or e-mail me, I'd be interested to find out.

Best of luck, Dan.
 
I've gotten gnuplot to work, but I'm not certain what you're asking when you refer to Xcode. I don't use gnuplot to debug software if this is the question.

The link that you give points to GUI's for gnuplot. The simplest interface for 2D plots that I've found is octave. The plots are created using gnuplot and are displayed in aquaterm.
 
No: I'm not debugging code. I have a fairly lengthy calculation in C and would like to see intermediate results plotted out so that I know it is behaving as I expect. I can put the results in a text file and then use gnuplot (or several other programs suich as pro fit) to plot the data, but that is after the calculations have finished.
Peter Watson
 
sudo apt-get install gnuplot

Then you can use gnuplot with either XDarwin, X11.app, or any GUI that you chose (I like octave).
 
You need to install Aquaterm and then download GNUPlot, if you haven't already done so. Next, you need to create a symlink from /usr/local/bin/gnuplot to /usr/bin/gnuplot, unless you know how to add /usr/local/bin to the *entire* system path, not just from the terminal. If you don't want to create the symlinks, you can of course add /usr/local/bin to your PATH variable. You need to do this _outside_ the shell, so just editing .profile will _NOT_ work. This is important or you'll be pulling out hair for a long time. I did ::ha::

This can be done by creating a folder called .MacOSX in your home directory. Then create the file environment.plist and edit it in your favorite text editor to contain the following lines:

Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.
com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
        <key>GNUTERM</key>
        <string>aqua</string>
        <key>PATH</key>
        <string>/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin</string>
</dict>
</plist>

Now, GNUPlot should work from within Xcode. If it still doesn't you have to set the GNUTERM variable to equal 'aqua', which would be done if you copied my environment.plist file above.

Enjoy GNUPlot from within Xcode :)
 
Hi Viro.

Weldone! I'll have a go at pulling those apps off when I get back to my broadband connection - I'm on damn dial up at the moment.

When I was installing TexShop with TexLive I had the problem that 1) I couldn't see /usr and 2) not even from the terminal could I edit that folder? I ended up installing everything in ~/library .

To enter that to the entire system path do you just have to mess around with unix's PATH environmental variable. Do you know enough about unix to explain the point in enviromental variables anf the PATH file? (And yes I took me a while to get texshop working before I figured out that I need to change them too!)
 
The PATH environment variable is the path where the OS will know to look for executables. For example if you type in the command 'man', the OS will look through the paths on the PATH variable for the command man. This saves you from having to type out the entire path to the command. So in effect, the PATH variable acts as a kind of short-cut, storing the location of commonly used executables so you needed type in the full path when you call those executables.

If you install additional software, it is usually recommended that you install them somewhere other than /usr/bin or /bin, since these are normally reserved for the system utilities. That is why TexShop installs teTeX in /usr/local/bin. If you installed teTeX via the i-Installer provided on the TexShop website, it will automatically update your PATHs for you.

Now, for manually changing the PATH. All *nix OSes have funny places for storing allowing the user to edit the PATH. One place to set the PATH will be the file /etc/profile. Here, on most Unix systems the following line will do:
Code:
export PATH=/usr/bin:/bin:/usr/local/bin:/my/path/here:$PATH"

On OS X, that sort of works. For some reason (feature? bug?) the contents of /etc/profile only seem to be read when you open a Terminal session. Hence, when running executables through any other means (Xcode, Finder, etc) the PATH will not reflect the updated path you had set. This is where the environment.plist file comes in. This sets the PATH globally, and the environment.plist file is read each time you log in. So this seems to be the best way to set environment variables on OS X. Completely non-standard, but hey, it's Apple :)

Hope that helps you.
 
Yeah that makes a lot of sense thanks.

I decided not to wait and down loaded both gnuplot and aquaterm! I have followed the simple instruction and used the terminal to compile and 'install' gnuplot, I have also installed AquaTerm.

But how do I get them to use each other. I guess there is a environmental variable trick here?!

I can't find any help doc on the web about how to do this either so I guess it's pretty easy. How do you get these two up and running?
 
You need to follow my instructions in the previous post about creating the environment.plist file. That will get GNUPlot to work with AquaTerm.
 
I have tried but ran into a few problems.

I don't have a directory at
Code:
/usr/local/bin
The only directory I have inside 'local' is called 'lib'.

The directory:
Code:
usr/bin/
doesn't contain gnuplot. The only gnu items in there are: 'gnuattach', 'gnuclient', 'gnudoit', 'gnumake', 'gnuserv' and 'gnutar'.

I believe I have successfully completed the installation but now I'm thinking may be not? Infact, searching the system after installation for 'gnuplot' revels only one unix exec at:
Code:
Desktop/GNUplot-4.0.0/src
It is in there from when I downloaded the file in the first place!

Do you have any advice on what I should do?

Additionally I don't know how to add symlink in macOS X or the terminal. I also don't know how to edit the PATH,
not just from the terminal.
The only way I know how to do this is by typing the following into the terminal:
Code:
PATH=/the/location/of/target:$PATH; export PATH
Finally, Tiger won't allow me to make a folder in the home directory starting with a full stop. Terminal will. However, it is invisible! Typing 'ls' doesn't show it. Stranger still, when I type
Code:
cd ~.macosx
it goes straight there - just an empty folder right where I asked for it!

I would really appreciate a little help if you have the time - hope you do! I would be great to get this up and running finally.

All the best, a confused physicist, Dan.
 
Ahh! I have got gnuplot to work with aquaterm! Just a simple case of downloading the general platform rather than the PPC platform installer - doh
 
You need to create the folder .MacOSX (case is important) and you need to create a file in that folder called environment.plist (the contents of which I have posted in a previous posting).

Yes, you need to download the .dmg files, which are already compiled for OS X. Zip and bz2 files are just source code, and you'll have to compile them yourself.
 
Just an update if people are following this link in the future:

Install the following.

GNUplot for MacOS is on this page. Be sure to get the PPC platform (i.e. the .dmg file) this way you don't have to mess around with the terminal and unix stuff. I'd also get the pdf help file.

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

Now this is more or less what I figured out to get Aquaterm and GNUplot working with the help from people in this post. I haven't tried calling GNUplot from Xcode yet. But I will be figuring out how to use the adapters soon. There are other people here who know how to do this.

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. You will need to do the next bit from the terminal.

But first a few unix commands for the terminal:
Code:
cd = change directory
cd ~ = change directory to your home (the tide character always mean home to MacOS)
cd / = change directory to the root
ls = list file in directory
ls -a = list all (even invisible files)
ls -al = as above but with metadata printed too.
mkdir = make a directory
mv = move a file
info nameOfCommand = get info on a command
Firstly, open TextEdit and make a file with the text 'set terminal aqua', click save, make sure you unclick the square box because we don't want it to be saved as a .txt file. In the message window that pops choose the Use "." button.

Now every-time GNUplot starts up it will load aquaterm to display your data.

Secondly, we need to change the path variable to make the 'system' know where GNUplot is. (If you type 'gnuplot' from the terminal and get a 'can't find' type error you need to do this.)

NB - I don't know how to permanently change the PATH variable so I am editing PATH every time the terminal loads.

In terminal type, 'export'. You should be able to see a line called something like PATH='bin:more:directories/listed/here:new/directories/separated/by:colon' this is the value of your PATH variable. *IMPORTANT* do not do delete any of the directories in this string. My PATH:
Code:
PATH="/bin:/sbin:/usr/bin:/usr/sbin:/Users/Daniel/Library/TeTeX/bin/powerpc-apple-darwin-current:/usr/local/bin"
Highlight and Edit --> Copy ALL of your PATH (from the first P of path to the very last " that terminates the string).

Now make a file called .profile in your home directory (same technique as last time). Inside the file, Edit --> Paste the PATH that you just copied. But include the path to GNUplot, which should be /usr/local/bin. make sure you add a colon after the pervious last entry to tell the system that this is a new directory in which to look. Save the file as we did before.

Close the terminal.

Open the terminal and type 'gnuplot'. GNUplot should now open!

Inside GNUplot terminal type 'plot sin(x)' (with out the inverted commas). AquaTerm should open and display your plot. If not make sure that AquaTerm is open and try again, this oddity was reported before, have a look here. The next time you launch GNUplot from the terminal in will open AquaTerm automatically.

Please post if there is a better way of doing things. You might want to post too if you know how to change the path by not editing the .profile. Viro has posted before saying that this won't work when trying to call GNUplot from inside your Xcode projects, you have to change it globally. Hope this as been useful.
 
Launching gnuplot with Aquaterm and plotting sin(x) works fine thanks to boyfarrell's last post.

I've also installed gnuplot_i, but I can't get it to work with Xcode, building fails with
powerpc-apple-darwin8-gcc-4.0.1: gnuplot_i.o: No such file or directory.
Any suggestions?

Update: I added -gnuplot_i.o to "Other Linker Flags" under "Project/Edit Project Settings" in Xcode and it compiles. However, when running the application I get
cannot find DISPLAY variable: is it set?
cannot find gnuplot in your PATH

I'm sure /usr/local/bin where gnuplot is located is set in the $PATH variable...
 
I've already done all of that. Gnuplot is in /usr/local/bin which is set in the file environment.plist. I can also launch gnuplot from any location via terminal, but gnuplot_i cannot find it in Xcode.
 
Hi folks,

How have you installed gnuplot_i? Have you compiled it and installed the binary in /usr/local/lib/ and the header in /usr/local/include/ ?

You will then need to link against using something like: -lgnuplot_i.o or -lgnuplot_i or -gnuplot_i.o in the other linker flag section I think (not to sure about this, it's been a while but I did the above and got it working at some point in the past!).

However, if you don't want to mess around with all that linking stuff (this is what I currently do):

Just import the gnuplot_i.h and gnuplot_i.c into your xcode project that way xcode handles it all for you.

Cheers,
 
Hi,
it's not a problem of getting to run gnuplot_i from within Xcode.
When I try to call gnuplot_init() I get the message mentioned in my first post ("cannot find DISPLAY variable", "cannot find gnuplot in your PATH"). This is a result of gnuplot_get_program_path() failing, obviously.

The strange thing is that I can call gnuplot from anywhere in the terminal and it works. I guess this tells me that the path to gnuplot is set, as far as I understand it.

Thanks.
 
Hi,

As an experiment I deleted the gnuplot directory from my .MacOS/environment.plist file. I then logged out and back in again and managed to replicate your error:
cannot find gnuplot in your PATH

Seems like your enviroment.plist is setup incorrectly, can you post it?

If this isn't the answer, I'm not to sure what is? Are you using a new version of gnuplot and aquaterm? The only other thing I can think of is that you are using X11 terminal rather that 'termial'; you see they have seperate enviromental variables. I ran into this problem once, I set the the DYLD_LIBRARY_PATH in the terminal and then when I changed to X11 terminal it didn't have clue what I was meaning! I really don't think that is the case here I'm just racking my brain for possibilties.

Dan.
 
Back
Top