macdevcenter.com
oreilly.comSafari Books Online.Conferences.

advertisement

AddThis Social Bookmark Button

Unix Gems for Mac OS X
Pages: 1, 2, 3, 4

To change the format of the plot, you can use any one of GNUPlot's formatting commands. Here are some examples. (Switch your terminal back to aqua, set term aqua, before running these commands).

gnuplot> set title 'Test Plot'
gnuplot> set style function linespoints
gnuplot> plot sin(x)

These example show how to create plots interactivity within GNUPlot. All of this requires a lot of typing. Another way to use GNUPlot is to save all your data and commands in files and tell GNUPlot to process the files to produce the plot. This is a very powerful technique since you can write code to generate these files on the fly and feed them to GNUPlot automatically.

Let's take a look at how this works. Imagine you are developing a program and would like to plot its CPU usage. To accomplish this, we need a script that captures the process' CPU usage and another script that takes this data and plots it using GNUPlot.

For this example, we'll use 3 programs. The first is called fibonacci, a C program that generates the fibonacci series. The other two programs are scripts that acquire CPU information and plot the data. One is called logger.py, which collects CPU usage while the fibonacci program runs and writes it to a file. The other script is called plotCPU.py. It writes a plot format file and calls GNUPlot to display the plot of CPU usage.

To use these scripts, you need to open two shells. In the first shell, compile the fibonacci program (gcc -o fibonacci fibonacci.c). Next, run the fibonacci program by typing fibonacci at the prompt. While fibonacci is running, type the command python logger.py fibonacci 1 > fibonacci.dat in the second shell.

Once the fibonacci program exits, Ctrl-C out of the logging script. Finally, run plotCPU.py to generate the plot (python plotCPU.py).

There are lots of other things you can do with GNUPlot like generating 3D and multi-plot. If you ever need to visualize data, definitely check out GNUPlot. It's very powerful when combined with scripting languages like Perl and Python and is a natural addition to the development process.

Miscellaneous Programs

Before concluding, I'd like to mention two other programs I really like. The first is called bc, an arbitrary precision calculator language. If you are at the command line and need to perform some quick calculation, or possibly need more power than the calculator that comes with Mac OS X, take a look at bc.

The bc program supports arbitrary precision numbers and is great for complex, as well as simple calculations. In addition to being an interactive calculator, its also a language with a similar syntax to "C."

Here are some simple examples of bc in action:


% bc
12+54
66
x=2
y=3.123
z = x*y
z
6.246
scale=100
12/9
1.333333333333333333333333333333333333333333333333333333333333333333\
3333333333333333333333333333333333
scale=10
12/9
1.3333333333
z = 12/9
"z = "; z
quit
%

To exit bc, type quit or Ctrl-d. Take a look at the bc man page and the resource section of this article for more information.

A useful feature of Apple's TextEdit program is you can set it up to check spelling as you type. This way, if you misspell a word, you are notified immediately and can make the corrections right a way.

If you use Emacs for your writing, you can get the same functionally by using Flyspell. Flyspell is an Emacs minor mode that enables Emacs to perform spell checking and correction as you type.

Flyspell has lots of features. You can select your own dictionary, it works great with LaTeX, and can be set up to only check certain types of files. This way, it only checks your spelling for text and LaTeX files for example, and not source code; very useful.

Flyspell is very easy to set up so check its documentation for more information on installation and use.

Final Thoughts

There you have it, a look at some very useful Unix-based programs that you can use under Mac OS X. In this article, I only covered a few of my personal favorites. As you can imagine, there are lots of others waiting to be discovered. Check out the Resources section for information on where you can discover more.

Resources

GNU Screen

Remind

GNUPlot

bc

Flyspell

Other Resources