OS/2 eZine - http://www.os2ezine.com
Spacer
June 16, 2002

Do you have an OS/2 product or service you'd like to advertise?


gnuplot

First of all, gnuplot is not related to GNU (Gnu's Not Unix) project or the FSF (Free Software Foundation) in any way. It's gnuplot, not GNUplot. There's a story about this, but you should probably read about this for yourself at the gnuplot FAQ (ftp://ftp.ucc.ie/pub/gnuplot/faq/gnuplot-faq.html). It is freeware (though not necessarily open-source, as the FAQ notes.) I'm not sure if the situation has changed, as the development files are now being hosted at Sourceforge->gnuplot (http://sourceforge.net/projects/gnuplot/). So any of you OS/2 programmers out there with time on your hands, here's something to do!

What is gnuplot?

gnuplot is a command-line plotting package. It's available on many platforms including various UNIX's, Linux, Windows, and, of course, OS/2. In fact, a lot of the new, cool features in gnuplot were part originally made first as special extensions for OS/2.

Now wait, before you brush off a command-line program, you have to understand what it is used for. gnuplot is mainly for scientific plotting, so you are not usually pushing around a bunch of data as you would in a spreadsheet. Typically, one might be wanting to plot mathematical functions such as fx = sin(2*pi*f*t)*exp(-4*t). So, if anyone can think of a better way to enter this in the computer other than a command line, let me know! (Well, I guess some might argue that hand-writing recognition would be better.)

To install gnuplot on OS/2, it's pretty much just unzip and run the executable. (Note: emx.dll is required, but nearly all OS/2 users will probably have this already.) You will likely want to add the gnuplot directory to your path in the CONFIG.SYS, as this will be important when interfacing with other programs later. The package comes with a bunch of documentation on installation and compilation and such, most of the installation notes pertain to UNIX/Linux, but there are a few scattered OS/2 notes in there. Not that it's a big loss, since there's not much to worry about with OS/2.

When you run the executable, you're put into a command-line window.

gnuplot command window

From this window, you can simply enter your commands at the prompt, or, type quit to exit the program. (Note: gnuplot is case-sensitive.) If you're worried about it being antiquated, don't! As mentioned before, this is still the preferred method of entering the information. A very expensive commercial package, Matlab, still does exactly the same thing, even though Matlab does do much more than just plot. (The latest version of Matlab that was recently released has been prettied up slightly, but it's still just a command-line window you work from.)

Using gnuplot

gnuplot comes bundled with some documentation and a few demos to help you get started. For more advanced functions, you should really grab a gnuplot tutorial. However, in general, it's pretty easy to use, just type whatever you want to do on the command line. For example, just typing: plot(sin(5*x)) will produce just what you might expect, a plot of a sine wave. If you have more complicated functions or a series of commands to enter, you can always save it in a text file and have gnuplot load the file and execute it.

gnuplot is also capable of plotting discrete data. If you have a text file with columns of data, it's just a simple matter of typing the command: plot 'MyData.txt', for example, and it will plot your data (and error bars too, if you wish.) It requires that your data be separated in columns (e.g. with tabs, spaces, comma, etc,) but that's not uncommon. It would probably be a little strange if your text data weren't sorted in such a fashion!

If you're willing to put in a bit of learning effort, you'll find that gnuplot is capable of some fairly complicated stuff, including some impressive looking 3-D figures. The appropriate command to use here is splot instead of plot, but the syntax remains the same.

gnuplot of interlocking tori

I couldn't figure out how to get solid-surfaces working, it just sits there "thinking" forever until I hit CTRL-C. But that, I think, is an issue with the development version (or my video drivers.) But as this plot from Petr's page demonstrates, it is capable of generating some very nice looking plots.

gnuplot 3D surface plots

But, there is still a bit more! gnuplot can not only generate static plots, but also produce simple animations as well. While certainly impressive, it is more than just eye candy, and can be used to visualize parameter variations or time development of some functions. A nice demo called "animate.dem" is included in the package which will show you how it's done. Just type: load 'animate.dem' and the demo will automatically run. You're not going to be making "Shrek" with this, but it will handle data visualization. For those of you who don't usually do this, you ought to give it a shot. The world's most powerful computer is sitting on your shoulders, and you'd be amazed what kind of insights can arise when you can see a visual simulation. (Just for example, I could describe the path of a football in the air, accounting for wind-speed, ball-wobble, gravity, etc. with a very complicated equation. But any child, just by watching the path of motion, can predict exactly where to go to intercept and catch it on the ground.)

If you ever forget how to do something, help is available by typing the very cryptic command help on the command line. Just help will give you a list of topics available. If you ask for help on a command, for example help splot, it will give you a summary of what the command does and the appropriate syntax. All help information is presented on the command line window, and there is no search facility. Is this somewhat primitive? Yes. Could it be better? Yes. But hey, you know what? Matlab is exactly the same, and up until very recently, Maple and Mathematica (also two other expensive math packages) don't do very much better. I don't know why this is so, maybe this is left over 'tradition' from the UNIX world and their man pages.

End Notes

This isn't meant to be a tutorial for gnuplot, just to make you aware of its existence and capabilities, so if gnuplot sounds useful, you really ought to go read through the FAQ and dig up a nice tutorial.

At less than 3MB of disk space and freely available, you should keep this tool in your arsenal! It will easily handle much of what you ask it to do, and it's a pretty "standard" tool that's available on plenty of platforms.

The current stable version is 3.7.1, which you can find on the gnuplot FTP site (ftp://ftp.ucc.ie/pub/gnuplot/). The latest development version, 3.8i, is not very stable (in my experience,) but since it adds quite a few useful new features (such as drag 'n drop of fonts onto the graph and solid surface plotting,) it may be worth your time to use the latest version, or perhaps keep both installed. Precompiled binaries of 3.8i can be downloaded from Petr Mikulik's gnuplot download page (http://www.sci.muni.cz/%7Emikulik/gnuplot/).


Where to get gnuplot

gnuplot FTP site (ftp://ftp.ucc.ie/pub/gnuplot/) - pre-compiled binaries of stable release.
Petr Mikulik's gnuplot download page (http://www.sci.muni.cz/%7Emikulik/gnuplot/) - pre-compiled binaries of latest development release.

Related Links

Sourceforge (http://sourceforge.net/projects/gnuplot/) - source code for gnuplot.
gnuplot FAQ (ftp://ftp.ucc.ie/pub/gnuplot/faq/gnuplot-faq.html)
Petr Mikulik's OS/2 gnuplot pages (http://www.sci.muni.cz/%7Emikulik/gnuplot.html) - information and screenshots of gnuplot.


Isaac Leung (mailto:atomic_frogii@yahoo.ca) got a degree in Engineering Physics and then Electrical Engineering after which he promptly got a job as a product engineer at a company which makes high speed datacom chips. He is old enough to have cut his computer teeth on Commodore 64's and first played with OS/2 1.3 EE while at a summer job with IBM. The first PC he ever owned came with Windows 95, but he soon slapped on OS/2 Warp 3 and has been Warping ever since. In his spare time, he plots to take over the world.

This article is courtesy of www.os2ezine.com. You can view it online at http://www.os2ezine.com/20020616/page_5.html.

Copyright (C) 2002. All Rights Reserved.