# Introduction

This is the FAQ ("frequently asked questions") document for the Gri scientific graphing language, (c) 1991-2003 Dan Kelley, to whom you are asked to email reports of Gri errors, or suggestions for Gri improvements or new features.

# The Questions

## A1 Features

### A1.1 What is Gri?

Gri is a program for drawing scientific graphs. It makes xy plots (linegraphs and scattergraphs), contour plots, and image plots. Unlike many scientific plotting packages, Gri provides precise control over fonts, line widths, grayscales, colors, etc. Since Gri was written by a scientist, it does the kinds of plots scientists want. It has few frills; e.g., it does not do 3D mesh plots, because the author dislikes them. Gri is command-driven, not mouse driven.

### A1.2 What does Gri' stand for? How is it pronounced?

Gri stands for gr-interactive', and gr' is the name of a subroutine library that preceded Gri. The interactive' adjective indicates that Gri can be used interactively -- that is, Gri is an interpreted language whereas Gr is a compiled language. Gri' rhymes with tree'.

### A1.3 What does Gri cost?

Gri is free. A commercial version, called Gre will be made available soon. It contains most of Gri as a subset, but also contains quite a lot of the Perl language as well, making it a fully functional and efficient programming language.

### A1.4 How long will it take to learn Gri?

Most users can get Gri working after spending half an hour with manual (see Q2.1). Familiarity with your operating system (for example for viewing PostScript files) will speed this somewhat. After that, it's best to learn new features only as you come to need them. To begin with, you should skim the manual and the cookbook (see Q2.3), looking just at the illustrations. This will take no more than an hour.

The Gri manual is like most computer manuals: it would be a waste of time to read it cover to cover before starting to use Gri. But you'll find the manual helpful as you branch out, modifying the existing examples and inventing code of your own.

Learning how to use a new command usually takes only a minute but realizing that the command exists can take longer. That's why many users with sophisticated needs find it useful to spend an afternoon leafing through the entire manual at some point.


## A2 Documentation

### A2.1 Is there a quick-reference card for Gri?

Yes, two quick-reference cards are stored on the Gri development site http://gri.sourceforge.net, and these are also installed when gri is installed.

### A2.2 Where can I get documentation for Gri?

Full documentation is available in several forms on the Gri development site Gri development site http://gri.sourceforge.net, Check out the FAQ file (which you are reading now), reference cards (see previous answer), etc.

The Gri manual is available on the WWW (world wide web) at the URL http://gri.sourceforge.net/gridoc/html/index.html .

### A2.3 Is there a cookbook of Gri programs to use for guidance?

Yes, at the website http://gri.sourceforge.net/gri-cookbook/index.html

### A2.4 Is there a newsgroup for Gri?

Gri has several discussion forums at the development site http://gri.sourceforge.net, and users are highly encouraged to participate!

### A2.5 Where can I get some sample Gri input files?

Sample files are scattered throughout the Gri manual and cookbook; the manual also contains a test-suite that you may find helpful in learning the language syntax, especially for programming.

## A3 Can Gri do ... ?

### A3.1 Can Gri do barcharts?

Gri has no specific command for barcharts, but the operating system can easily rearrange your data into a form that lets Gri draw barcharts. In the following example, the synonym \width is set to the desired width of the bars and \missing is set to an arbitrary missing value. The rest of the code will make sense to any Perl programmer. If you don't know Perl, you should learn it.

\width = "1"                    // width of bars, in x units
\missing = "-99"                // missing value
set missing value \missing
set x axis 0 6 1
set y axis 0 20 10
draw axes none                  // will get whited out by the chart anyway

// Create dataset
system cat > barchart.dat << "EOF"
1 12
2 14
3 15
4 13
5 10
EOF

// Create barchart style dataset and plot it
system perl <<"EOF"
open (IN, "barchart.dat") || die "Cannot open barchart.dat";
while(<IN>) {
($x[$i], $y[$i]) = split(' ');
$i++; }$n = $i; open (TMP, ">tmp") || die "Cannot open tmp"; for ($i = 0; $i <$n; $i++) { print TMP$x[$i] - \width / 2, " ", 0, "\n"; print TMP$x[$i] - \width / 2, " ",$y[$i], "\n"; print TMP$x[$i] + \width / 2, " ",$y[$i], "\n"; print TMP$x[$i] + \width / 2, " ", 0, "\n"; print TMP \missing, " ", \missing, "\n"; } EOF open tmp read columns x y set graylevel 0.95 draw curve filled to 0 y set graylevel 0 draw curve draw axes draw title "Demonstrate Gri barchart" ### A3.2 Can Gri do histograms? Gri has no specific command for histograms, but the operating system can easily rearrange your data into a histogram format. Here is Gri code to do it: open "histogram -l 0 -h 10 -i 0.5 < inputfile |" read columns x y // y is number of obs draw curve filled to 0 y where histogram is a perlscript which creates a histogram file named inputfile. An example of histogram is: #!/opt/bin/perl # Calculate histogram of 1-column data$usage ="\
NAME\
histogram -- create histogram file, given data file (1 column)\
\
SYNOPSIS\
histogram -l low -h high -i increment < input_file > output_file\
\
DESCRIPTION\
Scans the input values and finds the percentage of data in bins\
starting at value low', ending at value high', and incrementing by\
value inc'.\
\
FILES\
Standard input:  column of numbers\
Standard output: columns: (bin_centre, per, cum_per, num, cum_num)\
where 'per'=percentage and 'num'=number.\
";
require "getopts.pl";
$opt_l = 0;$opt_h = 0;
$opt_i = 0; &Getopts('l:h:i:'); die "You must supply commandline arguments!\n$usage" if ($opt_l ==$opt_h || $opt_i == 0);$n = ($opt_h -$opt_l) / $opt_i; print STDERR "Will have$n bins, running from $opt_l to$opt_h in steps of $opt_i\n"; for ($i = 0; $i <=$n; $i++) {$bin[$i] = 0; } while(<>) { chop; ($x) = split;
$i = int(0.5 + ($x - $opt_l) /$opt_i);
$i = 0 if ($i < 0);
$i =$n if ($i >$n);
$bin[$i]++;
}
for ($i = 0;$i <= $n;$i++) {
$x =$opt_l + $opt_i * ($i - 0.5);
print "$x$bin[$i]\n";$x = $opt_l +$opt_i * ($i + 0.5); print "$x $bin[$i]\n";
}

### A3.3 Can Gri do error bars?

Gri has no specific command for error bars. It has no internal representation of error bar data -- that is, you can't get them by a read columns command. However, you can get error bars quite easily, simply by reading the data line by line, plotting each one as individually. Here's an example of error bars in y, where the third column stores the error:

open a.dat
while 1
if ..eof..
break
end if
draw symbol bullet at .x. .y.
draw line from .x. {rpn .y. .ey. -} to .x. {rpn .y. .ey. +}
end while

### A3.4 Can Gri draw labels for Tukey box plots?

Yes. Here is sample code, in which a label "My Label" is drawn to the right of the median of a Tukey plot extending in the y direction:

1 11
2 22
1.2 3
3 5
2 20
3 10

draw y box plot at 2
draw label "My Label" at {rpn 2 xusertocm 0.4 +} \
{rpn y median yusertocm "M" ascent 2 / -} \
cm

### A3.5 Can Gri read compressed data files?

Yes, as of version 2.6 Gri can read compressed files, e.g.

open myfile.gz
will work. You may also, of course, do
open "zcat myfile.gz |"
if you like.

### A3.6 Can Gri use scientific notation on axes?

You have to trick it. Here's an example:

// NOTE: this requires manual setting of axes.
1 1.1e3
2 1.0e3
3 1.4e3
4 2.3e3
4 1.0e4

y /= 1e3
set y axis 1 5 1
set y format "%g$\times10^3$"
draw curve

### A3.7 Can Gri label x-axis with day of week?

A future version of Gri will have much more powerful and general ways of handling axes labelling. In the meantime, you have to trick Gri to get such special effects. Here's an example:

set x axis 1 8 1
set y axis 0 1 .1
set font size 0
draw x axis at top
draw y axis at right
draw x axis at bottom
set font size 12
draw y axis at left
draw label "Mon" centered at 1.5 {rpn ..ymargin.. 0.7 - ycmtouser}
draw label "Tue" centered at 2.5 {rpn ..ymargin.. 0.7 - ycmtouser}
draw label "Wed" centered at 3.5 {rpn ..ymargin.. 0.7 - ycmtouser}
draw label "Thu" centered at 4.5 {rpn ..ymargin.. 0.7 - ycmtouser}
draw label "Fri" centered at 5.5 {rpn ..ymargin.. 0.7 - ycmtouser}
draw label "Sat" centered at 6.5 {rpn ..ymargin.. 0.7 - ycmtouser}
draw label "Sun" centered at 7.5 {rpn ..ymargin.. 0.7 - ycmtouser}
Note that the offset of 0.7 centimeters looks OK to me, with a 12 point font, but you may wish to experiment if you don't like the placement.

### A3.8 Can Gri draw maps?

Gri can draw maps, but it lacks builtin support for map projections. (A previous version had projections, but they were not working correctly and were removed.) Gri does not have builtin coastline files, either. Many good coastline files are on the web; see, for example, Rich Signell's site http://crusty.er.usgs.gov/coast/getcoast.html or the USGS mapping site http://www.usgs.gov or the Global Self-consistent Hierarchical High-resolution Shoreline site http://www.ngdc.noaa.gov/mgg/shorelines/gshhs.html

### A3.9 Can Gri draw residuals on regressions?

There is no builtin command for that, but it's easy enough to code, as follows:

0.05 12.5
0.25 19
0.5  15
0.75 15
0.95 13

draw regression line
# Draw the residuals individually
.i. = 0
while {rpn .i. ..num_col_data.. >}
.x. = {rpn x .i. @}
.y. = {rpn y .i. @}
.ypred. = {rpn .x. ..coeff1.. * ..coeff0.. +}
draw line from .x. .y. to .x. .ypred.
.i. += 1
end while

## A4 Gri and other programs

### A4.1 Is Gri better than Fortran/C/... plotting subroutines?

Gri started out as a set of subroutines. The set is called gr'; the name gri' means gr-interactive. Although I wrote both gr' and gri', I haven't used gr in years. I am unaware of anybody else who ever used gr'. Thus, in at least this case, the interpreted Gri language is superior to subroutines.

In some applications the graphics are hard-wired into the computation so using Gri might not make sense. An example is the SPEM numerical model, which has builtin NCAR plotting calls. But this approach is inefficient in user-time and computer-time, because changing the format of the output may require re-running a model. The best approach is to decouple preparation of data from presentation of data.

In highly interactive applications, such as many uses of matlab and statistical programs such as S and S-plus, it may make sense to use the builtin graphics routines because they are so tightly bound to the processing.

### A4.2 How can I include Gri plots in LaTeX/Word/... files?

#### Latex

There are several schemes for including PostScript figures, such as those created by Gri, into LaTeX files. That's unfortunate, in the sense that it can confuse folks who are not experts. The example below works great at the moment, but 5 years ago a typical user might have another command instead of includegraphics, and 5 years from now there may be something new. Still, I've found that decade-old LaTeX files still work for me, so you shouldn't worry about the chagnes.

The example below includes the file fig.ps as a figure. To test this, you may run a Gri script named fig.gri consisting of the single command draw axes, and then save the following into a file named test.tex, and then run LaTeX on it, which in unix would mean typing latex test at the prompt.

\documentclass{article}
\usepackage[dvips]{graphicx}

\begin{document}

\begin{figure}
\includegraphics{fig.ps}
\caption{Isn't this a nice graph?}
\end{figure}

Nice graph, eh?

\end{document}

It is worth noting that LaTeX has handled graphics in various ways over the years. The above indicates the preferred scheme as of 2001 or so, but other older schemes still work.

#### MS Word

All you need to do is to convert the file to GIF or PNG (see the next question), or to another file format that MS word handles. It is a bad idea to use a JPEG format, since that doesn't work well on linegraphs.

### A4.3 How may I convert Gri output to GIF format?

Conversion of the Gri PostScript output to GIF is normally done for inclusion in web-pages. For a discussion of the merits of various image formats, see Information Architecture. I have been told that GIF images suffer from both technical limitations (no gamma value is stored in the file) and license restrictions. The PNG format was designed to overcome these limitations, and is expected to replace GIF over time.

It should also be noted that there is no generally acceptable way to convert PostScript to gif, especially when the PostScript is vector based. One problem is that of resolution: if the output GIF is low-resolution, then the text may be drawn roughly because of rasterization. In many convertors one may specify the size of the output image, which permits control over this resolution problem, giving the user the task of weighing file size against output quality. Note also that the colour table frequently gets reordered in the conversion, possibly leading to inaccurate results. Simply stated, PostScript is superior to GIF and other raster-based formats. That's why Gri chose PostScript for the output model.

There are several ways to convert Gri PostScript into GIF or PNG images.

• METHOD 1. Use the convert program, which is a part of the ImageMagick set of software. The convert software is quite powerful, being able to convert from almost any format into almost any other, e.g.
$convert gri-1.ps gri-1.png If the output is to be used for the web, the above is fine. If it's to be imported into a word processor such as MS-Word, then the pixel resolution is insufficient because the default is 72 dpi. Try this instead:$ convert -density 300x300 gri-1.ps gri-1.png

The ImageMagick software is free, and available on the world-wide-web at URL http://www.wizards.dupont.com/cristy/ImageMagick.html

• METHOD 2: The GNU program gs can also do this conversion. In newer versions, this conversion to GIF is builtin. Here is a shellscript
#!/usr/bin/sh
gri -y -p -b $1.gri gs -q -dNOPAUSE -sDEVICE=ppm -sOutputFile=$1.ppm $1.ps -c quit ppmtogif -interlace -transparent rgb:ff/ff/ff$1.ppm > $1.gif rm -f$1.ppm

• METHOD 3: In older versions of gs, you must run a little program in the gs interpreter, by typing

## A6 Gri on various computers

### A6.1 What computers does Gri work on?

Gri has been ported to several Unix machines (e.g. Sun solaris and sunOS; IBM RISC; HP RISC; SGI; DEC alpha; and x86 linux) and to x86 MS-DOS. An old version is available for DEC vax VMS.

### A6.2 What kind of compiler is required to compile gri?

Gri requires a C++ compiler capable of handling the language feature called "templates," and it also needs the so-called "standard template library" (STL). Templates have been a feature of C++ since about 1994, and STL became part of the draft C++ library standard in early 1996. If your compiler vendor does not support templates or STL, you should obtain a newer compiler.

The free C++ compiler called g++, available from the Free Software Foundation, is known to compile Gri on at least a half-dozen problems. The compiler version must be 2.7.2 or higher for success.

### A6.3 Why can't I link my compiled gri? (on HP computer)

Unfortunately, I made a bad programming decision several versions ago -- I decided to start using the STL (the standard template library). The STL is part of the draft ANSI C++ standard, so I figured I'd be safe. And my tests on solaris and linux platforms indicated that STL worked as advertised, in g++ 2.7.x. However, I should have checked further. It turns out that g++ on some platforms (e.g. HP's unix and IBMRS's AIX unix) does not handle templates properly. The linker cannot locate templates defined in one file and used in another. This issue is discussed at some length in the g++ documentation, where three methods are presented for solving the problem. (In the info-format documentation, you can find the relevant parts by searching for the string "where's the template?") In Gri I've used what method 3 as defined in the g++ manual. Apparently this fails on some platforms. Although I'd welcome tests by users on the other two g++ methods, and I'd be happy to switch if one of them appeared to work more universally, I have to say that I'm not optimistic: from what I read on the newsgroups, nobody is having much success on this. The GNU folks say that g++ version 2.8 will handle templates much better, so I'm waiting for that. Unfortunately it's been, so far, a two-year wait.

Almost certainly, commercial compilers handle templates better, but I lack resources to purchase these for the various platforms. I'd be happy, though, to act as a broker for anyone who is able to compile Gri on the problematic platforms, and who is willing to share their results.

### A6.4 Is there a Macintosh version of Gri?

There once was a clicky-pointy Macintosh version of gri, but I got frustrated with modifying the code each time Apple upgraded the OS and stopped maintaining the code. After several years of living (happily) without the Macintosh, I flushed the Mac code down the drain.

### A6.5 Is there a DOS/Windows version of Gri?

Versions of Gri have been available for MSDOS/Windows platforms for years, kindly provided by Gri users with MSDOS/Windows machines. In summer 2001, the porting procedure was systematized within the GnuWin32 project. This project provides win32 ports of GNU tools. It has been keeping very up-to-date with Gri development, trailing the Unix versions by only a week or so. Please visit http://gnuwin32.sourceforge.net for more on the GnuWin32 project, and to download Gri (and other GNU software) for your windows platform.

If, for some reason, you'd like to compile your own MSDOS/Windows version, check the Gri manual under the heading Compilation on x86 (PC-style) Computers.

As for viewing Gri output, I recommend obtaining a copy of the Ghostview program (which is a general PostScript display program), in the version called GSview.

### A6.6 Is there a linux version of Gri?

For non-RedHat versions of linux, one compiles and installs Gri in the usual way; see the manual for more details.

Users of RedHat linux have it much easier though! A RPM (RedHat Program Manager) version of Gri exists, so that installing it takes just one line of typing, or one mouse-click in a GUI interface to RPM.

The RPM (RedHat Package Manager) version exists at the Gri development site http://gri.sourceforge.net, Once you've downloaded this, install Gri by typing

rpm -i gri-2.1.17-1.i386.rpm
Later on, Gri may be uninstalled ('extracted') by typing
rpm -e gri

Knowledgeable RedHat users will know that RPM can also give information about Gri; for non-experts, here are a few examples:

rpm -qa       --  list all installed packages
rpm -qi gri   --  summarize gri capabilities (if it's installed)
rpm -ql gri   --  list all files related to gri

## A7 Gri bugs

### A7.1 What are known bugs in Gri?

Gri is used daily by many users, including the author, so that it suffers few serious bugs. Generally, more recent versions of Gri suffer fewer bugs than earlier versions. This improvement owes much to the trial of daily usage by folks with differing working styles; and all users can thank those who send in bug reports (see Q7.2).

One of the main problems with recent versions of Gri is that line numbers of syntax errors are reported inaccurately, if the error occured inside a new-command.

A list of Gri bugs is maintained in the manual.

### A7.2 How can I report Gri bugs?

The first step is to make sure it is actually a bug. You might try, for example, posting a question to the Gri newsgroup (see Q2.3), and getting advice from other users. Please be clear, so you don't waste others users' time. If you think you've found a bug, let the author know. Here's the advice from the manual (see especially item 4, for directions on emailing bug reports):

Your bug reports help make Gri reliable and useful. Reporting bugs often results in quick changes to gri which will solve your problem. This is especially true if your version is reasonably up-to-date, for then you can simply get the corrected version and replace the version you were using. Here is how to report bugs.

The details of how to report bugs is in the online documents , but the quick answer is to go to the Sourceforge Gri/bug site and use the slick GUI interface there.