1\input texinfo
2
3@c
4@comment *** Start of HTML stuff ***
5@comment # HTML support, via comments in texinfo:
6@comment #
7@comment #   `@c HTML some-stuff'
8@comment #       Pass "some-stuff", or in other words all the text following
9@comment #       the HTML token on the same line, directly to the output file.
10@comment #
11@comment #       For example, you might do one of the following:
12@comment #
13@comment # (1) Let user see gif image.
14@comment #       @c HTML <A HREF="file.gif">Click to see plot</A> <P>
15@comment #
16@comment # (2) Let user ftp to a location.
17@comment #       @c HTML <A HREF="ftp:#location">the Gri FTP site.</A> <P>
18@comment #
19@comment # (3) Ignore some texinfo stuff.
20@comment #       @c HTML <!--
21@comment #       some texinfo lines
22@comment #       @c HTML -->
23@comment #
24@comment # (4) Create new file, possibly named and titled.
25@comment #       @c HTML <!-- newfile filename "other_words_for_title" "margin_note" -->
26@comment # if it occurs on a line all by itself, causes
27@comment # this perlscript to chop files here.  The filename
28@comment # will be as specified.  The other_words
29@comment # will be used as the title.  If neither the
30@comment # filename nor the other_words are present, then
31@comment # this script makes up filenames using numbers, e.g.,
32@comment # gri1.html, gri2.html.  If the filename is ".",
33@comment # then this same naming scheme is used, but the titles
34@comment # are used.
35@comment #
36@comment # (5) Plant a comment to be stripped out as a latex command
37@comment #     @c HTML <!-- latex: some-stuff -->
38@comment *** End of HTML stuff ***
39@c
40@comment OVERRIDE some defaults in texinfo.tex
41@documentencoding ISO-8859-1
42@iftex
43@message{}
44@message{gri.texi: overriding parskip, }
45@global@parskip=4pt             @c space between paragraphs
46
47@message{overriding baselineskip, }
48@global@baselineskip=12pt       @c line spacing
49@message{overriding lispnarrowing }
50@c @global@lispnarrowing=0.2cm  @c left margin on examples
51@global@widowpenalty=10000      @c Prevent widows
52@global@clubpenalty=10000       @c Prevent orphans
53
54
55@message{}
56@end iftex
57@comment %**start of header
58@setfilename gri.info
59@settitle Gri
60@set GRI-VERSION 2.12.23
61@set GRI-PREVIOUS-VERSION 2.12.22
62@set AUTHOR-EMAIL dankelley@@users.sourceforge.net
63@include version.texi
64@c %**end of header
65@iftex
66@finalout
67@end iftex
68@setchapternewpage odd
69@titlepage
70@title Gri
71
72@ifnottex
73@image{./examples/logo}
74@end ifnottex
75
76
77
78@subtitle A Program to Make Science Graphs
79@subtitle Version @value{GRI-VERSION}
80@subtitle 2011
81@author Dan E. Kelley
82@page
83@vskip 0pt plus 1filll
84Copyright @copyright{} 1991-2011 Dan Kelley
85@sp 2
86@end titlepage
87
88@dircategory Scientific Applications
89@direntry
90* Gri: (gri).  Programming language for scientific illustration
91@end direntry
92
93@summarycontents
94@contents
95
96
97@node   Top, Introduction, (dir), (dir)
98@comment node-name, next, previous, up
99@top Gri
100@c HTML <!--
101
102Gri is an extensible plotting language designed for scientists.  It can
103draw x-y plots, contour plots, and image plots, and has rudimentary
104programming capabilities.  It is not mouse driven, nor gui-based;
105rather, it is an interpreted scriping language.  Users regard it as an
106analogue to the latex document formatting language: users gain
107considerable power, at the price of a moderate learning curve.
108
109This manual describes Gri version
110@value{GRI-VERSION} @c , updated @value{UPDATED},
111(c) 1991-2011, Dan Kelley
112
113Gri is released with the GNU Public License (@ref{License}).
114
115@c HTML -->
116
117@c HTML <map name="navigate_top">
118@c HTML <area alt="Introduction" shape="rect" coords="581,2,599,24" href="Introduction.html">
119@c HTML </map>
120@c HTML <map name="navigate_bottom">
121@c HTML <area alt="Introduction" shape="rect" coords="581,2,599,24" href="Introduction.html">
122@c HTML </map>
123@c HTML
124@c HTML <A HREF="logo.html">
125@c HTML <IMG align=left ALT="Gri Logo" SRC="logo.png"></A>
126@c HTML Gri is an extensible
127@c HTML plotting language for producing scientific graphs, such as
128@c HTML <A HREF="X-Y.html">x-y plots</A>,
129@c HTML <A HREF="ContourPlots.html">contour plots</A>, and
130@c HTML <A HREF="Images.html">image plots</A>.
131@c HTML <p>
132@c HTML This document describes Gri @value{GRI-VERSION},
133@c HTML <br>(c) 1991-2008 <A HREF="http://www.phys.ocean.dal.ca/~kelley"> Dan Kelley.</A>
134@comment HTML Gri is distributed
135@comment HTML with a <A HREF="License.html">license</A> that permits
136@comment HTML sharing in an OpenSource way.
137@c HTML <p><br>
138@c HTML <b>New users:</b>
139@c HTML To see if Gri might be useful to you, spend a few minutes
140@c HTML reading the
141@c HTML <A HREF="Introduction.html">introduction</A>, the
142@c HTML <A HREF="SimpleExample.html">simple example</A> tutorial, the
143@c HTML <A HREF="./FAQ.html">FAQ</A> and the
144@c HTML <A HREF="http://gri.sourceforge.net/gri-cookbook/index.html">
145@c HTML cookbook.</A>
146
147@c HTML It is also a good idea to check out the real-world
148@c HTML <A HREF="Examples.html">examples</A>.
149@c HTML Then you should return here to scan the table of contents.
150@c HTML <P>
151@c HTML <b>Experienced users:</b>
152@c HTML To check the syntax of a command, consult
153@c HTML the <A HREF="ListOfGriCommands.html"> list
154@c HTML of Gri commands</A>.  See
155@c HTML the <A HREF="History.html">history</a>
156@c HTML to learn how Gri has changed over time.
157@c HTML <p>
158@c HTML <b>Open-Source Development:</b>
159@c HTML Gri is distributed under an OpenSource licence (GPL).
160@c HTML To monitor (or contribute to) the development
161@c HTML process, visit
162@c HTML <a href="http://gri.sourceforge.net">
163@c HTML <tt>gri.sourceforge.net</tt></a>.
164@c HTML <p>
165@c HTML <b>See also:</b>
166@c HTML The <a href="http://www.phys.ocean.dal.ca/~kelley/gre">
167@c HTML Gre language</a> combines Gri features with Perl features.
168@c HTML <br>
169@c HTML <!--
170@menu
171* Introduction::                What Gri is for
172* Simple Example::              Introductory example
173* Invoking Gri::                Running/viewing/printing Gri
174* Getting More Control::        Controlling axes, text, color, etc.
175
176* X-y Plots::                   Drawing x-y linegraphs/scattergraphs
177* Contour Plots::               Drawing contour plots
178* Images::                      Drawing black+white or color images
179
180* Examples::                    Some real-world examples
181* Handling Data::               Dealing with oddly-configured data
182* Commands::                    All about the many Gri commands
183* Programming::                 How to program in the Gri language
184* Environment::                 Related tools
185* Emacs Mode::                  Editing Gri code inside Emacs
186* History::                     How Gri has changed over time
187* Installation::                How to install Gri
188* Bugs::                        How to report on bugs
189* Test Suite::                  Series of test programs
190* Gri in the Press::            Further reading
191* Acknowledgments::             Many folks have helped me with Gri
192* License::                     Gri is open-source!
193
194Three indices
195* Concept Index::               Detailed index
196* Index of Commands::           Commands in Gri
197* Index of Builtins::           Builtin variables
198@end menu
199@c HTML -->
200
201@c HTML <!-- newfile Introduction.html "Gri: introduction" "Introduction" -->
202
203@node   Introduction, Simple Example, Top, Top
204@comment  node-name,  next,  previous,  up
205@chapter Introduction
206
207@strong{Gri is a programming language for drawing science-style graphs}.
208It is not mouse-driven, and it does not draw business-style graphs
209(e.g. pie charts, three-dimensional graphs).  Gri has substantial power
210in advanced applications.  It has been proven to be easy to learn; for
211simple applications, the learning curve is less than an hour.  Many
212users regard Gri as the plotting equivalent of the La@TeX{} document
213preparation system.
214
215@strong{Computers Gri works on:} unix computers of many types, plus
216Microsoft Windows, and Macintosh OSX.  You'll find Gri pre-packaged
217for various unixes, e.g. linux/debian, linux/redhat, and freeBSD.
218
219@strong{Capabilities of Gri} are those scientists commonly want, since Gri
220was written by a scientist.  It is not so useful for business people --
221e.g., Gri draws xy graphs (@ref{X-y Plots}), contour plots
222(@ref{Contour Plots}), and image plots
223(@ref{Images}), but it will
224not draw pie-charts unless you teach it how.  The list of capabilities
225of Gri is similar to many packages, but unlike many of the other
226packages, Gri gives you control over line widths, fonts, grayscales,
227etc.  (@ref{Getting More Control}), and it is a programming language
228of moderate power.
229
230@strong{The Gri drawing metaphor} is that of pen on paper.  The ink in the
231pen is opaque.  An item drawn in white ink will erase a previously drawn
232underlying object drawn in black ink.  For example, to draw a timeseries
233curve in which the region between positive data values and the y=0 axis
234is filled with black ink, you might use (@code{draw curve filled}) to
235draw the timeseries with black ink (the default color), blackening the
236area between the curve and the lower axis.  Then you could load white
237ink into the pen (using the @code{set graylevel 1} or
238@code{set graylevel white} command) and white-out a box drawn between the zero
239line and the lower axis.  Then you'd load black ink back into the pen
240(@code{set graylevel 0}) and draw the curve again, so that the negative
241part would appear again.
242
243@strong{Input/output} in Gri may be interactive or non-interactive.  For
244interactive use, type @code{gri} at the system commandline prompt.  For
245non-interactive use, with Gri commands in a command-file called
246@file{cmd.gri}, type @code{gri cmd.gri}.
247
248@strong{Gri output} is in the PostScript page description language.  The
249output is therefore of high quality, device-independent, capable of
250being inserted into popular text processors (e.g. LaTeX), and easily
251displayed.
252
253@strong{Online help:} the Gri command @code{help} makes Gri
254list the first words of all known commands, along with a hint for
255getting further help.  To get more information, type @code{help}
256followed by a command-name (e.g. @code{help read}).  There is also a
257tiny bit of information stored online and categorized by topic.  Get
258this by typing for example @code{help - strings} (@ref{Online Help}).
259
260@strong{Data analysis} in Gri is limited.  It has rudimentary data
261analysis functions, such as regression, column manipulation, smoothing,
262etc, but it is not intended as an integrated analysis/graphics package.
263
264@strong{System calls} are an easy and important facet of Gri.  It is easy
265to use operating system commands within Gri (@ref{System};
266@ref{Operating System};
267@ref{Get Env}).  This
268allows you to use familiar, powerful tools, and keeps Gri simple.
269Particularly useful is the ability to read files through operating
270system filters (@ref{Open}).
271
272@strong{Programming Gri} is quite straightforward, and users familiar with
273other programming languages find it easy.  If Gri lacks a drawing
274method, you can add it fairly easily, since Gri has programming elements
275such as @code{if} statements (@ref{If Statements}), @code{while} loops
276(@ref{While}), facilities for interacting with the user
277(@ref{Query}), and mechanisms for storing numbers in "variables"
278(@ref{Variables}),
279and text strings in "synonyms" (@ref{Synonyms}).  The Gri syntax can
280be augmented easily (@ref{Adding New Commands}), and these
281augmentations can be stored in a startup file (@ref{Resource File}),
282creating personalized versions of Gri.
283
284
285@cindex FTP site, cookbook
286@strong{Manuals:} Gri has an online texinfo manual, a PostScript manual, a
287WWW manual, a
288@c HTML <A HREF="http://gri.sourceforge.net/gri-cookbook/index.html">
289cookbook
290@c HTML </A>
291@cindex Gri newsgroup
292@cindex newsgroup
293and several reference cards.  It also has several discussion groups
294(@ref{Discussion Group}).
295
296
297@strong{Version Numbering Scheme}
298@cindex gri version
299@cindex version numbers
300
301When you launch Gri interactively (without naming a commandfile, i.e. by
302just typing @code{gri} at the unix prompt), you'll see something like
303
304@example
305 gri - scientific graphic program (version @value{GRI-VERSION})
306 GPL Copyright 2008 by Dan E. Kelley.
307
308 Type `help' for an overview of Gri commands, or see the
309 full manual at
310     /usr/share/doc/gri-@value{GRI-VERSION}/html/index.html
311 and its text-only version in the 'gri' INFO node.
312
313 Visit http://gri.sourceforge.net for updates and resources.
314gri:
315@end example
316
317@noindent
318
319The last line is a prompt, suggesting that you type in Gri commands.
320You may type @code{quit} to get out of gri.
321
322The first line gives the version number.  You can also get this by
323running Gri with the command @code{gri -v}.  Version numbers have three
324numbers separated by periods.  The first number increments for major
325changes, the second for smaller changes, the third for still smaller
326changes.  The second number also indicates whether a copy is an
327experimental version or a more reliable release version.  Experimental
328versions have the second digit being an odd integer, while release
329versions have this digit being even.
330
331
332@c HTML <!-- newfile SimpleExample.html "Gri: simple example" "Simple example" -->
333
334@node   Simple Example, Invoking Gri, Introduction, Top
335@comment  node-name,  next,  previous, up
336@chapter Simple Gri Program and How to Run it
337@cindex first-time usage
338@cindex hint, first-time usage
339@cindex beginners, simple example
340@cindex drawing x-y graphs, simple
341This chapter introduces Gri with a common example: an x-y graph.  The
342example is discussed in detail later (@ref{X-y Plots}).  The data files
343and command files here and throughout the manual should be available to
344you in a directory @file{.../gri/examples} on unix machines.
345
346
347
348
349@section Gri Command file
350
351@cindex example 01, linegraph using data in a separate file
352
353Here is a Gri command file to plot a linegraph of a set of (x,y) data,
354stored as space-separated columns in a file called @file{example1.dat}:
355
356@example
357# Example 1 -- Linegraph of data in separate file
358open example1.dat     # Open the data file
359read columns x y      # Read (x,y) columns
360draw curve            # Draw data curve
361draw title "Example 1"# Title above plot
362@end example
363
364@noindent
365The first line is a comment, as are all things following hash symbols (@code{#}).
366(An exception to this rule is made within strings contained
367within the double-quote character @code{"}.  This allows @code{sed}
368system commands to work as expected; (@ref{System}).)
369
370The other lines are Gri command lines; (@ref{X-y Plots}) for more
371explanation.
372
373
374@section Data File
375The data file @file{example1.dat} looks like:
376
377@example
3780.05 12.5  # first point
3790.25 19    # second point
3800.5  15    # third point
3810.75 15    # ... you get the idea!
3820.95 13
383@end example
384
385@noindent
386Note that spaces (or tabs) separate numbers.  Any data line may have a
387comment on it, just as any command line may.
388
389
390@section Running The Command File
391Type @file{gri example1.gri} at the system prompt.  Gri will create a
392PostScript file called @file{example1.ps}.  For details on running Gri
393see @ref{Invoking Gri}.
394
395
396
397@section Output Graph
398The output PostScript file is called @file{example1.ps}.
399
400@c HTML <A HREF="example1.png">
401@c HTML <IMG ALT="Example 1" SRC="example1-tiny.png" ALIGN=top>
402@c HTML </A>
403@c HTML Click the plot to enlarge it.)
404@c HTML <P>
405@c HTML It looks something like the miniature shown above.
406
407@c BUG: pdftex ignores the size.
408@image{./examples/example1, 300pt}
409
410@cindex example 01, linegraph using data in a separate file
411
412To view Gri output, use your favorite PostScript previewer.
413
414Note that in the above example, Gri automatically chose reasonable
415scales for the axes, based on the range of the data.  The next chapter
416illustrates that Gri also gives you control over such things.
417
418
419@c HTML <!-- newfile InvokingGri.html "Gri: running" "Invoking Gri" -->
420
421@node   Invoking Gri, Getting More Control, Simple Example, Top
422@comment  node-name,  next,  previous,  up
423@chapter Invoking Gri
424@section Invoking Gri in a nutshell
425First, the short story.  In 90 percent of cases, Gri is run as
426
427@example
428gri myscript
429@end example
430
431where the file @file{myscript.gri} holds a script (list of Gri
432commands), and Gri will create a PostScript file called
433@file{myscript.ps} with the output.
434
435Some folks like to give the @file{.gri} suffix explicitly, so they
436would invoke Gri as
437
438@example
439gri myscript.gri
440@end example
441
442@noindent instead.
443
444If you'd rather not have @file{myscript.ps} as the PostScript output file
445name (let's say you prefer @file{graph1.ps}) you'd do
446
447@example
448gri -output graph1.ps myscript.gri
449@end example
450
451Few readers will need to know more than this.  But, for the rest, the
452table in the next section gives full details on all the optional
453arguments that Gri can handle.
454
455@section Using Gri to draw things
456To draw things, invoke Gri as
457
458@example
459gri [OPTIONS] [CmdFile [optional_arguments]]
460@end example
461
462@cindex @code{[]} syntax for optional words in commands
463@cindex optional words in commands, @code{[]} syntax
464
465@noindent
466where the square brackets indicate that the enclosed items
467are optional.  The @code{OPTIONS} item may consist of one
468or more of the following (explained below):
469
470@example
471[-batch]
472[-b]
473[-chatty N]
474[-c      N]
475[-debug]
476[-d]
477[-directory_default]
478[-directory pathname]
479[-help]
480[-h]
481[-no_bounding_box]
482[-no_cmd_in_ps]
483[-no_startup_message]
484[-output PS_file_name|SVG_file_name]
485[-private]
486[-no_private]
487[-publication]
488[-p]
489[-superuser N]
490[-trace]
491[-t]
492[-yes]
493[-y]
494[-version]
495[-v]
496[-warn_offpage]
497[-no_warn_offpage]
498@end example
499@noindent
500@cindex colon on commandline
501@cindex commandline flag colon
502@cindex arguments on commandline, accessing
503@cindex commandline arguments, accessing
504@cindex @code{argv}, RPN operator to access commandline arguments
505@cindex @code{argc}, RPN operator to access commandline arguments
506
507Here, the optional @code{optional_arguments} are a mechanism to
508customize the action of the given Gri script from the commandline.
509After Gri processes standard arguments (e.g. @code{-t} for tracing), it
510puts the remaining commandline arguments into a list.  This behavior is
511borrowed from C and othe languages, so Gri borrows the name of the list
512as well: it's called the "arg" list, and its elements are available with
513the RPN operators named @file{argc} (@ref{Solitary Operators})
514and @file{argv} (@ref{Unary Operators}).
515
516For a note on usage within the Emacs gri-mode, see @ref{Filename
517arguments when running gri}.
518
519
520@strong{Details of command-line options}
521@cindex options on Gri command-line
522@cindex command-line options
523
524@itemize @bullet
525
526@item  @code{-batch} or @code{-b}
527@cindex batch processing
528@cindex @code{-batch} command-line option
529Stops Gri from printing out prompts and hints.
530
531@item  @code{-chatty N} or @code{-c N}
532@cindex @code{-chatty} command-line option
533Make Gri print out various informative messages.  The numerical
534value gives a level of chattiness.  A value
535of 1, the default if the @code{-chatty} code is not supplied, tells Gri to
536keep you informed of some important things, like the success in gridding
537data for contouring.  Higher values make Gri tell you more:
538
539Information printed at various chatty levels:
540@itemize @bullet
541
542@item @strong{0}
543The bare minimum is printed.  Thus invoking Gri as @code{gri -c 0}@dots{}
544will make it as quiet as can be.
545
546@item @strong{1 or higher} (the default)
547The full filenames of the commandfiles are displayed at startup time.
548
549@code{convert columns to grid} prints percentage of grid filled, as well
550as a suite of diagnostics, if you've let it calculate the region of
551influence automatically.  It also prints a warning of the time it
552expects to take, before starting the calculation.
553
554@code{convert grid to image} prints characteristics of image created,
555including amount of image clipped.
556
557@code{read grid data} reports number of data values it could not read
558(since they were nonnumeric).
559
560@code{draw symbol} reports number of data points not drawn because they
561were missing or outside clip region (if one exists).
562
563@item @strong{2 or higher}
564@code{draw contour} prints value of contour being drawn.
565
566@code{open "...|"} prints the command to be passed to the operating
567system as well as the name of the temporary file being created; also
568notifies user when the temporary file is destroyed.
569
570@code{show image} reports histograms in intensity bands of 8 units,
571instead of the default 16 units.
572
573@item @strong{3 or higher}
574@code{show image} reports histograms in intensity bands of 4 units,
575instead of the default 16 units.
576
577@end itemize
578
579@item  @code{-debug} or @code{-d}
580@cindex @code{-debug} command-line option
581@vindex @code{..debug..}, for debugging (by normal users)
582Sets the built-in variable flag @code{..debug..} that you can use to
583isolate blocks of code.
584
585@item  @code{-directory_default}
586@cindex @code{-directory_default} command-line option
587Reports directory where @file{gri.cmd} is expected to be found, either
588in the default location or the one specified by @code{-directory}
589commandline option.
590
591@item  @code{-directory pathname}
592@cindex @code{-directory} command-line option
593Specifies the directory where Gri looks for the startup file
594@file{gri.cmd}.  (This file teaches Gri the standard commands; Gri will
595report an error and die if it cannot find this file.)  If this switch is
596not provided -- and it is normally not -- then Gri looks for
597@file{gri.cmd} in a standard system directory (sometimes,
598but not always,
599@file{/usr/local/share/gri/@value{GRI-VERSION}}) which was specified
600during the compilation of the Gri program itself.  For more on how Gri looks
601for @file{gri.cmd}, see the subsection below.
602
603@item  @code{-no_bounding_box}
604@cindex postscript bounding box
605@cindex bounding box
606@cindex @code{-no_bounding_box} command-line option
607Make the so-called ``bounding box'' in the PostScript file be the full
608page.  The bounding box is used by some PostScript previewers to clip
609the image to just the drawn parts of the page, and is used by the
610@code{epsfbox} macro in @code{latex} to automatically determine the
611geometry of the graph for inclusion in text.  Normally the bounding box
612is calculated automatically, to enclose all the items drawn on the page.
613But the box may also be set with the @code{set bounding box} command
614(@ref{Set Bounding Box}).
615
616@item  @code{-no_cmd_in_ps}
617@cindex -no_cmd_in_ps
618Prevent Gri from inserting the lines of the commandfile into the
619PostScript file as comments.  (These comments can be used by the
620@code{-creator} commandline option (see above), but they take up a little
621bit of space and users might sometimes want to get rid of them.)
622
623@item  @code{-no_warn_offpage}
624@cindex postscript bounding box
625@cindex bounding box
626@cindex @code{-no_warn_offpage} command-line option
627Do not warn if items are offpage.  (Contrast this with @code{-warn_offpage}.)
628
629@item @code{-output PS_file_name}
630@cindex specifying the PostScript file name
631@cindex PostScript file name, specifying
632@cindex commandline option @code{-output PS_file_name}
633@cindex -output PS_file_name commandline option
634Specify the PostScript filename.  If this is not specified, the
635PostScript filename is derived from the name of the commandfile
636(e.g. @file{mygraph.gri} produces @file{mygraph.ps}), or, for
637interactive use, it will have a name like @file{gri-00.ps}, or
638@file{gri-01.ps} if the former file exists, etc.
639
640@item @code{-output SVG_file_name}
641@cindex specifying the SVG file name
642@cindex SVG file name, specifying
643@cindex commandline option @code{-output SVG_file_name}
644@cindex -output SVG_file_name commandline option
645Specify the SVG filename.  This is a pre-feature, as of version 2.12.x,
646meaning that SVG output is not working properly yet.  If you specify an
647SVG file name, you will see a long list of warnings.  These are
648debugging messages, and are not specific to your actual Gri script.  For
649example, you will see warnings about centring strings, even if you are
650not centering any strings.  This manual does not contain a list of
651working features (or broken features) for SVG output; the idea is that a
652discussion of such things be done using the bug-reporting system of the
653Gri website @ref{Reporting Bugs}.  In addition to bugs, the author is
654interested in users' opinions on the scheme of the SVG, especially the
655hieararchy of groupings of graphical elements.  It is because such
656things are being altered that this is designated a pre-feature.
657
658@item  @code{-no_startup_message}
659@cindex startup message
660@cindex @code{-no_startup_message} command-line option
661Stops Gri from printing the startup message.
662
663
664@item  @code{-private}
665@cindex @code{-private} command-line option
666@cindex private, command-line flag
667Prevents inserting any information about the user into the PostScript
668file (see @code{-no_private}, next).  As of version 2.12.10,
669this privacy option is assumed by default.
670
671@item  @code{-no_private}
672@cindex @code{-no_private} command-line option
673@cindex no_private, command-line flag
674Instructs Gri to include comments in the PostScript file that identify
675the user, state the commandline arguments used in invoking Gri, and
676that list all the commands that were executed.  This information can
677be recovered by calling Gri on the PostScript file, with the
678@code{-creator} commandline argument.  Until version 2.12.10,
679the default was to include this information, but a change was
680made out of privacy concerns.
681
682@item  @code{-publication} or @code{-p}
683@cindex @code{-publication} command-line option
684@cindex publication quality, command-line flag
685Sets the built-in variable @code{..publication..} to 1.  You may use
686this to distinguish between working plots and publication plots, as in
687this example:
688
689@example
690if !..publication..
691  draw time stamp
692  draw title "working version of plot"
693end if
694@end example
695
696@item  @code{-superuser}
697@cindex @code{-superuser} command-line option
698@vindex @code{..superuser..}, for debugging (by developers)
699(This option is included here only for completeness.  It should only be
700used by developers (who will alter the code to print debugging
701information if @code{-superuser} is set in addition to @code{-debug}).
702An optional value can be inserted (e.g. @code{-superuser 2}) to set the
703debugging level (retrievable by the function superuser()) to indicated
704integer value.  Specifying the @code{-superuser} command-line option
705sets the built-in variable @code{..superuser..} to 1 or the specified
706value.)
707
708For flag meanings, see @code{superuser} command (@ref{Superuser}).
709Using the question-mark symbol @code{?} instead of a flag number makes
710Gri print out the list of flags.
711
712@item  @code{-trace} or @code{-t}
713@cindex @code{-trace} command-line option
714@cindex tracing execution, command-line option
715Makes Gri print out command lines as they are executed; this has the
716same effect as the @code{set trace} command.
717
718@item  @code{-version} or @code{-v}
719@cindex @code{-version} command-line option
720Display version information and exit successfully.
721
722@item  @code{-warn_offpage}
723@cindex command-line option @code{-warn_offpage}
724@cindex @code{-warn_offpage} command-line option
725Causes warnings to be issued for all items drawn far off a 8.5x11 inch
726page.  This is the default.  (Contrast with @code{-no_warn_offpage}.)
727
728@item  @code{-yes} or @code{-y}
729@cindex @code{-yes} command-line option
730@vindex @code{..use_default_for_query..}, simulate @code{-yes} commandline flag
731@cindex interaction with user, @code{-y} command-line option
732Bypasses all @code{query} commands, making Gri act as though the user
733typed a carriage-return (thus giving the default) for each @code{query}.
734
735@item  @code{-help} or @code{-h}
736@cindex @code{-help} command-line option
737Prints explanation of options.
738
739@item @code{CommandFile}
740@cindex @code{\\.path_commands.} builtin synonym
741@cindex builtin synonym @code{\\.path_commands.}
742@cindex @code{CommandFile} command-line option
743@cindex command files
744@cindex files, Command-file
745@cindex command-line, specifying command file
746If a command file @code{CommandFile} is specified, then commands will
747be read from that file instead of the keyboard.  If the @code{chatty}
748level is 1 or larger, Gri prints the names of the commandfiles at
749startup time.  It is conventional but not necessary that the filename
750ends in @code{.gri}.  If the filename does end in @code{.gri}, you may
751delete this suffix; Gri will assume it as implied.
752
753@end itemize
754
755@strong{Executable scripts.} If you don't need to supply commandline
756options, you can put the following line as the first line in your Gri
757program
758
759@example
760#!/usr/bin/gri
761@end example
762
763@noindent (or point to wherever Gri is located on your machine), and
764@code{chmod +x} the file.  Then you can run Gri simply by naming the
765file.  There is no particular advantage in this, except for saving the
766typing of a few characters, but some folks like this.
767
768
769@cindex @file{gri.cmd}, how it is located
770@strong{How Gri locates the} @file{gri.cmd} @strong{file}.
771In a normal installation, Gri finds the @file{gri.cmd} file all by
772itself.  However, developers and some others may wish to control where
773Gri looks for this file.  The rules below specify how Gri looks for
774@file{gri.cmd}.
775@table @emph
776
777@item Case 1
778If @code{-directory} was given on the commandline used to invoke Gri
779(e.g. @code{gri -directory /some/place mycommand_file.gri}), then
780Gri will use the @file{gri.cmd} in the named directory.  An error will
781result if @file{gri.cmd} is not found there.
782
783@item Case 2
784If @code{-directory} was not given on the commandline, then
785Gri looks for @file{gri.cmd} in a location that was specified during
786compilation.  If @file{gri.cmd} is found there, then it is used.  If it
787is not found, then Gri checks to see if an environment variable named
788@code{GRI_DIRECTORY_LIBRARY} is defined.  If so, then Gri takes this to
789be the name of a directory that contains the @file{gri.cmd} file.  If
790@file{gri.cmd} is not found there, an error results.
791@end table
792
793
794
795@section Extracting commandfile from a PostScript file
796@cindex recovering commands from a PostScript file
797@cindex command-line option @code{-creator}
798@cindex @code{-creator} command-line option
799
800@example
801gri -creator PostScriptFile
802@end example
803
804@noindent @strong{See also} @code{-no_cmd_in_ps}.
805
806The @code{-creator} flag makes gri examine the indicate PostScript file,
807and produce a facsimile of the command file (or interactively-typed
808commands) that created this PostScript file.  (This only works if the
809Gri command that created the PostScript file used the
810@code{-no_private} commandline argument.)
811
812@c REMOVED_AFTER_2_8_x @section Fixing a broken PostScript file
813@c REMOVED_AFTER_2_8_x To make Gri repair a PostScript file created by a Gri job that failed
814@c REMOVED_AFTER_2_8_x midway through:
815@c REMOVED_AFTER_2_8_x
816@c REMOVED_AFTER_2_8_x @example
817@c REMOVED_AFTER_2_8_x gri -repair bad.ps good.ps
818@c REMOVED_AFTER_2_8_x @end example
819@c REMOVED_AFTER_2_8_x
820@c REMOVED_AFTER_2_8_x This may very well not work, and the author only provides it in case it
821@c REMOVED_AFTER_2_8_x may help you.  Essentially all it does it try to complete a so-called
822@c REMOVED_AFTER_2_8_x PostScript "path", if Gri died in the middle of drawing a path.  Please
823@c REMOVED_AFTER_2_8_x don't expect too much from this command, and don't expect bug fixes to
824@c REMOVED_AFTER_2_8_x it.
825
826@c HTML <!-- newfile GettingMoreControl.html "Gri: getting more control" "Getting more control" -->
827
828@node   Getting More Control, Simple Example Revisited, Invoking Gri, Top
829@comment  node-name,  next,  previous,  up
830@chapter Controlling Axes, Fonts, Colors, etc
831
832Gri provides a great many things that you can control, if you want to.
833An introduction to some of these things is presented in the sections
834below.
835
836@menu
837* Simple Example Revisited::    Adding more details
838* Axis Scaling::                Gri automatically scales and draws axes
839* Log And Linear::              Selecting log/linar axes
840* Length::                      Adjusting axis length
841* Range::                       Adjusting axis range
842* Labels::                      Adjusting labels on axes
843* Position::                    Positioning the axes
844* Fonts::                       Setting fonts
845* Pen Color::                   Controlling Pen color
846@end menu
847
848@c HTML <!-- newfile SimpleExampleRevisited.html "Gri: simple example revisited" "Getting more control" -->
849
850@node   Simple Example Revisited, Axis Scaling, Getting More Control, Getting More Control
851@section An example
852@cindex scales
853@cindex axes, scales
854@cindex font, selecting
855Below is a followup to the previous example, which names the x and the y
856axes.
857
858@example
859# Fancier version of Example 1
860open example1.dat
861read columns x y
862set x name "Time, hours"
863set y name "U, m/s"
864draw curve
865@end example
866
867The difference is that the x and y axes are named with a @code{set}
868command.  There are many @code{set} commands, and they are all pretty
869simple, e.g. @code{set x size 15} makes the x-axis be 15 centimeters
870long, instead of the default of 10 centimeters.  Indeed, you can control
871anything you want in gri, e.g. graph size, line width, fonts, etc etc.
872Speaking of fonts, the @code{$\alpha$} type of latex formatting of Greek
873letters is supported in a limited way.
874Also, Gri handles ISO-Latin-1 encodings as well as the U.S. style.
875
876
877The example below illustrates a few more @code{set} commands.  This
878example is intentionally complicated, being about a good example of the
879level of complexity of many plots made by Gri.  Read the comments to see
880what is being done, and consult the plot as you read the commandfile.
881
882@cindex multiple panels
883@cindex example 03 (controlling scales, etc)
884
885
886
887@c HTML <A HREF="example3.png">
888@c HTML <IMG ALT="Example 3" SRC="example3-tiny.png"
889@c HTML ALIGN=top>
890@c HTML </A>
891@c HTML <A HREF="example3.html">The command-file.</A> <P>
892
893@image{./examples/example3, 300pt}
894@cindex example 03, controlling scales, etc
895
896
897@c HTML <!--
898@example
899# Example 3 -- Controlling scales, etc
900#
901# Example of how to control axis scales, etc.  This example makes
902# two panels, plotting the same data in different ways.
903#
904#
905# ----- PANEL 1 ------------------------------------------------
906#
907# Set up the x axis.
908#
909# Make the x axis run from 0 to 1, with labelled tics each 0.25.
910set x axis 0   1   .25
911# Make the x-axis be 5 cm long; in other words, make the plot 5 cm wide.
912set x size 5
913# Put 2 cm of space between the left edge of the plot and the left
914# edge of the paper.
915set x margin 2
916# Give the x-axis the name "t" with subscript 0.
917set x name "$t_0$"
918#
919# Set up the y axis.
920#
921# Make the y axis run from 10 to 20, with labelled tics at intervals
922# of 5 and smaller, unlabelled tics, at intervals of 1.  Other
923# commands are similar to those for the x-axis.
924set y axis 10 20 5 1
925set y size 10
926set y margin 2
927set y name "F"
928#
929# Now, read our simple data set.
930open example1.dat
931read columns x y
932close
933#
934# Draw a curve connecting these (x,y) data.  Note that the axes, as
935# defined above, will be drawn automatically along with the curve.
936draw curve
937
938
939#
940# ----- PANEL 2 ------------------------------------------------
941#
942# OK, now for a more complicated version.  We'll keep the same data, but
943# redraw it in a new panel, to the right of the first graph.  So, the
944# first step is to increase the x margin.  The @{rpn@} command simply
945# creates a number which is the sum of the old x margin (stored in
946# the variable ..xmargin..) and the old plot width (stored in
947# the variable ..xsize..), plus an extra 1 cm
948set x margin @{rpn ..xsize.. ..xmargin.. + 1 +@}
949#
950# Set the line thickness for the curve to 1 point (0.3 mm) and the
951# axis line thickness to 0.2 points (0.1 mm).
952set line width 1.0              # points
953set line width axis 0.2         # points
954# Set the tics to be 1.5 mm.
955set tic size 0.15               # centimetres
956# Draw axes and frame, with axes offset from frame.  Some
957# people find this more attractive.
958set axes style offset
959draw axes 1
960# Now draw the actual curve.
961draw curve
962# Superimpose dots (diameter 1.5 mm) at the data.
963set symbol size 0.15
964draw symbol bullet
965#
966# All done.
967# Draw a title above the plot.
968set font size 20
969\label = "Example 3 -- scales, axes, etc"
970draw label "\label" at          \
971    @{rpn 8.5 2.54 * "\label" width - 2 /@} \
972    @{rpn ..ytop.. yusertocm 2 +@}\
973    cm
974@end example
975@c HTML -->
976
977
978@c HTML <!-- newfile AxisScaling.html "Gri: axis scaling" "Getting more control" -->
979
980@node   Axis Scaling, Log And Linear, Simple Example Revisited, Getting More Control
981@comment  node-name,  next,  previous,  up
982@section Axis scaling
983@cindex axes, and mathematical operations on columns
984@cindex axes, autoscaling of
985@vindex @code{..xlast..}, last drawn x value
986@vindex @code{..ylast..}, last drawn y value
987@vindex @code{..xmargin..}, left margin
988@vindex @code{..ymargin..}, bottom margin
989@vindex @code{..xsize..}, x-axis length
990@vindex @code{..ysize..}, y-axis length
991@vindex @code{..xleft..}, x value at left of plot
992@vindex @code{..xright..}, x value at right of plot
993@vindex @code{..xinc..}, x increment on axes
994@vindex @code{..ybottom..}, y value at bottom of plot
995@vindex @code{..ytop..}, y value at top of plot
996@vindex @code{..yinc..}, y increment on axes
997
998Gri normally assumes that you are plotting scientific graphs, and
999therefore whenever it sees a command like @code{draw curve} or
1000@code{draw symbol}, it draws an appropriate axis first.  You can turn
1001this feature off, by using @code{draw axes none} before the other
1002@code{draw} command.
1003
1004Furthermore, Gri picks axis scales by itself, by scanning the (@code{x},
1005@code{y}) columns.  If you don't like the scales Gri picks, you can
1006override them (@ref{Range}).
1007
1008Gri normally draws axes labelled at left and bottom, and with an axis
1009frame with tics all around.  If you don't like this default axis style
1010you can specify other styles.  For example, if the commands
1011@code{draw x axis} and @code{draw y axis} are placed before the @code{draw curve}
1012command, Gri will realize you've already specified axes, and just draw
1013them on the left and bottom sides of the box, without completing the
1014axis frame.
1015
1016For your general use, Gri stores the minimum and maximum x and y
1017values of the @strong{axes} in the variables @code{..xleft..},
1018@code{..xright..}, @code{..ybottom..}, and @code{..ytop..}.  It also
1019stores the increments used in labelling these axes in the
1020@code{..xinc..}  and @code{..yinc..} variables.
1021
1022To determine the minimum and maximum values of column data, you
1023may use the built-in RPN functions @code{min}, @code{max}, and
1024@code{mean} (@ref{Manipulation of Columns etc}).
1025
1026Gri stores the last (x,y) pair on a curve (whether data or axis) in the
1027@code{..xlast..} and @code{..ylast..} variables
1028
1029Gri stores the axis sizes in @code{..xsize..} and @code{..ysize..}.  It
1030stores the space to the left of the plot in @code{..xmargin..} and the
1031space below the plot in @code{..ymargin..}.
1032
1033
1034@c HTML <!-- newfile LogAndLinearAxes.html "Gri: log and linear axes" "Getting more control" -->
1035
1036@node   Log And Linear, Length, Axis Scaling, Getting More Control
1037@comment  node-name,  next,  previous,  up
1038@section Logarithmic and linear axes
1039@cindex logarithmic axes
1040@cindex axes, logarithmic
1041@cindex linear axes
1042@cindex axes, linear
1043Axes are linear by default; to make logarithmic axes, use commands
1044@code{set x type log} and @code{set y type log}.
1045
1046
1047
1048@c HTML <!-- newfile AxisLength.html "Gri: axis length" "Getting more control" -->
1049
1050@node   Length, Range, Log And Linear, Getting More Control
1051@comment  node-name,  next,  previous,  up
1052@section Axis Length
1053@cindex axes, guide to choosing length of
1054@cindex length of axes, guide on choosing
1055@cindex data files, protecting against movement of
1056The axes are normally 10 centimetres long.  To set the axis lengths (in
1057centimetres), use commands like @code{set x size 5} and
1058@code{set y size 7}.  Some people like the ratio of axes to be in the
1059so-called golden ratio @code{(root(5)-1)/2}; to get that, you could do
1060this:
1061@cindex axis sizes, scaled with golden ratio
1062@cindex golden ratio, used for axes sizes
1063
1064@example
1065set x size 15
1066set y size @{rpn ..xsize.. 5 0.5 power 1 - 2 / *@}
1067@end example
1068
1069@cindex scaling for maps
1070@cindex maps, scaling
1071For maps, you'll want the plot scaled so that shapes retain their aspect
1072ratio.  To do this, do @code{set x size .cm.} and then do
1073@code{resize y for maps} (or vice versa).
1074
1075
1076@c HTML <!-- newfile AxisRange.html "Gri: axis range" "Getting more control" -->
1077
1078@node   Range, Labels, Length, Getting More Control
1079@comment  node-name,  next,  previous,  up
1080@section Axis Range
1081@cindex axes, range of values on
1082@cindex range of axes
1083To override axis ranges set by Gri, use @code{set x axis} and
1084@code{set y axis}.  With these commands, you specify the range of the axes; you
1085may also set the interval for numbered tics, and an interval for
1086unnumbered tics.  The unnumbered tics must be at an interval that
1087divides evenly into the numbered tic interval, but the numbered tic
1088interval need not divide into the min/max range.  Thus,
1089@code{set x axis 0 1.1 0.5} will create an axis that will range from 0 to 1.1, with
1090labelled tics at the values 0, 0.5 and 1.
1091
1092
1093@c HTML <!-- newfile AxisLabels.html "Gri: axis labels" "Getting more control" -->
1094
1095@node   Labels, Position, Range, Getting More Control
1096@comment  node-name,  next,  previous,  up
1097@section Axis Name
1098@cindex labels, on axes
1099@cindex axes, labels for
1100To set the name of the x axis, use @code{set x name "string"}, and
1101similarly for the y-axis.  The default names are @code{x} and @code{y}.
1102
1103
1104@c HTML <!-- newfile AxisPosition.html "Gri: axis position" "Getting more control" -->
1105
1106@node   Position, Fonts, Labels, Getting More Control
1107@comment  node-name,  next,  previous,  up
1108@section Axis location
1109@cindex axes, location of
1110@cindex positioning axes
1111If you don't like the default position of axes (at left and bottom), you
1112may get Gri to draw axes anywhere you like, using commands like
1113@code{draw y axis at right} (so the y axis is at the right-hand end of
1114the x range) or @code{draw x axis at top} (so the x axis is at the top
1115of the plot); you may even specify an exact location, such as
1116@code{draw x axis at 22.2}.
1117
1118Normally, the x axis is placed at the bottom end of the y axis, and the
1119y axis is placed at the left end of the x axis.  Some people prefer a
1120style in which the axes are positioned a small offset away from these
1121locations.  To get this effect, you may either position the axes
1122yourself, or simply use the @code{set axes style offset} command
1123(@ref{Set}).  If you want this axis style for all their plots, put the
1124line @code{set axes style offset} in your @file{~/.grirc} startup file
1125(@ref{Resource File}).
1126
1127
1128@c HTML <!-- newfile Fonts.html "Gri: fonts" "Getting more control" -->
1129
1130@node   Fonts, Pen Color, Position, Getting More Control
1131@comment  node-name,  next,  previous,  up
1132@section Fonts
1133Fonts are selected with @code{set font to} (@ref{Set Font To}) and font
1134sizes are selected with @code{set font size} (@ref{Set Font Size}).
1135
1136Much more about text, including how to draw mathematical symbols, how to
1137use subscripts and superscipts, how to write non-English (accented)
1138European text, etc, is discussed (@ref{Text}).
1139
1140
1141@c HTML <!-- newfile PenColor.html "Gri: pen color" "Getting more control" -->
1142
1143@node   Pen Color, X-y Plots, Fonts, Getting More Control
1144@comment  node-name,  next,  previous,  up
1145@section Colour of ink in pen
1146@cindex graylevel, explanation
1147@cindex lines, gray, explanation
1148
1149The darkness of the ``pen'' used in drawing commands (for either lines or
1150for text) is set by @code{set graylevel .brightness.}.  A brightness
1151value of 0 corresponds to black ink, and a brightness value of 1
1152corresponds to white ink.  Values outside this range are clipped to the
1153nearer endpoint.  Values inside this range choose a proportional
1154graylevel in between; for example, @code{set graylevel 0.5} gives a 50
1155percent gray tone.
1156
1157The graylevel applies to text as well as lines.  Often you'll want to
1158draw a gray line and a black label beside it, or you'll want to set a
1159graylevel temporarily.  Here's how to do it:
1160
1161@example
1162# Save old graylevl, set, then reset to old
1163.old_gray. = ..graylevel..
1164set graylevel 0.5
1165draw curve
1166set graylevel 0
1167draw label for last curve "TEST"
1168set graylevel .old_gray.
1169@end example
1170
1171
1172The color of the "pen" may be set to any value you can describe with an
1173RGB (red, green, blue) or HSB (hue, saturation, brightness)
1174specification, or a color name.  This pen color applies to everything,
1175even text.
1176
1177@noindent @b{The} @code{set color \name} @b{command}
1178
1179Set the pen color to the indicated name.  There are two types of
1180names: hexadecimal-triplet names and English names.
1181
1182@anchor{pen-color-hexadecimal}
1183Hexadecimal-triplet names are of a form often used in web-pages.  They
1184consist of exactly 6 characters, which are divided by Gri into three
1185sets of two characters, specifying the red component, the green
1186component, and the blue component of the color, respectively.  These
1187components are in hexadecimal notation, i.e. ranging from 00 to FF,
1188indicating values from 0 to 255.  For example,
1189@example
1190set color ACD4EF
1191@end example
1192@noindent
1193sets a pastel blue color, almost the color of a robin's egg.
1194
1195The English colors are written simply in the form
1196@example
1197set color blue
1198@end example
1199@noindent
1200where the color is from the following list.  (Gri requires that you
1201use the exact form shown, including the capitilization.)  The color
1202mixes are identical to those used in X11.
1203
1204@cindex builtin colors, list of
1205@cindex colors, list of
1206
1207@example
1208NAME               RED    GREEN  BLUE
1209"white"            1.000  1.000  1.000
1210"LightGray"        0.827  0.827  0.827
1211"darkslategray"    0.184  0.310  0.310
1212"black"            0.000  0.000  0.000
1213"red"              1.000  0.000  0.000
1214"brown"            0.647  0.165  0.165
1215"tan"              0.824  0.706  0.549
1216"orange"           1.000  0.647  0.000
1217"yellow"           1.000  1.000  0.000
1218"green"            0.000  1.000  0.000
1219"ForestGreen"      0.133  0.545  0.133
1220"cyan"             0.000  1.000  1.000
1221"blue"             0.000  0.000  1.000
1222"skyblue"          0.529  0.808  0.922
1223"magenta"          1.000  0.000  1.000
1224@end example
1225
1226@noindent
1227To get more colors than those provided in the above list, use the
1228@code{read colornames} command.
1229
1230You should do a test case for your printer to see which colors you find
1231most to your liking.  You'll want to pick colors that look different
1232from each other.  In some cases you might want to avoid dithered colors,
1233since they look too broken on really thin lines.  For example, on my
1234printer I like the following colors: @code{black}, @code{red},
1235@code{yellow}, @code{green}, @code{cyan}, and @code{magenta}.
1236
1237
1238@noindent @b{The} @code{set color rgb .red. .green. .blue.} @b{command}
1239
1240This command sets the color using the red-green-blue color model.  If
1241you are familiar with how colors add (e.g. red plus green yields
1242yellow), then you might like this, but most people find it easier to use
1243the @code{set color hsb ...} style described below.
1244
1245Set the individual color components as follows.  The numbers
1246@code{.red.}, @code{.green.} and @code{.blue.} range from 0 (for no
1247contribution of that color component to the final color) to 1 (for
1248maximal contribution).  Values less than 0 are clipped to 0; values
1249greater than 1 are clipped to 1. EXAMPLES:
1250
1251@example
1252set color rgb 0   0   0  # black
1253set color rgb 1   1   1  # white
1254set color rgb 1   0   0  # bright red
1255set color rgb 0.5 0   0  # dark red
1256set color rgb 0   1   0  # pure green
1257set color rgb 1   1   0  # yellow: red + green
1258@end example
1259
1260
1261@noindent @b{The} @code{set color hsb .hue. .saturation. .brightness.} @b{command}
1262
1263In this color model, the color ("hue") is specified with a single
1264parameter.  Many people find this easier than using the corresponding
1265@code{rgb} command.
1266
1267@cindex hint, color palette range
1268Set the individual color components as follows.  The numbers
1269@code{.hue.}, @code{.saturation.} and @code{.brightness.} range from 0
1270to 1.  The color, represented by @code{.hue.}, ranges from 0 for pure
1271red, through 1/3 for pure green, and 2/3 for pure blue, and back to 1
1272again for pure red.  (HINT: It is a good idea to limit the total range
1273of hue you use to 2/3, instead of 1; otherwise you'll get confused by
1274(nearly) repeated colors at the crossover.  For example, limit the hue
1275to range from 1/3 to 1, or 0 to 2/3.)  The purity of the color,
1276represented by @code{.saturation.}, ranges from 0 (none of the hue is
1277visible) to 1 (the maximal amount is present).  Less saturated colours
1278are like those you would get from mixing black paint into colored
1279paint.  The brightness of the color, represented by @code{.brightness.},
1280ranges from 0 (black) to 1 (maximal brightness).  Lowering brightness is
1281like decreasing the intensity of the light you shine on a painting.
1282
1283Hue, saturation, and brightness values are all clipped to the range 0 to 1.
1284EXAMPLES:
1285
1286@example
1287set color hsb 0    1   1  # pure, bright red
1288set color hsb 0    1 0.5  # half black, half red
1289set color hsb .333 1   1  # pure, bright green
1290@end example
1291
1292
1293
1294
1295
1296@c HTML <!-- newfile X-Y.html "Gri: xy plots" "X-Y Plots" -->
1297
1298@node   X-y Plots, Linegraphs, Pen Color, Top
1299@comment  node-name,  next,  previous,  up
1300@chapter X-Y Plots
1301
1302@menu
1303* Linegraphs::                  x-y graphs with data connected by line segments
1304* Scattergraphs::               x-y graphs with data indicated by symbols
1305* Formula Plots::
1306@end menu
1307
1308@node   Linegraphs, Scattergraphs, X-y Plots, X-y Plots
1309@comment  node-name,  next,  previous,  up
1310@section Linegraphs
1311The following Gri commands will draw a linegraph.  For the output graph
1312(@ref{Getting More Control}).
1313@cindex linegraphs
1314@cindex x-y graphs
1315@cindex drawing linegraphs
1316@cindex example 01, linegraph using data in a separate file
1317
1318This plots a simple linegraph:
1319
1320@c HTML <A HREF="example1.png">
1321@c HTML <IMG ALT="Example 1" SRC="example1-tiny.png"
1322@c HTML ALIGN=top>
1323@c HTML </A>
1324
1325
1326@example
1327# Example 1 -- Linegraph using data in a separate file
1328
1329open example1.dat      # Open the data file
1330read columns x y       # Read (x,y) columns
1331draw curve             # Draw data curve
1332draw title "Example 1" # Title above plot
1333@end example
1334
1335Here's what the command lines mean:
1336
1337@itemize @bullet
1338@item
1339The first line is a comment.  Anything to the right of a hash-mark
1340@code{#} is considered to be a comment.  (This symbol is also called a
1341"pound".)
1342
1343@cindex comments, @code{#} style
1344@item
1345The second line is blank.  Gri ignores blank lines between commands.
1346@item
1347@code{open example1.dat} tells Gri to open the indicated file (in
1348the current directory) as an input data file.  You can specify files
1349outside the current directory by using conventional unix-shell pathnames
1350(e.g., @code{open ~/data/TS/section1/T_S.dat} or
1351@code{open ../data/file.dat}).  You can even use "synonyms" (@ref{Synonyms}.) in
1352filenames, as in @code{open \BASENAME.dat}.
1353@item
1354@code{read columns x y} tells Gri to start reading columnar data,
1355the first column being @code{x}, the second @code{y}.  @code{x} and
1356@code{y} are predefined names for whatever ends up on the horizontal and
1357vertical axes.
1358
1359@cindex reading columns of data
1360@cindex format for columnar data
1361@cindex data format
1362@cindex multiple datasets in one file
1363
1364The number of data needn't be specified.  Gri reads columns until a
1365blank line or end-of-file is found.  You can tell Gri how many lines to
1366read with a command like @code{read columns 10 x y}.  Multiple datasets
1367can reside within one file; provided that they are separated by a single
1368blank line, Gri can access them by multiple @code{read} commands.
1369
1370Like C, Gri expects numbers to be separated by one or more spaces or
1371tabs.  Commas are not allowed.  If the columns were reversed, the
1372command would be @code{read columns y x}.  If there were an initial
1373column of extraneous data, the command would be
1374@code{read columns * x y}, or @code{read columns x=2 y=3}
1375(@ref{Read Columns}).
1376@item
1377@code{draw curve} tells Gri to draw a curve connecting the points
1378in the @code{x} and @code{y} columns. A nice scale will be selected
1379automatically.  (You can change this or any other plot characteristics
1380easily, as you'll see later.)
1381@cindex drawing data lines
1382@item
1383@code{draw title} tells Gri to write the indicated string
1384centered above the plot. The title @strong{must} be enclosed in quotes.
1385@cindex titles, drawing above plot
1386@cindex drawing titles
1387@item
1388@code{quit} tells Gri to exit.
1389@end itemize
1390
1391Gri will draw axes automatically, and pick its own scales.
1392
1393If you wish to draw several curves which cross each other, you should
1394try using @code{draw curve overlying} instead of
1395@code{draw curve}.  This will make it easier to distinguish the
1396different curves.
1397
1398
1399@node   Scattergraphs, Formula Plots, Linegraphs, X-y Plots
1400@comment  node-name,  next,  previous,  up
1401@section Scattergraphs
1402@cindex scattergraphs
1403This section contains two examples, the first being a fuller explanation
1404of all the bells and whistles, the second being a simple explanation
1405of how to get a very quick plot, given just a file containing a matrix
1406of grid data.
1407
1408
1409To get a scattergraph with symbols at the data points, substitute
1410@code{draw symbol} for @code{draw curve}.  Both symbols and a curve
1411result if both @code{draw curve} and @code{draw symbols} are used.
1412See @ref{Getting More Control} for an example.
1413
1414By default, the symbol used is an x.  To get another symbol, use a
1415command like @code{draw symbol 0} or @code{draw symbol plus}.
1416
1417To change the symbol size from the default of 0.2 cm use commands like
1418@code{set symbol size 0.1} to set to 1 mm (@ref{Set Symbol Size}).
1419
1420@subsection Coding data with symbols
1421@cindex symbols
1422To get different symbols for different data points, insert symbol codes
1423from the above list as a column along with the x-y data, and substitute
1424the command @code{read columns x y z}, and then draw them with
1425@code{draw symbol}.  Gri will interpret the rounded-integer
1426values of the @code{z} columns as symbol codes.  Note that even if
1427you've read in a z column which you intend to represent symbols, it will
1428be overridden if you designate a specific symbol in your
1429@code{draw symbols} command; thus @code{draw symbol 0} puts a @code{+}
1430at the data points whether or not you've read in a symbol column.
1431
1432@subsection Drawing a symbol legend
1433@cindex legend for symbol
1434@cindex symbol legend
1435
1436The following example shows how you might write a symbol legend for a
1437plot.  The legend is drawn 1 cm to the right of the right-hand side of
1438the axes, with the bottom of the legend one quarter of the way up the
1439plot; @ref{Draw Symbol Legend}.  The lines in the legend are
1440double-spaced vertically.  To change the location of the legend, alter
1441the @code{.legend_x. =} and @code{.legend_y. =} lines.  To change the
1442spacing, alter the @code{.legend_y. +=} line.
1443
1444@example
1445set x axis -1 5 1
1446set y axis -1 5 1
1447read columns x y z
14480 0 0
14491 1 1
14502 2 2
14513 3 3
1452
1453draw symbol
1454
1455# Legend
1456.leg_x. = @{rpn ..xmargin.. ..xsize.. + 1 +@}
1457.leg_y. = @{rpn ..ymargin.. ..ysize.. 4 / +@}
1458draw symbol legend 0 "Foo" at .leg_x. .leg_y. cm
1459.leg_y. += @{rpn "M" ascent 2 *@}
1460draw symbol legend 1 "Bar" at .leg_x. .leg_y. cm
1461.leg_y. += @{rpn "M" ascent 2 *@}
1462@end example
1463
1464
1465@subsection Coding data with symbol colors
1466@cindex color, symbols
1467@cindex symbols in color
1468To get different colors for different symbols, read a color code into
1469the z column, and do for example @code{draw symbol bullet color hue z}.
1470The numerical color code ranges from 0 (red) through to 1, passing
1471through green at 1/3 and blue at 2/3.
1472
1473@node   Formula Plots, Contour Plots, Scattergraphs, X-y Plots
1474@comment  node-name,  next,  previous,  up
1475@section Formula Plots
1476@cindex functions, how to plot
1477@cindex formulae, how to plot
1478There are two methods for formula graphs.
1479
1480@enumerate
1481
1482@item @strong{Use the system yourself.}
1483Do as in this example:
1484
1485@example
1486open "awk 'BEGIN@{for(i=0;i<3.141;i+=0.05)\
1487    @{print(i,cos(i))@}@}' |"
1488read columns x y
1489close
1490draw curve
1491@end example
1492
1493@noindent
1494
1495@item @strong{Let Gri calculate things for you}
1496
1497The simplest is to let Gri
1498calculate things for you with the @code{create columns from function}
1499command (@ref{Create}).  The command assumes that you have defined
1500the synonym called @code{\function} which defines @code{y} in terms of
1501@code{x}.
1502
1503Gri uses the program @code{awk} to create the columns, and cannot work
1504without it.
1505
1506Here is an example of using @code{create columns from function}:
1507
1508@example
1509show "First 2 terms of perturbation expansion"
1510set y axis name horizontal
1511set y name "sea-level"
1512set x name "$\omega$t"
1513
1514\b = "0.4" # perturbation parameter b=dH/H
1515\xmin = "0"
1516\xmax = "6.28"
1517\xinc = "3.14 / 20"
1518\function = "cos(x)"
1519set x axis \xmin \xmax
1520create columns from function
1521draw curve
1522draw title "SOLID LINE  \function"
1523
1524\function = "(cos(x)+\b/2*(1-cos(2*x)))"
1525create columns from function
1526set dash 1
1527draw curve
1528draw title "DASHED LINE \function"
1529
1530draw title "b = \b"
1531@end example
1532
1533Here's another example, in which the curve @code{y = 1/(\int + \sl*x)}
1534is drawn through some data.  Note how @code{sprintf} is used to set
1535@code{\xmin} and @code{\xmax} using the scales that Gri has determined
1536in reading the data.
1537
1538@example
1539open file.data
1540read columns x y
1541close
1542draw symbol bullet
1543\int = "-0.1235"
1544\sl = "0.003685"
1545sprintf \xmin "%f" ..xleft..
1546sprintf \xmax "%f" ..xright..
1547\function = "1/(\int + x * \sl)"
1548create columns from function
1549draw curve
1550@end example
1551
1552@end enumerate
1553
1554
1555
1556
1557@c HTML <!-- newfile ContourPlots.html "Gri: contour plots" "Contour Plots" -->
1558
1559@node   Contour Plots, Pre-gridded Data, Formula Plots, Top
1560@comment  node-name,  next,  previous,  up
1561@chapter Contour Plots
1562@cindex contours
1563Contour plots can be done with either pregridded data or randomly
1564distributed (ie, ungridded) data.
1565@menu
1566* Pre-gridded Data::            Contouring f(x1, y1, x2, y2, ...)
1567* Ungridded Data::              Contouring f(x, y) where (x,y) are not on a grid
1568@end menu
1569
1570@node   Pre-gridded Data, Ungridded Data, Contour Plots, Contour Plots
1571@comment  node-name,  next,  previous,  up
1572@section Pre-gridded Data
1573@cindex contours, pre-gridded data
1574This section presents two examples of contouring pre-gridded data, the
1575first example illustrating a boilerplate program to contour data
1576stored in a simple matrix form in a file, the second example
1577illustrating a case with more control of the details (e.g., a nonuniform
1578grid).
1579
1580
1581@subsection Simple example
1582
1583This example was hardwired to know the size of the grid, etc.  Here's
1584an example which is more general, in that it determines the dimensions
1585of the grid data from using unix system commands.  Note that the grid is
1586set to run from 0 to 1 in both x and y; you'll most likely want
1587to change that after you see the initial plot, but this should get you
1588started.
1589
1590@cindex grid data, determining geometry from file
1591@cindex image data, determining geometry from file
1592
1593@example
1594\file = "somefile.dat"
1595\rows = system wc \file      | awk '@{print $1@}'
1596\cols = system head -1 \file | awk '@{print NF@}'
1597set x grid 0 1 /\cols
1598set y grid 0 1 /\rows
1599open \file
1600read grid data \rows \cols
1601close
1602draw contour
1603@end example
1604
1605
1606@subsection Complicated example
1607
1608To get a simple contour graph based on pre-gridded
1609data, with full control of axes, etc, do something like this:
1610@cindex drawing contours of pregridded data
1611@cindex example 04 (contouring pregridded data)
1612
1613@c HTML <A HREF="example4.png">
1614@c HTML <IMG ALT="Example 4" SRC="example4-tiny.png"
1615@c HTML ALIGN=top>
1616@c HTML </A>
1617@c HTML <A HREF="example4.html">The command-file.</A> <P>
1618
1619@image{./examples/example4, 300pt}
1620
1621
1622@c HTML <!--
1623@example
1624# Example 4 -- Simple contour graph
1625
1626#
1627# Read x-grid; blank-line means stop reading.
1628read grid x
16290
1630.2
16311
1632
1633# Note that the x-grid was irregular.  The y-grid
1634# in this example is regular, so we can just set
1635# it to range from 10 to 20, incrementing by 2.5.
1636set y grid 10 20 2.5
1637# Thus we now have a grid 3 wide and 5 high.  Let's
1638# read the actual data now.
1639read grid data
16401 2 3
16412 3 4
16423 4 5
16434 5 6
16445 6 7
1645
1646# Now draw contours (automatically set; we could
1647# have done `draw contour 2' to draw contour for
1648# value 2 or `draw contour 1 10 2' to draw contours
1649# ranging from 1 to 10 with an increment of 2.)
1650draw contour
1651draw title "Example 4"
1652@end example
1653@c HTML -->
1654
1655
1656Here several new things have been introduced.
1657
1658First, you've got to define a grid in xy space.  This example uses a
1659non-uniform x-grid, and reads it in from the commandfile.  In this form,
1660the blank line is essential; it tells Gri that the end of data has been
1661located; if you like, you can specify the number of lines to read, as in
1662@code{read grid x 3}.
1663
1664The y-grid for this example is uniform, however, so it may be specified
1665with the @code{set y grid} command.  It obtains values (10, 12.5, 15,
166617.5, 20).  The @code{set x|y grid} commands accept negative increments.
1667Furthermore, it is possible to specify the number of steps, rather than
1668the increment size, by putting @code{/} before the third number; thus
1669@code{set x grid 0 1 /5} and @code{set x grid 0 1 0.2} are equivalent.
1670
1671Having defined a grid, it is time to read in the gridded data.  Here this
1672is done with the @code{read grid data} command.  Since Gri already knows
1673the grid dimensions, it will read the data appropriately.  You could
1674also have told it (@code{read grid data 3 5}).
1675
1676The first dataline is the top of the y-grid.  In other words, the data
1677appear in the file just as they would on the graph, assuming that the
1678x-grid and y-grid both increase.
1679
1680Sometimes you want to read in the transpose of a matrix.  Gri lets you
1681do that.  If the @code{bycolumns} keyword is present at the end of the
1682@code{read grid} command, the first dataline will contain the first
1683@strong{column}, of the data.
1684
1685If you have an extraneous column of data to the left of your data
1686matrix, do @code{read grid data * 2 3}
1687
1688Now Gri has the grid in its head.  We tell it to draw some contours
1689with the @code{draw contour} command.   As the comments in the example
1690show, the contour values will be selected automatically, but you can
1691alter that.
1692
1693
1694
1695
1696
1697@node   Ungridded Data, Images, Pre-gridded Data, Contour Plots
1698@comment  node-name,  next,  previous,  up
1699@section Ungridded data
1700@cindex contours, ungridded data
1701@cindex gridding data, advice on methods
1702When you have f=f(x,y) points at random x and y, you must cast them onto
1703a grid to contour them.  This is a difficult problem.  There are many
1704ways to grid data, and all have both good and bad features.  You should
1705try various methods, and various settings of the parameters of the
1706methods.  If you have a favorite gridding method that you prefer, you
1707should probably pre-grid the data yourself.  If not, Gri can do it for
1708you.  Gri has two methods for doing this, the ``boxcar'' method and the
1709``objective analysis'' method.  Each method puts holes in the grid
1710wherever there are too few data to map to grid points, unless you
1711specifically ask to fill in the whole grid.
1712
1713The next two sections show first an example, then a discussion of the
1714methods and how to use them.
1715
1716@subsection Example
1717@cindex drawing contours of ungridded data
1718@cindex Barnes method for gridding data
1719
1720This example uses data taken from Figure 5 of S. E.  Koch and M.
1721DesJardins and P. J. Kocin, 1983.  ``An interactive Barnes objective map
1722anlaysis scheme for use with satellite and conventional data,'', J.
1723Climate Appl.  Met., vol 22, p. 1487-1503.  Readers should compare
1724Figures 5 and 6 of that paper to the results shown here.
1725
1726@c HTML <A HREF="example5.png">
1727@c HTML <IMG ALT="Example 5" SRC="example5-tiny.png"
1728@c HTML ALIGN=top>
1729@c HTML </A>
1730@c HTML <A HREF="example5.html">The command-file.</A> <P>
1731
1732
1733@image{./examples/example5}
1734@cindex example 05 - Contouring ungridded data, from figure
1735
1736
1737@c HTML <!--
1738@example
1739# Example 5 - Contouring ungridded data, from figure
1740# 5 of Koch et al., 1983, J. Climate Appl. Met.,
1741# volume 22, pages 1487-1503.
1742open example5.dat
1743read columns x y z
1744close
1745set x size 12
1746set x axis 0 12 2
1747set y size 10
1748set y axis 0 10 2
1749draw axes
1750set line width symbol 0.2
1751set symbol size 0.2
1752draw symbol bullet
1753set font size 8
1754draw values
1755set x grid 0 12 0.25
1756set y grid 0 10 0.25
1757
1758# Use default method (Barnes)
1759convert columns to grid
1760
1761set font size 10
1762draw contour 0 40 2
1763set font size 12
1764draw title "Example 5 -- wind (Fig5 Koch et al, 1983)"
1765@end example
1766@c HTML -->
1767
1768
1769
1770@subsection Discussion of Methods
1771
1772The various commands for converting columns to a grid are given in
1773(@ref{Convert Columns To Grid}).  Generally, the Barnes method is best.
1774
1775
1776@c HTML <!-- newfile Images.html "Gri: image plots" "Image Plots" -->
1777
1778@node   Images, Reading and Creating Image Data, Ungridded Data, Top
1779@comment  node-name,  next,  previous,  up
1780@chapter Image Plots
1781@cindex image plots, general
1782
1783Gri can read in images stored in various formats.  It can also create
1784image data internally, by converting gridded data, which is quite handy
1785in some contouring applications.
1786
1787@cindex American Geophysical Union, recommended image gray levels
1788
1789Note: if your diagram is to be reproduced by a journal, it is unlikely
1790that the reproduction will be able to distinguish between any two
1791graylevels which differ by less than 0.2.  Also, graylevels less than
17920.2 may appear as pure black, while those of 0.8 or more may appear as
1793pure white.  These guidelines are as specified by American Geophysical
1794Union (publishers of J. Geophysical Res.), as of 1998.
1795
1796
1797@menu
1798* Reading and Creating Image Data:: Reading image, and creating from grid data
1799* Image PostScript Output::     How the image is embedded in the PostScript
1800* Example Image::               How to plot a satellite image
1801@end menu
1802
1803@node Reading and Creating Image Data, Image PostScript Output, Images, Images
1804@comment  node-name,  next,  previous,  up
1805@section Reading and Creating Image Data
1806@cindex converting grids to images
1807@cindex grid, converting to image
1808@cindex data, images
1809@cindex image, data format
1810
1811Gri can do black and white image plots, such as satellite images.  There
1812are several ways to create image data in Gri
1813@itemize @bullet
1814@item
1815Create images from gridded data using @code{convert grid to image}.  For
1816examples see @ref{Grayscale Images}),
1817@ref{Combination},
1818and @ref{Contouring}.
1819@item
1820Read raw ascii image data files.  Use @code{read grid}.
1821@item
1822Read PGM (portable graymap) ascii files.  (That is, a file with magic
1823characters @code{P1} or @code{P3} at the start.)  Use the
1824@code{read image pgm} command, for a file opened in ascii mode with
1825@code{open filename}.
1826@item
1827Read raw binary data, with or without headers.  Use @code{read image},
1828after skipping any header bytes using the @code{skip} command, for a
1829file opened in binary mode with @code{open filename binary}.
1830@item
1831Read a Sun ``rasterfile'' file (but only in uncompressed form).  Use
1832@code{read image rasterfile} for a file opened in binary mode with
1833@code{open filename binary}.
1834@item
1835Read a PGM (portable graymap) binary file.  (A file with magic
1836characters @code{P2} or @code{P4} at the start.)  Use the
1837@code{read image pgm} for a file opened in binary mode with
1838@code{open filename binary}.
1839@item
1840Aside: Images can be converted to grids (for contouring) using
1841@code{convert image to grid}
1842(@ref{Convert}).
1843@end itemize
1844
1845Once the image is created, its grayscale/colorscale may be manipulated
1846with the commands @code{set image grayscale} and
1847@code{set image colorscale}, which permit linear and histogram-equalized
1848blendings over the grayscale or color range, or with
1849@code{read image grayscale} and
1850@code{read image colorscale}, which permit reading in the grayscale or
1851color values individually, one for each of the 256 pixel values.
1852
1853It is important to understand the structure of image data.  Gri works
1854only with 8-bit image data.  This means that a given pixel of the image
1855may have only one of 256 possible values.  The example below uses a
1856satellite image of surface temperature.  The suppliers of the data
1857dictate that pixel value 0 corresponds to a temperature of 5C, and a
1858pixel value of 255 corresponds to 30.5C, so the resolution is 0.1C per
1859pixel value.  This resolution will be apparent if the output of the
1860example below is previewed on a grayscale/color monitor --- notice the
1861quantization in the palette.  This resolution issue is not very
1862important with satellite images, since you have to use what you are
1863given by the suppliers of the data.  However, the issue is very important
1864when you are converting grid data to images.  When Gri converts grid
1865data to image data, it neccessarily discards information, because the
1866grid data have resolution to about 6 digits, whereas the image data have
1867only 8-bit (2-3 digit) resolution.  The @code{set image range} commands
1868determines the range of this 8-bit resolution in terms of user units.
1869All other things being equal, it would be preferable to use the smallest
1870range consistent with the range of your data.  If your grid data ranged
1871from 0 to 1, say, you might @code{set image range 0 1}.  This would give
1872a resolution in the image of 1/255 in the user units.  But, when Gri
1873converts the grid into an image, it will @strong{clip} all data outside
1874the indicated range.  In this case, any data greater than 1 in the grid
1875would translate to @strong{exactly} 1 in the image.  Naturally there is a
1876tradeoff between having a range large enough to encompass any data in
1877the grid, and a range small enough to yield adequate resolution.  In
1878most cases, 8-bit resolution will be adequate, but it is good to be
1879aware of the limitations.  One should always @code{draw image palette},
1880and check it on a color monitor for bandedness, which is a sign of
1881resolution problems.
1882
1883
1884
1885@node  Image PostScript Output, Example Image, Reading and Creating Image Data, Images
1886@comment  node-name,  next,  previous,  up
1887@section About The PostScript Output
1888@cindex image, PostScript output
1889@cindex postscript output, embedded images
1890
1891Programmers Note: Gri inserts some special comments in the PostScript
1892file, to help programmers extract the image data; to extract the
1893information, you'll have to understand how PostScript handles images.
1894Gri inserts a single comment line before a line ending in the token
1895@code{im}:
1896
1897@example
1898%BEGIN_IMAGE
1899170.70 170.70 534.86 534.86 128 128 im
1900@end example
1901@noindent
1902The first four numbers are the (x,y) locations of the lower-left and
1903upper-right corners of the image, in units of points on the page (72
1904points = 1 inch).  The fifth and sixth numbers are the width of the
1905image and the height of the image.  The keyword @code{im} is always
1906present on this line.  Gri inserts the following comment line at the end
1907of the image data
1908
1909@example
1910%END_IMAGE
1911@end example
1912
1913@node  Example Image, Examples, Image PostScript Output, Images
1914@comment  node-name,  next,  previous,  up
1915@section Example (Satellite image)
1916@cindex satellite images
1917
1918Here's an example that will plot different types of images, depending on
1919your answers to @code{query} questions.  The file called
1920@file{\filename} is the data file, in binary format with one byte
1921(@code{unsigned char} in C) for each pixel, stored with the northwest
1922pixel first, and the pixel to the east of that next. The file called
1923@code{\mask} is in the same format, and the numbers are 0 if the point
1924is over the sea and 1 if over land.  The mask file is used in computing
1925the histograms, which is done if @code{\histo} is 1.
1926
1927The file in this example covers 128 * 128 pixels over the Gulf of
1928Maine. The numbers in @code{\filename} correspond to surface
1929temperatures according to the equation
1930
1931@example
1932T = 5 + 0.1 * pixel_value
1933@end example
1934
1935@noindent
1936which explains the following lines in the command file:
1937
1938@example
1939\0val = "5"             # 0 in image
1940\255val = "30.5"        # 255 in image
1941@end example
1942
1943@cindex images, histogram scaling
1944@cindex images, linear scaling
1945
1946Depending on @code{\histo}, the graymap will be linear or
1947histogram-enhanced. The histogram method
1948consists of dividing the cumulative histogram for the values in the
1949image up into 256 levels, and assigning a graylevel to each.  This has
1950the effect of creating maximal contrast in all ranges of graylevel. It
1951points up features really well, but it is a nonlinear mapping, so it is
1952not good for telling you where gradients are strong or weak.
1953
1954@c HTML <!--
1955Examples are shown for linear mapping and histogram mapping.
1956@c HTML -->
1957@cindex histogram enhancement of image plots
1958@cindex drawing image plots
1959@cindex drawing satellite images
1960
1961@c HTML <A HREF="example6.png">
1962@c HTML <IMG ALT="Example 6" SRC="example6-tiny.png"
1963@c HTML ALIGN=top>
1964@c HTML </A>
1965@c HTML <A HREF="example6.html">The command-file.</A> <P>
1966
1967
1968@image{./examples/example6}
1969
1970@image{./examples/example6histogram}
1971@cindex example 06, plot IR image of Gulf of Maine
1972
1973@c HTML <!--
1974@example
1975# Example 6 -- Plot IR image of Gulf of Maine
1976# Define characteristics of norda images
1977# Note that the pixel to temperature conversion formula is
1978#
1979#   Temperature = 5C + pixel_value / 10
1980#
1981# where pixel_value ranges from 0 to 255.  Thus, a pixel value of 0
1982# corresponds to a temperature of 5C, and 255 corresponds to 30.5C;
1983# this is why the limits \0val and \255val, for use by the `set image
1984# range' command, take on these values.
1985\0val = "5"                     # 0 in image
1986\255val = "30.5"                # 255 in image
1987.rows. = 128
1988.cols. = 128
1989.pixel_width. = 2
1990.km. = @{rpn .cols. .pixel_width. *@}
1991
1992# get filenames
1993query \filename "Name image file" ("example6image.dat")
1994query \maskname "Name mask  file" ("example6mask.dat")
1995
1996# get data, then mask, each in 8-bit image format
1997open \filename 8bit
1998set image range \0val \255val
1999read image .rows. .cols. box 0 0 .km. .km.
2000close
2001open \maskname 8bit
2002read image mask .rows. .cols.
2003close
2004
2005# find out what grayscale method to use
2006query \histo "Do histogram enhancement? (yes|no)" ("no")
2007query \minT  "T/deg for white on page?          " ("10")
2008query \maxT  "T/deg for black on page?          " ("15")
2009\incT = "1"
2010
2011# set up scales.
2012set x size 12.8
2013set y size 12.8
2014set x name "km"
2015set y name "km"
2016set x axis 0 .km. 32
2017set y axis 0 .km. 32
2018
2019# plot image, grayscale, and histogram
2020if @{"\histo" == "yes"@}
2021    set image grayscale using histogram black \maxT white \minT
2022else
2023    set image grayscale black \maxT white \minT
2024end if
2025draw image
2026draw image palette left \minT right \maxT increment \incT
2027draw image histogram
2028if @{"\histo" == "yes"@}
2029    draw title "Example 6: grayscale histogram enhanced"
2030else
2031    draw title "Example 6: grayscale linear \minT to \maxT"
2032end if
2033@end example
2034@c HTML -->
2035
2036
2037
2038@c HTML <!-- newfile Examples.html "Gri: extra examples" "Examples" -->
2039
2040@node   Examples, Box Plots, Example Image, Top
2041@comment node-name,  next,  previous,  up
2042@chapter Real-world examples
2043@cindex cookbook
2044The example files in this manual should be available to you directly,
2045having been installed with Gri; if not, ask your system manager to check
2046the FTP site.
2047
2048Additionally, I've collected a few real life examples here.  Other
2049sources are the Gri cookbook, available at
2050@url{http://gri.sourceforge.net/gri-cookbook/index.html}.
2051
2052
2053@menu
2054* Box Plots::                   Tukey box plots, which show histograms
2055* Contouring::                  sample contour plot
2056* Grayscale Images::            create and plot image, from gridded data
2057* Combination::                 image and contour combination plot
2058* Fancy::                       fancy plot with lots of tricks
2059* Legend::                      plot with annotated curves and legend
2060* Polygons::                    read geometry, then draw polygon
2061* TS Diagram::                  temperature-salinity diagrams
2062* PDF Diagram::                 probability-density function
2063* Running Means::               skyline plot of running means
2064* Finite Element Model Mesh::   plotting mesh of FEM-type model
2065* Handling Data::               samples of handling data
2066@end menu
2067
2068
2069@c HTML <!-- newfile BoxPlots.html "Gri: box plots" "Examples" -->
2070
2071@node   Box Plots, Contouring, Examples, Examples
2072@comment  node-name,  next,  previous,  up
2073@section Box plots
2074Box plots were invented by Tukey for eda (exploratory data analysis).
2075They show nonparametric statistics.  The centre of the box is the
2076median.  The box edges show the first quartile (q1) and the third
2077quartile (q3).  The distance from q3 to q1 is called the inter-quartile
2078range.  The whiskers (lines with crosses on them) extend to the furthest
2079points still within 1.5 inter-quartile ranges of q1 and q3.  Beyond the
2080whiskers, all outliers are shown, in open circles up to a distance of 3
2081inter-quartile ranges beyond q1 and q3, and in closed circles beyond
2082that.  Below is an example that uses a "new command" to define each box
2083plot (@ref{Adding New Commands}).
2084
2085@c HTML <A HREF="example7.png">
2086@c HTML <IMG ALT="Example 7" SRC="example7-tiny.png"
2087@c HTML ALIGN=top>
2088@c HTML </A>
2089@c HTML <A HREF="example7.html">The command-file.</A> <P>
2090
2091
2092@image{./examples/example7}
2093
2094@cindex example 07, box plots of mixing efficiency vs density ratio (meddy)
2095
2096
2097@c HTML <!--
2098@example
2099# Example 7 -- Box plots of mixing efficiency vs density ratio (meddy)
2100
2101`Draw y boxplot from \file at .x.'
2102Draw a y boxplot for data in given file, at given
2103value of x.
2104@{
2105    open \.word4.
2106    read columns * y
2107    close
2108    draw y box plot at \.word6.
2109@}
2110if !..publication..
2111    draw time stamp
2112end if
2113set x axis 1 3 1 0.1
2114set x name "Density Ratio, $R_\rho$"
2115set x margin 4
2116set y axis -2 1 1
2117#
2118# Must fool gri into not drawing the axes, because the y data
2119# are already in logspace.
2120draw axes none
2121Draw y boxplot from example7a.dat at 1.3
2122Draw y boxplot from example7b.dat at 1.4
2123Draw y boxplot from example7c.dat at 1.5
2124Draw y boxplot from example7d.dat at 1.6
2125Draw y boxplot from example7e.dat at 1.7
2126Draw y boxplot from example7f.dat at 1.8
2127Draw y boxplot from example7g.dat at 1.9
2128delete y scale
2129set y name "Efficiency, $\Gamma$"
2130set y type log
2131set y axis 0.01 10 1
2132draw axes
2133draw title "Example 7 -- Box plot"
2134@end example
2135@c HTML -->
2136
2137
2138@c HTML <!-- newfile ContouringExample.html "Gri: contouring example" "Examples" -->
2139
2140
2141@node   Contouring, Grayscale Images, Box Plots, Examples
2142@comment  node-name,  next,  previous,  up
2143@section Contouring
2144This example plots a section of dT/drho vs x and rho (actually, sigma-t,
2145as the label indicates).  The contours are unlabelled; I'm only
2146interested in the zero crossings.
2147
2148There are some other useful tricks in this example, such as calling
2149@code{awk} and @code{wc} from the unix system.
2150
2151(In the plot shown, all @code{query} questions were answered with
2152carriage return, yielding the defaults; the @code{-p} flag was specified
2153on execution, so the time stamp was not drawn.)
2154
2155@c HTML <A HREF="example8.png">
2156@c HTML <IMG ALT="Example 8" SRC="example8-tiny.png"
2157@c HTML ALIGN=top>
2158@c HTML </A>
2159@c HTML <A HREF="example8.html">The command-file.</A> <P>
2160
2161
2162@image{./examples/example8}
2163
2164@cindex example 08, plot T=T(x,rho) section of eubex data
2165
2166
2167
2168@c HTML <!--
2169@example
2170# Example 8 -- Plot T=T(x,rho) section of eubex data
2171
2172`Initialize Parameters'
2173@{
2174    \FILE_DATA = "example8a.dat" # T vs rho
2175    \FILE_LOCN = "example8b.dat" # section distances
2176    set missing value -99.0
2177    #
2178    # Following values from ~/eubex/processing/to_rho_bins/do_rho_inter
2179    \RHO_MIN = "28.1"
2180    \RHO_MAX = "27.5"
2181    \RHO_INC = "-0.002"
2182    \NY = "301"
2183    \xmin = "350"
2184    \xmax = "0"
2185    \xinc = "-100"
2186    \ymin = "28.1"
2187    \ymax = "27.8"
2188    \yinc = "-0.1"
2189    \zmin = "0"
2190    \zmax = "2.5"
2191@}
2192`Initialize Axes'
2193/*
2194Set up axes
2195*/
2196@{
2197    set x name "km"
2198    set x size 10
2199    set x axis \xmin \xmax \xinc
2200    set y name "$\sigma_T$"
2201    set y size 5
2202    set y axis name horizontal
2203    set y axis \ymin \ymax \yinc
2204    set y format "%.1f"
2205@}
2206`Initialize Files'
2207@{
2208    query \data "Data file?   " ("\FILE_DATA")
2209    query \locn "Station locn?" ("\FILE_LOCN")
2210@}
2211`Read Data'
2212@{
2213    # Read x-locations
2214    system awk '@{print $2@}' < \locn > TMP
2215    system wc TMP | awk '@{print $1@}' > NUM
2216    open NUM
2217    read .gridx_number.
2218    close
2219    system rm NUM
2220    open TMP
2221    read grid x .gridx_number.
2222    close
2223    system rm TMP
2224    # Create y-locations
2225    set y grid \RHO_MIN \RHO_MAX \RHO_INC
2226    #
2227    # Read data
2228    open \data
2229    read grid data \NY .gridx_number.
2230    close
2231@}
2232`Plot Contours'
2233@{
2234    set graylevel .contour_graylevel.
2235    set clip on
2236    set line width 0.5
2237    draw contour -3 3 0.25 unlabelled
2238    #
2239    # wide line at 0 degrees
2240    set line width 2
2241    draw contour 0 unlabelled
2242@}
2243`Plot Image And Maybe Contours'
2244@{
2245    \imagefile = "image"
2246    set image range \zmin \zmax
2247    convert grid to image box \xmin  \ymin \xmax \ymax
2248    query \dohisto "Do histogram scaling? (yes|no)" ("yes")
2249    \incs = "no"
2250    if @{"\dohisto" == "yes"@}
2251	set image grayscale using histogram
2252    else
2253	\zinc = "0.25"
2254	query \incs "In linear scaling, band at an increment of \zinc?" ("yes")
2255	if @{"\incs" == "yes"@}
2256	    set image grayscale black \zmin white \zmax increment \zinc
2257	else
2258	    set image grayscale black \zmin white \zmax
2259	end if
2260    end if
2261    write image rasterfile to \imagefile
2262    show "wrote image rasterfile `\imagefile '"
2263    draw image
2264    draw image palette
2265    query \do_contours "Do contours as well (yes|no)" ("yes")
2266    if @{"\do_contours" == "yes"@}
2267	Plot Contours
2268    end if
2269    draw title "Example 8 -- \data black=\zmin white=\zmax"
2270    if @{"\dohisto" == "yes"@}
2271	draw title "Histogram enhanced grayscales"
2272    else
2273	if @{"\incs" == "yes"@}
2274	    draw title "Grayscale banded at intervals of \zinc"
2275	end if
2276    end if
2277@}
2278Initialize Parameters
2279Initialize Axes
2280Initialize Files
2281Read Data
2282query \doimage "Draw image (yes|no)" ("no")
2283if @{"\doimage" == "yes"@}
2284    .contour_graylevel. = 1	# white contours
2285    Plot Image And Maybe Contours
2286else
2287    .contour_graylevel. = 0	# black contours
2288    Plot Contours
2289    draw title "Example 8"
2290end if
2291@end example
2292@c HTML -->
2293
2294
2295
2296@c HTML <!-- newfile ImageExample.html "Gri: image example" "Examples" -->
2297
2298@node   Grayscale Images, Combination, Contouring, Examples
2299@comment  node-name,  next,  previous,  up
2300@section Image created from coarsely gridded data
2301This example reads gridded ascii station data (@code{Read Data}),
2302creates an interpolated image (@code{convert grid ...}), and then plots
2303the image.
2304
2305There are some other useful tricks in this example, such as calling
2306@code{awk} and @code{wc} from the unix system.
2307
2308(In the plot shown, all @code{query} questions were answered with
2309carriage return, yielding the defaults; the @code{-p} flag was specified
2310on execution, so the time stamp was not drawn.)
2311@cindex axes, automatic drawing of
2312
2313@c HTML <A HREF="example9.png">
2314@c HTML <IMG ALT="Example 9" SRC="example9-tiny.png"
2315@c HTML ALIGN=top>
2316@c HTML </A>
2317@c HTML <A HREF="example9.html">The command-file.</A> <P>
2318
2319@image{./examples/example9}
2320
2321@cindex example 09, plot dTdrho-rho section
2322
2323
2324@c HTML <!--
2325@example
2326# Example 9 -- Plot dTdrho-rho section
2327
2328`Initialize Parameters'
2329@{
2330    \FILE_DATA = "example9a.dat" # T vs rho
2331    \FILE_LOCN = "example9b.dat" # section distances
2332    #
2333    # Following values from ~/eubex/processing/to_rho_bins/do_rho_inter
2334    \RHO_MIN = "28.1"
2335    \RHO_MAX = "27.5"
2336    \RHO_INC = "-0.002"
2337    \NY = "301"
2338    set missing value -99.0
2339    \xmin = "350"
2340    \xmax = "0"
2341    \xinc = "-100"
2342    \ymin = "28.1"
2343    \ymax = "27.8"
2344    \yinc = "-0.1"
2345    \zmin = "-10"		# black
2346    \zmax = "0"			# white
2347@}
2348`Initialize Axes'
2349Set up axes.
2350@{
2351    set x name "km"
2352    set x size 10
2353    set x axis \xmin \xmax \xinc
2354    set y size 5
2355    set y name "$\sigma_T$"
2356    set y axis name horizontal
2357    set y axis \ymin \ymax \yinc
2358    set y format %.1lf
2359    draw axes none
2360@}
2361`Initialize Files'
2362@{
2363    query \data "Data file?   " ("\FILE_DATA")
2364    query \locn "Station locn?" ("\FILE_LOCN")
2365@}
2366`Read Data'
2367@{
2368    # Read x-locations
2369    system awk '@{print $2@}' < \locn > TMP
2370    system wc TMP | awk '@{print $1@}' > NUM
2371    open NUM
2372    read .gridx_number.
2373    close
2374    system rm NUM
2375    open TMP
2376    read grid x .gridx_number.
2377    close
2378    system rm TMP
2379    # Create y-locations
2380    set y grid \RHO_MIN \RHO_MAX \RHO_INC
2381    #
2382    # Read data
2383    open \data
2384    read grid data \NY .gridx_number.
2385    close
2386@}
2387Initialize Parameters
2388Initialize Axes
2389Initialize Files
2390Read Data
2391set image range \zmin \zmax
2392set image colorscale hsb 0 1 1 \zmin   hsb .6 1 1 \zmax
2393convert grid to image box \xmin  \ymin \xmax \ymax
2394#
2395# Draw the image, then draw the axes.  Note that the image has
2396# extends beyond the axes frame, so we will turn clipping
2397# on before drawing it, to make a clean picture.
2398set clip postscript on
2399draw image
2400set clip postscript off
2401draw axes
2402
2403#
2404# All done.
2405draw title "Example 9"
2406if @{"\dohisto" == "yes"@}
2407    draw title "Histogram enhanced grayscales"
2408end if
2409@end example
2410@c HTML -->
2411
2412
2413@c HTML <!-- newfile ImageWithContours.html "Gri: image and contours" "Examples" -->
2414
2415@node   Combination, Fancy, Grayscale Images, Examples
2416@comment  node-name,  next,  previous,  up
2417@section Combination of image and contour
2418@cindex image plot, with contours
2419@cindex contours on images
2420
2421The following example reads gridded data and creates an image as in the
2422previous example, but also superimposes unlabelled white contour lines.
2423
2424(In the plot shown, all @code{query} questions were answered with
2425carriage return, yielding the defaults; the @code{-p} flag was specified
2426on execution, so the time stamp was not drawn.)
2427@cindex example 10 (image plot with contours)
2428
2429@c HTML <A HREF="example10.png">
2430@c HTML <IMG ALT="Example 10" SRC="example10-tiny.png"
2431@c HTML ALIGN=top>
2432@c HTML </A>
2433@c HTML <A HREF="example10.html">The command-file.</A> <P>
2434
2435@image{./examples/example10}
2436
2437@cindex example 10, draw image plot of flushing of dye out of cove
2438
2439
2440@c HTML <!--
2441@example
2442# Example 10 -- Draw image plot of flushing of dye out of cove
2443if !..publication..
2444    draw time stamp
2445end if
2446\file = "example10.dat"
2447query \contours "Superimpose contours? (yes|no)" ("yes")
2448query \file     "Input file name               " ("\file")
2449open \file
2450read line \header
2451read \D
2452read .nx.
2453read .ny.
2454set x name "distance along cove"
2455set y name "time"
2456set x grid 0 1 /.nx.
2457set x axis 0 1 0.5 0.1
2458set y grid 0 .ny. / .ny.
2459set y axis 0 .ny.
2460read grid data * * .ny. .nx.
2461set image range 0 20
2462set image grayscale black 20 white 0 increment 5
2463convert grid to image
2464draw image
2465if @{"\contours" == "yes"@}
2466    set graylevel 1.0
2467    draw contour 0 20 1 unlabelled
2468    set graylevel 0.0
2469end if
2470draw axes
2471draw image palette left -1 right 21 increment 5
2472draw title "Example 10 -- file=\file header=`\header'"
2473@end example
2474@c HTML -->
2475
2476@ifhtml
2477A color version of this is possible using @code{set image colorscale}
2478as shown here:
2479@cindex example 10color, draw color image plot
2480@end ifhtml
2481
2482@c HTML <A HREF="example10color.png">
2483@c HTML <IMG ALT="Example 10 in colour" SRC="example10color-tiny.png"
2484@c HTML ALIGN=top>
2485@c HTML </A>
2486@c HTML <A HREF="example10color.html">The command-file.</A> <P>
2487
2488
2489@c HTML <!--
2490@example
2491# Example 10color -- Draw color image plot
2492
2493# Test various colorscales.
2494# INSTRUCTIONS: Uncomment one of the following '\scale = ' statements
2495
2496# CASE 1: From black at high values to white at low values
2497#\scale = "rgb 0 0 0 20.0 rgb 1 1 1  0.0 increment 5"
2498
2499# CASE 2: From skyblue at 20 to tan for 0; traverse RGB space
2500#         See also case 5, which names the colors.
2501#\scale = "rgb 0.529 0.808 0.922 20.0 rgb 0.824 0.706 0.549 0.0 increment 5"
2502
2503# CASE 3: From skyblue at 20 to tan for 0; traverse HSB space
2504#         Is it just me, or is this uglier than case 2?
2505#\scale = "hsb 0.548 0.426 0.922 20.0 hsb 0.095 0.334 0.824 0.0 increment 5"
2506
2507# CASE 4: Use a spectrum; traverse HSB space
2508#\scale = "hsb 0 1 1 20.0 hsb 0.6666 1 1  0.0 increment 5"
2509
2510# CASE 5: From skyblue to tan, traversing RGB space (by default)
2511#         (Compare case 2, which uses similar endpoints, with
2512#         colors specified with RGB values, and larger increment.)
2513#\scale = "skyblue 20.0 tan 0.0 increment 2"
2514
2515# CASE 6: From skyblue to tan, traversing RGB space (by default)
2516#         Compare 2 and 5; note this has continuous increment
2517#\scale = "skyblue 20.0 tan 0.0"
2518
2519# CASE 7: From blue to brown
2520\scale = "blue 20.0 brown 0.0 increment 2.5"
2521
2522open example10.dat
2523read line \header
2524read \D
2525read .nx.
2526read .ny.
2527set x name "distance along cove"
2528set y name "time"
2529set x grid 0 1 /.nx.
2530set x axis 0 1 0.5 0.1
2531set y grid 0 .ny. / .ny.
2532set y axis 0 .ny.
2533read grid data * * .ny. .nx.
2534set image range 0 20
2535convert grid to image
2536set image colorscale \scale
2537draw image
2538
2539# Draw contours in white ink
2540set graylevel 1.0
2541draw contour 0 20 1 unlabelled
2542set graylevel 0.0
2543
2544draw axes                               # redraw in case whited out
2545draw image palette left -1 right 21 increment 5
2546set font size 9
2547
2548# Title tells what method used
2549draw title "Used `draw image colorscale \scale'"
2550@end example
2551@c HTML -->
2552
2553
2554
2555@c HTML <!-- newfile FancyPlot.html "Gri: adding bells and whistles" "Examples" -->
2556
2557
2558@node   Fancy, Legend, Combination, Examples
2559@comment  node-name,  next,  previous,  up
2560@section Fancy x-y linegraph
2561@cindex fancy plot
2562The following code shows a fancy plot with lots of bells and whistles.
2563@cindex multiple panels, example
2564@cindex labels, example
2565@cindex graylevel for lines, example
2566
2567@c HTML <A HREF="example11.png">
2568@c HTML <IMG ALT="Example 11" SRC="example11-tiny.png"
2569@c HTML ALIGN=top>
2570@c HTML </A>
2571@c HTML <A HREF="example11.html">The command-file.</A> <P>
2572
2573
2574
2575@image{./examples/example11, 400pt}
2576
2577@cindex example 11, fancy plot
2578
2579
2580
2581@c HTML <!--
2582@example
2583# Example 11 -- Fancy plot
2584# Pen sizes, etc.
2585#
2586.thin. = 0.5                    # for whole data set
2587.thick. = 2                     # for bravo time period
2588.gray_for_guiding_lines. = 0.75 # for guiding lines
2589.tmin. = 1964                   # time axis
2590.tmax. = 1974
2591.tinc. = 5
2592.tincinc. = 1
2593.missing_value. = -9
2594\file = "./example11.dat"
2595#
2596# Guiding lines to draw on both panels.
2597#
2598.1xl. = 1962
2599.1yb. = -3
2600.1xr. = 1968
2601.1yt. = 3
2602.1slope. = @{rpn .1yt. .1yb. - .1xr. .1xl. - /@}
2603.1intercept. = @{rpn .1yb. .1slope. .1xl. * -@}
2604.2xl. = 1966.4
2605.2yb. = 3
2606.2xr. = 1980
2607.2yt. = -1
2608.2slope. = @{rpn .2yt. .2yb. - .2xr. .2xl. - /@}
2609.2intercept. = @{rpn .2yb. .2slope. .2xl. * -@}
2610#
2611# PANEL 1: Bravo time period.
2612#
2613set x margin 3
2614set x size 15
2615set y margin 3
2616set y size 5
2617# Draw border big enough for this and next panel.
2618draw border box @{rpn ..xmargin.. 2 -@} \
2619    @{rpn ..ymargin.. 2 -@} \
2620    @{rpn ..xmargin.. ..xsize.. + 2 +@} \
2621    @{rpn ..ymargin.. ..ysize.. 2 * 3 + + 2 +@} \
2622    0.2 0.75
2623set missing value .missing_value.
2624set ignore error eof
2625set x name "Year"
2626set x axis .tmin. .tmax. .tinc. .tincinc.
2627set y name "Area / 10$^5$km$^2$"
2628set y axis -3 3 1
2629draw axes
2630#
2631# Draw index lines 1 and 2.
2632#
2633# Upward sloped line.
2634set line width .thin.
2635set graylevel .gray_for_guiding_lines.
2636if @{rpn .1intercept. ..xright.. .1slope. * + ..ytop.. <@}
2637    draw line from              \
2638        ..xleft..               \
2639        @{rpn .1intercept. ..xleft.. .1slope. * +@} \
2640        to                      \
2641        @{rpn ..ytop.. .1intercept. - .1slope. /@} \
2642        ..ytop..
2643else
2644    draw line from              \
2645        ..xleft..               \
2646        @{rpn .1intercept. ..xleft.. .1slope. * +@} \
2647        to                      \
2648        ..xright..              \
2649        @{rpn .1intercept. ..xright.. .1slope. * +@}
2650end if
2651set graylevel 0
2652#
2653# Downward sloped line.
2654set line width .thin.
2655set graylevel .gray_for_guiding_lines.
2656if @{rpn .2intercept. ..xleft.. .2slope. * + ..ytop.. <@}
2657    draw line from              \
2658        @{rpn ..ytop.. .2intercept. - .2slope. /@} \
2659        ..ytop..                \
2660        to                      \
2661        ..xright..              \
2662        @{rpn .2intercept. ..xright.. .2slope. * +@}
2663else
2664    draw line from              \
2665        ..xleft..               \
2666        @{rpn .2intercept. ..xleft.. .2slope. * +@} \
2667        to                      \
2668        ..xright..              \
2669        @{rpn .2intercept. ..xright.. .2slope. * +@}
2670end if
2671set graylevel 0
2672#
2673# Finally, draw the data curve on top, after first
2674# whiting out a background.
2675set input data window x .tmin. .tmax.
2676open \file
2677read columns x y
2678close
2679y /= 1e5
2680set line width ..linewidthaxis..
2681draw zero line
2682set line width @{rpn .thick. 3 *@}
2683set graylevel 1
2684draw curve
2685set graylevel 0
2686set line width .thick.
2687draw curve
2688
2689#
2690# PANEL 2: Longer timescale.
2691#
2692delete x scale
2693set x margin bigger 5
2694set x size 10
2695set x name ""
2696set y name ""
2697set y margin bigger @{rpn ..ysize.. 3 +@}
2698#
2699# Draw long data set in thin pen.
2700set input data window x off
2701open \file
2702read columns x y
2703close
2704y /= 1e5
2705#
2706# Draw guiding lines, axes, etc.
2707set x axis 1952 1980 5 1
2708draw axes frame
2709set line width .thin.
2710set graylevel .gray_for_guiding_lines.
2711draw line from .1xl. .1yb. to .1xr. .1yt.
2712draw line from .2xl. .2yb. to .2xr. .2yt.
2713set graylevel 0
2714set line width ..linewidthaxis..
2715draw zero line
2716
2717
2718draw x axis at bottom
2719.old. = ..fontsize..
2720set font size 0
2721draw y axis at left
2722set font size .old.
2723delete .old.
2724#
2725# Draw full curve (first whiting out region around it).
2726set line width @{rpn .thin. 4 *@}
2727set graylevel 1
2728draw curve
2729set graylevel 0
2730set line width .thin.
2731draw curve
2732#
2733# Draw bravo time period (first whiting out region around it).
2734set input data window x .tmin. .tmax.
2735open \file
2736read columns x y
2737close
2738y /= 1e5
2739set line width @{rpn .thick. 3 *@}
2740set graylevel 1
2741draw curve
2742set graylevel 0
2743set line width .thick.
2744draw curve
2745#
2746# Done
2747set font size 20
2748\label = "Example 11 (Arctic ice anomaly)"
2749draw label "\label" at          \
2750    @{rpn 8.5 2.54 * "\label" width - 2 /@} \
2751    @{rpn ..ytop.. yusertocm 0.7 +@} \
2752    cm
2753if !..publication..
2754    draw time stamp
2755end if
2756@end example
2757@c HTML -->
2758
2759
2760
2761
2762@c HTML <!-- newfile Legend.html "Gri: drawing legends for curve types etc" "Examples" -->
2763
2764
2765@node   Legend, Polygons, Fancy, Examples
2766@comment  node-name,  next,  previous,  up
2767@section Legends and annotated lines
2768@cindex drawing legends
2769@cindex legends
2770@cindex annotating lines
2771The following example shows how to handle annotated curves and legends.
2772
2773
2774@c HTML <A HREF="example12.png">
2775@c HTML <IMG ALT="Example 12" SRC="example12-tiny.png"
2776@c HTML ALIGN=top>
2777@c HTML </A>
2778@c HTML <A HREF="example12.html">The command-file.</A> <P>
2779
2780@image{./examples/example12}
2781
2782@cindex example 12, linegraph with key inside plot
2783
2784
2785@c HTML <!--
2786@example
2787# Example 12 -- Linegraph with key inside plot
2788set font size 10                # points (1in = 72pt)
2789set x size 10                   # cm
2790set y size 10                   # cm
2791set x name "Height"
2792set y name "Total Energy"
2793
2794# Following axis setups not necessary; will autoscale if you
2795# remove these.
2796set x margin 3
2797set x axis 800 960 20
2798set y margin 3
2799set y axis -0.4 1 0.2
2800
2801# Read data.  Format is columns (x, y1, y2, y3, y4)
2802open example12.dat
2803read columns x y
2804draw curve
2805draw label for last curve "1"
2806
2807rewind
2808set line width @{rpn ..linewidth.. 1.5 *@}
2809read columns x * y
2810draw curve
2811draw label for last curve "2"
2812
2813rewind
2814set line width @{rpn ..linewidth.. 1.5 *@}
2815read columns x * * y
2816draw curve
2817draw label for last curve "3"
2818
2819rewind
2820set line width @{rpn ..linewidth.. 1.5 *@}
2821read columns x * * * y
2822draw curve
2823draw label for last curve "4"
2824
2825# Draw the key.
2826# NOTES:
2827# (1) This key is inside the plot; its location was chosen
2828#     after looking at the data.  To put the key in a different
2829#     location, alter the .key_topleft_x. and .key_topleft_y.
2830#     variables.  For example, you could put the key to the
2831#     right of the plot by changing the next line to:
2832#     `.key_topleft_x. = @{rpn ..xsize.. 0.5 +@}'
2833# (2) The variable .dy_inc. is the spacing between lines in
2834#     the key.  It should be OK even if you change the
2835#     font size above.
2836.key_topleft_x. = 0.5           # cm right of left axis
2837.key_topleft_y. = 0.5           # cm below top axis
2838.dy_inc. = @{rpn ..fontsize.. pttocm 1.5 *@}
2839
2840draw label "1 = Model 1A" at    \
2841    @{rpn ..xleft.. xusertocm .key_topleft_x. +@} \
2842    @{rpn ..ytop.. yusertocm .key_topleft_y. -@} cm
2843
2844.key_topleft_y. += .dy_inc.
2845draw label "2 = Model 2A" at    \
2846    @{rpn ..xleft.. xusertocm .key_topleft_x. +@} \
2847    @{rpn ..ytop.. yusertocm .key_topleft_y. -@} cm
2848
2849.key_topleft_y. += .dy_inc.
2850draw label "3 = Model 1B" at    \
2851    @{rpn ..xleft.. xusertocm .key_topleft_x. +@} \
2852    @{rpn ..ytop.. yusertocm .key_topleft_y. -@} cm
2853
2854.key_topleft_y. += .dy_inc.
2855draw label "4 = Model 2B" at    \
2856    @{rpn ..xleft.. xusertocm .key_topleft_x. +@} \
2857    @{rpn ..ytop.. yusertocm .key_topleft_y. -@} cm
2858
2859draw title "Example 12 -- Total heating vs height of boundary layer"
2860@end example
2861@c HTML -->
2862
2863
2864@c HTML <!-- newfile Polygons.html "Gri: drawing polygons" "Examples" -->
2865
2866@node   Polygons, TS Diagram, Legend, Examples
2867@comment  node-name,  next,  previous,  up
2868@section Drawing gray polygons
2869@cindex polygons, filled
2870@cindex gray level, example for polygons
2871The following example shows how to draw polygons of a graylevel that is
2872read in.  It also draws a bullet (within the polygon).  See the help
2873lines at the start.
2874
2875@example
2876`Draw Polygon And Bullet'
2877Draw a polygon of a given graylevel, with a bullet
2878(black dot) at an indicated location.  The polygon
2879coordinates are read in by this command, as are
2880the graylevel and the location of the bullet.
2881
2882Variables used:
2883  .black.
2884  .white.
2885
2886Input data read:
2887
2888line   1:
2889  A code (which is ignored) and a graylevel
2890  to draw the polygon with. The value for this
2891  graylevel ranges from .black. (which codes
2892  to black ink on the paper) to .white.
2893  (which codes to blank paper).
2894
2895line   2:
2896  An (x,y) location for the bullet.
2897
2898line   3:
2899  Skipped.
2900
2901line 4-n:
2902  Locations of vertices of polygon, ended with a blank line.
2903@{
2904  read .code. .graylevel. # Read line 1
2905  read .x. .y.            # Read line 2
2906  skip                    # Skip line 3
2907  read columns x y        # Read a polygon
2908  # Adjust .graylevel. to range between 0
2909  # (for black ink) and 1 (for white paper),
2910  # then set graylevel and draw polygon.
2911  .graylevel. = @{rpn .graylevel. \
2912      .black. - .white. .black. - /@}
2913  set graylevel .graylevel.
2914  draw curve filled
2915  # Draw black bullet
2916  set graylevel 0
2917  draw symbol bullet at .x. .y.
2918  # Clean up local storage.
2919  delete .code.
2920  delete .graylevel.
2921  delete .x.
2922  delete .y.
2923@}
2924@end example
2925
2926
2927@c HTML <!-- newfile TSDiagram.html "Gri: drawing TS diagrams" "Examples" -->
2928
2929@node   TS Diagram, PDF Diagram, Polygons, Examples
2930@comment  node-name,  next,  previous,  up
2931@section Temperature-Salinity Diagram
2932@cindex oceanographic plots
2933@cindex oceanographic plots, isopycnals on TS diagrams
2934@cindex T-S diagram, example of drawing
2935@cindex temperature-salinity diagram
2936@cindex isopycnals
2937Here is how you might draw an oceanographic "TS" (temperature salinity)
2938diagram:
2939@cindex example 13, TS diagram, with isopycnals
2940
2941@c HTML <A HREF="example13.png">
2942@c HTML <IMG ALT="Example 13" SRC="example13-tiny.png"
2943@c HTML ALIGN=top>
2944@c HTML </A>
2945@c HTML <A HREF="example13.html">The command-file.</A>
2946
2947
2948@image{./examples/example13}
2949
2950@c HTML <!--
2951@example
2952# Example 13 -- TS diagram, with isopycnals
2953#
2954# Draw Axes
2955set line width axis 0.25
2956set line width 0.75
2957.tic_size. = 0.1                # cm
2958set symbol size 0.03
2959.isopycnal_fontsize. = 8        # for isopycnal labels
2960.axes_fontsize. = 10            # for axes
2961set font size .axes_fontsize.
2962set x margin 2
2963set x size 10
2964set y margin 2
2965set y size 10
2966.Smin. = 33.4
2967.Smax. = 35.0
2968.Sinc. = 0.5
2969.Sincinc. = 0.1
2970.thetamin. = -2.0
2971.thetamax. = 11.0
2972.thetainc. = 1.0
2973.thetaincinc. = 1.0
2974set tic size .tic_size.
2975set x name "Salinity / PSU"
2976set y name "Potential Temperature / $\circ$C"
2977set x axis .Smin. .Smax. .Sinc. .Sincinc.
2978set y axis .thetamin. .thetamax. .thetainc. .thetaincinc.
2979set axes style offset
2980draw axes 1
2981set clip on
2982.old. = ..fontsize..
2983set font size .isopycnal_fontsize.
2984draw isopycnal 26.00
2985draw isopycnal 26.50 unlabelled
2986draw isopycnal 27.00
2987draw isopycnal 27.50 unlabelled
2988draw isopycnal 28.00
2989draw isopycnal 28.50 unlabelled
2990draw isopycnal 29.00
2991set clip off
2992set font size .old.
2993#
2994# Draw the data.
2995open example13.dat
2996read columns x y
2997draw symbol bullet
2998set font size ..
2999draw title "Example 13 -- TS diagram, with isopycnals"
3000@end example
3001@c HTML -->
3002
3003@c HTML <!-- newfile PDFDiagram.html "Gri: PDF Diagram" "Examples" -->
3004
3005
3006@node   PDF Diagram,  Running Means, TS Diagram, Examples
3007@comment  node-name,  next,  previous,  up
3008@section Probability Density Function Diagram
3009@cindex probability density function diagram
3010@cindex perl, use to create probability density function
3011A common application is to draw the probability density function for
3012(x,y) data.  Gri has no builtin facility to do this, but the following
3013example shows how to create the gridded PDF data using a call to the
3014@code{perl} system command.  The gridded data thus generated are
3015contoured, creating a PDF diagram.  As the comments in the program
3016state, the first call to Perl is specific to a particular dataset, and
3017can be ignored on first reading; it just creates the file
3018@file{tmp-xy.\.pid.}.
3019
3020@example
3021# Draw prob-density-function TS diagram for Bravo data
3022
3023# This first call to perl is specific to the
3024# particular (weird) dataset.  All that matters
3025# is that a file of (x,y) data is created, and
3026# stored in the file called `tmp-xy.\.pid.'
3027system perl <<"EOF"
3028#
3029# Slurp in x[], y[] data
3030$dir = "/users/dek/kelley/Labrador/bravo/data";
3031$Sfile = "$dir/S_25db_1day";
3032$Tfile = "$dir/T_25db_1day";
3033open(S, "$Sfile") || die "Can't open input $Sfile";
3034open(T, "$Tfile") || die "Can't open input $Tfile";
3035open(ST, ">tmp-xy.\.pid.")
3036    || die "Can't open tmp-xy.\.pid.";
3037$day = 5;
3038$year = 1964;
3039while(<S>) @{
3040    @@S = split;
3041    $_ = <T>;
3042    @@T = split;
3043    if (240 < $day && $day < 360) @{
3044        for ($i = 0; $i < $#S; $i++) @{ #all depths
3045            print ST "$S[$i] $T[$i]\n";
3046        @}
3047    @}
3048    $day += 1;
3049    if ($day > 365) @{
3050        $year++;
3051        $day = 0;
3052    @}
3053    if ($year > 1967) @{ last; @}
3054@}
3055EOF
3056
3057#
3058# Create 2D PDF for (x,y) data in file \infile
3059# storing the results in \outfile.  X ranges
3060# between the indicated limits, with the indicated
3061# binsize, as does y.  The synonyms defined
3062# on the next 4 lines are the only input this
3063# perlscript needs; the perlscript itself is
3064# quite general.  For details of what it does,
3065# particularly the scaling of the PDF, see
3066# the perl comments.
3067\xmin = "33.5"; \xmax = "35.5"; \xinc = "0.05";
3068\ymin = "-2.0"; \ymax = "11.0"; \yinc = "0.25";
3069\infile = "tmp-xy.\.pid."
3070\outfile = "tmp-grid.\.pid."
3071system perl <<"EOF"
3072#
3073# Prepare 2 dimensional probability-density-function
3074# dataset for contouring by Gri.  This reads (x,y)
3075# data from a file called $infile (defined below)
3076# and creates an output file called $outfile
3077# (also defined below) containing the
3078# x-grid, the y-grid, and then the grid data,
3079# suitable for reading/contouring by the Gri
3080# commands
3081#       open tmp-grid.\.pid.
3082#       read .number_of_data.
3083#       read grid x
3084#       read grid y
3085#       read grid data
3086#       draw contour
3087#
3088# The values in the output grid are defined so
3089# that they sum to the reciprocal of the
3090# product of the x binsize and y binsize (see
3091# definition of $factor below).
3092#
3093$xmin = \xmin; $xmax = \xmax; $xinc = \xinc;
3094$ymin = \ymin; $ymax = \ymax; $yinc = \yinc;
3095$infile = "\infile";
3096$outfile = "\outfile";
3097#
3098# Slurp in the x[], y[] data, storing
3099# the total number of data in $n.
3100open(IN,  "$infile")   || die "Can't open infile";
3101open(OUT, ">$outfile") || die "Can't open outfile";
3102$n = 0;
3103while(<IN>) @{
3104    ($x[$n], $y[$n]) = split;
3105    $n++;
3106@}
3107#
3108# Zero out matrix (stored in a linear array scanned
3109# as one reads a book).
3110$cols = int(1 + ($xmax - $xmin) / $xinc);
3111$rows = int(1 + ($ymax - $ymin) / $yinc);
3112for ($y = $ymax; $y > $ymin; $y -= $yinc) @{
3113    for ($x = $xmin; $x < $xmax; $x += $xinc) @{
3114        $l = int(($x - $xmin) / $xinc
3115            + $cols * int(($y - $ymin) / $yinc));
3116        $sum[$l] = 0;
3117    @}
3118@}
3119#
3120# Cumulate (x,y) data into the matrix
3121$inside = 0;
3122for ($i = 0; $i < $n; $i++) @{
3123    if ($ymin <= $y[$i] && $y[$i] <= $ymax
3124        && $xmin <= $x[$i] && $x[$i] <= $xmax) @{
3125        $l = int(($x[$i] - $xmin) / $xinc
3126            + $cols * int(($y[$i] - $ymin) / $yinc));
3127        $sum[$l]++;
3128        $inside++;
3129    @} else @{
3130        print STDERR "($y[$i], $x[$i]) clipped\n";
3131    @}
3132@}
3133#
3134# Print number of points (to allow renormalization
3135# if the user wishes)
3136print OUT "$inside\n";
3137#
3138# Print x grid, y grid, then grid itself
3139for ($x = $xmin; $x < $xmax; $x += $xinc) @{
3140    printf OUT "%lg\n", $x;
3141@}
3142print OUT "\n";
3143for ($y = $ymax; $y > $ymin; $y -= $yinc) @{
3144    printf OUT "%lg\n", $y;
3145@}
3146print OUT "\n";
3147#
3148# The $factor variable scales the PDF.
3149$factor = 1 / $xinc / $yinc / $inside;
3150for ($y = $ymax; $y > $ymin; $y -= $yinc) @{
3151    for ($x = $xmin; $x < $xmax; $x += $xinc) @{
3152        $l = int(($x - $xmin) / $xinc
3153            + $cols * int(($y - $ymin) / $yinc));
3154        printf OUT "%lg ", $factor * $sum[$l];
3155    @}
3156    print OUT "\n";
3157@}
3158EOF
3159
3160# Axes
3161set x margin 3
3162set x margin 6
3163set x name "Salinity [PSU]"
3164set y name "Potential Temperature [$\circ$C]"
3165set x axis 34.5 34.8 0.1
3166set y axis 5 9 1
3167draw axes
3168
3169# PDF
3170open tmp-grid.\.pid.
3171read .number_of_data.
3172read grid x
3173read grid y
3174read grid data
3175.smooth. = 0
3176
3177# Contours.  Use clipping, since the axes are
3178# zooming in on part of the PDF.
3179set font size 8
3180set contour label position centered
3181set clip postscript on
3182set line width rapidograph 4x0
3183draw contour 0.2 2.2 0.4 unlabelled
3184set line width rapidograph 0
3185draw contour 0.4 2.4 0.4
3186set clip postscript off
3187end if
3188@end example
3189
3190
3191@c HTML <!-- newfile RunningMeans.html "Gri: running means" "Examples" -->
3192
3193
3194@node   Running Means, Finite Element Model Mesh, PDF Diagram, Examples
3195@comment  node-name,  next,  previous,  up
3196@section Running-Mean Skyline Diagram
3197@cindex  Running-Mean Skyline Diagram
3198Timeseries data are often cast into running means; e.g. a temperature
3199record might be cast into monthly mean values.  The following example
3200shows how to use a perl script to accomplish this easily, producing a
3201graph with both the raw data (bullets) and the running mean (a skyline
3202plot).
3203
3204@example
3205`Bin with  x .min. .max. .inc. \in_file \out_file'
3206
3207Creates \out_file from \in_file.  In each of these
3208files, column 1 represents x and column 2 represents
3209y.  The \out_file file contains the average values
3210of y in x bands of width .inc., centred at .min.,
3211(.min.+.inc.), up to .max, and with missing values
3212inserted in bands with no x-data in \in_file.
3213Each x-band is represented in \out_file by a
3214plateau in y, and adjacent bands with
3215non-missing data are connnected by vertical
3216lines; the effect is a skyline plot of the
3217banded means.  Sample application: plot
3218monthly means of a variable.
3219@{
3220    if @{rpn \.words. 8 !=@}
3221        show "ERROR: `\.proper_usage.' called without"
3222        show " giving all parameters"
3223        quit 1
3224    end if
3225    system perl <<"EOF"
3226    $min = \.word3.;
3227    $max = \.word4.;
3228    $inc = \.word5.;
3229    open(IN,   "\.word6.")
3230        || die "`\.proper_usage': no \\in_file";
3231    open(OUT, ">\.word7.")
3232        || die "`\.proper_usage': no \\out_file";
3233
3234    $n = ($max - $min) / $inc;
3235    #
3236    # Set up bins.
3237    for($i = 0; $i <= $n; $i++) @{
3238       $xx[$i] = 0;
3239       $yy[$i] = 0;
3240       $nn[$i] = 0;
3241    @}
3242    while(<IN>) @{
3243        ($x, $y) = split(' ');
3244        $i = int(0.5 + ($x - $min) / $inc);
3245        $i =      0 if $i <      0;
3246        $i = $n - 1 if $i > $n - 1;
3247        $xx[$i] += $x;
3248        $yy[$i] += $y;
3249        $nn[$i]++;
3250    @}
3251    for($i = 0; $i <= $n; $i++) @{
3252        if ($nn[$i] > 0) @{
3253            $xx[$i] /= $nn[$i];
3254            $yy[$i] /= $nn[$i];
3255            $xleft  = $min + $inc * ($i - 0.5);
3256            $xright = $min + $inc * ($i + 0.5);
3257            #
3258            # If datum to left non-missing,
3259            # just draw vertical line
3260            # down to the last yy value.
3261            if ($i > 0 && $nn[$i - 1] > 0) @{
3262                print OUT "$xleft $yy[$i - 1]\n";
3263            @} else @{
3264                print OUT "$xleft \.missingvalue.\n"
3265            @}
3266            print OUT "$xleft  $yy[$i]\n";
3267            print OUT "$xright $yy[$i]\n";
3268        @}
3269    @}
3270EOF
3271@}
3272
3273# Bin into months
3274Bin with x 1964 1974 @{rpn 1 12 /@} \
3275    timeseries.dat tmp.dat
3276open tmp.dat
3277read columns x y
3278close
3279draw curve                      # skyline of means
3280open timeseries.dat
3281read columns x y
3282close
3283draw symbol bullet              # data
3284system rm -f tmp.dat            # clean up
3285@end example
3286
3287
3288@c HTML <!-- newfile FEM.html "Gri: Finite Element Model mesh" "Examples" -->
3289
3290
3291@node   Finite Element Model Mesh, Handling Data, Running Means, Examples
3292@comment  node-name,  next,  previous,  up
3293@section Finite Element Model mesh
3294@cindex  Finite Element Model mesh
3295@cindex FEM mesh plot
3296@cindex mesh plot for FEM
3297
3298Finite Element Models (used in fluid mechanics) employ non-rectangular
3299meshes, and plotting these meshes requires a few intermediate steps.
3300Consider the common case of triangular elements.  Suppose two data files
3301exist describing the mesh, the first, @file{model.nodes} say, consists
3302of a description of the x-y coordinates of the nodes (vertices) of the
3303triangles.  The second, @file{model.elements} say, consists of a
3304description of which triplet of nodes defines each triangle in the mesh.
3305Here, from a sample application, is a node file called
3306@file{model.nodes}:
3307
3308@example
33091	1	1
33102	2	1
33113	1	2
33124	3	1.5
33135	2	2
33146	1.5	3
3315@end example
3316@noindent
3317Here is the corresponding file of the elements, called @file{model.elements}
3318
3319@example
33201	1	2	3
33212	2	5	3
33223	2	4	5
33234	3	5	6
3324@end example
3325
3326@noindent
3327In each of these files, the first column is a reference number.  Thus,
3328@file{model.elements} indicates that the first triangle is defined by
3329the nodes numbered @code{1}, @code{2} and @code{3} as defined in
3330@file{model.nodes}.  More specifically, the triangle is defined by
3331vertices at (x,y) locations (1,1), (2,1), and (1,2).
3332
3333A Gri program, named @file{FEM.gri}, to draw the nodes is the following.
3334
3335@example
3336set missing value -99.99
3337# Create data using perl-script ...
3338system FEM.pl model.nodes model.elements > tmp
3339# ... then plot it ...
3340open tmp
3341read columns x y
3342close
3343draw curve
3344# ... and, finally, clean up the temporary file
3345system rm tmp
3346@end example
3347
3348@noindent
3349The work of interpreting the data files is done by the perlscript that
3350follows, named @file{FEM.pl}
3351
3352@example
3353#!/usr/bin/perl -w
3354$missing = -99.99;              # missing value
3355$node_file = $ARGV[0];
3356$element_file = $ARGV[1];
3357open (NODE, $node_file)
3358    or die "Cannot open '$node_file' file";
3359open (ELEM, $element_file)
3360    or die "Cannot open '$element_file' file";
3361
3362# Read in node information, creating arrays
3363# named $node_x[] and $node_y[]. Check that
3364# the first column (the index) makes sense.
3365$max_node = 1;
3366while(<NODE>) @{
3367    ($index, $node_x[$max_node], $node_y[$max_node])
3368        = split;
3369    die "Node mismatch at index=$index"
3370        if ($index != $max_node);
3371    $max_node++;
3372@}
3373
3374# Read in triangle elements, into arrays
3375# $a[], $b[], and $c[].  Check that the
3376# first column (the index) makes sense.
3377$max_elem = 1;
3378while(<ELEM>) @{
3379    ($index, $a[$max_elem], $b[$max_elem], $c[$max_elem])
3380        = split;
3381    die "Element mismatch at index=$index"
3382        if ($index != $max_elem);
3383    $max_elem++;
3384@}
3385
3386# Print out triangles suitable for plotting in gri.
3387for ($i = 1; $i < $max_elem; $i++) @{
3388    print $node_x[$a[$i]], " ", $node_y[$a[$i]], "\n";
3389    print $node_x[$b[$i]], " ", $node_y[$b[$i]], "\n";
3390    print $node_x[$c[$i]], " ", $node_y[$c[$i]], "\n";
3391    # Repeat first, to close the triangle.
3392    print $node_x[$a[$i]], " ", $node_y[$a[$i]], "\n";
3393    print $missing, " ", $missing, "\n";
3394@}
3395@end example
3396
3397@c HTML The resultant image is below.
3398@c HTML <IMG ALT="FEM image" SRC="FEM.png">
3399
3400
3401
3402
3403@c HTML <!-- newfile HandlingData.html "Gri: handling data" "Examples" -->
3404
3405@node   Handling Data, Handling Headers, Finite Element Model Mesh, Examples
3406@comment node-name,  next,  previous,  up
3407@section Handling Data
3408@cindex data, dealing with odd datasets
3409
3410@menu
3411* Handling Headers::            How to skip or read header lines
3412* Ignoring Columns::            Ignoring columns that are not of interest
3413* Column Algebra::              How to do algebra on columns
3414* Combining Columns::           Combining columns from separate files
3415* Plotting Several Columns::    Plotting several y-columns vs one x-column
3416@end menu
3417
3418
3419@c HTML <!-- newfile HandlingHeaders.html "Gri: handling headers" "Examples" -->
3420
3421@node   Handling Headers, Ignoring Columns, Handling Data, Handling Data
3422@comment  node-name,  next,  previous,  up
3423
3424@subsection Handling headers
3425
3426@cindex skipping header lines
3427@cindex header lines, skipping
3428@b{Case 1 -- known number of header lines.}
3429This is easy.  If you know that the file has, say, 10 header lines, you
3430can just do this:
3431
3432@example
3433open file
3434skip 10
3435read columns x y
3436...
3437@end example
3438
3439@b{Case 2 -- header itself indicates number of header lines.}
3440Quite often the first line of a file will indicate the number of header
3441lines.  For example, suppose the first line contains a single number,
3442indicating the number of header lines to follow:
3443
3444@example
3445open file
3446read .skip.
3447skip .skip.
3448read columns x y
3449...
3450@end example
3451
3452@b{Case 3 -- header lines marked by a textual key.}
3453Sometimes header lines are indicated by a textual key, for example, the
3454characters @code{HEADER} at the start of the line in the file.  The easy
3455way to skip such a header is to use a system command.  Depending on your
3456familiarity with the operating system (here presumed to be Unix), you
3457might choose to use Grep, Awk, or Perl.  Here are examples:
3458
3459@example
3460open "grep -v '^HEADER' file |"
3461@end example
3462
3463For more on the @code{|} mechanism, see @ref{Open}.  The Grep command
3464prints lines which do not match the indicated string
3465(because of the @code{-v} switch), and the @code{^} character stands for
3466the start of the line (@ref{Grep}).  Thus all lines with the key word at the
3467@strong{start} of the line are skiped.
3468
3469@cindex reading information from header lines
3470@cindex header lines, reading information from
3471@b{Case 4 -- reading and using information in header.}
3472Consider a dataset in which the first line gives the time of
3473observation, followed by a list of observations.  This might be, for
3474example, an indication of the data taken from a weather balloon released
3475at a particular time from a fixed location, with the main data being air
3476temperature as a function of elevation of the balloon.  The time
3477indication might be, for instance, the hour number.  One might need to
3478know the time to print a label on the diagram.  You could do that by:
3479
3480@example
3481open file
3482read .time.
3483read columns x y
3484draw curve
3485sprintf \label "Time of observation is %f hour" .time.
3486draw title "\label"
3487@end example
3488
3489@noindent
3490where the @code{sprintf} command has been used to change the numerical
3491time indication into a synonym that can be inserted into a quoted string
3492for drawing the title of the diagram (@ref{Sprintf}).  Here the time has
3493been assumed to be a decimal hour.  You might also have three numbers on
3494the line, perhaps a day, an hour and a minute.  Then you could do
3495something like
3496
3497@example
3498open file
3499read .d. .h. .m.
3500read columns x y
3501draw curve
3502sprintf \label "Obs. %.0f:%.0f, day %.0f" .h. .m. .d.
3503draw title "\label"
3504@end example
3505
3506@noindent
3507Here the @code{%.0f} code is used to ensure no numbers will be written
3508after the decimal point.  Naturally, you could convert this to a decimal
3509day, by e.g.
3510
3511@example
3512...
3513.dday. = @{rpn .day. .hour. 24 / .min. 24 / 60 /@}
3514sprintf \label "Decimal day is %.4f" .dday.
3515...
3516@end example
3517
3518@noindent
3519(Some of you might know how many minutes in a day, but I'm silly so I
3520kept the extra mathematical step -- nothing is lost by being
3521straightforward!)
3522
3523@c HTML <!-- newfile IgnoringColumns.html "Gri: ignoring columns" "Examples" -->
3524
3525@node   Ignoring Columns, Column Algebra, Handling Headers, Handling Data
3526@comment  node-name,  next,  previous,  up
3527@subsection Ignoring columns that are not of interest
3528Quite often a dataset will have many columns, of which only a couple are
3529of interest to you.  Consider for example oceanographic data which
3530has columns storing, in order, these variables: (1) depth in water
3531column, (2) "in situ" temperature, (3) "potential" temperature, (4)
3532salinity, (5) conductivity, (6) density, (7) sigma-theta, (8) sound
3533speed, and (9) oxygen concentration.  But you might only be interested
3534in plotting a graph of salinity on the x-axis and depth on the y-axis.
3535Here are several ways to do this:
3536
3537@example
3538open file
3539read columns y * * x
3540draw curve
3541@end example
3542
3543@noindent
3544where the @code{*} is a place-keeper to indicate to skip that column.
3545For a large number of columns, or as an aesthetic choice, you might
3546prefer to write this a
3547
3548@example
3549open file
3550read columns y=1 x=4
3551draw curve
3552@end example
3553
3554Many users would just as soon not bother with this syntax, preferring
3555instead to use system tools with which they are more familiar.  So a
3556Gawk user might write
3557
3558@example
3559open "gawk '@{print($1, $4)@}' file |"
3560read columns y x
3561draw curve
3562@end example
3563
3564@noindent
3565For more on the Gawk command see @ref{Awk}.
3566
3567
3568@c HTML <!-- newfile ColumnAlgebra.html "Gri: column algebra" "Examples" -->
3569
3570@node   Column Algebra, Combining Columns, Ignoring Columns, Handling Data
3571@comment  node-name,  next,  previous,  up
3572@subsection Algebra on column data
3573Suppose the file contains (x,y), but you wish to plot 2y times x.  You
3574could do the doubling of y within Gri, as
3575
3576@example
3577open file
3578read columns x y
3579y *= 2
3580draw curve
3581@end example
3582
3583@noindent
3584or you could use a system tool, e.g. gawk, as in this example (@ref{Awk}).
3585
3586@example
3587open "gawk '@{print($1,2*$2)@}' file|"
3588read columns x y
3589draw curve
3590@end example
3591
3592The latter is preferable in the sense that it is more powerful.  The
3593reason for this is that Gri allows you to manipulate the x and y
3594columns, using so-called RPN mathematics (@ref{rpn Mathematics}), but
3595you cannot blend the columns.  For example, you cannot easily form the
3596ratio y/x in Gri.  (Actually, you can, by looping through your data and
3597doing the calculation index by index, but if you knew that already you
3598wouldn't need to be reading this section!)  Such blending is trivial in
3599the operating system, though, as in the following Gawk example (@ref{Awk}).
3600
3601@example
3602open "gawk 'print @{($1, $2/$1)@}' file |"
3603read columns x y
3604draw curve
3605@end example
3606
3607@c HTML <!-- newfile CombiningColumns.html "Gri: combining columns" "Examples" -->
3608
3609@node   Combining Columns, Plotting Several Columns, Column Algebra, Handling Data
3610@comment  node-name,  next,  previous,  up
3611@subsection Combining columns from different files
3612Suppose you want to plot a column (@code{y}, say) from one file versus a
3613second column (@code{x}) from a second data file.  The easy way is to
3614use a system command to create a new file, for example the Unix command
3615@code{paste} -- but of course you don't want to clutter your filesystem
3616with such files, so you should do this withing Gri:
3617
3618@example
3619open "paste file1 file2 |"
3620read columns x y
3621draw curve
3622@end example
3623
3624
3625@c HTML <!-- newfile PlottingSeveralColumns.html "Gri: plotting several columns" "Examples" -->
3626
3627@node   Plotting Several Columns, Commands, Combining Columns, Handling Data
3628@comment  node-name,  next,  previous,  up
3629@subsection Plotting several y-columns versus on x-column
3630Sometimes you'll have a datafile with the first column being x, and the
3631other columns being various things to plot versus x.  For example, you
3632might have the data
3633
3634@example
36351  8 11  9
36362 22 21 20
36373 11 10  9
36384 20 15 10
3639@end example
3640
3641@noindent
3642in a file called @code{test.dat}.  Let's say the x-column is time, and
3643the y-columns are the readings from three temperature sensors.  The
3644following illustrates how you might plot these data.  If you think the
3645new-command which starts this script is useful, just insert it in your
3646@file{~/.grirc} file and you can just use it without re-defining it each
3647time.  This will give Gri a command called @code{draw curves}.
3648
3649@example
3650`draw curves \xname \y1name ...'
3651Draw multiple y columns versus an x column.  Assumes
3652that the datafile is open, and that x is in the first
3653column, with the y values in one or more following
3654columns.
3655
3656The number of columns is figured out from the options,
3657as is the name of the x-axis, and the labels to be
3658used on each of the y curves.
3659@{
3660  # NB. the 3 below lets us skip the words 'draw'
3661  # and 'curves', and the name of the x-column.
3662  .num_of_y_columns. = @{rpn wordc 3 -@}
3663  if @{rpn .num_of_y_columns. 1 >@}
3664    show "ERROR: `draw curves' needs at least 1 y column!"
3665    quit
3666  end if
3667
3668  set x name @{rpn 2 wordv@}
3669  set y name ""
3670
3671  # Loop through the columns.
3672  .col. = 0
3673  while @{rpn .num_of_y_columns. .col. <@}
3674    # The x-values will be in column 1, with y-values
3675    # in columns 2, 3, ..., of the file.
3676    .ycol. = @{rpn .col. 2 +@}
3677    rewind
3678    read columns x=1 y=.ycol.
3679    # At this point, you may want to change line thickness,
3680    # thickness, color, dash-type, etc.  For illustration,
3681    # let's set dash type to the column number.
3682    set dash .col.
3683    draw curve
3684    draw label for last curve @{rpn .col. 3 + wordv@}
3685    .col. += 1
3686  end while
3687@}
3688
3689open test.dat
3690draw curves time y1 y2 y3
3691@end example
3692
3693
3694@c HTML <!-- newfile Commands.html "Gri: complete list of commands" "Gri Commands" -->
3695
3696@node   Commands, Overview Of Gri Commands, Plotting Several Columns, Top
3697@comment  node-name,  next,  previous,  up
3698@chapter List of Commands in the Gri Language
3699@cindex programming, complete list of Gri commands
3700@cindex syntax of Gri commands
3701@cindex keywords of Gri commands
3702@menu
3703* Overview Of Gri Commands::    General classification of commands
3704* Command Syntax::              Syntax of the commands
3705* List Of Gri Commands::
3706@end menu
3707
3708@c HTML <!-- newfile CommandsOverview.html "Gri: Overview of commands" "Gri Commands" -->
3709
3710@node   Overview Of Gri Commands, Command Syntax, Commands, Commands
3711@comment  node-name,  next,  previous,  up
3712@section Overview of Gri Commands
3713@cindex types of gri commands
3714@cindex overview of gri commands
3715@cindex gri commands, categories of
3716
3717The Gri commands may be divided roughly into a few categories, as indicated in the following list.
3718
3719@itemize @bullet
3720
3721@item @strong{Working with files}:
3722Commands are @code{open}, @code{close}, @code{skip}, @code{read}, and
3723@code{rewind}.
3724
3725@item @strong{Controlling parameters of the drawn material}:
3726Various @code{set} commands control values of parameters, like size of plot,
3727linewidth, font, etc.
3728
3729@item @strong{Drawing things}:
3730Various @code{draw} commands let you draw data, axes, etc.
3731
3732@item @strong{Interacting with the user}:
3733The @code{query} command gets instructions from the user.  The
3734@code{show} command displays messages to user.
3735
3736@item @strong{Controlling program flow}:
3737The @code{if} statement controls optional execution of commands
3738(@ref{If Statements}).  The @code{while} statement allows loops.
3739
3740@item @strong{Moving around in directories}:
3741The @code{pwd}, @code{cd} and @code{ls} commands do the usual unix
3742things.
3743
3744@item @strong{Using the operating system}
3745The @code{system} command passes instructions to the operating system;
3746the output may be saved into a synonym by using
3747@code{\syn = system ...}.  The @code{get env} command determines the value of any
3748unix environment variables the system has defined.  For more discussion
3749(@ref{Operating System}).
3750
3751@item @strong{Statistical operations}:
3752Some very limited capabilities exist; for example, @code{regress} does
3753linear regression.
3754
3755@item @strong{Mathematical operations}:
3756Simple mathematical manipulation of column, grid, and image data is
3757provided.  Also, wherever Gri expects a number, it will accept a
3758reverse-polish expression; for example, @code{set x size 10} could also
3759be written @code{set x size @{rpn 20 2 /@}}.  For details
3760(@ref{Mathematics}).
3761@end itemize
3762
3763
3764@c HTML <!-- newfile CommandSyntax.html "Gri: Command Syntax" "Gri Commands" -->
3765@node   Command Syntax, List Of Gri Commands, Overview Of Gri Commands, Commands
3766@comment  node-name,  next,  previous,  up
3767@section Command syntax
3768The syntax description is enclosed within angled single quotes, optional
3769items are enclosed in square brackets, multiword items are enclosed in
3770curly braces, and vertical bars separate different legitimate choices.
3771For example, the documentation item for the command for drawing contours
3772
3773@example
3774`draw contour \
3775    [.value. |  \
3776      @{.min. .max. .inc. [.inc_unlabelled.]@}] \
3777    [unlabelled]'
3778@end example
3779
3780@noindent
3781indicates that following are legal:
3782
3783@example
3784draw contour                   # gri selects levels
3785draw contour unlabelled        # " but unlabelled
3786draw contour 10                # single contour line
3787draw contour 10 unlabelled     # " but unlabelled
3788draw contour 0 100 10          # contours at z=0,1,
3789draw contour 0 10 1 unlabelled # " but unlabelled
3790# contours at 0, 0.1, ... labelled at 0, 1
3791draw contour 0 10 1 0.1
3792@end example
3793
3794@noindent
3795Note that items enclosed in braces must appear in their entirety; for
3796example,
3797
3798@example
3799draw contour 0 10              # WRONG; missing .inc.
3800@end example
3801
3802@noindent
3803which might look similar @code{draw contour .min. .max. .inc.} to you,
3804looks like garbage to Gri.  Gri will recognize it as an attempt at the
3805@code{draw contour} command (because the first 2 words match the syntax)
3806but it will then get confused, spit out an error message, and quit.
3807
3808
3809
3810@c HTML <!-- newfile ListOfGriCommands.html "Gri: List of commands" "Gri: Commands" -->
3811@node   List Of Gri Commands, Assert, Command Syntax, Commands
3812@comment  node-name,  next,  previous,  up
3813@section List of all Gri commands
3814
3815Commands are listed below in the order in which they are defined in the
3816@file{gri.cmd} file (@ref{Invoking Gri}).  What you see here
3817is similar to, but not identical to, the text of the online help.  Gri
3818usually accepts both American and English spellings
3819(As an example of spelling latitude, Gri accepts @code{grey} anywhere the
3820manual says @code{gray}, and @code{colour} for @code{color}.)
3821
3822@cindex gri commands, complete list of
3823@cindex commands, complete list of
3824@cindex spelling of gri commands
3825@cindex gray vs Grey spelling
3826@cindex grey vs Gray spelling
3827@cindex colour vs Color spelling
3828
3829
3830
3831@menu
3832* Assert::                      Assert something to be true (for debugging)
3833* Cd::                          Change directory
3834* Close::                       Close a file
3835* Convert::                     Convert various data types
3836* Create::                      Create columns from specified function
3837* Debug::                       Set to debugging mode
3838* Delete::                      Delete various data structures
3839* Differentiate::               Differentiate things
3840* Draw::                        Draw various things
3841* End Group::                   End a group
3842* Expecting::                   Make Gri warn of incompatibilites
3843* Filter::                      Filter (smooth) various data structures
3844* Flip::                        Flip or transpose grid or image
3845* Get Env::                     Get a unix environment variable
3846* Group::                       Start a group of drawn objects
3847* Heal::                        Interpolate across missing values
3848* Help::                        Give on-line help
3849* If::                          If and if/else statements
3850* Ignore::                      Ignore some of data recently read in
3851* Input::                       Input PostScript file into output file
3852* Insert::                      Run another command file
3853* Interpolate::                 Interpolate grid data to new x/y grid
3854* List::                        List source of a gri command
3855* Ls::                          List files in current directory
3856* Mask::                        Mask the image
3857* New::                         Get space for new variable or synonym
3858* Newpage::                     Start a new page
3859* New Postscript File::         Start a new PostScript file
3860* Open::                        Open a data file
3861* Postscript::                  Insert a line into the PostScript file
3862* Pwd::                         Print working directory
3863* Query::                       Get user input
3864* Quit::                        Exit from gri
3865* Read::                        Read something
3866* Regress::                     Do linear regressions on columnar data
3867* Reorder::                     Reorder columns
3868* Rescale::                     Re-determine scales for x/y axes
3869* Resize::                      Resize plot width/height for maps
3870* Return::                      Return early from command or insert file
3871* Rewind::                      Rewind data file to beginning
3872* Rpnfunction::                 Define an rpn function
3873* Set::                         Set various preference flags, etc
3874* Show::                        Show values of various things
3875* Skip::                        Skip some lines in data file
3876* Sleep::                       Sleep for a while
3877* Smooth::                      Smooth data
3878* Source::                      Run another command file
3879* Sprintf::                     Print variable values into a synonym
3880* State::                       Save or restore the graphics state
3881* Superuser::                   Enable some programmers debugging commands
3882* System::                      Performing system commands within gri
3883* Unlink::                      Delete file
3884* While::                       Loop over some code while a condition is true
3885* Write::                       Write data to a file
3886@end menu
3887
3888
3889
3890
3891@c HTML <!-- newfile Assert.html "Gri: `assert' command" "Gri Commands" -->
3892
3893@node   Assert, Cd, List Of Gri Commands, List Of Gri Commands
3894@comment  node-name,  next,  previous,  up
3895@subsection @code{assert}
3896@cindex debugging, with @code{assert} command
3897@cindex @code{assert} command, for debugging
3898@findex assert
3899
3900@example
3901`assert .condition. ["message"]
3902@end example
3903
3904@noindent
3905The condition may be a variable, a synonym, or an RPN expression.  If
3906this condition is true (i.e. evaluates to a non-zero number), do
3907nothing.  If the condition is false, the program will terminate with an
3908error condition (in unix, it will terminate with a non-zero exit code).
3909
3910Before termination, a message will be printed, the form of which depends
3911on the optional @code{"message"} string.
3912
3913If no @code{"message"} string is given, the the printed message will
3914indicate the name of the command-file and the line at which the assert
3915command was encountered.
3916
3917If a @code{"message"} string is given, and if it ends in a newline
3918(@code{"\\n"}), then this string is printed.
3919
3920If a @code{"message"} string is given, and if it does not end in
3921@code{"\\n"}, then the string is printed along with an indication of the
3922location in the command-file.
3923
3924(Perl users will recognize this as being patterned on the @code{"die"}
3925command.)
3926
3927
3928
3929@c HTML <!-- newfile Cd.html "Gri: `cd' command" "Gri Commands" -->
3930
3931@node   Cd, Close, Assert, List Of Gri Commands
3932@comment  node-name,  next,  previous,  up
3933@subsection @code{cd}
3934@cindex changing directories
3935@cindex directories, changing
3936@cindex @code{cd} command
3937@findex cd
3938
3939@example
3940`cd [\pathname]'
3941@end example
3942
3943@noindent
3944If a pathname specified, change to that directory.  Normal unix
3945filenames are used, as in the C-shell convention.  For example, the
3946commands @code{cd ~/src} and @code{cd $HOME/src} are equivalent.  You may
3947specify relative pathnames as in @code{cd ../sister_directory}.
3948
3949If no \pathname directory path is specified, go to the home directory,
3950exactly as @code{cd ~} and @code{cd $HOME} do.
3951
3952
3953@c HTML <!-- newfile Close.html "Gri: `close' command" "Gri Commands" -->
3954
3955@node   Close, Convert, Cd, List Of Gri Commands
3956@comment  node-name,  next,  previous,  up
3957@subsection  @code{close}
3958@cindex files, closing
3959@cindex closing files
3960@findex close
3961@cindex @code{close} command
3962
3963@example
3964`close [\filename]'
3965@end example
3966
3967@noindent
3968If no filename is specified, close the most recently opened data-file;
3969otherwise close the indicated file.
3970
3971
3972@c HTML <!-- newfile Convert.html "Gri: `convert' command" "Gri Commands" -->
3973
3974@node   Convert, Convert Columns To Grid, Close, List Of Gri Commands
3975@comment  node-name,  next,  previous,  up
3976@subsection The @code{convert} commands
3977
3978@menu
3979* Convert Columns To Grid::      Create grid from (x,y,f) data
3980* Convert Columns To Spline::    Create spline (x',y') from (x,y) data
3981* Convert Grid To Columns::      Create (x,y,f) data from grid
3982* Convert Grid To Image::        Create an image from grid data
3983* Convert Image To Grid::        Create a grid from image data
3984@end menu
3985
3986
3987@node   Convert Columns To Grid, Convert Columns To Spline, Convert, Convert
3988@comment  node-name,  next,  previous,  up
3989@subsubsection @code{convert columns to grid}
3990@findex convert columns to grid
3991@cindex @code{convert columns to grid} command
3992Various forms exist:
3993
3994@example
3995`convert columns to grid OPTIONS'
3996@end example
3997
3998@noindent
3999where the @code{OPTIONS} may be omitted or
4000selected from this list:
4001
4002@example
4003`neighbor'
4004`boxcar    [.xr. .yr. [.n. .e.]]'
4005`objective [.xr. .yr. [.n. .e.]]'
4006`barnes    [.xr. .yr. .gamma. .iter.]'
4007@end example
4008
4009@noindent
4010For more discussion on the methods see @ref{Ungridded Data}.
4011
4012All these commands ``grid'' columnar (x,y,z) data.  That is, they fill
4013up a grid based on some form of interpolation of the possibly randomly-spaced
4014columnar data.  There are many methods in existence for doing
4015this, and Gri implements several of them as alternatives.
4016
4017The grid will have been defined by commands such as @code{set x grid},
4018@code{set y grid}, @code{read grid x} and @code{read grid y}.  As of
4019version 2.1.9, Gri does not require a grid to have been pre-defined; it
4020will create a regular 20 by 20 grid, spanning the range of x and y data,
4021as a default.  This is a good starting point in many cases.
4022
4023@table @emph
4024
4025@item `neighbor' method
4026Very fast but very limited.
4027
4028@item `boxcar' method
4029Slower but a lot better.  Still, this can produce noisy contours if the
4030data are not densely and uniformly ditributed through domain.
4031
4032@item `objective' method
4033Somewhat slower than `boxcar', but produces better fields since the
4034averaging function is smooth.
4035
4036@item `barnes' method
4037Somewhat slower than `objective', but only by a constant factor (that
4038is, independent of number of data).  This produces by far the best
4039results, since the smoothing function has variable spatial scale.  This
4040is the default method if no method is supplied.
4041@end table
4042
4043All except the @code{neighbor} method may take optional arguments to
4044define the x and y scales of the smoothing function (called @code{.xr.}
4045and @code{.yr.}).  (The barnes method has two other optional arguments
4046-- see below.)  If you do not supply these arguments, Gri will make a
4047reasonable choice and inform you of its decision.  Many users find that
4048it is best to @code{convert columns to grid} with no additional
4049parameters as a first step, to get advice on values to use for the
4050optional parameters.
4051
4052The default @code{.xr.} and @code{.yr.} are calculated by determining
4053the span in x and in y directions, and dividing each by the square root
4054of the number of data points.  These numbers are then multiplied by the
4055square root of 2.  The method is as proposed by S. E. Koch and M.
4056DesJardins and P. J. Kocin, 1983.  ``An interactive Barnes objective map
4057anlaysis scheme for use with satellite and conventional data,'',
4058J. Climate Appl.  Met., vol 22, p. 1487-1503.
4059
4060If @code{.xr.} and @code{.yr.} were supplied but negative, then Gri
4061interprets this as an instruction to modify the default values,
4062described in last paragraph, by multiplying by the absolute values of
4063the negative numbers given, instead of muliplying by square root of 2.
4064
4065If the @code{chatty} option is turned on
4066then Gri will print out the values of
4067(dx,dy) that it has
4068calculated; this gives you some guidance for supplying your own values
4069of @code{(.xr.,.yr.)} if you choose to supply them yourself.  It is also
4070a good idea to let these parameters be a guide for your grid spacing;
4071for example, Koch et al., 1983, suggest using grid spacing of 0.3 to 0.5
4072times (dx,dy).
4073
4074And now, the details @dots{}
4075
4076@itemize @bullet
4077
4078@item @strong{``Neighbor'' method}
4079The @code{convert columns to grid neighbor} method is useful for (x,y,z)
4080data which are already gridded (i.e., for which x and y take only values
4081which lie on the grid), or nearly gridded.  The (x,y,z) data are scanned
4082from start to finish. For each data point, the nearest grid point is
4083found.  Nearness is measured as Cartesian distance, with scale factor
4084given by the distance between the first and second grid points.  In
4085other words, distance is given by D=sqrt(dx*dx+dy*dy) where dx is ratio
4086of distance from data point to nearest grid point, in x-units, divided
4087by the difference between the first two elements of the x-grid, and dy
4088is similarly defined.  Once the grid point nearest the data point is
4089determined, Gri adds the z-value to a list of possible values to store
4090in the grid.  Once the entire data set has been scanned, Gri then goes
4091back to each grid point, and chooses the z-value of the data point that
4092was nearest to the grid point -- that is, it stores the z value of the
4093(x,y,z) data triplet which has minimal D value.  Note that this scheme
4094is independent of the order of the data within the columns.
4095
4096@cindex computational cost, of @code{convert columns to grid} command
4097
4098The @code{neighbor} method is useful when the data are already
4099pre-gridded, meaning that the (x,y,z) triplets have x and y values which
4100are already aligned with the grid.  @strong{Computational cost:} For
4101@code{P} data points, @code{X} x-grid points, and @code{Y} y-grid
4102points, the method calculation cost is proportional to
4103@code{P*[log2(X)+log2(Y)]} where @code{log2} is logarithm base 2.
4104As discussed below, this is often several orders of magnitude lower than
4105the other methods of gridding.
4106
4107@item @strong{``Objective'' method}
4108In the @code{objective} method, a smoothing technique known as objective
4109mapping is applied.  It is essentially a variable-size smoothing filter
4110of approximately Gaussian shape (it is method ``two'' of Levy and Brown
4111[1986 J. Geophysical Res. vol 91, p 5153-5158]) The parameters
4112@code{.xr.} and @code{.yr.} give the width of the filter.
4113
4114With the optional additional parameters @code{.n.} and @code{.e.} are
4115specified, then grid values will be assigned the missing value if there
4116are fewer than @code{.n.} (x,y,f) data in the neighborhood of the
4117gridpoint, even after enlarging the neighborhood by widening and
4118heightening by root(2) up to @code{.e.} times.  (The enlargement is only
4119done if fewer than @code{.n.} points are found.)  If these parameters
4120are not specified in the command, then values @code{.n.}=5 and
4121@code{.e.}=1 are assumed.  The special case where @code{.e.} is negative
4122tells Gri to @strong{always} fill in each grid point, by extending the
4123neighborhood to enclose the entire dataset if necessary.
4124
4125@strong{Computational cost:} For @code{P} data points, @code{X} x-grid
4126points, and @code{Y} y-grid points, the method calculation cost is
4127proportional to @code{P*X*Y}.  Given that @code{X} and @code{Y} are
4128determined by the requirement for smoothness of contours and the size of
4129the graph, they are more or less fixed for all applications.  They are
4130often in the range of 20 or so -- on 10 cm wide graph, this yields a
4131contour footprint of 1/2 cm, which is often small enough to yield smooth
4132contours.  Therefore, the computational cost scales linearly with the
4133number of data points.  Compared to the ``neighborhood'' method, this is
4134more costly by a factor of @code{X*Y/log_2(X)/log_2(Y)} which is
4135normally in the range from 20 to 50.
4136
4137@item @strong{``Boxcar'' method}
4138In the @code{boxcar} method, the grid points are derived from simple
4139averages calculated in rectangles @code{.xr.} wide and @code{.yr.} tall,
4140centred on the gridpoints.  The @code{.n.} and @code{.e.} parameters
4141have similar meanings as in the ``objective'' method.
4142
4143@strong{Computational cost:} Roughly same as @code{objective} method
4144described above.
4145
4146@item @strong{``Barnes'' method}
4147This is the default scheme.
4148
4149The Barnes algorithm is applied.  If no parameters are specified,
4150@code{.xr.} and @code{.yr.} are determined as above, with @code{.gamma.}
4151set to 0.5, and @code{.iter.} set to 2 so that two iterations are done.
4152On successive iterations, the smoothing lengthscales @code{.xr} and
4153@code{.yr} are each reduced by multiplying by the square root of
4154@code{.gamma.}.  Smaller @code{.gamma.} values yield better resolution
4155of small-scale features on successive iterations.  Koch et al., 1983,
4156recommend using a @code{.gamma.} value in the range 0.2 to 1, with two
4157iterations.
4158
4159Provided that all the grid points are close enough to at least some
4160column data, the entire grid is filled.  But if @code{.xr.} and
4161@code{.yr.} are too small, the weighting function can fall to zero,
4162since it is exponential in the sum of the squares of the
4163x-distance/@code{.xr.} and the y-distance/@code{.yr.}; in that case
4164missing values result at those grid points.  On a 32 bit computer, the
4165weighting function will fall to zero when x-distance/@code{.xr.}  and
4166y-distance/@code{.yr.}  are less than about 15 to 20.
4167
4168If weights have been read in (@ref{Read Columns}), then these values are
4169applied in addition to the distance-based weighting.  (The normalization
4170means that weights for two data points of e.g. 1 and 2 will yield the
4171same result as if the weights had been given as 10 and 20.)
4172
4173The computational cost at each iteration scales as @code{P*X*Y)}.  This
4174is comparable to that of the ``objective'' and ``boxcar'' methods.
4175Since normally two iterations are done, ``barnes'' is about double the
4176cost of these methods.  (Note: versions prior to 2.1.8 were much slower
4177for large datasets, being proportional to @code{P*P}.)
4178
4179References: (1) Section 3.6 in Roger Daley, 1991, ``Atmospheric data
4180analysis,'' Cambridge Press, New York. (2) S. E. Koch and M. DesJardins
4181and P. J. Kocin, 1983.  ``An interactive Barnes objective map anlaysis
4182scheme for use with satellite and conventional data,'', J. Climate Appl.
4183Met., vol 22, p. 1487-1503.
4184@end itemize
4185
4186The Barnes algorithm is as follows:
4187
4188@tex
4189The gridded field is estimated iteratively.  Successive iterations
4190retain largescale features from previous iterations, while adding
4191details at smaller scales.
4192
4193The first estimate of the gridded field, here denoted $G_{ij}^{(0)}$
4194(the parenthetic superscript indicating the order of the iteration) is
4195given by a weighted sum of the input data, with $z_k$ denoting the
4196k-th $z$ value.
4197
4198$$
4199G_{ij}^{(0)}
4200=
4201{ {\sum_1^{n_k} W_{ijk}^{(0)} z_k} \over {\sum_1^{n_k} W_{ijk}^{(0)}} }
4202$$
4203
4204The weights $W_{ijk}^{(0)}$ are defined in terms of a Gaussian
4205function decaying with distance from observation point to grid point:
4206
4207$$
4208W_{ijk}^{(0)}
4209=
4210\exp \left[ - { {(x_k-X_i)^2} \over {L_x^2} }
4211            - { {(y_k-Y_j)^2} \over {L_y^2} } \right]
4212$$
4213
4214\noindent
4215Here $L_x$ and $L_y$ are lengths which define the smallest
4216$(x,y)$ scales over which the gridded field will have significant
4217variations (for details of the spectral response see Koch et al. 1983).
4218
4219Note: if the user has supplied weights then these
4220are multiplied into the normal distance-based weights; i.e. $w_i
4221W_{ijk}$ is used instead of $W_{ijk}$.
4222
4223The second iteration derives a grid $G_{ij}^{(1)}$ in terms of the first
4224grid $G_{ij}^{(0)}$ and ``analysis values'' $f_k^{(0)}$ calculated at
4225the $(x_k,y_k)$ using a formula analogous to the above.
4226(Interpolation based on the first estimate of the grid $G_{ij}^{(0)}$
4227can also be used to calculate $f_k^{(0)}$, with equivalent results for a
4228grid of sufficiently fine mesh.)  In this iteration, however, the
4229weighted average is based on the difference between the data and the
4230gridded field, so that no further adjustment of the gridded field is
4231done in regions where it is already close to through the observed
4232values.  The second estimate of the gridded field is given by
4233
4234$$
4235G_{ij}^{(1)}
4236=
4237G_{ij}^{(0)}
4238+
4239{ {\sum_1^{n_k} W_{ijk}^{(1)} (f_k - f_k^{(0)})} \over {\sum_1^{n_k} W_{ijk}^{(1)}}
4240}
4241$$
4242
4243\noindent
4244where the weights $w_{ik,1}$ are defined by analogy with
4245$W_{ik}^{(0)}$ except that $L_x$ and $L_y$ are replaced by
4246$\gamma^{1/2}L_x$ and $\gamma^{1/2}L_y$.  The nondimensional parameter
4247$\gamma$ ($0<\gamma<1$) controls the degree to which the focus is
4248improved on the second iteration.  Just as the weighting function
4249forced the gridded field to be smooth over scales smaller than $L_x$
4250and $L_y$ on the first iteration, so it forces the second estimate of
4251the gridded field to be smooth over the smaller scales
4252$\gamma^{1/2}L_x$ and $\gamma^{1/2}L_y$.
4253
4254The first iteration yields a gridded field which represents the
4255observations over scales larger than $(L_x,L_y)$, while successive
4256iterations fill in details at smaller scales, without greatly
4257modifying the larger scale field.
4258
4259In principle, the iterative process may be continued an arbitrary
4260number of times, each time reducing the scale of variation in the
4261gridded field by the factor $\gamma^{1/2}$.  Koch et al. 1983
4262suggest that there is little utility in performing more than two
4263iterations, providing an appropriate choice of the focussing parameter
4264$\gamma$ has been made.  Thus the gridding procedure defines a gridded
4265field based on three tunable parameters: $(L_x,L_y,\gamma)$.
4266@end tex
4267
4268
4269@ifinfo
4270The gridded field is estimated iteratively.  Successive iterations
4271retain largescale features from previous iterations, while adding
4272details at smaller scales.
4273
4274The first estimate of the gridded field, here denoted
4275@code{G_(ij)^0} (the superscript indicating the order of the
4276iteration) is given by a weighted sum of the input data, with
4277@code{z_k} denoting the k-th @code{z} value.
4278
4279@example
4280             sum_1^n W_(ijk)^0 z_k
4281G_(ij)^(0) = ----------------------
4282               sum_1^n W_(ijk)0
4283@end example
4284@noindent
4285where the notation @code{sum_1^n} means to sum the elements
4286for the @code{k} index ranging from 1 to @code{n}.
4287
4288The weights @code{W_(ijk)^0} are defined in terms of a Guassian
4289function decaying with distance from observation point to grid point:
4290
4291@example
4292               (   (x_k - X_i)^2       (y_k - Y_j)^2  )
4293W_(ijk)^0 = exp(-  --------------  -  --------------- )
4294               (      L_x^2                L_y^2      )
4295@end example
4296
4297@noindent
4298Here @code{L_x} and @code{L_y} are lengths which define the smallest
4299@code{(x,y)} scales over which the gridded field will have significant
4300variations (for details of the spectral response see Koch et al. 1983).
4301
4302Note: if the user has supplied weights then these
4303are applied in addition to the distance-based weights.  That is,
4304@code{w_i W_(ijk)} is used instead of @code{W_(ijk)}.
4305
4306The second iteration derives a grid @code{G_(ij)^1} in terms of the
4307first grid @code{G_(ij)^0} and ``analysis values'' @code{f_k^0}
4308calculated at the @code{(x_k,y_k)} using a formula analogous to that
4309above.  (Interpolation based on the first estimate of the grid
4310@code{G_(ij)^0} can also be used to calculate @code{f_k^0}, with
4311equivalent results for a grid of sufficiently fine mesh.)  In this
4312iteration, however, the weighted average is based on the difference
4313between the data and the gridded field, so that no further adjustment
4314of the gridded field is done in regions where it is already close to
4315through the observed values.  The second estimate of the gridded field
4316is given by
4317
4318@example
4319                       sum_1^n W_(ijk)^1 (f_k - f_k^0)
4320G_(ij)^1 = G_(ij)^0 +  -------------------------------
4321                              sum_1^n W_(ijk)^1
4322@end example
4323
4324@noindent where the weights @code{w_@{ik,1@}} are defined by analogy
4325with @code{W_@{ik@}^0} except that @code{L_x} and @code{L_y} are
4326replaced by @code{gamma^@{1/2@}L_x} and @code{gamma^@{1/2@}L_y}.  The
4327nondimensional parameter @code{gamma} (@code{0<gamma<1}) controls the
4328degree to which the focus is improved on the second iteration.  Just
4329as the weighting function forced the gridded field to be smooth over
4330scales smaller than @code{L_x} and @code{L_y} on the first iteration,
4331so it forces the second estimate of the gridded field to be smooth
4332over the smaller scales @code{gamma^@{1/2@}L_x} and
4333@code{gamma^@{1/2@}L_y}.
4334
4335The first iteration yields a gridded field which represents the
4336observations over scales larger than @code{(L_x,L_y)}, while successive
4337iterations fill in details at smaller scales, without greatly
4338modifying the larger scale field.
4339
4340In principle, the iterative process may be continued an arbitrary number
4341of times, each time reducing the scale of variation in the gridded field
4342by the factor @code{gamma^@{1/2@}}.  Koch et al. 1983 suggest that there
4343is little utility in performing more than two iterations, providing an
4344appropriate choice of the focussing parameter @code{gamma} has been made.
4345Thus the gridding procedure defines a gridded field based on three
4346tunable parameters: @code{(L_x,L_y,gamma)}.
4347@end ifinfo
4348
4349
4350
4351
4352
4353@node   Convert Columns To Spline, Convert Grid To Columns, Convert Columns To Grid, Convert
4354@comment  node-name,  next,  previous,  up
4355@subsubsection @code{convert columns to spline}
4356@cindex spline, fitting to (x,y) data
4357@findex convert columns to spline
4358@cindex @code{convert columns to spline} command
4359
4360@example
4361`convert columns to spline \
4362    [.gamma.] \
4363    [.xmin. .xmax. .xinc.]'
4364@end example
4365
4366Fit a normal or taut interpolating spline, y=y(x), through the (x,y)
4367data.  Then subsample this spline to get a new set of (x,y) data.  If
4368the spline x-values, @code{.xmin.}, etc, are not specified, the spline
4369ranges from the smallest x-value with legitimate data to the largest
4370one, with 200 steps in between.
4371
4372The parameter @code{.gamma.} determines the type of spline used.  If
4373@code{.gamma.} is not specified, or is given as zero, a standard
4374interpolating spline is used.  A knot appears at each x location, with
4375cubic polynomials spanning the space between the knots.  If
4376@code{.gamma.} lies between 0 and 6, a taut spline is used; this tends
4377to have fewer wiggles than a normal spline.  If @code{.gamma.}  lies in
4378the range 0 to 3, a taut spline is used, with the possible insertion of
4379knots between interior x pairs.  The value 2.5 is used commonly.  If
4380@code{.gamma.} lies in the range 3 to 6, extra knots are permitted in
4381the x pairs at the ends of the domain.  A value of 5.5 is used commonly.
4382
4383@strong{Reference} Chapter 16 of Carl de Boar, 1987. ``A Practical Guide
4384to Splines'' Springer-Verlag.
4385
4386@example
4387read columns x y  # function is y=x^2
43880 0
43891 1
43902 4
43913 9
43924 16
4393
4394set symbol size 0.2
4395draw symbol bullet
4396convert columns to spline
4397draw curve
4398@end example
4399
4400
4401@node   Convert Grid To Columns, Convert Grid To Image, Convert Columns To Spline, Convert
4402@comment  node-name,  next,  previous,  up
4403@subsubsection @code{convert grid to columns}
4404@findex convert grid to columns
4405@cindex columns, creating from grid
4406@cindex @code{convert grid to columns} command
4407
4408@example
4409`convert grid to columns'
4410@end example
4411
4412@noindent
4413Create column data from grid data.  Each non-missing gridpoint is
4414translated into a single (x,y,z) triplet.  If column data already exist,
4415then they are first erased.  This command is useful in changing the grid
4416configuration, perhaps from a non-uniform grid to a uniform grid.  In
4417the following example, a new grid with x=(0, 0.05, 0.1, ..., 0.1) and
4418y=(10, 11, ..., 20) is created.  The default gridding method
4419(@code{convert columns to grid}) is used here, but of course one is free
4420to adjust the method as usual.
4421
4422@example
4423# ... read/create grid
4424convert grid to columns
4425delete grid
4426set x grid  0  1 0.05
4427set y grid 10 20 1
4428convert columns to grid
4429@end example
4430
4431
4432@node   Convert Grid To Image, Convert Image To Grid, Convert Grid To Columns, Convert
4433@comment  node-name,  next,  previous,  up
4434@subsubsection @code{convert grid to image}
4435@findex convert grid to image
4436@cindex image, creating from grid
4437@cindex @code{convert grid to image} command
4438
4439@example
4440`convert grid to image [directly] [size .width. .height.] \
4441    [box .xleft. .ybottom. .xright. .ytop.]'
4442@end example
4443
4444@noindent
4445With no options specified, convert grid to a 128x128 image,
4446using an image range as previously set by @code{set image range}, and using
4447interpolation (see below).
4448
4449With the @code{directly} option, no interpolation is used; each grid
4450point is used to calculate the colour of a single image pixel.  Since
4451images are always uniform in Gri, this will only work if the grid is
4452also uniform, i.e. there must be a constant distance between columns
4453in the grid, and the same for the rows.  This method is useful for
4454fine-grained grids, especially if they contain isolated points (e.g. a
4455numerical model might have a trace of points representing a river).
4456
4457With the @code{size} options @code{.width.} and @code{.height.}
4458specified, they set the number of rectangular patches in the image.
4459Interpolation is used.
4460
4461With the @code{box} options specified, they set the bounding box for
4462the image.  If @code{box} is not given, the image spans the same
4463bounding box as the grid as set by @code{set x grid} and @code{set y
4464grid}.  Again, interpolation is used in this form.
4465
4466Normally, missing values in the grid become white in the image, but this
4467can be changed using the @code{set image missing value color to}@dots{}
4468command.
4469
4470@cindex image, interpolation from grid
4471@cindex interpolation, from grid to image
4472
4473@b{Interpolation method:} The interpolation scheme is the same used for
4474contouring.  Image points that lie outside the grid domain are
4475considered missing.  For points within the grid, the first step is to
4476locate the patch of the grid upon which the pixel lies.  Then the 4
4477neighboring grid points are examined, and one of the following cases
4478holds.
4479@enumerate
4480@item
4481If 3 or more of them are missing, the pixel is considered missing.
4482@item
4483If just one of the neighboring grid points is missing, then the image
4484pixel value is determined by bilinear interpolation on the remaining 3
4485non-missing grid points.  (This amounts to fitting a plane to three
4486measurements of height.)
4487@item
4488If all 4 of the grid points are non-missing, then the rectangle defined
4489by the grid patch is subdivided into four triangles.  The triangles are
4490defined by the two diagonal lines joining opposite corners of the
4491rectangle.  An ``image point'' is constructed at the center of the grid
4492patch, with f(x,y) value taken to be the average of the values of the
4493four neighbors.  This value is taken to be the value at the common
4494vertex of the four triangles, and then bilinear interpolation is used to
4495calculate the image pixel value.
4496@end enumerate
4497
4498@node   Convert Image To Grid, Create, Convert Grid To Image, Convert
4499@comment  node-name,  next,  previous,  up
4500@subsubsection @code{convert image to grid}
4501@findex convert image to grid
4502@cindex @code{convert image to grid} command
4503@cindex grid, creating from image
4504
4505@example
4506`convert image to grid'
4507@end example
4508
4509@noindent
4510Convert image to grid, using current graylevel/colorlevel mapping.  For
4511example, if one had a linear mapping of pixel values 0->255 into the
4512user values 10->20, as in
4513
4514@example
4515set image range 10 20
4516set image grayscale black 10 white 20
4517@end example
4518
4519@noindent
4520then the output grid will be of value 10 where the pixel value is 0,
4521etc.  If the image is in color, the grid values will represent the
4522result of mapping the colors to grayscale in the standard way (Foley and
4523VanDam, 1984). [BUG: as of 1.063, the colorscale is ignored completely,
4524and I'm not sure what happens.] The image data are interpolated onto the
4525grid using a nearest-neighbor substitution.  This command insists that
4526the image x/y grids have already been defined.
4527
4528
4529
4530
4531
4532@c HTML <!-- newfile Create.html "Gri: `create' command" "Gri Commands" -->
4533
4534@node   Create, Create Columns From Function, Convert Image To Grid, List Of Gri Commands
4535@comment  node-name,  next,  previous,  up
4536@subsection The @code{create} commands
4537@menu
4538* Create Columns From Function:: prepare to draw a function
4539* Create Image Grayscale::       prepare to draw banded image
4540@end menu
4541
4542@node   Create Columns From Function, Create Image Grayscale, Create, Create
4543@comment  node-name,  next,  previous,  up
4544@subsubsection @code{create columns from function}
4545@findex create
4546@cindex @code{create columns from function} command
4547
4548@example
4549`create columns from function'
4550@end example
4551
4552@noindent
4553Plot a function of x which is defined in synonym \function.
4554
4555@example
4556ENVIRONMENT
4557\function = function to plot.
4558\xmin     = minimum x value
4559\xmax     = maximum x value
4560\xinc     = increment in x values
4561
4562EXAMPLE
4563\function = "cos(x)"
4564\xmin     = "0"
4565\xmax     = "2 * 3.14"
4566\xinc     = "0.1"
4567create columns from function
4568draw curve
4569@end example
4570
4571@noindent
4572NOTE: This only works on machines which have the @code{awk} command
4573available at the commandline.  This means most unix machines and some
4574vax machines.
4575
4576@node   Create Image Grayscale, Debug, Create Columns From Function, Create
4577@comment  node-name,  next,  previous,  up
4578@subsubsection @code{create image grayscale}
4579@cindex image, banded
4580@findex create image grayscale
4581
4582@example
4583`create image grayscale banded .band.'
4584@end example
4585
4586@noindent
4587Make a banded grayscale with in units of .band. pixel values each.
4588Thus, pixel values 0 to (.band. - 1) on the image will map to 0, while
4589values from .band. to (2 * .band. - 1) will map to .band., etc.  For
4590example, .band. = 2 gives grayscale = (0 0 2 2 4 4 6 6 ... 252 252 254
4591254).
4592
4593@c HTML <!-- newfile Debug.html "Gri: `debug' command" "Gri Commands" -->
4594
4595@node   Debug, Delete, Create Image Grayscale, List Of Gri Commands
4596@comment  node-name,  next,  previous,  up
4597@subsection @code{debug}
4598@cindex debugging
4599@findex debug
4600@cindex @code{debug} command
4601
4602@example
4603`debug [.n.]|[clipped values in draw commands]|off'
4604@end example
4605
4606@noindent
4607With no optional parameters, sets the value of @code{..debug..} to 1.
4608(Normally, @code{..debug..} is 0.)  You may use @code{..debug..} in
4609@code{if}
4610statements, etc.  Note that @code{..debug..} is also set to 1 when gri
4611is invoked with the commandline switch @code{-d}.
4612
4613With @code{.n.} specified, @code{..debug..} is set to @code{.n.}; a
4614value of zero for @code{.n.} turns debugging off, while 1 turns it on.
4615Higher values may be used for deeper debugging, if you choose:
4616
4617@example
4618if @{rpn ..debug.. 2 <@}
4619  # Code to do if ..debug.. is greater than 2.
4620end if
4621@end example
4622
4623@noindent
4624Note that you can assign to @code{..debug..} as you can to any other
4625variable; @code{debug .n.} is equivalent to @code{..debug.. = .n.}.
4626
4627With the @code{clipped} option, Gri prints any clipped data encountered
4628during any @code{draw ...} commands, EXCEPT in the case of
4629@code{postscript} clipping, where no check is possible.  (Note that
4630@code{..debug..} is not affected.)
4631
4632All these forms of debugging are cancelled by @code{debug off}.
4633
4634
4635@c HTML <!-- newfile Delete.html "Gri: `delete' command" "Gri Commands" -->
4636
4637@node   Delete, Differentiate, Debug, List Of Gri Commands
4638@comment  node-name,  next,  previous,  up
4639@subsection @code{delete}
4640@cindex deleting variables, synonyms, scales, etc
4641@cindex grid, deleting
4642@cindex scales, deleting
4643@cindex synonyms, deleting
4644@cindex variables, deleting
4645@findex delete
4646@cindex @code{delete} command
4647
4648@example
4649`delete .variable.|\synonym [.variable.|\synonym [...]]'
4650`delete columns [where missing]'
4651`delete columns [randomly .fraction.]'
4652`delete grid'
4653`delete [x|y] scale'
4654@end example
4655
4656@noindent
4657Delete some item or characteristic.
4658
4659@itemize @bullet
4660
4661@item @code{delete .variable.}
4662Delete definition of variable @code{.variable.}, making it undefined.
4663Any number of variables or synonyms may be specified on one line.
4664
4665@item @code{delete \synonym}
4666Delete definition of synonym @code{\synonym}, making it undefined.  Any
4667number of variables or synonyms may be specified on one line.
4668
4669@item @code{delete \@@alias}
4670Delete the item named by the alias (@ref{Alias Synonyms}).
4671
4672@item @code{delete} with an @code{&} item
4673Delete the item in the calling program.
4674
4675@item @code{delete columns}
4676Delete column data.
4677
4678@item @code{delete columns where missing}
4679Completely delete all column data for which any one of x, y, etc is missing.
4680
4681@item @code{delete columns randomly .fraction.}
4682Randomly select fraction @code{.fraction.}  of the non-missing column
4683data, and designate them as being missing.
4684
4685@item @code{delete grid}
4686Delete grid data.
4687
4688@item @code{delete scale}
4689Delete scales for both x and y, so next @code{read columns} will set it.
4690
4691@item @code{delete x scale}
4692Delete scales for x, so next @code{read columns} will set it.
4693
4694@item @code{delete y scale}
4695Delete scales for y, so next @code{read columns} will set it.
4696@end itemize
4697
4698
4699@c HTML <!-- newfile Differentiate.html "Gri: `differentiate' command" "Gri Commands" -->
4700
4701@node   Differentiate, Draw, Delete, List Of Gri Commands
4702@comment  node-name,  next,  previous,  up
4703@subsection @code{differentiate}
4704@cindex differentiation
4705@findex differentiate
4706@cindex @code{differentiate} command
4707
4708@example
4709`differentiate @{x|y wrt index|y|x@} | @{grid wrt x|y@}'
4710@end example
4711
4712@noindent
4713Differentiate column data or grid data.  Only the @code{x} and @code{y}
4714columns may be differentiated.  They may be differentiated either with
4715respect to (``wrt'') the index (forming a first difference) or with
4716respect to the other column.  The derivative is done with the
4717backwards-difference algorithm.  Grid data may differentiated with
4718respect to @code{x} direction or @code{y} direction.  Grid
4719differentiation is done with a centred difference, with endpoints being
4720assigned the derivative of the neighboring interior point (so that the
4721second derivative is zero at the edges of the grid).
4722
4723
4724@c HTML <!-- newfile Draw.html "Gri: About draw commands" "Gri Commands" -->
4725
4726@node   Draw, Draw Arc, Differentiate, List Of Gri Commands
4727@comment  node-name,  next,  previous,  up
4728@subsection The @code{draw} commands
4729@findex draw
4730Draw commands do actual drawing on the page.  You can draw axes,
4731lineplots, symbols, contours, images, and text.
4732
4733@strong{NOTE} Gri likes drawings to have axes, so if a @code{draw} command
4734is executed before any axes have been drawn, Gri will draw axes after it
4735draws the item.  (You can get drawings without axes by preceding any
4736other @code{draw} commands with the command @code{draw axes none}.)
4737Many users have been surprised by the results of this rule.  For
4738example, if you do @code{set graylevel 0.5} before @code{draw curve},
4739you'll find that the axes are drawn in gray also.  To avoid this, make
4740sure to do @code{draw axes} before you modify the graylevel.)
4741
4742@menu
4743* Draw Arc::                    Draw an arc segment
4744* Draw Arrow::                  Draw single arrow
4745* Draw Arrows::                 Draw many arrows (using columns)
4746* Draw Axes If Needed::         Draw axes if haven't done so yet
4747* Draw Axes::                   Draw axes
4748* Draw Border Box::             Draw border around plot
4749* Draw Box::                    Draw a box, possibly filled
4750* Draw Circle::                 Draw a circle
4751* Draw Contour::                Draw contour(s)
4752* Draw Curve::                  Draw a curve of y(x) column data
4753* Draw Essay::                  Draw text, adjusting position for each line
4754* Draw Gri Logo::               Draw a Gri logo
4755* Draw Grid::                   Draw the location of grid points
4756* Draw Image Histogram::        Draw histogram of values in image
4757* Draw Image Palette::          Draw palette used in image plots
4758* Draw Image::                  Draw image
4759* Draw Isopycnal::              Draw isopycnal line on TS plot
4760* Draw Isospice::               Draw iso-spice line on TS plot
4761* Draw Label Boxed::            Draw a label in a box
4762* Draw Label Whiteunder::       Draw a label with white ink under it
4763* Draw Label For Last Curve::   What it says
4764* Draw Label::                  Draw text somewhere
4765* Draw Line From::              Draw line segment
4766* Draw Line Legend::            Draw legend displaying line types
4767* Draw Lines::                  Draw sequence of parallel lines
4768* Draw Patches::                Draw grayscale patches showing z(x,y)
4769* Draw Polygon::                Draw a polygon
4770* Draw Regression Line::        Draw line from regression between x and y
4771* Draw Symbol At::              Draw a symbol at a point
4772* Draw Symbol Legend::          Draw a symbol and a string describing it
4773* Draw Symbol::                 Draw symbols at (x,y), or at a point
4774* Draw Time Stamp::             Draw a timestamp at top of plot
4775* Draw Title::                  Draw a title for plot
4776* Draw Values::                 Draw numbers beside z(x,y)
4777* Draw X Axis::                 Draw the x axis
4778* Draw X Box Plot::             Draw box plots showing x spread
4779* Draw Y Axis::                 Draw the y axis
4780* Draw Y Box Plot::             Draw box plots showing y spread
4781* Draw Zero Line::              Draw y=0 or x=0
4782@end menu
4783
4784@node   Draw Arc, Draw Arrow, Draw, Draw
4785@comment  node-name,  next,  previous,  up
4786@subsubsection The @code{draw arc} command
4787@findex draw arc
4788@cindex arc, drawing
4789@cindex drawing arcs
4790
4791@example
4792`draw arc [filled] .xc_cm. .yc_cm. .r_cm. .angle_1. .angle_2.'
4793@end example
4794
4795Draw an "arc", that is, a portion of a circle.  The center of the
4796circle is at the coordinate (@code{.xc_cm.}, @code{.yc_cm.}), and the
4797circle radius is @code{.r_cm.}, all three quantities being in cm on
4798the page, @emph{not} in user-units.  The arc starts at angle
4799@code{.angle_1.}, measured in degrees counterclockwise from a
4800horizontal line, and extends to angle @code{.angle_2.}, in the same
4801units.
4802
4803If the keyword @code{filled} is present, the arc is filled with the
4804current color.  Otherwise it is drawn with the current "curve"
4805linewidth @ref{Set Line Width}.
4806
4807@node   Draw Arrow, Draw Arrows, Draw Arc, Draw
4808@comment  node-name,  next,  previous,  up
4809@subsubsection @code{draw arrow}
4810@cindex arrows, drawing single
4811
4812@example
4813draw arrow from .x0. .y0. to .x1. .y1. [cm]
4814@end example
4815
4816With no optional parameters, draw an arrow from (@code{.x0.},
4817@code{.y0.}) to (@code{.x1.}, @code{.y1.}), where coordinates are in
4818user units.  The arrow head will be at (@code{.x1.}, @code{.y1.}), and
4819its size is as set by most recent call to @code{set arrow size}.  With
4820the @code{cm} keyword present, the coordinates are in centimetres on the
4821page.  NOTE: This will not cause auto-drawing of axes.
4822
4823@node   Draw Arrows, Draw Axes If Needed, Draw Arrow, Draw
4824@comment  node-name,  next,  previous,  up
4825@subsubsection @code{draw arrows}
4826@findex draw arrows
4827@cindex @code{draw arrows} command
4828
4829@example
4830`draw arrows'
4831@end example
4832
4833@noindent
4834Draw a vector field consisting of arrows emanating from the coordinates
4835stored in the (x, y) columns.  The lengths and orientations of the
4836arrows are stored in the (u, v) columns, and the scale for the (u,v)
4837columns is set by @code{set u scale} and @code{set v scale}.  @strong{See also}
4838(1) To set arrow size, use @code{set arrow size}.  (2) To get a single
4839arrow, use @code{draw arrow}.
4840
4841
4842@node   Draw Axes If Needed, Draw Axes, Draw Arrows, Draw
4843@comment  node-name,  next,  previous,  up
4844@findex draw axes if needed
4845@cindex @code{draw axes if needed} command
4846@subsubsection @code{draw axes if needed}
4847
4848@example
4849`draw axes if needed'
4850@end example
4851
4852@noindent
4853Draw axes frame if required.  Used within gri commands that auto-draw axes.
4854NOTE: this should only be done by developers.
4855
4856
4857
4858@node   Draw Axes, Draw Border Box, Draw Axes If Needed, Draw
4859@comment  node-name,  next,  previous,  up
4860@findex draw axes
4861@cindex @code{draw axes} command
4862@subsubsection @code{draw axes}
4863
4864@example
4865`draw axes [.style.|frame|none]'
4866@end example
4867
4868@noindent
4869With no style (@code{.style.}) specified, draw x-y axes frame labelled
4870at left and bottom. The value of @code{.style.} determines the style of
4871axes:
4872@itemize @bullet
4873
4874@item @code{.style. = 0}
4875Draw x-y axes frame labelled at left and bottom.  Since this is the
4876default, it's best to leave it out altogether to make your code easier to
4877understand.
4878
4879@item @code{.style. = 1}
4880Draw axes without tics at top and right
4881
4882@item @code{.style. = 2}
4883Draw axes frame with no tics or labels; same as @code{draw axes frame}
4884@end itemize
4885
4886With the keyword @code{frame} specified, draw axes frame with no tics or
4887labels (just like @code{.style.} = 2, but preferable because it makes for
4888code that is easier to read and understand).
4889
4890With the keyword @code{none} specified, prevent Gri from automatically
4891drawing axes when drawing curves.
4892
4893Note: @code{set axes style} can also be used to set axes properties,
4894and then simply using @code{draw axes}, or letting axes be auto-drawn,
4895will result in the desired effect (@ref{Set Axes Style}).  However, if
4896the @code{draw axes} command explicitly asks for a particular style,
4897then it over-rides the style set by @code{Set Axes Style}.
4898
4899
4900@node   Draw Border Box, Draw Box, Draw Axes, Draw
4901@comment  node-name,  next,  previous,  up
4902@findex draw border box
4903@cindex @code{draw border box} command
4904@subsubsection @code{draw border box}
4905
4906@example
4907`draw border box .xleft. .ybottom. .xright. .ytop. \
4908    .width_cm. .brightness.'
4909@end example
4910
4911@noindent
4912Draw gray box, as decoration or alignment key for pastup. The box, with
4913outer lower left corner at (@code{.xleft.}, @code{.ybottom.}) and outer
4914upper right corner at (@code{.xright}., @code{.ytop.}) -- both coordinates
4915being in centimetres on the page -- is drawn with thickness
4916@code{.width_cm.} and with graylevel @code{.brightness.} (0 for black; 1
4917for white).  The gray line is drawn inside the box.  After drawing the
4918gray line, a thin black line is drawn along the outside edge.
4919
4920If the geometry is not specified with @code{.xleft.} and the other
4921parameters, then a reasonable margin is used around the present axes
4922area, and the defaults (@code{.border.} = 0.2, @code{.brightness.} =
49230.75) are used.
4924
4925NOTE: This command does not cause auto-drawing of axes.
4926
4927
4928@node   Draw Box, Draw Circle, Draw Border Box, Draw
4929@comment  node-name,  next,  previous,  up
4930@subsubsection @code{draw box}
4931@findex draw box
4932@cindex @code{draw box} command
4933
4934@example
4935`draw box filled .xleft. .ybottom. .xright. .ytop. [cm|pt]'
4936@end example
4937
4938@noindent
4939Draw filled box spanning indicated range, with lower-left corner at
4940(@code{.xleft.}, @code{.ybottom.}) and upper-right corner at
4941(@code{.xright.}, @code{.ytop.}).  The corners are specified in user
4942coordinates, unless the optional @code{cm} or @code{pt} keyword is
4943present, in which case they are in centimetres or points on the page.
4944An error will result if you specify user coordinates but they aren't
4945defined yet.
4946
4947No checking is done on the rectangle; for example, there is no
4948requirement that @code{.xleft.} be to the left of @code{.xright.} in your
4949coordinate system.
4950
4951NOTE: if the box is specified in user units, this command will cause
4952auto-drawing of axes, but not if the box is specified in @code{cm}
4953or @code{pt} units
4954
4955@example
4956`draw box .xleft. .ybottom. .xright. .ytop. [cm|pt]'
4957@end example
4958
4959@noindent
4960Draw box spanning indicated range, with lower-left corner at
4961(@code{.xleft.}, @code{.ybottom.)} and upper-right corner at (@code{.xright.},
4962@code{.ytop.}).
4963
4964The corners are specified in user coordinates, unless the optional
4965@code{cm} or @code{pt} keyword is present, in which case they are in
4966centimetres or points on the page.  An error will result if you
4967specify user coordinates but they aren't defined yet.
4968
4969No checking is done on the rectangle; for example, there is no
4970requirement that @code{.xleft.} be to the left of @code{.xright.} in your
4971coordinate system.
4972
4973
4974@node   Draw Circle, Draw Contour, Draw Box, Draw
4975@comment  node-name,  next,  previous,  up
4976@subsubsection @code{draw circle}
4977@cindex circles, drawing
4978@findex draw circle
4979@cindex @code{draw circle} command
4980
4981@example
4982draw circle with radius .r_cm. at .x_cm. .y_cm.
4983@end example
4984
4985@noindent
4986Draw circle of specified radius (in cm) at the specified
4987location (in cm on the page).
4988
4989
4990@node   Draw Contour, Draw Curve, Draw Circle, Draw
4991@comment  node-name,  next,  previous,  up
4992@subsubsection @code{draw contour}
4993@cindex drawing contours
4994@cindex contouring
4995@findex draw contour
4996@cindex @code{draw contour} command
4997
4998@example
4999`draw contour [@{.value. \
5000  [unlabelled | @{labelled "\label"@}]@} \
5001  | @{.min. .max. .inc. \
5002    [.inc_unlabelled.] [unlabelled]@}]'
5003@end example
5004
5005@noindent
5006This command draws contours based on the "grid" data previously read in
5007by a @code{read grid data} command or created by gridding column data
5008with a @code{create grid from columns} command.  If the grid data don't
5009exist, or if the x and y locations of the grid points do not exist (see
5010@code{set x grid}, @code{set y grid}, etc), Gri will complain.
5011
5012With no optional parameters, draw labelled contours at an interval
5013that is picked automatically based on the range of the data.
5014
5015With a single numerical value (@code{.value.}), draw the indicated
5016contour.  With the addition of @code{labelled "\label"}, put the
5017indicated label instead of a numeric label.  This can be useful for
5018using scientific notation instead of computer notation for exponents,
5019e.g.  @code{draw contour 1e-5 labelled "10$^@{-5@}$"}.
5020
5021With (@code{.min.}, @code{.max.} and @code{.inc.}) given, draw
5022contours for z(x,y) = @code{.min.}, z(x,y) = @code{.min. + .inc.},
5023z(x,y) = @code{.min. + 2*.inc.}, ..., z(x,y) = @code{.max.}
5024
5025With the additional value @code{.inc_unlabelled.} specified, extra
5026unlabelled contours are drawn at this finer interval.
5027
5028With the optional parameter @code{unlabelled} at the end of any form
5029of this command (except the @code{labelled "\label"} variation, of
5030course), Gri will not label the contour(s).
5031
5032@strong{Hint:} It can be effective to draw contours at a certain interval
5033with labels, and a thicker pen, e.g.
5034
5035@example
5036set line width rapidograph 3x0
5037draw contour -2 5 1 0.25
5038set line width rapidograph 1
5039draw contour -2 5 1
5040@end example
5041
5042@b{Interpolation method:} The interpolation scheme is the same used for
5043converting grid-values to image values (@ref{Convert Grid To Image}).
5044
5045@strong{See also} @code{set contour labels}
5046
5047
5048@node   Draw Curve, Draw Essay, Draw Contour, Draw
5049@comment  node-name,  next,  previous,  up
5050@subsubsection @code{draw curve}
5051@findex draw curve
5052@cindex @code{draw curve} command
5053@cindex x-y graphs
5054@cindex region painting
5055@cindex paint regions with color
5056@cindex filled regions
5057@cindex drawing curves
5058@cindex curves, drawing
5059Several forms exist.
5060
5061@example
5062`draw curve'
5063@end example
5064
5065@noindent
5066Draws a curve connecting the points (x,y), which have been read in by a
5067command like @code{read columns x y}.  Line segments are drawn between
5068all (x,y) points, except: (1) no line segments are drawn to any missing
5069data (see @code{set missing value}), and (2) if clipping is turned on
5070(see @code{set clip on}), no line segments are drawn outside the
5071clipping region.  @strong{See also} @code{draw curve overlying}
5072
5073@example
5074`draw curve overlying'
5075@end example
5076
5077@noindent
5078Like @code{draw curve}, except that before drawing, the area underneath
5079the curve (+/- one linewidth) is whited out.  This clarifies graphs
5080where curves overlie other curves or the axes.
5081@strong{See also} @code{draw curve}.
5082
5083@example
5084`draw curve filled [to @{.y. y@}|@{.x. x@}]'
5085@end example
5086
5087@noindent
5088The form @code{draw curve filled ...} draws filled curves.  If the
5089@code{to .value.} is not specified, fill the region defined by the x-y points
5090using the current paint colour (see @code{set graylevel}).  To complete
5091the shape, an extra line is drawn between the first and last points.
5092
5093The form @code{draw curve filled to .y. y} fills the region between y(x)
5094and y = @code{.y.}; do not connect the first and last points as in the
5095case where @code{to .yvalue.} is not specified.
5096
5097The form @code{draw curve filled to .x. x} fills the region between x(y)
5098and x = @code{.x.}
5099
5100
5101
5102
5103
5104@node   Draw Essay, Draw Gri Logo, Draw Curve, Draw
5105@comment  node-name,  next,  previous,  up
5106@subsubsection @code{draw essay}
5107@findex draw essay
5108@cindex @code{draw essay} command
5109
5110@example
5111`draw essay "text"|reset'
5112@end example
5113
5114@noindent
5115Draw indicated text on the page.  Succeeding calls draw text further and
5116further down the page, starting at the top.
5117
5118The current font size is used; to alter this, use @code{set font size}
5119before @code{draw essay}.
5120
5121When @code{reset} is present instead of text, the drawing position is
5122reset to the top of the page.  Use this after a @code{new page} command
5123to ensure that the next text lines will appear at the top of the page as
5124expected.  EXAMPLE:
5125
5126@example
5127set font size 2 cm
5128draw essay "Line 1, at top of page"
5129draw essay "Line 2, below top line"
5130@end example
5131
5132
5133@node   Draw Gri Logo, Draw Grid, Draw Essay, Draw
5134@comment  node-name,  next,  previous,  up
5135@subsubsection @code{draw gri logo}
5136@findex draw gri logo
5137@cindex @code{draw gri logo} command
5138@cindex logo, how to draw
5139
5140@example
5141`draw gri logo .x_cm. .y_cm. .height_cm. .style. \fgcolor \bgcolor'
5142@end example
5143
5144@noindent
5145Draw a Gri logo at given location with given style and colors.  The
5146lower-left corner of the logo will be @code{.x_cm.} centimeters from the
5147left-hand side of the page and @code{.y_cm.} centimeters from the bottom
5148of the page.  The logo will be @code{.height_cm.} centimeters tall.  The
5149textual parameters @code{\fgcolor} and @code{\bgcolor} give the foreground and
5150background colors, respectively, and these are used in styles as noted
5151in the table below
5152
5153@example
5154.style.    style
5155=======    ===================
5156   0       stroke curve
5157   1       fill with color \fgcolor, no background
5158   2       fill with color \fgcolor it in tight box of color \bgcolor
5159   3       as 2 but in square box
5160   4       draw in \fgcolor on top of shifted copy in \bgcolor
5161@end example
5162
5163An example is given below
5164
5165@example
5166draw gri logo 1 1 3 4 blue green
5167@end example
5168
5169@node   Draw Grid, Draw Image Histogram, Draw Gri Logo, Draw
5170@comment  node-name,  next,  previous,  up
5171@subsubsection @code{draw grid}
5172@findex draw grid
5173@cindex @code{draw grid} comman
5174
5175@example
5176`draw grid'
5177@end example
5178
5179@noindent
5180Draw plus-signs at locations where grid data are non-missing.
5181
5182@node   Draw Image Histogram, Draw Image Palette, Draw Grid, Draw
5183@comment  node-name,  next,  previous,  up
5184@subsubsection @code{draw image histogram}
5185@findex draw image histogram
5186@cindex @code{draw image histogram} command
5187@cindex image, histogra
5188
5189@example
5190`draw image histogram \
5191  [box .llx_cm. .lly_cm. .urx_cm. .ury_cm.]'
5192@end example
5193
5194@noindent
5195With no optional parameters, draw histogram of all unmasked parts of the
5196image, placing it above the current top of the plot.
5197
5198When the @code{box} options are present, they specify the box (in
5199centimetre coordinates on the page) in which the histogram plot is to be
5200done.
5201
5202
5203
5204@node   Draw Image Palette, Draw Image, Draw Image Histogram, Draw
5205@comment  node-name,  next,  previous,  up
5206@subsubsection @code{draw image palette}
5207@findex draw image palette
5208@cindex @code{draw image palette} comman
5209
5210@example
5211`draw image palette
5212   [axisleft|axisright|axistop|axisbottom]
5213   [left .left. right .right. [increment .inc.]]
5214   [box .xleft_cm. .ybottom_cm. .xright_cm. .ytop_cm.]'
5215@end example
5216
5217@noindent
5218@cindex image, drawing palette
5219@cindex image, drawing colorscale palette
5220@cindex colorscale, drawing
5221@cindex palette for image colorscale, drawing
5222With no optional parameters, draw palette for image, placed above the
5223current top showing values ranging from @code{.min_value.} to
5224@code{.max_value.} as given in @code{set image range}.
5225
5226Optional keywords (@code{axisleft}, etc) control the orientation of the
5227palette, the default being @code{axisbottom}.
5228
5229The optional parameters @code{.left.} and @code{.right.} may be used to
5230specify the range to be drawn in the palette.  If the additional
5231optional parameter @code{.inc.} is present, it specifies the interval
5232between tics on the scale; if not present, the tics are at increments of
52332 * (@code{.right.} - @code{.left}.).  (If @code{.inc.}  has the wrong
5234sign, it will be corrected without warning.)
5235
5236When the optional @code{box} parameters are present, they prescribe the
5237bounding box to contain the palette.  The units are centimetres on the
5238page.  If these parameters are not present, the box will be drawn above
5239the image plot.
5240
5241@cindex hint, palette range
5242@strong{Hint} It is a good idea to make the palette range @code{.left.} to
5243@code{.right.} extend a little beyond the range of full white and full
5244black, since otherwise neither pure white nor pure black will appear in
5245the colorbar.  For example
5246
5247@example
5248set image grayscale black 0 white 1 increment 0.1
5249draw image palette left -0.1 right 1.1 increment 0.1
5250@end example
5251
5252@cindex hint, contour lines on image palette
5253@strong{Hint} Continuous-tone images with superimposed contours are often
5254effective.  To get the contour lines drawn on the image palette, do
5255something like this
5256
5257@example
5258draw image
5259.left.   = 0
5260.right.  = 9
5261.inc.    = 1
5262.space.  = 3
5263.height. = 1
5264draw image palette left .left. \
5265  right .right. \
5266  increment .inc. \
5267  box \
5268    ..xmargin.. \
5269    @{rpn ..ymargin.. ..ysize.. + .space. + @} \
5270    @{rpn ..xmargin.. ..xsize.. +@} \
5271    @{rpn ..ymargin.. ..ysize.. + .space. + .height. + @}
5272draw contour .left. .right. .inc. unlabelled
5273
5274.c. = .left.
5275while @{rpn .right. .c. <= @}
5276  .c_cm. = @{rpn .c. .left. - \
5277   .right. .left. - / \
5278    ..xsize.. * ..xmargin.. +@}
5279  draw line from \
5280    .c_cm. \
5281    @{rpn ..ymargin.. ..ysize.. + .space. + @}\
5282    to \
5283    .c_cm. \
5284    @{rpn ..ymargin.. ..ysize.. + .space. + .height. +@} \
5285    cm
5286  .c. += 1
5287end while
5288@end example
5289
5290
5291@node   Draw Image, Draw Isopycnal, Draw Image Palette, Draw
5292@comment  node-name,  next,  previous,  up
5293@subsubsection @code{draw image}
5294@findex draw image
5295@cindex @code{draw image} comman
5296
5297@example
5298`draw image'
5299@end example
5300
5301@noindent
5302Draw black/white image made by @code{convert grid to image} or by
5303@code{read image}.
5304
5305
5306@node   Draw Isopycnal, Draw Isospice, Draw Image, Draw
5307@comment  node-name,  next,  previous,  up
5308@subsubsection @code{draw isopycnal}
5309@findex draw isopycnal
5310@cindex @code{draw isopycnal} command
5311@cindex T-S diagram, drawing isopycnals on
5312@cindex temperature-salinity diagram, drawing isopycnals on
5313@cindex isopycnals
5314@cindex oceanographic plots isopycnals on TS diagram
5315
5316@example
5317`draw isopycnal \
5318   [unlabelled] .density. [.P_sigma. [.P_theta.]]'
5319@end example
5320
5321Draw isopycnal curve for a temperature-salinity diagram.  This curve is
5322the locus of temperature and salinity values which yield seawater of the
5323indicated density, at the indicated pressure.  The UNESCO equation of
5324state is used.
5325
5326For the results to make sense, the x-axis should be salinity and the
5327y-axis should be either in-situ temperature or potential temperature.
5328
5329The @code{.density.} unit is kg/m^3.  If the supplied value exceeds 100
5330then it will be taken to indicate the actual density; otherwise it will
5331be taken to indicate density minus 1000 kg/m^3.  (The deciding value of
5332100 kg/m^3 was chosen since water never has this density; the more
5333intuitive value of 1000 kg/m^3 would be inappropriate since water can
5334have that density at some temperatures.)  Thus, 1020 and 20 each
5335correspond to an actual density of 1020 kg/m^3.
5336
5337The reference pressure for density, @code{.P_sigma.}, is in decibars
5338(roughly corresponding to meters of water depth).  If no value is
5339supplied, a pressure of 0 dbar (i.e. atmospheric pressure) is used.
5340
5341The reference pressure for theta, @code{.P_theta.}, is in decibars, and
5342defaults to zero (i.e. atmospheric pressure) if not supplied.  This
5343option is used if the y-axis is potential temperature referenced to a
5344pressure other than the surface.  Normally the potential temperature is,
5345however, referenced to the surface, so that specifying a value for
5346@code{.P_theta.} is uncommon.
5347
5348By default, labels will be drawn on the isopycnal curve; this may be
5349prevented by supplying the keyword @code{unlabelled}.  If labels are
5350drawn, they will be of order 1000, or of order 10 to 30, according to
5351the value of @code{.density.} supplied (see above).  The label format
5352defaults to "%g" in the C-language format notation, and may be
5353controlled by @code{set contour format}.  The label position may be
5354controlled by @code{set contour label position} command (bug: only
5355non-centered style works).  Setting label position is useful if labels
5356collide with data points.  Labels are drawn in the whiteunder mode, so
5357they can white-out data below.  For this reason it is common to draw
5358data points after drawing isopycnals.
5359
5360If the y-axis is in-situ temperature, the command should be called
5361without specifying @code{.P_sigma.}, or, equivalently, with
5362@code{.P_sigma.} = 0.  That is, the resultant curve will
5363correspond to the (S,T) solution to the equation
5364
5365@example
5366.density. = RHO(S, T, 0)
5367@end example
5368
5369@noindent
5370where @code{RHO=RHO(S,T,p)} is the UNESCO equation of state for
5371seawater.  This is a curve of constant sigma_T.
5372
5373If the y-axis is potential temperature referenced to the surface,
5374@code{.P_theta.} should not be specified, or should be specified to be
5375zero.  The resultant curve corresponds to a constant value of
5376potential density referenced to pressure @code{.P_sigma.}, i.e. the
5377(S,theta) solution to the equation
5378
5379@example
5380.density. = RHO(S, theta, .P_sigma.)
5381@end example
5382
5383@noindent
5384For example, with @code{.P_sigma.=0} (the default), the result
5385is a curve of constant sigma_theta.
5386
5387If the y-axis is potential temperature referenced to some pressure other
5388than that at the surface, @code{.P_theta.} should be supplied.  The
5389resultant curve will be the (S,theta) solution to the equation
5390
5391@example
5392.density. = RHO(S, T', .P_sigma.)
5393@end example
5394
5395@noindent
5396where
5397
5398@example
5399T'=THETA(S, theta, .P_theta., .P_sigma.)
5400@end example
5401
5402@noindent
5403where @code{THETA=THETA(S,T,P,Pref)} is the UNESCO formula for potential
5404temperature of a water-parcel moved to a reference pressure of
5405@code{Pref}.  Note that @code{theta}, potential temperature referenced
5406to pressure @code{.P_theta.}, is the variable assumed to exist on
5407the y-axis.
5408
5409
5410
5411
5412@node   Draw Isospice, Draw Label Boxed, Draw Isopycnal, Draw
5413@comment  node-name,  next,  previous,  up
5414@subsubsection @code{draw isospice}
5415@findex draw isospice
5416@cindex @code{draw isospice} command
5417@cindex T-S diagram, drawing spice lines on
5418@cindex temperature-salinity diagram, drawing spice lines on
5419@cindex spice lines, on TS diagram
5420@cindex oceanographic plots, iso-spice lines on TS diagrams
5421
5422@example
5423`draw isospice .spice. [unlabelled]'
5424@end example
5425
5426@noindent
5427Draw an iso-spice line for a "TS" diagram, using (S, T) data stored in
5428files in a subdirectory named @code{iso-spice0} in a directory named by
5429the unix environment variable @code{GRI_EOS_DIR}.  You must set this
5430environment variable yourself, in the normal unix way.  If
5431@code{GRI_EOS_DIR} is not defined, Gri looks in the directory
5432@file{/data/po/ocean/EOS/iso0}; of course, this will work only
5433for people on the same machine as the author.
5434
5435Only certain iso-spice lines are stored in these files, so only certain
5436values of @code{.spice.} are allowed.  They are 21.75, 22.00, 22.25,
5437..., 30.75.  You must supply @code{.density.} in exactly this format
5438(with 2 decimal places), or else Gri will not find the appropriate TS
5439file, and will give a "can't open file" error.  NB: isopycnals ranging
5440from about 23.00 to 26.00 cross a TS diagram spanning 34<S<36 and
54410<T<10.
5442
5443The line is labelled at the right with the density value, unless the
5444@code{unlabelled} option is given.
5445
5446Clipping should be on when drawing iso-spice lines.  A warning will be
5447given if the isospice line does not intersect the clipping region.
5448
5449EXAMPLE
5450
5451@example
5452set clip on
5453draw isospice line 27.00
5454draw isospice line 27.50 unlabelled
5455@end example
5456
5457
5458@node   Draw Label Boxed, Draw Label Whiteunder, Draw Isospice, Draw
5459@comment  node-name,  next,  previous,  up
5460@subsubsection @code{draw label}
5461@findex draw label boxed
5462@cindex @code{draw label boxed} command
5463@cindex text strings, drawing
5464@cindex drawing text strings
5465@cindex drawing labels
5466@cindex labels, drawing text anywhere
5467
5468@example
5469`draw label boxed "string" at .xleft. .ybottom. [cm]'
5470@end example
5471
5472@noindent
5473Draw boxed label for plot, located with lower-left corner at indicated
5474(x,y) position (specified in user units or in cm on the page).  The
5475current font size and pen color are used.  The geometry derives from the
5476current font size, with the label being centered within the box.
5477
5478
5479@node   Draw Label Whiteunder, Draw Label For Last Curve, Draw Label Boxed, Draw
5480@comment  node-name,  next,  previous,  up
5481@subsubsection @code{draw label whiteunder}
5482@findex draw label whiteunder
5483@cindex @code{draw label whiteunder} command
5484
5485@example
5486`draw label whiteunder "\string" at .xleft. .ybottom. [cm]'
5487@end example
5488
5489@noindent
5490Draw label for plot, located with lower-left corner at indicated (x,y)
5491position (specified in user units or in cm on the page).  Whiteout is
5492used to clean up the area under the label.  BUGS: Cannot handle angled
5493text; doesn't check for super/subscripts.
5494
5495
5496@node   Draw Label For Last Curve, Draw Label, Draw Label Whiteunder, Draw
5497@comment  node-name,  next,  previous,  up
5498@subsubsection @code{draw label for last curve}
5499@findex draw label for last curve
5500@cindex @code{draw label for last curve} command
5501@cindex drawing labels on xy curves
5502@cindex labels, for xy curves
5503
5504@example
5505`draw label for last curve "label"'
5506@end example
5507
5508@noindent
5509Draw a label for the last curve drawn, using the @code{..xlast..} and
5510@code{..ylast..} built-in variables.
5511
5512
5513@node   Draw Label, Draw Line From, Draw Label For Last Curve, Draw
5514@comment  node-name,  next,  previous,  up
5515@subsubsection @code{draw label}
5516@findex draw label
5517@cindex @code{draw label} command
5518
5519@example
5520`draw label "\string" [centered|rightjustified] \
5521    at .x. .y. [cm|pt] \
5522    [rotated .deg.]'
5523@end example
5524
5525@noindent
5526With no optional parameters, draw string at given location in USER units.
5527
5528With the @code{cm} or @code{pt} keyword is present, the location is in
5529centimetres or points on the page.
5530
5531With the @code{rotated} keyword present, the angle in degrees from the
5532horizontal, measured positive in the counterclockwise direction, is
5533given.
5534
5535With the keyword @code{centered} present, the text is centered at the
5536given location; similarly the keyword @code{rightjustified} makes the
5537text end at the given location.
5538
5539
5540
5541@node   Draw Line From, Draw Line Legend, Draw Label, Draw
5542@comment  node-name,  next,  previous,  up
5543@subsubsection @code{draw line from ... to}
5544@findex draw line
5545@cindex @code{draw line} command
5546
5547@example
5548`draw line from .x0. .y0. to .x1. .y1. [cm|pt]'
5549@end example
5550
5551@noindent
5552With no optional parameters, draw a line from (@code{.x0.},
5553@code{.y0.})  to (@code{.x1.}, @code{.y1}.), where coordinates are in
5554user units.  With the @code{cm} or @code{pt} keyword present, the
5555coordinates are in centimetres or points on the page.  NOTE: This will
5556not cause auto-drawing of axes.
5557
5558
5559
5560@node   Draw Line Legend, Draw Lines, Draw Line From, Draw
5561@comment  node-name,  next,  previous,  up
5562@subsubsection @code{draw line legend}
5563@findex draw line legend
5564@cindex @code{draw line legend} command
5565
5566@example
5567`draw line legend "label" at .x. .y. [cm] [length .cm.]'
5568@end example
5569
5570@noindent
5571Draw a legend identifying the current line type with the given label.  A
5572short horizontal line is drawn starting at the location (`.x.',
5573@code{.y.}), which may be specified in centimetres or, the default, in
5574user coordinates.  The line length is normally 1 cm, but this length can
5575be set by the last option.  The indicated label string is drawn 0.25 cm
5576to the right of the line.
5577
5578@strong{See also} @code{draw symbol legend ...}.
5579
5580EXAMPLE (of keeping track of the desired location for the legend)
5581
5582@example
5583.offset. = 1                    # cm to offset legends
5584# ... get salinity data
5585set line width 0.25
5586draw curve
5587draw line legend "Salinity" at .x. .y.
5588# ... get temperature data
5589set line width 1.0
5590set dash 0.45 0.05
5591draw curve
5592.y. += .offset.
5593draw line legend "Temperature" at .x. .y.
5594@end example
5595
5596
5597@node   Draw Lines, Draw Patches, Draw Line Legend, Draw
5598@comment  node-name,  next,  previous,  up
5599@subsubsection @code{draw lines}
5600@findex draw lines
5601@cindex @code{draw lines} command
5602
5603@example
5604`draw lines @{vertically .left. .right. .inc.@} | \
5605    @{horizontally .bottom. .top. .inc.@}'
5606@end example
5607
5608@noindent
5609Draw several lines, either vertically or horizontally.  This can be
5610useful in drawing gridlines for axes, etc.  The following example shows
5611how to draw thin gray lines extending from the labelled tics on the x
5612axis (ie, at 0, 0.1, 0.2, ... 1):
5613
5614@example
5615set x axis 0 1 0.1 0.05
5616set y axis 10 20 10
5617draw axes
5618set graylevel 0.75
5619set line width 0.5
5620draw lines vertically 0 1 0.1
5621set graylevel 0
5622@end example
5623
5624
5625
5626
5627@node   Draw Patches, Draw Polygon, Draw Lines, Draw
5628@comment  node-name,  next,  previous,  up
5629@subsubsection @code{draw patches}
5630@findex draw patches
5631@cindex @code{draw patches} command
5632@cindex drawing patches
5633@cindex patches, drawing
5634
5635@example
5636`draw patches .width. .height. [cm]'
5637@end example
5638
5639@noindent
5640With the optional @code{cm} keyword not present, draw column data z(x,y)
5641as gray patches according to the grayscale as set by most recent
5642@code{set image grayscale}.  The patches are aligned along the
5643horizontal, and have the indicated size in user units.
5644
5645With the optional keyword @code{cm} is present, the patch size is
5646specified in centimetres.
5647
5648
5649
5650
5651@node   Draw Polygon, Draw Regression Line, Draw Patches, Draw
5652@comment  node-name,  next,  previous,  up
5653@subsubsection @code{draw polygon}
5654@findex draw polygon
5655@cindex @code{draw polygon} command
5656@cindex polygons, drawing
5657@cindex drawing polygons
5658
5659@example
5660`draw polygon [filled] .x0. .y0. .x1. .y1. [other pairs] [user|cm|pt]'
5661@end example
5662
5663@noindent
5664Draw a polygon connecting the indicated points, specified in user
5665units.  The last point is joined to the first by a line segment.  At
5666least two points must be specified.  If the @code{filled} keyword is
5667present, the polygon is filled with the current pen color.  If no unit
5668is given, user units are used.
5669
5670
5671@node   Draw Regression Line, Draw Symbol At, Draw Polygon, Draw
5672@comment  node-name,  next,  previous,  up
5673@subsubsection @code{draw regression line}
5674@findex draw regression line
5675@cindex @code{draw regression line} command
5676
5677@example
5678`draw regression line [clipped]'
5679@end example
5680
5681@noindent
5682Fit and draw a regression line to column data, of the form
5683 @code{y = ..coeff0.. + ..coeff1.. * x}, exporting @code{..coeff0..},
5684@code{..coeff0_sig..}, @code{..coeff1..}  and @code{..coeff1_sig..}  as
5685global variables (@ref{Regress}).
5686
5687@noindent
5688Normally, the line is not clipped to the axes frame, but it will be if
5689the keyword @code{clipped} is given.
5690
5691@noindent
5692HINT: to label the plot you might do the following:
5693
5694@example
5695sprintf \label "y = %f + %f * x. R$^2$=%f" \
5696  ..coeff0.. ..coeff1.. ..R2..
5697draw title "The linear fit is \label"
5698@end example
5699
5700
5701
5702@node   Draw Symbol At, Draw Symbol Legend, Draw Regression Line, Draw
5703@comment  node-name,  next,  previous,  up
5704@subsubsection @code{draw symbol ... at}
5705@findex draw symbol at
5706@cindex @code{draw symbol at} command
5707
5708@cindex symbols, drawing single ones
5709@cindex drawing single symbols
5710
5711@example
5712`draw symbol .code.|\name at .x. .y. [cm|pt]'
5713@end example
5714
5715@noindent
5716Draw a symbol at given (single) location.  The location is normally in
5717user coordinates; it will be in centimetres on the page if the optional
5718@code{cm} or @code{pt} keyword is given.
5719
5720With the optional numerical/name code specified, then the symbol of
5721that number or name is drawn at each (x,y) datum, whether or not a
5722z-column exists.  The numerical/name codes are:
5723
5724@c HTML <center><IMG SRC="./resources/symbols.gif" ALT="Symbols in gri"></center>
5725@c HTML <p>
5726
5727@c HTML <!--
5728@example
5729 # name                description
5730-- ----                -----------
5731 0 plus                +
5732 1 times               x
5733 2 box                 box
5734 3 circ                circle
5735 4 diamond             diamond
5736 5 triangleup          triangle with base at bottom
5737 6 triangleright       triangle with base at left
5738 7 triangledown        triangle with base at top
5739 8 triangleleft        triangle with base at right
5740 9 asterisk            *
574110 star                star of David
574211 filledbox           filled box
574312 bullet              filled circle
574413 filleddiamond       filled diamond
574514 filledtriangleup    filled triangleup
574615 filledtriangleright filled triangleright
574716 filledtriangledown  filled triangledown
574817 filledtriangleleft  filled triangleleft
5749@end example
5750@c HTML -->
5751
5752
5753@node   Draw Symbol Legend, Draw Symbol, Draw Symbol At, Draw
5754@comment  node-name,  next,  previous,  up
5755@subsubsection @code{draw symbol legend}
5756@findex draw symbol legend
5757@cindex @code{draw symbol legend} command
5758
5759@example
5760`draw symbol legend \symbol_name "label" \
5761    at .x. .y. [cm]'
5762@end example
5763
5764@noindent
5765Draw indicated symbol at indicated location, with the indicated label
5766beside it.  The label is drawn one M-space to the right of the symbol,
5767vertically centered on the indicated @code{.y.} location.
5768
5769
5770
5771@node   Draw Symbol, Draw Time Stamp, Draw Symbol Legend, Draw
5772@comment  node-name,  next,  previous,  up
5773@subsubsection @code{draw symbol}
5774@findex draw symbol
5775@cindex @code{draw symbol} command
5776
5777@example
5778`draw symbol [[.code.|\name]    \
5779    | [graylevel z]             \
5780      [color [hue z|.h.]        \
5781             [brightness .b.]   \
5782             [saturation .s.]]]'
5783@end example
5784
5785@noindent
5786With no optional parameters, draw symbols at the (x,y) data.  If a
5787z-column has been read with @code{read columns}, then its value codes
5788the symbol to draw, according to the table below.  (The value of z is
5789first rounded to the nearest integer.)  If no z-column has been read,
5790the symbol X is drawn at each datum.
5791
5792With the optional numerical/name code specified, then the symbol of
5793that number or name is drawn at each (x,y) datum, whether or not a
5794z-column exists.  The numerical/name codes are:
5795@c HTML <center><IMG SRC="./resources/symbols.gif" ALT="Symbols in Gri"></center>
5796@c HTML <p>
5797
5798@c HTML <!--
5799@example
5800 # name                description
5801-- ----                -----------
5802 0 plus                +
5803 1 times               x
5804 2 box                 box
5805 3 circ                circle
5806 4 diamond             diamond
5807 5 triangleup          triangle with base at bottom
5808 6 triangleright       triangle with base at left
5809 7 triangledown        triangle with base at top
5810 8 triangleleft        triangle with base at right
5811 9 asterisk            *
581210 star                star of David
581311 filledbox           filled box
581412 bullet              filled circle
581513 filleddiamond       filled diamond
581614 filledtriangleup    filled triangleup
581715 filledtriangleright filled triangleright
581816 filledtriangledown  filled triangledown
581917 filledtriangleleft  filled triangleleft
5820@end example
5821@c HTML -->
5822
5823With the optional @code{graylevel z} fields specified, the graylevel is
5824given by the @code{z} column (0=black, 1=white).
5825
5826With the optional @code{color} field specified, the color is
5827specified, either directly in the command (the @code{hue .h.} form) or
5828in the z column.  For more information on color, refer to the
5829@code{set color hsb ...} command.
5830
5831Examples: both @code{draw symbol bullet color} and
5832@code{draw symbol bullet color hue z} draw bullets whose hue is given by
5833the value in the z column.  The hue (or the color, in other words)
5834blends smoothly across the spectrum as the numerical value ranges from 0
5835to 1.  The value 0yields red, 1/3 yields green, 2/3 yields blue, etc.
5836If the @code{brightness} and the @code{saturation} are not specified,
5837they both default to the value 1, which yields pure, bright colors.
5838
5839Example: draw all in green dots
5840@code{draw symbol bullet color hue 0.333 brightness 1 saturation 1}
5841
5842
5843Example: display spectrum of dots
5844
5845@example
5846set symbol size 0.3
5847open "awk 'END@{ \
5848    for(c=0;c<1;c+=1/40) \
5849        print(c,c,c)@}' | "
5850read columns x y z
5851close
5852draw symbol bullet color hue z
5853@end example
5854
5855
5856
5857
5858@node   Draw Time Stamp, Draw Title, Draw Symbol, Draw
5859@comment  node-name,  next,  previous,  up
5860@subsubsection @code{draw time stamp}
5861@findex draw times stamp
5862@cindex @code{draw time stamp} command
5863
5864@example
5865`draw time stamp \
5866    [fontsize .points. \
5867        [at .x_cm. .y_cm. cm \
5868            [with angle .deg.]]]'
5869@end example
5870
5871@noindent
5872Draw the command-file name, PostScript file name, and time, at the top
5873of graph.  Normally, the timestamp is drawn at the top of the page, in a
5874fontsize of 10 points.  But the user can specify the fontsize, and
5875additionally the location (in cm) and additionally the angle measured in
5876degrees anticlockwise from the horizontal.
5877
5878NOTE: If you want to have the plot drawn in landscape mode, ensure
5879that @code{set page landscape} precedes @code{draw time stamp.}
5880
5881
5882
5883@node   Draw Title, Draw Values, Draw Time Stamp, Draw
5884@comment  node-name,  next,  previous,  up
5885@subsubsection @code{draw title}
5886@findex draw title
5887@cindex @code{draw title} command
5888
5889@example
5890`draw title "\string"'
5891@end example
5892
5893@noindent
5894Draw the indicated string above the plot.
5895
5896
5897
5898@node   Draw Values, Draw X Axis, Draw Title, Draw
5899@comment  node-name,  next,  previous,  up
5900@subsubsection @code{draw values}
5901@findex draw values
5902@cindex @code{draw values} command
5903
5904@example
5905draw values                 \
5906    [.dx. .dy.]             \
5907    [\format]               \
5908    [separation .xcm. .ycm.]
5909@end example
5910
5911@noindent
5912Draw values of @code{z} column, at corresponding (@code{x}, @code{y})
5913locations.  If the @code{separation} keyword is present, the distance
5914between successive points is checked, and points are skipped unless the
5915x and y separations exceed the indicated distances.
5916
5917@itemize @bullet
5918
5919@item @code{draw values}
5920Draw the values of @code{z(x,y)}, positioned 1/2 M-space to the right of
5921@code{(x,y)} and vertically centred on @code{y}.  The values are written
5922in a good general format known as @code{%lg}, in C terminology.
5923
5924@item @code{draw values %.2f}
5925Draw values of @code{z(x,y)} positioned as described above, but using
5926the indicated format string.  This format string specifies that 2
5927numbers be used after the decimal place, and that floating point should
5928be used.  See any C manual for format codes.
5929
5930@item @code{draw values .dx. .dy.}
5931Print values of @code{z(x,y)} at indicated offset vector
5932(@code{.dx.},@code{.dy.}), measured in centimeters, from the values of
5933@code{(x,y)} at which the data are defined.
5934
5935@item @code{draw values .dx. .dy. %.3f}
5936Print values of @code{z(x,y)} at indicated distance from @code{(x,y)},
5937indicated format.
5938@end itemize
5939
5940
5941
5942@node   Draw X Axis, Draw X Box Plot, Draw Values, Draw
5943@comment  node-name,  next,  previous,  up
5944@subsubsection @code{draw x axis}
5945@findex draw x axis
5946@cindex @code{draw x axis} command
5947
5948@example
5949draw x axis [at bottom|top|@{.y. [cm]@} [lower|upper]]
5950@end example
5951
5952@noindent
5953Draw an x axis, optionally at a specified location and of a specified
5954style.
5955@itemize @bullet
5956
5957@item @code{draw x axis}
5958Draw a lower x axis (ie, one with the numbers below the line) at the
5959bottom of the box defined by @code{set y axis}.
5960
5961@item @code{draw x axis at bottom}
5962Draw a lower x axis (ie, one with the numbers below the line) at the
5963bottom of the box defined by @code{set y axis}.
5964
5965@item @code{draw x axis at top}
5966Draw an upper x axis (ie, one with the numbers above the line) at the
5967top of the box defined by @code{set y axis} (or above any existing
5968stacked x axes there)
5969
5970@item @code{draw x axis at .y.}
5971Draw a lower x axis at indicated value of @code{.y.}.
5972
5973@item @code{draw x axis at .y. upper}
5974Draw an upper x axis at indicated value of .y.
5975@end itemize
5976
5977
5978
5979@node   Draw X Box Plot, Draw Y Axis, Draw X Axis, Draw
5980@comment  node-name,  next,  previous,  up
5981@subsubsection @code{draw x box plot}
5982@findex draw x box plot
5983@cindex @code{draw x box plot} command
5984
5985@example
5986draw x box plot at .y. [size .cm.]
5987@end example
5988
5989@noindent
5990Draw Tukey box plots (which give a summary of histogram properties).
5991Box plots were invented by Tukey for eda (exploratory data analysis).
5992The centre of the box is the median.  The box edges show the first
5993quartile (q1) and the third quartile (q3).  The distance from q3 to q1
5994is called the inter-quartile range.  The whiskers (i.e., the lines with
5995crosses at the end) extend from q1 and q3 to the furthest data points
5996which are still within a distance of 1.5 inter-quartile ranges from q1
5997and q3.  Beyond the whiskers, all outliers are shown: open circles are
5998used for data within a distance of 3 inter-quartile ranges beyond q1 and
5999q3, and in closed circles beyond that.
6000
6001As a side effect, this command stores q1, q2, and q3
6002into variables @code{..q1..}, @code{..q2..}, and @code{..q3..}.
6003
6004
6005@itemize @bullet
6006
6007@item @code{draw x box plot at .y.}
6008Draw Tukey's box plot, spreading in the x direction, centered at
6009y=@code{.y.} and of default width 0.5 cm.
6010
6011@item @code{draw x box plot at .y. size .cm.}
6012Draw Tukey's box plot, spreading in the x direction, centered at
6013y=@code{.y.} and of width @code{.cm.} centimetres.
6014@end itemize
6015
6016
6017
6018@node   Draw Y Axis, Draw Y Box Plot, Draw X Box Plot, Draw
6019@comment  node-name,  next,  previous,  up
6020@subsubsection @code{draw y axis}
6021@findex draw y axis
6022@cindex @code{draw y axis} command
6023
6024@example
6025draw y axis [at left|right|@{.x. cm@} [left|right]]
6026@end example
6027
6028@noindent
6029Draw a y axis, optionally at a specified location and of a specified
6030style.
6031
6032@itemize @bullet
6033
6034@item @code{draw y axis}
6035Draw a left-hand-side y axis (ie, one with the numbers to the left of
6036the line) at left of box defined by `set x axis'
6037
6038@item @code{draw y axis at left}
6039Draw a left-hand-side y axis (ie, one with the numbers to the left of
6040the line) at left of box defined by @code{set x axis}.
6041
6042@item @code{draw y axis at right}
6043Draw a right-hand-side y axis (ie, one with the numbers to the right of
6044the line) at right of box defined by @code{set x axis}.
6045
6046@item @code{draw y axis at .x.}
6047Draw a left-hand-side y axis (ie, one with the numbers to the left of
6048the line) at indicated value of @code{.x.}
6049
6050@item @code{draw y axis at .x. right}
6051Draw a right-hand-side y axis (ie, one with the numbers to the right of
6052the line) at indicated value of @code{.x.}
6053@end itemize
6054
6055
6056
6057@node   Draw Y Box Plot, Draw Zero Line, Draw Y Axis, Draw
6058@comment  node-name,  next,  previous,  up
6059@subsubsection @code{draw y box plot}
6060@findex draw y box plot
6061@cindex @code{draw y box plot} command
6062
6063@example
6064draw y box plot at .x. [size .cm]
6065@end example
6066
6067@noindent
6068Draw Tukey box plots (which give summary of histogram properties).
6069@itemize @bullet
6070
6071@item @code{draw y box plot at .x.}
6072Draw Tukey's box plot, spreading in the y direction, centered at
6073x=@code{.x.} and of default width 0.5 cm.
6074
6075@item @code{draw y box plot at .x. size .cm.}
6076Draw Tukey's box plot, spreading in the y direction, centered at
6077x=@code{.x.} and of width @code{.cm.} centimetres.
6078@end itemize
6079
6080As a side effect, this command stores q1, q2, and q3
6081into variables @code{..q1..}, @code{..q2..}, and @code{..q3..}.
6082
6083
6084
6085@node   Draw Zero Line, End Group, Draw Y Box Plot, Draw
6086@comment  node-name,  next,  previous,  up
6087@subsubsection @code{draw zero line}
6088@findex draw zero line
6089@cindex @code{draw zero line} command
6090
6091@example
6092draw zero line [horizontally|vertically]
6093@end example
6094
6095@noindent
6096Draw lines corresponding to x=0 or y=0.
6097@itemize @bullet
6098
6099@item @code{draw zero line}
6100Draw line y=0 if it is within axes.
6101
6102@item @code{draw zero line horizontally}
6103Draw line y=0 if it is within axes.
6104
6105@item @code{draw zero line vertically}
6106Draw line x=0 if it is within axes.
6107@end itemize
6108
6109
6110@c HTML <!-- newfile EndGroup.html "Gri: `end group' command" "Gri Commands" -->
6111
6112@node   End Group, Expecting, Draw Zero Line, List Of Gri Commands
6113@comment  node-name,  next,  previous,  up
6114@subsubsection @code{end grouip}
6115@findex end group
6116@cindex @code{end group} command
6117
6118@example
6119end group
6120@end example
6121
6122@noindent
6123@emph{Command not implemented yet.  Syntax may change.}
6124
6125
6126
6127
6128
6129@c HTML <!-- newfile Expecting.html "Gri: `expecting' command" "Gri Commands" -->
6130
6131@node   Expecting, Filter, End Group, List Of Gri Commands
6132@comment  node-name,  next,  previous,  up
6133@subsection @code{expecting}
6134@cindex changes to Gri, protection against
6135@cindex protection against changes to Gri
6136@findex expecting
6137@cindex @code{expecting} command
6138@cindex incompatibilities, keeping track of
6139
6140@example
6141expecting version a.b
6142expecting version a.b.c
6143@end example
6144
6145@noindent
6146
6147Show a list of incompatibilites that have been introduced since the
6148named version.  This command can make your commandfiles more reliable
6149against changes to Gri.
6150
6151There are two forms of the version number.  Modern versions use the
6152triplet form, e.g.  @code{expecting version 2.8.7}, but prior to
6153October 1996 the version numbers were written in decimal form, so that
6154you would write @code{expecting version 1.069} for example.
6155
6156@c HTML <!-- newfile Filter.html "Gri: `filter' command" "Gri Commands" -->
6157
6158@node   Filter, Flip, Expecting, List Of Gri Commands
6159@comment  node-name,  next,  previous,  up
6160@subsection @code{filter}
6161@cindex columns, filtering
6162@cindex images, filtering
6163@cindex filtering image data
6164@cindex filtering column data
6165@cindex smoothing column data
6166
6167@findex filter
6168@cindex @code{filter} command
6169
6170@itemize @bullet
6171
6172@item @code{filter column x|y|z|u|v|weight recursively a[0] a[1] ... b[0] b[1] ...}
6173Filter indicated column, using a two-pass recursive filter.  The first
6174pass runs from the start to the end, while the second pass runs from the
6175end to the start; in this way, the phase shift inherent in this type of
6176filter is removed entirely.  The coefficients are used in the following
6177formula (demonstrated on the @code{x} column):
6178
6179@example
6180x_new[i] = b[0] * x[i] \
6181  + b[1] * x[i-1] \
6182  + b[2] * x[i-2] \
6183  + ... \
6184  - a[1] * x_new[i-1] \
6185  - a[2] * x_new[i-2] \
6186  - ...
6187@end example
6188
6189@noindent
6190Thus, for example, setting @code{a[i]} = 0 results in a simple
6191backwards-looking moving-average filter applied in two passes.  The real
6192power of this type of filter, however, comes when non-zero @code{a[i]}
6193coefficients are given, thus adding recursion (i.e., @code{x_new[i]}
6194depends on @code{x_new[i-...]}).  See any standard reference on digital
6195filters for an explanation.  You might find that the Matlab command
6196@code{butter} an easy way to design filter coefficients.  Here are some
6197examples:
6198
6199@example
6200# Filter x column with simple 2-point moving
6201# average.  (This slurs into a 3-point moving
6202# average, in effect, since the filter is run
6203# forwards and then backwards.)
6204filter column x recursively 0 0 0.5 0.5
6205
6206# Use filter designed with the Matlab
6207# command butter(2,0.1), which creates a
6208# 2nd order lowpass butterworth filter
6209# with a cutoff frequency of 0.1
6210# (in units which have a frequency
6211# of 1 corresponding to one-half the
6212# sampling rate).
6213filter column x recursively \
6214    1     -1.561  0.6414 \
6215    0.0201 0.0402 0.0201
6216@end example
6217
6218@item @code{filter grid rows|columns recursively a[0] a[1] ... b[0] b[1] ...}
6219@noindent
6220Apply recursive filter (see @code{filter column ... recursively} for
6221meaning of this filter operation) to the individual rows or columns of
6222the grid data.  For example, the command
6223@code{filter grid columns recursively 0 0 0.5 0.5}
6224applies a 2-point moving average filter across the columns,
6225smoothing the grid in the x-direction.
6226
6227@item @code{filter image highpass}
6228Remove low-wavenumber components from image (ie, sharpen edges).  Do
6229this by subtracting a Laplacian smoothed version of the image.
6230
6231@item @code{filter image lowpass}
6232Remove high-wavenumber components from image (ie, smooth shapes).  Do
6233this by Laplacian smoothing.
6234@end itemize
6235
6236@strong{See also} @ref{Smooth}.
6237
6238
6239@c HTML <!-- newfile Flip.html "Gri: `flip' command" "Gri Commands" -->
6240
6241@node   Flip, Get Env, Filter, List Of Gri Commands
6242@comment  node-name,  next,  previous,  up
6243@subsection @code{flip}
6244@cindex grid, flipping
6245@cindex image, flipping
6246@cindex flipping grids and images
6247@findex flip
6248@cindex @code{flip} command
6249
6250@example
6251`flip grid|image x|y'
6252@end example
6253
6254@noindent
6255Flip grid or image by relecting it about a horizontal or vertical
6256centerline.
6257@itemize @bullet
6258
6259@item @code{flip grid x}
6260Flip grid so right-hand side becomes left-hand side.
6261
6262@item @code{flip grid y}
6263Flip grid so bottom side becomes top side.
6264
6265@item @code{flip image x}
6266Flip image so right-hand side becomes left-hand side.
6267
6268@item @code{flip image y}
6269Flip image so bottom side becomes top side.
6270@end itemize
6271
6272
6273
6274@c HTML <!-- newfile GetEnv.html "Gri: `get env' command" "Gri Commands" -->
6275
6276
6277@node   Get Env, Group, Flip, List Of Gri Commands
6278@comment  node-name,  next,  previous,  up
6279@subsection @code{get env}
6280@cindex environment variables
6281@cindex unix environment variables
6282@cindex operating system, getenv
6283@cindex operating system, environment variables
6284@findex get env
6285@cindex @code{get env} command
6286
6287@example
6288`get env \result \environment_variable'
6289@end example
6290
6291@noindent
6292Get the value of an "environment variable" from the unix operating system,
6293and store the result in the indicated synonym.  This makes most sense on
6294unix systems (hence the name, patterned after the unix command
6295@code{getenv}).  This command can be useful in making gri programs
6296resistant to changes in data-file locations.  Suppose, for example,
6297there is a file called @file{data}, normally in a local directory called
6298@code{Bravo}.  The line @code{open Bravo/data} will fail if the Bravo
6299directory is moved.  But if the name of the datafile is stored in an
6300unix environment variable, @code{DIR_BRAVO} say, then the gri program will
6301work no matter where the Bravo data are moved, so long as an appropriate
6302environment variable is modified when the data are moved.  Example:
6303
6304@example
6305get env \dir DIR_BRAVO
6306if @{rpn "\dir" "" ==@}
6307    show "Cannot determine location of the Bravo data,"
6308    show "which should be stored in the environment"
6309    show "variable DIR_BRAVO.  You should"
6310    show "do something like"
6311    show "export DIR_BRAVO='/data/Bravo/'"
6312    show "in your ~/.environment file"
6313    quit
6314end if
6315open \dir/data
6316...
6317@end example
6318
6319
6320@c HTML <!-- newfile Group.html "Gri: `group' command" "Gri Commands" -->
6321
6322@node   Group, Heal, Get Env, List Of Gri Commands
6323@comment  node-name,  next,  previous,  up
6324@subsection @code{group}
6325@findex group
6326@cindex @code{group} command
6327
6328@example
6329`group ["\name"]'
6330@end example
6331
6332@noindent
6333@emph{Command not implemented yet.  Syntax may change.}
6334
6335
6336@c HTML <!-- newfile Heal.html "Gri: `heal' command" "Gri Commands" -->
6337
6338@node   Heal, Help, Group, List Of Gri Commands
6339@comment  node-name,  next,  previous,  up
6340@subsection @code{heal}
6341@findex heal
6342@cindex @code{heal} command
6343
6344@example
6345heal columns|@{columns along x|y@}
6346@end example
6347The @code{heal} command heals over gaps in either columnar or gridded
6348data.  This is done by linear interpolation across the missing-value
6349gaps.
6350
6351@itemize @bullet
6352
6353@item @code{heal columns}
6354@noindent
6355Fill in missing values in x, y, z, ... columns, by linear interpolation
6356to neighboring valid data.  All gaps in the data will get replaced
6357by a linear function of index which matches the data at the indices just
6358before and just after the gap.  For example, if the y data were
6359like
6360
6361@example
6362111
63633
6364-9
6365-9
6366-9
63677
6368333
6369@end example
6370
6371@noindent
6372where @code{-9} is the missing-value code, then they would get
6373replace by
6374
6375@example
6376111
63773
63784
63795
63806
63817
6382333
6383@end example
6384
6385@noindent
6386Notes: (1) This is done @strong{independently} for all existing columns.
6387(2) Gaps at the start and end of the columns are not filled in.
6388
6389@item @code{heal grid along x}
6390@noindent
6391Scan in the x direction, filling in missing values by linear
6392interpolation.  Since this uses the the x-grid, you must first have done
6393@code{read grid x} or @code{set x grid}.
6394
6395@item @code{heal grid along y}
6396@noindent
6397Scan in the y direction, filling in missing values by linear
6398interpolation.  Since this uses the the y-grid, you must first have done
6399@code{read grid y} or @code{set y grid}.
6400@end itemize
6401
6402
6403@c HTML <!-- newfile Help.html "Gri: `help' command" "Gri Commands" -->
6404
6405@node   Help, If, Heal, List Of Gri Commands
6406@comment  node-name,  next,  previous,  up
6407@subsection @code{help}
6408@findex help
6409@cindex @code{help} command
6410
6411@example
6412`help [*|command_name|@{- topic@}]'
6413@end example
6414
6415@noindent
6416Give help on a command or topic.
6417@itemize @bullet
6418
6419@item @code{help}
6420Print a general help message.
6421
6422@item @code{help *}
6423Prints complete help info.
6424
6425@item @code{help command_name}
6426Prints help on the command whose name begins with the
6427string @code{command_name}.  The string may be several words long; e.g.
6428@code{help set} or @code{help set x axis}.
6429
6430@item @code{help - topic_name}
6431The minus sign tells Gri that the string to follow it is a topic, not a
6432command.  Topics Gri knows about are listed by the one-word @code{help}
6433request.
6434@end itemize
6435
6436
6437
6438@c HTML <!-- newfile If.html "Gri: `if' command" "Gri Commands" -->
6439
6440@node   If, Ignore, Help, List Of Gri Commands
6441@comment  node-name,  next,  previous,  up
6442@subsection @code{if}
6443@cindex if statements
6444@findex if
6445@cindex @code{if} command
6446(@strong{See also} @ref{If Statements}.)
6447
6448@example
6449`if @{[!] .flag.@}|\flag|@{@{"string1" == "string2"@}@}'
6450@end example
6451
6452@noindent
6453Control program flow.  The @code{if} block is ended with a line
6454containing @code{end if}.  Optional @code{else} and @code{else if}
6455blocks are allowed.  Note that rpn expressions are allowed, and a
6456special form of string comparison is allowed, as in the examples below.
6457
6458@example
6459if .flag.
6460  # List of Gri commands to be done if .flag. is 1.
6461  # This list may extend across any number of lines.
6462end if
6463@end example
6464
6465@noindent
6466If the variable @code{.flag.} is not equal to 0, do the code between the
6467@code{if} line and the @code{end if} line.
6468
6469@example
6470if .flag.
6471  # Commands done if .flag. is 1
6472else
6473  # Commands done if .flag. is 0
6474end if
6475@end example
6476
6477@noindent
6478If the variable @code{.flag.} is not equal to 0, do the code between the
6479@code{if} line and the @code{else} line.  If @code{.flag.} is equal to
64800, do the code between the @code{else} line and the @code{end if} line.
6481
6482@example
6483if ! .flag.
6484  # Commands done if .flag. is 0
6485end if
6486@end example
6487
6488@noindent
6489If the variable @code{.flag.} is equal to 0, do the code between the
6490@code{if} line and the @code{end if} line.
6491
6492
6493@example
6494if @{rpn .flag. 10 <@}
6495  # Commands done if 10 is less than .flag.
6496end if
6497@end example
6498
6499@noindent
6500If the variable @code{.flag.} is greater than 10,
6501do the code between the
6502@code{if} line and the @code{end if} line.
6503
6504@example
6505if \smooth
6506  # Commands done if \smooth is 1
6507else
6508  # Commands done if \smooth is 0
6509end if
6510@end example
6511
6512@noindent
6513If the number stored in the synonym @code{\smooth} is not equal to 0, do
6514the code between the @code{if} line and the @code{else} line.  If the
6515synonym stores a representation of a number not equal to zero, do the
6516@code{else} part.  If the synonym contains text that does not decode to
6517a number, generate error message.
6518
6519@example
6520if @{"\item" == "Temperature"@}
6521  # Commands done if the synonym \item is equal to the
6522  # indicated text string.
6523end if
6524@end example
6525
6526@noindent
6527If the synonym @code{\item} has the value @code{Temperature} stored in
6528it, do the indicated code.
6529
6530@example
6531if @{rpn "\item" "Temperature" ==@}
6532  # Commands done if the synonym \item
6533  # equals indicated text string.
6534end if
6535@end example
6536
6537@noindent
6538As above, but using the @code{rpn} calculator
6539(@ref{rpn Mathematics}).
6540
6541@example
6542if @{rpn "\item" "Temperature" !=@}
6543  # ...
6544end if
6545@end example
6546
6547@noindent
6548As above, but do the indicated code if @code{\item} is @strong{not} equal
6549to @code{Temperature}.
6550
6551
6552
6553@c HTML <!-- newfile Ignore.html "Gri: `ignore' command" "Gri Commands" -->
6554
6555@node   Ignore, Input, If, List Of Gri Commands
6556@comment  node-name,  next,  previous,  up
6557@subsection @code{ignore}
6558@findex ignore
6559@cindex @code{ignore} command
6560
6561@example
6562`ignore last .n.'
6563@end example
6564
6565@noindent
6566Ignores last @code{.n.} lines read by @code{read columns}.
6567
6568
6569@c HTML <!-- newfile Input.html "Gri: `input' command" "Gri Commands" -->
6570
6571@node   Input, Insert, Ignore, List Of Gri Commands
6572@comment  node-name,  next,  previous,  up
6573@subsection @code{input}
6574@findex input
6575@cindex @code{input} command
6576
6577@example
6578`input \ps_filename \
6579  [.xcm. .ycm. \
6580    [.xmag. .ymag. \
6581      [.rot_deg.]]]'
6582@end example
6583
6584@noindent
6585Input the named PostScript file directly into the Gri output PostScript
6586file.  (If the filename has punctuation, insert it in double quotes,
6587e.g. @code{input "../thefile"}.)  If no options are specified, the file
6588is input at normal scale, with normal margins.  (Aside to PostScript
6589programmers: the named file is sandwiched between @code{gsave} and
6590@code{grestore} commands.)  If @code{.xcm.} and @code{.ycm.} are
6591specified, then the origin is moved to the named location first.  If, in
6592addition, @code{.xmag.} and @code{.ymag.} are specified, then these are
6593used as scale factors after translation.  Finally, if @code{.rot_deg.}
6594is specified in addition, then the indicated counterclockwise rotation
6595is applied after translation and scaling.  Hint: if the results look
6596wrong, the first thing to do is to think carefully about the order of
6597the (translation, scaling, rotation) operations.
6598
6599
6600
6601@c HTML <!-- newfile Insert.html "Gri: `insert' command" "Gri Commands" -->
6602
6603@node   Insert, Interpolate, Input, List Of Gri Commands
6604@comment  node-name,  next,  previous,  up
6605@subsection @code{insert}
6606@findex insert
6607@cindex @code{insert} command
6608
6609@example
6610`insert \filename'
6611@end example
6612
6613@noindent
6614Perform the commands in the indicated file.
6615
6616If the file name is absolute (i.e. starts with @code{.}, or with
6617@code{/} or with @code{~}) then an error results if the file is not
6618present (or cannot be read by this user).
6619
6620However, if the file name starts with a normal letter, Gri will try
6621harder to locate the file.  If it is not in the local directory, and if
6622a @code{set path to "PATH" for commands} has been done, then Gri will
6623search the colon-separated directories for the file (@ref{Set Path To}).
6624
6625If you don't want path-searching done, use the @code{source} command
6626instead (@ref{Source}).
6627
6628
6629
6630@c HTML <!-- newfile Interpolate.html "Gri: `interpolate' command" "Gri Commands" -->
6631
6632@node   Interpolate, List, Insert, List Of Gri Commands
6633@comment  node-name,  next,  previous,  up
6634@subsection @code{interpolate}
6635@findex interpolate
6636@cindex @code{interpolate} command
6637@cindex contouring, interpolating to new grid
6638@cindex grid, interpolating from one to another
6639
6640@example
6641interpolate x grid to .left. .right. .inc.|@{/.cols.@}'
6642interpolate y grid to .bottom. .top. .inc.|@{/.rows.@}'
6643@end example
6644
6645@noindent
6646Transform grid by interpolating between existing grid data, according to
6647a new x or y grid specified in the manner of @code{set x grid} and
6648@code{set y grid}.  Note that the new grid is neccessarily regular,
6649while the first grid needn't have been.  The data of the new grid are
6650constructed by interpolation, using the same interpolation algorithm as
6651the @code{convert grid to image} command.
6652
6653
6654
6655@c HTML <!-- newfile List.html "Gri: `list' command" "Gri Commands" -->
6656
6657@node   List, Ls, Interpolate, List Of Gri Commands
6658@comment  node-name,  next,  previous,  up
6659@subsection @code{list}
6660@findex list
6661@cindex @code{list} command
6662
6663@example
6664`list \command-syntax'
6665@end example
6666
6667@noindent
6668List the source of a gri command.  Often this is just the name of a C
6669function internal to gri (try @code{list list} for an example), but when
6670the command is written in the gri programming language the source will
6671be more understandable (try @code{list set panel}).
6672
6673
6674@c HTML <!-- newfile Ls.html "Gri: `ls' command" "Gri Commands" -->
6675
6676@node   Ls, Mask, List, List Of Gri Commands
6677@comment  node-name,  next,  previous,  up
6678@subsection @code{ls}
6679@cindex files, listing
6680@cindex directory listing
6681@findex ls
6682@cindex @code{ls} command
6683
6684@example
6685`ls [\file_specification]'
6686@end example
6687
6688@noindent
6689List files in current directory.  (The current directory can be printed
6690by the gri command @code{pwd} and can be set by the gri command
6691@code{cd}.)  @code{ls \file_specification} lists files in current
6692directory which match the file specification.  Normal unix file
6693specification options are understood.
6694
6695
6696@c HTML <!-- newfile Mask.html "Gri: `mask' command" "Gri Commands" -->
6697
6698@node   Mask, New, Ls, List Of Gri Commands
6699@comment  node-name,  next,  previous,  up
6700@subsection @code{mask}
6701@cindex masking image
6702@cindex image, masking
6703@findex mask
6704@cindex @code{mask} command
6705
6706@example
6707`mask the image [to @{uservalue .u.@}|@{imagevalue .i.@}]'
6708@end example
6709
6710@noindent
6711Examine both the image and the mask pixel by pixel.  For any pixels
6712which have a mask value of 1 (which indicates an invalid region of the
6713image), change the image value.  If no @code{to} phrase is present,
6714change the image value to 0 in pixel units.  If the
6715@code{to uservalue .u.} phrase is present, change the pixel to hold the
6716imagevalue that
6717corresponds to this uservalue (see @code{set image range} command for
6718a discussion of this correspondance).  If the @code{to imagevalue .i.}
6719phrase is present,
6720change the pixel to hold that imagevalue (in range 0 to 255 inclusive
6721for 8-bit images).
6722
6723
6724@c HTML <!-- newfile New.html "Gri: `new' command" "Gri Commands" -->
6725
6726@node   New, Newpage, Mask, List Of Gri Commands
6727@comment  node-name,  next,  previous,  up
6728@subsection @code{new}
6729@findex new
6730@cindex @code{new} command
6731@cindex synonyms, multiple copies of
6732@cindex synonyms, making local versions
6733@cindex variables, making local versions
6734@cindex variables, multiple copies of
6735
6736@example
6737new .variable_name. | \synonym_name \
6738   [.variable_name. | \synonym_name \
6739   [...]]
6740@end example
6741
6742@noindent
6743@code{new} sets aside storage for new version of the named variable(s)
6744and/or synonym(s).  Any number of variables and synonyms may be
6745specified.  If a given variable/synonym already exists, this will create
6746a new version of it, and future assignments will be stored in this new
6747version @strong{without} affecting the pre-existing version.  If the
6748variable/synonym is @code{delete}ed, the new version is deleted, making
6749the old, unaltered, version accessible again.
6750
6751This command is used mostly for temporary use, to prevent clashing with
6752existing values.  Suppose you want to change the font size inside a new
6753command or an if block.  Then you might do the following, where the
6754variable @code{.tmp.} is used to store the old font size.  Note that the
6755use of the @code{new/delete} statements prevents the assignment to the
6756local version of the variable @code{.tmp.} from affecting the value
6757known outside the @code{if} block, if in fact @code{.tmp.} happened to
6758exist outside the block.
6759
6760@example
6761set font size 10
6762draw label "This is in fontsize 10" at 10 2 cm
6763if .want_title.
6764  new .tmp.
6765  .tmp. = ..fontsize..
6766  set font size 22
6767  draw label "This is 22 font" at 10 5 cm
6768  set font size .tmp.
6769  delete .tmp.
6770end if
6771draw label "This is 10 font" at 10 8 cm
6772@end example
6773
6774@strong{Special case}: for local synonyms (e.g. @code{\.word1.}, etc.),
6775the @code{new} operator checks to see whether the synonym is standing
6776for an "ampersand" argument, signalling a changeable argument that is a
6777variable or a synonym.  In such a case, @code{new} creates a new
6778instance of the item in the calling context.  The test suite has
6779examples (@ref{Test Suite}).
6780
6781@c HTML <!-- newfile Newpage.html "Gri: `newpage' command" "Gri Commands" -->
6782
6783@node   Newpage, New Postscript File, New, List Of Gri Commands
6784@comment  node-name,  next,  previous,  up
6785@subsection @code{new page}
6786@cindex page breaks
6787@findex new page
6788@cindex @code{new page} command
6789
6790@example
6791`new page'
6792@end example
6793
6794@noindent
6795Finish the present page, and start a new page.  All settings (of
6796linewidth, axes, landscape/portrait, etc) are retained on the new page.
6797Among these settings is the flag that tells gri whether you need axes
6798plotted along with your data.
6799
6800
6801@node   New Postscript File, Open, Newpage, List Of Gri Commands
6802@comment  node-name,  next,  previous,  up
6803@subsection @code{new postscript file}
6804@findex new postscript file
6805@cindex @code{new postscript file} command
6806
6807@example
6808`new postscript file "name"'
6809@end example
6810
6811@noindent
6812Finish the present Postscript file, and start a new page with the given
6813name.  All settings (of linewidth, axes, landscape/portrait, etc.) and
6814data are retained on the new file.
6815
6816
6817
6818@c HTML <!-- newfile Open.html "Gri: `open' command" "Gri Commands" -->
6819
6820@node   Open, Opening Simple Files, New Postscript File, List Of Gri Commands
6821@comment  node-name,  next,  previous,  up
6822@subsection @code{open}
6823@findex open
6824@cindex @code{open} command
6825@cindex netCDF files, opening
6826@cindex operating system, filtering datafiles
6827@cindex system commands acting as datafiles
6828@cindex data files, opening
6829@cindex opening data files
6830There are two styles of @code{open} command.  In the first style, a
6831simple file is to be opened.  In the second style a unix-like "pipe" is
6832opened, i.e. Gri will read the output of a system command instead of a
6833file.
6834@menu
6835* Opening Simple Files::
6836* Opening Pipes::
6837* Opening URLs::
6838@end menu
6839
6840
6841@node   Opening Simple Files, Ascii Files, Open, Open
6842@comment  node-name,  next,  previous,  up
6843@subsubsection Opening simple files
6844
6845@menu
6846* Ascii Files::
6847* Binary Files::
6848* NetCDF Files::
6849@end menu
6850
6851@node   Ascii Files, Binary Files, Opening Simple Files, Opening Simple Files
6852@comment  node-name,  next,  previous,  up
6853@b{Ascii Files}
6854Most applications involve ascii files, and these are very easy to handle
6855in Gri.  For example given a data file named @file{foo.dat}, just use
6856the command
6857
6858@example
6859open foo.dat
6860@end example
6861
6862@noindent
6863and then you can read the data using various commands.  Thus a complete
6864program might be
6865
6866@example
6867open foo.dat
6868read columns x y
6869draw curve
6870@end example
6871
6872If a filename contains blanks or punctuation symbols, you must put it in
6873double quotes (@code{"}), e.g.
6874
6875@example
6876open "foo bar.dat"
6877@end example
6878
6879Indeed, Gri accepts double-quotes on any @code{open} command and some
6880folks use it on all commands, as a matter of habit.
6881
6882Gri can handle compressed files appropriately, e.g.
6883
6884@example
6885open foo.data.gz
6886@end example
6887
6888@noindent
6889so that there is no need to uncompress data for use with Gri.
6890
6891@cindex compressed files, opening
6892@cindex gzipped files, opening
6893@cindex opening gzipped
6894@cindex opening compressed files
6895
6896Gri is quite persistant in looking for your file, and if a given file is
6897not found, it will then check to see if a compressed version is
6898available, and use that instead.  Thus
6899
6900@example
6901open foo.dat
6902@end example
6903
6904@noindent
6905will look for a file named @file{foo.dat.gz} if @file{foo.dat} is not
6906available.  (Only files compressed with the GNU @code{gzip} utility are
6907handled.)
6908
6909If the @code{open} command was successful in opening the file, it will
6910set the value of the synonym @code{\.return_value.} to the @b{full}
6911pathname of the file.  Thus, if @code{open a.dat} is done in directory
6912@code{/home/gri}, then @code{\.return_value.} will equal
6913the string @code{/home/gri/a.dat}.
6914
6915
6916@node   Binary Files, NetCDF Files, Ascii Files, Opening Simple Files
6917@comment  node-name,  next,  previous,  up
6918@cindex binary data
6919
6920@b{Binary Files}
6921@cindex endian file compatibility, caution
6922@cindex little-endian vs big-endian data, caution
6923@cindex big-endian vs little-endian data, caution
6924Like most computer programs, Gri has some trouble with binary files.
6925One big issue is the so-called "endian" character of the computer.  Some
6926computers store multi-byte values with the most significant bytes first,
6927while others store them with the most significant bytes last.  The
6928problem is that nothing is stored in data files to indicate which
6929convention was employed.  For this reason, a version of Gri compiled on
6930a so-called "big-endian" computer will misinterpret multi-byte values
6931that were created on a so-called "little-endian" computer.  Many folks
6932in the scientific community have converted to using the NetCDF format
6933(see next section) for precisely this reason, since this format is
6934independent of the endian character of the computer.
6935
6936Presuming an appropriate endian character, however, reading is
6937straightforward.  A command of the form
6938
6939@example
6940open foo.dat binary
6941@end example
6942
6943@noindent
6944tells Gri that the data are stored in a binary format.  With the above
6945syntax, Gri expects images to be in @code{unsigned char} (8 bits), while
6946other data, such as columns and grids, are expected to be in 32-bit
6947format (suitable for reading into a so-called "float" variable in the C
6948programming language).
6949
6950You may also specify the format directly, as in the following examples;
6951Gri then interprets all data as being in the indicated format and then
6952converts to the internal format before using the data.
6953
6954@example
6955open \filename binary uchar
6956open \filename binary 8bit
6957open \filename binary int
6958open \filename binary float
6959open \filename binary double
6960open \filename binary 16bit
6961@end example
6962
6963As with ascii files, Gri will automatically uncompress any files that
6964are compressed, and if it fails to find a given filename, it will try to
6965open a compressed version of it (i.e. one with a @file{.gz} suffix).
6966
6967
6968@node   NetCDF Files, Opening Pipes, Binary Files, Opening Simple Files
6969@comment  node-name,  next,  previous,  up
6970@b{NetCDF Files}
6971@cindex netcdf data
6972The NetCDF format provides the best of both worlds.  It is binary, so
6973that data are relatively compact, and may be read very quickly.
6974(Reading ascii data is time-consuming in C++, the language in which Gri
6975is written.)  But it does not suffer the endian problem problem of
6976normal binary files (see previous section), since information about the
6977endian character is stored in the file itself, and Gri uses this
6978information to decode the data without difficulty, regardless of the
6979endian characteristics of the computer on which Gri is running and of
6980the computer that created the data.
6981
6982For more information on netCDF format, see
6983
6984@code{http://www.unidata.ucar.edu/packages/netcdf/index.html}
6985@c HTML <a href="http://www.unidata.ucar.edu/packages/netcdf/index.html">
6986@c HTML here </a>.
6987
6988The syntax of opening NetCDF files is as below
6989
6990@example
6991open foo.nc netCDF
6992@end example
6993
6994@noindent
6995and the syntax for reading such files is described in sections on the
6996various @code{read} commands (see e.g. @ref{Read Columns}).
6997
6998
6999
7000@node   Opening Pipes, Opening URLs, NetCDF Files, Open
7001@comment  node-name,  next,  previous,  up
7002@subsubsection Opening pipes
7003@cindex pipes, opening files through them
7004
7005Sometimes it makes sense to get Gri to work with the results of another
7006command in the OS.  Gri handles this by creating a so-called "pipe",
7007thus reading the output from the other command.  (Readers familiar with
7008the unix OS will know what pipes are all about, and especially why they
7009are a good thing.  Other readers might wish to skip this section.)
7010
7011Suppose we wish to plot an x-y plot using just the first few lines of a
7012datafile named @file{foo.dat}.  Unix users will know that a good way to
7013see the first few lines of such a file would be to type the command
7014@code{head foo.dat}.  They also know that these lines could be provided
7015to a second unix command, named @file{do_foo} say, by the command
7016@code{head foo.dat | do_foo}.  This uses a so-called "pipe", designated
7017by the vertical line (called a pipe symbol below).
7018
7019Gri can read the output from system commands by using a syntax in which
7020the (quoted) system command ends in a pipe symbol, e.g.
7021
7022@example
7023open "head foo.dat |"
7024@end example
7025
7026@noindent
7027as in the example above.
7028
7029@strong{Aside}: When pipe-open commands are used, Gri creates a temporary
7030file (often located in @file{/usr/tmp}, but that varies with machine).
7031This is automatically cleaned up when Gri completes executation, but if
7032Gri dies (or is interrupted) before it finishes, you'll be left with an
7033extra file in this temporary-storage directory.  It's up to you to clean
7034that directory up from time to time.
7035
7036Some common examples of pipe-open commands are given below.
7037
7038@enumerate
7039
7040@item
7041@cindex csv data
7042@cindex data, csv
7043@cindex data, comma-separated values
7044@cindex data, stored in comma-separated values
7045@cindex data, from a spreadsheet
7046@cindex data, spreadsheet
7047@cindex comma-separated values
7048@cindex spreadsheet data
7049@strong{Comma-separated values} are common in files created by, or
7050intended for, spreadsheets.  Since Gri expects data elements to be
7051separated by blanks (or tabs), you'll have to convert the commas into
7052blanks.  There are many ways to do that using pipes, e.g.
7053@file{sed} system utility, e.g.
7054
7055@example
7056open "sed -e 's/,/ /g' foo.dat |"
7057@end example
7058
7059Other unix facilities, such as @code{tr} will also work, of course.  If
7060the file has headers, you'll want to remove them also.  This can be done
7061with the @code{skip} command (@ref{Skip}) but you could also do it at
7062the open stage, e.g. to remove the first two lines, use
7063
7064@example
7065open "sed -e 's/,/ /g' foo.dat | tail +2 |"
7066@end example
7067
7068@item
7069@strong{Manipulating column data} is done by e.g.
7070
7071@example
7072open "cat foo.dat | awk '@{$1, $2 * 22@}' |"
7073@end example
7074
7075@noindent
7076where @file{awk} has been used to multiply the second column in the file
7077named @file{foo.dat} by 22.
7078
7079
7080@item
7081@strong{Time-based and geographical data} are sometimes encountered.  For
7082an example, suppose that longitude/latitude (i.e. x/y) data are stored
7083in Hour.minutesecond format, e.g. 12.2133 means hour 12, minute 21,
7084second 33.  Gri doesn't read HMS format, but gawk can be told to:
7085
7086@cindex geography, converting hour-minute-second to decimal hour
7087@cindex maps, converting hour-minute-second to decimal hour
7088@cindex conversion, hour-minute-second to decimal hour
7089@cindex hms format
7090@cindex hour, minute, second data
7091@cindex gawk, using to convert files from HMS to decimal
7092
7093@example
7094open "cat datafile.HMS |        \
7095    awk '@{                      \
7096    split($1, hms, \".\");      \
7097    h = hms[1];                 \
7098    m = int(hms[2] / 100);      \
7099    s = hms[2] - 100 * m;       \
7100    x = h + m / 60 + s / 3600;  \
7101    split($2, hms, \".\");      \
7102    h = hms[1];                 \
7103    m = int(hms[2] / 100);      \
7104    s = hms[2] - 100 * m;       \
7105    y = h + m / 60 + s / 3600;  \
7106    print(x,y)                  \
7107    @}' | "
7108    read columns x y
7109@end example
7110
7111@item
7112@strong{Timeseries data} are often stored in formats that blend letters
7113and numbers.  For one thing, using letters (e.g. @code{aug}) removes an
7114ambiguity in numerically-based data.  (Example: 02/03/2000 means one
7115thing to an American and another thing in the rest of the world.
7116However, everybody agrees on what 2000-Feb-03 means.)  Suppose, for
7117example, that we have data in a format such as
7118
7119@example
7120Tue_Jul_25_11:07:51 0.62
7121Tue_Jul_25_11:22:51 0.59
7122Tue_Jul_25_11:37:51 0.56
7123@end example
7124
7125@noindent
7126(stored in a file called @file{foo.dat} say) and we want a graph of the
7127y-variable (0.62, 0.59, 0.56) versus x-variable, time expressed say as
7128seconds in the day.  Then here is how that could be done:
7129
7130@example
7131open "cat foo.dat |\
7132    sed -e 's/_/ /g' -e 's/:/ /g' |\
7133    awk '@{print ($4*3600+$5*60+$6, $7)@}' |"
7134read columns x y
7135draw curve
7136@end example
7137
7138Note that the actual day information is skipped in this example;
7139seasoned @code{awk} users could easily fill in the code to handle
7140datasets spanning several days.
7141@end enumerate
7142
7143@node   Opening URLs, Postscript, Opening Pipes, Open
7144@comment  node-name,  next,  previous,  up
7145@subsubsection Opening URLs
7146@cindex URL, how to open
7147
7148Gri can open a URL, @emph{if} you have the @code{wget} program on your
7149machine.  (@code{wget} is available from the GNU website
7150@url{http://www.gnu.org/software/wget/}.)
7151
7152The URL must be enclosed in quotes (since otherwise,
7153Gri will interpret the @code{//} sequence as indicating an old way
7154of denoting comments).  For example,
7155@example
7156open "http://gri.sourceforge.net/gridoc/examples/example1.dat"
7157read columns x y
7158show columns
7159@end example
7160
7161If you don't have @code{wget} installed on your machine, the above won't
7162work, but you can always use another fetching program, with a system
7163call, as in the following:
7164@example
7165\url = "http://gri.sourceforge.net/gridoc/html/examples/example1.dat"
7166open "lynx -dump \url |"
7167read columns x y
7168draw curve
7169@end example
7170
7171
7172
7173
7174@c HTML <!-- newfile PostScript.html "Gri: `postscript' command" "Gri Commands" -->
7175
7176@node   Postscript, Pwd, Opening URLs, List Of Gri Commands
7177@comment  node-name,  next,  previous,  up
7178@subsection @code{postscript}
7179@cindex write PostScript commands directly to output file
7180@cindex postscript file, write to
7181@findex postscript
7182@cindex @code{postscript} command
7183
7184@example
7185`postscript \string'
7186@end example
7187
7188@noindent
7189Write the indicated string to the PostScript output file, after
7190substitution of synonyms if there are any.  Example:
7191
7192@example
7193\a = "45"  # angle
7194\w = "8.5" # page width
7195postscript gsave \w 72 mul 0 translate \a rotate
7196# ... other code to do stuff
7197postscript grestore
7198@end example
7199
7200Here is how to draw an image palette vertically instead of horizontally:
7201
7202@example
7203\X = "3"	# cm
7204\Y = "10"	# cm
7205\a = "90"       # degrees counterclockwise
7206postscript gsave \X 28.35 mul \Y 28.35 mul translate \a rotate
7207# Palette is at user's origin
7208draw image palette box 0 0 10 1
7209postscript grestore
7210@end example
7211
7212NOTE: the @code{postscript} command is @strong{very} dangerous, and should
7213normally only be used by developers.  Most of the code concerning this
7214is in the file @file{doline.cc}; look for the string
7215@code{postscriptCmd} to find the relevant code.
7216
7217
7218@c HTML <!-- newfile Pwd.html "Gri: `pwd' command" "Gri Commands" -->
7219
7220@node   Pwd, Query, Postscript, List Of Gri Commands
7221@comment  node-name,  next,  previous,  up
7222@subsection @code{pwd}
7223@cindex directory, how to find out
7224@findex pwd
7225@cindex @code{pwd} command
7226
7227@example
7228`pwd'
7229@end example
7230
7231@noindent
7232Print current directory (which can be set by @code{cd}).
7233
7234
7235
7236@c HTML <!-- newfile Query.html "Gri: `query' command" "Gri Commands" -->
7237
7238@node   Query, Quit, Pwd, List Of Gri Commands
7239@comment  node-name,  next,  previous,  up
7240@subsection @code{query}
7241@findex query
7242@cindex @code{query} command
7243@cindex user interaction, @code{query} command
7244@cindex interaction with user, @code{query} command
7245
7246@example
7247`query \synonym|.variable. \
7248  ["\prompt" ["\default"|.default.]]'
7249@end example
7250
7251@noindent
7252Ask the user for the value of a variable (number) or synonym (text
7253string).  Gri recognizes the type of the item being asked for, either a
7254variable or synonym, by the presence of a dot or backslash in the second
7255word of the command line.  If a prompt string is given (in quotes), then
7256this string is shown to the user.  If a default is given (in
7257parentheses), then it will be displayed also, and if the user types
7258carriage-return, then that item will be assigned to the variable or
7259synonym.  If the default has more than one item, then Gri considers this
7260a restrictive list of possibilities, and will demand that the answer be
7261in that list, going into an infinite query loop until an item from the
7262list (or carriage-return, meaning take first item) is found.  The items
7263in the list are to be separated by spaces, not commas or any other
7264non-whitespace characters.
7265
7266NOTE: The @code{-y} command-line option bypasses all query commands,
7267fooling Gri into thinking that the user typed a carriage-return to all
7268questions.  Thus the defaults, if they exist, are selected.
7269
7270
7271@c HTML <!-- newfile Quit.html "Gri: `quit' command" "Gri Commands" -->
7272
7273@node   Quit, Read, Query, List Of Gri Commands
7274@comment  node-name,  next,  previous,  up
7275@subsection @code{quit}
7276@cindex quiting Gri
7277@cindex stopping Gri
7278@findex quit
7279@cindex @code{quit} command
7280
7281@example
7282`quit [.exit_status.]'
7283@end example
7284
7285@noindent
7286Exits the gri program.  If an exit status (@code{.exit_status.}) is
7287specified, then Gri returns this value, rounded to the nearest integer,
7288as the ``exit status'' (a concept meaningful mostly in the unix
7289environment, where it designates an error).
7290
7291
7292@c HTML <!-- newfile Read.html "Gri: Read commands" "Gri Commands" -->
7293
7294@node   Read, Read Colornames, Quit, List Of Gri Commands
7295@comment  node-name,  next,  previous,  up
7296@subsection The @code{read} commands
7297
7298There are several varieties of @code{read} command.  Those commands used
7299for reading numerical information (e.g. @code{read columns}) are able to
7300decode variables and synonyms as well as simple numbers.
7301
7302@menu
7303* Read Colornames::             Read colornames
7304* Read Columns::                Read (x,y,...) columnar data
7305* Read Grid::                   Read grid for contouring
7306* Read Image Colorscale::       Read colormap for color image
7307* Read Image Grayscale::        Read colormap for gray image
7308* Read Image Mask::             Read mask for image
7309* Read Image::                  Read image
7310* Read From::                   Change which open file looked at
7311* Read Synonym or Variable::    Read individual synonym or variable
7312* Read Line::                   Read whole line
7313@end menu
7314
7315
7316@node   Read Colornames, Read Columns, Read, Read
7317@comment  node-name,  next,  previous,  up
7318@subsubsection @code{read colornames}
7319@findex read colornames
7320@cindex @code{read} command
7321@cindex @code{read colornames} command
7322@cindex colors, reading from X11 database
7323@cindex X11 colors, reading
7324
7325@example
7326`read colornames from RGB ["\filename"]'
7327@end example
7328
7329@noindent
7330With no filename given, reads an X11-format @code{rgb.txt} file that
7331is provided with gri.  Otherwise, reads the named file and tries to
7332interpret it as an X11 file.  The file format has 4 or more columns,
7333the first three giving the red, green and blue values in the range 0
7334to 255, and the last columns giving the colorname (which may have more
7335than one word). Once you have read in a colorname table, the named
7336colors may be used as builtin colors (@ref{Set Color}).  To view the
7337names and RGB values of the colors Gri knows, including builtin ones
7338and ones from @code{read colornames}, use @code{show colornames}.
7339
7340This command is akin to @code{set colorname} (@ref{Set Colorname}),
7341except that the latter uses the Gri notation of color constituents being
7342in the range from 0 to 1, whereas for @code{read colornames} uses an
7343X11 database, so that the color constitutents range from 0 to 255.
7344
7345
7346@node   Read Columns, Read Grid, Read Colornames, Read
7347@comment  node-name,  next,  previous,  up
7348@subsubsection @code{read columns}
7349@findex read columns
7350@cindex @code{read columns} command
7351
7352@example
7353`read columns ...'
7354@end example
7355
7356Read numbers into columns.  These columns have predefined
7357meanings and names.  For example, @code{read columns x y} instructs Gri
7358to read data into columns called @code{x} and @code{y}; it is these data
7359that Gri will use if you tell it to @code{draw curve}.  Other columns
7360are: @code{z}, used for contouring a function @code{z=z(x,y)};
7361@code{weight}, used for weighting data points; @code{u} and @code{v},
7362used for arrow (vector) plots.
7363
7364If the keyword @code{appending} is given as the last word on the
7365@code{read columns} line, then the new data will be appended to any
7366existing columnar data; otherwise they will overwrite any existing data.
7367
7368As a special case, if the @code{x} column is not indicated
7369(e.g. @code{read columns y}) then Gri creates x-values automatically, in
7370the sequence 0, 1, 2, etc.
7371
7372@itemize @bullet
7373
7374@item @code{read columns x y}
7375Read @code{x} in column 1, @code{y} in column 2 until blank-line found.
7376Only the first two numbers on each line will be read; any extra numbers
7377(or words) on the line will be ignored.
7378
7379@item @code{read columns * y * * x}
7380Read @code{x} in column 5, @code{y} in column 2.  The @code{*} character
7381is a spacer.  It instructs Gri to skip the first, third, and fourth
7382words on the data line.  These words need not be numbers.  This example
7383illustrates a general mechanism of using the @code{*} character to skip
7384over unwanted items in the data file.  Note that there is no need to
7385supply @code{*} characters for trailing extraneous words; Gri will skip
7386them anywary.  Finally, note that any order of @code{x} and @code{y}
7387(and the other columns; see below) is allowed.
7388
7389@item @code{read columns y=2 x=5} or @code{read columns x=5 y=2}
7390As above; read @code{x} in column 5 and @code{y} in column 2.  The
7391column number may be specified in this manner for all the named column
7392variables.  No spaces are allowed before or after the @code{=} sign.
7393The first column is called column 1.  Whether this format is used or the
7394@code{*} format is a matter of choice, except that numbered format also
7395permits using a given number to fill several variables (for example
7396@code{read columns x=1 y=2 u=1 v=2}).
7397
7398@cindex netCDF files, reading columns
7399
7400@item @code{read columns x="netCDF_name" ...}
7401If the file is a @code{netCDF} file, opened
7402by e.g. @code{open myfile.nc netCDF}, then the @code{netCDF} variables
7403for the columns, e.g.
7404
7405@example
7406open latlon.nc netCDF
7407read columns x="longitude" y="latitude"
7408@end example
7409
7410@noindent
7411Note: the data @strong{must} be stored as the @code{netCDF} ``float''
7412type.
7413
7414For more information on netCDF format, see
7415
7416@code{http://www.unidata.ucar.edu/packages/netcdf/index.html}
7417@c HTML <a href="http://www.unidata.ucar.edu/packages/netcdf/index.html">
7418@c HTML here </a>.
7419
7420@item @code{read columns * y z * x}
7421Read @code{x} in column 5, @code{y} in column 2, and @code{z} in column
74223.  The @code{z} column is used for contouring.
7423
7424@item @code{read columns x y u v}
7425@cindex direction field, how to read
7426@cindex vector field, how to read
7427@cindex arrows, how to read direction field
7428Read @code{x} and @code{y} in first two columns, and the ``arrow'' data
7429@code{u} and @code{v} as third and fourth columns.
7430
7431@item @code{read columns .rows. x y}
7432Read @code{.rows.} rows of column data.
7433@end itemize
7434
7435@cindex column data, x in one file and y in another
7436
7437Sometimes you'll have @code{x} in one file and @code{y} in another.  In
7438that case, use the operating system or an editor to put the columns in
7439one file.  In unix, the easy way is
7440
7441@example
7442open "paste file_with_x file_with_y |"
7443read columns x y
7444@end example
7445
7446
7447NOTE FOR BINARY FILES: For ascii files, Gri will proceed to a new line
7448after it has read the items requested; it skips any words appearing on
7449the data line after the last object of interest.  Thus
7450@code{read columns x y} will read the first two columns and ignore any other
7451columns that might be present.  But for binary files, Gri has no way of
7452knowing how to "skip" to the next line (see @code{skip} command), so you
7453will have to flesh out the @code{read columns} command with as many
7454spacers as are present in your data.  For example, if you have four
7455numbers in each data record and want to interpret the first two as
7456@code{x} and @code{y}, you would use @code{read columns x y * *} to read
7457the data.
7458
7459
7460RETURN VALUE:
7461@cindex @code{\.return_value.}, from @code{read columns}
7462Sets @code{\.return_value} to
7463@code{N rows N non-missing N inside-clip-region}
7464
7465
7466@node   Read Grid, Read Image Colorscale, Read Columns, Read
7467@comment  node-name,  next,  previous,  up
7468@subsubsection @code{read grid}
7469@findex read grid
7470@cindex reading grid data
7471@cindex grid, reading
7472@cindex @code{read grid} command
7473
7474@code{read grid} commands read grid characteristics.  (The ``grid'' is
7475the object that is contoured.)
7476
7477For normal ascii or binary files, the commands to read the grid's
7478x-locations, y-locations and data are:
7479
7480@example
7481`read grid x [.rows.]'
7482`read grid y [.rows.]'
7483`read grid data [spacers] \
7484  [.rows. .cols.] [spacers] [bycolumns]'
7485@end example
7486
7487@cindex netCDF files, reading grid data
7488For @code{netCDF} files, the commands are as follows (note that it is
7489not possible to specify the number of data to read, nor to read the grid
7490by columns).
7491
7492@example
7493`read grid x = "variable_name"'
7494`read grid y = "variable_name"'
7495`read grid data = "variable_name"'
7496@end example
7497
7498@noindent
7499The ordering of the y-grid data is the same as if they were read from a
7500normal file: the first number is considered to be at the top of the
7501plot.
7502
7503For more information on netCDF format, see
7504
7505@code{http://www.unidata.ucar.edu/packages/netcdf/index.html}
7506@c HTML <a href="http://www.unidata.ucar.edu/packages/netcdf/index.html">
7507@c HTML here </a>.
7508
7509
7510Details of the non-netCDF commands:
7511@itemize @bullet
7512
7513@item @code{read grid x [.cols.]}
7514Read the @code{x} locations of the grid points, one number per line.
7515If @code{.cols.} is supplied, then that many values will be read;
7516otherwise, reading will stop at end-of-file or blank-line.
7517
7518@item @code{read grid y [.rows.]}
7519As above, but for y grid;  @code{.rows.} is the number of rows.  The
7520first number to be read corresponds to the location of the @strong{top}
7521edge of the grid.  Thus, if you were to view the column of numbers with
7522a text editor, they would be oriented the same way as the corresponding
7523elements will appear on the page.
7524
7525@item @code{read grid data [.rows. .cols.]}
7526Read data for a grid having @code{.rows.} and @code{.cols.} columns.
7527(If @code{.rows.} and @code{.cols.} are not supplied, but the grid
7528already exists, then those pre-existing values are used.  If they are
7529specified here, then they are checked for consistency with the
7530pre-existing values if they exist.) Gri will read @code{.rows.} lines,
7531each containing @code{.cols.} numbers.  (Extra information in the file
7532can be skipped; see discussion of the @code{*} keyword below.)  Gri
7533will interpret the first line it reads as the grid data corresponding
7534to a value of y equal to @code{y[.rows.]}.  Thus, file should be
7535arranged like this:
7536
7537@example
7538f(x[1], y[.rows.])  ...  f(x[.cols.], y[.rows.])
7539        .
7540        .
7541        .
7542f(x[1], y[3])       ...  f(x[.cols], y[3])
7543f(x[1], y[2])       ...  f(x[.cols], y[2])
7544f(x[1], y[1])       ...  f(x[.cols], y[1])
7545@end example
7546
7547@item @code{read grid data [.rows. .cols.] bycolumns}
7548As above, but the @code{bycolumns} keyword tells Gri to read the data
7549one column at a time, instead of one row at a time.  Each line is
7550expected to contain @code{.rows.} numbers (as opposed to @code{.cols.}
7551numbers, as in the format where the @code{bycolumns} keyword is not
7552present).  (Extra information in the file can be skipped; see
7553discussion of the @code{*} keyword below).  The first line of the data
7554file contains the first column of the gridded data, corresponding to x
7555equal to @code{x[1]}).  The file should look like this:
7556
7557@example
7558f(x[1], y[1])     ...     f(x[1], y[.cols.])
7559f(x[2], y[1])     ...     f(x[2], y[.cols.])
7560f(x[3], y[1])     ...     f(x[3], y[.cols.])
7561        .
7562        .
7563        .
7564f(x[.rows.],y[1]) ...  f(x[.rows.], y[.cols.])
7565@end example
7566
7567@item @code{read grid data * * [.rows. .cols.]}
7568As @code{read grid data .rows. .cols.} except that the first two words
7569on each line are skipped.  As usual, trailing extraneous numbers are
7570also skipped.
7571@end itemize
7572
7573@strong{See also} @code{set x grid}, @code{set y grid}
7574
7575
7576@noindent
7577RETURN VALUE:
7578@cindex @code{\.return_value.}, from @code{read grid ...}
7579
7580@code{read grid x} sets @code{\.return_value} to @code{N cols}
7581
7582@code{read grid y} sets @code{\.return_value} to @code{N rows}
7583
7584@code{read grid data} sets @code{\.return_value} to @code{N rows N cols}
7585
7586
7587@node   Read Image Colorscale, Read Image Grayscale, Read Grid, Read
7588@comment  node-name,  next,  previous,  up
7589@subsubsection @code{read image colorscale}
7590@findex read image colorscale
7591@cindex @code{read image colorscale} command
7592@cindex image colorscale, reading
7593@cindex colorscale of image, reading from file
7594
7595@example
7596`read image colorscale [rgb|hsb]'
7597@end example
7598
7599@noindent
7600Read colorscale for image, from 256 lines each containing values for
7601Red, Green, and Blue (or Hue, Saturation and Brightness), separated by
7602whitespace.  The values are expected to be in the range 0 to 1, and are
7603clipped to these limits if not.
7604
7605For hints on how to create such an input file,
7606@ref{Read Image Grayscale}.  If the example given there has the
7607following code instead,
7608
7609@example
7610open "awk 'BEGIN @{               \
7611     for(i=0;i<256;i++) @{        \
7612       print((i - 50)/50, 1, 1)  \
7613     @}                           \
7614   @}' |"
7615read image colorscale hsb
7616@end example
7617
7618@noindent
7619then a linear full-color spectrum running from red at 10C to magenta at
762015C is achieved.
7621
7622
7623@node   Read Image Grayscale, Read Image Mask, Read Image Colorscale, Read
7624@comment  node-name,  next,  previous,  up
7625@subsubsection @code{read image grayscale}
7626@findex read image grayscale
7627@cindex @code{read image grayscale} command
7628@cindex @code{read image greyscale} command
7629@cindex image grayscale, reading
7630@cindex grayscale of image, reading from file
7631
7632@example
7633`read image grayscale'
7634@end example
7635
7636@noindent
7637Read grayscale for an image, from 256 lines each containing a
7638single value.  The values are expected to be in the range 0 to 1, and
7639are clipped to these limits if not.  For 8-bit images, Gri multiplies
7640these values by 255, and uses this list for the grayscale mapping.  Such
7641a list is created by @code{write image grayscale}.
7642
7643As an example, consider the code fragment (@ref{Images}).
7644
7645@example
7646set image range 5 30.5
7647set image grayscale black 10 white 15
7648@end example
7649
7650@noindent
7651is equivalent to
7652
7653@example
7654set image range 5 30.5
7655open "awk 'BEGIN @{\
7656  for(i=0;i<256;i++) @{\
7657    print(1-(i-50)/50)\
7658  @} \
7659@}' |"
7660read image grayscale
7661close
7662@end example
7663
7664@noindent
7665because the image formula is
7666@quotation
7667Temperature = 5C + 0.1C * pixelvalue
7668@end quotation
7669@noindent
7670where the pixelvalue ranges from 0 to 255.  Therefore, a temperature of
767110C is a pixelvalue of 50, and 15C is 100.  To get a grayscale ranging
7672between these values, therefore, we create a linear function which maps
7673the 50th pixelvalue into grayvalue 1, and the 100th pixelvalue into
7674grayvalue 0.  That is what the awk line does; to see the actual numbers,
7675you could insert the line @code{write image grayscale to TMP} and look at
7676the file @file{TMP} (bear in mind that Gri will clip the values to the
7677range 0 to 1).
7678
7679Sometimes you will have a file, say named @file{map.dat}, with RGB
7680numbers in the range 0-255, rather than 0-1 as Gri requires.  To read
7681them, use the operating system to convert the numbers for you
7682(@ref{Open}).
7683
7684@example
7685open "cat map.dat \
7686  | awk '@{print(($1+$2+$3)/3/255)@}' |"
7687read image grayscale
7688close
7689@end example
7690
7691
7692@node   Read Image Mask, Read Image, Read Image Grayscale, Read
7693@comment  node-name,  next,  previous,  up
7694@subsubsection @code{read image mask}
7695@findex read image mask
7696@cindex @code{read image mask} command
7697@cindex mask for image, reading
7698@cindex image mask, reading
7699
7700@example
7701`read image mask rasterfile|@{.rows. .cols.@}'
7702@end example
7703
7704@noindent
7705Read image mask.  The mask is associated with the image read in by the
7706@code{read image} command in the following way.  When computing image
7707histograms, Gri ignores any pixels in the image for which the
7708corresponding pixel in the mask is set to @code{1}.
7709
7710@itemize @bullet
7711
7712@item @code{read image mask rasterfile}
7713The image size is specified in the rasterfile file itself, so
7714it is not specified.
7715
7716@item @code{read image mask .rows. .cols.}
7717The file must contain @code{.rows.*.cols.} binary data.  Pixel
7718order is the same as for images.
7719@end itemize
7720
7721
7722@node   Read Image, Read From, Read Image Mask, Read
7723@comment  node-name,  next,  previous,  up
7724@subsubsection @code{read image}
7725@findex read image
7726@cindex @code{read image} command
7727@cindex images, reading
7728@noindent
7729There are several types of @code{read image} commands, depending on the
7730file format.  If the file is "raw", with no embedded information about
7731things like the width and height, then we need to specify everything, as
7732in the first format given below.  The other formats make use of the
7733header information in, e.g. PGM files.
7734
7735@strong{Headerless images}
7736
7737@example
7738`read image .rows. .cols. \
7739  [box .xleft. .ybottom. .xright. .ytop.] \
7740  [bycolumns]'
7741@end example
7742
7743@noindent
7744With no options specified (@code{read image .rows. .cols.}), read binary
7745data defining an @code{image}.  The image range must have previously
7746have been set by @code{set image range}.  The data are as written by
7747"unsigned char" format in C.
7748
7749When the @code{box} option is specified, the geometry of the image, in
7750user coordinates, is specified in terms of the cartesian coordinates of
7751the lower-left corner (@code{.xleft.}, @code{.ybottom.}) and upper-right
7752corner (@code{.xright.}, @code{.ytop.}).  If the @code{box} option is not
7753specified, this geometry can be specified with either @code{read x grid}
7754or @code{set x grid}, plus either @code{read y grid} or
7755@code{set y grid}.
7756
7757With the @code{bycolumns} keyword present, the image is read sweeping
7758from top-to-bottom, then left-to-right, instead of the usual order.
7759
7760
7761@strong{Sun rasterfile images}
7762
7763@example
7764`read image rasterfile [box .xleft. .ybottom. .xright. .ytop.]'
7765@end example
7766
7767@noindent
7768Read image in Sun rasterfile format.  Image geometry is inferred from
7769the header, so @code{.rows.} and @code{.cols} parameters are not given.
7770
7771@strong{PGM images}
7772
7773@example
7774`read image pgm [box .xleft. .ybottom. .xright. .ytop.]'
7775@end example
7776
7777@noindent
7778Read image in PGM (Portable Gray Map) format.  Image geometry is
7779inferred from the header, so @code{.rows.} and @code{.cols} parameters
7780are not given.  Both ascii and binary PGM formats are supported (that
7781is, files with magic characters of P2 and P5).
7782
7783@strong{NOTE} that there are many image formats and Gri doesn't try to
7784deal with them all.  The idea is to use another program to convert
7785images to a file format that Gri understands.  In the future Gri may
7786support PNG and other popular formats, especially in the Linux versions,
7787for which libraries exist to ease the input.
7788
7789
7790
7791@node   Read From, Read Synonym or Variable, Read Image, Read
7792@comment  node-name,  next,  previous,  up
7793@subsubsection @code{read from \filename}
7794@findex read from
7795@cindex @code{read from} command
7796@cindex file, selecting between open files
7797
7798@example
7799`read from \filename'
7800@end example
7801
7802@noindent
7803Cause future @code{read} commands to read from the indicated file.  If
7804that file is not open, an error message will result.  Use
7805@code{read from \filename} to shuffle reading among several open files.
7806
7807Gri can look up filenames for @code{read from} in terms of their
7808@b{full} pathnames or their @b{local} pathnames.  Thus, a local file
7809called @code{a.dat} in the directory @code{/home/gri} can be referred to
7810by @code{read from a.dat} or by @code{read from /home/gri/a.dat}, which
7811comes in handy if you need to work with two files of the same name, in
7812other directories.  However, since Gri has the ability to search for
7813files in a "path" (@ref{Set Path To}), you may not have specified an
7814exact path name; this is why the @code{open} command provides a return
7815value which names the full pathname (@ref{Opening Simple Files}).
7816
7817
7818@node   Read Synonym or Variable, Read Line, Read From, Read
7819@comment  node-name,  next,  previous,  up
7820@subsubsection @code{read} synonym/variable
7821@findex read
7822@cindex @code{read ...} command
7823@cindex variables, reading
7824@cindex synonyms, reading
7825@cindex reading variables
7826@cindex reading synonyms
7827
7828@example
7829`read [* [*...]] \synonym|.variable. [\synonym|.variable. [...]]@}'
7830@end example
7831
7832@noindent
7833Read one or more items from the next line of the input file.  These
7834items may be synonyms or variables.  The token @code{*} indicates
7835that the word in the datafile should be skipped.  As usual, the datafile
7836may be embedded in the commandfile, providing the last data line is blank.
7837
7838Normally one would use synonyms for words, and variables for numbers.
7839The items are separated by one or more "whitespace" characters
7840(e.g. space or TAB).  Thus, if a file contained the line
7841
7842@example
7843Temperature 10.3
7844@end example
7845
7846@noindent
7847then the line
7848
7849@example
7850read \var_name .var_value.
7851@end example
7852
7853@noindent
7854would have the same result as
7855
7856@example
7857\var_name = "Temperature"
7858.var_value. = 10.3
7859@end example
7860
7861This command ignores any trailing items on the line.  That is, the next
7862@code{read} command will start on the next line of the file.  In a
7863sense then, you get just one shot at analysing the input line in your
7864datafile.  If you need flexibility, you may wish to read the
7865@strong{whole} contents of the line into a synonym, which may be done
7866using the @code{read line} command instead, to read it in as a string.
7867(@ref{Read Line}).
7868
7869@cindex reading attributes in NetCDF files
7870@cindex netCDF files, reading attributes, units, etc
7871
7872If the input file is in the netCDF format, the
7873indicated item will be read.  For example,
7874@code{read \time:_MissingValue} reads the missing value for the variable
7875called @code{time}.  This conveniently allows your data file to dictate
7876axes names, units, missing values, etc.  Example:
7877
7878@example
7879# Plot profile of TU81N (age-corrected tritium)
7880open profile.nc netCDF
7881read columns x="TU81N" y="z"
7882read \@{z:_FillValue@}		# assume same for all
7883read \@{z:long_name@}
7884read \@{z:units@}
7885read \@{TU81N:long_name@}
7886read \@{TU81N:units@}
7887close
7888set missing value \@{z:_FillValue@}
7889set x name "\@{TU81N:long_name@} (\@{TU81N:units)@}"
7890set y name "\@{z:long_name@} (\@{z:units)@}"
7891set y axis decreasing
7892draw curve
7893@end example
7894
7895For more information on netCDF format, see
7896@code{http://www.unidata.ucar.edu/packages/netcdf/index.html}
7897@c HTML <a href="http://www.unidata.ucar.edu/packages/netcdf/index.html">
7898@c HTML here </a>.
7899
7900
7901
7902@node   Read Line, Regress, Read Synonym or Variable, Read
7903@comment  node-name,  next,  previous,  up
7904@subsubsection @code{read line}
7905@findex read line
7906@cindex @code{read line raw} command
7907@cindex @code{read line} command
7908@cindex lines in data files, parsing
7909@cindex parsing headers in data files
7910@cindex variables, reading
7911@cindex synonyms, reading
7912@cindex reading variables
7913@cindex reading synonyms
7914
7915@example
7916`read line \synonym'
7917@end example
7918
7919@noindent
7920Read the next line of the datafile (or commandfile), trim off a trailing
7921comment if there is one, and then store the next line of datafile into
7922the named synonym.
7923
7924@c HTML <!-- newfile Regress.html "Gri: `regress' command" "Gri Commands" -->
7925
7926@node   Regress, Reorder, Read Line, List Of Gri Commands
7927@comment  node-name,  next,  previous,  up
7928@subsection @code{regress}
7929@cindex statistics, performing regression
7930@cindex linear regression
7931@cindex regression, linear
7932@findex regress
7933@cindex @code{regress} command
7934
7935@example
7936`regress @{y vs x [linear]@}|@{x vs y [linear]@}'
7937@end example
7938
7939@noindent
7940Perform linear regression of @code{y} as a function of @code{x} or @code{x} as
7941a function of @code{y}.
7942
7943@itemize @bullet
7944
7945@item @code{regress y vs x}
7946Linear regression of y vs x.  Several quantities are reported and also
7947saved into builtin variables.  The intercept is defined as
7948@code{..coeff0..}, its 95 percent confidence limit is defined as
7949@code{..coeff0_sig..}.  Thus the confidence range is
7950@code{..coeff0..-..coeff0_sig..} to @code{..coeff0..+..coeff0_sig..}.
7951Similarly the slope and confidence limit are stored in @code{..coeff1..}
7952and @code{..coeff1_sig..}
7953
7954The squared correlation coefficient is stored in @code{..R2..}.
7955
7956@strong{Historical note} prior to version 2.1.15, a different meaning was
7957attached to @code{..coeff0_sig..} and @code{..coeff1_sig..}; they used
7958be defined as standard errors, without having been multiplied by the
7959appropriate student-t coefficient.
7960
7961@item @code{regress x vs y}
7962Linear regression of x vs y; for notation see above.
7963
7964@item @code{regress y vs x linear}
7965Linear regression of y vs x; for notation see above.
7966
7967@item @code{regress x vs y linear}
7968Linear regression of x vs y; for notation see above.
7969@end itemize
7970@noindent
7971
7972@c HTML <!-- newfile Reorder.html "Gri: `reorder' command" "Gri Commands" -->
7973
7974@node   Reorder, Rescale, Regress, List Of Gri Commands
7975@comment  node-name,  next,  previous,  up
7976@subsection @code{reorder}
7977@cindex columns, reordering
7978@cindex reordering Columns
7979@findex reorder
7980@cindex @code{reorder} command
7981
7982@example
7983`reorder columns randomly \
7984  |@{ascending in x|y|z@} \
7985  |@{descending in x|y|z@}'
7986@end example
7987
7988@noindent
7989Reorder the columns in various ways.
7990
7991In the @code{randomly} style, the column data are shuffled randomly by
7992index, retaining the correspondance between a given x and y.  This is
7993useful with @code{draw symbol} using colored dots -- it prevents the
7994overpainting of one dot on another from biasing the color field to
7995values that happened to occur near the end of the column data.  If you
7996prefer the overpainting to be done in random order, use this command to
7997reorder the columns randomly.  The random number is selected using the
7998system @code{rand} call, with the seed being provided by the PID
7999(process ID) of the job.
8000
8001The @code{ascending} and @code{descending} styles do what you'd expect.
8002
8003
8004
8005@c HTML <!-- newfile Rescale.html "Gri: `rescale' command" "Gri Commands" -->
8006
8007@node   Rescale, Resize, Reorder, List Of Gri Commands
8008@comment  node-name,  next,  previous,  up
8009@subsection @code{rescale}
8010@cindex axes, forcing rescaling
8011@cindex rescaling axes
8012@cindex math on columns, rescaling after
8013@findex rescale
8014@cindex @code{rescale} command
8015
8016@example
8017`rescale'
8018@end example
8019
8020@noindent
8021Re-determine the scales for the x and y axes.  Typically used after a
8022column math operation, when you want the new data to be auto-scaled.
8023(Note: normally, if the axes have already been drawn, Gri won't rescale
8024automatically just because you modify the column data.  This is designed
8025so that you can add offsets to curves, etc, while staying in saved axes.
8026But if the axes have not been drawn yet when you modify the column data,
8027then Gri will automatically rescale the axes it is planning to draw.)
8028
8029
8030
8031@c HTML <!-- newfile Resize.html "Gri: `resize' command" "Gri Commands" -->
8032
8033@node   Resize, Return, Rescale, List Of Gri Commands
8034@comment  node-name,  next,  previous,  up
8035@subsection @code{resize}
8036@cindex maps, scales
8037@findex resize x
8038@cindex @code{resize x} command
8039
8040@example
8041`resize @{x for maps@}|@{y for maps@}'
8042@end example
8043
8044@noindent
8045Resize the axes frame region in such a way that geographical objects
8046appear in correct proportions.  This assumes that y is degrees latitude
8047and x is degrees longitude.
8048
8049@itemize @bullet
8050
8051@item @code{resize x for maps}
8052Resize the plot width for maps, assuming that x represents longitude and
8053y represents latitude.  Before using this, you must have defined scales
8054for both x and y, and a size for y (ie, you must have done
8055@code{set x axis ...}, @code{set y axis ...} and @code{set y size});
8056this command
8057sets the x size, thus eliminating @code{set x size.} The result is that,
8058at the central latitude (y), a centimetre on the page will correspond to
8059an equal distance on the earth, in both the north-south and east-west
8060directions.
8061
8062@item @code{resize y for maps}
8063Resize the plot height for maps, assuming that x represents longitude
8064and y represents latitude.  Before using this, you must have defined
8065scales for both x and y, and a size for x (ie, you must have done
8066@code{set x axis ...}, @code{set y axis ...} and @code{set x size});
8067this command sets the y size, thus eliminating @code{set y size.} The
8068result is that, at the central latitude (y), a centimetre on the page
8069will correspond to an equal distance on the earth, in both the
8070north-south and east-west directions.
8071
8072@strong{See also} @code{resize x for maps}.
8073@end itemize
8074
8075
8076@c HTML <!-- newfile Return.html "Gri: `return' command" "Gri Commands" -->
8077
8078@node   Return, Rewind, Resize, List Of Gri Commands
8079@comment  node-name,  next,  previous,  up
8080@subsection @code{return}
8081@findex return
8082@cindex @code{return} command
8083
8084@example
8085`return'
8086@end example
8087
8088@noindent
8089Return early from a user-defined function or an @code{insert} file.  Or,
8090in the main gri program, do the same thing as @code{quit}.
8091
8092
8093@c HTML <!-- newfile Rewind.html "Gri: `rewind' command" "Gri Commands" -->
8094
8095@node   Rewind, Rpnfunction, Return, List Of Gri Commands
8096@comment  node-name,  next,  previous,  up
8097@subsection @code{rewind}
8098@findex rewind
8099@cindex @code{rewind} command
8100
8101@example
8102`rewind \filename'
8103@end example
8104
8105@noindent
8106Rewind a data-file to the beginning.  If no filename is given, this is
8107done for the currently active file; otherwise the named file is rewound.
8108
8109
8110@c HTML <!-- newfile Rpnfunction.html "Gri: `rpnfunction' command" "Gri Commands" -->
8111
8112@node  Rpnfunction, Set, Rewind, List Of Gri Commands
8113@comment  node-name,  next,  previous,  up
8114@subsection @code{rpnfunction}
8115@cindex rpn functions
8116@cindex defining rpn functions
8117@cindex functions in rpn expressions
8118@findex rpnfunction
8119@cindex @code{rpnfunction} command
8120
8121@example
8122`rpnfunction name replacement-words'
8123@end example
8124
8125@noindent
8126Create a new keyword for use in rpn expressions.  Inside any RPN
8127expression which follows this line, the word @code{name} will be
8128substituted with the indicated replacement words.
8129
8130For example,
8131the following shows the definition and use of a function which computes
8132the sine of twice an angle, by multiplying whatever is on the stack by
8133@code{2}, and then taking the sine of the result.
8134
8135@example
8136rpnfunction sin2 2 * sin
8137show "expect the number 1 to follow: " @{rpn 45 sin2@}
8138@end example
8139
8140The replacement words will have any synonyms in them translated first,
8141unless they start with an underscore followed by a double backslash.
8142Similarly, variables are substituted unless they start with an
8143underscore.  These exceptions are to allow the use of the @code{defined}
8144operator (@ref{rpn Mathematics}).
8145
8146Note: The mathematical constants @code{e} and @code{pi} are stored using
8147@code{rpnfunctions}.  Also, two @code{rpnfunctions} are provided for
8148finding the slope and intercept of a line joining two points, e.g.
8149@cindex linear interpolation
8150@cindex @code{linear_slope} rpn operator
8151@cindex @code{linear_intercept} rpn operator
8152@cindex rpn operator @code{linear_slope}
8153@cindex rpn operator @code{linear_intercept}
8154
8155@example
8156# Expect answers 1 and 10 ...
8157show "slope=" @{rpn 0 1 1 11 linear_slope@}
8158show "inter=" @{rpn 0 1 1 11 linear_intercept@}
8159@end example
8160
8161These are useful in @code{set grid missing above .intercept. .slope.}
8162and @code{set z missing above .intercept. .slope.}.
8163
8164
8165@c HTML <!-- newfile Set.html "Gri: Set commands" "Gri Commands" -->
8166
8167@node   Set, Set Axes Style, Rpnfunction, List Of Gri Commands
8168@comment  node-name,  next,  previous,  up
8169@subsection The @code{set} commands
8170@findex set
8171@cindex @code{set} command
8172Set various flags and parameters which Gri will use in later commands.
8173@menu
8174* Set Axes Style::              Set type of axes
8175* Set Arrow Size::              Set size for arrow heads
8176* Set Arrow Type::              Set type of arrow heads
8177* Set Beep::                    Set error beeping on or off
8178* Set Bounding Box::            Set PostScript bounding box
8179* Set Clip::                    Set clipping region
8180* Set Color::                   Set color of pen
8181* Set Colorname::               Create a color name
8182* Set Contour Format::          Set format for numbers on contours
8183* Set Contour Label For::       Set existence of contour labels
8184* Set Contour Label Position::  Set spacing of contour labels
8185* Set Contour Labels::          Control various things about contour lables
8186* Set Dash::                    Set style of dashed lines
8187* Set Environment::             (Developer cmd)
8188* Set Error Action::            Set error behavior
8189* Set Flag::                    Set flag to control Gri (developer cmd)
8190* Set Font Color::              Set color of pen used for text
8191* Set Font Encoding::           Set font encoding vector
8192* Set Font Size::               Set size of text
8193* Set Font To::                 Set font for text
8194* Set Graylevel::               Set graylevel of pen
8195* Set Grid Missing::            Set missing region of grid
8196* Set Ignore Initial Newline::  Set to ignore initial blank line
8197* Set Ignore Error Eof::        Set ability to tolerate EOF on files
8198* Set Image Colorscale::        Set colorscale mapping for image
8199* Set Image Grayscale::         Set grayscale mapping for image
8200* Set Image Missing Value Color::  Set missing value color in image
8201* Set Image Range::             Set range of data that image can hold
8202* Set Input Data Window::       Set data window for reading columns
8203* Set Input Data Separator::    Set separator between data items
8204* Set Line Cap::                Set line end (cap) type
8205* Set Line Join::               Set method for intersections of line segments
8206* Set Line Width::              Set width of lines
8207* Set Missing Value::           Set "missing" value
8208* Set Page Size::               Set page size
8209* Set Page::                    Set page style
8210* Set Panel::                   Establish geometry for a panel of multipanel plot
8211* Set Panels::                  Prepare for multipanel plot
8212* Set Path To::                 Set search-path for data or command files
8213* Set Postscript Filename::     Set name of PostScript file
8214* Set Symbol Size::             Set size of symbols
8215* Set Tic Size::                Set size of tics on axes
8216* Set Trace::                   Set printout of statements as executed
8217* Set Transparency::            Set transparency of the pen
8218* Set U Scale::                 Set scale for u (i.e. x) component of arrows
8219* Set V Scale::                 Set scale for v (i.e. y) component of arrows
8220* Set X Axis::                  Set range of x axis
8221* Set X Format::                Set format for numbers on x axis
8222* Set X Grid::                  Set x mesh of contour grid
8223* Set X Margin::                Set margin to left of x axis
8224* Set X Name::                  Set name of x axis
8225* Set X Size::                  Set length of x axis
8226* Set X Type::                  Set type of x axis (log/linear)
8227* Set Y Axis::                  Set range of y axis
8228* Set Y Format::                Set format for numbers on y axis
8229* Set Y Grid::                  Set y mesh of contour grid
8230* Set Y Margin::                Set margin below y axis
8231* Set Y Name::                  Set name of y axis
8232* Set Y Size::                  Set length of y axis
8233* Set Y Type::                  Set type of y axis (log/linear)
8234* Set Z Missing::               Set missing region of z column
8235@end menu
8236
8237@node   Set Axes Style, Set Arrow Size, Set, Set
8238@comment  node-name,  next,  previous,  up
8239@subsubsection @code{set axes style}
8240@findex set axes style
8241@cindex @code{set axes style} command
8242
8243@example
8244set axes style .style.     \
8245  | @{offset [.dist_cm.]@} \
8246  | rectangular|none|default
8247@end example
8248
8249@noindent
8250Tell Gri how you want the axes to look, when they are drawn later.
8251
8252@itemize @bullet
8253
8254@item @code{set axes style 0}
8255Set axes to be rectangular, with an x-y axis frame labelled at the left
8256and bottom and tic marks on all axes.
8257
8258@item @code{set axes style 1}
8259As style @code{0}, but only put tics on the lower and left axes.
8260
8261@item @code{set axes style 2}
8262As style @code{0} but without labels or tics on any axis,
8263i.e. just an axis frame.
8264
8265@item @code{set axes style offset [.dist_cm.]}
8266Set axes so that the actual x and y axes will be drawn with a space
8267separating them from the data area.  The space, if not set by the
8268@code{.distance_cm.} option, will be equal to the current tic size (see
8269@code{set tic size}).  This command can be used together with any other
8270@code{set axes style} command.  It applies to both the @code{draw axes}
8271command and with any @code{draw x|y axis} command in which the axis
8272location is not explicitly given.
8273
8274@item @code{set axes style rectangular}
8275Set axes to be rectangular, with an x-y axes frame labelled at the left
8276and bottom.
8277
8278@item @code{set axes style none}
8279Tell gri not to bother drawing axes before drawing curves, etc.
8280
8281@item @code{set axes style default}
8282Same as @code{set axes style 0}, and with @code{offset} turned off.
8283@end itemize
8284
8285@node   Set Arrow Size, Set Arrow Type, Set Axes Style, Set
8286@comment  node-name,  next,  previous,  up
8287@subsubsection @code{set arrow size}
8288@findex set arrow size
8289@cindex @code{set arrow size} command
8290@cindex arrows, setting size of heads
8291
8292@example
8293`set arrow size .size.           \
8294  | @{as .num. percent of length@} \
8295  | default'
8296@end example
8297
8298@noindent
8299Set the arrowsize (which is stored in the builtin variable
8300@code{..arrowsize..}).
8301
8302@itemize @bullet
8303
8304@item @code{set arrow size .size.}
8305Set the arrow size (ie, half-width of the arrowhead) to @code{.size.}
8306centimetres.
8307
8308@item @code{set arrow size as .num. percent of length}
8309Set the arrow size to be the indicated percentage of arrow length, as in
8310"HWP" in the singles ads.  (As a flag to this, @code{..arrowsize..} is
8311set to the negative of the fractional size measured in percent.)
8312
8313@item @code{set arrow size default}
8314Set the arrow size to the default of 0.2 cm.
8315@end itemize
8316
8317@node   Set Arrow Type, Set Beep, Set Arrow Size, Set
8318@comment  node-name,  next,  previous,  up
8319@subsubsection @code{set arrow type}
8320@findex set arrow type
8321@cindex @code{set arrow type} command
8322@cindex arrows
8323
8324@example
8325set arrow type .which.
8326@end example
8327
8328Set type of arrow, according to the value of @code{.which.}, rounded to
8329the nearest integer.  A rounded @code{.which.} value of 0 yields the
8330default arrows, drawn with three line strokes.  Value 1 yields outlined
8331arrows, sometimes used on definition sketches.  Value 2 yields filled,
8332swept-back arrow heads.
8333
8334This command uses the ``line join'' parameters that are presently active
8335(@ref{Set Line Join}).  So, by default, the arrow ends are rounded
8336(because the default line-join parameter is 1).  To get pointy ends,
8337first set the line join parameter to 0.
8338
8339
8340
8341@node   Set Beep, Set Bounding Box, Set Arrow Type, Set
8342@comment  node-name,  next,  previous,  up
8343@subsubsection @code{set beep}
8344@findex set beep
8345@cindex @code{set beep} command
8346@cindex errors, beeping
8347@cindex beeping on errors
8348
8349@example
8350`set beep on|off'
8351@end example
8352
8353@noindent
8354The command @code{set beep on} makes gri beep on errors and
8355@code{query}.  @code{set beep off} (the default) turns this beeping off.
8356
8357
8358@node   Set Bounding Box, Set Clip, Set Beep, Set
8359@comment  node-name,  next,  previous,  up
8360@subsubsection @code{set bounding box}
8361@findex set bounding box
8362@cindex @code{set bounding box} command
8363@cindex bounding box, setting
8364
8365@example
8366`set bounding box .xleft. .ybottom. .xright. .ytop. [pt|cm]'
8367@end example
8368
8369@noindent
8370Set the PostScript bounding box for the graph to the indicated values.  The
8371bounding box is used by some programs to determine the region of the
8372page on which marks have been made.  For example, La@TeX{} uses the
8373bounding box to decide how to position figures in documents.
8374
8375Normally, the bounding box is computed automatically unless the
8376@code{-no_bounding_box} commandline option has been specified;
8377(@ref{Invoking Gri}).  But if @code{set bounding box} is
8378done, the automatically computed value is ignored and the given box is
8379used instead.  Use this if Gri makes mistakes in its automatic selection
8380of bounding box.
8381
8382The coordinates of the bounding box may be specified in (1) user
8383coordinates, as defined @strong{at the moment} the command is executed, or
8384(2) in points on the page, measured from an origin at the lower-left
8385(72 point per inch), or (3) in centimeters on the page.  Which coordinate
8386system is used depends on the last keyword -- use @code{pt} for points,
8387@code{cm} for centimeters, and nothing at all for user-units.
8388
8389The most common use is in points, since that is how many other
8390application packages, e.g. La@TeX{} and dvips, specify the bounding box.
8391
8392If the box is specified in the user units, the user units in effect
8393@strong{at the moment} of executing the @code{set bounding box} command
8394are used.  This must be born in mind if the coordinate system is
8395changing during the execution of the program, e.g.  if margins are
8396changing or the x and y axes are changing.  For this reason it often
8397makes sense to put this command at the end of the commandfile.
8398
8399
8400@node   Set Clip, Set Color, Set Bounding Box, Set
8401@comment  node-name,  next,  previous,  up
8402@subsubsection @code{set clip}
8403@findex set clip
8404@cindex @code{set clip} command
8405
8406@example
8407`set clip [postscript] \
8408  @{on [.xleft. .xright. .ybottom. .ytop.]@} \
8409  @{to curve@} \
8410  | off'
8411@end example
8412
8413@noindent
8414Control clipping of following drawing commands.  Note that the
8415commands have two styles, one of which includes the keyword
8416@code{postscript}.  PostScript clipping does a cleaner job, but it
8417results in larger file sizes.  @emph{Important} if you are using
8418@code{postscript} clipping, then you be @emph{sure} to turn it off
8419using @code{set clip postscript off}, instead of @code{set clip off};
8420otherwise Gri will get mixed up.
8421
8422@itemize @bullet
8423
8424@item @code{set clip on}
8425Don't plot data outside axes.
8426
8427@item @code{set clip postscript on}
8428As above, but Postscript clipping.
8429
8430@item @code{set clip on .xleft. .xright. .ybottom. .ytop.}
8431Don't plot data outside indicated box.
8432
8433@item @code{set clip postscript on .xleft. .xright. .ybottom. .ytop.}
8434As above, but Postscript clipping.
8435
8436@item @code{set clip off}
8437Plot all data, whether inside the axes or not.
8438
8439@item @code{set clip postscript off}
8440As above, but Postscript clipping.
8441
8442@item @code{set clip to curve} set clip to the curve, as
8443would be drawn by a @code{draw curve filled} command, i.e. to the
8444polygon constructed by running along the xy points, in order, followed
8445by a final segment from the last point back to the first point.  This is a
8446"postscript" clip, as explained in the next item.
8447
8448@item @code{set clip postscript to curve}
8449As above, but Postscript clipping.
8450
8451@example
8452draw axes
8453set clip postscript on 10 20 0 1
8454draw curve
8455set clip postscript off
8456@end example
8457
8458@item @code{set clip postscript off}
8459Turn PostScript clipping off.
8460@strong{See also} @code{set input data window}.
8461@cindex data, clipping using @code{set input clip}
8462@cindex clipping data using @code{set input clip}
8463@end itemize
8464
8465@node   Set Color, Set Colorname, Set Clip, Set
8466@comment  node-name,  next,  previous,  up
8467@subsubsection @code{set color}
8468@findex set color
8469@findex set colour
8470@cindex @code{set color} command
8471@cindex @code{set colour} command
8472
8473@example
8474`set color \name               | \
8475    @{rgb .red. .green. .blue.@} | \
8476@{hsb .hue. .saturation. .brightness.@}'
8477@end example
8478
8479@noindent
8480Set the color of the ``pen'' used for drawing lines and text.  Normally
8481lines and text are drawn in the same color, but the text color can be
8482specified independently if desired (@ref{Set Font Color}).  This might be
8483useful to get contour lines of one color and labels of another.  The
8484spelling @code{colour} is also accepted.
8485
8486In the @code{set color \name} style, set the drawing color to the
8487indicated name, either from the builtin list (@code{white},
8488@code{LightGray}, @code{darkslategray}, @code{black}, @code{red},
8489@code{brown}, @code{tan}, @code{orange}, @code{yellow}, @code{green},
8490@code{ForestGreen}, @code{cyan}, @code{blue}, @code{skyblue},
8491@code{magenta}), or from a list created by @code{read colornames}.  In
8492the latter case, if the colorname has more than one word in it, use
8493quotes, e.g. @code{set color "ghost white"}.
8494
8495In the @code{set color rgb ...} style, set the individual color
8496components as indicated.  The numbers @code{.red.}, @code{.green.} and
8497@code{.blue.} range from 0 (for no contribution of that color component
8498to the final color) to 1 (for maximal contribution).  Values less than 0
8499are clipped to 0; values greater than 1 are clipped to 1.  EXAMPLES:
8500
8501@example
8502set color rgb 0   0   0 # black
8503set color rgb 1   1   1 # white
8504set color rgb 1   0   0 # bright red
8505set color rgb 0.5 0   0 # dark red (only 50 percent)
8506set color rgb 0   1   0 # pure green
8507set color rgb 1   1   0 # yellow: red + green
8508@end example
8509
8510In the @code{set color hsb ...} style, set the individual color
8511components as indicated.  The numbers @code{.hue.}, @code{.saturation.}
8512and @code{.brightness.} range from 0 to 1.  The color, represented by
8513.hue., ranges from 0 for pure red, through 1/3 for pure green, and 2/3
8514for pure blue, and back to 1 again for pure red. The purity of the
8515color, represented by .saturation., ranges from 0 (none of the hue is
8516visible) to 1 (the maximal amount is present).  The brightness of the
8517color, represented by @code{.brightness.}, ranges from 0 (black) to 1
8518(maximal brigntness).  Values less than 0 are clipped to 0; values
8519greater than 1 are clipped to 1.  EXAMPLES:
8520
8521@example
8522set color hsb 0    1   1 # pure, bright red
8523set color hsb 0    1 0.5 # half black, half red
8524set color hsb .333 1   1 # pure, bright green
8525@end example
8526
8527
8528@node   Set Colorname, Set Contour Format, Set Color, Set
8529@comment  node-name,  next,  previous,  up
8530@subsubsection @code{set colorname}
8531@findex set colorname
8532@cindex @code{set color name} command
8533
8534@example
8535`set colorname \name @{rgb .red. .green. .blue.@} \
8536                   | @{hsb .hue. .saturation. .brightness.@}'
8537@end example
8538
8539@noindent
8540Create a colorname with the indicated color.  The color components range
8541from 0 to 1, and will be clipped to these values if they are outside
8542this range.  EXAMPLE (borrowing a color from @file{/usr/lib/X11/rgb.txt}):
8543
8544@example
8545set colorname peachpuff rgb 1 @{rpn 218 255 / @}  @{rpn 185 255 / @}
8546draw box filled 2 2 3 3 cm
8547@end example
8548
8549This command is akin to @code{read colornames} (@ref{Read Colornames}),
8550except that the latter uses an X11 database, so the color constituents
8551range from 0 to 255, whereas for @code{set colorname} they range from 0
8552to 1.
8553
8554
8555
8556@node   Set Contour Format, Set Contour Label For, Set Colorname, Set
8557@comment  node-name,  next,  previous,  up
8558@subsubsection @code{set contour format}
8559@findex set contour format
8560@cindex @code{set contour format} command
8561
8562@example
8563`set contour format \style|default'
8564@end example
8565
8566@noindent
8567Normally, Gri draws the numeric labels of contours using a format code
8568called @code{%g} in the "C" language.  You may specify any other "long"
8569format using this command.  For example, @code{set contour format %.1f}
8570tells Gri to use one decimal place in the numbers, and also to prefer
8571the "float" notation to the exponential notation.  @code{set contour
8572format default} resets to the default @code{%f} format.  You may use
8573quotes around the format if you need to, to make the item be a single
8574word (e.g. @code{set contour format "%.1f m/s"}).
8575
8576
8577
8578@node Set Contour Label For, Set Contour Label Position, Set Contour Format, Set
8579@comment  node-name,  next,  previous,  up
8580@subsubsection @code{set contour label for}
8581@findex set contour label for
8582@cindex @code{set contour label for} command
8583
8584@example
8585`set contour label for lines exceeding .x. cm'
8586@end example
8587
8588@noindent
8589Make it so contour lines shorter than @code{.x.} centimeters will not be
8590labelled.
8591
8592
8593
8594@node   Set Contour Label Position, Set Contour Labels, Set Contour Label For, Set
8595@comment  node-name,  next,  previous,  up
8596@subsubsection @code{set contour label position}
8597@findex set contour label position
8598@cindex @code{set contour label position} command
8599@cindex contours, spacing of labels on
8600@cindex labels, on contours
8601
8602@example
8603`set contour label position \
8604  @{.start_cm. .between_cm.@} \
8605  | centered \
8606  | default'
8607@end example
8608
8609@noindent
8610By default, contour labels are drawn at the location 1 cm into the
8611contour curve, measured from the startpoint of the contour (e.g., for
8612contours crossing the axes frames, the label will be 1 cm from the
8613frame), and then at a uniform distance along the contour.  By default,
8614this uniform distance is the average dimension of the plotting area
8615inside the axes.  If @code{.start_cm.} and @code{.between_cm.} are
8616specified, the first label is drawn at a distance @code{.start_cm.} from
8617the start of the contour, and thereafter at a separation of
8618@code{.between_cm.}.
8619
8620If the @code{centered} option is used, then the contour labels are
8621centered along the length of the line.
8622
8623
8624
8625@node   Set Contour Labels, Set Dash, Set Contour Label Position, Set
8626@comment  node-name,  next,  previous,  up
8627@subsubsection @code{set contour labels}
8628@findex set contour labels
8629@cindex @code{set contour labels} command
8630@cindex contours, orientation of labels
8631@cindex contours, whiting/nowhiting under the labels
8632@cindex labels on contour lines, controlling orientation and white-under
8633
8634@example
8635set contour labels rotated \
8636  | horizontal \
8637  | whiteunder \
8638  | nowhiteunder
8639@end example
8640
8641@noindent
8642The first two options control whether contour labels are rotated to line
8643up with the contour lines, or whether they are horizontal (the default).
8644
8645The second two options control whether the region under contour labels
8646is whited out before drawing the label.  The default is
8647@code{whiteunder}, which has the visual effect of the label having been
8648drawn on a piece of paper and then pasted on.  This can look jarring
8649when the material under the contour is an image.  When
8650@code{nowhiteunder} is specified, the contour line is broken to make
8651space for the text, but no whiting out is done.
8652
8653@node   Set Dash, Set Environment, Set Contour Labels, Set
8654@comment  node-name,  next,  previous,  up
8655@subsubsection @code{set dash}
8656@findex set dash
8657@cindex @code{set dash} command
8658@cindex dashed lines
8659@cindex lines, dashed
8660@vindex @code{..length_dash..}, length/cm of dashes
8661@vindex @code{..length_blank..}, length/cm of blanks
8662
8663@example
8664`set dash [.n.|@{.dash_cm. .blank_cm. ...@}|off]'
8665@end example
8666
8667@noindent
8668Control dash-style for following @code{draw curve} and @code{draw line}
8669commands.
8670
8671@itemize @bullet
8672
8673@item @code{set dash}
8674Set to dashed line (0.4cm dashes, 0.1cm blanks).
8675
8676@item @code{set dash .n.}
8677Set to indicated pre-defined dashed line, according to table:
8678
8679@example
8680.n. dash/cm blank/cm
8681 0        -        -   ... (Solid line)
8682 1      0.2      0.1
8683 2      0.4      0.1
8684 3      0.6      0.1
8685 4      0.8      0.1
8686 5      1.0      0.1
868710      w        w
868811      w        2w
868912      w        3w
869013      w        4w
869114      w        5w
869215      w        6w
8693@end example
8694
8695@noindent
8696Where @code{w} is written, it indicates the current linewidth.  Thus,
8697types 10 through 15 give square-dotted lines.
8698
8699@item @code{set dash .dash_cm. .blank_cm. .dash_cm. .blank_cm. ...}
8700Set to indicated dashed line.  The series of lengths @code{.dash_cm.}
8701and @code{.blank_cm.} give the lengths of dash and blank portions
8702(measured in centimeters).  Any number of dash/blank lengths may be
8703given.  For example, @code{set dash 0.5 0.1 0.1 0.1} looks good.
8704
8705@item @code{set dash off}
8706Turn dashing off, setting to a solid line.
8707@end itemize
8708
8709@node   Set Environment, Set Error Action, Set Dash, Set
8710@comment  node-name,  next,  previous,  up
8711@subsubsection @code{set environment}
8712@findex set environment
8713@cindex @code{set environment} command
8714@cindex developer command @code{set environment}
8715
8716@example
8717`set environment'
8718@end example
8719
8720@noindent
8721Set environment (graylevel, axis length, etc) so that following plotting
8722commands will make use of anything set by either a @code{set} command or
8723by direct manipulation of builtin variables like @code{..xsize..}, etc.
8724NOTE: this should @strong{only} be done by developers.
8725
8726
8727@node   Set Error Action, Set Flag, Set Environment, Set
8728@comment  node-name,  next,  previous,  up
8729@subsubsection @code{set error}
8730@findex set error
8731@cindex @code{set error} command
8732@cindex Handling errors with @code{set error} command
8733
8734@example
8735`set error action to core dump'
8736@end example
8737
8738@noindent
8739Make Gri dump core when any error is found, to facilitate debugging.
8740
8741@node   Set Flag, Set Font Color, Set Error Action, Set
8742@comment  node-name,  next,  previous,  up
8743@subsubsection @code{set flag}
8744@findex set flag
8745@cindex @code{set flag} command
8746@cindex developer command @code{set flag}
8747
8748@example
8749`set flag \name [off]'
8750@end example
8751
8752@noindent
8753Set the indicated flag to YES.  The name of the flag is contained in a
8754single word, e.g. @code{set flag dan_28sep_test}.  The action of the
8755flags may change with time and is undocumented.  This command is
8756provided to enable selected users (e.g., the developer himself) to use
8757test features of Gri before they are frozen into a fixed syntax and
8758action.  The keyword @code{off} turns the indicated flag off.  NOTE:
8759this should @strong{only} be done by developers.
8760
8761@example
8762FLAG         DATE     ACTION
8763
8764jinyu1       29sep94  'convert columns to grid'
8765                       outputs (x,y,z,z_predicted)
8766
8767emulate_gre   9jun97  'E' format on axes yields
8768                      scientific notation
8769
8770kelley1      17jun97  for kelley only - quit contour
8771                      trace if hit nonlegit
8772
8773kelley2      17jun97  for kelley only: print
8774                      info while contour tracing
8775@end example
8776
8777
8778@node   Set Font Color, Set Font Encoding, Set Flag, Set
8779@comment  node-name,  next,  previous,  up
8780@subsubsection @code{set font color}
8781@findex set font color
8782@findex set font colour
8783@cindex font, setting color of
8784@cindex text, color used for
8785@cindex color, for text
8786@cindex @code{set font color} command
8787@cindex @code{set font colour} command
8788
8789@example
8790set font color \name           | \
8791    @{rgb .red. .green. .blue.@} | \
8792@{hsb .hue. .saturation. .brightness.@}
8793@end example
8794
8795@noindent
8796The syntax is the same as @code{set color}, except that this applies to
8797text only.  By default, text is drawn in the same color as lines, so
8798text color is changed as line color is changed (e.g. by using the
8799@code{set color} or @code{set graylevel} commands)).  However, once
8800@code{set font color} is used in a Gri program, the font thereafter
8801maintains a separate color from the lines.
8802
8803
8804@node   Set Font Encoding, Set Font Size, Set Font Color, Set
8805@comment  node-name,  next,  previous,  up
8806@subsubsection @code{set font encoding}
8807@findex set font encoding
8808@cindex font, setting encoding vector of
8809@cindex text, encoding vector of
8810@cindex font encoding
8811@cindex @code{set font encoding} command
8812@cindex postscript-standard font encoding
8813@cindex ISO latin 1 font encoding
8814
8815@example
8816set font encoding PostscriptStandard | isolatin1
8817@end example
8818
8819@noindent
8820Permits one to control the so-called ``font encoding'' used in text.
8821The default font encoding is ISO-Latin-1, which is best for English and
8822other European languages.  To learn how to enter accents in a text
8823editor, and for a brief overview of font encodings,
8824(@ref{Non-English Text}).
8825
8826If the so-called ``Postscript Standard'' font encoding is required, this
8827command permits changing the encoding.
8828
8829Note: few users will ever need this command.  If you don't even know
8830what ``font encoding'' is about, ignore this command!
8831
8832
8833
8834@node   Set Font Size, Set Font To, Set Font Encoding, Set
8835@comment  node-name,  next,  previous,  up
8836@subsubsection @code{set font size}
8837@findex set font size
8838@cindex @code{set font size} command
8839@cindex font size
8840
8841@example
8842`set font size @{.size. [cm]@}|default'
8843@end example
8844
8845@noindent
8846Set the size of the font for drawing of text.
8847
8848@itemize @bullet
8849
8850@item @code{set font size .size.}
8851Set font size to @code{.size.} points.  (A point is 1/72 of an inch,
8852or 1/28 of a centimetre.)
8853
8854@item @code{set font size .size. cm}
8855Set font size to @code{.size.} centimetres.
8856
8857@item @code{set font size default}
8858Set font size to default = 12 pts.
8859@end itemize
8860
8861@cindex American Geophysical Union, recommended font size
8862
8863If your figure is to be reproduced by a journal, you should check with
8864them about the range of font size they need.  This will, of course,
8865depend on whether your figure is reduced or enlarged during
8866reproduction.  For example, American Geophysical Union (publishers of
8867J. Geophysical Res.) recommends that one use fonts no smaller than 8
8868points.  They also recommend that the range in fontsize in a given
8869figure not exceed 2.
8870
8871
8872
8873@node   Set Font To, Set Graylevel, Set Font Size, Set
8874@comment  node-name,  next,  previous,  up
8875@subsubsection @code{set font to}
8876@findex set font to
8877@cindex @code{set font to} command
8878
8879@example
8880`set font to \fontname'
8881@end example
8882
8883@noindent
8884Set font to named style.  Note that the backslash is @strong{not} to be
8885written, but here merely means that this word has several alternatives.
8886For example, one might say @code{set font to Courier}.  The allowed
8887fontnames are:
8888@code{Courier}, a typewriter font (and the only monospaced font in Gri);
8889@code{Helvetica} (the default), a sans-serif font commonly used in drafting scientific graphs;
8890@code{HelveticaBold}, a bold version of Helvetica;
8891@code{Times} (also called @code{TimesRoman}), a font used in most newspapers;
8892@code{TimesBold}, a bold version of Times;
8893@code{Palatino} (also called @code{PalatinoRoman}), similar to Times;
8894@code{Symbol}, included for completeness, is a
8895mathematical font in which "a" becomes $\alpha$ of the math mode, etc.
8896For reference on these fonts see any book on PostScript.  The default
8897font is @code{Helvetica}.
8898
8899
8900@node   Set Graylevel, Set Grid Missing, Set Font To, Set
8901@comment  node-name,  next,  previous,  up
8902@subsubsection @code{set graylevel}
8903@findex set graylevel
8904@findex set greylevel
8905@cindex @code{set graylevel} command
8906@cindex @code{set greylevel} command
8907@cindex graylevel, command
8908@cindex lines, gray, command
8909
8910@example
8911`set graylevel .brightness.|white|black'
8912@end example
8913
8914@noindent
8915Set graylevel for lines to indicated numerical value between 0=black and
89161=white, or to the named color.
8917
8918@cindex American Geophysical Union, recommended gray levels
8919
8920Note: if your diagram is to be reproduced by a journal, it is unlikely
8921that the reproduction will be able to distinguish between any two
8922graylevels which differ by less than 0.2.  Also, graylevels less than
89230.2 may appear as pure black, while those of 0.8 or more may appear as
8924pure white.  These guidelines are as specified by American Geophysical
8925Union (publishers of J. Geophysical Res.), as of 1998.
8926
8927
8928
8929@node   Set Grid Missing, Set Ignore Initial Newline, Set Graylevel, Set
8930@comment  node-name,  next,  previous,  up
8931@subsubsection @code{set grid missing}
8932@findex set grid missing
8933@cindex @code{set grid missing} command
8934@cindex grid, missing values
8935@cindex contouring, clipping out invalid areas
8936
8937General format is
8938
8939@example
8940`set grid missing \
8941  @{above|below .intercept. .slope@} \
8942  | @{inside curve@}'
8943@end example
8944
8945@noindent
8946The style
8947
8948@example
8949`set grid missing above|below .intercept. .slope'
8950@end example
8951
8952@noindent
8953sets grid to missing value for all points above/below the line defined
8954by
8955@tex
8956$y = {\rm .intercept.} + {\rm .slope.} x$
8957@end tex
8958@ifinfo
8959y = .intercept. + .slope. * x
8960@end ifinfo
8961
8962The style
8963
8964@example
8965`set grid missing inside curve'
8966@end example
8967
8968@noindent
8969sets the grid to the missing value throughout an area described
8970by the curve last read in with @code{read columns}.  This is
8971useful for e.g. excluding land areas while contouring ocean
8972properties.  The curve may contain several "islands," each
8973tracing (clockwise) a region inside of which the grid is to
8974considered missing.  If the first point in an island doesn't
8975match the last, then an imaginary line is assumed which connects
8976them.  Multiple islands may be separated by missing-value codes.
8977
8978@strong{See also} @code{Set Z Missing}.
8979
8980@node   Set Ignore Initial Newline, Set Ignore Error Eof, Set Grid Missing, Set
8981@comment  node-name,  next,  previous,  up
8982@subsubsection @code{set ignore initial newline}
8983@findex set ignore initial newline
8984@cindex @code{set ignore initial newline} command
8985
8986@example
8987`set ignore initial newline [off]'
8988@end example
8989
8990@noindent
8991Make Gri ignore a newline if it occurs as the first character of the
8992next data file.  This is used for files made by FORTRAN programs on
8993VAX/VMS computers.
8994
8995
8996@node   Set Ignore Error Eof, Set Image Colorscale, Set Ignore Initial Newline, Set
8997@comment  node-name,  next,  previous,  up
8998@subsubsection @code{set ignore error eof}
8999@findex set ignore error eof
9000@cindex @code{set ignore error eof} command
9001@cindex files, testing for eof
9002@cindex eof on files
9003@cindex testing for end of file
9004@cindex testing for file eof
9005
9006@example
9007`set ignore error eof'
9008@end example
9009
9010@noindent
9011Stop Gri from considering that to encounter an end of file in future
9012@code{read} commands consitutes an error; Gri will simply warn about
9013future EOFs.
9014
9015
9016
9017
9018@node   Set Image Colorscale, Set Image Grayscale, Set Ignore Error Eof, Set
9019@comment  node-name,  next,  previous,  up
9020@subsubsection @code{set image colorscale}
9021@findex set image colorscale
9022@findex set image colourscale
9023@cindex @code{set image colorscale} command
9024@cindex @code{set image colourscale} command
9025@cindex colorscale, setting for images
9026@cindex image plots, setting colorscale
9027
9028@example
9029set image colorscale hsb .h. .s. .b. .im_value. \
9030    hsb .h. .s. .b. .im_value. [increment .im_value.]
9031set image colorscale rgb .r. .g. .b. .im_value. \
9032    rgb .r. .g. .b. .im_value. [increment .im_value.]
9033set image colorscale \
9034  \name .im_value. \
9035  \name .im_value. \
9036  [increment .im_value.]
9037@end example
9038
9039@noindent
9040Set colorscale mapping for image, using HSB (hue, saturation,
9041brightness) specification, RGB (red, green, blue) color specification,
9042or named colors.  The image range must previously have been set by
9043@code{set image range}, so that the @code{.im_value.} values will have
9044meaning.  Two pairs of (color, image-value) are given, and possibly an
9045increment.  Normally the colors are smoothly blended between the
9046endpoints, but if an increment is supplied, the colors are quantized.
9047The HSB method allows creation of spectral palettes, while the other two
9048methods create simple blending between the two endpoints.
9049
9050EG: To get a spectrum ranging between pure red (H=0) for image value of
9051-10.0, and pure blue (H=2/3) for image value of 10.0, do this:
9052
9053@example
9054set image colorscale hsb 0 1 1 -10 hsb .666 1 1 10
9055@end example
9056
9057EG: To get a scale running from pure red (at image-value 10.0) into pure
9058blue (at image-value 25.1), but with the colors blending intuitively in
9059between (i.e., blending as paint might), use @code{rgb} color
9060specification, as follows:
9061
9062@example
9063set image colorscale rgb 1 0 0 10 rgb  0 0 1 25.1
9064@end example
9065
9066EG: To get a quantized blend between the X11 colors @code{skyblue} at
9067image value of 0 and @code{tan} at image value of 20, and with steps at
9068image values incrementing by 5, do this:
9069
9070@example
9071set image colorscale skyblue 0 tan 20 increment 5
9072@end example
9073
9074@noindent
9075Note that the traversal is through RGB space, so it is
9076intuitive, not spectral.  See @code{set color} for a list of X11 colors
9077known to Gri.
9078
9079See also @code{read image colorscale} (@ref{Read Image Colorscale}).
9080
9081@node   Set Image Grayscale, Set Image Missing Value Color, Set Image Colorscale, Set
9082@comment  node-name,  next,  previous,  up
9083@subsubsection @code{set image grayscale}
9084@findex set image grayscale
9085@findex set image greyscale
9086@findex set image grayscale using histogram
9087@findex set image greyscale using histogram
9088@cindex @code{set image grayscale} command
9089@cindex @code{set image greyscale} command
9090@cindex @code{set image grayscale using histogram} command
9091@cindex @code{set image greyscale using histogram} command
9092@cindex grayscale, setting for images
9093@cindex image plots, setting grayscale
9094
9095@example
9096`set image grayscale using histogram \
9097  [black .bl. white .wh.]'
9098
9099`set image grayscale \
9100  [black .bl. white .wh. [increment .inc.]]'
9101@end example
9102
9103@noindent
9104Set up a grayscale mapping for images.  The image range must have
9105previously have been set by @code{set image range}.
9106
9107@example
9108`set image grayscale using histogram [black .bl. white .wh.]'
9109@end example
9110
9111@noindent
9112Create a grayscale mapping using linearized cumulative histogram
9113enhancement.  The image range must have previously have been set by
9114@code{set image range}.
9115
9116This creates maximal contrast in each range of graylevels,
9117and is useful for tracing subtle features between different images (for
9118example, it makes it easier to trace fronts between successive satellite
9119images).  The entire histogram is expanded, from the smallest value in
9120the image to the largest.
9121
9122With no options specified, the histogram is done from 0 in the image to
9123255 in the image.  If the black/white options are specified, the
9124histogram is done between these values.
9125
9126@example
9127`set image grayscale \
9128  [black .bl. white .wh. [increment .inc.]]'
9129@end example
9130
9131@noindent
9132With no optional parameters, create a grayscale mapping for the current
9133image, scaling it from black for the mininum value in the image to white
9134for the maximum value.  The image range must have previously have been
9135set by @code{set image range}.
9136
9137The optional parameters @code{.wh.} and @code{.bl.} specify the values
9138to be drawn in white and black in the image, with smooth linear blending
9139in between.
9140
9141Normally the blending from white to black is smooth (linear), but if the
9142additional optional parameter @code{.inc.} is specified, the blending is
9143quantized, jumping to darker values at (@code{.wh.} + @code{.inc.}),
9144(@code{.wh.} + 2* @code{.inc.}), etc.  (The sign of @code{.inc.} will be
9145altered, if necessary, to ensure that (@code{.wh.} + @code{.inc.}) is
9146between @code{.wh.} and @code{.inc.}.)  The colour switches to pure
9147white at the value @code{.wh.}, and remains pure white everywhere on the
9148"white" side of this value.  Similarly, the transition to pure black
9149occurs at the value @code{.bl.}.  In other words, neither pure white nor
9150pure black is present inside the interval from @code{.wh.} to
9151@code{.bl.}.  Therefore, when using the @code{draw image palette}
9152command, you might want to extend the range by one increment so as to
9153get an example of both pure white and pure black.
9154
9155@example
9156.w. = 0
9157.b. = 1
9158.i. = 0.2
9159set image grayscale white .w. black .b. increment .i.
9160draw image palette left \
9161  @{rpn .w. .i. -@} \
9162  right @{rpn .b. .i. +@} \
9163  increment .i.
9164@end example
9165
9166
9167@node   Set Image Missing Value Color, Set Image Range, Set Image Grayscale, Set
9168@comment  node-name,  next,  previous,  up
9169@subsubsection @code{set image missing value color}
9170@findex set image missing value color
9171@findex set image missing value colour
9172@cindex @code{set image missing value color} command
9173@cindex @code{set image missing value colour} command
9174
9175@example
9176set image missing value color to white|black|\
9177    @{graylevel .brightness.@}|@{rgb .r. .g. .b.@}
9178@end example
9179
9180@noindent
9181Set the color of ``missing'' pixels (white by default).  The image range
9182must have previously have been set by @code{set image range}.  Pixels
9183with missing values can result from creating images from grids which
9184have missing values; see the @code{convert grid to image} command.  The
9185@code{.brightness.} parameter in the @code{graylevel} style ranges from
91860 for black to 1 for white.  The @code{rgb} parameters allow setting to
9187full color.
9188
9189
9190@node   Set Image Range, Set Input Data Window, Set Image Missing Value Color, Set
9191@comment  node-name,  next,  previous,  up
9192@subsubsection @code{set image range}
9193@findex set image range
9194@cindex @code{set image range} command
9195
9196@example
9197set image range .0value. .255value.
9198@end example
9199
9200@noindent
9201Specify maximum possible range of values that images can hold, in user
9202units.  Gri needs to know this because it stores images in a limited
9203format capable of holding only 256 distinct values.  Unlike some other
9204programs, Gri encourages (forces) the user to specify things in terms of
9205user-units, not image-units.  This has the advantage of working
9206regardless of the number of bits per pixel.  Thus, for example,
9207@code{set image grayscale}, @code{set image colorscale},
9208@code{draw image grayscale}, etc, all use @strong{user} units.
9209
9210When an image is created by @code{convert grid to image}, values outside
9211the range spanned by @code{.0value.} and @code{.255value.} are clipped.
9212(There is no need, however, for @code{.0value.} to be less than
9213@code{.255value.}.)  This clipping discards information, so make sure
9214the range you give is larger than the range of data in the grid.
9215
9216EXAMPLE: consider a satellite image in which an internal value of 0 is
9217meant to correspond to 0 degrees Celsius, and an internal value of 255
9218corresponds to 25.5 degrees.  (This is a common scale.)  Then the Gri
9219command @code{set image range 0 25.5} would establish the required
9220range.  If this range were combined with a linear grayscale mapping (see
9221@code{set image grayscale}), the resultant granularity in the internal
9222representation of the user values would be (25.5-0)/255 or 0.1 degrees
9223Celsius; temperature variations from pixel to pixel which were less than
92240.1 degrees would be lost.
9225
9226All other image commands @strong{require} that the range has been set.
9227Thus, all these commands fail unless @code{set image range} has been
9228done: @code{draw image}, @code{draw image palette}, @code{read image},
9229@code{convert grid to image}, @code{set image grayscale}, and
9230@code{set image colorscale}.
9231
9232NOTE: If a range already exists when @code{set image range} is used,
9233then the settings are altered.  Thoughtless usage can therefore lead to
9234confusing results.  (The situation is like setting an axis scale,
9235plotting a curve with no axes, then altering the scale and plotting the
9236new axes.  It is legal but not necessarily smart.)
9237
9238
9239
9240
9241@node   Set Input Data Window, Set Input Data Separator, Set Image Range, Set
9242@comment  node-name,  next,  previous,  up
9243@subsubsection @code{set input data window}
9244@findex set input data window
9245@cindex @code{set input data window} command
9246
9247@example
9248`set input data window x|y @{.min. .max.@}|off'
9249@end example
9250
9251@noindent
9252Create a data window for following @code{read} statements.
9253
9254@itemize @bullet
9255
9256@item @code{set input data window x .min. .max.}
9257For future reading commands, ignore all data with x less than
9258@code{.min.} or x greater than @code{.max.} The data not in the interval
9259will not be read in at all.  This will hold until
9260@code{set data window x off} is done, in which case all data will be read in.
9261
9262@item @code{set input data window x off}
9263Return to normal conditions, in which all data are read in.
9264
9265@item @code{set input data window y .min. .max.}
9266Analgous to command for x.
9267
9268@item @code{set input data window y off}
9269Analagous to command for x.
9270@end itemize
9271
9272EXAMPLE: To set the input data window as the current x axis plus a
9273border of 5 centimetres to left and right, do the following:
9274
9275@example
9276set input data window x \
9277  @{rpn ..xleft..  xusertocm 5 - xcmtouser@} \
9278  @{rpn ..xright.. xusertocm 5 + xcmtouser@}
9279@end example
9280
9281@strong{See also} @code{set clip}
9282@cindex input data window
9283@cindex data, clipping using @code{set input data window}
9284@cindex clipping data using @code{set input data window}
9285
9286
9287
9288@node   Set Input Data Separator, Set Line Cap, Set Input Data Window, Set
9289@comment  node-name,  next,  previous,  up
9290@subsubsection @code{set input data separator}
9291@findex set input data separator
9292@cindex @code{set input data separator} command
9293
9294@example
9295`set input data separator TAB|default'
9296@end example
9297
9298@noindent
9299Set the separator between data items.  The @code{default} method is to
9300assume that data items are separated by one or more spaces or tabs, and
9301also to ignore any spaces or tabs at the start of a data line.
9302
9303In the @code{TAB} method the data are assumed to be separated by a
9304SINGLE tab character.  (Multiple tabs will result in null values being
9305assigned to items -- almost certainly not what you want!)  Also, initial
9306spaces and tabs on lines are NOT skipped.
9307
9308Use the @code{TAB} method only after thinking carefully about the above,
9309since the assignment of null values is problematic.
9310
9311
9312
9313@node   Set Line Cap, Set Line Join, Set Input Data Separator, Set
9314@comment  node-name,  next,  previous,  up
9315@subsubsection @code{set line cap}
9316@findex set line cap
9317@cindex @code{set line cap} command
9318@cindex setting line cap type
9319@cindex line cap
9320
9321@example
9322`set line cap .type.'
9323@end example
9324
9325@noindent
9326Set the type of ends (caps) of lines.  Use @code{.type.} of value 0 for
9327square ends, cut off precisely at the end of line, or 1 for round ends
9328which overhang half the line width, or 2 for square ends which overhang
9329half the line width.  The selected style is used for the ends of line
9330segments, as well as at corners.  In PostScript parlance, therefore,
9331this command sets both the linecap and the linejoin parameters.
9332
9333This command only applies to lines drawn with @code{draw curve},
9334@code{draw line} and @code{draw polygon}.  Axes are always drawn with a
9335line cap of 0.
9336
9337
9338
9339@node   Set Line Join, Set Line Width, Set Line Cap, Set
9340@comment  node-name,  next,  previous,  up
9341@subsubsection @code{set line join}
9342@findex set line join
9343@cindex @code{set line join} command
9344@cindex setting line join type
9345@cindex line join
9346
9347@example
9348`set line join .type.'
9349@end example
9350
9351@noindent
9352Set the type of intersection of lines.  Use @code{.type.} of value 0 for
9353mitered joins (pointy ends that may extend beyond the data points), a
9354value of 1 for rounded ends (the default), or a value of 2 for bevelled
9355(squared-off) ends.  See the @code{setlinejoin} command in any text on
9356the PostScript language for more information.
9357
9358This command only applies to lines drawn with @code{draw curve},
9359@code{draw line} and @code{draw polygon}.  Axes are always drawn with a
9360line join of 0.
9361
9362
9363
9364@node   Set Line Width, Set Missing Value, Set Line Join, Set
9365@comment  node-name,  next,  previous,  up
9366@subsubsection @code{set line width}
9367@findex set line width
9368@cindex @code{set line width} command
9369@cindex setting line width
9370@cindex line width
9371
9372@example
9373`set line width \
9374  [axis|symbol|all] \
9375  .width_pt. \
9376  | @{rapidograph \name@} \
9377  | default'
9378@end example
9379
9380@noindent
9381Set the width of lines used to draw curves (default), axes, symbols, or
9382all of the above.  The width may be set to a value specified in points
9383(conversion: 72 pt = 1 inch), to a named rapidograph width, or to the
9384default value.  The initial default values are: 0.709pt (or rapidograph
93853x0) for curves; 0.369pt (or rapidograph 6x0) for axes; 0.369pt (or
9386rapidograph 6x0) for symbols.  (To learn more about standard
9387pen widths, see the ISO 9175-1 documents.)
9388
9389@cindex American Geophysical Union, recommended line thickness
9390
9391If your figure is to be reproduced by a journal, you should check with
9392them about the range of line thicknesses they recommend.  This will, of
9393course, depend on whether your figure is reduced or enlarged during
9394reproduction.  For example, American Geophysical Union (publishers of
9395J. Geophysical Res.) recommends that one use line thicknesses no less
9396than 0.5 points and no more than 4 points.
9397
9398
9399
9400@cindex rapidograph scaling for line width
9401@cindex slides, suggested line widths
9402@cindex overhead projection images, suggested line widths
9403@cindex projected images, suggested line widths
9404
9405The rapidograph settings match the standard set of widths used in
9406technical fountain pens.  The table below gives width names along with
9407the width in points and centimetres, as given in the specifications
9408supplied with Rapidograph technical fountain pens.  Names marked by the
9409symbol @code{*} are in sequence increasing by the factor root(2).  Texts
9410on technical drawing often suggest using linewidths in the ratio of 2 or
9411root(2).  On many printers, the variation in width from root(2) increase
9412is too subtle to see, so the factor-of-2 rule may be preferable.  To get
9413sizes in a sequence doubling in width, pick from the list (@code{6x0},
9414@code{3x0}, @code{1}, @code{3.5} @code{7}).  To get a sequence
9415increasing in width by root(2), pick from the list (@code{6x0},
9416@code{4x0}, @code{3x0}, @code{0}, @code{1}, @code{2.5}, @code{3.5},
9417@code{6}, @code{7}).  The eye can distinguish curves with linewidths
9418differing by a factor of root(2) if the image is of high quality, but a
9419factor of 2 is usually better.  Similarly, for overhead projections and
9420projected slides, one would do well to use linewidths differing by a
9421factor of 4.
9422
9423
9424This is the list of @code{rapidograph} linewidths:
9425
9426@example
9427  Name      pt    cm
9428  ====    =====  =====
9429*  6x0    0.369  0.013
9430*  4x0    0.510  0.018
9431*  3x0    0.709  0.025
9432    00    0.850  0.03
9433*    0    0.992  0.035
9434*    1    1.417  0.05
9435     2    1.701  0.06
9436*    2.5  1.984  0.07
9437     3    2.268  0.08
9438*    3.5  2.835  0.1
9439     4    3.402  0.12
9440*    6    3.969  0.14
9441*    7    5.669  0.2
9442@end example
9443
9444
9445
9446
9447@node   Set Missing Value, Set Page Size, Set Line Width, Set
9448@comment  node-name,  next,  previous,  up
9449@subsubsection @code{set missing value}
9450@findex set missing value
9451@cindex @code{set missing value} command
9452@cindex missing values
9453
9454@example
9455`set missing value .value.|none'
9456@end example
9457
9458@noindent
9459If a numerical value is given, set the
9460missing-value code to that value, and also
9461store this value in the builtin variable
9462@code{..missingvalue..} and the builtin synonym @code{\.missingvalue..}
9463also.  After this command, Gri will ignore any data that are within
94640.1 percent of this value.  (This feature is commonly used in geophysical
9465data.)
9466
9467If @code{none} is given, turn off this feature.
9468
9469The default is that the feature is turned off.
9470
9471
9472
9473@node   Set Page Size, Set Page, Set Missing Value, Set
9474@comment  node-name,  next,  previous,  up
9475@subsubsection @code{set page size}
9476@findex set page
9477@cindex @code{set page size} command
9478
9479@example
9480`set page size letter|legal|folio|tabloid|A0|A1|A2|A3|A4|A5'
9481@end example
9482
9483@noindent
9484Set the page dimension, as indicated below.
9485@table @emph
9486
9487@item letter
9488American "letter" size: 8.5 x 11 inches
9489
9490@item legal
9491American "legal" size: 8.5 x 14 inches
9492
9493@item folio
9494American "folio" size: 8.5 x 13 inches
9495
9496@item tabloid
9497American "tabloid" size: 11 x 17 inches
9498
9499@item A5
9500Metric size: 14.8 x 21.0 cm
9501
9502@item A4
9503Metric size: 21.0 x 29.7 cm
9504
9505@item A3
9506Metric size: 29.7 x 42.0 cm
9507
9508@item A2
9509Metric size: 42.0 x 59.4 cm
9510
9511@item A1
9512Metric size: 59.4 x 84.1 cm
9513
9514@item A0
9515Metric size: 84.1 x 118.9 cm
9516@end table
9517
9518The effect is to possibly alter the PostScript "bounding box."  If all
9519the drawn material fits within the indicated page, then the bounding
9520box is not altered.  (In other words, Gri will still keep the bounding
9521box tight on the drawn items.)
9522
9523However, if any drawn item extends beyond the indicated size, it will
9524be clipped to the boundary.
9525
9526
9527@node   Set Page, Set Panel, Set Page Size, Set
9528@comment  node-name,  next,  previous,  up
9529@subsubsection @code{set page}
9530@findex set page
9531@cindex @code{set page} command
9532
9533@example
9534`set page portrait \
9535  | landscape \
9536  | @{factor .mag.@} \
9537  | @{translate .xcm. .ycm.@}'
9538@end example
9539
9540@noindent
9541Control orientation or scaling of what is drawn on the paper.
9542
9543@cindex portrait orientation of page
9544@cindex orientation of page, portrait
9545@cindex page orientation, portrait
9546@itemize @bullet
9547
9548@item @code{set page portrait}
9549Print graph normally (default).
9550
9551@cindex landscape orientation of page
9552@cindex orientation of page, landscape
9553@cindex page orientation, landscape
9554
9555@item @code{set page landscape}
9556Print graph sideways.
9557
9558@item @code{set page factor .mag.}
9559Scale everything to be drawn on the paper by the indicated magnification
9560factor.  This @strong{must} be called before any drawing commands.
9561
9562@item @code{set page translate .xcm. .ycm.}
9563Translate everything to be drawn on the paper by the indicated x/y
9564distances.  This @strong{must} be called before any drawing commands.
9565@end itemize
9566
9567@strong{Note}: The order of the factor/translate commands matters, so you
9568may need to experiment.  For example,
9569
9570@example
9571set page translate 2 1
9572set page factor 0.5
9573@end example
9574
9575@noindent
9576moves anything that would have been drawn at the lower-left corner of
9577the paper onto the point 2cm from the left side and 1cm from the bottom
9578side of the paper, and then applies the multiplication factor.
9579Reversing the order gives quite different results.  PostScript gurus
9580should note that the following two commands are inserted into the
9581PostScript file:
9582
9583@example
958456.900000 28.450000 translate
95850.500000 0.500000 scale
9586@end example
9587
9588
9589@node   Set Panel, Set Panels, Set Page, Set
9590@comment  node-name,  next,  previous,  up
9591@subsubsection @code{set panel}
9592@findex set panel
9593@cindex @code{set panel} command
9594@cindex Multi-panel plots
9595@cindex Window-pane plots
9596
9597@example
9598set panel .row. .col.
9599@end example
9600
9601@noindent
9602Establish the geometry for the panel in the indicated row and column;
9603that is, select which defined panel to draw into.  The
9604bottom row has @code{.row.} = 1, and the leftmost column has
9605@code{.col.} = 1.  This must be used only after defining the panel
9606layout using @code{Panels .row. .col. .dx_cm. .dy_cm.}.
9607
9608
9609@node   Set Panels, Set Path To, Set Panel, Set
9610@comment  node-name,  next,  previous,  up
9611@subsubsection @code{set panels}
9612@findex set panels
9613@cindex @code{set panels} command
9614@cindex Multi-panel plots
9615@cindex Window-pane plots
9616
9617@example
9618set panels .rows. .cols. [.dx_cm. .dy_cm.]
9619@end example
9620
9621@noindent
9622Set up for multipanel plots, with spacing @code{.dx_cm.} between the
9623columns and @code{.dy_cm.} between the rows.  If the spacings are not
9624supplied, 2cm is used.  The panels fill the rectangle which would
9625otherwise contain the single axis frame, as set by @code{set x size} and
9626@code{set x margin}, etc.
9627
9628The global variables @code{.panel_dx.}, @code{.panel_dy.},
9629@code{.panel_xmargin.}, @code{.panel_ymargin.}, @code{.panel_xsize.},
9630and @code{.panel_ysize} are created, to be used by later calls to
9631@code{set panel}.
9632
9633EXAMPLE
9634
9635@example
9636# Draw 2 panels across, 3 up the page.
9637
9638# The Panel interiors will be in region cornered
9639# by (2,2), (12,22) cm
9640set x margin 2
9641set y margin 2
9642set x size 10
9643set y size 20
9644set panels 2 3
9645
9646# Create dummy scale
9647set x axis 0 1
9648set y axis 0 1
9649
9650# Draw blank axes
9651et panel 1 1
9652raw axes
9653set panel 1 2
9654draw axes
9655set panel 1 3
9656draw axes
9657set panel 2 1
9658draw axes
9659set panel 2 2
9660draw axes
9661set panel 2 3
9662draw axes
9663@end example
9664
9665@strong{See also} @code{set panel .row. .col.}
9666
9667
9668@node   Set Path To, Set Postscript Filename, Set Panels, Set
9669@comment  node-name,  next,  previous,  up
9670@subsubsection @code{set path}
9671@findex set path
9672@cindex @code{set path} command
9673@cindex path, for command files
9674@cindex path, for data files
9675@cindex command files, path to search for
9676@cindex data files, path to search for
9677@cindex @code{\\.path_data.} builtin synonym
9678@cindex @code{\\.path_commands.} builtin synonym
9679@cindex builtin synonym @code{\\.path_data.}
9680@cindex builtin synonym @code{\\.path_commands.}
9681
9682@example
9683set path to "\path"|default for data|commands
9684@end example
9685
9686@noindent
9687Set the directory path that @code{open} will search for data files, or
9688that @code{insert} will search for command files.  This search will
9689@emph{not} be done if the filename starts with a @code{/}, @code{~}, or
9690@code{.} character.
9691
9692The path is formatted in a colon-separated manner, following the normal
9693Unix convention, and searching is from left to right.  For example, the
9694path @code{".:/usr/lib/gri"} tells Gri to search for the file first in
9695the local directory (named @file{.}), and if it is not found there, to
9696look next in the directory named @file{/usr/lib/gri}.
9697
9698The indicated path is stored in either @code{\.path_data.} or
9699@code{\.path_commands.}, as appropriate.  At startup time, each of these
9700paths is set to @file{"."}, the current directory, and this value is
9701reset if the @code{default} keyword is provided to this command.
9702
9703If you need to know where the file was eventually found, save the
9704@code{\.return_value.} just after the @code{open} command was executed.
9705For example, the following defines the synonym @code{\uk}, which is the
9706full pathname of the file containing some sort of data about Great
9707Britain.
9708
9709@example
9710set path to "/atlases/world:/atlases/northern_hemisphere" for data
9711open britain.dat        # we don't know where file is ...
9712\gb = "\.return_value." # ... until now!
9713
9714# Can later do command such as
9715#    read from \gb
9716# or
9717#    rewind \gb
9718# to work with this particular file, even if
9719# there is another file open that also is
9720# named "britain.dat".
9721@end example
9722
9723@node   Set Postscript Filename, Set Symbol Size, Set Path To, Set
9724@comment  node-name,  next,  previous,  up
9725@subsubsection @code{set postscript filename}
9726@findex set postscript filename
9727@cindex @code{set postscript filename} command
9728@cindex name, of PostScript file
9729@cindex postscript filename
9730
9731@example
9732`set postscript filename "\name"'
9733@end example
9734
9735@noindent
9736Set name of PostScript file, over-riding the present name.
9737
9738
9739@node   Set Symbol Size, Set Tic Size, Set Postscript Filename, Set
9740@comment  node-name,  next,  previous,  up
9741@subsubsection @code{set symbol size}
9742@findex set symbol size
9743@cindex @code{set symbol size} command
9744@cindex setting symbol size
9745@cindex symbols, setting size
9746
9747@example
9748`set symbol size .diameter_cm.|default'
9749@end example
9750
9751@noindent
9752Control the diameter of symbols drawn by @code{draw symbol} command.
9753
9754@itemize @bullet
9755
9756@item @code{set symbol size .diameter_cm.}
9757Make symbol size be @code{.diameter_cm.} centimeters in diameter.
9758
9759@item @code{set symbol size default}
9760Set to default diameter of 0.1 cm.
9761@end itemize
9762
9763
9764@node   Set Tic Size, Set Trace, Set Symbol Size, Set
9765@comment  node-name,  next,  previous,  up
9766@subsubsection @code{set tic size}
9767@cindex axes, setting tic size
9768@cindex tic size, setting
9769@findex set tic size
9770@cindex @code{set tic size} command
9771
9772@example
9773`set tic size .size.|default'
9774@end example
9775
9776@noindent
9777Control size of tics on axes.
9778@itemize @bullet
9779
9780@item @code{set tic size .size.}
9781Set tic size to @code{.size.} centimetres.
9782
9783@item @code{set tic size default}
9784Set tic size to default of 0.2 cm.
9785
9786@item @code{set tics in|out}
9787Make axis tics point inward or outward.  The default is outward.
9788@end itemize
9789
9790
9791@node   Set Trace, Set Transparency, Set Tic Size, Set
9792@comment  node-name,  next,  previous,  up
9793@subsubsection @code{set trace}
9794@findex set trace
9795@cindex @code{set trace} command
9796
9797@example
9798`set trace [on|off]'
9799@end example
9800
9801@noindent
9802Control printing of command lines as they are processed.
9803
9804@itemize @bullet
9805
9806@item @code{set trace}
9807Make Gri print command lines as they are processed.
9808
9809@item @code{set trace on}
9810Same as @code{set trace}.
9811
9812@item @code{set trace off}
9813Prevent printing command lines (default).
9814@end itemize
9815
9816@node   Set Transparency, Set U Scale, Set Trace, Set
9817@comment  node-name,  next,  previous,  up
9818@subsubsection @code{set transparency}
9819@findex set transparency
9820@cindex @code{set transparency} command
9821
9822@example
9823`set transparency .transparency.'
9824@end example
9825
9826@noindent
9827
9828Set the transparency of drawn items, 0 for opaque and 1 for invisibly
9829faint.  @emph{This command is provisional, as of summer 2004, and
9830this part of the documentation needs to be fleshed out so
9831users can build intuition on transparency.  For example,
9832a quick quiz: what color do you think comes from drawing
9833red on top of yellow, or on top of blue?
9834}
9835
9836
9837@node   Set U Scale, Set V Scale, Set Transparency, Set
9838@comment  node-name,  next,  previous,  up
9839@subsubsection @code{set u scale}
9840@findex set u scale
9841@cindex @code{set u scale} command
9842
9843@example
9844`set u scale .cm_per_unit.|@{as x@}'
9845@end example
9846
9847@noindent
9848Set scale for x-component of arrows.
9849
9850@itemize @bullet
9851
9852@item @code{set u scale .cm_per_unit.}
9853Set scale for @code{u} component of arrows.
9854
9855@item @code{set u scale as x}
9856Set scale for u component of arrows to be the same as the x-scale.
9857Equivalent to
9858@code{set u scale as @{rpn ..xsize.. ..xright.. ..xleft.. - /@}}.
9859@end itemize
9860
9861NOTE: this only works if the x-scale is LINEAR (see @code{set x type}).
9862
9863
9864
9865@node   Set V Scale, Set X Axis, Set U Scale, Set
9866@comment  node-name,  next,  previous,  up
9867@subsubsection @code{set v scale}
9868@findex set v scale
9869@cindex @code{set v scale} command
9870
9871@example
9872`set v scale .cm_per_unit.|@{as y@}'
9873@end example
9874
9875@noindent
9876Set scale for y-component of arrows.
9877
9878@itemize @bullet
9879
9880@item @code{set v scale .cm_per_unit.}
9881Set scale for @code{v} component of arrows.
9882
9883@item @code{set v scale as y}
9884Set scale for v component of arrows to be the same as the y-scale.
9885Equivalent to
9886@code{set v scale as @{rpn ..ysize.. ..ytop.. ..ybottom.. - /@}}.
9887@end itemize
9888
9889NOTE: this only works if the y-scale is LINEAR (see @code{set y type}).
9890
9891
9892@node   Set X Axis, Set X Format, Set V Scale, Set
9893@comment  node-name,  next,  previous,  up
9894@subsubsection @code{set x axis}
9895@findex set x axis
9896@cindex @code{set x axis} command
9897
9898@example
9899`set x axis top'
9900`set x axis bottom'
9901`set x axis increasing'
9902`set x axis decreasing'
9903`set x axis unknown'
9904`set x axis .left. .right. [.incBig. [.incSml.]] [labelling .labelling_value.]'
9905`set x axis labels [add] .position_1. "label_1" [.position_2. "label_2" [...]]'
9906`set x axis labels automatic'
9907@end example
9908
9909@noindent
9910Control various things about the x axis.
9911
9912@itemize @bullet
9913
9914@item @code{set x axis top}
9915Make next x-axis to be drawn have labels above the axis.
9916
9917@item @code{set x axis bottom}
9918Make next x-axis to be drawn have labels below the axis.
9919
9920@item @code{set x axis increasing}
9921Make next x-axis to be drawn have numeric labels increasing to the
9922right.  This applies only if autoscaling is done; otherwise, the
9923supplied values (@code{.left. .right. [.incBig.  [.incSml.]]}) are used.
9924
9925@item @code{set x axis decreasing}
9926Make next x-axis to be drawn have numeric labels decreasing to the
9927right.  This applies only if autoscaling is done; otherwise, the
9928supplied values (@code{.left. .right. [.incBig.  [.incSml.]]}) are used.
9929
9930@item @code{set x axis unknown}
9931Make Gri forget any existing scale for the x axis, whether set by
9932another @code{set x axis} command or automatically, during reading of
9933data.  This is essentially a synonym for @code{delete x scale}.
9934
9935@item @code{set x axis .left. .right.}
9936Make x-axis range from @code{.left.} to @code{.right.}
9937
9938@item @code{set x axis .left. .right. .incBig.}
9939Make x-axis range from @code{.left.} to @code{.right.}, with labelled
9940increments at @code{.incBig.} Note: In the case of log axes, and
9941provided that @code{set x type log} has been called previously, the
9942@code{.incBig.} parameter has a different meaning: it is the interval,
9943in decades, between numbered labels; the default is 1.
9944
9945@item @code{set x axis .left. .right. .incBig. labelling .labelling_value.}
9946As above, but with the axis labels including the indicated value, and
9947incremented larger and smaller by @code{.incBig}.  (This does not work
9948for logarithmic axes.)
9949
9950@item @code{set x axis .left .right. .incBig. .incSml.}
9951Make x-axis range from @code{.left.} to @code{.right.}, with labelled
9952increments at @code{.incBig.}, and small tics at @code{.incSml.}  NOTE:
9953if the axis is logarithmic, the value of @code{.incSml.} takes on a
9954special meaning: if it is positive then small tics are put at values 2,
99553, 4, etc. between the decades, but if @code{.incSml.} is negative then
9956no such small tics are used.
9957
9958@item @code{set x axis .left .right. .incBig. .incSml. labelling .labelling_value.}
9959As above, but with the axis labels including the indicated value, and
9960incremented larger and smaller by @code{.incBig}. (This does not work
9961for logarithmic axes.)
9962
9963
9964@item @code{set x axis labels .position. "label" [.position. "label" [...]]}
9965@cindex axis labels, controlling
9966@cindex day-of-week axis
9967Override the automatic labelling at axis tics, and instead put the
9968indicated labels at the indicated x values.  For example, a
9969day-of-week axis can be created by the code:
9970
9971@example
9972set x axis 0 7 1
9973set x axis labels 0.5 "Mon" 1.5 "Tue" 2.5 "Wed" \
9974                  3.5 "Thu" 4.5 "Fri" 5.5 "Sat" \
9975                  6.5 "Sun"
9976@end example
9977
9978The command replaces any existing labels, unless the `add' keyword is
9979present, in which case the new label information is appended to any
9980existing information.
9981
9982
9983@item @code{set x axis labels automatic}
9984Return to automatically-generated axis labels, undoing the command of
9985the previous item.
9986
9987@end itemize
9988
9989
9990@node   Set X Format, Set X Grid, Set X Axis, Set
9991@comment  node-name,  next,  previous,  up
9992@subsubsection @code{set x format}
9993@findex set x format
9994@cindex @code{set x format} command
9995
9996@example
9997`set x format \format|default|off
9998@end example
9999
10000@noindent
10001Set format for numbers on x axis.  The format is specified in the manner
10002of the "C" programming language.  The C formats (i.e., @code{%f},
10003@code{%e} and @code{%g}) are permitted.
10004For example, @code{set x format %.1f} tells Gri to use 1 decimal place,
10005and to prefer the "float" notation to the exponential notation.  The
10006form @code{set x format off} tells Gri not to write numbers on the axis.
10007To get spaces in your format, enclose the format string in
10008double-quotes, e.g., you might use @code{set x format "%.0f$\circ$ W"}
10009for a map, or @code{set x format "%f "} to make the numbers appear to
10010the left of their normal location.
10011
10012The default format is @code{%lg}.
10013
10014
10015@node   Set X Grid, Set X Margin, Set X Format, Set
10016@comment  node-name,  next,  previous,  up
10017@subsubsection @code{set x grid}
10018@findex set x grid
10019@cindex @code{set x grid} command
10020
10021@example
10022`set x grid .left. .right. .inc.|@{/.cols.@}'
10023@end example
10024
10025@noindent
10026Create x-grid for contour or image.  If a grid already exists, an error
10027will be declared; the way to interpolate from an existing grid to a new
10028one is with the @code{interpolate x grid} command.
10029
10030@itemize @bullet
10031
10032@item @code{set x grid .left. .right. .inc.}
10033Create x-grid ranging from the value @code{.left.} at the left to
10034@code{.right.} at the right, stepping by an increment of @code{.inc.}.
10035
10036@item @code{set x grid .left. .right. /.cols.}
10037Create x-grid with @code{.cols.} points, ranging from the value
10038@code{.left.} at the left to @code{.right.} at the right.
10039@end itemize
10040
10041
10042@node   Set X Margin, Set X Name, Set X Grid, Set
10043@comment  node-name,  next,  previous,  up
10044@subsubsection @code{set x margin}
10045@findex set x margin
10046@cindex @code{set x margin} command
10047
10048@example
10049`set x margin @{[bigger|smaller] .size.@}|default'
10050@end example
10051
10052@noindent
10053Control x margin, that is, the space between the left-hand side of the
10054page and the left-hand side of the plotting area.  (Note that axis
10055labels are drawn inside the margin; the margin extends to the axis line,
10056not to the labels.)
10057
10058@itemize @bullet
10059
10060@item @code{set x margin .size.}
10061Set left margin to @code{.size.} cm.  It is permissible to have negative
10062margins, with the expected effect.
10063
10064@item @code{set x margin bigger .size.}
10065Increases left margin by @code{.size.} cm.
10066
10067@item @code{set x margin smaller .size.}
10068Decreases left margin by @code{.size.} cm.
10069@item @code{set x margin default}
10070Set left margin to default = 6 cm.
10071@end itemize
10072
10073
10074
10075@node   Set X Name, Set X Size, Set X Margin, Set
10076@comment  node-name,  next,  previous,  up
10077@subsubsection @code{set x name}
10078@findex set x name
10079@cindex @code{set x name} command
10080
10081@example
10082`set x name "\name"|default'
10083@end example
10084
10085@noindent
10086Set name of x-axis to the indicated string.  An empty string
10087(@code{set x name ""}) causes the x axis to be unlabelled.  The
10088@code{default} is @code{"x"}.
10089
10090
10091
10092@node   Set X Size, Set X Type, Set X Name, Set
10093@comment  node-name,  next,  previous,  up
10094@subsubsection @code{set x size}
10095@findex set x size
10096@cindex @code{set x size} command
10097
10098@example
10099`set x size .width_cm.|default'
10100@end example
10101
10102@noindent
10103Set the width of the plotting area.  This does not include axis labels,
10104only the interior part of the plot.
10105
10106
10107@itemize @bullet
10108
10109@item @code{set x size .width_cm.}
10110Set width of x-axis in centimeters.
10111
10112@item @code{set x size default}
10113Set width of x-axis to default = 10 cm.
10114@end itemize
10115
10116
10117@node   Set X Type, Set Y Axis, Set X Size, Set
10118@comment  node-name,  next,  previous,  up
10119@subsubsection @code{set x type}
10120@findex set x type
10121@cindex @code{set x type} command
10122
10123@example
10124set x type linear|log|@{map E|W|N|S@}
10125@end example
10126
10127@noindent
10128Control transformation function mapping user units to centimetres on the
10129page.
10130
10131
10132@itemize @bullet
10133
10134@item @code{set x type linear}
10135Set to linear axis.
10136
10137@item @code{set x type log}
10138Set to log axis.  To avoid clashes in the linear to log transform, this
10139command should precede the creation of an axis scale, either explicitly
10140through the @code{set x axis .left. .right. ...} command or implicitly
10141through the @code{read columns} command.
10142
10143@item @code{set x type map E|W|N|S}
10144@cindex maps, format of x axis
10145Set to be a map.  This means that whole numbers on the axis will have a
10146degree sign written after them (and then the letter @code{E}, etc) and
10147that numbers which are multiples of 1/60 will be written in
10148degree-minute format, and that similarly numbers which are divisible by
101491/3600 will be in degree-minute-second format.  If none of these things
10150apply, the axis labels will be written in decimal degrees.  Note that
10151this command overrides any format set by @code{set x format}.
10152
10153BUG: this only has an effect if the axis is not already of type
10154@code{log}.
10155@end itemize
10156
10157
10158
10159@node   Set Y Axis, Set Y Format, Set X Type, Set
10160@comment  node-name,  next,  previous,  up
10161@subsubsection @code{set y axis}
10162@findex set y axis
10163@cindex @code{set y axis} command
10164
10165@example
10166`set y axis left'
10167`set y axis right'
10168`set y axis increasing'
10169`set y axis decreasing'
10170`set y axis .bottom. .top. [.incBig. [.incSml.]] [labelling .labelling_value.]'
10171`set y axis labels [add] .position_1. "label_1" [.position_2. "label_2" [...]]'
10172`set y axis labels automatic'
10173@end example
10174
10175@noindent
10176Control various things about the y axis.
10177
10178@itemize @bullet
10179
10180@item @code{set y axis name horizontal}
10181Make y-axis name be horizontal.
10182
10183@item @code{set y axis name vertical}
10184Make y-axis name be vertical (default).
10185
10186@item @code{set y axis left}
10187Make next y-axis to be drawn have labels to the left of the axis.
10188
10189@item @code{set y axis right}
10190Make next y-axis to be drawn have labels to the right of the axis.
10191
10192@item @code{set y axis increasing}
10193Make next y-axis to be drawn have numeric labels increasing up the page.
10194This applies only if autoscaling is done; otherwise, the supplied values
10195(@code{.left. .right. [.incBig.  [.incSml.]]}) are used.
10196
10197@item @code{set y axis decreasing}
10198Make next y-axis to be drawn have numeric labels decreasing up the page.
10199This applies only if autoscaling is done; otherwise, the supplied values
10200(@code{.left. .right. [.incBig.  [.incSml.]]}) are used.
10201
10202@item @code{set y axis unknown}
10203Make Gri forget any existing scale for the y axis, whether set by
10204another @code{set y axis} command or automatically, during reading of
10205data.  This is essentially a synonym for @code{delete y scale}.
10206
10207@item @code{set y axis .bottom. .top.}
10208Make y-axis range from @code{.bottom.} to @code{.top.}
10209
10210@item @code{set y axis .bottom. .top. .incBig.}
10211Make y-axis range from @code{.bottom.} to @code{.top.}, with labelled
10212increments at @code{.incBig.}
10213
10214@item @code{set y axis .bottom. .top. .incBig. labelling .labelling_value.}
10215As above, but with the axis labels including the indicated value, and
10216incremented larger and smaller by @code{.incBig}. (This does not work
10217for logarithmic axes.)
10218
10219@item @code{set y axis .bottom. .top. .incBig. .incSml.}
10220Make y-axis range from @code{.bottom.} to @code{.top.}, with labelled
10221increments at @code{.incBig.}, and small tics at @code{.incSml.}  NOTE:
10222if the axis is logarithmic, the value of @code{.incSml.} takes on a
10223special meaning: if it is positive then small tics are put at values 2,
102243, 4, etc. between the decades, but if @code{.incSml.} is negative then
10225no such small tics are used.
10226
10227@item @code{set y axis .bottom. .top. .incBig. .incSml. labelling .labelling_value.}
10228As above, but with the axis labels including the indicated value, and
10229incremented larger and smaller by @code{.incBig}. (This does not work
10230for logarithmic axes.)
10231
10232@item @code{set y axis labels .position. "label" [.position. "label" [...]]}
10233Override the automatic labelling at axis tics, and instead put the
10234indicated labels at the indicated y values.  For example, a
10235physical-condition axis can be created by the code:
10236
10237@example
10238set y axis 0 1 0.5
10239set y axis labels 0.25 "Weak" 0.75 "Strong"
10240@end example
10241
10242The command replaces any existing labels, unless the `add' keyword is
10243present, in which case the new label information is appended to any
10244existing information.
10245
10246
10247@item @code{set y axis labels automatic}
10248Return to automatically-generated axis labels, undoing the command of
10249the previous item.
10250
10251@item @code{set y axis name vertical}
10252Cause future y axes to be drawn with the name aligned vertically (the default).
10253
10254@item @code{set y axis name horizontal}
10255Cause future y axes to be drawn with the name aligned horizontally.
10256
10257@end itemize
10258
10259
10260@node   Set Y Format, Set Y Grid, Set Y Axis, Set
10261@comment  node-name,  next,  previous,  up
10262@subsubsection @code{set y format}
10263@findex set y format
10264@cindex @code{set y format} command
10265
10266@example
10267`set y format \format|default|off'
10268@end example
10269
10270@noindent
10271Set format for numbers on y axis.  The format is specified in the manner
10272of the "C" programming language.  The C formats (i.e., @code{%f},
10273@code{%e} and @code{%lg}) are permitted.  For example,
10274@code{set y format %.1f} tells Gri to use 1 decimal place, and to prefer
10275the "float" notation to the exponential notation.
10276The form @code{set y format off}
10277tells Gri not to write numbers on the axis.  To get spaces in your
10278format, enclose the format string in double-quotes, e.g., you might use
10279@code{set y format "%.0f$\circ$ N"} for a map, or
10280@code{set y format "%f"} to make the numbers appear to the right of
10281their normal location.
10282
10283The default format is @code{%lg}.
10284
10285@node   Set Y Grid, Set Y Margin, Set Y Format, Set
10286@comment  node-name,  next,  previous,  up
10287@subsubsection @code{set y grid}
10288@findex set y grid
10289@cindex @code{set y grid} command
10290
10291@example
10292`set y grid .bottom. .top. .inc.|@{/.rows.@}'
10293@end example
10294
10295@noindent
10296Create y-grid for contour or image.  If a grid already exists, an error
10297will be declared; the way to interpolate from an existing grid to a new
10298one is with the @code{interpolate x grid} command.
10299
10300@itemize @bullet
10301
10302@item @code{set y grid .bottom. .top. .inc.}
10303Create y-grid ranging from the value @code{.bottom.} at the bottom to
10304@code{.top.} at the top, stepping by an increment of @code{.inc.}.
10305
10306@item @code{set y grid .bottom. .top. /.rows.}
10307Create y-grid with @code{.rows.} points, ranging from the value
10308@code{.bottom.} at the bottom to @code{.top.} at the top.
10309@end itemize
10310
10311
10312
10313@node   Set Y Margin, Set Y Name, Set Y Grid, Set
10314@comment  node-name,  next,  previous,  up
10315@subsubsection @code{set y margin}
10316@findex set y margin
10317@cindex @code{set y margin} command
10318
10319@example
10320`set y margin @{[bigger|smaller] .size.@}|default'
10321@end example
10322
10323@noindent
10324Control y margin, that is, the space between the bottom side of the page
10325and the bottom of the plotting area.  (Note that axis labels are drawn
10326inside the margin; the margin extends to the axis line, not to the
10327labels.)
10328
10329@itemize @bullet
10330
10331@item @code{set y margin .size.}
10332Set bottom margin to @code{.size.} centimeters.  It is permissible to
10333have negative margins, with the expected effect.
10334
10335@item @code{set y margin bigger .size.}
10336Increases bottom margin by @code{.size.} centimeters.
10337
10338@item @code{set y margin smaller .size.}
10339Decreases bottom margin by @code{.size.} centimeters.
10340
10341@item @code{set y margin default}
10342Set bottom margin to default = 6 cm.
10343@end itemize
10344
10345
10346
10347@node   Set Y Name, Set Y Size, Set Y Margin, Set
10348@comment  node-name,  next,  previous,  up
10349@subsubsection @code{set y name}
10350@findex set y name
10351@cindex @code{set y name} command
10352
10353@example
10354`set y name "\name"|default'
10355@end example
10356
10357@noindent
10358Set name of y-axis to the indicated string.  An empty string
10359(@code{set y name ""}) causes the x axis to be unlabelled.  The
10360@code{default} is @code{"y"}.
10361
10362
10363
10364@node   Set Y Size, Set Y Type, Set Y Name, Set
10365@comment  node-name,  next,  previous,  up
10366@subsubsection @code{set y size}
10367@findex set y size
10368@cindex @code{set y size} command
10369
10370@example
10371`set y size .height_cm.|default'
10372@end example
10373
10374@noindent
10375Set the width of the plotting area.  This does not include axis labels,
10376only the interior part of the plot.
10377
10378@itemize @bullet
10379
10380@item @code{set y size .height_cm.}
10381Set height of y-axis in centimeters.
10382
10383@item @code{set y size default}
10384Set width of y-axis to default = 10 cm.
10385@end itemize
10386
10387
10388
10389@node   Set Y Type,  Set Z Missing, Set Y Size, Set
10390@comment  node-name,  next,  previous,  up
10391@subsubsection @code{set y type}
10392@findex set y type
10393@cindex @code{set y type} command
10394
10395@example
10396set y type linear|log|@{map N|S|E|W@}
10397@end example
10398
10399@noindent
10400Control transformation function mapping user units to centimetres on the
10401page.
10402
10403@itemize @bullet
10404
10405@item @code{set y type linear}
10406Set to linear axis.
10407
10408@item @code{set y type log}
10409Set to log axis.  To avoid clashes in the linear to log transform, this
10410command should precede the creation of an axis scale, either explicitly
10411through the @code{set y axis .left. .right. ...} command or implicitly
10412through the @code{read columns} command.
10413
10414@item @code{set y type map N|S|E|W}
10415@cindex maps, format of y axis
10416Set to be a map.  This means that whole numbers on the axis will have a
10417degree sign written after them (and then the letter @code{N}, etc), and
10418that numbers which are multiples of 1/60 will be written in
10419degree-minute format, and that similarly numbers which are divisible by
104201/3600 will be in degree-minute-second format.  If none of these things
10421apply, the axis labels will be written in decimal degrees.  Note that
10422this command overrides any format set by @code{set y format}.
10423
10424BUG: this only has an effect if the axis is not already of type
10425@code{log}.
10426@end itemize
10427
10428@node   Set Z Missing, Show, Set Y Type, Set
10429@comment  node-name,  next,  previous,  up
10430@subsubsection @code{set z missing}
10431@findex set z missing
10432@cindex @code{set z missing} command
10433
10434@example
10435set z missing above|below .intercept. .slope.
10436@end example
10437
10438@noindent
10439Set @code{z} column to be missing whenever the associated @code{y} and
10440@code{x} columns are above/below the line defined by
10441@tex
10442$y = {\rm .intercept.} + {\rm .slope.} x$
10443@end tex
10444@ifinfo
10445y = .intercept. + .slope. * x
10446@end ifinfo
10447
10448
10449@c HTML <!-- newfile Show.html "Gri: `show' command" "Gri Commands" -->
10450
10451@node   Show, Skip, Set Z Missing, List Of Gri Commands
10452@comment  node-name,  next,  previous,  up
10453@subsection @code{show}
10454@findex show
10455@cindex @code{show} command
10456
10457@example
10458`show ...'
10459@end example
10460
10461@noindent
10462Show some information by printing it to standard output.
10463
10464@itemize @bullet
10465
10466@item @code{show all}
10467Show lots of information about plot.
10468
10469@item @code{show axes}
10470@cindex axes, displaying information about
10471Show information about axes.
10472
10473@item @code{show color}
10474Show the current pen color used for lines and text.  This is not to be
10475confused with image color, which is independent.
10476
10477@item @code{show colornames}
10478@cindex RGB values of known colors
10479@cindex color, displaying names and RGB values of
10480Show all colors known by name, as defined by @code{read colornames}
10481command and also the builtin colors defined automatically
10482(e.g. @code{white}, @code{black}, @code{red}, etc),
10483(@ref{Read Colornames}).
10484
10485@item @code{show columns}
10486Show x, y, z, u, v column data.
10487
10488@item @code{show columns statistics}
10489@cindex statistics of column data
10490@cindex column, displaying statistics of
10491Show means, std devs, etc for columns.
10492
10493@item @code{show flags}
10494Show values of all flags. (Developers only.)
10495
10496@item @code{show grid}
10497@cindex grid data, displaying
10498Show an indication of the grid data (used for contouring).
10499
10500@item @code{show grid mask}
10501@cindex grid mask, displaying
10502Show 1 if grid data are valid or 0 if contours will not extend into this
10503region.
10504@c REMOVED FOR 2.6.0 @item @code{show hint of the day}
10505@c REMOVED FOR 2.6.0 @cindex hint of the day, displaying
10506@c REMOVED FOR 2.6.0 Show a Gri hint for today, picked at random from hints stored on the web
10507@c REMOVED FOR 2.6.0 at
10508@c REMOVED FOR 2.6.0 @c HTML <A HREF="http://gri.sourceforge.net/gridoc/html/HINTS.html">
10509@c REMOVED FOR 2.6.0 @file{http://gri.sourceforge.net/gridoc/html/HINTS.html}
10510@c REMOVED FOR 2.6.0 @c HTML </A>
10511@c REMOVED FOR 2.6.0 These will be downloaded at most once per day.  Since the download might
10512@c REMOVED FOR 2.6.0 take a couple of seconds, the hint is only downloaded once per day,
10513@c REMOVED FOR 2.6.0 being cached for later uses in the given day, in a user file called
10514@c REMOVED FOR 2.6.0 @file{~/.gri-hint-cache}.  This command will
10515@c REMOVED FOR 2.6.0 produce warning if the system program @code{lynx} is not available for
10516@c REMOVED FOR 2.6.0 downloading.
10517
10518@item @code{show image}
10519@cindex image, displaying histogram of
10520Show information about image, such as a histogram of values, and, if the
10521image is small enough, the actual data.
10522
10523@item @code{show license}
10524Show the license for Gri, which outlines how users are allowed to share
10525it freely.
10526
10527@item @code{show misc}
10528Show miscellaneous information about the plot, the data, etc.
10529
10530@item @code{show next line}
10531Show next line of data-file.
10532
10533@item @code{show synonyms}
10534@cindex synonyms, displaying list of
10535Show values of all synonyms, whether built-in or user-defined.
10536
10537@item @code{show stopwatch}
10538@cindex timing things
10539@cindex stopwatch, for timing things
10540@cindex @code{show stopwatch} command
10541Show elapsed time since first call to this command in the given Gri program.
10542
10543@item @code{show time}
10544Show the current time.
10545
10546@item @code{show traceback}
10547@cindex traceback
10548Show traceback (i.e., the tree of commands being done at this instant).
10549
10550@item @code{show variables}
10551@cindex variables, displaying list of
10552Show values of all variables, whether built-in or user-defined.
10553
10554@item @code{show .value.}
10555Show value of indicated variable.
10556
10557@item @code{show @{rpn ...@}}
10558Show result of computing indicated expression.
10559
10560@item @code{show "some text"}
10561@cindex @code{show} command, how to get a tab
10562@cindex @code{show} command, how to get a newline
10563@cindex tab, in a @code{show} command
10564@cindex newline, in a @code{show} command
10565Print the indicated string.  You may use a double-slash to prevent Gri
10566from substituting synonym values; thus it is common to do e.g.
10567
10568@example
10569\var = "Temperature"
10570show "Plotting \\var = 'var'"
10571@end example
10572
10573@noindent
10574which will produce the output line
10575
10576@example
10577Plotting \\var = 'Temperature'
10578@end example
10579
10580@item @code{show "time=" .time. "; depth=" .depth.}
10581Print strings and values as indicated.  If the last item is ellipses
10582(three dots with no spaces between them), then no newline is printed;
10583this makes the next @code{show} statement print on the same line.
10584
10585@cindex @code{\<<}, for newline in @code{show} commands
10586@cindex @code{\>>}, for horizontal tab in @code{show} commands
10587@cindex newline, using @code{\<<} in @code{show}
10588@cindex tab, using @code{\>>} in @code{show}
10589@cindex @code{show} command, using @code{\<<} for newline
10590@cindex @code{show} command, @code{\>>} for horizontal tab
10591
10592To get a newline in a printed string, use the three-character glyph
10593@code{\<<}, and to get a horizontal tab, use @code{\>>}, as in the
10594examples below
10595
10596@example
10597\a = "HI"
10598show "\\a=\a"
10599system echo -e "a\\nb"
10600show "first line\<<second line"
10601show "first line\<<\>>(tabbed) second line"
10602show "first line\<<\>>(tabbed) second line"
10603@end example
10604
10605@end itemize
10606
10607
10608@c HTML <!-- newfile Skip.html "Gri: `skip' command" "Gri Commands" -->
10609
10610@node   Skip, Sleep, Show, List Of Gri Commands
10611@comment  node-name,  next,  previous,  up
10612@subsection @code{skip}
10613@findex skip
10614@cindex @code{skip} command
10615@cindex data files, positioning within
10616@cindex files, positioning within
10617
10618@example
10619`skip [forward|backward] [.n.]'
10620@end example
10621
10622
10623@itemize @bullet
10624
10625@item @code{skip}
10626For ascii files, skip next line in the data file.  For binary files,
10627skip forward 1 byte.
10628
10629@item @code{skip backward}
10630For ascii files, skip backward 1 line in the data file.  For binary
10631files, skip backward 1 byte.
10632
10633@item @code{skip .n.} or @code{forward .n.}
10634For ascii files, skip forward @code{.n.} lines in the data file.  For
10635binary files, skip forward @code{.n.} bytes.
10636
10637@item @code{skip backward .n.}
10638For ascii files, skip backward @code{.n.} lines in the data file.  For
10639binary files, skip backward @code{.n.} bytes.
10640@end itemize
10641
10642
10643@c HTML <!-- newfile Sleep.html "Gri: `sleep' command" "Gri Commands" -->
10644
10645@node   Sleep, Smooth, Skip, List Of Gri Commands
10646@comment  node-name,  next,  previous,  up
10647@subsection @code{sleep}
10648@cindex sleep, causing Gri to
10649@cindex process, causing Gri to sleep
10650@cindex @code{sleep} command
10651
10652@example
10653`sleep .sec.'
10654@end example
10655
10656Cause Gri to sleep for the indicated number of seconds, which should be
10657a positive integer.  This command is ignored if @code{.sec.} is zero or
10658negative, and the value of @code{.sec.} is first rounded to the nearest
10659integer.
10660
10661Normally, this command is used only by the developer, as a way to slow
10662down Gri execution, to allow easier monitoring for debugging purposes.
10663Beware: it is tricky to kill a sleeping job!
10664
10665
10666@c HTML <!-- newfile Smooth.html "Gri: `smooth' command" "Gri Commands" -->
10667
10668@node   Smooth, Source, Sleep, List Of Gri Commands
10669@comment  node-name,  next,  previous,  up
10670@subsection @code{smooth}
10671@cindex columns, filtering
10672@cindex smoothing column data
10673@findex smooth
10674@cindex @code{smooth} command
10675All these smoothing commands ignore the @strong{location} of the data.  For
10676equispaced data these algorithms have the standard interpretation in
10677terms of digital filters.  For non-equispaced data, the interpretation
10678is up to the user.
10679
10680@example
10681`smooth @{x [.n.]@} \
10682  | @{y [.n.]@} \
10683  | @{grid data [.f.|@{along x|y@}]@}'
10684@end example
10685
10686The @code{smooth x} command does smoothing by the following formula
10687
10688@example
10689x[i-1]   x[i]   x[i+1]
10690------ + ---- + ------
10691  4       2       4
10692@end example
10693
10694The @code{smooth x .n.} command does boxcar smoothing with centred
10695boxcars @code{.n.} points wide.  The @code{smooth y} command does the
10696same as @code{smooth x}, but on the @code{y} column.
10697
10698@cindex grid data, smoothing
10699@cindex smoothing grid data
10700@cindex contours, smoothing grid data
10701@findex smooth grid data
10702@cindex @code{smooth grid data} command
10703There are several methods of smoothing grid data.  Note that isolated
10704missing values are filled in by each method.  (Let the author know if
10705you'd like that `feature' to be an option.)
10706
10707The @code{smooth grid data} command smooths gridded data, by weighted
10708average in a plus-shaped window about each gridpoint.  The smoothing
10709algorithm replaces each interior gridpoint value @code{z[i][j]} by
10710
10711@example
10712z[i][j]   z[i-1][j] + z[i+1][j] + z[i][j-1] + z[i][j+1]
10713------- + ---------------------------------------------
10714   2                          8
10715@end example
10716
10717@noindent
10718Points along the edges are smoothed by the same formula, after
10719inventing image points outside the domain by planar extrapolation.
10720
10721The @code{smooth grid data .f.} command performs partial smoothing.  A
10722temporary fully-smoothed grid @code{zSMOOTH[i][h]} is constructed as
10723above, and a linear combination of this grid and the original grid is
10724used as the replacement grid:
10725
10726@example
10727z[i][j] = (1-f) * z[i][j] + f * zSMOOTH[i][j]
10728@end example
10729
10730@noindent
10731where @code{f} is the value indicated on the command line.
10732Thus, @code{smooth grid data 0} performs no smoothing at all, while
10733@code{smooth grid data 1} is equivalent to @code{smooth grid data}.
10734
10735The @code{smooth grid data along x} command smooths the grid data
10736across @code{x} (i.e., horizontally), by replacing each value
10737@code{z[i][j]} with the value
10738
10739@example
10740z[i][j]   z[i-1][j] + z[i+1][j]
10741------- + ---------------------
10742   2                4
10743@end example
10744
10745@noindent
10746Points along the edges are smoothed by the same formula, after
10747inventing image points outside the domain by linear extrapolation.
10748
10749The @code{smooth grid data along y} command does the same thing as
10750@code{smooth grid data along x}, but the smoothing is along @code{y}.
10751
10752
10753@strong{See also} @ref{Filter}, a generalization of @code{smooth x|y}
10754which allows for more sophisticated filters.
10755
10756
10757
10758@c HTML <!-- newfile Source.html "Gri: `source' command" "Gri Commands" -->
10759
10760@node   Source, Sprintf, Smooth, List Of Gri Commands
10761@comment  node-name,  next,  previous,  up
10762@subsection @code{source}
10763@findex source
10764@cindex @code{source} command, for running another command file
10765@cindex running a commandfile
10766
10767@example
10768`source \filename'
10769@end example
10770
10771@noindent
10772Perform the commands in the indicated file.
10773
10774If the file cannot be found, an error results.  Contrast this with the
10775@code{insert} command (@ref{Insert}), which has the ability to search
10776for the file through a user-specified path (@ref{Set Path To}).
10777
10778
10779@c HTML <!-- newfile Sprintf.html "Gri: `sprintf' command" "Gri Commands" -->
10780
10781@node   Sprintf, State, Source, List Of Gri Commands
10782@comment  node-name,  next,  previous,  up
10783@subsection @code{sprintf}
10784@findex sprintf
10785@cindex @code{sprintf} command
10786@cindex variables, storing values within synonyms (strings)
10787@cindex strings, storing variable values within
10788@cindex synonyms, storing variable values within
10789
10790@example
10791`sprintf \synonym "format" .variable. [.variable. [...]]'
10792@end example
10793
10794@noindent
10795Write numbers into a synonym (text string).  This is useful for
10796labelling plots.
10797
10798@noindent
10799@code{sprintf \out "a = %lf b = %.2f" .a. .b.} - Create a synonym
10800called @code{\out}, and print the values of the variables @code{.a.} and
10801@code{.b.} into it.  If @code{.a.} = 1 and @code{.b.} = 0.112, then
10802@code{\out} will be @code{"a = 1 b = 0.11"}
10803
10804Formatting codes are as in the C programming language, eg:
10805
10806@example
10807%.2f  -- Use floating point with 2 decimal places.
10808%9.2f -- As above, but number takes 9 characters.
10809%e    -- Use exponential notation.
10810@end example
10811
10812@noindent
10813@strong{CAUTION}: Variables are stored in the @strong{floating point} in
10814Gri, so you must use a format like @code{"%f"},
10815@strong{not} an integer code like @code{"%d"}.
10816If you want an integer, use @code{"%.0f"}.
10817@cindex format, for sprintf command
10818
10819
10820@c HTML <!-- newfile State.html "Gri: `state' command" "Gri Commands" -->
10821
10822@node   State, Superuser, Sprintf, List Of Gri Commands
10823@comment  node-name,  next,  previous,  up
10824@subsection @code{state}
10825@cindex saving graphics state
10826@cindex restoring graphics state
10827@cindex graphics state, saving and restoring
10828@findex @code{state} command
10829
10830@example
10831`state save|restore|display'
10832@end example
10833
10834@noindent
10835The @code{save} operation pushes a record of the graphics state (pen and
10836font characteristics, margins, axis lengths, min/max/inc values on axes,
10837etc) onto a stack.  The @code{restore} operation replaces the present
10838state with whatever is on top of the stack, and then pops the stack.
10839Use @code{display} to see some of the state properties.
10840
10841The @code{state} command is useful for temporary changes of axis
10842properties, etc.
10843
10844BUG: only line characteristics (width, color) and font characteristics
10845(font, size, color) are saved so far.  In fact, the full list of what
10846should be saved has not yet been finalized by the author.
10847
10848
10849@c HTML <!-- newfile Superuser.html "Gri: `superuser' command" "Gri Commands" -->
10850
10851@node   Superuser, System, State, List Of Gri Commands
10852@comment  node-name,  next,  previous,  up
10853@subsection @code{superuser}
10854@cindex debugging using superuser flags
10855@cindex superuser flags
10856@findex superuser
10857@cindex @code{superuser} command
10858
10859@example
10860`superuser [value]'
10861@end example
10862
10863@noindent
10864Allow extra debugging information and commands.  Normally, this command
10865and the corresponding commandline flag @code{-superuser} are only used
10866by programmers altering the Gri source.
10867
10868These are the flags and their meanings:
10869@itemize @bullet
10870
10871@item @strong{1} Print cmdline before/after substituting synonyms.
10872
10873@item @strong{2} Print cmdline before/after substituting rpn expressions.
10874
10875@item @strong{4} Print all new commands as they are being defined
10876
10877@item @strong{8} Print the system commands that are used with
10878@code{open "...|"} and in other instances.
10879
10880@item @strong{128} Changeable; only author should use this.
10881
10882@item @strong{256} Changeable; only author should use this.
10883@end itemize
10884Note that all flags are equal to 2 raised to an integer power.  Since
10885the flag values are detected by a bitwise OR, you can combine flags by
10886adding; thus specifying a flag of 5 yields flags 1 and 4 together;
10887specifying 15 yields flags 1, 2, 4 and 8.
10888
10889
10890@c HTML <!-- newfile System.html "Gri: `system' command" "Gri Commands" -->
10891
10892@node   System, Unlink, Superuser, List Of Gri Commands
10893@comment  node-name,  next,  previous,  up
10894@subsection @code{system}
10895@cindex gawk, sample of use
10896@cindex operating system commands, printing results of
10897@cindex system commands, printing results of
10898@cindex operating system commands, assigned to synonyms
10899@cindex system commands, assigned to synonyms
10900@findex system
10901@cindex @code{system} command
10902
10903@example
10904`system \system-command'
10905@end example
10906
10907@noindent
10908Tell the operating system to perform the indicated action.  Whatever
10909string follows the word @code{system} is passed directly to the
10910operating system, @strong{after} substitution of synonyms if any exist.
10911
10912@cindex comments, and system commands
10913@cindex quoting in system commands
10914If your system command contains double-slashes, you must protect them
10915from Gri (which will interpret them as comments) by enclosing in
10916double-quotes, e.g. @code{system cat A | sed -e "s/foo//g" | cat > B}.
10917(In the particular case of the @code{sed} command you could also do
10918@code{system cat A | sed -e "s:foo::g" | cat > B}.
10919
10920Note that @code{rpn} expressions are not evaluated, and variable values
10921are not substituted before passing the string to the operating system.
10922The exit status is stored in the builtin variable
10923@code{..exit_status..}.
10924
10925There are two ways to use the system:
10926@itemize @bullet
10927@item
10928@strong{Assign output to synonym}: The form @code{\synonym = system ...}
10929does the system command and then inserts the output from that command
10930into the indicated synonym.)
10931
10932@item @strong{Just run a command}: The command @code{system ls} will list
10933the files in the current directory.
10934@end itemize
10935
10936For long commands, there are two approaches, the second preferred:
10937@itemize @bullet
10938@item
10939@strong{Use continuation lines}: String a lot of information onto one
10940effective system line, using the @code{\} line-continuation character
10941at the ends of lines.  The problem is that it is very easy to lose one of
10942these backslashes.  The next method is better.
10943@item
10944@strong{Here-is syntax} The here-is syntax of many unix shells is also
10945provided.  If the system command contains the characters @code{<<}
10946followed by a word (with no space between!) then Gri will issue a system
10947command which includes not only this line but also all succeeding lines,
10948until a line is found which matches the indicated word precisely (with
10949no leading space allowed).  The @code{<< "WORD"} syntax is also
10950supported, meaning that the operating system is being told not to mess
10951with the dollar-signs -- needed in perl.
10952
10953Be careful using this inside a new-command.  Gri
10954Recognizes the end of the body of a new-command by a line with @code{@}}
10955in the @strong{first column}, and no non-white characters thereafter.
10956If you system command happens to use a line with a curly brace (as in a
10957loop in perl, for example), you must put whitespace before the brace.
10958This won't affect the system command, but it will let Gri correctly
10959realize that this is @strong{not} the end of the new-command.  For more
10960information on new-commands (@ref{Parsing}).
10961
10962@strong{Caution:} Before sending the string to the system, Gri first
10963translates any synonyms present.  Be careful with this, since system
10964commands calling awk, etc, very often use backslashes for the newline
10965character @code{\n} within strings.  If you have a synonym whose name
10966starts with @code{\n}, you can get a conflict.  For example, the awk
10967command @code{print "foo\nbar";} should print a line with @code{foo} on
10968it, followed by a line with @code{bar} on it, but it will instead print
10969a single line with @code{fooMISTAKE}, if you had previously defined a
10970synonym as @code{\nbar = "MISTAKE"}.  One way to avoid this mistake is
10971to make sure any @code{\n} characters appear at the end of strings, and
10972then simply avoid having a synonym named @code{\n}.
10973
10974Here is a Perl example.
10975
10976@example
10977\m = "Foo bar"
10978system perl <<"EOF"
10979$a = 100;
10980print "foo bar is \m, and a is $a\n";
10981print "BETTER: foo bar is \m, and a is $a\n";
10982print "Q: was a 100?\n";
10983EOF
10984@end example
10985
10986@end itemize
10987
10988
10989@strong{Some more examples}:
10990@itemize @bullet
10991@item
10992To get the first 15 lines of a file called @file{foo.dat} inserted into
10993another file called @file{bar.dat}, you might do the following.  Only
10994the first method works; the second will fail because @code{.n.} will not
10995be translated before passing to the operating system.
10996
10997@example
10998\num = "-15"
10999system head \num foo.dat > bar.dat
11000# Following will not work correctly because .num.
11001# will not be translated
11002.num. = -15
11003system head .num. foo.dat > bar.dat
11004@end example
11005
11006@item
11007Issue a unix command to get a listing of files in the current
11008working directory, and pipe them into the @code{more} system command.
11009
11010@example
11011system ls -l *c | more
11012@end example
11013
11014@item
11015Store the date and time into a synonym, and use it in a
11016title:
11017
11018@example
11019\time = system date
11020...
11021draw title "Plotted at time \time"
11022@end example
11023
11024@item
11025Use @code{awk} to prepare a two-column table of x, ranging
11026from 0 to 1 in steps of 0.1, and sin(x).  The table is stored in a file
11027whose suffix is the process ID of the Gri job.  This file is then
11028opened, and the data plotted.  Finally, a system command is issued to
11029remove the temporary file.
11030
11031@example
11032system awk 'BEGIN @{ \
11033    for (x=0; x<1; x+=0.1) @{ \
11034      printf("%f %f\n", x, sin(x)) \
11035    @} \
11036  @}'  > tmp.\.pid.
11037open tmp.\.pid.
11038read columns x y
11039close
11040system rm tmp.\.pid.
11041draw curve
11042@end example
11043
11044@strong{Note}: in unix, this command calls the Bourne shell, not the C-shell
11045that is often used interactively.  For many simple uses, the only
11046difference from normal interactive use will be that @code{~} is not
11047expanded to the home directory.  For example, you should write
11048
11049@example
11050system awk -f $HOME/foo/bar/cmd.gawk
11051@end example
11052
11053@noindent
11054instead of the
11055
11056@example
11057system awk -f ~/foo/bar/cmd.gawk
11058@end example
11059
11060@noindent
11061that you might expect from interactive C-shell use.
11062@noindent
11063RETURN VALUE:
11064@cindex @code{\.return_value.}, from @code{system ...}
11065Sets @code{\.return_value} to system status
11066@code{N status}
11067@end itemize
11068
11069
11070
11071@c HTML <!-- newfile Unlink.html "Gri: `unlink' command" "Gri Commands" -->
11072
11073@node   Unlink, While, System, List Of Gri Commands
11074@comment  node-name,  next,  previous,  up
11075@subsection @code{unlink}
11076@cindex removing files with unlink
11077@cindex unlink, to remove files
11078@findex unlink
11079@cindex @code{unlink} command
11080
11081@example
11082`unlink \filename'
11083@end example
11084@noindent
11085Delete a filename and possibly the file to which it refers.  On
11086non-unix machines, this simply means to delete the file.  On unix
11087machines, the action is more subtle.  The unix OS permits several
11088processes to use a given file at once.  Therefore, @code{unlink}
11089doesn't immediately remove the file, but instead waits until other
11090processes are done with it.  Most users will never realize the
11091difference, however, and it is safe to think of @code{unlink} as
11092simply removing the file.  To learn more, type @code{man unlink} in a
11093unix shell.
11094
11095A common use of @code{unlink} is to remove files that were created
11096with the @code{tmpname} facility (@ref{Using OS Inside Gri}), e.g.
11097@example
11098\tmp = tmpname
11099# do some system commands to put data into this file
11100open \tmp
11101read columns x y
11102draw curve
11103unlink \tmp
11104@end example
11105
11106
11107
11108@c HTML <!-- newfile While.html "Gri: `while' command" "Gri Commands" -->
11109
11110@node   While, Write, Unlink, List Of Gri Commands
11111@comment  node-name,  next,  previous,  up
11112@subsection @code{while}
11113@cindex loops
11114@findex while
11115@cindex @code{while} command
11116
11117@example
11118`while .test.|@{rpn ...@}'
11119@end example
11120
11121@noindent
11122Perform statements in loop while the value of @code{.test.} or the RPN
11123expression is nonzero.  The end of the loop designated by a line
11124containing the words @code{end while}.  The value @code{.test.} may be
11125an rpn expression.  To leave the loop prematurely, use a @code{break}
11126statement.  Upon encountering a @code{break} statement, Gri jumps to the
11127line immediately following the loop.  If the @code{-chatty} option is
11128nonzero, a notification is printed every 1000 passes through the loop,
11129as a debugging measure to catch unintended infinite loops.
11130
11131@noindent
11132@strong{Examples}:
11133
11134@itemize @bullet
11135@item
11136Loop forever, printing a message over and over.
11137
11138@example
11139while 1
11140  show "This loops forever. Need to 'break'"
11141end while
11142@end example
11143
11144@item
11145Read number pairs from a file, plotting bullets at
11146the indicated locations.  Note the use of an infinite
11147loop, with a break condition following an
11148end-of-file test.  (Do not be tempted to write
11149such loops as @code{while !..eof..} because that
11150would not catch the end of file until the next
11151time through the loop.  The result would be
11152to draw the last bullet twice, since the @code{read}
11153will not update the variables when the end of
11154file is encountered.)
11155@example
11156while 1
11157  read .x. .y.
11158  if ..eof..
11159    break
11160  end if
11161  draw symbol bullet at .x. .y.
11162end while
11163
11164@end example
11165@item
11166Loop 10 times, printing the values of @code{.i.} as they range 0, 1,
11167@dots{}, 9.  After exiting from the loop, @code{.i.} will equal 10.  Be
11168@strong{careful} to use the correct rpn greater-than test to avoid an
11169infinite loop.
11170
11171@example
11172.i. = 0
11173while @{rpn .i. 10 >@}
11174  show .i.
11175  .i. += 1
11176end while
11177@end example
11178
11179@end itemize
11180
11181
11182@c HTML <!-- newfile Write.html "Gri: Write commands" "Gri Commands" -->
11183
11184@node   Write, Write Columns, While, List Of Gri Commands
11185@comment  node-name,  next,  previous,  up
11186@subsection The @code{write} commands
11187@findex write
11188@cindex @code{write} command
11189The @code{write} commands write various things.
11190@cindex file, saving results into
11191@cindex save results in a file
11192
11193If the filename is @file{stdout}, the information is written to the
11194standard output device (ie, the screen); if it is @file{stderr}, the
11195information is written to the standard error device (ie, the screen).
11196
11197@strong{IMPORTANT NOTE}: The @code{write} commands @strong{append} to the
11198output file, as opposed to overwriting the contents of the file.
11199Therefore if you've run the Gri script before, and want fresh output,
11200make sure to do something like the following
11201
11202@example
11203system rm -f the_grid.dat
11204write grid to grid.dat
11205@end example
11206
11207@menu
11208* Write Columns::               Write columns to a file
11209* Write Contour::               Write contour (x,y) data to a file
11210* Write Grid::                  Write grid data to a file
11211* Write Image::                 Write various properties of image to a file
11212@end menu
11213
11214@node   Write Columns, Write Contour, Write, Write
11215@comment  node-name,  next,  previous,  up
11216@subsubsection @code{write columns}
11217@cindex writing to a file, column data
11218@cindex column data, writing to a file
11219@cindex data in columns, writing to a file
11220
11221@example
11222`write columns to \filename'
11223@end example
11224
11225@noindent
11226Append data columns to the end of the indicated file.
11227
11228@node   Write Contour, Write Grid, Write Columns, Write
11229@comment  node-name,  next,  previous,  up
11230@subsubsection @code{write contour}
11231@cindex writing to a file, contour data
11232@cindex contour data, writing to a file
11233@cindex data in contours, writing to a file
11234
11235@example
11236`write contour .value. to \filename'
11237@end example
11238
11239@noindent
11240Append to the named file the (x,y) pairs defining the contour of the indicated value.
11241
11242The first line of output is a header line, containing two numbers: the
11243contour value and the missing value.  Then the (x,y) pairs are written a
11244line at a time, with missing values being used to indicate ends of
11245segments.  A blank line is written after the last data pair.  For
11246example, if the contour contained two closed regions, Gri would output a
11247pair of missing values as one of the xy pairs, to denote the separation
11248of the two curves.  You could read and plot the output as in this
11249example
11250
11251@example
11252write contour 10 to contour.out
11253open contour.out
11254read .contour_value. .missing.
11255set missing value .missing.
11256read columns x y
11257draw curve
11258@end example
11259
11260@node   Write Grid, Write Image, Write Contour, Write
11261@comment  node-name,  next,  previous,  up
11262@subsubsection @code{write grid}
11263@cindex writing to a file, grid data
11264@cindex grid data, writing to a file
11265@cindex data in grid, writing to a file
11266@cindex grid data, write to file
11267
11268@example
11269`write grid to \filename [bycolumns]'
11270@end example
11271
11272@noindent
11273Append grid to the end of the named file.  Storage is in @code{%f}
11274format, and is in normal image order.  If the keyword @code{bycolumns}
11275is present, then the grid is transposed first, in such a way that
11276@code{read grid data bycolumns} performed on that file will read back
11277the original grid data.
11278
11279@node   Write Image, Programming, Write Grid, Write
11280@comment  node-name,  next,  previous,  up
11281@subsubsection @code{write image}
11282@cindex writing to a file, image data
11283@cindex image data, writing to a file
11284@cindex data in image, writing to a file
11285
11286@example
11287`write image ... to \filename'
11288@end example
11289
11290@noindent
11291The variants of this command write various things about the image to the
11292named file, as illustrated in the following table.
11293
11294@itemize @bullet
11295
11296@item @code{write image to image.dat}
11297@cindex image data, write to file
11298Append image to the end of the named file.  Storage is by unsigned-char,
11299and is in normal image order.  There is no header.
11300
11301@item @code{write image rasterfile to image.dat}
11302Append image to the end of the named file, in Sun Rasterfile format.
11303
11304@item @code{write image pgm to mask.dat}
11305Append image mask to the end of the named file, in PGM 'rawbits' format.
11306
11307@item @code{write image mask to mask.dat}
11308@cindex image mask data, write to file
11309Append image mask to the end of the named file. Storage is by
11310unsigned-char, and is in normal image order.
11311
11312@item @code{write image mask rasterfile to mask.dat}
11313Append image mask to the end of the named file, in Sun Rasterfile
11314format.
11315
11316@item @code{write image mask pgm to mask.dat}
11317Append image mask to the end of the named file, in PGM 'rawbits' format.
11318
11319@item @code{write image colorscale to colorscale.dat}
11320@cindex image palette data, write to file
11321Append image colorscale transform to the end of the named file.  Storage
11322is a series of 256 lines, each containing 3 numbers (for Red, Green and
11323Blue) in the range 0 to 1.  The file is suitable for reading with the
11324@code{read image colorscale} command.
11325
11326@item @code{write image grayscale to grayscale.dat}
11327Append image grayscale transform to the end of the named file.  Storage
11328is a series of 256 lines, each containing a number in the range 0 to 1.
11329The file is suitable for reading with the @code{read image grayscale}
11330command.
11331@end itemize
11332
11333
11334
11335@c HTML <!-- newfile Programming.html "Gri: programming" "Programming Gri" -->
11336
11337@node   Programming, Defaults, Write Image, Top
11338@comment  node-name,  next,  previous,  up
11339@chapter Programming in the Gri Language
11340@cindex programming in Gri
11341
11342The Gri programming language has @code{if} statements to control program
11343flow, and a @code{while} statement to repeat commands.  There are two
11344data types in Gri: ``variables'' (to store numbers) and ``synonyms'' (to
11345store character strings).  Gri recognizes commands by matching
11346statements against its list of known commands.  This list is extensible;
11347it is easy to add new commands as extensions to Gri.
11348
11349@menu
11350* Defaults::                    How Gri normally acts
11351* Online Help::                 Getting help from gri itself
11352* Long Command Lines::          Continued lines
11353* Variables::                   Variables (for storing numbers)
11354* Synonyms::                    Synonyms (for storing character strings)
11355* If Statements::               If statements
11356* Loops::                       Repeating command lines
11357* Mathematics::                 Doing mathematics on columns, grids etc
11358* rpn Mathematics::             Doing mathematics on variables
11359* Text::                        Doing things with characters strings
11360* Adding New Commands::         How to customize Gri by adding new commands
11361* Missing Values::              How to specify missing data
11362* Hints::                       Hints for good Gri programming
11363* Debugging::                   Debugging Gri programs
11364* Error Messages::              What to do about Gri error messages
11365* Missing Values::              Missing value code
11366* Operating System::            Using Gri in OS and OS in Gri
11367* Resource File::               Personalizing Gri
11368@end menu
11369
11370
11371@c HTML <!-- newfile Defaults.html "Gri: defaults" "Programming Gri" -->
11372
11373@node   Defaults, Online Help, Programming, Programming
11374@comment  node-name,  next,  previous,  up
11375@section Defaults
11376@cindex default values
11377At startup time, Gri sets the values of some things, like font size.
11378Since Gri is still under development, some of these defaults might
11379change, so you should not rely on them remaining the same.    Presently,
11380the defaults are equivalent to:
11381
11382@example
11383set arrow size 0.2         # (cm)
11384set axes style 0
11385set beep off
11386set clip off
11387set clip postscript off
11388set contour format %lg
11389set contour label position ? ?
11390set contour labels horizontal
11391set contour labels whiteunder
11392set dash off
11393set font size 12           # (pt)
11394set font to helvetica
11395set graylevel 0            # Black ink
11396set ignore initial newline off
11397set input data window x off
11398set input data window y off
11399# Following set (curve, axes, symbol) widths to width
11400# of rapidograph pens called (6x0, 3x0,  6x0)
11401set line width 0.709        # (pt) for curves
11402set line width axis 0.369   # (pt) for axes
11403set line width symbol 0.369 # (pt) for symbols
11404set missing value 1.0e22
11405set page portrait
11406set page factor 1
11407set symbol size 0.1        # (cm)
11408set tic size 0.2           # (cm)
11409set tics out
11410set trace off
11411set x format %lg
11412set x margin 6.0           # (cm)
11413set x name "x"
11414set x size 10              # (cm)
11415set x type linear
11416set y axis name vertical
11417set y format %lg
11418set y margin 6.0           # (cm)
11419set y name "y"
11420set y size 10              # (cm)
11421set y type linear
11422@end example
11423
11424@noindent
11425(NOTE: Programmers may alter the gri source file
11426@file{defaults.h} and then recompile Gri, if they feel the need to
11427change these things.  Also, see the file @file{startup.c} and the
11428function @code{gr_begin()} in @file{gr.c}.)
11429
11430
11431@c HTML <!-- newfile OnlineHelp.html "Gri: online help" "Programming Gri" -->
11432
11433@node   Online Help, Long Command Lines, Defaults, Programming
11434@comment  node-name,  next,  previous,  up
11435@section Online Help
11436@cindex help, online
11437@cindex online help
11438Type @code{help} to get a list of available commands and other topics of
11439interest. Here's how Gri responds
11440
11441@example
11442Type `help' followed by a command-name:
11443 assert      cd            close         convert
11444 create      debug         delete        differentiate
11445 draw        expecting     filter        flip
11446 get         help          if            ignore
11447 input       insert        interpolate   list
11448 ls          mask          move          new
11449 open        pwd           query         quit
11450 read        regress       reorder       rescale
11451 resize      return        rewind        set
11452 show        skip          sleep         smooth
11453 source      sprintf       state         superuser
11454 system      write
11455Or type `help -' followed by a topic from this list:
11456 example     extending     files         math
11457 strings     synonyms      variables     manual
11458@end example
11459
11460Some commands have more words than shown.  You can type these additional
11461words to narrow the help down; otherwise Gri will give you help
11462on all commands that begin with the indicated words.  For example, try
11463@code{help set} and @code{help set x}.  When you ask for help on a
11464multi-word command, Gri tells you about all commands which begin
11465with the words you've typed.  Thus,
11466
11467@example
11468help
11469help draw
11470help draw zero
11471help draw zero line
11472@end example
11473
11474@noindent
11475narrow in on the command @code{draw zero line}.  The response to the
11476most complete request is
11477
11478@example
11479`draw zero line [horizontally|vertically]'
11480  draw zero line
11481    Draw line y=0 if it is within axes
11482  draw zero line horizontally
11483    Draw line y=0 if it is within axes
11484  draw zero line vertically
11485    Draw line x=0 if it is within axes
11486@end example
11487
11488The part enclosed in angled quotes is the syntactical description of the
11489command.  (NOTE: The square brackets indicate an optional word (in this
11490case) or words.  The vertical bar indicates that either the item on the
11491left or the item on the right may appear; it is a logical OR operator.
11492The only other special characters in syntax descriptions are the braces
11493@code{@{@}}, which are used to enclose multiple words which act as one
11494unit; they are used to clarify the choices presented to the OR
11495operator.)  Following the syntactical description are examples.  Each
11496example is indented 2 spaces, and a description of it (which always
11497starts with an upper-case character and ends with a period, to indicate
11498that it is an English description) follows that, indented by an
11499additional 2 spaces.
11500
11501
11502@c HTML <!-- newfile LongCommandLines.html "Gri: long command lines" "Programming Gri" -->
11503
11504@node  Long Command Lines, Variables, Online Help, Programming
11505@comment  node-name,  next,  previous,  up
11506@section Long Command Lines
11507
11508@cindex continued lines
11509@cindex commands extending over several lines
11510
11511To extend a command across several lines, use a backslash @code{\} at
11512the @strong{very} end of all lines but the last:
11513
11514@example
11515draw line from \
11516  10 20 \
11517  to \
11518  10 30
11519@end example
11520
11521
11522
11523@c HTML <!-- newfile Variables.html "Gri: variables" "Programming Gri" -->
11524
11525@node   Variables, About Variables, Long Command Lines, Programming
11526@comment  node-name,  next,  previous,  up
11527@section Variables
11528@cindex numbers, stored in variables
11529@cindex variables
11530@cindex programming, variables
11531
11532@menu
11533* About Variables::             What variables are used for, and how
11534* User Variables::              Defining your own variables
11535* Built-in Variables::          Variables pre-defined by Gri
11536@end menu
11537
11538@node   About Variables, User Variables, Variables, Variables
11539@comment  node-name,  next,  previous,  up
11540@subsection About variables
11541Variables store numbers.  As it reads your program, Gri
11542substitutes variable values any place a variable appears where a number
11543normally would.  For example, in the code below @code{.number.} is a
11544variable storing the value 10, so the two @code{read} statements have
11545the same effect:
11546
11547@example
11548.number. = 10
11549read columns .number. x y
11550read columns 10 x y
11551@end example
11552
11553Variable names begin and end with a single period (example:
11554@code{.num.}).  (Gri uses this odd notation to distinguish variable
11555names from ``normal'' words, which is necessary because Gri does not
11556have a limited list of keywords as other languages do.  Thus, the C
11557programming language is happy to let you use a variable name like
11558@code{latitude}, since it is not a keyword, but Gri is not, since it
11559might like to use that word itself in a new command.)
11560
11561You should not use names beginning and ending with double periods,
11562because Gri uses names like that to store built-in variables for its own
11563use (e.g., @code{..xsize..} saves the width of the plot).
11564
11565To store a number into a variable, use a command like
11566
11567@example
11568.time. = 10
11569@end example
11570
11571@noindent
11572or
11573
11574@example
11575.time. = @{rpn 10 sin@}
11576@end example
11577
11578Storage is automatically set aside when you assign into a nonexistent
11579variable; no ``declaration'' statements are required as in the C
11580language.
11581
11582The Gri command, @code{new} (@ref{New}), allows you to have several
11583``versions'' of a variable.  This is useful for local storage in new
11584commands, inside @code{if} statements, etc, since it lets you use
11585temporary variables without worrying about overwriting values outside
11586the local block of code.  The syntax is @code{new .variable. = value}
11587(where, as usual, @code{value} may be an rpn expression
11588(@ref{rpn Mathematics}).  Here is an example:
11589
11590@example
11591`foo bar'
11592@{
11593  new .a.         # Get storage
11594  .a. = 10        # Store a local value
11595  show "Locally, .a.=" .a. " (expect 10)"
11596  delete .a.      # Delete this local one
11597@}
11598.a. = 1
11599show "Global version has .a.=" .a. " (expect 1)"
11600foo bar
11601@end example
11602
11603To see if a given named variable (or synonym) exists, use the RPN
11604operator @code{defined} (@ref{rpn Mathematics}).
11605
11606
11607@node   User Variables, Built-in Variables, About Variables, Variables
11608@comment  node-name,  next,  previous,  up
11609@subsection User variables
11610@cindex variables, defined by user
11611@cindex user-defined variables
11612You can get Gri to read values for variables from your file.  Here's how
11613to read a number from a header line and then read that many lines of
11614columnar data:
11615
11616@example
11617open file.dat
11618read .num.
11619read columns .num. x y
11620@end example
11621
11622You can define variables within the Gri program:
11623
11624@example
11625.num. = 10
11626read columns .num. x y
11627@end example
11628
11629@cindex interaction with user, @code{query} command
11630You can get variables interactively from the user, using the
11631@code{query} command.  (If the user types carriage-return, or if the
11632command-line flag @code{-y} was specified when invoking Gri, the value
11633100 will be assigned to @code{.num.}).
11634For example,
11635
11636@example
11637query .num. "Number of rows to read?" (100)
11638read columns .num. x y
11639@end example
11640
11641Gri allows you to use a previous value of the variable in the default
11642string, as in this example:
11643
11644@example
11645.start. = 8                             # default
11646.stop. = 2                              # default
11647query .start. "Start time? " (.start.)
11648query .stop.  "Stop time?  " (.stop.)
11649@end example
11650
11651Variables can be manipulated using reverse polish notation (RPN)
11652mathematical operations (@ref{rpn Mathematics}).
11653
11654Variables are often useful in @code{if} statements.  Here are some
11655examples:
11656
11657@example
11658read .num_pts.
11659if .num_pts.
11660  show "There are some data"
11661  read columns .num_pts. x y
11662else
11663  show "There are no data"
11664end if
11665# ...
11666read .latitude.
11667if @{rpn .latitude. 10 <@}
11668  read .num.
11669  read .num. x y
11670  draw curve
11671else
11672  show "Skipping data North of 10deg N"
11673  read .num.
11674  skip .num.
11675end if
11676@end example
11677
11678
11679@node   Built-in Variables, Synonyms, User Variables, Variables
11680@comment  node-name,  next,  previous,  up
11681@subsection Built-in variables
11682@cindex variables, built-in
11683@cindex built-in variables
11684Built-in variables (@ref{Index of Builtins}) have names which begin and
11685end with @strong{two} periods.  For example, @code{..xsize..} is the width
11686of the x-axis in centimetres.  You may use these variables as you wish
11687(example: @code{..xsize.. = 4} is an alternative to
11688@code{set x size 4}), but you must be aware that these are not ``free''
11689variables for you to use for arbitrary purposes.  You can find out what
11690the built-in variables are by the command @code{show variables}.
11691
11692There are two types of variables
11693@itemize @bullet
11694@item
11695@strong{Startup} variables, which are created by Gri at startup time.
11696These variables can be relied upon to exist (barring changes in Gri
11697itself), unless you @code{delete} them.
11698@item
11699@strong{Spontaneous} variables (which are created by certain Gri commands,
11700and only exist if these commands have been executed).  For example, the
11701@code{regress} command defines @code{..coeff0..} (the intercept of the
11702fitted line), @code{..coeff1..} (the slope of the fitted line),
11703@code{..R2..} (the correlation coefficient).
11704@end itemize
11705
11706To see the values of the built-in variables (along with the user
11707variables), use @code{show variables}.  Here are some useful builtin
11708variables:
11709
11710@itemize @bullet
11711
11712@item @code{..arrowsize..}
11713@cindex arrows, size of heads stored in @code{..arrowsize..}
11714@vindex @code{..arrowsize..}, size of arrows
11715Stores either a positive number representing the halfwidth of arrowheads
11716measured in centimetres, or a negative number giving the negative of the
11717ratio of arrowhead halfwidth to arrow length (@ref{Set Arrow Size}).
11718
11719@item @code{..batch..}
11720@cindex batch processing
11721@vindex @code{..batch..}, flag used for batch mode
11722Flag used for batch mode.
11723
11724@item @code{..debug..}
11725@vindex @code{..debug..}, flag used for debugging
11726@cindex debug command-line option
11727@cindex debugging, using @code{..debug..}
11728Equal to 1 if the @code{-debug} command-line flag was set.  Flag used
11729for debugging (@ref{Invoking Gri}).  The @code{..debug..}
11730built-in variable is useful in isolating code to use only in test runs.
11731For example, you might use
11732
11733@example
11734if ..debug..
11735  show "Following are the column data"
11736  show columns
11737end if
11738@end example
11739
11740When you run the program with command-line @code{gri -debug file.gri}
11741the code in the @code{if} block will print out the columnar data, but
11742when you run it with @code{gri file.gri} these lines are not printed.
11743
11744@item @code{..eof..}
11745@vindex @code{..eof..}, flag indicating end-of-file
11746Flag indicating whether an end-of-file was encountered on the last
11747@code{read columns}.
11748
11749@item @code{..words_in_dataline..}
11750@vindex @code{..words_in_dataline..}
11751@cindex reading data, checks
11752@cindex data files, words in lines
11753Number of words on last dataline.  This is useful in constructs like
11754
11755@example
11756open tmp.dat
11757.num. = 0
11758while 1
11759  read .a. .b.
11760  if !..words_in_dataline..
11761    show "Got empty line or EOF, so break loop"
11762    break
11763  end if
11764  show "a=" .a. "b=" .b.
11765  show "; words in line=" ..words_in_dataline..
11766  .num. += 1
11767end while
11768show "Got " .num. "data lines."
11769@end example
11770
11771
11772@item @code{..fontsize..}
11773@cindex font, size
11774@vindex @code{..fontsize..}, size of letters
11775Size of letters, measured in points; there are 72.27 points in an inch
11776and 28.45 points in a centimetre.  The mathematical operators
11777@code{pttocm} and @code{cmtopt}, which do conversion between points and
11778centimetres, are often useful in labelling data curves
11779(@ref{rpn Mathematics}).
11780
11781@item @code{..graylevel..}
11782@cindex gray level
11783@vindex @code{..graylevel..}, graylevel (0=black)
11784Graylevel to use in drawing lines, text, etc.  Black ink is 0; white
11785paper is 1.  @strong{See also} @code{..red..} etc.
11786
11787@item @code{..image_height..}
11788@vindex @code{..image_height..}, height of image
11789Height of image, or 0 if no image defined yet.
11790
11791@item @code{..image_width..}
11792@vindex @code{..image_width..}, width of image
11793Width of image, or 0 if no image defined yet.
11794
11795@item @code{..length_dash..}
11796@vindex @code{..length_dash..}, length/cm of dashes
11797Length in cm of dashes in dashed lines.
11798
11799@item @code{..length_blank..}
11800@vindex @code{..length_blank..}, length/cm of blanks
11801Length in cm of blanks in dashed lines.
11802
11803@item @code{..linewidth..}
11804@vindex @code{..linewidth..}, width of lines
11805Width of lines for data curves (@ref{Set Line Width}).
11806
11807@item @code{..linewidthaxis..}
11808@vindex @code{..linewidthaxis..}, width of lines on axis
11809Width of lines on axes (@ref{Set Line Width}).
11810
11811@item @code{..linewidthsymbol..}
11812@vindex @code{..linewidthsymbol..}, width of lines in symbols
11813Width of lines in symbols (@ref{Set Line Width}).
11814
11815@item @code{..missingvalue..}
11816@vindex @code{..missingvalue..}, missing value code
11817Missing value code, also stored in the synonym @code{\.missingvalue.};
11818(@ref{Set Missing Value}).
11819
11820@item @code{..num_col_data..}
11821@vindex @code{..num_col_data..}, number column data
11822Number of column data that exist.  You might want to use this after
11823@code{read columns} to see if a data file actually had any data in it,
11824or use it in accessing individual elements of columns
11825(@ref{rpn Mathematics}).
11826
11827@item @code{..publication..}
11828@cindex publication quality plots, built-in variable @code{..publication..}
11829@vindex @code{..publication..}, flag for final copy of plot
11830Flag for final copy of plot.  The command-line option @code{-p} sets the
11831value of @code{..publication..} to 1.  A typical, and highly
11832recommended, code fragment is
11833
11834@example
11835if !..publication..
11836  draw time stamp
11837end if
11838@end example
11839
11840
11841@item @code{..red..}, @code{..green..}, @code{..blue..}
11842@vindex @code{..blue..}
11843Description of present color.  The values are between 0 and 1, with
11844(0,0,0) being black and (1,1,1) being white.  If color is gray, all
11845these will be equal.  You may assign to these, but it will @strong{not}
11846change the color.
11847
11848@item @code{..symbolsize..}
11849@cindex symbol size, stored in @code{..symbolsize..}
11850@vindex @code{..symbolsize..}, size of symbols
11851Size of symbols in centimetres.
11852
11853@item @code{..superuser..}
11854@vindex @code{..superuser..}, was -superuser flag set?
11855Equal to 0 if the flag was not set, or equal to the flag if it was.
11856
11857@item @code{..tic_direction..}
11858@vindex @code{..tic_direction..}, direction of axis tics
11859Direction of axis tics, 1 for inside or 0 for outside.
11860
11861@item @code{..tic_size..}
11862@vindex @code{..tic_size..}, size/cm of axis tics
11863Size of axis tics in centimetres.
11864
11865@item @code{..trace..}
11866@vindex @code{..trace..}, for tracing program execution
11867Equal to 1 if the @code{-trace} command-line flag was set.  Used for
11868tracing program execution.
11869
11870@item @code{..xinc..}
11871@vindex @code{..xinc..}, x increment on axes
11872x increment on axes.
11873
11874@item @code{..xleft..}
11875@vindex @code{..xleft..}, x value at left of plot
11876x value at left of plot.
11877
11878@item @code{..xmargin..}
11879@cindex margins
11880@vindex @code{..xmargin..}, left margin
11881Left margin, in centimetres.
11882
11883@item @code{..xright..}
11884@vindex @code{..xright..}, x value at right of plot
11885x value at right of plot.
11886
11887@item @code{..xsize..}
11888@cindex length of axes
11889@cindex axes, length of
11890@vindex @code{..xsize..}, x-axis length
11891x-axis length in centimetres.
11892
11893@item @code{..ybottom..}
11894@vindex @code{..ybottom..}, y value at bottom of plot
11895y value at bottom of plot.
11896
11897@item @code{..yinc..}
11898@vindex @code{..yinc..}, y increment on axes
11899y increment on axes.
11900
11901@item @code{..ymargin..}
11902@vindex @code{..ymargin..}, bottom margin
11903Bottom margin in centimetres.
11904
11905@item @code{..ysize..}
11906@vindex @code{..ysize..}, y-axis length
11907y-axis length in centimetres.
11908
11909@item @code{..ytop..}
11910@vindex @code{..ytop..}, y value at top of plot
11911y value at top of plot
11912
11913@item @code{..exit_status..}
11914@vindex @code{..exit_status..}, exit status from @code{system} call
11915The exit status from the most recent @code{system} call (or 0 if no
11916system calls have been done yet).
11917@end itemize
11918
11919
11920
11921
11922
11923You may use any of these built-in variables anywhere.  For example,
11924here's how to stack 3 graphs vertically on the page:
11925
11926@example
11927.offset. = @{rpn ..ysize.. 3 + @}
11928open file1
11929read columns x y
11930close
11931draw axes
11932draw curve
11933
11934..ymargin.. += .offset.
11935open file2
11936read columns x y
11937draw axes
11938draw curve
11939close
11940
11941..ymargin.. += .offset.
11942open file3
11943read columns x y
11944draw axes
11945draw curve
11946close
11947@end example
11948
11949@cindex mathematics, rpn notation, example
11950The first line needs a bit of explanation. It is a reverse-polish
11951expression.  The format is @code{@{} followed by @code{rpn} followed by
11952an expression followed by @code{@}}.  Within the expression, spaces must
11953separate operands.  This makes @code{.offset.} equal to the height of
11954y-axis plus 3 cm, so plots are separated by 3 cm.  To learn more about
11955@code{@{rpn ... @}} (@ref{rpn Mathematics}).
11956
11957Another possibly unfamiliar thing is the code @code{+=}.  It means take
11958the thing on the left hand side, and add to it the thing on the right
11959hand side.  (In this case, it is used to increase the y margin by the
11960value of @code{.offset.}.)
11961
11962
11963@c HTML <!-- newfile Synonyms.html "Gri: synonyms" "Programming Gri" -->
11964
11965@node   Synonyms, Naming Convention, Built-in Variables, Programming
11966@comment  node-name,  next,  previous,  up
11967@section Synonyms
11968@cindex character variables (synonyms)
11969@cindex synonyms, for storing character strings
11970@cindex programming, synonyms
11971@cindex synonyms, naming convention
11972Synonyms are used by Gri to store character strings.  Gri denotes
11973synonyms with words beginning with backslash (e.g., @code{\syn}),
11974following the @TeX{} convention.
11975
11976@menu
11977* Naming Convention::             Their names with a backslash, e.g. @code{\syn}
11978* Using Synonyms::                Some usage examples
11979* Important Builtin Synonyms::    e.g. @code{\.command_file.}
11980* Alias Synonyms::                e.g. @code{\@@alias}
11981* Local Synonyms::                Working with the arguments of newcommands
11982@end menu
11983
11984
11985@node   Naming Convention, Using Synonyms, Synonyms, Synonyms
11986@comment  node-name,  next,  previous,  up
11987@subsection Naming convention for synonyms
11988@cindex naming convention for synonyms
11989@cindex synonyms, naming convention
11990
11991Synonym names begin with a backslash (e.g., @code{\filename}).  After
11992the backslash, Gri expects a letter (upper or lower case) or one or more
11993periods.  Following this is an arbitrary string of letters, numbers, or
11994underscores.  If there are periods at the start, then the same number of
11995periods must be used at the end.  The following are some examples
11996@example
11997\simple = "Howdie"
11998\.longer_example. = "Dots and underscores are ok too"
11999\a2 = "OK for number at end ..."
12000\a3bb = "... and inside"
12001@end example
12002
12003Gri defines several synonyms for its own use, so that if you modify
12004these, you may get strange results.  Each of these starts and ends with
12005a single period.
12006
12007There is an exception to the above rule, one which mostly comes up when
12008using netCDF files which may have variable names that may contain
12009punctuation.  Gri permits synonym names to have punctuation characters
12010(but not blanks or tabs) in synonym names, provided that the second
12011character in the name is an opening brace and that the last character is
12012a closing brace, e.g.
12013
12014@example
12015\@{foo.bar@} = "Foo bar"
12016@end example
12017
12018@noindent  This is used particularly for files in the netCDF format,
12019for reading variable attributes, which by netCDF convention use a colon
12020(@code{:}) to separate variable name and attribute name (@ref{Read
12021Synonym or Variable}).  For more information on netCDF format, see
12022
12023@code{http://www.unidata.ucar.edu/packages/netcdf/index.html}
12024@c HTML <a href="http://www.unidata.ucar.edu/packages/netcdf/index.html">
12025@c HTML here </a>.
12026
12027Synonyms may be freely embedded in strings (a common example is
12028@code{draw title "Data from file `\datafile'"}.  They may also appear
12029anywhere in commands (e.g., @code{open \filename}).  The exception to
12030this rule is that Gri ignores your synonyms within math mode, in order
12031to prevent clashes (e.g. you might define @code{\alpha} as a synonym
12032storing the value @code{"foo bar"}, but Gri will ignore this within
12033math-mode, so that @code{$\alpha$} will still mean the Greek letter
12034alpha).
12035
12036To get a backslash in a string without Gri thinking it is part of a
12037synonym, use two backslashes (e.g.,
12038@code{show "The backslash character \\ is used for synonyms."}).  This
12039may sometimes be required in
12040@code{system}
12041commands (@ref{System}), to prevent Gri from converting
12042substrings like @code{\n} (which many system commands use to represent
12043the newline character).  For example, the command
12044@code{system perl -e 'print "foo\nbar";'} will be mangled if Gri has
12045already been told that
12046@code{\nbar} is a synonym.  (There will be no problem if @code{\nbar} is
12047not an existing synonym, since Gri will then just leave it in place.)
12048To be sure that no mangling can occur, replace each backslash with two
12049backslashes.  This tells Gri not to try to substitute a synonym at that
12050location.  In the example below, the first system call prints
12051@code{fooled you!} on one line line, because Gri substituted for what it
12052thought was a synonym called @code{\nbar}; the second (correctly) prints
12053@code{foo} on one line and @code{bar} on the next.
12054@cindex @code{system} command, how to get a tab
12055@cindex @code{system} command, how to get a newline
12056@cindex tab, in a @code{system} command
12057@cindex newline, in a @code{system} command
12058
12059@example
12060\nbar = "led you!"
12061system perl -e 'print "foo\nbar\n";'
12062system perl -e 'print "foo\\nbar\\n";'
12063@end example
12064
12065Similarly, if your system command is expecting to see @code{\t} (for a
12066tab character), then you must write @code{\\t} to prevent Gri from
12067trying to substitute a synonym named @code{\t}.
12068
12069The @code{show} command has a special syntax for permitting newlines and
12070tabs in strings (@ref{Show}).
12071
12072
12073@node   Using Synonyms, Generalizing Code, Naming Convention, Synonyms
12074@comment  node-name,  next,  previous,  up
12075@subsection Some uses for synonyms
12076@cindex character variables (synonyms)
12077@cindex synonyms, extracting individual words from
12078@cindex synonyms, assigning values to
12079@cindex synonyms, constructing using the operating system
12080@cindex user-defined synonyms
12081@cindex synonyms, for storing output from system commands
12082@cindex operating system commands, assigned to synonyms
12083@cindex system commands, assigned to synonyms
12084@cindex operating system, example of using to construct filenames
12085@cindex system commands, example of using to construct filenames
12086@cindex filenames, constructing using the operating system
12087
12088Synonyms store strings and are useful for anything strings are useful
12089for, e.g. filenames, plot labels, names of variables, etc.
12090
12091@menu
12092* Generalizing Code::
12093* Storing OS Output::
12094* Storing User Responses::
12095* Storing File Contents::
12096* Extracting Words From Strings::
12097@end menu
12098
12099@node   Generalizing Code, Storing OS Output, Using Synonyms, Using Synonyms
12100@comment  node-name,  next,  previous,  up
12101@subsubsection Using synonyms to generalize code
12102
12103Synonyms are often used to store filenames, since then only a single
12104line of a file may need to be altered, in order to work with another
12105file, e.g.
12106
12107@example
12108\filename = "columns.dat"
12109open \filename
12110# a lot more code using the file name
12111@end example
12112
12113
12114@node   Storing OS Output, Storing User Responses, Generalizing Code, Using Synonyms
12115@comment  node-name,  next,  previous,  up
12116
12117@subsubsection Using synonyms to store OS output
12118Synonyms provided a convenient way to store information from the OS.
12119
12120@example
12121# Show the date.
12122\date = system date
12123show "Time is \date"
12124
12125# Show the command file name, then use the system
12126# to construct a filename with the same beginning
12127# but ".dat" as the ending instead of ".gri".
12128show "The commandfile name is \.command_file."
12129\fn = system echo `basename \.command_file. .gri`.dat
12130show "A filename constructed from this is \fn"
12131@end example
12132
12133This example uses the Unix system commands @code{echo} and
12134@code{basename} to  construct a filename ending in @file{.dat}, from the
12135command file name (stored in the builtin string @code{\.command_file.}),
12136assuming that the command file name ends in @file{.gri}.
12137
12138NOTE: As usual, if the system command contains the Gri comment
12139designator (the string @code{#}), protect it with double-quotes
12140(@ref{System}).
12141
12142
12143@node   Storing User Responses, Storing File Contents, Storing OS Output, Using Synonyms
12144@comment  node-name,  next,  previous,  up
12145
12146@subsubsection Storing user responses via @code{query}
12147
12148You can ask the user for the contents of strings:
12149@cindex interaction with user, @code{query} command
12150
12151@example
12152query \filename "What's the data file?" ("file.dat")
12153@end example
12154
12155@noindent
12156The prompt @code{What's the name of the data file?} is typed to the
12157terminal, and whatever string the user types is inserted into the
12158synonym @code{\filename}. If the user types nothing, but simply presses
12159carriage return, the (optional) default string (which must be enclosed
12160in parentheses as shown) is put into @code{\filename}. Note that the
12161default is ignored if it is not written properly: it must be enclosed in
12162double quotes enclosed in parentheses, with no intervening spaces.
12163
12164
12165@node   Storing File Contents, Extracting Words From Strings, Storing User Responses, Using Synonyms
12166@comment  node-name,  next,  previous,  up
12167
12168@subsubsection Storing File Contents
12169You can read the contents of synonyms from a file:
12170
12171@example
12172open \directory_file
12173read \file_name
12174close
12175open \file_name
12176read columns x y
12177@end example
12178
12179@noindent
12180The first (space-separated) word is read into the the first synonym after
12181the @code{read} command, the second word into the second synonym, and so on.
12182If the word you want is not near the front of the line, you can use the command
12183@code{read line} to get the whole line, then use the method described above
12184to extract the word you want.  Indexing begins with 0, remember.
12185
12186
12187@node   Extracting Words From Strings, Important Builtin Synonyms, Storing File Contents, Using Synonyms
12188@comment  node-name,  next,  previous,  up
12189
12190@subsubsection Working with words within strings
12191
12192Sometimes a synonym will contain several words that you need to work
12193with indidually (e.g. it might contain a list of files that should be
12194processed).  There are two ways to do this.
12195
12196@table @emph
12197
12198
12199@item The @code{word of} syntax.
12200@example
12201\sentence = "This sentence has five words"
12202\first_word = word 0 of "\sentence"
12203\last_word = word 4 of "This sentence has five words"
12204@end example
12205
12206
12207@item The @code{[]} syntax
12208@cindex @code{[]} syntax for selecting words in synonyms
12209Individual words of synonyms may be accessed by prefixing the synonym
12210name with the index number of the word (starting at 0) enclosed in
12211square brackets.
12212
12213The number in the square brackets may be a constant, a variable, or a
12214synonym, but not a more complicated expression.  If the index value is a
12215floating-point number, it is first rounded to the nearest integer.  If
12216the index value is negative or exceeds the number of words minus 1, then
12217an empty string is retrieved.
12218
12219If @strong{no number} appears in the square brackets, the result is the
12220number of words in a synonym.
12221
12222@example
12223\syn = "This has 4 words in it"
12224show "\[0]syn   ... gives 'This'"
12225show "\[1]syn   ... gives 'has'"
12226.i. = 3
12227show \[.i.]syn  ... gives 'words'"
12228\i = "3"
12229show \[\i]syn   ... gives 'words'"
12230show "\[]syn    ... gives '6', i.e. number of words"
12231@end example
12232
12233@end table
12234
12235
12236
12237
12238@node   Important Builtin Synonyms, Alias Synonyms, Extracting Words From Strings, Synonyms
12239@comment  node-name,  next,  previous,  up
12240@subsection Some important builtin synonyms
12241@cindex synonyms, global
12242@cindex global synonyms
12243@cindex built-in synonyms, global
12244@cindex global built-in synonyms
12245@cindex synonyms, built-in, list of
12246@cindex return value, @code{\.return_value.}
12247@vindex @code{\.return_value.}, Return value
12248@vindex @code{\.ps_file.}, PostScript file name
12249@vindex @code{\.readfrom_file.}, data file name
12250@vindex @code{\.command_file.}, command-file name
12251@vindex @code{\.missingvalue.}, command-file name
12252@vindex @code{\.home.}, home directory
12253@vindex @code{\.system.}, operating system name
12254@vindex @code{\.user.}, user's login name
12255@vindex @code{\.time.}, time and date
12256@cindex directory, stored in synonym @code{\.wd.}
12257@cindex working directory, stored in synonym @code{\.wd.}
12258@cindex @code{\.wd.} synonym, storing working directory
12259@vindex @code{\.wd.}, working directory
12260@vindex @code{\.version.}, version of Gri
12261@vindex @code{\.pid.}, process ID of job
12262Within mathematics mode (portions of strings enclosed within
12263dollar-signs), Gri stores the definitions of many Greek letters and
12264mathematical symbols as math-mode synonyms (@ref{Mathematical Text}).
12265
12266Global synonyms are shared among commands.  To see the built-in global
12267synonyms (@ref{Index of Builtins})
12268use @code{show synonyms}, which
12269produces output that looks something like the following.
12270
12271@example
12272Synonyms...
12273    \.missingvalue.           = "10000000000000000000000.000000"
12274    \.return_value.           = ""
12275    \.version.                = "2.7.0"
12276    \.pid.                    = "3043"
12277    \.wd.                     = "/home/kelley"
12278    \.time.                   = "Sun May 20 13:18:32 2001"
12279    \.user.                   = "kelley"
12280    \.host.                   = "Intrusion.phys.ocean.dal.ca"
12281    \.system.                 = "unix"
12282    \.home.                   = "/home/kelley"
12283    \.lib_dir.                = "/usr/share/gri"
12284    \.command_file.           = "stdin"
12285    \.readfrom_file.          = "stdin"
12286    \.ps_file.                = "gri-00.ps"
12287    \.path_data.              = "."
12288    \.path_commands.          = "."
12289@end example
12290
12291@cindex time
12292@cindex date
12293@cindex @code{\.return_value.}, general
12294These things will be obvious to unix users; for example
12295@code{\.pid.} is the process ID of the job (often used in names for
12296temporary files), and @code{\.wd.} is the working directory (often used
12297in @code{draw title} commands to indicate in which directory the gri job
12298was run.
12299
12300Some commands set @code{\.return_value.} to non-blank; the
12301meaning of the return value varies from command to command.
12302
12303
12304
12305
12306
12307@node   Alias Synonyms, Local Synonyms, Important Builtin Synonyms, Synonyms
12308@comment  node-name,  next,  previous,  up
12309@subsection Alias synonyms: the @code{\@@alias} syntax
12310@cindex alias synonyms, with the @code{\@@alias} notation
12311@cindex @code{\@@alias} notation
12312@cindex synonyms, aliasing with the @code{\@@alias} notation
12313
12314Sometimes you need to work with a variable or a synonym whose name can
12315only be determined at run-time, perhaps through interaction with the
12316user, examination of a datafile, or examination of the command provided
12317to the OS when invoking Gri.
12318
12319Gri handles this by so-called "alias" synonyms, which store the names of
12320other items.
12321
12322The syntax is simple.  Suppose that a synonym, called @code{\pointer}
12323say, contains the @strong{name of} another synonym, or a variable.  Then
12324you may use @code{\@@pointer} anyplace you would normally use the item
12325named.
12326
12327@table @emph
12328
12329@item Illustrations of using the value of a named item
12330The following prints an approximation to Pi followed by the name of
12331movie star.
12332@example
12333.pi. = 3.14
12334\pi_pointer = ".pi."
12335show \@@pi_pointer  # just like 'show .pi.'
12336
12337\hero = "Gregory Peck"
12338\our_hero = "\\hero"
12339show "\@@our_hero"  # just like 'show "\hero"'
12340@end example
12341
12342
12343@item Illustrations of assigning to a named item
12344The following prints an approximation to 2*Pi and yet another star; the
12345point is that the alias appears to the left of an assignment operator.
12346@example
12347# Print approximation to 2*Pi
12348.pi. = 3.14
12349\pi_pointer = ".pi."
12350\@@pi_pointer *= 2
12351show .pi.
12352
12353# Stars don't shine alone
12354\hero = "Gregory Peck"
12355\our_hero = "\\hero"
12356\@@our_hero = "Harrison Ford"
12357show "\hero"
12358@end example
12359
12360@end table
12361
12362
12363
12364@node   Local Synonyms, If Statements, Alias Synonyms, Synonyms
12365@comment  node-name,  next,  previous,  up
12366@subsection Local synonyms
12367@cindex synonyms, local
12368@cindex local synonyms
12369@vindex @code{\.proper_usage.}
12370@vindex @code{\.words.}
12371@vindex @code{\.word0.}
12372@vindex @code{\.word1.}
12373@cindex built-in synonyms, local
12374@cindex local built-in synonyms
12375@cindex command lines, parsing in new Gri commands
12376@cindex programming, parsing command lines
12377@cindex programming, using local built-in synonyms
12378Local synonyms are created by Gri upon entry to a Gri command.  You use
12379them to parse the command line that was used in calling the new command,
12380to look for options, gather filenames, etc.  Local synonyms are known
12381only from within the local Gri command.  They are not listed by
12382@code{show synonyms}, but they can be used freely in commands like
12383@code{show "Number of words is \.words."}.
12384
12385@itemize @bullet
12386@item
12387Within any new Gri command, the number of words in the line that called
12388the command is available in @code{\.words.}.  The RPN operator @code{wordc}
12389also yields the same value (@ref{Solitary Operators}).
12390@item
12391The first word in the calling line is @code{\.word0.}, the second
12392@code{\.word1.}, etc.  (Note that this is the C convention, @strong{not} the
12393FORTRAN convention.  If @code{\.words.} is 2, then @code{\.word0.} and
12394@code{\.word1.} are defined, but @code{\.word2.}, which FORTRAN programmers
12395expect, will not be defined.)  If you don't know the place of the synonym
12396in advance (i.e. 0 versus 1, for @code{\.word0.} versus @code{\.word1.}),
12397then use the RPN operator @code{wordv} instead (@ref{Unary Operators}).
12398@item
12399Within any new Gri command, the proper calling usage is available in
12400@code{\.proper_usage.}.  This is useful in tests of syntax
12401(@ref{Adding New Commands}).  For example:
12402
12403@example
12404`draw depths from \file'
12405Draw depth data stored in indicated file.  If the
12406filename contains periods or slashes, you'll
12407have to enclose it in double quotes, as
12408in the second example:
12409  draw depths from file upper_cove
12410  draw depths from file ../old_data/upper_cove
12411@{
12412  if @{rpn \.words. 4 !=@}
12413    show "FATAL ERROR in `\.proper_usage.':"
12414    show "  Need 4 words; got \.words. words."
12415    quit
12416  end if
12417  # Right number of words, so continue onward...
12418@}
12419@end example
12420
12421@end itemize
12422These synonyms help you scan for optional words in commands.  Suppose
12423you have defined a new command @code{New Thing [option]}.  If you call
12424it with @code{New Thing}, then (within @code{New Thing}) @code{\.words.}
12425will be @code{"2"}, @code{\.word0.} will be @code{"New"} and @code{\.word1.}
12426will be @code{"Thing"}.  On the other hand, if you call it with
12427@code{New Thing 22.3} then @code{\.words.} will be @code{3},
12428@code{\.word0.} will be @code{"New"}, @code{\.word1.} will be
12429@code{"Thing"} as before, and @code{\.word2.} will be @code{"22.3"}.
12430
12431@strong{EXAMPLE}  Here is a new command to label lines drawn by
12432@code{draw curve}:
12433
12434@example
12435`Draw Label For Last Curve "label"'
12436Draw a label for the last curve drawn, using
12437..xlast.. and ..ylast.. built-in variables.
12438@{
12439  new .draw_label_for_last_curve_graylevel.
12440  .draw_label_for_last_curve_graylevel. = ..graylevel..
12441  set graylevel 0
12442  draw label "\.word5." at \
12443      @{rpn ..xlast.. xusertocm 0.1 + xcmtouser@} \
12444      @{rpn ..ylast.. yusertocm \
12445          ..fontsize.. pttocm 2 / -
12446          ycmtouser@}
12447  set graylevel .draw_label_for_last_curve_graylevel.
12448  delete .draw_label_for_last_curve_graylevel.
12449@}
12450open file.dat
12451read columns x y
12452draw curve
12453\label = "Illustration"
12454Draw Label For Last Curve "\label"
12455@end example
12456
12457@noindent
12458(Note that Gri has a built-in command
12459@code{draw label for last curve "\label"} written much as above, so
12460there is no need for you to enter
12461this new command into your @file{.grirc} file.  But you might want to
12462check @file{gri.cmd} to see how a full
12463command does checking of the calling syntax
12464(@ref{Invoking Gri}).
12465
12466
12467@c HTML <!-- newfile IfStatements.html "Gri: if statements" "Programming Gri" -->
12468
12469@node   If Statements, Loops, Local Synonyms, Programming
12470@comment  node-name,  next,  previous,  up
12471@section If Statements
12472@cindex programming, if statements
12473@cindex if statements
12474Gri has @code{if} statements to make your programs more flexible.
12475Here's an example:
12476@cindex interaction with user, @code{query} command
12477
12478@example
12479query \thick "Use thick lines? (0 or 1)" ("0")
12480if \thick
12481  set line width 2
12482else
12483  set line width 0.5
12484end if
12485@end example
12486
12487@noindent
12488If you answer 1 to the question, the line thickness will be set at 2
12489points.  If you answer 0 then a thin line will be used.  If you press
12490carriage return a thin line will be used.
12491
12492The item following the @code{if} can be
12493@itemize @bullet
12494@item
12495a number (1 means true; anything else means false)
12496@item
12497a variable (1 means true; anything else means false). Example:
12498
12499@example
12500if .plot_contours.
12501  draw contour
12502end if
12503@end example
12504
12505@item
12506a synonym which expands to a number (1 means true; anything else means
12507false). Example:
12508
12509@example
12510\plot_contours = "1"
12511if \plot_contours
12512  draw contour
12513end if
12514@end example
12515
12516(Don't worry about the fact that synonyms are strings; Gri
12517expands the string value before interpreting the @code{if} statement.)
12518@item
12519an expression of the form @code{@{string1 == string2 @}}.  The symbol
12520@code{==} is an operator which tests for string equality.  This expands
12521to @code{1} if the strings are equal, or @code{0} otherwise.  The
12522strings may be either synonyms or string constants.  If the string
12523constant contains only one word, then it is not necessary to enclose it
12524in quotes, but it is clearer to do so.  Examples:
12525@cindex labels, on axes
12526
12527@example
12528if @{"\variable" == "Salinity"@}
12529  set x name "Salinity"
12530else
12531  set x name "Unknown"
12532end if
12533@end example
12534
12535@item
12536a rpn (reverse polish notation) expression
12537(@ref{rpn Mathematics}):
12538
12539@example
12540if @{rpn .time. 100 <@}
12541  # ie, (100 < time), not (time < 100)
12542  show "Time > 100"
12543else if @{rpn .time. 100 >@}
12544  show "Time < 100"
12545else if @{rpn "\item" "later" ==@}
12546  show "Time ... later babe"
12547else
12548  show "Time is equal to 100"
12549end if
12550if @{rpn .time. 10 * 100 ==@}
12551  show "Time is equal to 10"
12552else
12553  show "Time is not equal to 10"
12554end if
12555@end example
12556
12557@end itemize
12558
12559There is no need to put the else part in if you don't need it. You
12560can do
12561
12562@example
12563set line width 0.5
12564if \use_thick_lines
12565  set line width 2
12566end if
12567@end example
12568
12569@noindent
12570if you wish.
12571
12572If you want just the else part, you can do
12573
12574@example
12575if ! \use_thick_lines
12576  set line width 0.5
12577end if
12578@end example
12579
12580(The exclamation point denotes logical negation: @code{! true} equals
12581@code{false}.)
12582
12583If statements may be nested many levels deep.  You may also have
12584@code{else if} blocks, as in:
12585
12586@example
12587if @{"\variable" == "S"@}
12588  set x name "Salinity"
12589  set x axis 32 33 0.5 .1
12590else if @{"\variable" == "T"@}
12591  set x name "Temperature"
12592  set x axis 15 20 1 0.5
12593else
12594  set x name "Unknown"
12595end if
12596@end example
12597
12598
12599@c HTML <!-- newfile Loops.html "Gri: Loops" "Programming Gri" -->
12600@node   Loops, Mathematics, If Statements, Programming
12601@comment  node-name,  next,  previous,  up
12602@section Loops
12603Gri provides only one type of loop, the @code{while} loop, described
12604elsewhere (@ref{While}).
12605
12606
12607@c HTML <!-- newfile Mathematics.html "Gri: Mathematics" "Programming Gri" -->
12608
12609@node   Mathematics, rpn Mathematics, Loops, Programming
12610@comment  node-name,  next,  previous,  up
12611@section Mathematics
12612Gri lets you do some simple mathematical manipulations on your
12613column and grid data.
12614
12615@subsection Column data
12616@cindex column mathematics
12617@cindex mathematics, on columns
12618@cindex powers, of columns or variables
12619@cindex exponentiation
12620@cindex logarithms
12621The column operators are @code{=}, @code{+=}, @code{-=}, @code{*=},
12622@code{/=}, @code{^=} (exponentiation) and @code{_=} (logarithm).  There
12623must be spaces before and after the operators, but no space between the
126242 letters of the operators. The operations may be applied not only to
12625@code{x} and @code{y} as shown, but also to @code{z} (used to hold data
12626to be contoured or written as symbols), and @code{u} and @code{v} (used
12627to store vector fields).
12628
12629The axis scales are @strong{not} changed by mathematical operations on the
12630columns, regardless of whether the scales were set manually or by Gri
12631command (@ref{Axis Scaling}).
12632
12633Elements of columns are available by the @code{@@} reverse polish
12634operator (@ref{rpn Mathematics}).
12635
12636Examples:
12637@itemize @bullet
12638@item
12639To multiply all the x data by 10, use @code{x *= 10}; to add 5 to each
12640y-value, use @code{y += 5}.
12641@item
12642To set all the y data to 10, do @code{y = 10}.  (This will only work if
12643you've already read column data.)
12644@end itemize
12645
12646See also @ref{Tertiary Operators} for a method of assigning or altering column data
12647using the RPN operator.
12648
12649@subsection Grid data
12650@cindex grid data mathematical operations
12651@cindex mathematics, on grid data
12652Various commands let you alter grid data as used in contouring
12653(@ref{Contour Plots}).  Possible commands are as follows.
12654
12655@example
12656grid data = number
12657grid data += number
12658grid data -= number
12659grid data *= number
12660grid data /= number
12661grid data ^= number # take data to power 'number'
12662grid data _= number # take log base 'number'
12663grid x = number
12664grid x += number
12665#... others as in `grid data'
12666grid y = number
12667grid y += number
12668#... others as in `grid data'
12669@end example
12670
12671
12672@subsubsection Image data
12673@cindex image mathematical operations
12674@cindex mathematics, on images
12675Various commands let you alter image data (@ref{Images}.).
12676Possible commands are as follows.
12677
12678@example
12679image += number
12680image -= number
12681image *= number
12682image /= number
12683image ^= number # power
12684image _= number # logarithm
12685@end example
12686
12687@subsubsection Image grayscale/colorscale
12688@cindex colorscale modification
12689@cindex grayscale modification
12690@cindex image grayscale/colorscale modification
12691@cindex mathematics, on image grayscale/colorscale
12692Various commands let you alter image data (@ref{Images}).
12693Possible commands are as follows.
12694
12695@example
12696image grayscale += number
12697image grayscale  -= number
12698image grayscale  *= number
12699image grayscale  /= number
12700image grayscale  ^= number # power
12701image grayscale  _= number # logarithm
12702image colorscale += number
12703image colorscale  -= number
12704image colorscale  *= number
12705image colorscale  /= number
12706image colorscale  ^= number # power
12707image colorscale  _= number # logarithm
12708@end example
12709
12710@subsubsection Variables
12711@cindex scalar operations
12712@cindex mathematics, on variables
12713Possible commands are:
12714
12715@example
12716.variable. = number
12717.variable. += number
12718.variable. -= number
12719.variable. *= number
12720.variable. /= number
12721.variable. ^= number # power
12722.variable. _= number # logarithm
12723@end example
12724
12725
12726@c HTML <!-- newfile ReversePolishMath.html "Gri: Reverse Polish Mathematics" "Programming Gri" -->
12727
12728@page
12729
12730@node   rpn Mathematics, Stack Operators, Mathematics, Programming
12731@comment  node-name,  next,  previous,  up
12732@section Rpn (reverse-polish notation) Calculator
12733@cindex examples of @code{rpn} mathematics
12734@cindex @code{rpn} mathematics, examples
12735@cindex mathematics, @code{rpn} notation, description
12736Gri can do simple mathematics on numbers.  The syntax is reverse-polish
12737notation (@code{rpn}), which is used in some calculators.  Most users
12738can learn rpn in a few minutes, so don't worry if you don't know RPN
12739yet.
12740
12741@strong{Syntax}: rpn expressions can be used anywhere Gri expects a number.
12742RPN expressions start with a opening curly brace (@code{@{}) which is
12743immediately followed by the word @code{rpn}.  rpn expressions end with a
12744closing curly brace (@code{@}}).  Instead of @code{set x size 10} you
12745could write @code{set x size @{rpn 20 2 /@}}, where the expression
12746@code{@{rpn 20 2 /@}} tells Gri to insert the number 20 onto a stack,
12747then insert the number 2 above it on the stack, and then divide the top
12748two items on the stack.  The following are equivalent:
12749
12750@example
12751set x size @{rpn 20 2 /@}           # 10 = 20/2
12752set x size @{rpn 30 2 / 5 -@}       # 10 = (30/2-5)
12753set x size @{rpn pi 3.1415 / 10 *@} # 10 = 10*pi/pi
12754@end example
12755
12756If an rpn expression contains a variable whose value is ``missing'',
12757then the value of the result of the expression will also be missing
12758(unless the value of the missing variable is thrown away with a
12759``pop'' operator).  However, if a missing value just happens to occur
12760as the result of an intermediate calculation, then the result is not
12761considered to be missing.
12762
12763RPN operations can be divided roughly into the following groups.
12764
12765@menu
12766* Stack Operators::             Operate on the rpn stack
12767* Rpn Functions::               Define a new rpn operator
12768* Tertiary Operators::          Act on top three items on stack
12769* Binary Operators::            Act on top two items on stack
12770* Unary Operators::             Act on top item on stack
12771* Solitary Operators::          Act alone
12772* Manipulation of Columns etc:: Act on data columns
12773* rpn Examples::                A few examples
12774@end menu
12775
12776@c HTML <!-- newfile StackOperators.html "Gri: RPN stack operators" "Programming Gri" -->
12777
12778@node   Stack Operators, Rpn Functions, rpn Mathematics, rpn Mathematics
12779@comment  node-name,  next,  previous,  up
12780@subsection Stack Operators
12781@cindex @code{pop} rpn stack operator
12782@cindex rpn stack operator @code{pop}
12783@cindex @code{dup} rpn stack operator
12784@cindex rpn stack operator @code{dup}
12785@cindex @code{exch} rpn stack operator
12786@cindex rpn stack operator @code{exch}
12787@cindex @code{roll_left} rpn stack operator
12788@cindex rpn stack operator @code{roll_left}
12789@cindex @code{roll_right} rpn stack operator
12790@cindex rpn stack operator @code{roll_right}
12791@cindex @code{pstack} rpn stack operator
12792@cindex rpn stack operator @code{pstack}
12793
12794Stack operators manipulate or display the stack.
12795
12796@code{pop} removes the top item from the stack (@ref{Unary Operators}).
12797
12798@code{dup} duplicates the top item on the stack (@ref{Unary Operators}).
12799
12800@code{exch} reorders the top two items on the stack (@ref{Binary Operators}).
12801
12802@code{pstack} prints the items on the stack (without changing the
12803stack).
12804
12805@code{roll_right} rolls the items to the right.
12806
12807@code{roll_left} rolls the items to the left.
12808
12809For example, the following shows how you might use @code{exch} or
12810@code{roll_right} to change the sense of a subtraction.
12811
12812@example
12813show @{rpn 1 2            -@} " ... yields -1"
12814show @{rpn 1 2 exch       -@} " ... yields  1"
12815show @{rpn 1 2 roll_right -@} " ... yields  1"
12816@end example
12817
12818
12819
12820@c HTML <!-- newfile RpnFunction.html "Gri: RPN functions" "Programming Gri" -->
12821
12822@node   Rpn Functions, Tertiary Operators, Stack Operators, rpn Mathematics
12823@comment  node-name,  next,  previous,  up
12824@subsection Rpn function Operators
12825@code{rpnfunction} operators are user-defined operators.  The parser
12826replaces any such operator with the user-defined rpn expression.  The
12827@code{rpnfunction} operators are both general and powerful.  An
12828@code{rpnfunction} may be composed of any legal primitive rpn constructs
12829or even other legal @code{rpnfunction} constructs.  For details,
12830(@ref{Rpnfunction}).
12831
12832
12833@c HTML <!-- newfile TertiaryOperators.html "Gri: tertiary operators" "Programming Gri" -->
12834
12835@node   Tertiary Operators, Binary Operators, Rpn Functions, rpn Mathematics
12836@comment  node-name,  next,  previous,  up
12837@subsection Tertiary Rpn Operators
12838@table @code
12839
12840
12841@item @{rpn 0 4 "hello" substr @}
12842@cindex RPN operator @code{substr}
12843@cindex substrings, getting with RPN operator @code{substr}
12844@cindex @code{substr} RPN operator
12845Extract 4 characters from the indicated string, starting at character
12846number 0 (i.e. the start of the string).  In other words, replace the
12847three items on the top of the stack with the single item
12848@code{\"hell\"}.
12849@end table
12850
12851
12852@c HTML <!-- newfile BinaryOperators.html "Gri: RPN binary operators" "Programming Gri" -->
12853
12854@node   Binary Operators, Unary Operators, Tertiary Operators, rpn Mathematics
12855@comment  node-name,  next,  previous,  up
12856@subsection Binary Operators
12857
12858@cindex binary operators in rpn expressions
12859@cindex logical operators in rpn expressions
12860@cindex comparison operators in rpn expressions
12861@cindex @code{<} comparison operator in rpn expressions
12862@cindex @code{>} comparison operator in rpn expressions
12863@cindex @code{==} comparison operator in rpn expressions
12864@cindex mathematical operators in rpn expressions
12865@cindex conversion between user and page units
12866@cindex page units, converting to user units
12867@cindex user units, converting to page units
12868@cindex larger of two numbers, rpn operator @code{sup}
12869@cindex smaller of two numbers, rpn operator @code{inf}
12870@cindex rpn operator @code{sup}, finds larger of pair
12871@cindex rpn operator @code{inf}, finds smaller of pair
12872@cindex @code{sup} rpn operator, finds larger of pair
12873@cindex @code{inf} rpn operator, finds smaller of pair
12874
12875Binary operators act on the @strong{top two} items on the stack.  Most
12876binary operators replace two items on the stack with one item, e.g.
12877@code{@{rpn 1 2 /@}} yields 0.5.  However, a few binary operators
12878replace one pair of items with a new pair of items, e.g. the
12879@code{xyusertocm} operator replaces an (x,y) pair in user coordinates
12880with an (xcm,ycm) pair in coordinates of centimeters on the page.
12881
12882The binary operators are illustrated below, in rough alphabetical order.
12883
12884@table @code
12885
12886@item @{rpn 3 2 +@}
12887@cindex @code{+} rpn operator
12888@cindex rpn operator @code{+}
12889Add 2 to 3.
12890
12891@item @{rpn 3 2 -@}
12892@cindex @code{-} rpn operator
12893@cindex rpn operator @code{-}
12894Subtract 2 from 3.
12895
12896@item @{rpn 3 2 *@}
12897@cindex @code{*} rpn operator
12898@cindex rpn operator @code{*}
12899Multiply 3 by 2.
12900
12901@item @{rpn 3 2 /@}
12902@cindex @code{/} rpn operator
12903@cindex rpn operator @code{/}
12904Divide 3 by 2.
12905
12906@item @{rpn 3 2 <@}
12907@cindex @code{<} rpn operator
12908@cindex rpn operator @code{<}
12909@cindex HP calculators, RPN notation different from
12910@cindex RPN notation, difference from old-series HP calculators
12911
12912Test whether 2 is less than 3, yielding 1.  Note: this convention may
12913be confusing to users who are familiar with HP calculators from
12914decades past.  Present-day calculators use this convention, but
12915possibly older calculators used the reverse convention, using @code{>}
12916where Gri uses @code{<}.
12917
12918
12919@item @{rpn 3 2 <=@}
12920@cindex @code{<=} rpn operator
12921@cindex rpn operator @code{<=}
12922Test whether 2 is less than or equal to 3.
12923
12924
12925@item @{rpn 3 2 >@}
12926@cindex rpn operator @code{>}
12927Test whether 2 is greater than 3, yielding 0.
12928
12929
12930@item @{rpn 3 2 >=@}
12931@cindex @code{>=} rpn operator
12932@cindex rpn operator @code{>=}
12933Test whether 2 is greater than or equal to 3, yielding 0.
12934
12935
12936@item @{rpn 3 2 ==@}
12937@cindex rpn operator @code{==}
12938Test whether 2 and 3 are equal, yielding 0.  (Do not confuse this with
12939the asignment operator @code{=}, described next.)
12940
12941
12942@item @{rpn 10 ".ten." =@}
12943@cindex @code{=} rpn operator assigns to variables, synonyms, and columns
12944@cindex rpn operator @code{=}
12945@cindex assigning to columns, variables and synonyms within RPN expressions
12946@cindex variables, assigning within RPN expressions
12947@cindex synonyms, assigning within RPN expressions
12948@cindex columns, assigning within RPN expressions
12949@cindex column dat, assigning within RPN expressions
12950
12951Assign the value @code{10} to the variable named @code{.ten.}.  The
12952variable name must be put in quotes, or else Gri will insert the value
12953of the variable (if it exists) into the expression, instead of trying
12954to assign to it.
12955
12956After the assignment is done, the stack is cleared of both the value and
12957the variable name.  For example, in the following code
12958@example
12959@{rpn 3.1415 ".pi." =@}
12960show .pi.
12961@end example
12962the first line evaluates to a blank line, and the second prints the value of Pi.
12963
12964NOTE: Do not confuse this with the @code{==} equality operator
12965described above.
12966
12967@item @{rpn "hello" "\\greeting" =@}
12968Assign the value @code{"hello"} to the synonym @code{\greeting}.  See
12969notes at the above item.
12970
12971@item @{rpn 3.14159 0 "x" =@}
12972Assign the value Pi to the first element (at index @code{0})
12973of the @code{x} column.  All columns may be assigned to in this way, e.g.
12974the following is a technique for plotting a quadratic function:
12975@example
12976.i. = 0
12977.n. = 10
12978while @{rpn .i. .n. >@}
12979    @{rpn .i. .n. 1 - /     .i. "x" =@}
12980    @{rpn x .i. @@ 2 power  .i. "y" =@}
12981    .i. += 1
12982end while
12983draw curve
12984@end example
12985
12986@item @{rpn 0 1 &@}
12987@cindex @code{&} rpn operator
12988@cindex rpn operator @code{&}
12989Test whether 0 and 1 are both true, yielding 0.
12990
12991@item @{rpn 0 1 and@}
12992@cindex @code{and} rpn operator
12993@cindex rpn operator @code{and}
12994Test whether 0 and 1 are both true, yielding 0.
12995
12996@item @{rpn y x area@}
12997Calculate the area under the curve y=y(x).  For details
12998(@ref{Manipulation of Columns etc}).
12999
13000@item @{rpn 0 1 |@}
13001@cindex @code{|} rpn operator
13002@cindex rpn operator @code{|}
13003Test whether either 0 or 1 is true, yielding 1.
13004
13005@item @{rpn 0 1 or@}
13006@cindex @code{or} rpn operator
13007@cindex rpn operator @code{or}
13008Test whether either 0 or 1 is true, yielding 1.
13009
13010@item @{rpn 2 3 exch@}
13011@cindex @code{exch} rpn operator
13012@cindex rpn operator @code{exch}
13013Exchange 2 and 3 on the stack, yielding @code{3 2} on the stack.  (See
13014also @code{pop} and @code{dup}.)
13015
13016
13017@item @{rpn x 0 @@@}
13018@cindex @code{@@} rpn operator, for accessing columnar data
13019Yields the value of the first number in the x column.  A similar form
13020also works for @code{y}, etc.  (@ref{Manipulation of Columns etc}).
13021
13022
13023@item @{rpn 2 3 inf@}
13024@cindex @code{inf} rpn operator
13025@cindex rpn operator @code{inf}
13026Pick the smaller of two values, yielding 3.  (Opposite to @code{sup}.)
13027
13028
13029@item @{rpn 2 3 power@}
13030@cindex @code{power} rpn operator
13031@cindex rpn operator @code{power}
13032@cindex HP calculators, RPN notation different from
13033@cindex RPN notation, difference from old-series HP calculators
13034Take 2 to the 3rd power, yielding 8.  Note: This convention may be
13035confusing to users who are familiar with HP calculators from decades
13036past.  Present-day calculators use this convention, which they write as
13037@code{y^x}, but older calculators used the reverse convention, labelling
13038the key @code{x^y}.
13039
13040
13041
13042@item @{rpn 2 3 remainder@}
13043@cindex @code{remainder} rpn operator
13044@cindex rpn operator @code{remainder}
13045Calculate the remainder after dividing 2 by 3, yielding 2.  The return value
13046for @code{@{rpn A B remainder@}} is @code{B - n * A}, where @code{n} is
13047the quotient of @code{A/B}, rounded towards zero to an integer.  In this
13048case, @code{2/3} rounds to an @code{n} value of zero, yielding 2 as the
13049resulting remainder.
13050
13051
13052@item @{rpn "heLLo" "s/L/l/g" sed@}
13053@cindex @code{sed} rpn operator
13054@cindex rpn operator @code{sed}
13055Switch all instances of @code{L} into @code{l}, yielding the string
13056@code{"hello"} on the stack.  This can be helpful for working with
13057filenames, etc.  The work is preformed with a system call to the
13058@code{sed} utility (present on unix systems), and therefore this
13059command will fail if @code{sed} is not installed, or if the OS cannot
13060be contacted.
13061
13062
13063@item @{rpn "file" ".dat" strcat@}
13064@cindex @code{strcat} rpn operator
13065@cindex rpn operator @code{strcat}
13066Concatenate the two strings, yielding the string @code{"file.dat"}.
13067
13068
13069@item @{rpn 2 3 sup@}
13070@cindex @code{sup} rpn operator
13071@cindex rpn operator @code{sup}
13072Pick the larger of two values, yielding 3.  (Opposite to @code{inf}.)
13073
13074@end table
13075
13076
13077@c HTML <!-- newfile UnaryOperators.html "Gri: RPN unary operators" "Programming Gri" -->
13078
13079@node   Unary Operators, Solitary Operators, Binary Operators, rpn Mathematics
13080@comment  node-name,  next,  previous,  up
13081@subsection Unary Operators
13082@cindex rpn, system calls
13083@cindex rpn, conversion of string to number
13084@cindex system calls in rpn expressions
13085@cindex string, conversion to number in rpn expressions
13086@cindex conversion, string to number, in rpn expressions
13087@cindex checking for missing value in rpn expressions
13088@cindex missing value, checking for in rpn  expressions
13089
13090Unary operators replace the last item on the stack with another item.
13091For example, the @code{sin} operator takes the sine of the number on the
13092top of the stack; e.g., @code{@{rpn 45 sin@}} yields the sine of 45 degrees.
13093
13094The unary operators are illustrated below, in rough alphabetical order.
13095
13096@table @code
13097
13098@item @{rpn 0 !@}
13099@cindex @code{!} rpn operator
13100@cindex rpn operator @code{!}
13101@cindex logical negation, @code{!} rpn operator
13102@cindex negation, @code{!} rpn operator
13103Replace 0 (false) with its logical negation 1 (true).
13104
13105@item @{rpn 0 not@}
13106@cindex @code{not} rpn operator
13107@cindex rpn operator @code{not}
13108@cindex logical negation, @code{not} rpn operator
13109@cindex negation, @code{not} rpn operator
13110Replace 0 (false) with its logical negation 1 (true).
13111
13112@item @{rpn -3 abs@}
13113@cindex @code{abs} rpn operator
13114@cindex rpn operator @code{abs}
13115Calculate the absolute value of @code{-3}.
13116
13117
13118@item @{rpn 0.5 acos@}
13119@cindex @code{acos} rpn operator
13120@cindex rpn operator @code{acos}
13121Calculate the inverse cosine of 0.5, yielding 60 (degrees).
13122
13123@item @{rpn 2 acosh@}
13124@cindex @code{acosh} rpn operator
13125@cindex rpn operator @code{acosh}
13126Calculate the inverse hyperbolic cosine of 2, yielding 1.317.  (Note:
13127argument must equal or exceed 1, or an error results.)
13128
13129@anchor{age-rpn-operator}
13130@item @{rpn "filename" age@}
13131@cindex makefiles, emulating action with the @code{age} rpn operator
13132@cindex file age, determined with the @code{age} rpn operator
13133@cindex @code{age} rpn operator
13134@cindex rpn operator @code{age}
13135Calculate the ``age'' of the indicated file, in seconds.  An age of
13136zero indicates that the file was created, or last modified, within 1
13137second of the execution of the @code{age} operator.
13138
13139
13140On unix (and similar) machines, the calculation is done on unix
13141machines with the @code{stat()} subroutine.  On other machines, the
13142@code{age} operator may cause an error.
13143
13144The age of a non-existent file is reported as the number of seconds
13145since the system clock's reference time, i.e. since 1970-jan-1 on unix
13146machines.  This convention is so that scripts like that in the example
13147below will work as intended.
13148
13149A typical use of this command is the creation of data-files from shell
13150scripts, as illustrated below.  The idea is to update (or create) the
13151file @file{file.dat} using the system-executable script
13152@file{creator.pl}, but only to do so if @file{creator.pl} is younger
13153than @file{file.dat}.
13154@example
13155if @{rpn "file.dat" age "creator.pl" age <@}
13156   system "./creator.pl > file.dat"
13157end if
13158open file.dat
13159@end example
13160For the convenience in such usage, a non-existent file is assigned the
13161maximum possible file age on the given OS, e.g. on a unix machine, the
13162age is reported as though the non-existent file had been created on
13163January 1, 1970 on a unix machine.
13164
13165
13166@item @{rpn 0.5 asin@}
13167@cindex @code{asin} rpn operator
13168@cindex rpn operator @code{asin}
13169Calculate the inverse sine of 0.5, yielding 30 (degrees).
13170
13171
13172@item @{rpn 1 atan@}
13173@cindex @code{atan} rpn operator
13174@cindex rpn operator @code{atan}
13175Calculate the inverse tangent of 1, yielding 45 (degrees).
13176
13177
13178@item @{rpn 0.5 atanh@}
13179@cindex @code{atan} rpn operator
13180@cindex rpn operator @code{atan}
13181Calculate the inverse hyperbolic tangent of 0.5, yielding 0.549306
13182(radians).
13183
13184
13185@item @{rpn 0 argv@}
13186@cindex @code{argv} rpn operator, access commandline arguments
13187@cindex arguments on command line, accessing with @code{argv} rpn operator
13188@cindex commandline arguments, accessing with @code{argv} rpn operator
13189Returns the name of the Gri command-file, which is considered as the first
13190"optional" argument.  (It may seem odd that the name of the command-file
13191is considered an option, but Gri does this for consistency with C and
13192other languages.  It is useful.)  Other arguments provided when Gri
13193was invoked are provided as @code{rpn 1 argv}, etc.
13194
13195A string consisting of a single blank character results if one tries to
13196access beyond the list of arguments that were actually supplied.  See
13197also the @code{argc} solitary operator (@ref{Solitary Operators}), which
13198returns the number of optional arguments.
13199
13200For example, if Gri is invoked as
13201
13202@example
13203gri myscript.gri file1.dat file2.dat
13204@end example
13205
13206@noindent
13207and if @file{myscript.gri} contained
13208
13209@example
13210.n. = @{rpn argc@}
13211.i. = 0
13212while @{rpn .n. .i. <@}
13213    show "argument " .i. " is " @{rpn .i. argv@}
13214    .i. += 1
13215end while
13216@end example
13217
13218@noindent
13219then the output would be
13220
13221@example
13222argument 0 is myscript.gri
13223argument 1 is file1.dat
13224argument 2 is file2.dat
13225@end example
13226
13227For usage within the Emacs gri-mode, see
13228@ref{Filename arguments when running gri}.
13229
13230
13231@item @{rpn "hi" ascent@}
13232@cindex @code{ascent} rpn operator
13233@cindex rpn operator @code{ascent}
13234Determine ascent of this string (in cm), in the present font and
13235fontsize.  (See also @code{descent} and @code{width}.)
13236
13237
13238@item @{rpn "3.1" atof@}
13239@cindex @code{atof} rpn operator
13240@cindex rpn operator @code{atof}
13241Calculate the numerical value contained in indicated string.
13242
13243
13244@item @{rpn 1.5 ceil@}
13245@cindex @code{ceil} rpn operator
13246@cindex rpn operator @code{ceil}
13247Calculate the next higher integer, yielding 2.  (Opposite of @code{floor}.)
13248
13249
13250@item @{rpn 45 cos@}
13251@cindex @code{cos} rpn operator
13252@cindex rpn operator @code{cos}
13253Calculate the cosine of 45 degrees, yielding 0.707.
13254
13255
13256@item @{rpn 1 cosh@}
13257@cindex @code{cosh} rpn operator
13258@cindex rpn operator @code{cosh}
13259Calculate the hyperbolic cosine of 1 (radian), yielding 1.543.
13260
13261
13262@item @{rpn 1 cmtopt@}
13263@cindex @code{cmtopt} rpn operator
13264@cindex rpn operator @code{cmtopt}
13265Convert from 1 centimeter to so-called ``point'' units, yielding 28.45.
13266(Opposite of @code{pttocm}.)
13267
13268@item @{rpn 170 dec2hex@}
13269@cindex converting decimal values to hexadecimal strings
13270@cindex hexadecimal, converting to from decimal
13271Convert a number into a string which is its hexadecimal
13272representation.  Before the conversion, the number is rounded to the
13273nearest integer, and if the result is negative, an error results.  The
13274string is double-quoted, with letters (if there are any) being in
13275upper case.
13276
13277For example
13278@code{\hex = @{rpn  63  dec2hex@}}
13279is equivalent to
13280@code{\hex = "3F"}.
13281
13282Compare with @code{hex2dec}, the inverse.
13283
13284@item @{rpn "\\syn" defined@}
13285@cindex testing for existence of a synonym
13286@cindex synonyms, checking for existence of
13287@cindex existence of a synonym, testing
13288Test whether the synonym is defined at the moment, returning 1 if
13289so and 0 if not.  (Note the double-backslash in the synonym name, which
13290is required.)
13291
13292
13293@item @{rpn ".var." defined@}
13294@cindex existence of a variable, testing
13295@cindex testing for existence of a variable
13296@cindex variables, checking for existence of
13297Test whether the variable is defined at the moment, returning 1 if
13298so and 0 if not.
13299
13300
13301@item @{rpn "\\@@alias" defined@}
13302@cindex testing for existence of an aliased synonym
13303@cindex alias synonyms, checking for existence of
13304@cindex existence of an alias synonym, testing
13305Test whether the variable/synonym item that is named by the alias
13306(@ref{Alias Synonyms}) is defined at the moment, returning 1 if so and 0
13307if not.
13308
13309
13310
13311
13312@item @{rpn "hi" descent@}
13313@cindex @code{descent} rpn operator
13314@cindex rpn operator @code{descent}
13315Calculate the descent (below the baseline in cm) for the given string,
13316in the present font and fontsize.  (See also @code{ascent} and
13317@code{width}.)
13318
13319
13320@item @{rpn "/home/me/data/timeseries" directory_exists@}
13321@cindex @code{directory_exists} rpn operator
13322@cindex file permissions, testing with @code{file_exists} and @code{directory_exists}
13323@cindex rpn operator @code{directory_exists}
13324Determine whether indicate directory exists, yielding @code{1} if it does
13325and @code{0} otherwise.  (See also @code{file_exists}.)
13326
13327
13328@item @{rpn 2 dup@}
13329@cindex @code{dup} rpn operator
13330@cindex rpn operator @code{dup}
13331Duplicate the top item on stack, yielding @code{2 2} on the stack.
13332(See also @code{exch} and @code{pop}.)
13333
13334
13335@item @{rpn 1 exp@}
13336@cindex @code{exp} rpn operator
13337@cindex rpn operator @code{exp}
13338Calculate the value of @code{e} raised to the indicated power, yielding 2.71828.
13339
13340
13341@item @{rpn 2 exp10@}
13342@cindex @code{exp10} rpn operator
13343@cindex rpn operator @code{exp10}
13344Calculate the value of @code{10} raised to the indicated power, yielding 100.
13345
13346
13347@item @{rpn "foo.dat" file_exists@}
13348@cindex @code{file_exists} rpn operator
13349@cindex rpn operator @code{file_exists}
13350Determine whether the indicate file exists, yielding @code{1} if it does
13351and @code{0} otherwise.  (See also @code{directory_exists}.)
13352
13353
13354@item @{rpn 1.5 floor@}
13355@cindex @code{floor} rpn operator
13356@cindex rpn operator @code{floor}
13357Calculate the nearest smaller integer, yielding 1.  (Opposite of
13358@code{ceil}.)
13359
13360
13361@item @{rpn "AA" hex2dec@}
13362@cindex converting hexadecimal strings to decimal values
13363@cindex hexadecimal, converting to decimal
13364Convert a string, representing a hexadecimal value, into an integer.
13365The string must be double-quoted, and it may contain either lower- or
13366upper-case letters; this is in contrast to the inverse function,
13367@code{dec2hex}, which returns upper-case.
13368
13369This operator is most often used in working with colours, since Gri
13370handles colour components in decimal terms, whereas many other
13371applications refer to the components in hexadecimal notation.
13372
13373Compare with @code{dec2hex}, the inverse.
13374
13375
13376@item @{rpn 3 ismissing@}
13377@cindex @code{ismissing} rpn operator
13378@cindex rpn operator @code{ismissing}
13379Yields 1 if the indicated value is a ``missing value'' or 0 otherwise.
13380
13381
13382@item @{rpn 100 log@}
13383@cindex @code{log} rpn operator
13384@cindex rpn operator @code{log}
13385Calculate the base-10 logarithm of 100, yielding 2.
13386
13387
13388@item @{rpn 10 ln@}
13389@cindex @code{ln} rpn operator
13390@cindex rpn operator @code{ln}
13391Calculate the natural logarithm of 10, yielding 2.30259.
13392
13393
13394@item @{rpn x mean@}
13395Yields the mean value of the (non-missing) numbers in the x column.  A
13396similar form also works for @code{y}, etc.
13397(@ref{Manipulation of Columns etc}).
13398
13399
13400@item @{rpn x max@}
13401Yields the largest value of the (non-missing) numbers in the x column.  A
13402similar form also works for @code{y}, etc.
13403(@ref{Manipulation of Columns etc}).
13404
13405
13406@item @{rpn x min@}
13407Yields the smallest value of the (non-missing) numbers in the x column.  A
13408similar form also works for @code{y}, etc.
13409(@ref{Manipulation of Columns etc}).
13410
13411
13412@item @{rpn 28.45 pttocm@}
13413@cindex @code{pttocm} rpn operator
13414@cindex rpn operator @code{pttocm}
13415Calculate the number of centimeters in 28.45 printers points, yielding 1.
13416(Opposite of @code{cmtopt}.)
13417
13418
13419@item @{rpn 1 2 pop@}
13420@cindex @code{pop} rpn operator
13421@cindex rpn operator @code{pop}
13422Remove the top item from the stack, yielding @code{1} on the stack.
13423Generates an error if the stack is empty.  (See also @code{exch} and
13424@code{dup}.)
13425
13426
13427@item @{rpn 4 sqrt@}
13428@cindex @code{sqrt} rpn operator
13429@cindex rpn operator @code{sqrt}
13430Calculate the square root of 4, yielding 2.  (Negative arguments yield
13431errors.)
13432
13433
13434@item @{rpn 45 sin@}
13435@cindex @code{sin} rpn operator
13436@cindex rpn operator @code{sin}
13437Calculate the sine of 45 (degrees), yielding 0.707107.
13438
13439
13440@item @{rpn 2 sinh@}
13441@cindex @code{sinh} rpn operator
13442@cindex rpn operator @code{sinh}
13443Calculate the hyperbolic sine of 2, yielding 3.62686.
13444
13445
13446@item @{rpn "hello" strlen@}
13447@cindex @code{strlen} rpn operator
13448@cindex rpn operator @code{strlen}
13449Determine the number of characters in string, including the quotation
13450marks, e.g. 7 here.
13451
13452
13453@item @{rpn "date" system@}
13454@cindex @code{system} rpn operator
13455@cindex rpn operator @code{system}
13456Call the indicated system function and insert its ouput on the stack,
13457yielding the date as a character string.
13458
13459
13460@item @{rpn 45 tan@}
13461@cindex @code{tan} rpn operator
13462@cindex rpn operator @code{tan}
13463Calculate the tangent of 45 (degrees), yielding 1.
13464
13465
13466@item @{rpn tanh@}
13467@cindex @code{tanh} rpn operator
13468@cindex rpn operator @code{tanh}
13469Calculate the hyperbolic tangent of 2, yielding 0.964028.
13470
13471
13472@item @{rpn "hi" width@}
13473@cindex @code{width} rpn operator
13474@cindex rpn operator @code{width}
13475Determine width of this string (in cm), in the present font and fontsize.
13476(See also @code{ascent} and @code{descent}.)
13477
13478
13479@item @{rpn 0 wordv@}
13480@cindex RPN operator @code{wordv}
13481@cindex @code{wordv} RPN operator
13482Returns the first word used in invoking the present command.  Similar
13483to the @code{\.word0.} synonym (@ref{Local Synonyms}).  Example:
13484
13485@example
13486`let us test .it.'
13487@{
13488  .w. = 0
13489  while @{rpn .w. wordc >@}
13490    show "The " .w. "-th word is `" @{rpn .w. wordv@} "'."
13491    .w. += 1
13492  end while
13493@}
13494let us test "this thing"
13495let us test "this" "thing"
13496let us test "Pi is" @{rpn 3.14@}
13497@end example
13498
13499If you are using this to parse options given to the command, it is up to
13500you to skip the non-optional words in the command.  In this case, for
13501example, we skipped the first three words (@code{let}, @code{us}, and
13502@code{test}).
13503
13504
13505@item @{rpn 1 xusertocm@}
13506@cindex @code{xusertocm} rpn operator
13507@cindex rpn operator @code{xusertocm}
13508Calculate the x coordinate, in centimeters measured from left-hand side of
13509page, corresponding to a user-value of x=1.  (Opposite of
13510@code{xcmtouser}.)
13511
13512
13513@item @{rpn 1 xcmtouser@}
13514@cindex @code{xcmtouser} rpn operator
13515@cindex rpn operator @code{xcmtouser}
13516Calculate the x value, in user units, for a point that is 1 centimeter from
13517the left-hand edge of the paper.  (Opposite of @code{xusertocm}.)
13518
13519
13520@item @{rpn 1 yusertocm@}
13521@cindex @code{yusertocm} rpn operator
13522@cindex rpn operator @code{yusertocm}
13523Calculate the y coordinate, in centimeters measured from bottom side of
13524page, corresponding to a user-value of x=1.  (Opposite of
13525@code{ycmtouser}.)
13526
13527
13528@item @{rpn 1 ycmtouser@}
13529@cindex @code{ycmtouser} rpn operator
13530@cindex rpn operator @code{ycmtouser}
13531Calculate the y value, in user units, for a point that is 1 centimeter from
13532the bottom edge of the paper.  (Opposite of @code{yusertocm}.)
13533
13534
13535@end table
13536
13537
13538
13539
13540
13541
13542
13543@c HTML <!-- newfile SolitaryOperators.html "Gri: RPN solitary operators" "Programming Gri" -->
13544
13545@node   Solitary Operators, Manipulation of Columns etc, Unary Operators, rpn Mathematics
13546@comment  node-name,  next,  previous,  up
13547
13548@subsection Solitary Operators
13549@cindex rpn operator @code{argc}, yielding number of commandline arguments
13550@cindex @code{argc} rpn operator, yielding number of commandline arguments
13551
13552Solitary operators do not act on items on the stack; rather, they
13553generate items themselves and insert them on the stack.
13554
13555The solitary operators are illustrated below, in alphabetical order.
13556
13557@table @code
13558
13559@item @{rpn argc@}
13560Yields number of command-line arguments given by the user when Gri was
13561invoked.  Thus, invoking Gri as
13562
13563@example
13564gri myfile.gri file1.dat file2.dat
13565@end example
13566
13567@noindent
13568yields 3, for arguments @file{myfile.gri}, @code{file1.dat},
13569and @code{file2.dat}.  These arguments are accessible through
13570the @code{argv} unary operator (@ref{Unary Operators}).
13571
13572
13573@item @{rpn e@}
13574@cindex e, base of natural logarithms, in RPN expressions
13575Yields the base of natural logarithms, i.e. @code{2.718}...
13576
13577
13578@item @{rpn pi@}
13579@cindex pi, in RPN expressions
13580Yields Pi, i.e. @code{3.141}...
13581
13582
13583@item @{rpn rand@}
13584@cindex RPN operator @code{rand}
13585@cindex @code{rand} RPN operator
13586@cindex random numbers, generating in RPN expressions
13587Generate a random number in the range 0 to 1, using the C subroutine
13588@code{drand48()} if it is available, otherwise the less well-distributed
13589@code{rand()} subroutine.
13590
13591
13592@item @{rpn wordc@}
13593@cindex RPN operator @code{wordc}
13594@cindex @code{wordc} RPN operator
13595Returns number of words used in invoking the present command.  Similar
13596to the @code{\.words.} synonym (@ref{Local Synonyms}).  Example:
13597
13598@example
13599`let us test .it.'
13600@{
13601  show "This command has " @{rpn wordc@} " words"
13602@}
13603let us test 10
13604let us test @{rpn 3 1 +@}
13605let us test "this"
13606let us test "this thing"
13607@end example
13608
13609The operator @code{wordv} may be used to extract the words of the
13610command (@ref{Unary Operators}).
13611@end table
13612
13613
13614
13615@c HTML <!-- newfile ManipulatingColumns.html "Gri: RPN column manipulation" "Programming Gri" -->
13616
13617@node   Manipulation of Columns etc, rpn Examples, Solitary Operators, rpn Mathematics
13618@comment  node-name,  next,  previous,  up
13619
13620@subsection Manipulation of Columns etc
13621
13622@subsubsection Columns
13623@cindex column data, accessing individual values and stats
13624@cindex standard deviation, column data
13625@vindex @code{..num_col_data..}, number column data
13626
13627
13628
13629Individual data in the @code{x}, @code{y}, @code{z}, @code{u}, @code{v}
13630and @code{weight} columns can be accessed with the @code{@@} operator.
13631The first point has index 0.  Examples:
13632
13633@example
13634show "first x is " @{rpn x 0 @@ @}
13635show "last  x is " @{rpn x ..num_col_data.. 1 - @@ @}
13636show "and here are all the data:"
13637.i. = 0
13638while @{rpn .i. ..num_col_data.. >@}
13639    show @{rpn x .i. @@ @}
13640    .i. += 1
13641end while
13642@end example
13643
13644
13645@cindex maximum, column data
13646@cindex minimum, column data
13647@cindex statistics, column data
13648@cindex column data, statistics
13649@cindex mean, calculating for column data
13650@cindex standard deviation, calculating for column data
13651@cindex skewness, calculating for column data
13652@cindex kurtosis, calculating for column data
13653The mean value is available from the @code{mean} operator (e.g.,
13654@code{.xmean. = @{rpn x mean @}}, while the standard deviation is given
13655by @code{stddev}, the skewness is given by @code{skewness},
13656and the kurtosis is given by @code{kurtosis} (using the definition
13657that yields 3 for a gaussian distribution).
13658
13659The minimal and maximal values are given by
13660@code{min} and @code{max}.
13661
13662@cindex @code{area} rpn operator
13663@cindex rpn operator @code{area}
13664@cindex area under curve
13665The area under the curve y=y(x) is found by @code{@{rpn y x area @}},
13666defined by
13667@ifinfo
13668@code{0.5 * sum ( (y[i] + y[i-1]) * (x[i] - x[i-1]) )}
13669for @code{i} ranging from 1 to @code{..num_col_data..}-1.
13670@end ifinfo
13671@tex
13672${1}\over{2} \left( \sum_1^{n-1} (y_i + y_{i-1}) (x_i - x_{i-1}) \right)$
13673for data with $i$ ranging $0$--$..num\_col\_data..-1$
13674@end tex
13675
13676@subsubsection Grid
13677@cindex grid data -- accessing individual values and stats
13678@cindex maximum, grid data
13679@cindex minimum, grid data
13680@cindex grid data -- minimum, maximum, mean
13681
13682Grid data can be accessed with e.g. @code{@{rpn grid min @} },
13683@code{@{rpn grid max @} }, and @code{@{rpn grid mean @} }.
13684
13685@cindex rpn operator @code{interpolate}
13686@cindex grid, interpolating to given (x,y) value
13687@cindex  interpolating grid to given (x,y) value
13688The value of the grid at a given @code{(.x.,.y.)} coordinate may be
13689found by by e.g. @code{@{rpn grid .x. .y. interpolate@}}.  The
13690interpolation scheme is the same as that used in converting grids to
13691images.
13692
13693
13694@c HTML <!-- newfile RPNexamples.html "Gri: RPN examples" "Programming Gri" -->
13695
13696@node   rpn Examples, Text, Manipulation of Columns etc, rpn Mathematics
13697@comment  node-name,  next,  previous,  up
13698@subsection rpn Examples
13699
13700Here are some reverse-polish expressions and the corresponding algebraic
13701interpretations:
13702
13703@itemize @bullet
13704
13705@item @code{@{rpn 1 2 + 10 / @}}
13706= (1+2)/10
13707
13708@item @code{@{rpn .a. .b. + .c. + .d. / @}}
13709= (.a.+.b.+.c.)/.d.
13710
13711@item @code{@{rpn e 2 / @}}
13712= e/2 (Gri knows values of ``e'' and ``pi'')
13713
13714@item @code{@{rpn 23 sin 100 * 12 cos + @}}
13715= cos(12) + 100sin(23)
13716
13717@item @code{@{rpn 5 2 power @}}
13718= 25
13719
13720@item @code{@{rpn 2 log exp @}}
13721= exp(log 2)
13722
13723@item @code{@{rpn 2 ln exp10 @}}
13724= 10^ln2
13725
13726@item @code{@{rpn 1.7 floor @}}
13727= 1 (rounds down to nearest integer.  Note that the floor of -1.7 is -2)
13728
13729@item @code{@{rpn 10.1 2 remainder @}}
13730= 0.1 (remainder of 10.1 after division by 2; see C function @code{remainder(x,y)})
13731
13732@item @code{@{rpn -10.1 2 remainder @}}
13733= -0.1
13734
13735@item @code{@{rpn -10.1 -2 remainder @}}
13736= -0.1
13737
13738@item @code{@{rpn .num. 10 > @}}
13739= 1 if 10 exceeds .num., or 0 otherwise
13740@end itemize
13741
13742@noindent
13743NOTES:
13744@itemize @bullet
13745@cindex trigonometric operations in rpn math
13746@cindex mathematics, trigonometric operations
13747@item
13748The units of @code{sin}, @code{cos}, etc, are degrees, not radians.
13749@item
13750@cindex page units
13751@cindex user units
13752@cindex mapping page location units to user units
13753@cindex transforming page location units to user units
13754@cindex scales, accessing
13755@cindex mathematics, rpn notation, example
13756The scales of the plot are accessible to @code{rpn}.  For example, with
13757the command
13758
13759@example
13760draw label "hi" at 10 20
13761@end example
13762
13763@noindent
13764you draw the indicated string at the indicated location in
13765user coordinates.  To put it 0.15 centimetres to the right of this
13766location and 0.1 centimetres lower, you could do as follows:
13767
13768@example
13769draw label "\label" at \
13770    @{rpn .x. xusertocm 0.15 + xcmtouser@} \
13771    @{rpn .y. yusertocm 0.10 - ycmtouser@}
13772@end example
13773
13774(Note that the x and y scales have individual translations from "user"
13775to "cm" coordinates.)
13776@item
13777Some conversion factors are built into @code{rpn}; @code{cmtopt}
13778converts from centimetres to points (by dividing by 28.45; the
13779conversion factor to inches is 72.27) while @code{pttocm} converts from
13780points to centimetres.  For example, here is how to label a data curve
13781with a label placed near the last y-value of the data set:
13782@cindex drawing labels for data curves
13783@cindex labels, on data curves
13784
13785@example
13786draw curve
13787.y. = @{rpn ..ylast.. yusertocm 0.5 - ycmtouser@}
13788draw label "Smoothed" at ..xlast.. .y.
13789@end example
13790
13791@end itemize
13792
13793
13794@c HTML <!-- newfile Text.html "Gri: Text in Gri" "Text" -->
13795
13796@node   Text, Embedded Synonyms, rpn Examples, Programming
13797@comment  node-name,  next,  previous,  up
13798@section Text Strings
13799
13800Any text can be drawn in any size; Gri does not limit font size to a
13801list, e.g. 10 point, 12 points, etc.  Several fonts are available in
13802Gri, e.g. Times, Helvetica, etc.; these are all standard PostScript
13803fonts.  Support for some non-English languages (e.g. French) is also
13804provided.  And, finally, Gri supports inclusion of simple mathematical
13805expressions (Greek letters, superscripts, etc.) in text, using a
13806LaTeX-style syntax.
13807
13808@menu
13809* Embedded Synonyms::           Embedding synonyms in text strings
13810* Mathematical Text::           Mathematical symbols and Greek letters
13811* Non-English Text::            French, etc.
13812* Adjustment Of Character Position:: thinspaces
13813@end menu
13814
13815
13816@c HTML <!-- newfile EmbeddedSynonyms.html "Gri: embedded synonyms" "Text" -->
13817
13818@node   Embedded Synonyms, Mathematical Text, Text, Text
13819@comment  node-name,  next,  previous,  up
13820@subsection Embedding synonyms in quoted text strings
13821@cindex synonyms, embedding in quoted text strings
13822@cindex text strings, embedding synonyms within
13823@strong{Outside} math strings, you can embed your synonyms at will.  For
13824example, you can include the name of a data file in the title of your
13825plot as follows
13826@cindex interaction with user, @code{query} command
13827
13828@example
13829query \filename "File to read from?" ("data.file")
13830open \filename
13831read columns x y
13832draw curve
13833draw title "data from \filename"
13834@end example
13835
13836Within math strings (ie, between matched dollar-signs), these synonyms
13837are disabled, and only the mathematical symbols and Greek letters work.
13838
13839
13840@c HTML <!-- newfile MathematicalText.html "Gri: mathematical text" "Text" -->
13841
13842@node   Mathematical Text, Non-English Text, Embedded Synonyms, Text
13843@comment  node-name,  next,  previous,  up
13844@subsection Mathematical text
13845
13846@subsubsection Subscripts
13847@cindex subscripts
13848@cindex text, subscripts
13849As in @TeX{} and La@TeX{}, you must be in math-mode to use subscripts;
13850in other words, you must enclose the string or substring in
13851dollar-signs.  For single-character subscripts, insert an underline
13852prior to the character to be subscripted:
13853
13854@example
13855draw title "$a_2$"
13856@end example
13857
13858@noindent
13859For multiple-character subscripts, insert braces before and after the
13860item to be subscripted:
13861
13862@example
13863draw title "$a_@{22@}$"
13864@end example
13865
13866@subsubsection Superscripts
13867@cindex superscripts
13868@cindex text, superscripts
13869As in @TeX{} and La@TeX{}, you must be in math-mode to use superscripts;
13870in other words, you must enclose the string or substring in
13871dollar-signs.  For single-character superscripts, insert a carat prior
13872to the character to be superscripted:
13873
13874@example
13875draw title "$a^2$"
13876@end example
13877
13878@noindent
13879For multiple-character superscripts, insert braces before and after the
13880item to be superscripted:
13881
13882@example
13883draw title "$a^@{22@}$"
13884@end example
13885
13886@subsubsection Mathematical symbols
13887@cindex mathematical Symbols
13888@cindex greek Letters
13889@cindex text, mathematical symbols
13890@cindex text, Greek letters
13891As in @TeX{} and LaTeX, you indicate mathematical symbols and Greek
13892letters with backslash sequences.  The following LaTeX symbols are
13893defined in math mode in Gri (cf tables in Lamport's section 3):
13894
13895@ifinfo
13896@example
13897\Delta \Downarrow \Gamma \Im \Lambda \Leftarrow
13898\Leftrightarrow \Omega \Pi \Phi \Psi \Re
13899\Rightarrow \Sigma \Theta \Uparrow \Upsilon \Xi
13900\alpha \approx \ast \beta \bullet \chi \circ
13901\cong \delta \div \downarrow \epsilon \equiv
13902\eta \exists \forall \gamma \geq \gg \in \infty
13903\iota \kappa \lambda \langle \leftarrow
13904\leftrightarrow \leq \ll \mu \nabla \neq \nu
13905\omega \partial \phi \pi \pm \prod \propto \psi
13906\rangle \rho \rightarrow \sigma \sim \subset
13907\subseteq \sum \supset \supseteq \surd \sqrt
13908\tau \theta \times \uparrow \upsilon \varpi
13909\wedge \xi \zeta \vartheta \varsigma \varphi
13910\aleph \oplus \otimes \wp \prime \emptyset
13911\angle \neg \clubsuit \diamondsuit \spadesuit
13912\cdot \lfloor \lceil \rceil \rfloor
13913@end example
13914@end ifinfo
13915
13916@tex
13917({\tt $\backslash$Delta}, $\Delta$),
13918({\tt $\backslash$Downarrow}, $\Downarrow$),
13919({\tt $\backslash$Gamma}, $\Gamma$),
13920({\tt $\backslash$Im}, $\Im$),
13921({\tt $\backslash$Lambda}, $\Lambda$),
13922({\tt $\backslash$Leftarrow}, $\Leftarrow$),
13923({\tt $\backslash$Leftrightarrow}, $\Leftrightarrow$),
13924({\tt $\backslash$Omega}, $\Omega$),
13925({\tt $\backslash$Phi}, $\Phi$),
13926({\tt $\backslash$Pi}, $\Pi$),
13927({\tt $\backslash$Psi}, $\Psi$),
13928({\tt $\backslash$Re}, $\Re$),
13929({\tt $\backslash$Rightarrow}, $\Rightarrow$),
13930({\tt $\backslash$Sigma}, $\Sigma$),
13931({\tt $\backslash$Theta}, $\Theta$),
13932({\tt $\backslash$Uparrow}, $\Uparrow$),
13933({\tt $\backslash$Upsilon}, $\Upsilon$),
13934({\tt $\backslash$Xi}, $\Xi$),
13935({\tt $\backslash$alpha}, $\alpha$),
13936({\tt $\backslash$approx}, $\approx$),
13937({\tt $\backslash$ast}, $\ast$),
13938({\tt $\backslash$beta}, $\beta$),
13939({\tt $\backslash$bullet}, $\bullet$),
13940({\tt $\backslash$chi}, $\chi$),
13941({\tt $\backslash$circ}, $\circ$),
13942({\tt $\backslash$cong}, $\cong$),
13943({\tt $\backslash$delta}, $\delta$),
13944({\tt $\backslash$div}, $\div$),
13945({\tt $\backslash$downarrow}, $\downarrow$),
13946({\tt $\backslash$epsilon}, $\epsilon$),
13947({\tt $\backslash$equiv}, $\equiv$),
13948({\tt $\backslash$eta}, $\eta$),
13949({\tt $\backslash$exists}, $\exists$),
13950({\tt $\backslash$forall}, $\forall$),
13951({\tt $\backslash$gamma}, $\gamma$),
13952({\tt $\backslash$geq}, $\geq$),
13953({\tt $\backslash$gg}, $\gg$),
13954({\tt $\backslash$in}, $\in$),
13955({\tt $\backslash$int}, $\int$),
13956({\tt $\backslash$infty}, $\infty$),
13957({\tt $\backslash$iota}, $\iota$),
13958({\tt $\backslash$kappa}, $\kappa$),
13959({\tt $\backslash$lambda}, $\lambda$),
13960({\tt $\backslash$langle}, $\langle$),
13961({\tt $\backslash$leftarrow}, $\leftarrow$),
13962({\tt $\backslash$leftrightarrow}, $\leftrightarrow$),
13963({\tt $\backslash$leq}, $\leq$),
13964({\tt $\backslash$ll}, $\ll$),
13965({\tt $\backslash$mu}, $\mu$),
13966({\tt $\backslash$nabla}, $\nabla$),
13967({\tt $\backslash$neq}, $\neq$),
13968({\tt $\backslash$nu}, $\nu$),
13969({\tt $\backslash$omega}, $\omega$),
13970({\tt $\backslash$partial}, $\partial$),
13971({\tt $\backslash$phi}, $\phi$),
13972({\tt $\backslash$pi}, $\pi$),
13973({\tt $\backslash$pm}, $\pm$),
13974({\tt $\backslash$prod}, $\prod$),
13975({\tt $\backslash$propto}, $\propto$),
13976({\tt $\backslash$psi}, $\psi$),
13977({\tt $\backslash$rangle}, $\rangle$),
13978({\tt $\backslash$rho}, $\rho$),
13979({\tt $\backslash$rightarrow}, $\rightarrow$),
13980({\tt $\backslash$sigma}, $\sigma$),
13981({\tt $\backslash$sim}, $\sim$),
13982({\tt $\backslash$subset}, $\subset$),
13983({\tt $\backslash$subseteq}, $\subseteq$),
13984({\tt $\backslash$sum}, $\sum$),
13985({\tt $\backslash$supset}, $\supset$),
13986({\tt $\backslash$supseteq}, $\supseteq$),
13987({\tt $\backslash$surd}, $\surd$),
13988({\tt $\backslash$sqrt}, $\surd$),
13989({\tt $\backslash$tau}, $\tau$),
13990({\tt $\backslash$theta}, $\theta$),
13991({\tt $\backslash$times}, $\times$),
13992({\tt $\backslash$uparrow}, $\uparrow$),
13993({\tt $\backslash$upsilon}, $\upsilon$),
13994({\tt $\backslash$varpi}, $\varpi$),
13995({\tt $\backslash$wedge}, $\wedge$),
13996({\tt $\backslash$xi}, $\xi$),
13997({\tt $\backslash$zeta}, $\zeta$),
13998({\tt $\backslash$vartheta}, $\vartheta$),
13999({\tt $\backslash$varsigma}, $\varsigma$),
14000({\tt $\backslash$varphi}, $\varphi$),
14001({\tt $\backslash$aleph}, $\aleph$),
14002({\tt $\backslash$oplus}, $\oplus$),
14003({\tt $\backslash$otimes}, $\otimes$),
14004({\tt $\backslash$wp}, $\wp$),
14005({\tt $\backslash$prime}, $\prime$),
14006({\tt $\backslash$emptyset}, $\emptyset$),
14007({\tt $\backslash$angle}, $\angle$),
14008({\tt $\backslash$neg}, $\neg$),
14009({\tt $\backslash$clubsuit}, $\clubsuit$),
14010({\tt $\backslash$diamondsuit}, $\diamondsuit$),
14011({\tt $\backslash$spadesuit}, $\spadesuit$)
14012({\tt $\backslash$cdot}, $\cdot$)
14013({\tt $\backslash$lfloor}, $\lfloor$)
14014({\tt $\backslash$lceil}, $\lceil$)
14015({\tt $\backslash$rceil}, $\rceil$)
14016({\tt $\backslash$rfloor}, $\rfloor$)
14017@end tex
14018
14019@c HTML <A HREF="./resources/math_symbols.gif">Click here</A> to see the
14020@c HTML symbols and their names.
14021
14022@noindent
14023For example, you might use these as follows:
14024
14025@example
14026draw title "$\alpha$ = thermal expansion coefficient"
14027@end example
14028
14029Sometimes you'll want a mathematical symbol to be adjacent to a normal
14030text string, with no space between.  You can do this by enclosing in
14031braces, as in LaTeX.
14032
14033@cindex text, inserting forward/backward space
14034@cindex space in text
14035@cindex superscripts and subscripts -- how to align using @code{\!}
14036@cindex aligning superscripts and subscripts with @code{\!}
14037
14038@TeX{} and La@TeX{} handle combinations of superscripts and subscripts
14039very cleanly, putting one above the other.  Presently, Gri does not do
14040this; for example @code{set x name "$A_1^2$"} will have the 2 appearing
14041to the right of the 1 instead of above it.  Proper positioning will be
14042added to a later version of Gri, but in the meantime you can achieve the
14043desired effect with the @TeX{} ``negative thinspace'' psuedo-character
14044in math-mode.  Using this feature will not hurt you when the new Gri
14045becomes available.  The symbol for a negative thinspace is @code{\!} in
14046math-mode.  It has no meaning in nonmath mode.  A thinspace is 1/6 of an
14047``em-space'' (a @TeX{} term, normally equal to the width of the
14048character ``M'' in the current font).  In most fonts, numbers are half
14049the width of the letter ``M'', so that 3 negative thinspaces will move
14050leftward over a single number.  Thus, if the example above becomes
14051@code{set x name "$A_1\!\!\!^2"}, the 2 will be positioned above the 1.
14052(Equivalently, you could write @code{set x name "$A^2\!\!_1$"}.)
14053Depending on the actual characters you have in the super/subscripts, you
14054might need more or less thinspaces; some experimentation might be
14055required.  Also, note that the symbol @code{\,} in math mode is a
14056positive thinspace (which moves the next character a little bit to the
14057right).  Thus, you can add a little extra spaces between characters by
14058doing something like @code{set x name "A$\,$B"}.
14059
14060To get a hat over a single character, do something like the following
14061(which draws a hat over the character "h"):
14062@cindex hat, drawing hat on top of character
14063
14064@example
14065draw label "h$@{\!\!\!^@{^\wedge@}@}$" at 10 12 cm
14066@end example
14067
14068@cindex overbar, drawing line on top of character
14069@cindex latex overline command, emulating
14070@cindex overline, emulating latex command
14071To get an overbar on a rho, do this:
14072
14073@example
14074draw label "$\rho\!\!\!\!^-$" at 3 3 cm
14075@end example
14076
14077
14078
14079@c HTML <!-- newfile NonEnglishText.html "Gri: non-English text" "Text" -->
14080
14081@node   Non-English Text, Adjustment Of Character Position, Mathematical Text, Text
14082@comment  node-name,  next,  previous,  up
14083@subsection Non-English characters
14084
14085@cindex iso-latin-1 font encoding
14086@cindex text, ISO characters
14087@cindex accented characters in text
14088@cindex non-English language text
14089@cindex French accents in text
14090
14091Gri relies on the ``standard'' PostScript fonts, however, and it
14092suffers all limitations of these fonts.
14093
14094Gri supports both English and some other European-derived languages,
14095permitting text with accents on letters.  (It does not support
14096Oriental or other languages at this time.)  The accents are supported
14097by using the so-called ISO-Latin-1 font-encoding scheme (also called
14098the ISO-8859-1 scheme), and so, from what the author can gather from
14099his reading, Gri should support various languages from western
14100European, e.g. English, French, Spanish, Catalan, Basque, Portuguese,
14101Italian, Albanian, Rhaeto-Romanic, Dutch, German, Danish, Swedish,
14102Norwegian, Finnish, Faroese, Icelandic, Irish, Scottish, and as well
14103as Afrikaans and Swahili.
14104
14105Gri uses the ISO-Latin-1 font encodings by default, although the
14106so-called `standard' font-encoding may also be selected with the
14107@code{Set Font Encoding} command (@ref{Set Font Encoding}).  For more
14108on font encodings see any book on PostScript fonts ... although the
14109bottom line is that if you are using accented characters in your work,
14110then you probably already know about encodings, and if you don't use
14111accents then you needn't learn about this topic except for the
14112pleasure of learning about other languages.
14113
14114The method of handling accented characters is very simple.  If you can
14115type it, Gri can draw it!  It is up to you to determine how to enter the
14116accents.  Most text editors permit this.  Since many users will prefer
14117the Emacs editor, a few words about that are in order.
14118
14119For complete information about entering iso-latin-1 characters in Emacs,
14120consult your Emacs manual in the section
14121@ifinfo
14122@ref{(emacs)Single-Byte Character Support}
14123@end ifinfo
14124@ifhtml
14125@code{(emacs)Single-Byte Character Support}
14126@end ifhtml
14127which describes the available methods suitable for the Emacs version you
14128are using.  A few examples are nevertheless provided below.
14129
14130Consider the task of inserting French text, with the Emacs
14131text-editor. There are several ways of doing this (and you may wish to
14132consult your emacs info manual).  A method that works in emacs-19 up to
14133current emacs-20 versions uses the emacs @file{iso-transl.el} package by
14134putting the following in your @file{~/.emacs} file:
14135
14136@example
14137(require 'iso-transl)
14138(iso-transl-set-language "French")
14139(standard-display-european t)
14140@end example
14141
14142Loading the iso-transl package defines three ways of entering the non-ASCII
14143printable characters with codes above 127: the prefix @kbd{C-x 8}, or
14144the @key{Alt} key, or a dead accent key.  For example, you can enter
14145uppercase A-umlaut as @kbd{C-x 8 " A} or @kbd{Alt-" A} (if you have an
14146Alt key) or @kbd{umlaut A} (if you have an umlaut/diaeresis key).
14147
14148A more recently introduced method is to enter the mode which allows
14149quick insertion of iso-latin-1 characters. Do the Emacs command
14150@code{M-x iso-accents-mode} (either manually, or in a hook that's done
14151automatically). Now, suppose the x-axis is to represent temperature. All
14152you'd have to do is type in the command
14153
14154@example
14155set x name "Temp'erature"
14156@end example
14157
14158As you type, the quote mark will dissappear, and reappear as an accent
14159on the @code{e}.  And then, Gri will recognize this accented @code{�},
14160and it will draw the accent on the axis label.
14161
14162Perhaps the future default way of accomplishing this task is to use MULE
14163support directly.  First, customize MULE using
14164@code{M-x customize-group RET mule} setting the
14165@code{current language environment} (e.g. latin-1) and
14166the @code{default input method} (e.g. latin-1-prefix).  Then, invoking
14167@code{M-x toggle-input-method} (e.g. @key{C-\}) toggles into a mode similar
14168to the @code{iso-accents-mode} minor-mode described above.
14169
14170@c HTML <!-- newfile AdjustingCharacterPosition.html "Gri: adjusting character position" "Text" -->
14171
14172@node   Adjustment Of Character Position, Adding New Commands, Non-English Text, Text
14173@comment  node-name,  next,  previous,  up
14174@subsection Adjustment Of Character Position
14175@cindex text, thin-spaces within
14176@cindex thin-space in text
14177Micro-positioning is available within math-mode, via the
14178symbols @code{\!} (which means go left one thin-space) and @code{\,}
14179(which means go right one thin-space).  (A thin-space is 1/6 the width of
14180the letter ``M'').
14181
14182
14183@c HTML <!-- newfile NewCommands.html "Gri: Adding new commands" "Programming Gri" -->
14184
14185@node   Adding New Commands, Purpose, Adjustment Of Character Position, Programming
14186@comment  node-name,  next,  previous,  up
14187@section Adding new commands to Gri
14188@cindex commands, how to add new ones to Gri
14189@cindex new commands, how to add to Gri
14190@cindex adding new commands to Gri
14191@cindex extending Gri by adding new commands
14192Gri provides so-called "newcommands" as a sort of subroutine syntax on steroids.
14193@menu
14194* Purpose::                       What newcommands are for
14195* Parsing::                       How Gri parses commands
14196* Simple New Command::            Simple example of adding new command
14197* Complicated New Command::       More complicated example
14198* Changeable Command Arguments::  The &.var. and &\syn syntax
14199@end menu
14200
14201@c HTML <!-- newfile PurposeOfSynonyms.html "Gri: Purpose of Synonyms" "Programming Gri" -->
14202@node   Purpose, Parsing, Adding New Commands, Adding New Commands
14203@comment  node-name,  next,  previous,  up
14204@subsection Purpose of newcommands
14205Gri can be extended easily.  Primitive commands (e.g. @code{set x name})
14206can be supplemented with so-called "new commands."  New commands are a
14207little like subroutines other programming languages.  For example, you
14208might find that you often draw filled curves with a particular graylevel
14209(say 0.5), and then return the graylevel to the previous value.  This
14210requires you to do the following each time:
14211
14212@example
14213new .old_graylevel.
14214.old_graylevel. = ..graylevel..
14215set graylevel 0.5
14216draw curve filled to 0 y
14217set graylevel .old_graylevel.
14218delete .old_graylevel.
14219@end example
14220
14221@noindent
14222This gets a bit tedious, and it would obviously be nicer to just say
14223something like
14224
14225@example
14226Draw my kinda curve
14227@end example
14228
14229To make this shortcut, you'd tell Gri about the existence of a new
14230command called @code{Draw my kinda curve}, and tell it that the new
14231command can be accomplished by the longer code fragment written above.
14232
14233Once you've learned how to make new commands, you are likely to use them
14234a lot.  The following explains how you add new commands.  For advice on
14235programming style, etc., (@ref{Resource File}).
14236
14237
14238@c HTML <!-- newfile ParsingSynonyms.html "Gri: How synonyms are parsed" "Programming Gri" -->
14239@node   Parsing, Simple New Command, Purpose, Adding New Commands
14240@comment  node-name,  next,  previous,  up
14241@subsection How Gri parses commands
14242@cindex new commands, how they are parsed
14243Whenever Gri reads a command line, it compares it with its list of
14244commands.  This list is searched in this order: (1) the universal
14245@file{gri.cmd} file (@ref{Invoking Gri}), (2) your resource
14246file (@ref{Resource File}), if it exists, and then (3) your command
14247file itself.  Gri stops searching when it finds a Gri command that
14248matches the command line.  "Matching" means that the command line is
14249identical in all words in a Gri command, scanning from the left, until
14250it encounters a word containing
14251@itemize @bullet
14252@item
14253A quote (e.g. @code{"string"})
14254@item
14255A synonym name (e.g. @code{\file})
14256@item
14257A variable name (e.g. @code{.number.})
14258@item
14259An opening square bracket (e.g. @code{[option]})
14260@item
14261An opening brace (e.g.  @code{@{a|b@}})
14262@item
14263A choice between two items (e.g.  @code{first|second})
14264@item
14265A variable-name with a @code{&} character immediately to the left
14266(e.g. @code{&.var.}).  This is a signal that the variable may be
14267changed inside the newcommand (@ref{The Ampersand Syntax}).
14268@item
14269A synonym-name with a @code{&} character immediately to the left
14270(e.g. @code{&\syn}).  This is a signal that the synonym may be
14271changed inside the newcommand (@ref{The Ampersand Syntax}).
14272@end itemize
14273
14274When Gri finds a command that matches your command line, it assumes that
14275this is the intended command, and searches no further.  This means that
14276you must be careful not to have your command hidden by other commands.
14277For example, if your resource file contained these lines, Gri would
14278@strong{never} execute the second new command, because calls to it match
14279the first command.  To avoid this, you may either reverse the order of
14280the definitions, so that Gri will find the proper routine, or rename one
14281of the routines.
14282
14283@example
14284`Draw foo'
14285Draw a foo.
14286@{
14287  show "drawing a foo"
14288@}
14289`Draw foo bar'
14290Draw a foo bar.
14291@{
14292  show "drawing a foo bar"
14293@}
14294@end example
14295
14296Gri searches the @file{gri.cmd} file first, so any new command that you
14297create that clashes with built-in commands will be ignored by Gri
14298(@ref{Invoking Gri}).  Gri will warn you of this, and proceed,
14299ignoring your newer definition.  To get around this,
14300you can use capital letters
14301to begin the words of your new command.  By convention, Gri never uses
14302capital letters in this way, so a clash is impossible (except with any
14303similar command you might have defined previously, such as in your
14304@file{~/.grirc} file).
14305
14306@c HTML <!-- newfile SimpleNewCommand.html "Gri: creating a simple new command" "Programming Gri" -->
14307
14308@node   Simple New Command, Complicated New Command, Parsing, Adding New Commands
14309@comment node-name,  next,  previous,  up
14310@subsection Simple example of a new command
14311@cindex new commands, simple example
14312To make a new command called @code{Show The Time} insert the following
14313into your @file{~/.grirc} resource file or into your command-file
14314somewhere near the top, or at least before you use the command.
14315
14316@example
14317`Show The Time'
14318New command to show the time of day.
14319@{
14320  show "\.time."
14321@}
14322@end example
14323
14324@noindent
14325EXPLANATION:
14326@itemize @bullet
14327
14328@item
14329The name of the new command is enclosed in angled single-quote marks.
14330The words of the new command should begin with upper-case letters to
14331prevent a name clash with a present or future built-in Gri command.
14332@strong{Formatting convention:} Make sure that the entire definition
14333string, from the opening angled quote to the ending angled quote,
14334appears on one line.  Otherwise Gri will give an error like
14335
14336@example
14337ERROR: Can't extract syntax for new command
14338@end example
14339
14340@item
14341Following the name line, you may optionally insert any number of lines
14342which will become the @code{help} information for the new command.  See
14343the file @file{gri.cmd} for the recommended stylistic conventions in
14344writing help information (@ref{Invoking Gri}). If your @code{help} text
14345includes an example that uses an opening brace (@code{@{}) you must
14346escape the brace with a backslash, e.g. (@code{\@{}).
14347@item
14348Following the help lines, if they exist, the body of the new command is
14349given, sandwiched between a starting line containing an opening brace
14350(@code{@{}) as the @strong{only} nonwhite character, and an ending line
14351containing a closing brace (@code{@}}) as the only nonwhite character.
14352Any valid Gri commands may be used in the body of the new command.  It
14353is acceptable to use other new commands in the body. Recursion is also
14354allowed -- a new command is allowed to call itself (although there is a
14355limit on nesting, of perhaps a thousand or so; this varies with the
14356version of Gri).  @strong{Formatting convention:} It is usual, but not
14357necessary, to use an indentation level of 2 spaces in the body of the
14358new command.
14359@end itemize
14360@noindent
14361The new command is invoked by @code{Show The Time}.  Help for the
14362command is found by @code{help Show The Time} or @code{help Show}.
14363
14364
14365@c HTML <!-- newfile ComplicatedNewCommand.html "Gri: creating a complicated new command" "Programming Gri" -->
14366
14367@node   Complicated New Command, Changeable Command Arguments, Simple New Command, Adding New Commands
14368@comment node-name,  next,  previous,  up
14369@subsection Complicated example of a new command
14370@cindex extending Gri by adding new commands, complicated example
14371@cindex adding new commands, complicated example
14372@cindex new commands, complicated example
14373The following example from the global @file{gri.cmd} file illustrates
14374how to parse/check the commandline (@ref{Local Synonyms}), which is a
14375good practice in any code you expect to re-use.  The first @code{if}
14376statement checks that the word @code{at} is in the right place (this
14377would not have been checked by the syntax matcher, the word having
14378followed a string).  The presence of the keyword @code{cm} is checked
14379for, and user units or cm units are used accordingly.  Local variables
14380are created (@code{new}) and then destroyed (@code{delete}) so that
14381this new command cannot affect outside code.
14382
14383@example
14384`draw label whiteunder "\string" at .xleft. .ybottom. [cm]'
14385Draw label for plot, located with lower-left corner
14386at indicated (x,y) position (specified in user
14387units or in cm on the page).  Whiteout is used
14388to clean up the area under the label.  BUGS:
14389Cannot handle angled text; doesn't check for
14390super/subscripts.
14391@{
14392    if @{rpn "\.word4." "at" !=@}
14393      show "ERROR: 5th word must be `at', not `\.word4.'"
14394      show traceback
14395      quit
14396    end if
14397    new .x. .y. .oldgray. .space.
14398    if @{rpn \.words. 7 ==@}
14399      .x. = @{rpn \.word5. xusertocm@}
14400      .y. = @{rpn \.word6. yusertocm@}
14401    else if @{rpn \.words. 8 ==@}
14402      if @{rpn "\.word7." "cm" !=@}
14403        show "ERROR: Require 8th word to be `cm'"
14404        show traceback
14405        quit
14406      end if
14407      .x. = \.word5.
14408      .y. = \.word6.
14409    else
14410      show "ERROR: Require 7 or 8 words, not \.words."
14411      show traceback
14412      quit
14413    end if
14414    # Coordinates now in cm.  Next, white out a box
14415    # under the text (and .space. centimetres
14416    # beyond text), then draw label.
14417    .space. = 0.1               # Space of 1mm
14418    .oldgray. = ..graylevel..
14419    set graylevel white
14420    draw box filled                          \
14421      @{rpn .x. .space. -@}                    \
14422      @{rpn .y. .space. -@}                    \
14423      @{rpn .x. "\.word3." width + .space. +@} \
14424      @{rpn .y. "M" ascent + .space. + @} cm
14425    set graylevel .oldgray.
14426    draw label "\.word3." at .x. .y. cm
14427    delete .x. .y. .oldgray. .space.
14428@}
14429@end example
14430
14431
14432@c HTML <!-- newfile ChangeableCommandArguments.html "Gri: making a newcommand change its arguments" "Programming Gri" -->
14433
14434@node   Changeable Command Arguments, The Ampersand Syntax, Complicated New Command, Adding New Commands
14435@comment node-name,  next,  previous,  up
14436@subsection Altering command arguments -- the @code{&} syntax
14437@cindex command arguments, how to alter
14438@cindex newcommand arguments, how to alter
14439@cindex arguments to new commands, how to alter
14440@cindex the @code{&.variable.} notation
14441@cindex the @code{&\synonym} notation
14442@cindex variables, and the @code{&} syntax
14443@cindex synonym, and the @code{&} syntax
14444
14445The Gri language permits a newcommand to change variables and synonyms
14446passed as arguments, using a syntax that is quite similar to that
14447employed by the C++ language.
14448
14449@menu
14450* The Ampersand Syntax::                Denoting changeable arguments
14451* Doubling A Variable::                 Variables (e.g. @code{&.variable.})
14452* Manipulating A Synonym::              Synonyms (e.g. @code{&\synonym})
14453* Nesting::                             Newcommands called by newcommands
14454* Using New And Delete::                Isolating local variables and synonyms
14455* Determining Calling Information::     The @code{\&.word?.} and @code{\&&.word?.} syntax
14456* Implementation of Ampersand Syntax::  Algorithm Gri uses
14457@end menu
14458
14459
14460@node   The Ampersand Syntax, Doubling A Variable, Changeable Command Arguments, Changeable Command Arguments
14461@comment  node-name,  next,  previous,  up
14462@subsubsection Overview of the @code{&} syntax
14463
14464Normally the arguments to a newcommand are parsed into either numerical
14465values or strings, before execution is passed into the newcommand.  This
14466is a akin to the scheme called "call by value" in some programming
14467languages.  Gri also provides a syntax, borrowed from C++, that permits
14468a newcommand to alter the contents of variable or synonym arguments.
14469
14470The technique is simple.  To permit a newcommand to modify an argument
14471that is a variable or a synonym, just put a @code{&} to the left of the
14472item on the calling line.  Then, within the newcommand, the
14473corresponding local synonym (i.e. @code{\.word1.}, etc.) will behave as
14474though it were the instance of the original variable or synonym.
14475
14476The @code{&} is placed to the left of the variable-name or synonym-name
14477without intervening space.  For example @code{foo &.var. &\syn} tells
14478the parser that the newcommand named @code{foo} may possibly alter the
14479values of the variable @code{.var.} and the synonym @code{\syn}, as they
14480exist in the calling context.
14481
14482It is important to note that Gri pays very little attention to the
14483@code{&} in a syntax-declaration line.  All it does is to note that the
14484item to the right of the @code{&} is not a fixed word in the newcommand
14485being defined; this follows the usual rules for parsing newcommand syntax
14486(@ref{Parsing}).
14487
14488
14489@node   Doubling A Variable, Manipulating A Synonym, The Ampersand Syntax, Changeable Command Arguments
14490@comment  node-name,  next,  previous,  up
14491@subsubsection Example: doubling a variable
14492
14493Consider the task of adding a fixed amount to a variable.  If the
14494variable we wish to double is @code{.x.}, we might write
14495
14496@example
14497`double_a_particular_variable'
14498@{
14499    .x. = @{rpn .x. 2 *@}
14500@}
14501.x. = 10
14502double_a_particular_variable
14503@end example
14504
14505@noindent
14506Code such as that presented above occurs in many applications.  (Turn
14507the multiplication into an addition, and change @code{.x.} to
14508@code{..ymargin..}, and you'll start to see the core of an application
14509that draws multiple graph panels, one above another.)  However, the code
14510is too specific to be of much general use!
14511
14512What if we want to double some other variable instead?  The code below
14513shows how to do that.
14514
14515@example
14516`double &.value.'
14517@{
14518    \.word1. = @{rpn \.word1. 2 *@}      # line 3
14519@}
14520.x. = 10                               # line 5
14521double &.x.
14522.y. = 3.14
14523double &.y.
14524@end example
14525
14526@noindent
14527At line 3 Gri interprets the @code{\.word1.} to the @strong{left} of the
14528equals sign as a reference to the variable that is set to the value 10
14529in line 5.  Similarly, the @code{\.word1.} to the @strong{right} of the
14530equals sign evaluates to 10, the value in the calling program.
14531
14532Gri automatically determines whether an item is a variable or a synonym,
14533and does the correct thing.  Thus, for example, if line 3 above were written as
14534
14535@example
14536\.word1. = "hello"                 # ERROR
14537@end example
14538
14539@noindent
14540an error would be reported, since @code{double} was called with a
14541variable as an argument, and variables cannot hold strings.
14542
14543@node   Manipulating A Synonym, Nesting, Doubling A Variable, Changeable Command Arguments
14544@comment  node-name,  next,  previous,  up
14545@subsubsection Example: manipulating a synonym
14546
14547Synonyms are treated in the same way, as is illustrated in the following
14548example.
14549
14550@noindent
14551Q: what does the following print?
14552
14553@example
14554`add_a_dat &\filename'
14555@{
14556    \.word1. = @{rpn "\.word1." ".dat" strcat@}
14557@}
14558\filename = "test"
14559add_a_dat &\filename
14560show "\filename"
14561@end example
14562
14563@noindent
14564A: it prints @code{test.dat}.
14565
14566
14567@node   Nesting, Using New And Delete, Manipulating A Synonym, Changeable Command Arguments
14568@comment  node-name,  next,  previous,  up
14569@subsubsection Nesting
14570
14571One newcommand may call another, letting a deeply-nested newcommand
14572alter values of synonyms and variables that may otherwise be hidden
14573behind @code{new} items of the same name.  This is done by using the
14574@code{&} notation at each step.  The following provides an example of
14575passing a variable through two levels of newcommands.
14576
14577@noindent
14578Q: what does the following print?
14579
14580@example
14581`food critic &food'
14582@{
14583    \.word2. = "\.word2.s"
14584    yummy &\.word2.
14585@}
14586`yummy &foods'
14587@{
14588    \.word1. = "\.word1. are tasty"
14589@}
14590\a = "apple"
14591food critic &\a
14592show "\a"
14593@end example
14594
14595@noindent
14596A: it prints @code{apples are tasty}.
14597
14598
14599
14600@node   Using New And Delete, Determining Calling Information, Nesting, Changeable Command Arguments
14601@comment  node-name,  next,  previous,  up
14602@subsubsection About @code{new} and @code{delete}
14603
14604@cindex @code{new}, used on changeable arguments
14605@cindex @code{delete}, used on changeable arguments
14606@cindex changeable arguments, using @code{new} on
14607@cindex changeable arguments, using @code{delete} on
14608
14609If @code{new} and @code{delete} are executed on local synonyms inside
14610newcommands (e.g.  @code{new \.word1.})  they create and destroy
14611variables and synonyms in the context of the @strong{calling program}.
14612
14613For example, consider the following.
14614
14615@noindent
14616Q: what does the following print?
14617
14618@example
14619`poetry &\s'
14620@{
14621    new \s                             # line 3
14622    \s = "rose"
14623    \.word1. = "\.word1. is a \s"      # line 5
14624    delete \s                          # line 6
14625@}
14626\s = "A rose "                         # line 8
14627poetry &\s
14628show "\s"
14629@end example
14630
14631@noindent
14632A: it prints @code{A rose is a rose}.
14633
14634The key point here is that the instance of the synonym named @code{\s}
14635in the calling program, set in line 8, is modified by the @code{poetry}
14636newcommand, in line 6.  This modification involves the use of a synonym,
14637@strong{also named} @code{\s}, that "lives" wholly within the newcommand,
14638being created in line 3 and destroyed in line 6.
14639
14640
14641@node   Determining Calling Information, Implementation of Ampersand Syntax, Using New And Delete, Changeable Command Arguments
14642@comment  node-name,  next,  previous,  up
14643@subsubsection Determining calling information
14644
14645@cindex @code{\&} and @code{\&&} notation
14646@cindex newcommands, determining calling argument names with @code{\&}
14647@cindex newcommands, determining calling argument level with @code{\&&}
14648
14649Newcommands may determine the name and the nesting level of changeable
14650calling arguments.  To get the name, put a single ampersand after the
14651backslash of the local synonym of interest.  To get the nesting level (0
14652for main program, etc.) put two ampersands after the backslash.
14653@example
14654`NC &.var.'
14655@{
14656    show "\&.word1. (expect '.a.')"
14657    show "\&&.word1. (expect 0)"
14658@}
14659.a. = 1
14660NC &.a.
14661@end example
14662
14663@strong{Note}: neither of these items may be used an lvalue.  That is,
14664they may not be used to the left of an equals sign.  But you can always
14665get around that by clever use of alias synonyms (@ref{Alias Synonyms}).
14666
14667
14668
14669@node   Implementation of Ampersand Syntax, Hints, Determining Calling Information, Changeable Command Arguments
14670@comment  node-name,  next,  previous,  up
14671@subsubsection How Gri implements the @code{&} syntax
14672
14673@cindex @code{&} syntax, how it is parsed
14674@cindex parsing of the @code{&} syntax
14675
14676When the parser encounters an unquoted @code{&} followed immediately by
14677the name of a variable or a synonym, it converts the whole token
14678(@code{&} plus name) into a specially-encoded string that can be
14679recognized inside newcommands.  (This is @strong{only} done if the
14680@code{&} and the variable name are @strong{not} enclosed in double
14681quotes.)
14682
14683This specially-encoded string contains not just the name of the variable
14684or synonym, but also the current level of nesting of newcommands.  In
14685this way a newcommand can have its own private versions of variables,
14686created by @code{new}, that won't be misinterpreted for the
14687identically-named variables in the calling program.
14688
14689The format of these specially-encoded strings is
14690@code{#\bn\ba\bm\be\b:\bN \b_ \bl\be\bv\be\bl\b:\bL#\b},
14691where @code{N} stands for
14692the name of the variable/synonym, @code{L} stands for the current level,
14693and @code{\b} is the backspace character (hexadecimal 08 in the ascii
14694table).  This string is designed to be strange enough that users are
14695unlikely to use it themselves.  The coding scheme is not entirely
14696arbitrary, however; note that if the backspace characters are ignored
14697the result has the form @code{name:N_level:L}.  It's also worth noting
14698that if this string were printed on a terminal that erased characters
14699when typing backspaces the result would be of the form @code{N_L}.
14700
14701Examples: @code{@.a.} in the main program
14702(i.e. at level 0) encodes to
14703@code{#\bn\ba\bm\be\b:\b.a. \b_ \bl\be\bv\be\bl\b:\b0#\b}
14704and @code{&\my_syn} inside a newcommand called by the main program
14705(i.e. at level 1) encodes to
14706@code{#\bn\ba\bm\be\b:\b\my_syn \b_ \bl\be\bv\be\bl\b:\b1#\b}.
14707
14708Inside a newcommand, Gri checks to see if builtin synonyms
14709(e.g. @code{\.word1.}) hold such specially-encoded strings.  If so, then
14710the appropriate versions of the variables are used in preference to any
14711variables that may have been newly created by @code{new} inside the
14712newcommand.
14713
14714
14715
14716@c HTML <!-- newfile Hints.html "Gri: Hints for Gri programming" "Programming Gri" -->
14717
14718@node   Hints, Debugging, Implementation of Ampersand Syntax, Programming
14719@comment  node-name,  next,  previous,  up
14720@section Hints for Gri Programming
14721@cindex hints
14722
14723Here are some hints for good Gri programs:
14724
14725@itemize @bullet
14726@item
14727Whenever working with grids (for contouring) or images, make use of the
14728@code{show grid} or @code{show image} commands.  They will give you
14729useful information about the statistics (min/max/histogram) of the items.
14730@item
14731Use the operating system, not Gri, to manipulate your data.  For
14732example, if you have a file whose first column is x times 100, and third
14733is the arcsin of y, you could do:
14734
14735@example
14736open "gawk '@{print $1/100, sin($3)@}' |"
14737read columns x y
14738@end example
14739
14740If you have x and y in a non-decimal geographical format
14741(e.g. hour.minute-second format), use the operating system to convert
14742for you (@ref{Open}).
14743@item
14744Use the @code{pstack} operator liberally in your rpn expressions
14745to see what is going on (@ref{rpn Mathematics}).
14746@item
14747While developing programs, put a @code{show columns statistics} command
14748after every @code{read column} command, to check that the data have been
14749read correctly.
14750@item
14751Development time can be minimized by limiting the number of data being
14752processed.  For example, in a multi-panel plot, it is often necessary to
14753try various alternatives before aesthetic scales and page layout is
14754achieved.  The process can be speeded up by limiting the number of data
14755being processed, as shown below.  (If Gri finds fewer data in the file
14756than specified, it will simply use the data that it found; so when the
14757program works, just change @code{.n.} into something large.)
14758
14759@example
14760.n. = 100 # 10000 for later
14761...
14762# Panel 1
14763read columns .n. x y
14764...
14765# Panel 2
14766read columns .n. x y
14767...
14768@end example
14769
14770@item
14771Create new commands to do repetitive work.
14772@item
14773Use @code{draw time stamp} on all plots except for publication versions:
14774
14775@example
14776if !..publication..
14777  draw time stamp
14778end if
14779@end example
14780
14781@item
14782For multiple panels on one page, do @code{delete x scale}
14783or @code{delete y scale} before each
14784new panel, so you will start afresh.  Clearly identify
14785code for particular panels with
14786comments.  This reduces errors you might get if you shuffle things
14787later.
14788@item
14789Use the @code{..num_col_data..} built-in variable to see how many data
14790have passed the @code{set input data window} data window in the last
14791@code{read columns} command.  The following example shows how to
14792avoid drawing an unwanted curve:
14793
14794@example
14795open \f
14796read columns x y
14797close
14798if ..num_col_data..
14799  draw curve
14800  draw label "\f" at \
14801      @{rpn ..xlast.. xusertocm 0.5@} \
14802      @{rpn ..ylast.. yusertocm 0.2@} cm
14803end if
14804@end example
14805
14806@cindex hint, using @code{query} to interact with user
14807@item
14808Use synonyms and @code{query} for filenames.  This makes programs much
14809more flexible.  Note that you can string synonyms together:
14810
14811@example
14812\dir = "~/EOS/iso0/"
14813query \file "Give file in directory \dir" ("1.dat")
14814open \dir/\file
14815@end example
14816
14817It is also a good idea to give a restrictive list of possibilities in
14818your @code{query} command, to avoid complicated @code{if} commands later
14819(@ref{Query}).
14820@item
14821Use multiple @code{draw title} commands:
14822
14823@example
14824draw title "Atlantic water entering Arctic Ocean"
14825draw title "\.command_file. \.time."
14826@end example
14827
14828@item
14829Use the @code{query} command to interact with the user (@ref{Query}).  The results can be stored in variables and synonyms.
14830
14831@end itemize
14832
14833
14834@c HTML <!-- newfile Debugging.html "Gri: Debugging Gri programs" "Programming Gri" -->
14835
14836@node   Debugging, Error Messages, Hints, Programming
14837@comment  node-name,  next,  previous,  up
14838@section Debugging Gri Programs
14839@cindex debugging Gri programs
14840@cindex problems and how to cope with them
14841Here are some hints for debugging Gri programs:
14842@itemize @bullet
14843@item
14844If no data appear on an xy plot, insert @code{show columns statistics}
14845or @code{show columns} after the @code{read columns} command.  It may be
14846that you have fixed your axes, and that the axes frame does not include
14847the data.
14848@item
14849@cindex tracing execution, using @code{..trace..}
14850If you get an error message, rerun your Gri program using the
14851@code{-trace} command-line option, to see which line is causing the
14852problem.  This often reveals logic errors (e.g. in (@code{if}
14853statements).  You may also turn tracing on or off at any point in your
14854Gri program by setting the built-in variable @code{..trace..} to 1 or 0.
14855Many Gri users have the Gri command aliased to be in trace mode by
14856default.
14857@item
14858If Gri complains of a syntax error, consult the printed manual, one of
14859the online manuals, or the online help facility (@ref{Online Help}).
14860@item
14861Check the version number (printed at startup) to see if a new version of
14862Gri has been installed, and check the manual for known incompatabilities.
14863@item
14864Sprinkle @code{show} commands throughout your program, to see what's
14865happening.  Even when you are sure your program works, it is a good idea
14866to embed @code{show} statements so are they executed if the
14867@code{-debug} flag is set:
14868
14869@example
14870if ..debug..
14871  show "X=" .x. "and label is `\label'"
14872end if
14873@end example
14874
14875
14876@item
14877If your @code{draw} commands don't draw anything, check to see
14878whether you've fooled yourself by enforcing an improper scaling; remove
14879explict scaling (@code{set x axis ...}), clipping (@code{set clip}), data
14880selection windows (@code{set input data window x|y}) and missing values
14881(@code{set missing value}).  Another trick is to read only a portion of
14882the data set (@code{read columns 10 x y}) and then print out all the
14883values (@code{show columns}).
14884@end itemize
14885
14886If you determine that the bug is in Gri, not in your program, please
14887report the bug, so that other users will not have the same hassle;
14888(@ref{Reporting Bugs}).
14889
14890
14891
14892@c HTML <!-- newfile ErrorMessages.html "Gri: error messages" "Programming Gri" -->
14893@node   Error Messages, Missing Values, Debugging, Programming
14894@comment  node-name,  next,  previous,  up
14895@section Error Messages
14896@cindex error messages
14897Gri error messages are in three types:
14898@enumerate
14899@item
14900Operating system error messages, such as @code{segmentation fault}.
14901These should never appear, and indicate a bug in Gri.  Please report
14902these to the author (@ref{Reporting Bugs}).
14903@item
14904Internal Gri error messages.  The message starts with the words
14905@code{FATAL error}, and quotes a file number and a line number, e.g.
14906
14907@example
14908FATAL error: startup.c:199: ...
14909@end example
14910
14911@noindent
14912Such errors indicate either a deficiency in your computer (e.g.
14913insufficient storage space) or an internal bug in Gri.  If the message
14914does not indicate running out of storage, please report the error to the
14915author (@ref{Reporting Bugs}).
14916
14917For fatal error messages on a unix system, Gri dumps core, unless you
14918have turned that feature off, with the @code{ulimit -c 0} unix command
14919in a startup file.  This creates a file called @file{core}, which can
14920help you in diagnosing the Gri bug.  If you have the @code{gdb}
14921debugger, just type @code{gdb gri core} and then type @code{where} to
14922get a traceback stack.  Please email this with your other information
14923about the Gri bug.
14924@item
14925An indication that your commandfile is flawed, either in syntax or in
14926meaning.  These messages end with a line indicating the offending line
14927in your commandfile, e.g. the command @code{set x axis 0 1 -1} yields:
14928
14929@example
14930ERROR: `set x axis .left. .right. .incBig.'
14931        has .incBig. of wrong sign
14932 Bad command:  `set x axis 0 1 -1 '
14933@end example
14934
14935@noindent
14936Normally, such error messages do not indicate a flaw in Gri, but rather
14937in your reasoning, so report them to the author only if you are very
14938sure that a Gri bug must underly them.
14939@end enumerate
14940
14941
14942
14943@c HTML <!-- newfile MissingValues.html "Gri: missing values" "Programming Gri" -->
14944@node   Missing Values, Operating System, Error Messages, Programming
14945@comment  node-name,  next,  previous,  up
14946@section Missing data
14947@cindex data, missing values
14948@cindex missing value code
14949@cindex NaN for missing value code
14950@vindex @code{..missingvalue..}, value for missing data
14951Most Gri commands will ignore data points equal to a "missing value."
14952For example, @code{draw curve} connects only points which are not equal
14953(to within 0.01 percent) of the missing value.  The curve has holes at
14954missing data.  Initially the missing-value is set to 1.0e22.  You may
14955alter this value with @code{set missing value .value.}.
14956The built-in variable @code{..missingvalue..} stores the current value
14957of the missing-value.
14958
14959Additionally, Gri will ignore anything it reads that is equal to the
14960string @code{NaN} or @code{Inf}.  These are produced by matlab, C, and
14961other programs when dividing by zero, etc.
14962
14963Gri also ignores mathematical operations on data items which are equal to
14964the missing value.  Thus, for example, if your missing value is -99 then
14965the command @code{x += 1} will not change the values equal to -99 to -98,
14966since this would have the side-effect of making the datum no longer be
14967considered missing.
14968
14969
14970@c HTML <!-- newfile OperatingSystem.html "Gri: operating system" "Programming Gri" -->
14971
14972@node   Operating System, Using OS Inside Gri, Missing Values, Programming
14973@comment  node-name,  next,  previous,  up
14974@section Interaction Between Gri and Operating System
14975@cindex awk, sample of use
14976@cindex operating system commands, printing results of
14977@cindex system commands, printing results of
14978@cindex operating system commands, assigned to synonyms
14979@cindex system commands, assigned to synonyms
14980
14981@menu
14982* Using OS Inside Gri::         Accessing the OS from inside Gri
14983* Using Gri Inside OS::         Tricks for using Gri in unix
14984@end menu
14985
14986@node   Using OS Inside Gri, Using Gri Inside OS, Operating System, Operating System
14987@comment  node-name,  next,  previous,  up
14988@subsection Using the OS from within Gri
14989
14990Gri uses the operating system internally for things like paging through
14991help information.
14992
14993@cindex system calls, using dollar-parenthesis shell syntax
14994@cindex protecting Gri programs against datafile movement
14995@cindex unix, dollar-parenthesis notation within Gri commands
14996@cindex @code{\$()} syntax for system commands
14997@cindex dollar-parenthesis syntax for system commands
14998The operating system may be called @strong{within} Gri commands, using a
14999syntax borrowed from the @code{Bash} unix shell.  After substituting
15000synonyms in the commandline, Gri scans for dollar-parenthesis blocks
15001(e.g. @code{\$(system-command)}, replacing them with the textual result
15002of sending the indicated system-command to the OS.  The replacements are
15003done from left to right in the commandline, starting at the deepest
15004nesting level.
15005
15006@cindex pathname of commandfile
15007@cindex commandfile, pathname
15008Often the dollar-parentheis syntax is used in title commands, to
15009indicate the full pathname of the Gri commandfile, e.g.
15010
15011@example
15012draw title "\$(pwd)/\.command_file."
15013@end example
15014
15015In assignment to synonyms, expansion of dollar-parenthesis is not done.
15016Thus the operating system is called twice on the second line below, and
15017not at all on the first line; to see this, run it as @code{gri -s8 -t}.
15018
15019@example
15020\dir = "\$(echo $MY_DIR)"
15021show "\$(head -1 \dir/MY_FILE)"
15022@end example
15023
15024@strong{Syntax Note} Dollar-parenthesis blocks must be prefixed with
15025backslash to avoid confusion with math expressions within strings, for
15026example to avoid breaking @code{draw label "$(x,y)$" at 3 3 cm}.  This
15027is an example of how @TeX{} notation and unix shell notation collide.
15028
15029@strong{Example} It is a good idea to employ unix environment variables to name
15030directories containing data, so that Gri scripts will work unchanged
15031even if the data are moved (so long as the environment variables are
15032altered), e.g.
15033
15034@cindex using environment variables for directory names
15035@cindex strings, embedding OS output into
15036@cindex OS, embedding system output into strings
15037@cindex calling OS from within strings
15038
15039@example
15040# Figure how many lines in a file
15041\dir ="$(echo DIRECTORY_WHERE_I_STORE_SOLAR_DATA)"
15042open "\dir/solar_data_file_name`
15043...
15044open "\$(echo DIR_ANOTHER)/another_data_set"
15045@end example
15046
15047@noindent
15048Another method is to pass instructions to the operating system with the
15049@code{system} command.  This discards output.  Whatever follows the word
15050@code{system} is first scanned for synonyms (but not rpn expressions or
15051variables); after replacement of any existing synonyms, the line is
15052passed directly to the operating system.  Any results are printed on the
15053terminal.
15054
15055Frequently used system commands are @code{awk}, @code{head}, @code{grep} and
15056@code{sed}.  Examples:
15057
15058@itemize @bullet
15059@item
15060Here's how to paste several files together to form a temporary file for
15061plotting.  (Notice that a temporary file incorporating the PID of the job
15062is created and later removed.)
15063
15064@example
15065system paste -d" " 1.dat 2.dat 3.dat > tmp.\.pid.
15066open tmp.\.pid.
15067read columns x y
15068close
15069system rm tmp.\.pid.
15070@end example
15071
15072@item
15073Here's how to plot each line in a file called @file{inp} which has
15074the string @code{;} at the start of the line.
15075
15076@example
15077system cat inp | grep -v "^;" | cat > tmp.\.pid.
15078open tmp.\.pid.
15079read columns x y
15080system rm tmp.\.pid.
15081@end example
15082
15083@item
15084Here's how to use the @code{awk} system command to create a tabulated
15085function for plotting.
15086
15087@example
15088system awk                             \
15089    'BEGIN @{                           \
15090       for (x=0; x<1; x+=0.1) @{        \
15091         printf ("%f %f\n", x, sin(x)) \
15092       @}                               \
15093     @}'                                \
15094    > tmp.\.pid.
15095open tmp.\.pid.
15096read columns x y
15097close
15098system rm tmp.\.pid.
15099draw curve
15100@end example
15101
15102@cindex pipes, opening files through them
15103@cindex opening files through pipes
15104
15105@noindent
15106This example is more cleanly written using the piping facility of the
15107@code{open} command (which automatically creates a temporary file, and
15108destroys it when @code{close} is done)
15109
15110@example
15111open "awk 'BEGIN @{       \
15112  for(x=0;x<1;x+=0.1) @{  \
15113    print(x,sin(x))      \
15114  @}                      \
15115@}'|"
15116read columns x y
15117close
15118draw curve
15119@end example
15120
15121
15122@item Sometimes you need just a single output item from the operating
15123system.  In this case, you can store the results from the operating
15124system in a synonym by using the @code{\synonym = system ...}
15125assignment command.
15126@item
15127@cindex temporary file allocation
15128@cindex file, temporary
15129@cindex filename, temporary
15130@cindex @code{tmpname}
15131subroutine A related command is @code{\synonym = tmpname}, which
15132stores in the synonym the name of a temporary file created by the
15133system.  The file is created with the @code{tmpname} system call, so
15134it is guaranteed not to clash with any existing files.  Typically, the
15135filename is something like @file{/usr/tmp/griAAAa1233}.  In many cases
15136you'll want to remove the file within Gri, once you're done, and that
15137can be done with @code{unlink} (@ref{Unlink}) or with a
15138@code{system rm -f} command.  A useful bit of code is as follows
15139@example
15140\file = tmpname
15141system ... SOME_SYSTEM_COMMANDS ... > \file
15142... use this new file for something ...
15143unlink \file
15144@end example
15145
15146@end itemize
15147
15148
15149@node   Using Gri Inside OS, Resource File, Using OS Inside Gri, Operating System
15150@comment  node-name,  next,  previous,  up
15151@subsection Using Gri from within the OS
15152
15153@strong{This section only applies to unix systems.}
15154
15155Save the following into a file called @file{p} and then make it
15156executable using @code{chmod}.  It runs Gri on a named file, with the
15157@code{-yes} flag set
15158so that any @code{query} commands are automatically answered in the
15159affirmative, and then displays the results in a Ghostscript window.
15160(USAGE: @code{p cmdfile.gri})
15161
15162@example
15163#!/usr/bin/sh
15164# Run Gri, then plot in gs window
15165case $# in
151661)
15167        base=`basename $1 .gri | sed -e s/.*,#`
15168        gri -yes $base.gri && ghostview $base.ps
15169        ;;
15170*)
15171        echo "Proper usage: $0 cmdfile.gri"
15172        ;;
15173esac
15174@end example
15175
15176
15177@c HTML <!-- newfile ResourceFile.html "Gri: The Gri resource file" "Programming Gri" -->
15178
15179@node   Resource File, Environment, Using Gri Inside OS, Programming
15180@comment  node-name,  next,  previous,  up
15181@section Sample Resource File
15182@cindex files, @file{~/.grirc} initialization file
15183@cindex @file{~/.grirc} initialization file
15184@cindex initialization commands
15185@cindex startup commands
15186@cindex resource files
15187
15188The following shows a sample @file{~/.grirc} resource file.  Much of the
15189code here is adding new commands (@ref{Adding New Commands}.)
15190
15191@example
15192# Some folks like tics to point inwards ...
15193set tics in
15194
15195# Hey, I'm bored with Helvetica font, and
15196# Palatino is a bit prettier than Times
15197set font to PalatinoRoman
15198
15199# Now for something a bit less trivial.
15200# This lets me draw a set of y-values
15201# against a single x-value, by e.g.
15202#    open xyyy.dat
15203#    draw curves time T1 T2 T3
15204# where the first column of the file is
15205# time, and the others are temperatures
15206# at various sensors.
15207`draw curves \xname \y1name ...'
15208Draw multiple y columns versus an x column.  Assumes
15209that the datafile is open, and that x is in the first
15210column, with the y values in one or more following
15211columns.
15212
15213The number of columns is figured out from the options,
15214as is the name of the x-axis, and the labels to be
15215used on each of the y curves.
15216@{
15217  # NB. the 3 below lets us skip the words 'draw'
15218  # and 'curves', and the name of the x-column.
15219  .num_of_y_columns. = @{rpn wordc 3 -@}
15220  if @{rpn .num_of_y_columns. 1 >@}
15221    show "ERROR: `draw curves' needs at least 1 y column!"
15222    quit
15223  end if
15224
15225  set x name @{rpn 2 wordv@}
15226  set y name ""
15227
15228  # Loop through the columns.
15229  .col. = 0
15230  while @{rpn .num_of_y_columns. .col. <@}
15231    # The x-values will be in column 1, with y-values
15232    # in columns 2, 3, ..., of the file.
15233    .ycol. = @{rpn .col. 2 +@}
15234    rewind
15235    read columns x=1 y=.ycol.
15236    # At this point, you may want to change line thickness,
15237    # thickness, color, dash-type, etc.  For illustration,
15238    # let's set dash type to the column number.
15239    set dash .col.
15240    draw curve
15241    draw label for last curve @{rpn .col. 3 + wordv@}
15242    .col. += 1
15243  end while
15244@}
15245@end example
15246
15247
15248
15249
15250
15251@c HTML <!-- newfile Environment.html "Gri: extra programs that work with Gri" "Gri Extras" -->
15252
15253@node   Environment, Extras, Resource File, Top
15254@comment  node-name,  next,  previous,  up
15255@chapter Environment
15256
15257Gri comes with a few ancillary programs that may be useful.  Gri also
15258provides a simple scheme to use other system tools (e.g. @code{awk}).
15259These are discussed here.  And speaking of discussing, this chapter ends
15260with a note about a mail-list Gri discussion group.
15261
15262@menu
15263* Extras::                      Extra things provided with Gri
15264* Using System Tools::          Using Gri with other tools
15265* Discussion Group::            Gri email list
15266@end menu
15267
15268@c HTML <!-- newfile Extras.html "Gri: Extras" "Gri Environment" -->
15269
15270@node   Extras, gri_merge, Environment, Environment
15271@comment  node-name,  next,  previous,  up
15272@section Extra things provided with Gri
15273
15274@menu
15275* gri_merge::                   Merge files to one page
15276* gri_unpage::                  Separate multipage doc into separate files
15277@end menu
15278
15279@node   gri_merge, gri_unpage, Extras, Extras
15280@comment  node-name,  next,  previous,  up
15281@subsection @code{gri_merge} -- combine PostScript files
15282@cindex gri_merge
15283Merge separate PostScript files, created by Gri, into one page.  To
15284learn how it works, type @code{gri_merge -h} at the system prompt, to
15285see:
15286
15287@example
15288PURPOSE: Strings Gri PostScript files together.
15289
15290BUGS:    With old versions, of gri, make sure to match each `set clip
15291 postscript on' with a `set clip postscript off'.
15292
15293USAGE (style 1):
15294    gri_merge [OPTIONS] CxR a.ps b.ps ... > merged_file.ps
15295 Merges the files onto one page, in 'C' columns and 'R' rows.  The C*R
15296 files are given in the order of words on a page.  The page is
15297 presumed to be 8.5x11 in size, as are all the input files, and the
15298 input files are sized to fit, and kept in natural scale.
15299
15300USAGE (style 2):
15301    gri_merge [OPTIONS] xcm ycm enlarge a.ps [b.ps ...] > merged_file.ps
15302 Where `enlarge' is a scale factor applied after offsetting `xcm' to
15303 the right and `ycm' upward.
15304
15305EXAMPLE (style 2):
15306 The following
15307   gri_merge  2 12 .5 a.ps \
15308            12 12 .5 b.ps \
15309             2  2 .5 c.ps \
15310            12  2 .5 d.ps > all.ps
15311 produces 4 panels from gri plots done using margins and sizes
15312 as specified in the following lines in a gri commandfile
15313   set x margin 2
15314   set x size 15
15315   set y margin 2
15316   set y size 15
15317 The OPTIONS, available if your 'perl' has 'getopts' library, are:
15318   -u graylevel -- set graylevel for underlay beneath panels, by default 0.75.
15319                   Values range from 0 (black) to 1 (white), although a value
15320                   of precisely 1 means do NOT draw underlay.
15321   -b graylevel -- Set value for background under individual panels, again 0
15322                   for black to 1 for white, with 1 meaning no drawing.
15323   -h           -- Print this help message and quit.
15324@end example
15325
15326
15327@node   gri_unpage, Using System Tools, gri_merge, Extras
15328@comment  node-name,  next,  previous,  up
15329@subsection @code{gri_unpage} -- split pages into files
15330@cindex gri_unpage
15331Given a multipage PostScript file, @code{gri_unpage} creates several new
15332PostScript files, one for each page.  To learn how it works, type
15333@code{gri_unpage -h} at the system prompt, to see:
15334
15335@example
15336PURPOSE: Chop multipage Gri PostScript file into one file per page.
15337USAGE:   gri_unpage name.ps -- create files name-1.ps, name-2.ps, etc, one
15338                               for each page of name.ps.
15339         gri_unpage -h      -- print this help message
15340
15341BUGS:    1. Bounding box is always 8.5x11 inches.
15342         2. Assumes that all Gri fonts are used even if they aren't.
15343@end example
15344
15345
15346@c HTML <!-- newfile SystemTools.html "Gri: Using System Tools With Gri" "Gri Environment" -->
15347
15348@node   Using System Tools, Why Use The Environment, gri_unpage, Environment
15349@comment  node-name,  next,  previous,  up
15350@section Using System Tools With Gri
15351
15352Using system tools to manipulate your data makes sense for several
15353reasons.  First, you may be familiar with those tools already.  Second,
15354learning these tools will help you in all your work.
15355
15356@menu
15357* Why Use The Environment::     Introduction
15358* Grep::                        Search files for patterns
15359* Sed::                         Serial editor
15360* Awk::                         Search and manipulate data
15361* Perl::                        Search and manipulate data
15362@end menu
15363
15364@node   Why Use The Environment, Grep, Using System Tools, Using System Tools
15365@comment  node-name,  next,  previous,  up
15366@subsection Introduction
15367
15368Each of the programs listed in the sections below is available for Unix.
15369Some (e.g. Perl and the Awk variant called Gawk) are available on other
15370operating systems as well.  Each of these tools is fully documented in
15371Unix manpages, so here I'll just give an indication of a couple of
15372useful techniques you might want to use.
15373
15374Bear in mind that these tools can do very similar jobs.  For example,
15375Awk can do much of what Sed and Grep can do, but also a whole lot more.
15376If you don't know Sed or Grep, I suggest you learn Awk instead.  Then
15377again, Perl can also do anything Gawk can do, and a whole lot more!
15378(For one thing, it is easier to work with multiple files in Perl.)  In
15379fact, Perl is the most powerful of this list.  If you know none of these
15380tools, you might want to learn Perl instead of the others.  But Perl is
15381more complicated for simple work than Awk is, so the most reasonable
15382path might be to learn both Awk and Perl.
15383
15384For simple applications, you will probably want to use these tools in a
15385piped open command, e.g.
15386
15387@example
15388open "awk '@{print $1, $3/$2@}' MyFile |"
15389@end example
15390
15391@noindent
15392which creates a temporary file (automatically erased when Gri finishes)
15393which contains the output from running the system command that preceeds
15394the pipe symbol (@code{|}) (@ref{Open}).
15395
15396(Here and in all the examples of this chapter, it is assumed that the
15397user's input file is named @file{MyFile}.)
15398
15399For more complicated appplications, you may use the Gri @code{system}
15400command as follows.
15401
15402@example
15403system perl   >tmp  <<"EOF"
15404open(IN, "MyFile");
15405while(<IN>) @{
15406    ($x, $y) = split;
15407    print "$x", " ", cos($y), "\n";
15408@}
15409EOF
15410open tmp
15411read columns x y
15412draw curve
15413system rm -f tmp
15414@end example
15415
15416@noindent
15417Here a temporary file, named @file{tmp}, has been used to store the
15418results of the calculation.  Note that this file was specifically
15419cleaned up by the second @code{system} command.  (Many folks, including
15420the author, would prefer to take the perl script out of the above and
15421make it a standalone executable script, calling it from Gri with the
15422one-line form.  But it is just a matter of style.)
15423
15424
15425
15426@node   Grep, Sed, Why Use The Environment, Using System Tools
15427@comment  node-name,  next,  previous,  up
15428@subsection Grep
15429
15430@cindex grep system tool
15431@cindex overview of grep system tool
15432
15433The most common application of Grep is to select lines matching a
15434pattern, or not matching a pattern.  Here is how to skip all lines with
15435the word "HEADER" in them:
15436
15437@example
15438open "grep -v 'HEADER' MyFile |"
15439...
15440@end example
15441
15442@noindent
15443Note that Gawk and Perl do this just as easily.
15444
15445
15446@node Sed, Awk, Grep, Using System Tools
15447@comment  node-name,  next,  previous,  up
15448@subsection Sed
15449
15450@cindex sed system tool
15451@cindex overview of sed system tool
15452
15453Sed is normally used for simple changes to files.  For example, if you
15454have columnar data which are separated with comma characters instead of
15455whitespace, you could make it Gri compatible by
15456
15457@example
15458open "sed -e 's/,/ /g' MyFile |"
15459@end example
15460
15461@noindent
15462Where the @code{-e} flag indicates that the next item is a command to
15463Sed, in this case a command to switch ("s") the comma character with the
15464blank character, globally ("g") across each line of the file.  See also
15465the overview of Perl.
15466
15467@node Awk, Perl, Sed, Using System Tools
15468@comment  node-name,  next,  previous,  up
15469@subsection Awk
15470
15471@cindex awk system tool
15472@cindex gawk system tool
15473@cindex overview of awk system tool
15474
15475Awk is great for one-liners.  If your system lacks Awk, you can procure
15476the GNU version, called Gawk, from the web for free.  For better or
15477worse, Gawk is not fully compatible with Awk.  The good thing is that
15478Gawk is pretty much the same on all operating systems, whereas the
15479installed Awk may not be.  I use Gawk instead of Awk, for this reason
15480and because it is normally faster.
15481
15482The main concept in Awk is of "patterns" and "actions."  In the Awk
15483syntax, actions are written in braces following patterns written with no
15484braces.  (This will become clear presently.)
15485
15486Whenever a line in the data file matches the pattern, the action is
15487done.
15488
15489The default pattern is to match to every line in the file.  This is done
15490if no pattern is supplied.
15491
15492The default action is to print the line, and this is done if no action
15493is supplied.
15494
15495Here are a few examples.  To skip first 10 lines of a file:
15496
15497@example
15498open "awk 'NR>10' MyFile |"
15499read ...
15500@end example
15501
15502@noindent
15503Here the pattern was that @code{NR} (a special Awk variable for the
15504number of the record, starting with 1 for the first line of the file)
15505exceeded 10.  And the action was taken by default since nothing was
15506supplied between braces, to print this line.
15507
15508@noindent
15509To plot the cosine of the second column against the first column:
15510
15511@example
15512open "awk '@{print ($1, cos($2))@}' MyFile |"
15513read columns x y
15514draw curve
15515@end example
15516
15517@noindent
15518Here no pattern was supplied, so the action was done for every line.
15519
15520Combining these two forms, then, and supplying both a pattern and an
15521action, here is how one might print the first and eighth columns of the
15522file @file{MyFile}, but only for the first 10 lines of the file:
15523
15524@example
15525open "awk NR<=10 @{print ($1, $8)@} MyFile |"
15526@end example
15527
15528
15529
15530
15531@node  Perl, Discussion Group, Awk, Using System Tools
15532@comment  node-name,  next,  previous,  up
15533@subsection Perl
15534
15535@cindex perl system tool
15536@cindex overview of perl system tool
15537
15538Perl can do almost @strong{anything} with your data, since it is a full
15539programming language designed to also emulate several Unix utilities.
15540
15541In perl, as in other commands, the commandline switch @code{-e}
15542indicates that a Perl command is given in the next word of the command
15543line.  The commandline switch @code{-p} indicates to print the line,
15544after any indicated Perl actions have been done on it.  Here, for
15545example, is how one would emulate a Sed replacement of comma by blank:
15546
15547@example
15548open "perl -pe 's/,/ /g' MyFile |"
15549@end example
15550
15551Perl also has a commandline switch @code{-a} indicating that lines
15552should be "autosplit" into an array called @code{$F}.  The first element
15553of this array is @code{$F[0]}.  Splitting is normally done on
15554white-space character(s), although this may be changed if desired.
15555Here, for example, is how to take the cosine of the second column of a
15556file, and print this after the first column:
15557
15558@example
15559open "perl -pea 'print($F[0], cos($F[1]))' MyFile |"
15560@end example
15561
15562
15563@c HTML <!-- newfile DiscussionGroup.html "Gri: Discussion Group" "Gri Discussion Group" -->
15564
15565@node   Discussion Group, Emacs Mode, Perl, Environment
15566@comment  node-name,  next,  previous,  up
15567@cindex discussion Group
15568@cindex email list
15569@section Gri Discussion Group
15570Before emailing to the Gri newsgroup, it is a good idea to consult the
15571@c HTML <A HREF="./FAQ.html">
15572@c HTML FAQ
15573@c HTML </A>
15574list of answers to Frequently Asked Questions.
15575
15576
15577As of summer 2000, Gri traffic has been moved to the web-based
15578discussion groups at the SourceForge website
15579@url{http://gri.sourceforge.net}
15580about which little need be said here, because the website is very
15581easy to use.
15582
15583@c HTML <!-- newfile Emacs.html "Gri: Emacs editing mode" "Emacs editing mode" -->
15584
15585@node   Emacs Mode, About Gri Mode, Discussion Group, Top
15586@comment  node-name,  next,  previous,  up
15587@chapter Editing Gri Files in GNU Emacs
15588
15589@cindex gri code, editing
15590@cindex editing Gri code with Emacs
15591@cindex emacs, editing mode for Gri
15592@cindex gri-mode, editing in emacs
15593
15594If you use the GNU Emacs (or XEmacs) text editor, writing Gri command
15595files is made easier with the Gri editing mode (gri-mode.el),
15596written by Peter S. Galbraith
15597@c HTML <A HREF="mailto:Peter S Galbraith <psg@debian.org>">
15598@code{<psg@@debian.org>}.
15599@c HTML </A>
15600
15601@menu
15602* About Gri Mode::
15603* Gri-mode screenshots::                  What it looks like.
15604* Installing gri-mode.el::                The nuts and bolts.
15605* Major Gri-mode commands::               It knows about Gri commands.
15606* Other features::                        IMenu, Toolbar, etc.
15607* Dealing with many Gri versions::        gri-mode handles it.
15608* Filename arguments when running gri::   gri-set-command-postarguments.
15609@end menu
15610
15611@c HTML <!-- newfile AboutGriMode.html "Gri Mode: About Gri Mode" "Gri Mode:About Gri Mode" -->
15612
15613@node   About Gri Mode, Gri-mode screenshots, Emacs Mode, Emacs Mode
15614@comment  node-name,  next,  previous,  up
15615@section About Gri Mode
15616
15617Gri mode has all the wonderful things you've come to expect from Emacs modes.
15618Here's a brief overview of the features:
15619@itemize @bullet
15620@item
15621It can @strong{complete} partially typed commands, builtin variables
15622and synonyms (@code{gri-complete}, @key{M-Tab}) and help you edit the
15623syntax that was thus inserted for you (@code{gri-option-select},
15624@kbd{C-c C-o}; @code{gri-option-kill}, @kbd{C-c C-k}).
15625@item
15626It can provide a short help synopsis concerning the command on the
15627current line (@code{gri-help-this-command}, @kbd{C-c C-h}), or load the
15628info manual for that command (@code{gri-info-this-command}, @kbd{C-c
15629C-i}).  It knows the list of all Gri commands, and can provide help or
15630info regarding any of them (@code{gri-help}, @kbd{C-c M-h};
15631@code{gri-info}, @kbd{C-c M-i}) using command name completion at the
15632prompt (@key{Tab}).
15633@item
15634All Gri commands are listed in a pull-down menu from the menubar, which
15635you can use to either enter the text of the selected command, or obtain
15636help or info about it.
15637@item
15638It can help you find an unknown command by listing all
15639containing a given word (@code{gri-apropos}, @kbd{C-c C-a}).
15640@item
15641It fontifies your Gri code using colour coding.
15642@item
15643It indents if statements, loops, and so on (@code{gri-indent-line}, @key{Tab}).
15644@item
15645It can let you run Gri and view its output without leaving the editor
15646(@code{gri-run}, @kbd{C-c C-r}).  If an error is encountered, Emacs will
15647rearrange the buffer so the cursor is on the bad line of the Gri command-file.
15648@item
15649If you've already run Gri, and therefore have a PostScript output file,
15650the mode will let you view that file (@code{gri-view}, @kbd{C-c C-v})
15651even if that file is compressed.
15652@end itemize
15653
15654@noindent
15655Thus one never has to leave Emacs; type @kbd{C-c C-r} to run Gri, and if
15656there is no error, the graph comes up automatically.  If there was an error,
15657gri-mode will move editing point to the line with the error and display
15658the error message. Given that the mode can complete partially typed commands,
15659this means a substantial saving in development time.
15660
15661Inside gri-mode, type @kbd{C-h m} for help on the mode, including a list
15662of all commands and key definitions.
15663
15664
15665@c HTML <!-- newfile GriModeScreenshots.html "Gri Mode: Screenshots" "Gri Mode: Screenshots" -->
15666
15667@node   Gri-mode screenshots, Screenshot 1, About Gri Mode, Emacs Mode
15668@comment  node-name,  next,  previous,  up
15669@section Gri-mode screenshots, what it looks like.
15670@cindex gri-mode, screenshots
15671
15672@cindex screen snapshots, using Gri
15673@cindex snapshots of computer screen, using Gri
15674
15675@comment Now handle PostScript version
15676@iftex
15677In the first screenshot, the user has entered the text
15678@code{set font} and has pressed @key{M-Tab} twice
15679to see the list of possible completions.  The
15680@file{*Completions*} buffer is displayed in a separate
15681frame because the user is using the @file{framepop.el}
15682add-on package.  A similar effect can be obtained using
15683@code{special display} buffers in Emacs.
15684
15685@image{./screenshots/gri-screenshot-1, 400pt}
15686
15687Here, the user has selected the command @code{set font to} and,
15688forgetting what valid font name could be used, then invoked @kbd{C-c
15689C-h} to get help about that command. The user found the needed
15690information and finished typing in `Helvetica'.
15691
15692@image{./screenshots/gri-screenshot-2, 400pt}
15693
15694Here we see the user cascading through the Gri commands pull-down menu
15695until @code{draw axes} is reached.
15696
15697@image{./screenshots/gri-screenshot-3, 400pt}
15698
15699With the output previewed in a @code{gv} window after pressing @kbd{C-c
15700C-v}, the user is ready to print the file using a pull-down menu.
15701
15702@image{./screenshots/gri-screenshot-4, 400pt}
15703@end iftex
15704
15705@comment Now handle more complicated HTML version
15706@c @ifhtml
15707
15708@comment First the index images pointing to new HTML files.
15709@c HTML <p>
15710@c HTML <A HREF="ScreenShot1.html">
15711@c HTML <IMG ALT="Possible completions to `set font'."
15712@c HTML SRC="./screenshots/gri-screenshot-1-tiny.png" ALIGN=left></A>
15713@c HTML gri-mode displays possible completions to entered text.
15714@c HTML <br clear=left>
15715@c HTML <p>
15716@c HTML <A HREF="ScreenShot2.html">
15717@c HTML <IMG ALT="Displaying Help about current command."
15718@c HTML SRC="./screenshots/gri-screenshot-2-tiny.png" ALIGN=left></A>
15719@c HTML gri-mode displays help about the current command.
15720@c HTML <br clear=left>
15721@c HTML <p>
15722@c HTML <A HREF="ScreenShot3.html">
15723@c HTML <IMG ALT="Cascading the command pull-down menu."
15724@c HTML SRC="./screenshots/gri-screenshot-3-tiny.png" ALIGN=left></A>
15725@c HTML The pull-down menu listing all gri commands.
15726@c HTML <br clear=left>
15727@c HTML <p>
15728@c HTML <A HREF="ScreenShot4.html">
15729@c HTML <IMG ALT="Getting set to print the PostScript output."
15730@c HTML SRC="./screenshots/gri-screenshot-4-tiny.png" ALIGN=left></A>
15731@c HTML The `Perform' menu to run gri, preview, print...
15732@c HTML <br clear=left>
15733@c HTML <p>
15734
15735@comment Next, generate these new HTML files (sneaky).
15736
15737@menu
15738* Screenshot 1::
15739* Screenshot 2::
15740* Screenshot 3::
15741* Screenshot 4::
15742@end menu
15743
15744
15745@c HTML <!-- newfile ScreenShot1.html "Gri: Screenshot 1" "Screenshot 1" -->
15746@node   Screenshot 1, Screenshot 2, Gri-mode screenshots, Gri-mode screenshots
15747@comment  node-name,  next,  previous,  up
15748@subsection Screenshot 1
15749
15750@c HTML <!--
15751@ifinfo
15752Screenshots are not visible in the info node; see the online
15753HTML documents.
15754@end ifinfo
15755@c HTML -->
15756
15757In the first screenshot, the user has entered the text @code{set font}
15758and has pressed @key{M-Tab} twice to see the list of possible
15759completions.  The @file{*Completions*} buffer is displayed in a
15760separate frame because the user is using the @file{framepop.el} add-on
15761package.  A similar effect can be obtained using @code{special
15762buffers} in Emacs.
15763
15764@c HTML <IMG SRC="./screenshots/gri-screenshot-1.png"></A>
15765
15766@c HTML <!-- newfile ScreenShot2.html "Gri: Screenshot 2" "Screenshot 2" -->
15767@node   Screenshot 2, Screenshot 3, Screenshot 1, Gri-mode screenshots
15768@comment  node-name,  next,  previous,  up
15769@subsection Screenshot 2
15770
15771@c HTML <!--
15772@ifinfo
15773Screenshots are not visible in the info node; see the online
15774HTML documents.
15775@end ifinfo
15776@c HTML -->
15777
15778Here, the user has selected the command @code{set font to} and,
15779forgetting what valid font name could be used, then invoked @kbd{C-c
15780C-h} to get help about that command. The user found the needed
15781information and finished typing in `Courier'.
15782Meanwhile, an idle timer displays the default setting for this command in
15783the minibuffer after a few seconds of inactivity.
15784
15785@c HTML <IMG SRC="./screenshots/gri-screenshot-2.png"></A>
15786
15787@c HTML <!-- newfile ScreenShot3.html "Gri: Screenshot 3" "Screenshot 3" -->
15788@node   Screenshot 3, Screenshot 4, Screenshot 2, Gri-mode screenshots
15789@comment  node-name,  next,  previous,  up
15790@subsection Screenshot 3
15791
15792@c HTML <!--
15793@ifinfo
15794Screenshots are not visible in the info node; see the online
15795HTML documents.
15796@end ifinfo
15797@c HTML -->
15798
15799Here we see the user cascading through the Gri commands pull-down menu
15800until @code{draw axes} is reached.  This menu can be used to display Info
15801(or help) about a given command, or to insert the selection.  The default
15802is Info.  This menu is a good way to browse for a command when you don't
15803exactly remember its name.
15804
15805@c HTML <IMG SRC="./screenshots/gri-screenshot-3.png"></A>
15806
15807@c HTML <!-- newfile ScreenShot4.html "Gri: Screenshot 4" "Screenshot 4" -->
15808@node   Screenshot 4, Installing gri-mode.el, Screenshot 3, Gri-mode screenshots
15809@comment  node-name,  next,  previous,  up
15810@subsection Screenshot 4
15811
15812@c HTML <!--
15813@ifinfo
15814Screenshots are not visible in the info node; see the online
15815HTML documents.
15816@end ifinfo
15817@c HTML -->
15818
15819With the output previewed in a @code{gv} window after pressing @kbd{C-c
15820C-v} (or pressing the @code{gv} icon in the toolbar, or selecting it from
15821the @code{Perform} pull-down menu), the user is ready to print the file,
15822here using the @code{Perform} pull-down menu.
15823
15824@c HTML <IMG SRC="./screenshots/gri-screenshot-4.png"></A>
15825@c @end ifhtml
15826
15827@c HTML <!-- newfile InstallingGriMode.html "Gri Mode: Installation" "Gri Mode: Installation" -->
15828@node   Installing gri-mode.el, Step 1, Screenshot 4, Emacs Mode
15829@comment  node-name,  next,  previous,  up
15830@section Installing gri-mode.el, the nuts and bolts.
15831@cindex gri-mode, installing
15832
15833The Emacs @file{gri-mode.el} file is now bundled with gri, so odds are
15834you already have it.  If not, you will find it at gri's web site
15835@c HTML <A HREF="http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/gri/gri/gri-mode.el">
15836http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/gri/gri/gri-mode.el
15837@c HTML </A>
15838
15839The following installation steps appear a @strong{bit} complicated.
15840That's only because gri has changed how it gets installed a few times,
15841and gri-mode.el works with all of these various methods.  If you use gri
15842from a Linux package (Debian or Red Hat) or if you compiled it yourself using
15843the default configuration, you won't need to do much.
15844
15845To install @file{gri-mode.el}, follow these 4 steps.  If gri-mode is
15846already installed, you can skip the first two steps and move on to the
15847last two, in which you tell Emacs that you'd like to use Gri mode when
15848you edit files that end in @file{.gri}, the Gri suffix.  (Actually, if
15849you're using Debian linux, you can skip all of these steps since the
15850system will assume that you want gri-mode if you're editing a Gri file.)
15851
15852@menu
15853* Step 1::  Placing gri-mode.el where Emacs can find it.
15854* Step 2::  Configuring gri-mode to where gri lives on your system.
15855* Step 3::  Telling emacs to load gri-mode
15856* Step 4::  Extra user configuration of gri-mode.
15857@end menu
15858
15859@node   Step 1, Step 2, Installing gri-mode.el, Installing gri-mode.el
15860@comment  node-name,  next,  previous,  up
15861@subsection Placing gri-mode.el where Emacs can find it.
15862@cindex gri-mode, Placing gri-mode.el where Emacs can find it.
15863
15864(Those using gri from gri's @strong{RPM} package, a @strong{Debian} package
15865or a @strong{Red Hat} package users can skip this, as it is done
15866for them)
15867
15868Extra @file{.el} files like @file{gri-mode.el} that are not part of Emacs
15869should be stored in a directory where Emacs will find them when you ask
15870it to load them.  The files should therefore be found in Emacs'
15871@strong{load-path}.  To see the directory list currently in the load-path,
15872do this in Emacs:
15873
15874@example
15875C-h v load-path
15876@end example
15877
15878If you have access to system directories, put gri-mode.el in a
15879@strong{site-lisp} directory, such as
15880@file{/usr/local/share/emacs/site-lisp/} That way all users will have
15881access to the files.
15882
15883If you don't have access to a site-lisp directory (e.g. you have only a
15884user account), then create a directory where your extra @file{.el} files
15885will be stored and add it to Emacs' load-path.  For example, say you
15886created the directory @file{~/emacs} and stored gri-mode.el there, you would
15887then put this near the top of your @file{~/.emacs} file:
15888
15889@example
15890(setq load-path (cons "~/emacs" load-path))
15891@end example
15892
15893@node   Step 2, Step 3, Step 1, Installing gri-mode.el
15894@comment  node-name,  next,  previous,  up
15895@subsection Telling gri-mode where gri resides
15896@cindex gri-mode, Configuring gri-mode to where gri lives on your system
15897
15898(Those using gri from gri's @strong{RPM} package, a @strong{Debian} package
15899or a @strong{Red Hat} package users can skip this, as it is done
15900for them)
15901
15902You may skip this section if gri is installed on your system as
15903@file{/usr/local/bin/gri-@value{GRI-VERSION}} and
15904@file{/usr/local/share/gri/@value{GRI-VERSION}/gri.cmd} (the default
15905when compiling gri yourself).  If not, then you may need to set the Emacs
15906variable @code{gri*directory-tree} in a startup file such as in your
15907@file{~/.emacs} file.
15908
15909The Emacs variable @code{gri*directory-tree} is used to configure
15910gri-mode to tell it where Gri is installed on your system. For the
15911default gri installation paths used in this gri release, gri-mode
15912expects to find the gri executable and the file gri.cmd as:
15913@code{gri*directory-tree/@value{GRI-VERSION}/gri.cmd}
15914and @code{/usr/local/bin/gri-}@value{GRI-VERSION}
15915where @code{gri*directory-tree} is by default set to
15916@file{/usr/local/share/gri/}.
15917
15918If you have only one version of gri installed on your system, gri-mode
15919will also look to find @file{gri.cmd} and the gri executable like so:
15920@enumerate
15921@item
15922Gri executable in the PATH, with startup file
15923@file{gri*directory-tree/gri.cmd}.
15924@item
15925Gri executable in the PATH, with startup file
15926@file{gri*directory-tree/lib/gri.cmd}.
15927@item
15928Gri executable @code{gri*directory-tree/bin/gri}, with startup file
15929@code{gri*directory-tree/lib/gri.cmd}.
15930@end enumerate
15931
15932However, gri-mode was designed to support, and ease the use of,
15933@strong{multiple installed versions} of gri.  To use this feature, you
15934must use the gri version number as a directory name under the
15935@code{gri*directory-tree} path, like this:
15936
15937@example
15938gri*directory-tree/VERSION/bin/gri
15939gri*directory-tree/VERSION/lib/gri.cmd
15940@end example
15941
15942(e.g. @file{/opt/gri/2.040/bin/gri} and
15943@file{/opt/gri/2.040/lib/gri.cmd} with @code{gri*directory-tree} set to
15944@code{"/opt/gri"})
15945
15946or without the @strong{lib} and @strong{bin} subdirectories if the executable is
15947found in the PATH named like @file{gri-VERSION} (This is the way Debian
15948packages are set up):
15949the file @file{gri*directory-tree/VERSION/gri.cmd}
15950and the @file{gri-VERSION} executable in the PATH
15951(e.g. @file{/usr/share/gri/2.1.18/gri.cmd} and
15952@file{/usr/bin/gri-2.1.18} with @code{gri*directory-tree} set to
15953@code{"/usr/share/gri"})
15954
15955@strong{Important note:} You may have more than one tree and make a list
15956of them:
15957
15958@example
15959(setq gri*directory-tree '("/opt/gri/" "/usr/share/gri/"))
15960@end example
15961
15962@strong{Examples:}
15963
15964@enumerate
15965@item
15966 If you use a RedHat package
15967 installed like:
15968
15969@example
15970/usr/bin/gri
15971/usr/share/gri/gri.cmd
15972@end example
15973
15974@noindent
15975then you'd also use:
15976
15977@example
15978(setq gri*directory-tree "/usr/share/gri/")
15979@end example
15980
15981 but gri-mode would know of only one installed version of gri.
15982
15983@item
15984 If you use a Debian GNU/Linux installation like:
15985
15986@example
15987/usr/bin/gri -> /usr/bin/gri-2.1.18
15988/usr/share/gri/2.1.18/gri.cmd
15989@end example
15990
15991@noindent
15992then you'd use:
15993
15994@example
15995(setq gri*directory-tree "/usr/share/gri/")
15996@end example
15997
15998 Note that all gri binaries must exist in the path with version number
15999 suffixes (e.g. @file{gri-2.1.18}) since there is no
16000 @file{/usr/share/gri/2.1.18/bin/} directory (using a similar structure
16001 to @file{opt/gri} below) where gri-mode can find the binary
16002 corresponding to a given version number.
16003
16004@item
16005 If you had multiple versions of Gri installed like so (this reflects
16006 the installation paths used in older gri releases):
16007
16008@example
16009/opt/gri/2.040/bin/gri
16010/opt/gri/2.040/lib/gri.cmd
16011/opt/gri/2.041/bin/gri
16012/opt/gri/2.041/lib/gri.cmd
16013@end example
16014
16015then you'd use:
16016
16017@example
16018(setq gri*directory-tree "/opt/gri/")
16019@end example
16020
16021@end enumerate
16022
16023@node   Step 3, Step 4, Step 2, Installing gri-mode.el
16024@comment  node-name,  next,  previous,  up
16025@subsection Telling emacs to load gri-mode
16026@cindex gri-mode, Telling emacs to load gri-mode
16027
16028(Those using a @strong{Debian} package can skip this, as it is done
16029for them)
16030
16031To tell emacs to use this mode with @file{.gri} files, you can load
16032gri-mode whenever a new emacs session is starting by adding the
16033following line to your @file{~/.emacs} file:
16034
16035@example
16036(require 'gri-mode)
16037@end example
16038
16039This is a good method when you only start emacs once a week and
16040use it for every file you edit (as you should).
16041
16042If you startup a fresh emacs every time you edit then you probably only
16043want to load gri-mode into emacs when you need it.  In that case,
16044instead of the @code{require} statement above, add the following lines
16045to your @file{~/.emacs} file:
16046
16047@example
16048(autoload 'gri-mode "gri-mode" "Enter Gri-mode." t)
16049(setq auto-mode-alist (cons '("\\.gri$" . gri-mode) auto-mode-alist))
16050@end example
16051
16052The first line tells Emacs that it will find out what it needs to know
16053about running the command @code{M-x gri-mode} by loading the file
16054@file{gri-mode.el}.  The second line tells it to run the command
16055@code{M-x gri-mode} when a file with extension @file{.gri} is visited
16056(thus using gri-mode with all those files).
16057
16058@node   Step 4, Major Gri-mode commands, Step 3, Installing gri-mode.el
16059@comment  node-name,  next,  previous,  up
16060@subsection Extra user configuration of gri-mode
16061@cindex gri-mode, Extra user configuration of gri-mode
16062
16063@strong{All users should do this at some time.}
16064
16065At this point, gri-mode should start up when you edit a gri file.  You
16066may optionally customize gri-mode by:
16067
16068@enumerate
16069
16070@item
16071 using the Custom interface (see the Help or Gri-Help menu or run the
16072 command @code{M-x gri-customize}), or
16073
16074@item
16075 manually setting variables in your @file{~/.emacs} file.  These are
16076 briefly described by typing @kbd{C-h m} while in gri-mode.  Then, for
16077 further infomation, use emacs' @code{describe-variable} command, bound
16078 to @kbd{C-h v}.  For example, for more information about the
16079 @code{gri*WWW-program} variable, you'd type @code{C-h v gri*WWW-program}
16080 (note that emacs does @key{Tab} completion, so pressing the
16081 @key{Tab} key after typing-in gri will display all gri related
16082 variables.)
16083@end enumerate
16084
16085@c HTML <!-- newfile MajorGriModeCommands.html "Gri Mode: Major Commands" "Gri Mode: Major Commands" -->
16086@node   Major Gri-mode commands, Gri command names, Step 4, Emacs Mode
16087@comment  node-name,  next,  previous,  up
16088@section Major Gri-mode commands.
16089@cindex gri-mode, major commands
16090
16091This section describes the major gri-mode commands, briefly showing how
16092they can increase your productivity.
16093
16094
16095@menu
16096* Gri command names::     How gri-mode names all gri commands.
16097* Possible completions::  A list of all valid commands matching so far.
16098* Command abbreviations:: Abbreviating many words at one time.
16099* Variable completion::   Completion of builtin variable and synonyms.
16100* Editing the syntax::    What to do after gri-complete.
16101* User commands::         gri-mode knows about ~/.grirc.
16102* Gri code fragments::    Use them as short-cuts.
16103* Info interface::        Getting help about the current command.
16104@end menu
16105
16106@c HTML <!-- newfile GriModeCommandNames.html "Gri Mode: command names" "Gri Mode: command names" -->
16107@node   Gri command names, Possible completions, Major Gri-mode commands, Major Gri-mode commands
16108@comment  node-name,  next,  previous,  up
16109@subsection How gri-mode names Gri commands
16110@cindex gri-mode, gri command names
16111@cindex gri-mode, how it names gri commands
16112
16113A major feature of Gri mode is the completion of partially typed
16114commands.  Let's examine how
16115gri-mode decides to name gri commands.  A name is determined by removing
16116bracketed options from the syntax line of a given command.  This is
16117different from what the gri parser does.  In this way, the gri command
16118
16119@example
16120draw label "\string" [centered|rightjustified] at .x. .y. [cm] [rotated .deg.]
16121@end example
16122
16123@noindent
16124is named by gri-mode simply @code{draw label at}.  Note how the `at'
16125stays in the name because it is not optional.  So when you see
16126@code{draw label at} in gri-mode's menus or prompts, you are more likely
16127to associate the name with what the command actually does.
16128
16129@c HTML <!-- newfile GriModeCompletions.html "Gri Mode: command completion" "Gri Mode: command completion" -->
16130@node   Possible completions, Command abbreviations, Gri command names, Major Gri-mode commands
16131@comment  node-name,  next,  previous,  up
16132@subsection Possible completions of gri command names
16133@cindex gri-mode, possible completions
16134
16135When you press @key{M-tab} to complete a command name (or a variable
16136or synonym name as described below), gri-mode will
16137expand it as much as it can and do nothing further.  If you type in
16138nothing more and insist by using @code{gri-complete} (@key{M-tab})
16139again, gri-mode will respond by showing all possible completions in the
16140@file{*completions*} buffer.  In this way you can use
16141@code{gri-complete} word-by-word to abbreviate commands without ever
16142displaying completions, like you would for file completion in emacs or
16143bash.
16144
16145If a completion is ambiguous, but could be exact, invoke
16146gri-complete a second time to complete it. e.g.
16147
16148@example
16149sh@key{M-tab}
16150@end example
16151
16152@noindent
16153expands to
16154
16155@example
16156show
16157@end example
16158
16159@noindent
16160and informs you that 12 possible completions exists; then
16161
16162@example
16163show@key{M-tab}
16164@end example
16165
16166@noindent
16167will display these completions in the completions buffer; then typing
16168@key{M-tab} again forces completion to a complete but not unique
16169possibility:
16170
16171@example
16172show .value.|@{rpn ...@}|"\text" [.value.|@{rpn ...@}|text [...]]
16173@end example
16174
16175Completions are shown immediately (without invoking gri-complete again)
16176if the completions window is already displayed or if there are 3
16177possibilities or less.  In this case they are displayed in the
16178minibuffer.
16179
16180Note: The @file{*completions*} window is deleted after a command is fully
16181completed.  @code{gri-complete} uses its own @file{*completions*}
16182buffer, which is not displayed in the buffer-list to avoid clutter.
16183
16184@c HTML <!-- newfile GriModeCompletions2.html "Gri Mode: command completion" "Gri Mode: command completion" -->
16185@node   Command abbreviations, Variable completion, Possible completions, Major Gri-mode commands
16186@comment  node-name,  next,  previous,  up
16187@subsection Command name abbreviation
16188@cindex gri-mode, command name abbreviation
16189
16190gri-mode uses command name abbreviations in a non-Unix way in that all
16191words that compose the command name may be abbreviated (and not only
16192the word preceding the cursor).  For example, one can type in
16193
16194@example
16195dr x a@key{M-tab}
16196@end example
16197
16198@noindent
16199and it will expand1 all the words to
16200
16201@example
16202draw x axis [at bottom|top|@{.y. [cm]@} [lower|upper]]
16203@end example
16204
16205This is reminiscent of VMS, which the author was used to when
16206gri-mode.el was initially created.  It's likely that a gri-mode.el
16207rewritten from scratch wouldn't have this feature since it's not part
16208of the Unix mindset.
16209
16210@c HTML <!-- newfile GriModeCompletionVarSyn.html "Gri Mode: variable completion" "Gri Mode: variable completion" -->
16211@node   Variable completion, Editing the syntax, Command abbreviations, Major Gri-mode commands
16212@comment  node-name,  next,  previous,  up
16213@subsection Variable (and synonym) completion
16214@cindex gri-mode, variable completion
16215@cindex gri-mode, sysnonym completion
16216
16217It's also possible to do @key{M-tab} completion on gri builtin
16218variable and synonym names while editing a command.  Simply type in
16219the leading @code{.} (dot) or @code{\} (slash) character and
16220invoke completion with @key{M-tab}.
16221
16222For example,
16223
16224@example
16225..x@key{M-tab}
16226@end example
16227
16228@noindent
16229displays a completions buffer listing the possible completions:
16230
16231@example
16232..xmargin..                        ..xsize..
16233..xleft..                          ..xright..
16234..xlast..
16235@end example
16236
16237@noindent
16238Typing in an extra @code{m} will complete to @code{..xmargin..} and
16239the following help information will be displayed in the minibuffer:
16240
16241@example
16242margin to left of axis area. Default is 6 cm.
16243@end example
16244
16245@c HTML <!-- newfile GriModeEditing.html "Gri Mode: editing completed syntax" "Gri Mode: editing completed syntax" -->
16246@node   Editing the syntax, User commands, Variable completion, Major Gri-mode commands
16247@comment  node-name,  next,  previous,  up
16248@subsection Editing the syntax output by gri-complete
16249@cindex gri-mode, editing gri syntax
16250
16251You might wonder what to do with all the bracketed code left behind by
16252@code{gri-complete}.  It certainly won't go through the gri parser
16253without error, so you have to edit it out.
16254
16255The tools provided in gri-mode are @code{gri-option-select} (@kbd{C-C
16256C-o}) and @code{gri-kill-option} (@kbd{C-C C-k}) to narrow in on a
16257particular gri command, given a syntax description left on the line by
16258@code{gri-complete}.  The cursor location is used to decide which gri
16259command(s) to narrow to.
16260
16261For example, if @code{gri-complete} is used on the line `dr x a', the
16262result will be a line like
16263
16264@example
16265draw x axis [at bottom|top|@{.y. [cm]@} [lower|upper]]
16266@end example
16267
16268This is the gri way of describing many commands at once.  The above
16269syntax description is a shortcut formulation for all of:
16270
16271@example
16272draw x axis
16273draw x axis at bottom
16274draw x axis at bottom top
16275draw x axis at bottom bottom
16276draw x axis at top
16277draw x axis at top top
16278draw x axis at top bottom
16279draw x axis at .y. cm
16280draw x axis at .y. cm lower
16281draw x axis at .y. cm upper
16282@end example
16283
16284The @code{gri-option-select} (@kbd{C-C C-o}) command provides easy
16285navigation to select one of these commands.  The narrowing process is
16286governed by the cursor position.  For example, to get the command
16287narrowed down to
16288
16289@example
16290draw x axis at bottom [lower|upper]
16291@end example
16292
16293@noindent
16294place the cursor somewhere in the word `bottom' and invoke
16295@code{gri-option-select}.  To complete the narrowing process, selecting
16296
16297@example
16298draw x axis at bottom lower
16299@end example
16300
16301@noindent
16302move the cursor to some place in the word `lower' and invoke
16303@code{gri-option-select again}.  On the other hand, to get
16304
16305@example
16306draw x axis at bottom
16307@end example
16308
16309@noindent
16310you would have put the cursor over either the word `lower' or `upper',
16311and invoke @code{gri-kill-option} (@kbd{C-C C-k}) instead.
16312
16313You might want to practice using this example to learn
16314how to do it.  If you make a mistake, note that the normal Emacs undo
16315works.
16316
16317
16318@c HTML <!-- newfile GriModeUserCommands.html "Gri Mode: user commands" "Gri Mode: user commands" -->
16319@node   User commands, Gri code fragments, Editing the syntax, Major Gri-mode commands
16320@comment  node-name,  next,  previous,  up
16321@subsection User commands with gri-mode
16322@cindex gri-mode, user-defined commands
16323
16324User gri commands defined in @file{~/.grirc} (@ref{Resource File}) or at
16325the beginning of a gri file can also be used with @code{gri-complete}.
16326Note that user commands are added from the current buffer whenever
16327`gri-mode' is invoked.  They may override previous user commands, but
16328not gri system commands.
16329
16330@c HTML <!-- newfile GriModeCodeFragments.html "Gri Mode: code fragments" "Gri Mode: code fragments" -->
16331@node   Gri code fragments, Info interface, User commands, Major Gri-mode commands
16332@comment  node-name,  next,  previous,  up
16333@subsection Inserting gri code fragments in Emacs
16334@cindex gri-mode, gri code fragments
16335@cindex gri-mode, enter chunks of code with short-cuts
16336
16337Since gri version 1.063, gri has special commands that begin with
16338a question mark `?'.  These special commands have no options, and
16339are composed only of standard gri commands.  Their purpose is to
16340provide a short-cut for entering many lines of gri at once (e.g.
16341bits of sample code about contouring grids, or your own preamble
16342which you use at the time to set fonts and line widths).
16343
16344@code{gri-complete} acts in a special way with these commands, by
16345replacing the abbreviated name which you are completing by all the lines
16346contained within the gri command.
16347
16348The user is allowed to define new fragments in @file{~/.grirc}, and also
16349to override the gri system fragments.  You can therefore fine-tune gri's
16350fragments to your taste.  To see the names of all gri fragments, type in
16351a question mark at the beginning of a line in a gri buffer and press
16352@key{M-Tab} twice to @code{gri-complete} it and display possible
16353choices.  The gri commands used to replace them are found in the
16354@file{*gri-syntax*} buffer.
16355
16356@c HTML <!-- newfile GriModeUserInterface.html "Gri Mode: user interface" "Gri Mode: user interface" -->
16357@node   Info interface, Other features, Gri code fragments, Major Gri-mode commands
16358@comment  node-name,  next,  previous,  up
16359@subsection Info interface for help on current command
16360@cindex gri-mode, Info interface
16361
16362The Info system is built into Emacs (@kbd{C-h i}), and provides an easy
16363method of navigation on-line help (including this manual).  We suggest
16364that you install the gri info files on your system (they are already
16365installed with packaged versions of gri in Debian or Red Hat formats).
16366
16367Not only will Info (@kbd{C-h i}) be able to navigate through all of
16368gri's inline manual, but gri-mode's function
16369@code{gri-info-this-command} (@kbd{C-c C-i}) will display the correct
16370info page about the gri command being edited on the current line.
16371
16372Additionally, gri-mode has the command @code{gri-info} (@kbd{C-c M-i})
16373which will prompt you (using @key{tab} completion) for any command to
16374list Info about.  There's also a menu-bar pull-down menu which lists all
16375gri commands, and you can get to Info from that too.
16376
16377@c HTML <!-- newfile EmacsFeatures.html "Gri: Other Features of gri-mode" "Emacs Mode: Other Features of gri-mode" -->
16378@node  Other features, Dealing with many Gri versions, Info interface, Emacs Mode
16379@comment  node-name,  next,  previous,  up
16380@section Other features of gri-mode
16381@cindex gri-mode, imenu support
16382@cindex gri-mode, toolbar
16383
16384@itemize @bullet
16385@item
16386@code{IMenu support}:
16387IMenu is a GNU/Emacs package used to source code files.  It can be
16388setup for a particular mode to list a menu of function definitions and
16389variable declarations.  In gri-mode, the IMenu is available from the
16390menubar and provides links to @code{new command declarations} as well
16391as value settings for @code{variables} and @code{synomyns}.
16392@item
16393@code{Toolbar support}:
16394XEmacs21 and Emacs-21 have support for a toolbar (a set of iconic
16395buttons that are shortcuts for commands), however the two editors
16396don't not have compatible toolbar setups.  Currently gri-mode only
16397defines a single icon for XEmacs (to run gri on the current buffer)
16398and defines three for GNU/Emacs (to run gri, to view the postscript
16399file, and to lookup Info about the command on the current line).
16400@item
16401@code{Idle Help}:
16402When GNU/Emacs sits idle with the cursor on a command line, it looks
16403up any defaults the command may have and displays the information in
16404the minibuffer.  For example, sitting on a line that says @code{set
16405font size 10}, it will display @code{set font size: default is 12 point in variable ..fontsize..}.
16406@end itemize
16407
16408
16409@c HTML <!-- newfile Emacs4.html "Gri: Dealing with many Gri versions" "Emacs Mode: Dealing with many Gri versions" -->
16410@node   Dealing with many Gri versions, Filename arguments when running gri, Other features, Emacs Mode
16411@comment  node-name,  next,  previous,  up
16412@section Dealing with many Gri versions, gri-mode handles it.
16413@cindex gri-mode, handling multiple Gri versions
16414
16415Earlier we explained that you might have many versions of gri installed
16416on your system (@ref{Installing gri-mode.el}).  You may use gri-mode to
16417access these various versions with the following gri-mode commands:
16418
16419@itemize @bullet
16420@item
16421@code{gri-set-version}:
16422Tells gri-mode to use a given version as the default for all your gri
16423files.  Tab completion is available listing all available versions (if
16424they are not all listed, that means that the Emacs variable
16425@code{gri*directory-tree} is not correctly set
16426(@ref{Installing gri-mode.el})).  Your selection is stored in the file
16427@file{~/.gri-using-version} and is remembered across editing
16428sessions. If you select @strong{default} as your answer, gri-mode reverts
16429to using the default version of gri as installed on your system (which
16430may change after you update it) and deletes the
16431@file{~/.gri-using-version} file.
16432
16433@item
16434@code{gri-set-local-version}:
16435Tells gri-mode to use a given version of gri @strong{this} gri file
16436(the one currently being edited when you invoke the command).  Tab
16437completion is again available to list all available versions.  Your
16438selection overrides the default version selected by
16439@code{gri-set-version} for this file, and is stored as an Emacs variable
16440at the bottom of the gri file.  It is remembered across editing
16441sessions. If you select @strong{default} as your answer, gri-mode reverts
16442to using the default version of gri as selected by
16443@code{gri-set-version} and deletes the Emacs variable setting at the
16444bottom of the gri file.
16445@end itemize
16446
16447@c HTML <!-- newfile Emacs5.html "Gri: Filename arguments when running gri" "Emacs Mode: Filename arguments when running gri" -->
16448@node Filename arguments when running gri, History, Dealing with many Gri versions, Emacs Mode
16449@comment  node-name,  next,  previous,  up
16450@section Filename arguments when running gri
16451@cindex gri-mode, handling filename command arguments
16452@cindex gri-mode, handling argv and argc
16453
16454Usually, gri is run specifying only a gri command file to process, which
16455lends itself well to the gri-mode command @code{gri-run}.  But Gri can
16456be also invoked from the command line using optional arguments, usually
16457filenames but not necessarily, e.g.
16458
16459@example
16460$ gri somefile.gri datafile.dat datafile2.dat ...
16461@end example
16462
16463@noindent
16464or
16465
16466@example
16467$ gri somefile.gri *.dat
16468@end example
16469
16470The arguments are accessed with RPN operators @file{argc} and
16471@file{argv} (@ref{Unary Operators}).
16472
16473gri-mode provides a method to set the arguments (usually filenames) to
16474use when @code{gri-run} is called in a specific gri script.  Use the
16475gri-mode command @code{gri-set-command-postarguments} to setup a
16476string that gri-mode will use, and the gri-mode command
16477@code{gri-unset-command-postarguments} to clear it.  For ease-of-use,
16478these commands are made available from the menubar under the
16479@code{Perform -> Run Settings} entries.  The specified string will be
16480stored in the locally-defined (aka buffer-local) variable
16481@code{gri-command-postarguments} and will be written within a gri
16482comment at the bottom of the file such that Emacs remembers it across
16483editing sessions.
16484
16485@c HTML <!-- newfile History.html "Gri: History of Gri" "History of Gri Versions" -->
16486@node   History, Stable Stream, Filename arguments when running gri, Top
16487@comment  node-name,  next,  previous,  up
16488@chapter History of Gri Versions
16489
16490Gri, like many modern software projects, has two ``streams'' of
16491development running side by side.  One is called ``stable,'' the other
16492``unstable.''  @emph{Most users should use the stable stream}, which
16493has been well tested.  (The unstable version is for users who wish to
16494try out new features that are under development.)
16495
16496Stable versions always have an even number as the middle number in
16497their version designation, e.g. @code{2.6.0}, while unstable versions
16498always have an odd number there, e.g. @code{2.7.0}.  This middle
16499number indicates a sort of family of related releases.  Within a
16500stable stream, all versions sharing a given middle number have the
16501same features; new releases are made only to fix bugs.  Thus, version
16502@code{2.6.1} fixed bugs in version @code{2.6.0}.
16503
16504To learn more about the bugs, and their resolution, visit the bugs page at
16505@uref{http://sourceforge.net/tracker/?func=browse&group_id=5511&atid=105511,gri.sourceforge.net}
16506and adjust the "status" menu to read "closed".
16507
16508@menu
16509* Stable Stream::
16510* Unstable Stream::
16511* Deprecated Commands::
16512@end menu
16513
16514
16515@c HTML <!-- newfile StableStream.html "Gri: Stable Stream" "Gri: History" -->
16516@node   Stable Stream, Version 2.12, History, History
16517@comment  node-name,  next,  previous,  up
16518@section Stable Stream
16519
16520In any given stable stream, only the version with a @code{0} as the
16521last number in the triplet has new features; the later versions only
16522correct flaws.  For example, version @code{2.6.0} offers new features
16523compared to any of the @code{2.4.x} versions, but @code{2.6.1} differs
16524only in the fixing of bugs.
16525
16526@menu
16527* Version 2.12::
16528* Version 2.10::
16529* Version 2.8::
16530* Version 2.6::
16531* Version 2.4::
16532* Version 2.2::
16533@end menu
16534
16535@c HTML <!-- newfile Version_2_12.html "Gri: Version 2.12" "Gri: Version 2.12" -->
16536@node   Version 2.12, Version 2.10, Stable Stream, Stable Stream
16537@comment  node-name,  next,  previous,  up
16538@subsection Version 2.12
16539@cindex version 2.12
16540
16541@comment ADD-NEW-BUG-FIXES-HERE
16542
16543@subsubsection Version 2.12.23 [2011 July 6 @uref{http://en.wikipedia.org/wiki/Malawi, Malawai Independence Day}]
16544@strong{Bug fixes}
16545@itemize @bullet
16546@item
16547@uref{https://sourceforge.net/projects/gri/forums/forum/16975/topic/4596628/index/page/1}
16548@dots{} @code{pgm} images grayscale was wrong
16549@end itemize
16550
16551@subsubsection Version 2.12.22
16552@strong{Bug fixes}
16553@itemize @bullet
16554@item
16555Fix github bug
16556@uref{http://github.com/dankelley/gri/issues#issue/5}
16557@dots{} @code{draw image} failed on some black/white images
16558@end itemize
16559
16560@subsubsection Version 2.12.21 [2010 June 8 @uref{http://en.wikipedia.org/wiki/World_Oceans_Day, World Ocean Day}]
16561@strong{Bug Fixes}
16562@itemize @bullet
16563@item
16564Fix github bug
16565@uref{http://github.com/dankelley/gri/issues#issue/1}
16566@dots{} @code{convert grid to image directly} misplaced image ``patches'' by one patch width and one patch height
16567@end itemize
16568
16569
16570@subsubsection Version 2.12.20 [2010 April 9 @uref{http://en.wikipedia.org/wiki/Vimy_Ridge_Day, Vimy Ridge Day}]
16571@strong{New Features}
16572@itemize @bullet
16573@item
16574add @code{labelling} option to @code{set x axis} and @code{set y axis}.
16575
16576@item
16577add @code{directly} option to @code{convert grid to image}.
16578@end itemize
16579
16580@strong{Bug Fixes}
16581@itemize @bullet
16582@item
16583Fix SourceForge bug
16584@uref{https://sourceforge.net/forum/forum.php?thread_id=2913919&forum_id=16974,#2913919}
16585@dots{} SVG: all symbols are "."
16586@item
16587Fix SourceForge bug
16588@uref{https://sourceforge.net/forum/forum.php?thread_id=2913893&forum_id=16974,#2913893}
16589@dots{} svg segfault on draw label
16590@item
16591Fix SourceForge bug
16592@uref{https://sourceforge.net/forum/forum.php?thread_id=2913841&forum_id=16974,#2913841}
16593@dots{} svg draw box filled not filled
16594@item
16595Fix SourceForge bug
16596@uref{https://sourceforge.net/forum/forum.php?thread_id=2913840&forum_id=16974,#2913840}
16597@dots{} svg images are upside-down
16598@item
16599Fix SourceForge bug
16600@uref{https://sourceforge.net/forum/forum.php?thread_id=2913838&forum_id=16974,#2913838}
16601@dots{} image postscript clip problem
16602@end itemize
16603
16604@subsubsection Version 2.12.19 [2009 July 17 @uref{http://en.wikipedia.org/wiki/World_Day_for_International_Justice, World Day for International Justice}]
16605
16606@strong{New Features}
16607@itemize @bullet
16608@item
16609Fix SourceForge ``bug''
16610@uref{https://sourceforge.net/forum/forum.php?thread_id=2977816&forum_id=16974,#2977816}
16611@dots{} Fedora packaging requires more precise license declarations.
16612@end itemize
16613
16614@strong{Bug Fixes}
16615@itemize @bullet
16616@item
16617Fix SourceForge bug
16618@uref{https://sourceforge.net/forum/forum.php?thread_id=3266884&forum_id=16974,#3266884}
16619@dots{} error in docs for strlen.
16620@end itemize
16621
16622
16623@subsubsection Version 2.12.18 [2008 Sep 8 @uref{http://en.wikipedia.org/wiki/International_Literacy_Day, International Literacy Day}]
16624
16625@strong{Bug Fixes}
16626@itemize @bullet
16627
16628@item
16629Improve security of temporary-file handling.
16630
16631@item
16632Fix SourceForge bug
16633@uref{http://sourceforge.net/tracker/index.php?func=detail&aid=1985862&group_id=5511&atid=105511,#1985862}
16634@dots{} SVG output had axis linewidth equal to curve line width.
16635
16636@end itemize
16637
16638
16639@subsubsection Version 2.12.17 [2008 May 29 @uref{http://en.wikipedia.org/wiki/Oak_Apple_Day, Oak Apple Day (England)}]
16640
16641@strong{New Features}
16642@itemize @bullet
16643
16644@item  Add GNU readline support so that interactive mode will have history, command editing, etc.
16645
16646@end itemize
16647
16648@strong{Bug Fixes}
16649@itemize @bullet
16650
16651@item
16652Fix SourceForge bug
16653@uref{https://sourceforge.net/tracker/?func=detail&atid=105511&aid=1913577&group_id=5511,#1913577}
16654@dots{} superscripts did not end correctly, if preceeded by an inline @code{@{@}} block.
16655
16656@item
16657Fix SourceForge bug
16658@uref{https://sourceforge.net/tracker/index.php?func=detail&aid=1761562&group_id=5511&atid=105511,#1761562}
16659@dots{} y axis name printed upside down, for log axes in which user specified a high values at the bottom end of the axis
16660
16661@end itemize
16662
16663
16664@subsubsection Version 2.12.16 [2007 Jul 20 @uref{http://en.wikipedia.org/wiki/Apollo_11, anniversary of the first moon landing}]
16665
16666@strong{Bug Fixes}
16667@itemize @bullet
16668
16669@item
16670Fix Debian bug
16671@uref{http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=130802,#130802}
16672@dots{} postscript problem in landscape mode, refreshed in gv viewer
16673
16674@item
16675Fix Debian bug
16676@uref{http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=434010,#434010}
16677@dots{} @code{set page landscape} requires @code{set page size} first, but it should really default to something reasonable instead.
16678
16679@end itemize
16680
16681
16682@subsubsection Version 2.12.15 [2007 Apr 16 @uref{http://en.wikipedia.org/wiki/Mawlid, celebration of birthday of Muhammad}]
16683
16684@strong{Bug Fixes}
16685@itemize @bullet
16686
16687@item
16688Fix SourceForge bug
16689@uref{https://sourceforge.net/tracker/index.php?func=detail&aid=1700978&group_id=5511&atid=105511,#1700978}
16690@dots{} html concept index mostly broken
16691
16692@item
16693Fix SourceForge bug
16694@uref{https://sourceforge.net/tracker/index.php?func=detail&aid=1698924&group_id=5511&atid=105511,#1698924}
16695@dots{} box plots show missing data
16696
16697@item
16698Fix Debian bug #417217
16699@dots{} will not compile in GCC 4.3
16700
16701@item
16702Fix SourceForge bug
16703@uref{https://sourceforge.net/tracker/index.php?func=detail&aid=1698116&group_id=5511&atid=105511,#1698116}
16704@dots{} poorly-positioned name of RHS y-axis
16705
16706@end itemize
16707
16708
16709@subsubsection Version 2.12.14 [2007 Jan 08: @uref{http://en.wikipedia.org/wiki/Seijin_shiki, Coming-of-Age Day (Japan)}]
16710@strong{Bug Fixes}
16711@itemize @bullet
16712
16713@item
16714Fix SourceForge bug
16715@uref{https://sourceforge.net/tracker/index.php?func=detail&aid=1630768&group_id=5511&atid=105511,#1630768}
16716@dots{} Fix to segfault in clipped images (a bug that may have developed after version 2.13.3)
16717@end itemize
16718
16719
16720@subsubsection Version 2.12.13 [2006 Nov 06: @uref{http://en.wikipedia.org/wiki/Public_holidays_in_Tajikistan, Constitution Day (Tajikistan)}]
16721@strong{Bug Fixes}
16722@itemize @bullet
16723
16724@item
16725Fix SourceForge bug
16726@uref{https://sourceforge.net/tracker/index.php?func=detail&aid=1591475&group_id=5511&atid=105511,#1591475}
16727@dots{} Fix to compile in Solaris CC
16728
16729@item
16730Fix SourceForge bug
16731@uref{https://sourceforge.net/tracker/index.php?func=detail&aid=1591062&group_id=5511&atid=105511,#1591062}
16732@dots{} Fix to compile in OpenBSD
16733
16734@end itemize
16735
16736@subsubsection Version 2.12.12 [2006 July 16: @uref{http://en.wikipedia.org/wiki/Yellow_Pig%27s_Day,Yellow Pigs Day}]
16737@strong{Bug Fixes}
16738@itemize @bullet
16739
16740@item
16741Fix SourceForge bug
16742@uref{https://sourceforge.net/tracker/index.php?func=detail&aid=1523033&group_id=5511&atid=105511,#1523033}
16743@dots{} Malloc error (freeing something already freed?)
16744
16745@item
16746Fix SourceForge bug
16747@uref{https://sourceforge.net/tracker/index.php?func=detail&aid=1523032&group_id=5511&atid=105511,#1523032}
16748@dots{} @code{create columns from function} bug, if there is an existing directory called @code{tmp}.
16749
16750@item
16751Fix SourceForge bug
16752@uref{https://sourceforge.net/tracker/index.php?func=detail&aid=1491105&group_id=5511&atid=105511,#1491105}
16753@dots{} @code{set x axis labels} had no affect for log axes (same for y)
16754
16755@end itemize
16756
16757
16758@subsubsection Version 2.12.11 [2006 Mar 30: Hindu New Year]
16759@strong{Bug Fixes}
16760@itemize @bullet
16761
16762@item
16763Fix SourceForge bug
16764@uref{https://sourceforge.net/tracker/index.php?func=detail&aid=1449546&group_id=5511&atid=105511,#1449546}
16765@dots{} x axis limits not correctly inferred from @code{set x grid} (same for y).
16766
16767@end itemize
16768
16769@subsubsection Version 2.12.10 [2006 Jan 26: Australia Day]
16770@strong{Bug Fixes}
16771@itemize @bullet
16772
16773@item
16774Fix SourceForge bug
16775@uref{https://sourceforge.net/tracker/?func=detail&atid=105511&aid=1408259&group_id=5511
16776,#1408259}
16777@dots{} PostScript file contained private information.  This was fixed by adding
16778new commandline arguments @code{-private} and @code{-no_private}, the
16779former of which (the new default) means to not include the user's name,
16780the invocation arguments, or the command-file contents (@ref{Invoking Gri}).
16781
16782@item
16783Fix SourceForge bug
16784@uref{http://sourceforge.net/tracker/index.php?func=detail&aid=12851803&group_id=5511&atid=105511,#1285180}
16785@dots{} NaN was mishandled.  (The bug may have arisen in version 2.12.7 or thereabouts.)
16786
16787@item
16788Port to the @uref{http://www.freebsd.org/,FreeBSD} operating system,
16789with help from Christopher Illies and Roman Neuhauser.
16790
16791@item
16792Fix SourceForge bug
16793@uref{http://sourceforge.net/tracker/index.php?func=detail&aid=1217273&group_id=5511&atid=105511,#1217273}
16794@dots{} missing some version numbers within docs
16795
16796@item
16797Fix SourceForge bug
16798@uref{http://sourceforge.net/tracker/index.php?func=detail&aid=1196613&group_id=5511&atid=105511,#1196613}
16799@dots{} user-supplied x-axis labels can run offscale (fix for y-axis later...)
16800
16801@item
16802Fix SourceForge bug
16803@uref{http://sourceforge.net/tracker/index.php?func=detail&aid=1198341&group_id=5511&atid=105511,#1198341}
16804@dots{} x-axis labels incorrectly rotated (sometimes)
16805
16806@item
16807Fix SourceForge bug
16808@uref{http://sourceforge.net/tracker/index.php?func=detail&aid=1199280&group_id=5511&atid=105511,#1199280}
16809@dots{} warning about @code{malloc} for RPN assignments
16810
16811@item
16812Fix SourceForge bug
16813@uref{http://sourceforge.net/tracker/index.php?func=detail&aid=1196115&group_id=5511&atid=105511,#1196115}
16814@dots{} @code{gri_unpage} and @code{gri_merge} mis-installed
16815
16816@item
16817Fix SourceForge bug
16818@uref{http://sourceforge.net/tracker/index.php?func=detail&aid=1153209&group_id=5511&atid=105511,#1153209}
16819@dots{} Emacs mode incompatible with new version of @code{gv} PostScript viewer
16820
16821Fix SourceForge bug
16822@uref{http://sourceforge.net/tracker/index.php?func=detail&aid=1101172&group_id=5511&atid=105511,#1101172}
16823@dots{} @code{gri -help} incorrectly stated meaning of last argument(s)
16824
16825@item
16826Fix SourceForge bug
16827@uref{http://sourceforge.net/tracker/index.php?func=detail&aid=835711&group_id=5511&atid=105511,#835711}
16828@dots{} @code{draw gri logo} fails.
16829
16830@item
16831Fix SourceForge bug
16832@uref{http://sourceforge.net/tracker/index.php?func=detail&aid=1098269&group_id=5511&atid=105511,#1098269}
16833@dots{} problem compiling on AMD64 machine.  (Solution provided by Andreas Jochens, a Debian user.)
16834
16835@item
16836Fix SourceForge bug
16837@uref{http://sourceforge.net/tracker/index.php?func=detail&aid=867515&group_id=5511&atid=105511,#867515}
16838@dots{} problem with junk appearing in images.
16839
16840@item
16841Fix SourceForge bug
16842@uref{http://sourceforge.net/tracker/index.php?func=detail&aid=875881&group_id=5511&atid=105511,#875881}
16843@dots{} problem compiling with gcc 2.95.3 compiler.
16844
16845@end itemize
16846
16847
16848@subsubsection Version 2.12.9 [2005 Jan 6: @uref{http://en.wikipedia.org/wiki/Epiphany_%28feast%29,Feast of Epiphany}]
16849@strong{Bug Fixes}
16850@itemize @bullet
16851
16852@item
16853Fix SourceForge bug
16854@uref{http://sourceforge.net/tracker/index.php?func=detail&aid=1094087&group_id=5511&atid=105511,#1094087}
16855@dots{} @code{set path to} incorrectly parsed colon-separated paths
16856
16857@item
16858Fix SourceForge bug
16859@uref{http://sourceforge.net/tracker/index.php?func=detail&aid=1085788&group_id=5511&atid=105511,#1085788}
16860@dots{} @code{image *=}, @code{image /=}, @code{image ^=}, and @code{image _=} all gave incorrect results
16861
16862@item
16863Fix SourceForge bug
16864@uref{http://sourceforge.net/tracker/index.php?func=detail&aid=1084123&group_id=5511&atid=105511,#1084123}
16865@dots{} does not compile in fink
16866
16867
16868@item
16869Fix SourceForge bug
16870@uref{http://sourceforge.net/tracker/index.php?func=detail&aid=676767&group_id=5511&atid=105511,#676767}
16871@dots{} on fink systems, @code{help} does not work
16872
16873@end itemize
16874
16875
16876@subsubsection Version 2.12.8 [2004]
16877@strong{Bug Fixes}
16878@itemize @bullet
16879
16880@item
16881Fix SourceForge bug
16882@uref{http://sourceforge.net/tracker/index.php?func=detail&aid=1019141&group_id=5511&atid=105511,#1019141}
16883@dots{} @code{draw arc} ignores the present pen color
16884
16885
16886@item
16887Fix SourceForge bug
16888@uref{http://sourceforge.net/tracker/index.php?func=detail&aid=997741&group_id=5511&atid=105511,#997741}
16889@dots{} PostScript broken on images with y-axis decreasing, and enclosed by PostScript clipping
16890
16891
16892@item
16893Fix SourceForge bug
16894@uref{http://sourceforge.net/tracker/index.php?func=detail&aid=978822&group_id=5511&atid=105511,#978822}
16895@dots{} documentation wrong on @code{set path to}
16896
16897@item
16898Fix SourceForge bug
16899@uref{http://sourceforge.net/tracker/index.php?func=detail&aid=932203&group_id=5511&atid=105511,#932203}
16900@dots{} misplaced labels caused by @code{set x axis labels}
16901
16902@item
16903Fix SourceForge bug
16904@uref{http://sourceforge.net/tracker/index.php?func=detail&aid=928277&group_id=5511&atid=105511,#928277}
16905@dots{} @code{draw polygon} should take @code{cm} and @code{pt} units
16906
16907@item
16908Fix SourceForge bug
16909@uref{http://sourceforge.net/tracker/index.php?func=detail&aid=930259&group_id=5511&atid=105511,#930259}
16910@dots{} fix @code{draw arc}'s drawing of an extra line (thanks for the fix, Wolfgang Voegeli)
16911
16912@item
16913Fix SourceForge bug
16914@uref{http://sourceforge.net/tracker/index.php?func=detail&aid=923719&group_id=5511&atid=105511,#923719}
16915@dots{} @code{draw curve overlying} ignored the effect of @code{set dash}
16916
16917@item
16918Fix SourceForge bug
16919@uref{http://sourceforge.net/tracker/index.php?func=detail&aid=914125&group_id=5511&atid=105511,#914125}
16920@dots{} offpage points in axes were reported as having been drawn by @code{draw curve}.
16921
16922
16923@item
16924Fix SourceForge bug
16925@uref{http://sourceforge.net/tracker/index.php?func=detail&aid=877613&group_id=5511&atid=105511,#877613}
16926@dots{} @code{help} (and other commands using temporary files) does not work in OSX/Fink version.
16927
16928@item
16929Fix SourceForge bug
16930@uref{http://sourceforge.net/tracker/index.php?func=detail&aid=874483&group_id=5511&atid=105511,#874483}
16931@dots{} @code{state save} doesn't keep track of @code{dash} settings.
16932
16933@item
16934Fix SourceForge bug
16935@uref{http://sourceforge.net/tracker/index.php?func=detail&aid=873245&group_id=5511&atid=105511,#873245}
16936@dots{} inaccurate times are given in the warnings about slow operations on OSX platform (days are reported instead of seconds)
16937
16938@item
16939Fix SourceForge bug
16940@uref{http://sourceforge.net/tracker/index.php?func=detail&aid=871477&group_id=5511&atid=105511,#871477}
16941@dots{} the `missing value' feature should not be the default.  The solution
16942involved adding a new command @code{set missing value none}, which
16943is now the default.
16944
16945@end itemize
16946
16947
16948@subsubsection Version 2.12.7 [2003 Sep 4]
16949
16950@strong{Bug Fixes}
16951@itemize @bullet
16952
16953@item
16954Fix SourceForge bug
16955@uref{http://sourceforge.net/tracker/index.php?func=detail&aid=800022&group_id=5511&atid=105511,#800022}
16956AKA Debian bug
16957@uref{http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=208589,#208589},
16958@dots{} did not build on some Debian platforms because it was based
16959on an old version of @code{automake}.
16960
16961@end itemize
16962
16963
16964@subsubsection Version 2.12.6 [2003 Sep 1: Labour Day]
16965
16966@strong{New Features}
16967@itemize @bullet
16968
16969@item
16970Add @code{age} RPN function, for testing file ages (@ref{age-rpn-operator}).
16971
16972@end itemize
16973
16974@strong{Bug Fixes}
16975@itemize @bullet
16976
16977@item
16978Fix SourceForge bug
16979@uref{http://sourceforge.net/tracker/index.php?func=detail&aid=773850&group_id=5511&atid=105511,#773850}
16980@dots{} bounding-box is increased by @code{draw symbol} even if (rectangular) postscript clipping is active.
16981
16982@item
16983Fix SourceForge bug
16984@uref{http://sourceforge.net/tracker/index.php?func=detail&aid=760130&group_id=5511&atid=105511,#760130}
16985@dots{} Solaris cannot compile with @key{C-l} in Makefile.
16986
16987@item
16988Fix SourceForge bug
16989@uref{http://sourceforge.net/tracker/index.php?func=detail&aid=743134&group_id=5511&atid=105511,#743134}
16990@dots{} bounding box not limited by @code{set clip postscript}
16991
16992@item
16993Fix SourceForge bug
16994@uref{http://sourceforge.net/tracker/index.php?func=detail&aid=750561&group_id=5511&atid=105511,#750561}
16995@dots{} during compilation, @code{make} rebuilds HTML docs even if up-to-date
16996
16997@end itemize
16998
16999
17000
17001@subsubsection Version 2.12.5 [2003 May 19: Victoria Day]
17002
17003@strong{New Features}
17004@itemize @bullet
17005@item
17006Apply a patch provided Kawamura Masao, relating to (a) errors in the
17007documentation of file locations and (b) a programming error hidden
17008behind an unset precompiler flag.
17009
17010@item
17011Add hexadecimal colornames (@ref{pen-color-hexadecimal}).
17012
17013@end itemize
17014
17015@strong{Bug Fixes}
17016@itemize
17017@item
17018Fix SourceForge bug
17019@uref{http://sourceforge.net/tracker/index.php?func=detail&aid=739761&group_id=5511&atid=105511,#739761}
17020@dots{} @code{draw time stamp} named the command-file incorrectly
17021
17022@item
17023Fix SourceForge bug
17024@uref{http://sourceforge.net/tracker/index.php?func=detail&aid=720607&group_id=5511&atid=105511,#720607}
17025@dots{} the emacs mode looked for html documentation files in an incorrect location on linux/redhat systems
17026
17027@end itemize
17028
17029
17030@subsubsection Version 2.12.4 [2003 Apr 06]
17031@strong{Bug Fixes}
17032@itemize
17033@item
17034Fix SourceForge bug
17035@uref{http://sourceforge.net/tracker/index.php?func=detail&aid=696073&group_id=5511&atid=105511,#696073}
17036@dots{} did not handle @code{\$()} syntax correctly.
17037
17038@item
17039Fix SourceForge bug
17040@uref{http://sourceforge.net/tracker/index.php?func=detail&aid=715884&group_id=5511&atid=105511,#715884}
17041@dots{} mixup on protected-quotes within double-quoted strings
17042
17043@item
17044Fix Debian bug
17045@uref{http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=183912,#183912}
17046@dots{} would not compile on m86k architecture.
17047
17048@item
17049Fix SourceForge bug
17050@uref{http://sourceforge.net/tracker/index.php?func=detail&aid=711354&group_id=5511&atid=105511,#711354}
17051@dots{} @code{Creator:} comment in PostScript file named the command-file incorrectly,
17052if there were options on the gri invocation command.  Since this naming of the
17053command-file was not especially useful, and since nobody has complained of this bug
17054but the author, the feature has simply been deleted.  Just complain if you want it back!
17055
17056@item
17057Fix SourceForge bug
17058@uref{http://sourceforge.net/tracker/index.php?func=detail&aid=706202&group_id=5511&atid=105511,#706202}
17059@dots{} A hint about the page orientation was not given in the Postscript
17060comments.  The lack of this hint has no affect on printing, etc.,
17061only viewing in some viewers.
17062
17063@end itemize
17064
17065
17066@subsubsection Version 2.12.3 [2003 Mar 1]
17067@strong{Bug Fixes}
17068@itemize
17069@item
17070Fix SourceForge bug
17071@uref{http://sourceforge.net/tracker/index.php?func=detail&aid=685919&group_id=5511&atid=105511,#685919}
17072@dots{} @code{-output} commandline argument failed on @file{.eps} file extension.
17073
17074@end itemize
17075
17076
17077@subsubsection Version 2.12.2 [2003 Feb 7: Munro Day at @uref{http://www.dal.ca/,Dalhousie University}]
17078
17079@strong{Bug Fixes}
17080
17081@itemize
17082
17083@item
17084Fix SourceForge bug
17085@uref{http://sourceforge.net/tracker/index.php?func=detail&aid=675304&group_id=5511&atid=105511,#675304}
17086@dots{} Segmentation fault can occur on @code{read image pgm}
17087if an image already exists, e.g. created by
17088@code{convert grid to image}.
17089
17090@item
17091Fix SourceForge bug
17092@uref{http://sourceforge.net/tracker/index.php?func=detail&aid=647234&group_id=5511&atid=105511,#647234}
17093@dots{} Source file @file{draw.cc} will not compile on MAC OS X 10.1.5 at optimization level 2, so drop the level to no optimization, as a temporary measure.
17094
17095@item
17096Fix SourceForge bug
17097@uref{http://sourceforge.net/tracker/index.php?func=detail&aid=671022&group_id=5511&atid=105511,#671022}
17098@dots{} @code{flip image x|y} did not flip images correctly, except in special circumstances.
17099
17100@item
17101Fix SourceForge bug
17102@uref{http://sourceforge.net/tracker/index.php?func=detail&aid=669603&group_id=5511&atid=105511,#669603}
17103@dots{} @code{skip backward .n.} erroneously skipped forward
17104
17105@item
17106Fix SourceForge bug
17107@uref{http://sourceforge.net/tracker/index.php?func=detail&aid=667754&group_id=5511&atid=105511,#667754}
17108@dots{} @code{read image pgm} segfaults on memory if an image has already been created by @code{convert grid to image}
17109
17110@item
17111Fix SourceForge bug
17112@uref{http://sourceforge.net/tracker/index.php?func=detail&aid=664388&group_id=5511&atid=105511,#664388}
17113@dots{} @code{read image pgm} fails if an image already exists
17114
17115@item
17116Fix SourceForge bug
17117@uref{http://sourceforge.net/tracker/index.php?func=detail&aid=654129&group_id=5511&atid=105511,#654129}
17118@dots{} ignoring @file{~/.grirc} file
17119
17120@item
17121Fix SourceForge bug
17122@uref{http://sourceforge.net/tracker/index.php?func=detail&aid=654127&group_id=5511&atid=105511,#654127}
17123@dots{} configure scripts are broken
17124
17125@item
17126Fix SourceForge bug
17127@uref{http://sourceforge.net/tracker/index.php?func=detail&aid=649132&group_id=5511&atid=105511,#649132}
17128@dots{} removed unused LDFLAGS phrase from Makefile
17129
17130@item
17131Fix SourceForge bug
17132@uref{http://sourceforge.net/tracker/index.php?func=detail&aid=649134&group_id=5511&atid=105511,#649134}
17133@dots{} tweak gcc optimization
17134
17135@item
17136Fix SourceForge bug
17137@uref{http://sourceforge.net/tracker/index.php?func=detail&aid=649136&group_id=5511&atid=105511,#649136}
17138@dots{} examples 8 and 9 broken
17139
17140@item
17141Fix SourceForge bug
17142@uref{http://sourceforge.net/tracker/index.php?func=detail&aid=641406&group_id=5511&atid=105511,#641406}
17143@dots{} RPN too aggressive on missing values
17144
17145@end itemize
17146
17147
17148@subsubsection Version 2.12.1 [2002 Sep 25]
17149@strong{Bug Fixes}
17150
17151@itemize
17152
17153@item
17154Fix SourceForge bug
17155@uref{http://sourceforge.net/tracker/index.php?func=detail&aid=613075&group_id=5511&atid=105511,#613075}
17156@dots{} RPN operators @code{sin}, @code{cos}, and @code{tan} were limited in range (new bug in last release)
17157
17158@end itemize
17159
17160
17161
17162@subsubsection Version 2.12.0 [2002 Sep 15: @uref{http://www.terryfox.org/,Terry Fox Day}, Canada.]
17163
17164@strong{New Features}
17165
17166@itemize @bullet
17167
17168@item
17169Add @code{sed} RPN operator, to work on strings @ref{Binary Operators}.
17170
17171@item
17172Add @code{skewness} and @code{kurtosis} RPN operators, to work on
17173columns @ref{Manipulation of Columns etc}.
17174
17175@end itemize
17176
17177
17178@strong{Removed Features}
17179
17180@itemize
17181
17182@item
17183n/a
17184
17185@end itemize
17186
17187
17188@strong{Bug Fixes}
17189
17190@itemize
17191
17192@item
17193Fix SourceForge bug
17194@uref{http://sourceforge.net/tracker/index.php?func=detail&aid=606303&group_id=5511&atid=105511,#606303}
17195@dots{} web-pages were not valid html-4.0.
17196
17197@item
17198Fix SourceForge bug
17199@uref{http://sourceforge.net/tracker/index.php?func=detail&aid=593958&group_id=5511&atid=105511,#593958}
17200@dots{} missing-values should be ignored if they occur in intermediate results of RPN calculations.
17201
17202@item
17203Fix SourceForge bug
17204@uref{http://sourceforge.net/tracker/index.php?func=detail&aid=600395&group_id=5511&atid=105511,#600395}
17205@dots{} won't compile with recently released version (3.2) of GCC compiler.
17206
17207@item
17208Fix SourceForge bug
17209@uref{http://sourceforge.net/tracker/index.php?func=detail&aid=600223&group_id=5511&atid=105511,#600233}
17210@dots{} segfaults if some RPN operators are used on stacks that do
17211not contain enough entries (e.g. @code{show @{rpn cosh@}}).
17212@end itemize
17213
17214
17215@c HTML <!-- newfile Version_2_10.html "Gri: Version 2.10" "Gri: Version 2.10" -->
17216@node   Version 2.10, Version 2.8, Version 2.12, Stable Stream
17217@comment  node-name,  next,  previous,  up
17218@subsection Version 2.10
17219@cindex version 2.10
17220
17221@subsubsection Version 2.10.1 [2002 Jun 1]
17222
17223@strong{Bug Fixes}
17224
17225@itemize
17226
17227@item
17228Fix SourceForge bug
17229@uref{http://sourceforge.net/tracker/index.php?func=detail&aid=562911&group_id=5511&atid=105511,#562911}
17230@dots{} won't build with @file{gcc-3.0} compiler.  This was reported by
17231the Debian hppa builder as Debian bug
17232@uref{http://bugs.debian.org/148572,#148572}.
17233
17234
17235@item
17236Fix SourceForge bug
17237@uref{http://sourceforge.net/tracker/index.php?func=detail&aid=562558&group_id=5511&atid=105511,#562558}
17238@dots{} @code{draw title} terminates program if have non-positive data and had initially specified log axes.
17239
17240@item
17241Fix SourceForge bug
17242@uref{http://sourceforge.net/tracker/index.php?func=detail&aid=562014&group_id=5511&atid=105511,#562014}
17243@dots{} won't build if @code{popt} library is unavailable.  This was reported by
17244the Debian ia64 builder as Debian bug
17245@uref{http://bugs.debian.org/148493,#148493}.
17246
17247
17248@item
17249Fix SourceForge bug
17250@uref{http://sourceforge.net/tracker/index.php?func=detail&aid=558463&group_id=5511&atid=105511,#558463}
17251@dots{} in HTML docs, the ``press'' margin tag was misdirected.
17252
17253@item
17254Fix SourceForge bug
17255@uref{http://sourceforge.net/tracker/index.php?func=detail&aid=562017&group_id=5511&atid=105511,#562017}
17256@dots{} parser fails with DOS end-of-line.
17257
17258@item
17259Fix SourceForge bug
17260@uref{http://sourceforge.net/tracker/index.php?func=detail&aid=562113&group_id=5511&atid=105511,#562113}
17261@dots{} @code{new page} postscript error in @file{gv} viewer.
17262
17263@end itemize
17264
17265
17266@subsubsection Version 2.10.0 [2002 May 20: Victoria Day]
17267
17268@strong{New Features}
17269
17270@itemize @bullet
17271
17272@item
17273In the documentation, change the names of some variables to be
17274clearer: @code{ll_x} is now written @code{xleft}, etc.
17275
17276@item
17277Add RPN binary operators @code{and}, @code{or} for logical operations
17278@ref{Binary Operators}, along with negation operator @code{not}
17279@ref{Unary Operators}.
17280
17281@item
17282Add @code{draw arc} command (@ref{Draw Arc}).
17283
17284@item
17285Add @code{set x axis labels} (@ref{Set X Axis}) and
17286@code{set y axis labels} (@ref{Set Y Axis}) commands.
17287
17288@item
17289Permit specification of @code{pt} units for
17290@code{draw label} (@ref{Draw Label}),
17291@code{draw box} (@ref{Draw Box}),
17292@code{draw symbol at} (@ref{Draw Symbol At}),
17293and
17294@code{draw line from} (@ref{Draw Line From}).
17295
17296@item
17297Add @code{set clip to curve} (@ref{Set Clip}) command.
17298@emph{Caution:} this
17299needs extension, and may have a bug if called twice in succession [but
17300is this with an intervening @code{set clip off}]
17301
17302@item
17303Add @code{group} and @code{end group} commands, in preparation for SVG
17304output.  So far these commands do nothing, and are basically just a
17305signal that users should not create commands with these names since Gri
17306will need them soon.
17307
17308@item
17309Add @code{..xinc..} and @code{..yinc..} builtin variables (@ref{Axis Scaling}).
17310
17311@item
17312Make the @code{open} command accept URLs as filenames (@ref{Open}).
17313
17314@end itemize
17315
17316
17317
17318@strong{Removed Features}
17319
17320@itemize
17321
17322@item
17323Remove @code{gri -repair old.ps new.ps} since (a) it was only half
17324functional, (b) it was hard to code in the new scheme of
17325argument-processing and (c) the author was not aware of anybody every
17326having used it.
17327
17328@item
17329Make the @code{-chatty} commandline option require a value (@ref{Invoking Gri}).
17330
17331@end itemize
17332
17333
17334
17335@strong{Bug Fixes}
17336
17337@itemize
17338
17339@item
17340Fix SourceForge bug
17341@c HTML <a href="http://sourceforge.net/tracker/index.php?func=detail&aid=552009&group_id=5511&atid=105511">
17342#552009
17343@c HTML </a>
17344(@code{rpn} can segfault if @code{!=} operator is written as @code{=!})
17345
17346@item
17347Fix SourceForge bug
17348@c HTML <a href="http://sourceforge.net/tracker/index.php?func=detail&aid=546109&group_id=5511&atid=105511">
17349#546109
17350@c HTML </a>
17351(bounding box wrong if postscript clipping used)
17352@c HTML </a>
17353
17354@item
17355Fix SourceForge bug
17356@c HTML <a href="http://sourceforge.net/tracker/index.php?func=detail&aid=514495&group_id=5511&atid=105511">
17357#514495
17358@c HTML </a>
17359in which @code{set clip to curve} failed to handle missing values in the curve.
17360@c HTML </a>
17361
17362@item
17363Fix SourceForge bug
17364@c HTML <a href="http://sourceforge.net/tracker/index.php?func=detail&aid=450465&group_id=5511&atid=105511">
17365#450465
17366@c HTML </a>
17367(@code{create columns from function} was broken).
17368
17369@end itemize
17370
17371
17372
17373
17374@c HTML <!-- newfile Version_2_8.html "Gri: Version 2.8" "Gri: Version 2.8" -->
17375@node   Version 2.8, Version 2.6, Version 2.10, Stable Stream
17376@comment  node-name,  next,  previous,  up
17377@subsection Version 2.8
17378
17379@subsubsection Version 2.8.7 [2002 Apr 03]
17380@itemize @bullet
17381@item
17382Fix SourceForge bug
17383@c HTML <a href="http://sourceforge.net/tracker/index.php?func=detail&aid=482120&group_id=5511&atid=105511">
17384#482120
17385@c HTML </a>
17386(@code{regress} ignores data weights)
17387@item
17388Fix SourceForge bug
17389@c HTML <a href="http://sourceforge.net/tracker/index.php?func=detail&aid=508657&group_id=5511&atid=105511">
17390#508657
17391@c HTML </a>
17392(missing backslash in drawing undefined synonyms)
17393
17394@item
17395Fix SourceForge bug
17396@c HTML <a href="http://sourceforge.net/tracker/index.php?func=detail&aid=523450&group_id=5511&atid=105511">
17397#523450
17398@c HTML </a>
17399(log axes detect non-positive values too late)
17400@item
17401Fix SourceForge bug
17402@c HTML <a href="http://sourceforge.net/tracker/index.php?func=detail&aid=521045&group_id=5511&atid=105511">
17403#521045
17404@c HTML </a>
17405(installation/compilation with Solaris Workshop V6 Update 2 compiler)
17406@end itemize
17407
17408
17409
17410@subsubsection Version 2.8.6 [2002 Feb 14]
17411@itemize @bullet
17412@item
17413Fix SourceForge bug
17414@c HTML <a href="http://sourceforge.net/tracker/index.php?func=detail&aid=513002&group_id=5511&atid=105511">
17415#513002
17416@c HTML </a>
17417(minor documentation error in @code{set clip})
17418@item
17419Fix SourceForge bug
17420@c HTML <a href="http://sourceforge.net/tracker/index.php?func=detail&aid=509592&group_id=5511&atid=105511">
17421#509592
17422@c HTML </a>
17423(HTML docs had midordered indices)
17424@item
17425Fix SourceForge bug
17426@c HTML <a href="http://sourceforge.net/tracker/index.php?func=detail&aid=506534&group_id=5511&atid=105511">
17427#506534
17428@c HTML </a>
17429(map axes give wrong minutes in negative regions).  Thanks, Brian, for the patch on this!
17430@item
17431Fix SourceForge bug
17432@c HTML <a href="http://sourceforge.net/tracker/index.php?func=detail&aid=508088&group_id=5511&atid=105511">
17433#508088
17434@c HTML </a>
17435(grimode: gv should update, not be relaunched)
17436@item
17437Fix SourceForge bug
17438@c HTML <a href="http://sourceforge.net/tracker/index.php?func=detail&aid=506490&group_id=5511&atid=105511">
17439#506490
17440@c HTML </a>
17441(@code{-v} commandline option returned wrong version number)
17442@end itemize
17443
17444
17445@subsubsection Version 2.8.5 [2001 Dec 13]
17446@itemize @bullet
17447@item
17448Fix SourceForge bug
17449@c HTML <a href="http://sourceforge.net/tracker/index.php?func=detail&aid=492472&group_id=5511&atid=105511">
17450#492472
17451@c HTML </a>
17452(@code{inf} rpn operator caused segfault)
17453@end itemize
17454
17455@subsection Version 2.8.4 [2001 Oct 4]
17456@itemize @bullet
17457@item
17458Fix SourceForge bug
17459@c HTML <a href="http://sourceforge.net/tracker/index.php?func=detail&aid=467973&group_id=5511&atid=105511">
17460#467973
17461@c HTML </a>
17462(@code{gri -version} gave wrong version number, breaking the Emacs Gri mode.)
17463@item
17464Fix SourceForge bug
17465@c HTML <a href="http://sourceforge.net/tracker/index.php?func=detail&aid=468014&group_id=5511&atid=105511">
17466#468014
17467@c HTML </a>
17468(@code{draw grid} disobeyed pencolor.)
17469@end itemize
17470
17471@subsubsection Version 2.8.3 [2001 Oct 1]
17472@itemize @bullet
17473@item
17474Fix SourceForge bug
17475@c HTML <a href="http://sourceforge.net/tracker/index.php?func=detail&aid=462243&group_id=5511&atid=105511">
17476#462243
17477@c HTML </a>
17478(endian problem in Rasterfile images + reading problem in PGM images).
17479@end itemize
17480
17481@subsubsection Version 2.8.2 [2001 Sep 19]
17482@itemize @bullet
17483@item
17484Fix SourceForge bug
17485@c HTML <a href="http://sourceforge.net/tracker/index.php?func=detail&aid=461444&group_id=5511&atid=105511">
17486#461444
17487@c HTML </a>
17488(wouldn't compile with the @code{mingw32} compiler, for windows 32 machines).
17489@item
17490Fix SourceForge bug
17491@c HTML <a href="http://sourceforge.net/tracker/index.php?func=detail&aid=454557&group_id=5511&atid=105511">
17492#454557
17493@c HTML </a>
17494(wouldn't compile with the pre-release version 3.0.1 of the GNU c++ compiler,
17495in the case in which netCDF was already installed)
17496@end itemize
17497
17498@subsubsection Version 2.8.1 [2001 Sep 7]
17499@itemize @bullet
17500@item
17501Fix SourceForge bug
17502@c HTML <a href="http://sourceforge.net/tracker/index.php?func=detail&aid=450465&group_id=5511&atid=105511">
17503#450465
17504@c HTML </a>
17505(@code{create columns from function} was broken).
17506@item
17507Fix SourceForge bug
17508@c HTML <a href="http://sourceforge.net/tracker/index.php?func=detail&aid=454557&group_id=5511&atid=105511">
17509#454557
17510@c HTML </a>
17511(wouldn't compile with the pre-release version 3.0.1 of the GNU c++ compiler)
17512@end itemize
17513
17514
17515@subsection Version 2.8.0 [2001 Jul 30]
17516
17517@b{New command syntax}
17518@itemize @bullet
17519@item
17520Add @code{unlink} command as a unix-familiar way to delete files
17521(@ref{Unlink}).
17522@item
17523Add @code{set page size} command to clip to a given page size
17524(@ref{Set Page}).
17525@item
17526Add @code{substr} RPN operator to permit extraction of sub-strings
17527(@ref{Tertiary Operators}).
17528@item
17529Add @code{default} possibility for the @code{set x name} and the
17530@code{set y name} commands.
17531@item
17532@cindex underscore, in numbers
17533@cindex numbers, using underscore to separate thousand parts
17534@cindex thousand parts, indicating in numbers using underscore
17535Add Perl-like ability to put underscores in numerical constants, to
17536guide your eye.  These underscores are ignored by Gri, so that for
17537example @code{.v. = 1_000} and @code{.v. = 1000} are equivalent as far
17538as Gri is concerned.
17539@end itemize
17540
17541@b{Emacs mode} (@ref{Emacs Mode})
17542@itemize @bullet
17543@item
17544Give @key{M-Tab} the
17545ability to complete builtin variables and synonyms as well as
17546commands
17547@item
17548Add ``idle-timer minibuffer help'' to display defaults for builtin
17549variables under the cursor.
17550@item
17551Add fontification of builtin variables @emph{only}
17552if they are spelled correctly.
17553@end itemize
17554
17555
17556@b{Developer changes}
17557@itemize @bullet
17558@item
17559Add @code{make source-arch-indep} target in sources.  This will build a
17560source tar file in which all the architecture-independent material
17561(documentation in HTML, postscript and Info formats) is pre-made.  This
17562makes it easier to install gri on a host that doesn't have TeX and
17563ImageMagick installed.
17564@item
17565Complete the port to IBM's compiler for their AIX operating system.
17566@end itemize
17567
17568
17569@c HTML <!-- newfile Version_2_6.html "Gri: Version 2.6" "Gri: Version 2.6" -->
17570@node   Version 2.6, Version 2.4, Version 2.8, Stable Stream
17571@comment  node-name,  next,  previous,  up
17572@subsection Version 2.6
17573
17574@subsection Version 2.6.4 [2001 Jul 9: Dan's birthday]
17575@itemize @bullet
17576@item
17577Fix SourceForge bug
17578@c HTML <a href="http://sourceforge.net/tracker/index.php?func=detail&aid=435688&group_id=5511&atid=105511">
17579#435688
17580@c HTML </a>
17581(remnants of @code{polar} column type, no longer supported, remained in documentation)
17582@item
17583Fix SourceForge bug
17584@c HTML <a href="http://sourceforge.net/tracker/index.php?func=detail&aid=435603&group_id=5511&atid=105511">
17585#435603
17586@c HTML </a>
17587(@code{set dash} produced broken PostScript)
17588@item
17589Fix SourceForge bug
17590@c HTML <a href="http://sourceforge.net/tracker/index.php?func=detail&aid=431114&group_id=5511&atid=105511">
17591#431114
17592@c HTML </a>
17593(@code{-0} could appear on axes)
17594@end itemize
17595
17596@subsection Version 2.6.3 [2001 Jun 22]
17597@itemize @bullet
17598@item
17599Fix SourceForge bug
17600@c HTML <a href="http://sourceforge.net/tracker/index.php?func=detail&aid=433250&group_id=5511&atid=105511">
17601#433250
17602@c HTML </a>
17603(@code{draw symbol} ignored dashing state sometimes)
17604@item
17605Fix SourceForge bug
17606@c HTML <a href="http://sourceforge.net/tracker/index.php?func=detail&aid=432549&group_id=5511&atid=105511">
17607#432549
17608@c HTML </a>
17609(contours sometimes unlabelled)
17610@item
17611Tweak internal coding for compilation on AIX compilers.
17612@end itemize
17613
17614
17615
17616@subsubsection Version 2.6.2 [2001 May 19]
17617@itemize @bullet
17618@item
17619Fix SourceForge bug
17620@c HTML <a href="http://sourceforge.net/tracker/index.php?func=detail&aid=425174&group_id=5511&atid=105511">
17621#425174
17622@c HTML </a>
17623(synonym interpolation broken on e.g. @code{show "[\syn]"}
17624@item
17625Fix SourceForge bug
17626@c HTML <a href="http://sourceforge.net/tracker/index.php?func=detail&aid=425175&group_id=5511&atid=105511">
17627#425175
17628@c HTML </a>
17629(@code{while !..eof..} acted ignored end of file)
17630@end itemize
17631
17632
17633@subsubsection Version 2.6.1 [2001 May 10]
17634@itemize @bullet
17635@item
17636Fix SourceForge bug
17637@c HTML <a href="http://sourceforge.net/tracker/index.php?func=detail&aid=420499&group_id=5511&atid=105511">
17638#420499
17639@c HTML </a>
17640(gri-mode.el compatibility issues with emacs-21;  Mostly bad old code.)
17641@item
17642Fix SourceForge bug
17643@c HTML <a href="http://sourceforge.net/tracker/index.php?func=detail&aid=421076&group_id=5511&atid=105511">
17644#421076
17645@c HTML </a>
17646(byte-compiled gri-mode.el has broken IMenu support;  Affects Debian package.)
17647@item
17648Fix SourceForge bug
17649@c HTML <a href="http://sourceforge.net/tracker/index.php?func=detail&aid=419599&group_id=5511&atid=105511">
17650#419599
17651@c HTML </a>
17652(wouldn't compile under GNU g++ 3.x compiler)
17653@item
17654Fix SourceForge bug
17655@c HTML <a href="http://sourceforge.net/tracker/index.php?func=detail&aid=418065&group_id=5511&atid=105511">
17656#418065
17657@c HTML </a>
17658(documentation mentions back-tic notation, which is not available)
17659@item
17660Fix SourceForge bug
17661@c HTML <a href="http://sourceforge.net/tracker/index.php?func=detail&aid=417333&group_id=5511&atid=105511">
17662#417333
17663@c HTML </a>
17664(vague error message @code{RPN string operator})
17665@item
17666Fix SourceForge bug
17667@c HTML <a href="http://sourceforge.net/tracker/index.php?func=detail&aid=415277&group_id=5511&atid=105511">
17668#415277
17669@c HTML </a>
17670(make fails on MSDOS)
17671@item
17672Fix SourceForge bug
17673@c HTML <a href="http://sourceforge.net/tracker/index.php?func=detail&aid=415149&group_id=5511&atid=105511">
17674#415149
17675@c HTML </a>
17676(@code{file.cc} parse error on MSDOS)
17677@item
17678Fix SourceForge bug
17679@c HTML <a href="http://sourceforge.net/tracker/index.php?func=detail&aid=414520&group_id=5511&atid=105511">
17680#414520
17681@c HTML </a>
17682(@code{draw symbol ... at} should automatically produces axes unless the location is in @code{cm} coordinates)
17683@item
17684Fix SourceForge bug
17685@c HTML <a href="http://sourceforge.net/tracker/index.php?func=detail&aid=414010&group_id=5511&atid=105511">
17686#414010
17687@c HTML </a>
17688(items in the html concept index were in an odd order)
17689@item
17690Fix SourceForge bug
17691@c HTML <a href="http://sourceforge.net/tracker/index.php?func=detail&aid=413986&group_id=5511&atid=105511">
17692#413986
17693@c HTML </a>
17694(@code{~username} was broken in @code{open})
17695@item
17696Fix SourceForge bug
17697@c HTML <a href="http://sourceforge.net/tracker/index.php?func=detail&aid=411904&group_id=5511&atid=105511">
17698#411904
17699@c HTML </a>
17700(@code{/} was ugly in math mode)
17701@end itemize
17702
17703
17704@subsubsection Version 2.6.0 [2001 April 1]
17705@itemize @bullet
17706@item
17707Permit @code{rewind} to take a filename.
17708@item
17709Make @code{open} set @code{\.return_value.} to the full pathname of the
17710file that was opened.
17711@item
17712Add @code{set path} command (@ref{Set Path To}).
17713@item
17714Remove functioning of @code{GRIINPUTS} environment variable, since this
17715is more cleanly handled with the newly added @code{set path to} command
17716(@ref{Set Path To}).
17717@item
17718Remove @code{\.awk.} synonym, which was deemed to be unhelpful.  Users
17719with many scripts that use this variable might wish to put a line like
17720@example
17721\.awk. = "gawk"
17722@end example
17723in their @file{~/.grirc} file.
17724@item
17725Change the format of images in the PostScript output file, as a
17726workaround for a bug in the @code{ps2pdf} program.
17727@item
17728Add ``ampersand'' (@code{\&} and @code{\&&})
17729syntax to permit newcommands to
17730look up the name and nesting level of changeable arguments
17731(@ref{Changeable Command Arguments}).
17732@item
17733Add ``at-sign'' (@code{@@}) syntax for aliases
17734(@ref{Alias Synonyms}).
17735@item
17736Add ability to embed newlines in @code{show}
17737commands with the @code{\<<} sequence (@ref{Show}).
17738@item
17739Add ability to embed TAB characters in @code{show}
17740commands with the @code{\>>} sequence (@ref{Show}).
17741@item
17742Make various @code{read} commands (@ref{Read}) able to decode synonyms
17743as well as variables and simple numbers.
17744@item
17745Add @code{strlen} RPN operator (@ref{Unary Operators}).
17746@item
17747Add @code{default} option to @code{set x format} and
17748@code{set y format} commands.
17749@item
17750Add @code{new postscript file} (@ref{New Postscript File}) command.
17751@item
17752Switch email list from @code{majordomo} to GNU @code{mailman}.
17753@item
17754No longer remove comments from data lines that are read.  This served
17755little function, interfered with recent user code, and could be
17756accomplished by reading through a @code{sed} pipe in any case.
17757@item
17758Make the first element of the @code{argv} array be the name of
17759the command-file.  (This makes Gri consistent with languages such
17760as C.)
17761@item
17762Add chapter on test suite (@ref{Test Suite}).
17763@item
17764Let newcommands have changeable arguments (@ref{Changeable Command Arguments}).
17765@item
17766Remove @code{-s} as an abbreviation for the commandline option @code{-superuser}.
17767@item
17768Remove the @code{:} syntax from the commandline options.
17769@item
17770Add commandline option @code{-output PS_file_name}.
17771@item
17772Add @code{assert} command (@ref{Assert}).
17773@item
17774Add test suite (mainly for developers).
17775@item
17776Add @code{sleep} command (@ref{Sleep}).
17777@item
17778Remove command @code{show hint of the day}, since I no longer permission
17779to use cgi-bin to provide the hints via web-server.
17780@item
17781Permit indexing of synonym words with variables, in addition to
17782constants.
17783@item
17784Fix bug in interpolating synonyms in the test-expression of @code{while} loops.
17785@item
17786Put source on the
17787Source Forge open-source development website, at
17788@url{http://gri.sourceforge.net}.
17789Gri users can benefit from this site in may ways.  First, it is a great
17790way to keep track of new versions.  With a mouse-click you can cause
17791SourceForge to email you whenever a new version of Gri is released.
17792Second, SourceForge has
17793newsgroups
17794(@url{http://sourceforge.net/forum/?group_id=5511})
17795and email lists
17796(@url{http://sourceforge.net/mail/?group_id=5511})
17797devoted to Gri.  These are archived, so that you can stop monitoring
17798them for a while and then go back and see what you've missed.  Third,
17799Source Forge has a powerful
17800bug-tracking facility.
17801(@url{http://sourceforge.net/bugs/?group_id=5511})
17802With this you may check for existing bugs reported by users, submit new
17803bug reports, and also track the process of bug removal (e.g. optionally
17804receiving emails when the bug is removed).
17805@item
17806Add @code{set colorname} command (@ref{Set Colorname}).
17807@item
17808Add @code{source} command (@ref{Source}).
17809@item
17810Add RPN operators @code{wordc} (@ref{Solitary Operators}) and
17811@code{wordv} (@ref{Unary Operators}) for accessing the words in the
17812present Gri command.
17813@item
17814Add RPN operators @code{argc} (@ref{Solitary Operators}) and
17815@code{argv} (@ref{Unary Operators}) for accessing the command-line
17816arguments used when Gri was invoked from the operating system.
17817@item
17818Add automatic support for compressed data files.  So far, this only
17819works with gzipped files (@ref{Open}).
17820@item
17821Add two new RPN operators, @code{file_exists} and
17822@code{directory_exists} (@ref{Unary Operators}).
17823@item
17824Reorganize parts of manual (e.g.  changing the section about the Emacs
17825@file{gri-mode.el} into a chapter, with screen snapshots).
17826@item
17827Improve the HTML form of the manual (e.g. color-code the Gri syntax in
17828examples, provide access to all the indices, use Jpeg format, et.).
17829@item
17830Add several new features to @code{gri-mode.el}:
17831
178321) Add a menubar pull-down menu listing all Gri commands,
17833      allowing the user to get @code{Help} or @code{Info} on any command or
17834      @code{Insert} it in the current Gri file.
17835
178362) Add a menubar pull-down entry to @code{Perform} to set
17837      @code{gri-run} settings such as flag options passed to gri.
17838
178393) Gri info file can have @strong{.info} extension now.
17840
178414) Made @code{gri-apropos} an alias for @code{gri-help-apropos}.
17842
178435) gri-mode now uses the customize interface (See
17844      @code{gri-customize}).
17845
178466) The @code{~/.gri-syntax} file has changed format.  As a
17847      side-effect, spaces are used instead of hyphens to display Gri commands,
17848      and one can now select a command with the mouse in the
17849      @strong{Completions} buffer.
17850
17851@end itemize
17852
17853
17854
17855@c HTML <!-- newfile Version_2_4.html "Gri: Version 2.4" "Gri: Version 2.4" -->
17856@node   Version 2.4, Version 2.2, Version 2.6, Stable Stream
17857@comment  node-name,  next,  previous,  up
17858@subsection Version 2.4
17859
17860@subsubsection Version 2.4.4 [2000 May 7]
17861Change so that only a warning is printed if mathematical operations are
17862requested on empty arrays (e.g. @code{y += 10}).  Previously, an error
17863was reported and Gri exited with an error condition, which is bothersome
17864in scripts that rely on successful completion of the Gri job.
17865
17866Port to the BeOS operating system.
17867
17868@subsubsection Version 2.4.3 [2000 Apr 1]
17869Change location of all files, to be consistent with Redhat convention.
17870Previously, things were in @code{/opt/gri}; now they are in more
17871standard locations.
17872
17873@subsubsection Version 2.4.2 [2000 Mar 25]
17874Remove bug in which @code{convert grid to image} produced incorrect
17875images, visible as a patchy appearance with coarse grids.
17876
17877@subsubsection Version 2.4.1 [2000Jan 31]
17878Remove bug in which @code{convert image to grid} failed to take note of
17879the gri minimum and maximum, so that contouring of the grid was not
17880possible for grids created from images.
17881
17882@subsubsection Version 2.4.0 [2000 Jan 05]
17883Add @code{set input data separator}.  Make @code{read columns} work with
17884various input separators. Make @code{read .x.}, etc, work with various
17885input separators.
17886
17887
17888
17889@c HTML <!-- newfile Version_2_2.html "Gri: Version 2.2" "Gri: Version 2.2" -->
17890@node   Version 2.2, Unstable Stream, Version 2.4, Stable Stream
17891@comment  node-name,  next,  previous,  up
17892@subsection Version 2.2
17893
17894@subsubsection Version 2.2.6 [1999 Nov 25]
17895Make web-based manual easier to read by putting a light-grey background
17896under sample code.
17897
17898@subsubsection Version 2.2.5 [1999 Nov 10]
17899Fix bug in RPN calculations that prevented using a negative exponent.
17900
17901@subsubsection Version 2.2.4 [1999 Nov 7]
17902Add @code{set font encoding}, and also change the encoding to
17903ISO-Latin-1.  (This doesn't hurt old code since Gri didn't make any
17904claims to handle characters outside the normal printing-set before
17905anyway.)
17906
17907Fix bug in which there were 4 dead links in the HTML version of manual.
17908
17909Clean up some problems with Debian distribution (thanks, Peter Galbraith!).
17910
17911@subsubsection Version 2.2.3 [1999 Jun 30]
17912Fix bug in which word-of-synonym (e.g. @code{\[0]mysyn}) was not
17913detected correctly (thanks to bug report from Kazuhiko Nakayama in
17914Japan)
17915
17916@subsubsection Version 2.2.2 [-]
17917Clean a few spelling and cross-reference errors in documentation.
17918
17919@subsubsection Version 2.2.1 [1999 Mar 31]
17920For debian, properly locate the @code{netcdf} library, if it is
17921installed.
17922
17923Remove remnants of old commands for polar axes.
17924
17925Correct error in which the right-most and upper-most pixel of images
17926created by @code{convert grid to image} may be blank (or not, depending
17927on roundoff error) under certain conditions of exact matchup between
17928grid spacing and image spacing.
17929
17930Don't create PostScript file if the commandfile is non-existent, or if
17931there were errors on the commandline.
17932
17933@subsubsection Version 2.2.0 [1999 Mar 25]
17934First debian release.  Versions exist for intel, alpha, 68K and powerpc.
17935
17936
17937
17938@c HTML <!-- newfile UnstableStream.html "Gri: Unstable Stream" "Gri: History" -->
17939@node   Unstable Stream, Development Version, Version 2.2, History
17940@comment  node-name,  next,  previous,  up
17941@section Unstable Stream
17942
17943@menu
17944* Development Version::
17945* Plans::
17946@end menu
17947
17948
17949@c HTML <!-- newfile Development_Version.html "Gri: Development Version" "Gri: Development Version" -->
17950@node   Development Version, Plans, Unstable Stream, Unstable Stream
17951@comment  node-name,  next,  previous,  up
17952@subsection Development Version
17953
17954The list below shows changes that have been made in the development
17955version of Gri, i.e. the version on CVS at
17956@url{http://gri.sourceforge.net}.  Some or all of these features may
17957enter the next stable stream of Gri, but it is important to note that
17958@emph{anything} that's listed here may be changed without notice!  The
17959main exception is bug fixes, which will enter the stable stream unless
17960they are found to create new bugs.
17961
17962@subsubsection New Features
17963
17964@itemize @bullet
17965@item
17966n/a
17967@end itemize
17968
17969
17970@subsubsection Removed Features
17971
17972@itemize @bullet
17973@item
17974n/a
17975@end itemize
17976
17977
17978@subsubsection Bug Fixes
17979
17980@itemize @bullet
17981
17982@item
17983Fix SourceForge bug
17984@uref{http://sourceforge.net/tracker/index.php?func=detail&aid=618041&group_id=5511&atid=105511,#618041}
17985@dots{} solaris compile error, relating to the subroutine @code{gethostname()} in the @file{startup.cc} source code file.
17986
17987
17988@end itemize
17989
17990
17991
17992
17993@c HTML <!-- newfile Plans.html "Gri: plans for future versions" "Gri: plans for future versions" -->
17994
17995@node   Plans, Deprecated Commands, Development Version, Unstable Stream
17996@comment  node-name,  next,  previous,  up
17997@subsection Plans
17998@c FOR NEXT RELEASE:
17999@c 1) Fix bug in @code{read colorname} that caused it to try to
18000@c    interpret comments in the X11 color-name file as though
18001@c    they were actual colors.
18002@c
18003@c 2) Improve writing in the @code{read image} section of this manual.
18004@c
18005@c 3) Fix bugs in the HTML version of the manual, as reported
18006@c    by the 'tidy' checking programme.
18007
18008@cindex plans for future versions
18009@cindex command-line interface
18010@cindex image formats, other than 8-bit
18011
18012Some plans for future versions are given below.  A more extensive
18013list, together with target timescales and notes on the progress
18014towards completion, is available in the to-do list at the development
18015site (@url{http://gri.sourceforge.net}), which is also the place to go
18016if you have suggestions for other changes to Gri.
18017
18018@cindex endian file compatibility, plans
18019@cindex little-endian vs big-endian data, plans
18020@cindex big-endian vs little-endian data, plans
18021
18022@subsubsection High Priority
18023
18024@enumerate
18025
18026@item Add ability to generate SVG (scalable vector graphics) output.  This
18027file type can be edited with GUI-based tools, making it easy for users
18028to put the final touches on graphs "manually."  This feature will
18029require a great deal of work, mainly to do with grouping of graphical
18030elements, and so I'll need to rely on advice from users.
18031
18032@item Switch to @code{popt} library for the processing of command-line
18033options.  (Docs on this are at
18034@url{http://cvs.gnome.org/lxr/source/popt}.)
18035
18036@item Change @code{set axes style} from number-based selection to
18037word-based selection, and print a deprecation warning if the
18038number-based syntax is used.
18039
18040@item Switch from @code{tmpname} to @code{mkstemp} subroutine, for temporary filenames.
18041
18042@item Add readline support, to handle history, command-line editing, etc,
18043for interactive usage
18044(Docs on this are at
18045@url{http://cnswww.cns.cwru.edu/~chet/readline/readline.html}.)
18046
18047@end enumerate
18048
18049
18050@subsubsection Medium priority
18051
18052@enumerate
18053
18054@item Add optimal interpolation as another method for gridding
18055data (@ref{Convert Columns To Grid}).
18056
18057@item Add ability to read PNG images (@ref{Read Image})
18058(Docs on this are at @url{http://www.libpng.org/pub/png/}.)
18059
18060@end enumerate
18061
18062
18063@subsubsection Low priority
18064
18065@enumerate
18066
18067@item Add non-RPN mathematics.
18068
18069@item Add graphical output to the screen as commands are executed.
18070
18071@item Add support for both little-endian and big-endian binary data.
18072
18073@end enumerate
18074
18075
18076
18077@c HTML <!-- newfile DeprecatedCommands.html "Gri: Deprecated Commands" "Gri: History" -->
18078@node   Deprecated Commands, Installation, Plans, History
18079@comment  node-name,  next,  previous,  up
18080@section Deprecated Commands
18081@cindex deprecated commands
18082
18083@itemize @bullet
18084@item @emph{version 2.9.0}
18085@itemize @bullet
18086@item Replace @code{set y axis label horizontal} with @code{set y axis name horizontal}.
18087@item Replace @code{set y axis label vertical} with @code{set y axis name vertical}.
18088@end itemize
18089@end itemize
18090
18091
18092
18093@c HTML <!-- newfile Installation.html "Gri: installing Gri" "Installing Gri" -->
18094
18095@node   Installation, Unix-install, Deprecated Commands, Top
18096@comment  node-name,  next,  previous,  up
18097@chapter Installing Gri
18098
18099@menu
18100* Unix-install::
18101* Msdos-install::
18102* OS2-install::
18103* Mac-install::
18104* Beos-install::
18105@end menu
18106
18107@c HTML <!-- newfile Unix-install.html "Gri: installing Gri" "Installing Gri" -->
18108
18109@node   Unix-install, Archiving Old Versions, Installation, Installation
18110@comment  node-name,  next,  previous,  up
18111@section Unix Installation
18112@cindex directory structure of Gri installation
18113
18114@menu
18115* Archiving Old Versions::      Keeping the old and the new
18116* Linux::                       Installing on linux
18117* Precompiled Unix::            Installing precompiled versions
18118* Uncompiled Unix::             Compiling and installing
18119@end menu
18120
18121
18122@c HTML <!-- newfile Archiving.html "Gri: archiving old versions" "Gri: archiving old versions" -->
18123@node   Archiving Old Versions, Linux, Unix-install, Unix-install
18124@comment  node-name,  next,  previous,  up
18125@section Archiving Old Versions
18126
18127Gri, like other complex programs, sometimes changes in such a way as to
18128break old scripts.  This is less so of changes since about 1998 or so,
18129since the syntax became pretty firm about that time.
18130
18131Still, disk costs are so cheap that you would be well-advised to keep a
18132backup version of Gri, whenever you update.  This is pretty simple; you
18133need to keep a copy of the executable and the library file, and you need
18134to write a tiny shellscript that calls this particular executable with
18135this particular library file.  For example, you might do the following
18136
18137@example
18138mkdir -m 755 -p           /usr/local/share/gri/@value{GRI-VERSION}
18139cp /usr/bin/gri           /usr/local/share/gri/@value{GRI-VERSION}
18140cp /usr/share/gri/gri.cmd /usr/local/share/gri/@value{GRI-VERSION}
18141@end example
18142
18143@noindent
18144and then create a shellscript called
18145@file{/usr/local/bin/gri-@value{GRI-VERSION}} containing
18146
18147@example
18148#!/usr/bin/sh
18149/usr/local/share/gri/@value{GRI-VERSION}/gri \
18150    -directory /usr/local/share/gri/@value{GRI-VERSION} \
18151    "$@@"
18152@end example
18153
18154@noindent
18155to invoke this version of Gri.
18156
18157To be able to access this old version of gri from within the Emacs
18158gri-mode, you would reset the Emacs variable @code{gri*directory-tree}
18159like so in the file @file{~/.emacs}
18160(@ref{Step 2} in
18161@ref{Installing gri-mode.el})
18162
18163@example
18164(setq gri*directory-tree
18165    '("/usr/local/share/gri/" "/usr/share/gri/"))
18166@end example
18167
18168
18169
18170
18171@c HTML <!-- newfile linux-install.html "Gri: installing Gri" "Installing Gri" -->
18172
18173@node   Linux, Precompiled Unix, Archiving Old Versions, Unix-install
18174@comment  node-name,  next,  previous,  up
18175@subsection Installation on Linux computers
18176
18177@cindex linux distributions
18178@cindex debian
18179@cindex redhat
18180@cindex RPM version of installation package
18181@cindex installation, debian linux
18182@cindex installation, redhat linux
18183@cindex installation, linux redhat/debian
18184
18185Installation is easy on various flavors of linux.  Versions
18186are available from the official distributions and also at
18187@c HTML <A HREF="http://sourceforge.net/project/showfiles.php?group_id=5511">
18188@file{http://sourceforge.net/project/showfiles.php?group_id=5511}
18189@c HTML </A>
18190
18191The RedHat version supports intel platforms only, while the Debian
18192version supports intel, alpha, 68K and powerpc.  Installation follows
18193the normal method for these distributions ... if you have the
18194distribution, you surely know what to do.  If you don't, you may want to
18195switch when you see that you can install Gri by clicking an icon in a
18196window, or by typing, e.g. in RedHat linux:
18197
18198@example
18199rpm -i gri-@value{GRI-VERSION}
18200@end example
18201
18202Debian-linux installation may be done with any of several GUI-based
18203tools, or with the following system command:
18204
18205@example
18206dkpg -i gri_@value{GRI-VERSION}-1_i386.deb
18207@end example
18208
18209@noindent
18210or via a properly configured @code{apt} interface that will fetch the
18211latest version from the net:
18212
18213@example
18214apt-get install gri
18215@end example
18216
18217
18218@c HTML <!-- newfile precompiled-unix.html "Gri: installing Gri" "Installing Gri" -->
18219
18220@node   Precompiled Unix, Uncompiled Unix, Linux, Unix-install
18221@comment  node-name,  next,  previous,  up
18222@subsection Pre-compiled unix versions
18223Pre-compiled versions of Gri exist for various computers, e.g. SPARC
18224(both sunOS and solaris), IBM-RS, Sequent, and Linux.  The following
18225instructions, which assume a version number @value{GRI-VERSION}, and a
18226SPARC solaris machine, show how to install these.
18227
18228The compressed tar file, with a name like
18229@file{gri-binary-SunOS5-@value{GRI-VERSION}.tar.gz} (in this example a
18230Sun OS 5 binary is assumed, with gri version number @value{GRI-VERSION})
18231contains a directory which holds the executable Gri file, @file{gri},
18232the library file @file{gri.cmd}, an instructions file, @file{README},
18233and a Makefile to install Gri.
18234
18235Here's how to install Gri, starting with this tar file:
18236
18237@enumerate
18238@item
18239First, uncompress (unzip) the file, and un-tar it, by doing
18240
18241@example
18242gunzip -c gri-binary-SunOS5-@value{GRI-VERSION}.tar.gz | tar xvf -
18243@end example
18244
18245@noindent
18246or
18247
18248@example
18249zcat gri-binary-SunOS5-@value{GRI-VERSION}.tar.gz | tar xvf -
18250@end example
18251
18252@noindent
18253This will yield a new directory, with a name like
18254@file{gri-binary-SunOS5-@value{GRI-VERSION}}, which contains the
18255indicated files.
18256@item
18257Follow the instructions in the @file{README} file to install Gri.
18258@end enumerate
18259
18260
18261@c HTML <!-- newfile uncompiled-unix.html "Gri: installing Gri" "Installing Gri" -->
18262
18263@node   Uncompiled Unix, Msdos-install, Precompiled Unix, Unix-install
18264@comment  node-name,  next,  previous,  up
18265@section Compilation on Unix computers
18266The following steps indicate how to compile Gri on unix computers.  The
18267procedure is quite standard.
18268
18269@cindex configure script, how to use to compile gri
18270@cindex compiling gri
18271@cindex how to compile gri
18272
18273@table @emph
18274
18275@item Requirements
18276You'll need a C++ compiler that is modern enough to handle 'templates'
18277(i.e. almost any compiler from 1998 onward).  Don't worry -- if your
18278compiler isn't new enough, you'll see that in a minute or two!
18279
18280You'll need TeX and texinfo to make the info files, and optionally the
18281netCDF library (if you wish gri to be able to read netCDF binary data
18282files).  To make the HTML manual, you'll need imagemagick, info, gs and its
18283fonts.
18284
18285On Debian GNU/Linux systems, the required packages are listed as
18286Build-Depends in the @file{control} file found in the @file{debian}
18287directory, to which you must add the package @file{build-essential}.
18288
18289
18290@item Unpack the source
18291Type
18292
18293@example
18294gunzip gri-@value{GRI-VERSION}.tgz
18295tar xvf gri-@value{GRI-VERSION}.tar
18296@end example
18297
18298@noindent
18299(or similar commands) to uncompress and untar the contents.  This will
18300yield a new directory named @file{gri-@value{GRI-VERSION}} which
18301contains many files.
18302
18303
18304@item Move to the Gri directory
18305
18306@example
18307cd gri-@value{GRI-VERSION}
18308@end example
18309
18310
18311@item Configure your compiler
18312Next you must "configure" the Gri source files.  During this step, a
18313series of tests will be made about your operating system and your
18314compiler.  Most of these tests need no interaction from you, but there
18315is one overall choice that you may wish to make: the place on your
18316filesystem where Gri (and many associated library and documentation
18317files) will reside.  To get the default installation, with files
18318residing within the directory @file{/usr/local}, type
18319
18320@example
18321./configure
18322@end example
18323
18324@noindent
18325at this time.  If you'd rather the files go into another location, run
18326the @code{configure} script differently, e.g.  to get the Gri files to
18327reside within the @file{/opt} directory, type:
18328
18329@example
18330./configure --prefix=/opt
18331@end example
18332
18333@noindent
18334In response, you'll see the results of several tests of the properties
18335of your operating system, your C++ compiler, etc.  Normally you can
18336ignore these results.
18337
18338@cindex handling multiple gri versions
18339@cindex multiple gri versions
18340@cindex versions, handling multiple
18341
18342As an example, typing @code{./configure} without a @code{--prefix}
18343option yields the directory tree (@code{...} indicates several files not
18344displayed in this list, for brevity).  In this example,
18345the most up-to-date version is @value{GRI-VERSION}, but a previous
18346version @value{GRI-PREVIOUS-VERSION} has also been retained.  (Note that
18347only one copy of the documentation is retained; this is all that's
18348needed, since old versions are documented there as well as new
18349versions.)
18350
18351@example
18352/usr/local
18353|-- bin
18354|   |-- gri -> gri-@value{GRI-VERSION}
18355|   |-- gri-@value{GRI-VERSION}
18356|   |-- gri-@value{GRI-PREVIOUS-VERSION}
18357|   |-- gri_merge
18358|   `-- gri_unpage
18359|-- info
18360|   |-- ...
18361`-- share
18362    `-- gri
18363        |-- 2.6.0
18364        |   |-- gri.cmd
18365        |   |-- license.txt
18366        |   |-- logo.dat
18367        |   `-- startup.msg
18368        |-- 2.4.0
18369        |   |-- gri.cmd
18370        |   |-- license.txt
18371        |   |-- logo.dat
18372        |   `-- startup.msg
18373        `-- doc
18374            |-- examples
18375            |   |-- ...
18376            `-- html
18377                |-- ...
18378                |-- resources
18379                |   |-- ...
18380                `-- screenshots
18381                    |-- ...
18382@end example
18383
18384@b{Trouble-shooting 1}: If the permission of the @file{configure} file is
18385wrong, you'll get an error like @code{Permission denied}; if so, try
18386typing @code{sh ./configure} to run it in the Bourne shell.  If that
18387fails, you are going to have to do some old-fashioned work!  Start by
18388copying the generic Makefile called @file{Makefile.generic} into
18389@file{Makefile}, and try the following steps, perhaps editing the
18390@file{Makefile} if you run into errors.
18391
18392
18393@b{Trouble-shooting 2}: Gri uses a C++ feature called 'templates'.
18394Unfortunately, templates are handled in different ways by different
18395compilers.  At least as of Spring 1997, the GNU compiler, vsn 2.7.x
18396(used by many Gri folks) has problems with templates.  Therefore the
18397configure script will check to see if you are using the GNU c++
18398compiler, and if you are it will check whether the ("template
18399repository") compiler flag @code{-frepo} is known on your machine.  If
18400it is not, an alternative method of templates will be used.  But if it
18401is, you'll be asked, for confirmation, whether you wish to use the
18402@code{-frepo} flag.  On many machines (e.g. Solaris) you should answer
18403@code{n} to this question.  The prompt will explain.  Also, note that
18404you can avoid the prompt by running configure as either of the two
18405below:
18406
18407@example
18408./configure --enable-frepo
18409./configure --disable-frepo
18410@end example
18411
18412(Such switches will be ignored unless you're using the GNU compiler.)
18413
18414@b{Trouble-shooting 3}: If optional system libraries like the netCDF
18415library, if it exists, are installed in nonstandard places, you might
18416have to change the unix environment variable @code{LD_LIBRARY_PATH}.
18417For example, on my machine the @code{netcdf} library is not installed in
18418@file{/usr/lib}, as the @code{configure} script assumes, but rather in
18419@file{/usr/local/share/netcdf/lib}.  Therefore I have the following line
18420in one of my startup files:
18421
18422@example
18423export LD_LIBRARY_PATH=/usr/lib:/usr/local/share/netcdf/lib
18424@end example
18425
18426
18427@item Compiling Gri
18428Now compile Gri by typing
18429
18430@example
18431make
18432@end example
18433
18434
18435@item Testing Gri
18436@cindex test suite
18437Type
18438
18439@example
18440make check
18441@end example
18442
18443@noindent
18444to do some tests on the version of Gri that you just compiled.  If no
18445errors are reported, you may go to the next step.
18446
18447
18448@item Installing Gri
18449Assuming compilation succeeds, install @file{gri} and the ancillary file
18450@file{gri.cmd}, by typing
18451
18452@example
18453make install
18454@end example
18455
18456If you wish to see where files where be installed, first try a dry run
18457typing
18458
18459@example
18460make -n install
18461@end example
18462
18463
18464@item Cleaning up
18465Once these things are done, you may type
18466
18467@example
18468make clean
18469cd doc ; make clean
18470@end example
18471
18472@noindent
18473to clean up some files.  Of course, you could just erase the whole
18474source, but the source is probably worth a penny of hard-drive space,
18475isn't it?
18476@end table
18477
18478
18479
18480@c HTML <!-- newfile msdos-install.html "Gri: installing Gri" "Installing Gri" -->
18481
18482@node   Msdos-install,  OS2-install, Uncompiled Unix, Installation
18483@comment  node-name,  next,  previous,  up
18484@section Compilation on x86 (PC-style) Computers
18485
18486Versions exist for MSDOS, windows, and Linux operating systems.
18487(Actually, the windows version is just the MSDOS version, which can be
18488run inside an msdos window within windows-95, windows-NT, etc.)
18489
18490@subsection MSDOS Operating System
18491@cindex compilation under MSDOS
18492@cindex MSDOS compilation
18493
18494To compile and install Gri under MSDOS, do this:
18495@enumerate
18496@item
18497To begin, install @code{DJGPP V2}, if it is not on your system already.
18498It can be found at
18499@url{http://www.delorie.com/djgpp}
18500@item
18501Uncompress and extract from gri source package (@ref{Uncompiled Unix}).
18502@item
18503Type @code{make -f Makefile.dj2} to compile.  If it fails, you might
18504have to edit the file @file{Makefile.dj2} to match the characteristics
18505of your system.  Please inform the author,
18506@c HTML <A HREF="mailto:Dan.Kelley@Dal.CA">
18507Dan Kelley
18508@c HTML </A>
18509at Dan.Kelley@@Dal.CA, if you think your modifications might be useful
18510to others.
18511@item
18512Type @code{make -f Makefile.dj2 install} to install it (normally on the
18513@code{C:} drive).
18514@end enumerate
18515
18516If you encounter problems, read the first few lines of the Makefile
18517(i.e. the file @file{Makefile.dj2}) for hints on things to try.  For
18518example, in the present version of @file{Makefile.dj2} these hints are
18519given:
18520@enumerate
18521@item
18522There is a good chance that this Makefile will work as is, so try that
18523first.
18524@item
18525If you have the @file{netcdf} library (used for certain types of
18526atmospheric and oceanographic datasets), then un-comment and possibly
18527edit the appropriate @code{NETCDF_...} lines below, as instructed by the
18528comments preceding these lines.
18529@item
18530If you don't want Gri inserted in the directory @file{c:/gri}, edit the
18531@code{instdir = ...} line below.
18532@item
18533If you get error messages about the @file{stdcxx} library, edit the
18534@code{LIBS} line below, rewriting @file{-lstdcxx} as @file{-lstdcx}.
18535@item
18536If you get compilation errors relating to @code{time} or to
18537@code{ftime}, try putting the token @code{-DHAVE_FTIME=1} in the list of
18538similar token in the @code{DEFS = ...} line.  For consistency
18539(basically, so the author can help you if you do this), put it right
18540after the @code{-D_GRI_=1} token.
18541@end enumerate
18542
18543To view the output, use a PostScript viewer such as GSview.
18544
18545
18546
18547@subsection LINUX Operating System
18548@cindex compilation under Linux
18549@cindex linux compilation
18550@cindex LINUX compilation
18551Linux is a good emulation of unix, and it is free.  Gri for linux is
18552compiled and installed according to the normal unix instructions.
18553The compiled version is with a name like
18554@code{gri-binary-solaris-2.1.10.tar.gz}; treat it as in other unix
18555systems (@ref{Uncompiled Unix}).
18556
18557
18558
18559@c HTML <!-- newfile os2-install.html "Gri: installing Gri" "Installing Gri" -->
18560@node   OS2-install, Mac-install, Msdos-install, Installation
18561@comment  node-name,  next,  previous,  up
18562@section Compilation under OS/2
18563@cindex compilation under OS/2
18564@cindex OS/2 unix compilation
18565
18566Gri compiles, using the gcc compiler under OS/2, provided that the
18567included @code{Makefile.os2} is used.  Be sure to edit the first few
18568lines to change filenames as required, especially taking care to
18569account for whether the netCDF library is installed, etc.
18570
18571
18572
18573@c HTML <!-- newfile mac-install.html "Gri: installing Gri" "Installing Gri" -->
18574
18575@node   Mac-install, Beos-install, OS2-install, Installation
18576@comment  node-name,  next,  previous,  up
18577@section Compilation in Macintosh OS X
18578@cindex compilation in Macintosh OS X
18579@cindex macintosh unix compilation
18580@cindex darwinport
18581@cindex fink
18582
18583The OS X system provides a BSD unix that suites Gri very well. With the (free)
18584developer package, it also provides a very up-to-date version of the @code{gcc}
18585compiler. Thus, installing Gri on Macintosh can be done using the normal Unix
18586instructions.
18587
18588But there are also easier ways. Gri is compatible with Fink and Darwinports, the
18589two popular packaging systems on OS X. If you use OS X and do not have Fink or
18590Darwinports installed, then you should probably install one, or both. Each
18591distribution has strengths, and each has weaknesses, and it is difficult to
18592provide a firm recommendation between the two.
18593
18594@emph{Caveat.} As of mid-2007, neither distribution appears to handle package
18595dependencies as well as is done by popular linux distributions. For example, in
18596working through the steps listed below, the author found that his Darwinports
18597system had a problem with a system library that handles internationalization. The
18598"update" operation of the system was insufficient to solve the problem, and so it
18599was necessary to do some web searching to find a patch. The patch failed, but
18600another search revealed a second (hand-edit) patch that got it working. In excess
186014 CPU hours were required to rebuild the packages that were broken.
18602
18603If you'd like to build a local Darwinports version of Gri, to get the
18604latest version instead of whatever version is provided by Darwinports,
18605follow these steps:
18606
18607@itemize @bullet
18608
18609@item Download the source from CVS at SourceForge. (If you don't know what the previous
18610sentence means, you will quite likely have difficulties with the other steps.)
18611
18612@item Visit the @code{darwinports} directory of the newly-created directory tree, and type
18613@example
18614sudo port -d -v build
18615@end example
18616to build it. This will take several minutes, during which you
18617may find it helpful to do a search on "darwinport build". For example, the
18618O'Reilly page
18619(@url{http://www.oreillynet.com/pub/a/mac/2004/04/09/darwinports.html?page=3},
18620last checked in July 2007)
18621is very good.  Note that you will be
18622building from the source that is stored on SourceForge, not from the Darwinports
18623source. That's the trick of issuing the @code{build version} of the @code{port}
18624command.
18625
18626@item Do a "destroot" operation:
18627@example
18628sudo port -d -v destroot
18629@end example
18630
18631@item Install it:
18632@example
18633sudo port -d -v install
18634@end example
18635Note: if you already have an older version of Gri in the Darwinports system, you must first
18636issue the command
18637@example
18638sudo port deactivate gri
18639@end example
18640
18641@end itemize
18642
18643
18644@c HTML <!-- newfile Beos-install.html "Gri: bugs" "Gri Bugs" -->
18645
18646@node   Beos-install, Bugs, Mac-install, Installation
18647@comment  node-name,  next,  previous,  up
18648@section Compilation under BeOS
18649@cindex compilation under BeOS
18650@cindex BeOS unix compilation
18651
18652The BeOS system compiles Gri cleanly without modification; just follow
18653the instructions for unix.
18654
18655
18656@c HTML <!-- newfile Bugs.html "Gri: bugs" "Gri Bugs" -->
18657
18658@node   Bugs, Known Bugs, Beos-install, Top
18659@comment  node-name,  next,  previous,  up
18660@chapter Bugs
18661
18662@menu
18663* Known Bugs::                  Bugs in the current version
18664* Reporting Bugs::              How to report bugs
18665* Killing Bugs::                How to (try to) kill bugs
18666@end menu
18667
18668@c HTML <!-- newfile KnownBugs.html "Gri: bugs" "Gri Bugs" -->
18669
18670@node   Known Bugs, Reporting Bugs, Bugs, Bugs
18671@comment  node-name,  next,  previous,  up
18672@section Known bugs
18673@cindex bugs in Gri
18674
18675To get a list of known bugs, in the present or past versions, visit
18676@url{http://sourceforge.net/tracker/?atid=105511&group_id=5511&func=browse}.
18677
18678@c HTML <!-- newfile ReportingBugs.html "Gri: bugs" "Gri Bugs" -->
18679
18680@node   Reporting Bugs, Killing Bugs, Known Bugs, Bugs
18681@comment  node-name,  next,  previous,  up
18682@cindex bugs, how to report
18683@section Reporting Bugs
18684
18685Bug reports help make Gri more reliable and useful for all users, so
18686please report any bugs you find.  The scheme will be familiar to you, if
18687you've participated in open-source work before.
18688
18689@enumerate
18690
18691@item
18692Visit the bug-tracking part of the Source Forge Gri development site, at
18693@url{http://sourceforge.net/bugs/?group_id=5511}
18694to see whether your bug has already been reported.  You may find that it
18695has been reported and fixed already in a new version, in which case you
18696should archive your existing Gri version and upgrade.  If the bug has
18697been reported and @strong{not} fixed, then you may still wish to add a
18698supplemental bug report, so the author knows that this bug is of concern
18699to you as well as the others.  (Plus, reporting it this way ensures that
18700you'll receive an email when the bug is fixed.)
18701
18702@item
18703Debugging is made easier if the problem is reduced in scope.
18704Therefore, please reduce your application and your data to the
18705simplest case that produces the error.
18706
18707@item
18708@cindex bug, resulting in bus error
18709@cindex bug, resulting in segmentation fault
18710@cindex bus error, what to do
18711@cindex segmentation fault, what to do
18712@cindex debugger used with Gri
18713If you know how, please try to find the bug yourself.  After all, Gri
18714is open-source for a reason!  The procedure is described in the next
18715section (@ref{Killing Bugs}).
18716
18717@end enumerate
18718
18719
18720@c HTML <!-- newfile KillingBugs.html "Gri: bugs" "Gri Bugs" -->
18721
18722@node   Killing Bugs, Debugging Software You Will Need, Reporting Bugs, Bugs
18723@comment  node-name,  next,  previous,  up
18724@cindex bugs, how to kill them
18725@section Killing Bugs
18726@menu
18727* Debugging Software You Will Need::
18728* Debugging at a Glance::
18729* Debugging Example::
18730@end menu
18731
18732@node   Debugging Software You Will Need, Debugging at a Glance, Killing Bugs, Killing Bugs
18733@comment  node-name,  next,  previous,  up
18734@subsection Software that you'll need
18735This section is intended to help you find and kill bugs yourself, by
18736indicating how the author does this work.  Since Gri is open-source,
18737all users are invited to try to kill bugs themselves!
18738
18739If you know nothing of C or C++, you may as well not read further,
18740since there is little chance of your making progress.  On the other
18741hand, experienced programmers won't need any of the advice I give
18742below.
18743
18744You'll need the Gri source and a C++ compiler.  It also helps if you
18745have @code{gdb}, the GNU debugger, installed; the instructions below
18746assume that's the case.  Also, the instructions assume that you're
18747using the Emacs editor, and running @code{gdb} from within Emacs.
18748Otherwise, you'll want to glance at the documentation on @code{gdb} to
18749see how to use it in standalone mode.
18750
18751@node   Debugging at a Glance, Debugging Example, Debugging Software You Will Need, Killing Bugs
18752@comment  node-name,  next,  previous,  up
18753@cindex electric fence, for debugging
18754@subsection Debugging at a glance
18755The list below is a sketch of what you might try, and in what order.
18756
18757@itemize @bullet
18758
18759@item Check the bug list to see if other users have found your bug,
18760and also to see if there is a workaround.
18761
18762@item Try a more recent version of gri.  If it works, you might wish to
18763archive the version you have at the moment and upgrade.
18764
18765@item If you suspect your bug has something to do with system calls,
18766as in the @code{system} command (@ref{System}) or as in piped input
18767files (@ref{Open}), you should re-run the script with
18768@code{gri -superuser8} instead of with @code{gri}.  This will cause
18769Gri to print out all commands that it is handing over to the operating
18770system; you may see the error that way.  (Hint: it may help to
18771interactively cut/paste the commands into your OS shell to see what the
18772action of the command is.)
18773
18774@item If your bug results in early termination, you should run Gri
18775inside a debugger (e.g. GDB, assumed henceforth).  When the program
18776terminates, type @code{where} to see where termination occured.  Often
18777this will give a clue.  In many cases, early termination results from
18778faults in memory allocation.  To check memory allocation, you'll need to
18779recompile Gri, linking it against a debugging memory allocator.  Many
18780such tools exist; see comments in the @code{Makefile} for a hint at how
18781to use a popular one, called ``Electric Fence.''
18782
18783@item If your bug does not result in early termination, you may find
18784the best scheme is to trim your example down as much as possible, and
18785then run Gri inside the GDB (or other debugger) so that you can monitor
18786program execution.  The next section explains this in detail.
18787@end itemize
18788
18789
18790@node   Debugging Example, Test Suite, Debugging at a Glance, Killing Bugs
18791@comment  node-name,  next,  previous,  up
18792@subsection A debugging Example
18793Let's take a recent bug as an example.  Peter Galbraith found that the
18794gri script
18795
18796@example
18797set color hsb 0.999 1 1
18798draw box filled 2 2 3 3 cm
18799set color hsb 1.000 1 1
18800draw box filled 4 2 5 3 cm
18801@end example
18802
18803@noindent
18804produced odd results in a previous version of Gri; the color patches
18805should have been of nearly the same color, but the first one was red, as
18806expected, and the second was magenta.
18807
18808The list below shows how I found Peter's bug.  Experienced C or C++
18809programmers will find all of this very familiar, and will really only
18810need to read item 6 of the list below, since that's the only action that
18811is really specific to Gri.  (Note: for display purposes, I've broken
18812some of the lines in the files into two lines in this list.)
18813
18814@enumerate
18815
18816
18817@item Copy the above script (called @file{test.gri}) into the Gri source
18818directory, and the script into an Emacs buffer.  @b{Note:} all the
18819following steps are done within Emacs, and the items in parentheses are
18820the Emacs keys to get the indicated actions.
18821
18822
18823@item If you're working from a pre-compiled version, you'll need to get the
18824source first and do a compile yourself (@ref{Uncompiled Unix}).  Then do
18825a @code{make tags} command (type this to the unix shell) to create a
18826so-called "tag" table.
18827
18828
18829@item Run Gri in this emacs buffer (@kbd{C-cC-r}) noting from the
18830postscript window that pops up that the colors are, indeed, mixed up.
18831
18832
18833@item Load up the @code{gdb} debugger by typing @kbd{M-x gdb gri}.  This
18834will open a new Emacs buffer in which you may type commands.  We'll be
18835switching back and forth between this buffer and various source files.
18836
18837
18838@item Reasoning that the error probably occurs at @code{set color} or
18839@code{draw box}, try replacing the latter by a command such as
18840@code{draw label "hi" at 3 3 cm"}.  The color is still wrong, indicating
18841that it is the @code{set color} command that has the problem.
18842
18843
18844@item Next, we must find where the C++ code corresponding to the
18845@code{set color} command resides.  As it turns out, all @code{set}
18846commands are defined in the source file @code{set.cc}, and this command
18847is defined in a subroutine called @code{set_colorCmd()}.  But the author
18848knows this -- how would you?  The answer is to look in the
18849@file{gri.cmd} file, for the @code{set color} command.  (Search for the
18850string @code{`set color }.) Then read down to see the body of the
18851command, enclosed in braces; you'll see
18852
18853@example
18854@{
18855    extern "C" bool set_colorCmd(void);
18856@}
18857@end example
18858
18859@noindent
18860which indicates that the subroutine name is @code{set_colorCmd()}.
18861
18862
18863@item Next we need to edit this subroutine to see what it is doing.
18864There are several ways to find it (e.g. @code{grep} through the source
18865files), but the easiest is to use the "tags" feature of Emacs, by typing
18866@kbd{M-. set_colorCmd}.  This will bring you to the indicated
18867subroutine.
18868
18869
18870@item Have a look through this subroutine to see what it is doing.  It
18871looks very much like many other Gri subroutines.  A check is done on the
18872number of words provided to the command, in the
18873
18874@example
18875	switch (_nword) @{
18876@end example
18877
18878@noindent
18879line.  (That's line @file{set.cc:484} at the moment -- but it may be
18880different by the time you read this file, if I've changed it!)  We are
18881calling it with 6 words (@code{set color hsb 1.000 1 1}), so move down
18882to the line
18883
18884@example
18885	case 6:
18886@end example
18887
18888@noindent
18889and you'll see that there is an @code{if} statement seeing whether this
18890word is @code{rgb} or @code{hsv}.  These statements are checking
18891@code{_word[2]}, which is the third word of the command.  (In Gri, as in
18892C, words start at zero.  Thus, for this command, @code{_word[0]} is
18893@code{set}, @code{_word[1]} is @code{color}, and @code{_word[2]} is
18894expected to be either @code{rgb} or @code{hsb}.  We are having problems
18895with the @code{hsb} style, so we'll move down to that code.  The code
18896that's being executed is as follows.
18897
18898@example
18899@} else if (!strcmp(_word[2], "hsb")) @{
18900        // `set color hsb .hue. .saturation. .brightness.'
18901        double          hue, saturation, brightness;
18902        Require(getdnum(_word[3], &hue),
18903                READ_WORD_ERROR(".hue."));
18904        Require(getdnum(_word[4], &saturation),
18905                READ_WORD_ERROR(".saturation."));
18906        Require(getdnum(_word[5], &brightness),
18907                READ_WORD_ERROR(".brightness."));
18908        // Clip if necessary
18909        CHECK_HSB_RANGE(hue);
18910        CHECK_HSB_RANGE(saturation);
18911        CHECK_HSB_RANGE(brightness);
18912        gr_hsv2rgb(hue, saturation, brightness,
18913                &red, &green, &blue);
18914        PUT_VAR("..red..", red);
18915        PUT_VAR("..green..", green);
18916        PUT_VAR("..blue..", blue);
18917        c.setHSV(hue, saturation, brightness);
18918        _griState.set_color_line(c);
18919        if (_griState.separate_text_color() == false)
18920                _griState.set_color_text(c);
18921        return true;
18922@end example
18923
18924The @code{Require} lines are ensuring that we could decode the values of
18925the variables @code{hue}, etc, from the commandline.  Then we clip the
18926range of these values.  Then we convert from @code{hsb} color format to
18927@code{rgb} color format, save the values of the colors in Gri variables
18928with @code{PUT_VAR}, and then set the color with @code{c.setHSV}.
18929Finally we save this color in the Gri "state" with
18930@code{_griState.set_color_line(c)}.
18931
18932As it turns out, Gri outputs all colors to the PostScript file in RGB
18933format, so the we may well suspect that the problem is in the
18934@code{gr_hsv2rgb()} line.
18935
18936
18937@item We have an idea where to look now, so let's go to the line just after
18938it, in the editor, and insert a "breakpoint" there by typing
18939@kbd{C-x SPC}.  Then move to the @code{gdb} buffer and re-run Gri
18940by typing
18941
18942@example
18943run -directory . test.gri
18944@end example
18945
18946@noindent
18947to run Gri on our script.  Then, magic happens!  Gri stops at the
18948indicated breakpoint, and Emacs will display both the @code{gdb} buffer
18949and the @code{set.cc} buffer.  The latter has a margin indication
18950telling what line were are on.  You may now type @code{gdb} commands in
18951the @code{gdb} buffer.  In particular, type
18952
18953@example
18954p hue
18955@end example
18956
18957@noindent
18958to print the hue.  Then type
18959
18960@example
18961p red
18962@end example
18963
18964@noindent
18965to see the red value.  Then type
18966
18967@example
18968c
18969@end example
18970
18971@noindent
18972to continue running Gri.  It will pause again.  Check the hue and red
18973values again, as above.  If you like, play around with hue value in the
18974Gri script @file{test.gri} and run gri again (type @code{r} in
18975@code{gdb}).  This seems to indicate that the conversion is working
18976strangely.
18977
18978
18979@item To see how the conversion is done, clear the breakpoints by typing
18980@kbd{delete} in the @code{gdb} buffer, then insert a breakpoint
18981@strong{before} @code{gr_hsv2rgb} is called.  Then, run Gri again (@kbd{r}
18982in the @code{gdb} buffer).  When it stops just before this subroutine,
18983type @kbd{s} to "step into" the subroutine.  Then you'll see a
18984conversion code from the (wonderful) textbook of Foley and Van Dam.
18985You'll see
18986
18987@example
18988void
18989gr_hsv2rgb(double h, double s, double v,
18990           double *r, double *g, double *b)
18991@{
18992	h = 6.0 * pin0_1(h);
18993	s = pin0_1(s);
18994	v = pin0_1(v);
18995	int i = (int) floor(h);
18996	if (i > 5)
18997		i = 5; // Prevent problem if hue is exactly 1
18998	double f = h - i;
18999	double p = v * (1.0 - s);
19000        ...
19001@end example
19002
19003@noindent
19004in the present version of Gri, but in the previous (buggy) version, the
19005@code{if} statement was missing.  Without this @code{if} statement, Gri
19006produced wrong colors.  With the statement, the colors are correct.
19007@end enumerate
19008And so ends the example.  You may wish to read the Foley and Van Dam
19009textbook to see just what I'm doing in @code{gr_hsv2rgb}, but suffice it
19010to say that the problem in the (older) version of Gri was that @code{i}
19011could take the value 6 if the hue was exactly equal to 1, and that was
19012erroneous.
19013
19014In reading the code, you may notice that it is formatted in a uniform
19015way: the Kernighan and Ritchie scheme (from their classic C textbook),
19016with 8-character indents.  I get this by putting the following lines
19017in the @file{~/.emacs} file, which is used to customize the Emacs editor:
19018
19019@example
19020(defun my-c-mode-common-hook ()
19021  (c-set-style "K&R")
19022  (setq c-basic-offset 8)
19023  )
19024(add-hook 'c-mode-common-hook 'my-c-mode-common-hook)
19025@end example
19026
19027If you submit patches, please use the same format as I've done, so
19028that I can more easily see the changes you've made.
19029
19030
19031@c HTML <!-- newfile TestSuite.html "Gri: Test Suite" "Test Suite" -->
19032
19033@node   Test Suite, Gri in the Press, Debugging Example, Top
19034@comment  node-name,  next,  previous,  up
19035@chapter Test Suite
19036
19037@cindex test suite
19038@cindex suite of test files
19039
19040The following test files are invoked by typing @code{make test}, after
19041compiling Gri.  They are provided here because they are examples of
19042scripts that are @strong{known to work} for the version of Gri described
19043in this manual.
19044
19045Heavy use is made of the @code{assert} command (@ref{Assert}) in these
19046test files.  Thus the @strong{code itself} demonstrates the features,
19047instead of comments in the code.  This is advantageous since comments
19048tend to be incorrect!
19049
19050
19051
19052@c HTML <a href="tst_suite/tst_IO.html">Test file `<tt>tst_IO.gri</tt>'.</a><p>
19053@iftex
19054@sp 1
19055@noindent Test file @file{tst_IO.gri}:
19056
19057@cartouche
19058@include tst_suite/tst_IO.texi
19059@end cartouche
19060@end iftex
19061
19062@c HTML <a href="tst_suite/tst_control.html">Test file `<tt>tst_control.gri</tt>'.</a><p>
19063@iftex
19064@sp 1
19065@noindent Test file @file{tst_control.gri}:
19066
19067@cartouche
19068@include tst_suite/tst_control.texi
19069@end cartouche
19070@end iftex
19071
19072@c HTML <a href="tst_suite/tst_rpn.html">Test file `<tt>tst_rpn.gri</tt>'.</a><p>
19073@iftex
19074@sp 1
19075@noindent Test file @file{tst_rpn.gri}:
19076
19077@cartouche
19078@include tst_suite/tst_rpn.texi
19079@end cartouche
19080@end iftex
19081
19082
19083@c HTML <a href="tst_suite/tst_var_syn.html">Test file `<tt>tst_var_syn.gri</tt>'.</a><p>
19084@iftex
19085@sp 1
19086@noindent Test file @file{tst_var_syn.gri}:
19087
19088@cartouche
19089@include tst_suite/tst_var_syn.texi
19090@end cartouche
19091@end iftex
19092
19093
19094@c HTML <!-- newfile GriInThePress.html "Gri: in the Press" "Gri: in the Press" -->
19095
19096@node   Gri in the Press, Acknowledgments, Test Suite, Top
19097@comment  node-name,  next,  previous,  up
19098@chapter Gri in the Press
19099@cindex scientific journals with Gri graphs
19100
19101A gentle introduction to Gri is provided in a Linux Journal article, available at
19102@url{http://www2.linuxjournal.com/lj-issues/issue75/3743.html}
19103on the web.
19104
19105In March 2000, I emailed some Gri users to ask for the names of
19106scientific journals in which they have published Gri-produced graphs.
19107The list, which mainly arrived on Sunday in response to an email I
19108sent Saturday (don't Gri users take a break?) is presented below, to
19109indicate the range of Gri use in the press.
19110
19111@b{Journals in Oceanography, Atmospheric Science, Earth Science, etc.}
19112@itemize @bullet
19113
19114@item @strong{Bulletin on Coastal Oceanography} (in Japanese with English
19115abstract)
19116
19117@item @strong{Fisheries Oceanography}
19118
19119@item @strong{Deep-Sea Research}
19120
19121@item @strong{EOS, Transactions of the American Geophysical Union}
19122
19123@item @strong{Estuarine, Coastal and Shelf Science}
19124
19125@item @strong{Geophysical Research Letters}
19126
19127@item @strong{Journal of Atmospheric and Oceanic Technology}
19128
19129@item @strong{Journal of Geophysical Research}
19130
19131@item @strong{Journal of Marine Research}
19132
19133@item @strong{Journal of Plankton Research}
19134
19135@item @strong{Journal of Physical Oceanography}
19136
19137@item @strong{Journal of the Japan Scoiety for Marine Surveys and Technology}
19138(in Japanese with English abstract)
19139
19140@item @strong{Limnology and Oceanography}
19141
19142@item @strong{Marine Biology}
19143
19144@item @strong{Marine Ecology Progress Series}
19145
19146@item @strong{Monthly Weather Review}
19147
19148@item @strong{Oceanography}
19149
19150@item @strong{Paleoceanography}
19151
19152@item @strong{Progress in Oceanography}
19153
19154@item @strong{Quaternary Research}
19155
19156@item @strong{Scientia Marina}
19157
19158@item @strong{South African Journal of Marine Science}
19159
19160@item @strong{Umi no Kenkyu} (Japanese version for Journal of Oceanography, in
19161Japanese with English abstract)
19162@end itemize
19163
19164@b{Journals in Physics, Chemistry, etc.}
19165@itemize @bullet
19166
19167@item @strong{Applied Physics A}
19168
19169@item @strong{Journal of Fluid Mechanics}
19170
19171@item @strong{Journal of Physical Chemistry B}
19172
19173@item @strong{Physica D}
19174
19175@item @strong{Physics of Fluids}
19176
19177@item @strong{Physics A}
19178
19179@item @strong{Physics Letters B}
19180
19181@item @strong{Physical Review C}
19182
19183@item @strong{Physical Review Letters}
19184
19185@item @strong{Research on Chemical Intermediates}
19186
19187@item @strong{Theoretical Computational Fluid Dynamics}
19188@end itemize
19189
19190@b{Other Journals}
19191@itemize @bullet
19192
19193@item @strong{Nature}
19194@end itemize
19195
19196@b{Books, Monographs, etc.}
19197@itemize @bullet
19198
19199@item @strong{The Atlas of Hawai'i} (University of Hawai'i Press)
19200
19201@item @strong{Differential Equations with Applications to Biology} (American Mathematical Society)
19202
19203@item @strong{Ocean Drilling Program} publications
19204@end itemize
19205
19206
19207@c HTML <!-- newfile Acknowledgments.html "Gri: Acknowledgments" "Acknowledgments" -->
19208
19209@node   Acknowledgments, License, Gri in the Press, Top
19210@comment  node-name,  next,  previous,  up
19211@chapter Acknowledgments
19212@cindex user input to Gri
19213@cindex acknowledgments
19214
19215Over the years, many Gri users have been kind enough to help in its development. Some
19216have done so by sending in bug reports, others by requesting features, others by
19217submitting patches.  A few of their names are:
19218Ivo Alxneit,
19219@cindex contributor, Ivo Alxneit
19220@cindex Ivo Alxneit (contributor)
19221Karin Bryan,
19222@cindex Karin Bryan (contributor)
19223@cindex contributor, Karin Bryan
19224Sara Bennett,
19225@cindex Sara Bennett (contributor)
19226@cindex contributor, Sara Bennett
19227Luke Blaikie,
19228@cindex Luke Blaikie (contributor)
19229@cindex contributor, Luke Blaikie
19230Dave Brickman,
19231@cindex Dave Brickman (contributor)
19232@cindex contributor, Dave Brickman
19233Steve Cayford,
19234@cindex Steve Cayford (contributor)
19235@cindex contributor, Steve Cayford
19236Clyde Clements,
19237@cindex Clyde Clements (contributor)
19238@cindex contributor, Clyde Clements
19239Andrew Collier,
19240@cindex Andrew Collier (contributor)
19241@cindex contributor, Andrew Collier
19242Pierre Flament,
19243@cindex Pierre Flament (contributor)
19244@cindex contributor, Pierre Flament
19245Peter Galbraith,
19246@cindex Peter Galbraith (contributor)
19247@cindex contributor, Peter Galbraith
19248Dave Hebert,
19249@cindex Dave Hebert (contributor)
19250@cindex contributor, Dave Hebert
19251David A. Holland,
19252@cindex David A Holland (contributor)
19253@cindex contributor, David A. Holland
19254Christopher Illies,
19255@cindex Christopher Illies (contributor)
19256@cindex contributor, Christopher Illies
19257Cody Kirkpatrick,
19258@cindex Cody Kirkpatrick (contributor)
19259@cindex contributor, Cody Kirkpatrick
19260Thomas Larsen,
19261@cindex Thomas Larsen (contributor)
19262@cindex contributor, Thomas Larsen
19263Alejandro L�pez-Valencia,
19264@cindex Alejandro Lopez-Valencia (contributor)
19265@cindex contributor, Alejandro Lopez-Valencia
19266Kawamura Masao,
19267@cindex Kawamura Masao (contributor)
19268@cindex contributor, Kawamura Masao
19269Steve Matheson,
19270@cindex Steve Matheson (contributor)
19271@cindex contributor, Steve Matheson
19272Brian May,
19273@cindex Brian May, contributor
19274@cindex contributor, Brian May
19275Ed Nather,
19276@cindex Ed Nather (contributor)
19277@cindex contributor, Ed Nather
19278Roman Neuhauser,
19279@cindex Roman Neuhauser (contributor)
19280@cindex contributor, Roman Neuhauser
19281Carl Osterwisch,
19282@cindex Carl Osterwisch (contributor)
19283@cindex contributor, Carl Osterwisch
19284Richard Andrew Miles Outerbridge,
19285@cindex Richard Andrew Miles Outerbridge (contributor)
19286@cindex contributor, Richard Andrew Miles Outerbridge
19287Tim Powers,
19288@cindex Tim Powers (contributor)
19289@cindex contributor, Tim Powers
19290Jinyu Sheng,
19291@cindex Jinyu Sheng (contributor)
19292@cindex contributor, Jinyu Sheng
19293Toru Suzuki,
19294@cindex Toru Suzuki (contributor)
19295@cindex contributor, Toru Suzuki
19296Keith Thompson,
19297@cindex Keith Thompson (contributor)
19298@cindex contributor, Keith Thompson
19299David Trueman,
19300@cindex David Trueman (contributor)
19301@cindex contributor, David Trueman
19302Wolfgang Voegeli,
19303@cindex contributor and bug-fixer, Wolfgang Voegeli
19304@cindex Wolfgang Voegeli (contributor and bug fixer)
19305Jeff Whitaker,
19306@cindex Jeff Whitaker (contributor)
19307@cindex contributor, Jeff Whitaker
19308and George White.
19309@cindex George White (contributor)
19310@cindex contributor, George White
19311
19312Prime among these is Peter Galbraith, who has been a close collaborator in Gri
19313development and in my scientific work, for two (!) decades.
19314
19315To all, thanks.
19316
19317
19318@c HTML <!-- newfile License.html  "Gri: License" "License" -->
19319
19320@node   License, Concept Index, Acknowledgments, Top
19321@comment  node-name,  next,  previous,  up
19322@chapter License
19323@cindex license
19324Gri is distributed under the GPL public license, an Open Source license
19325that provides certain rights and freedom to users, notably the access
19326to source code and the right to modify it and/or redistribute it.
19327The full text of the GPL license is given below.
19328
19329@example
19330		    GNU GENERAL PUBLIC LICENSE
19331		       Version 2, June 1991
19332
19333 Copyright (C) 1989, 1991 Free Software
19334     Foundation, Inc.  59 Temple Place, Suite
19335     330, Boston, MA 02111-1307 USA
19336
19337 Everyone is permitted to copy and distribute
19338 verbatim copies of this license document, but
19339 changing it is not allowed.
19340
19341			    Preamble
19342
19343  The licenses for most software are designed to
19344take away your freedom to share and change it.
19345By contrast, the GNU General Public License is
19346intended to guarantee your freedom to share and
19347change free software--to make sure the software
19348is free for all its users.  This General Public
19349License applies to most of the Free Software
19350Foundation's software and to any other program
19351whose authors commit to using it.  (Some other
19352Free Software Foundation software is covered by
19353the GNU Library General Public License instead.)
19354You can apply it to your programs, too.
19355
19356  When we speak of free software, we are
19357referring to freedom, not price.  Our General
19358Public Licenses are designed to make sure that
19359you have the freedom to distribute copies of free
19360software (and charge for this service if you
19361wish), that you receive source code or can get it
19362if you want it, that you can change the software
19363or use pieces of it in new free programs; and
19364that you know you can do these things.
19365
19366  To protect your rights, we need to make
19367restrictions that forbid anyone to deny you these
19368rights or to ask you to surrender the rights.
19369These restrictions translate to certain
19370responsibilities for you if you distribute copies
19371of the software, or if you modify it.
19372
19373  For example, if you distribute copies of such a
19374program, whether gratis or for a fee, you must
19375give the recipients all the rights that you have.
19376You must make sure that they, too, receive or can
19377get the source code.  And you must show them
19378these terms so they know their rights.
19379
19380  We protect your rights with two steps: (1)
19381copyright the software, and (2) offer you this
19382license which gives you legal permission to copy,
19383distribute and/or modify the software.
19384
19385  Also, for each author's protection and ours, we
19386want to make certain that everyone understands
19387that there is no warranty for this free software.
19388If the software is modified by someone else and
19389passed on, we want its recipients to know that
19390what they have is not the original, so that any
19391problems introduced by others will not reflect on
19392the original authors' reputations.
19393
19394  Finally, any free program is threatened
19395constantly by software patents.  We wish to avoid
19396the danger that redistributors of a free program
19397will individually obtain patent licenses, in
19398effect making the program proprietary.  To
19399prevent this, we have made it clear that any
19400patent must be licensed for everyone's free use
19401or not licensed at all.
19402
19403  The precise terms and conditions for copying,
19404distribution and modification follow.
19405
19406		    GNU GENERAL PUBLIC LICENSE
19407
19408   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION
19409   AND MODIFICATION
19410
19411  0. This License applies to any program or other
19412work which contains a notice placed by the
19413copyright holder saying it may be distributed
19414under the terms of this General Public License.
19415The "Program", below, refers to any such program
19416or work, and a "work based on the Program" means
19417either the Program or any derivative work under
19418copyright law: that is to say, a work containing
19419the Program or a portion of it, either verbatim
19420or with modifications and/or translated into
19421another language.  (Hereinafter, translation is
19422included without limitation in the term
19423"modification".)  Each licensee is addressed as
19424"you".
19425
19426Activities other than copying, distribution and
19427modification are not covered by this License;
19428they are outside its scope.  The act of running
19429the Program is not restricted, and the output
19430from the Program is covered only if its contents
19431constitute a work based on the Program
19432(independent of having been made by running the
19433Program).  Whether that is true depends on what
19434the Program does.
19435
19436  1. You may copy and distribute verbatim copies
19437of the Program's source code as you receive it,
19438in any medium, provided that you conspicuously
19439and appropriately publish on each copy an
19440appropriate copyright notice and disclaimer of
19441warranty; keep intact all the notices that refer
19442to this License and to the absence of any
19443warranty; and give any other recipients of the
19444Program a copy of this License along with the
19445Program.
19446
19447You may charge a fee for the physical act of
19448transferring a copy, and you may at your option
19449offer warranty protection in exchange for a fee.
19450
19451  2. You may modify your copy or copies of the
19452Program or any portion of it, thus forming a work
19453based on the Program, and copy and distribute
19454such modifications or work under the terms of
19455Section 1 above, provided that you also meet all
19456of these conditions:
19457
19458    a) You must cause the modified files to carry
19459    prominent notices stating that you changed
19460    the files and the date of any change.
19461
19462    b) You must cause any work that you
19463    distribute or publish, that in whole or in
19464    part contains or is derived from the Program
19465    or any part thereof, to be licensed as a
19466    whole at no charge to all third parties under
19467    the terms of this License.
19468
19469    c) If the modified program normally reads
19470    commands interactively when run, you must
19471    cause it, when started running for such
19472    interactive use in the most ordinary way, to
19473    print or display an announcement including an
19474    appropriate copyright notice and a notice
19475    that there is no warranty (or else, saying
19476    that you provide a warranty) and that users
19477    may redistribute the program under these
19478    conditions, and telling the user how to view
19479    a copy of this License.  (Exception: if the
19480    Program itself is interactive but does not
19481    normally print such an announcement, your
19482    work based on the Program is not required to
19483    print an announcement.)
19484
19485These requirements apply to the modified work as
19486a whole.  If identifiable sections of that work
19487are not derived from the Program, and can be
19488reasonably considered independent and separate
19489works in themselves, then this License, and its
19490terms, do not apply to those sections when you
19491distribute them as separate works.  But when you
19492distribute the same sections as part of a whole
19493which is a work based on the Program, the
19494distribution of the whole must be on the terms of
19495this License, whose permissions for other
19496licensees extend to the entire whole, and thus to
19497each and every part regardless of who wrote it.
19498
19499Thus, it is not the intent of this section to
19500claim rights or contest your rights to work
19501written entirely by you; rather, the intent is to
19502exercise the right to control the distribution of
19503derivative or collective works based on the
19504Program.
19505
19506In addition, mere aggregation of another work not
19507based on the Program with the Program (or with a
19508work based on the Program) on a volume of a
19509storage or distribution medium does not bring the
19510other work under the scope of this License.
19511
19512  3. You may copy and distribute the Program (or
19513a work based on it, under Section 2) in object
19514code or executable form under the terms of
19515Sections 1 and 2 above provided that you also do
19516one of the following:
19517
19518    a) Accompany it with the complete
19519    corresponding machine-readable source code,
19520    which must be distributed under the terms of
19521    Sections 1 and 2 above on a medium
19522    customarily used for software interchange;
19523    or,
19524
19525    b) Accompany it with a written offer, valid
19526    for at least three years, to give any third
19527    party, for a charge no more than your cost of
19528    physically performing source distribution, a
19529    complete machine-readable copy of the
19530    corresponding source code, to be distributed
19531    under the terms of Sections 1 and 2 above on
19532    a medium customarily used for software
19533    interchange; or,
19534
19535    c) Accompany it with the information you
19536    received as to the offer to distribute
19537    corresponding source code.  (This alternative
19538    is allowed only for noncommercial
19539    distribution and only if you received the
19540    program in object code or executable form
19541    with such an offer, in accord with Subsection
19542    b above.)
19543
19544The source code for a work means the preferred
19545form of the work for making modifications to it.
19546For an executable work, complete source code
19547means all the source code for all modules it
19548contains, plus any associated interface
19549definition files, plus the scripts used to
19550control compilation and installation of the
19551executable.  However, as a special exception, the
19552source code distributed need not include anything
19553that is normally distributed (in either source or
19554binary form) with the major components (compiler,
19555kernel, and so on) of the operating system on
19556which the executable runs, unless that component
19557itself accompanies the executable.
19558
19559If distribution of executable or object code is
19560made by offering access to copy from a designated
19561place, then offering equivalent access to copy
19562the source code from the same place counts as
19563distribution of the source code, even though
19564third parties are not compelled to copy the
19565source along with the object code.
19566
19567  4. You may not copy, modify, sublicense, or
19568distribute the Program except as expressly
19569provided under this License.  Any attempt
19570otherwise to copy, modify, sublicense or
19571distribute the Program is void, and will
19572automatically terminate your rights under this
19573License.  However, parties who have received
19574copies, or rights, from you under this License
19575will not have their licenses terminated so long
19576as such parties remain in full compliance.
19577
19578  5. You are not required to accept this License,
19579since you have not signed it.  However, nothing
19580else grants you permission to modify or
19581distribute the Program or its derivative works.
19582These actions are prohibited by law if you do not
19583accept this License.  Therefore, by modifying or
19584distributing the Program (or any work based on
19585the Program), you indicate your acceptance of
19586this License to do so, and all its terms and
19587conditions for copying, distributing or modifying
19588the Program or works based on it.
19589
19590  6. Each time you redistribute the Program (or
19591any work based on the Program), the recipient
19592automatically receives a license from the
19593original licensor to copy, distribute or modify
19594the Program subject to these terms and
19595conditions.  You may not impose any further
19596restrictions on the recipients' exercise of the
19597rights granted herein.  You are not responsible
19598for enforcing compliance by third parties to this
19599License.
19600
19601  7. If, as a consequence of a court judgment or
19602allegation of patent infringement or for any
19603other reason (not limited to patent issues),
19604conditions are imposed on you (whether by court
19605order, agreement or otherwise) that contradict
19606the conditions of this License, they do not
19607excuse you from the conditions of this License.
19608If you cannot distribute so as to satisfy
19609simultaneously your obligations under this
19610License and any other pertinent obligations, then
19611as a consequence you may not distribute the
19612Program at all.  For example, if a patent license
19613would not permit royalty-free redistribution of
19614the Program by all those who receive copies
19615directly or indirectly through you, then the only
19616way you could satisfy both it and this License
19617would be to refrain entirely from distribution of
19618the Program.
19619
19620If any portion of this section is held invalid or
19621unenforceable under any particular circumstance,
19622the balance of the section is intended to apply
19623and the section as a whole is intended to apply
19624in other circumstances.
19625
19626It is not the purpose of this section to induce
19627you to infringe any patents or other property
19628right claims or to contest validity of any such
19629claims; this section has the sole purpose of
19630protecting the integrity of the free software
19631distribution system, which is implemented by
19632public license practices.  Many people have made
19633generous contributions to the wide range of
19634software distributed through that system in
19635reliance on consistent application of that
19636system; it is up to the author/donor to decide if
19637he or she is willing to distribute software
19638through any other system and a licensee cannot
19639impose that choice.
19640
19641This section is intended to make thoroughly clear
19642what is believed to be a consequence of the rest
19643of this License.
19644
19645  8. If the distribution and/or use of the
19646Program is restricted in certain countries either
19647by patents or by copyrighted interfaces, the
19648original copyright holder who places the Program
19649under this License may add an explicit
19650geographical distribution limitation excluding
19651those countries, so that distribution is
19652permitted only in or among countries not thus
19653excluded.  In such case, this License
19654incorporates the limitation as if written in the
19655body of this License.
19656
19657  9. The Free Software Foundation may publish
19658revised and/or new versions of the General Public
19659License from time to time.  Such new versions
19660will be similar in spirit to the present version,
19661but may differ in detail to address new problems
19662or concerns.
19663
19664Each version is given a distinguishing version
19665number.  If the Program specifies a version
19666number of this License which applies to it and
19667"any later version", you have the option of
19668following the terms and conditions either of that
19669version or of any later version published by the
19670Free Software Foundation.  If the Program does
19671not specify a version number of this License, you
19672may choose any version ever published by the Free
19673Software Foundation.
19674
19675  10. If you wish to incorporate parts of the
19676Program into other free programs whose
19677distribution conditions are different, write to
19678the author to ask for permission.  For software
19679which is copyrighted by the Free Software
19680Foundation, write to the Free Software
19681Foundation; we sometimes make exceptions for
19682this.  Our decision will be guided by the two
19683goals of preserving the free status of all
19684derivatives of our free software and of promoting
19685the sharing and reuse of software generally.
19686
19687			    NO WARRANTY
19688
19689  11. BECAUSE THE PROGRAM IS LICENSED FREE OF
19690CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO
19691THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT
19692WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
19693HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM
19694"AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
19695EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED
19696TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
19697FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE
19698RISK AS TO THE QUALITY AND PERFORMANCE OF THE
19699PROGRAM IS WITH YOU.  SHOULD THE PROGRAM PROVE
19700DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY
19701SERVICING, REPAIR OR CORRECTION.
19702
19703  12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE
19704LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT
19705HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
19706REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE
19707LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL,
19708SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES
19709ARISING OUT OF THE USE OR INABILITY TO USE THE
19710PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
19711DATA OR DATA BEING RENDERED INACCURATE OR LOSSES
19712SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF
19713THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
19714EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN
19715ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
19716
19717		     END OF TERMS AND CONDITIONS
19718
19719	    How to Apply These Terms to Your New
19720	    Programs
19721
19722  If you develop a new program, and you want it
19723to be of the greatest possible use to the public,
19724the best way to achieve this is to make it free
19725software which everyone can redistribute and
19726change under these terms.
19727
19728  To do so, attach the following notices to the
19729program.  It is safest to attach them to the
19730start of each source file to most effectively
19731convey the exclusion of warranty; and each file
19732should have at least the "copyright" line and a
19733pointer to where the full notice is found.
19734
19735    <one line to give the program's name and a
19736    brief idea of what it does.> Copyright (C)
19737    yyyy <name of author>
19738
19739    This program is free software; you can
19740    redistribute it and/or modify it under the
19741    terms of the GNU General Public License as
19742    published by the Free Software Foundation;
19743    either version 2 of the License, or (at your
19744    option) any later version.
19745
19746    This program is distributed in the hope that
19747    it will be useful, but WITHOUT ANY WARRANTY;
19748    without even the implied warranty of
19749    MERCHANTABILITY or FITNESS FOR A PARTICULAR
19750    PURPOSE.  See the GNU General Public License
19751    for more details.
19752
19753    You should have received a copy of the GNU
19754    General Public License along with this
19755    program; if not, write to the Free Software
19756    Foundation, Inc., 59 Temple Place, Suite 330,
19757    Boston, MA 02111-1307 USA
19758
19759
19760Also add information on how to contact you by
19761electronic and paper mail.
19762
19763If the program is interactive, make it output a
19764short notice like this when it starts in an
19765interactive mode:
19766
19767    Gnomovision version 69, Copyright (C) yyyy
19768    name of author Gnomovision comes with
19769    ABSOLUTELY NO WARRANTY; for details type
19770    `show w'.  This is free software, and you are
19771    welcome to redistribute it under certain
19772    conditions; type `show c' for details.
19773
19774The hypothetical commands `show w' and `show c'
19775should show the appropriate parts of the General
19776Public License.  Of course, the commands you use
19777may be called something other than `show w' and
19778`show c'; they could even be mouse-clicks or menu
19779items--whatever suits your program.
19780
19781You should also get your employer (if you work as
19782a programmer) or your school, if any, to sign a
19783"copyright disclaimer" for the program, if
19784necessary.  Here is a sample; alter the names:
19785
19786  Yoyodyne, Inc., hereby disclaims all copyright
19787  interest in the program `Gnomovision' (which
19788  makes passes at compilers) written by James
19789  Hacker.
19790
19791  <signature of Ty Coon>, 1 April 1989
19792  Ty Coon, President of Vice
19793
19794This General Public License does not permit
19795incorporating your program into proprietary
19796programs.  If your program is a subroutine
19797library, you may consider it more useful to
19798permit linking proprietary applications with the
19799library.  If this is what you want to do, use the
19800GNU Library General Public License instead of
19801this License.
19802@end example
19803
19804
19805
19806
19807@c HTML <!--
19808
19809@node   Concept Index, Index of Commands, License, Top
19810@comment node-name, next, previous, up
19811@unnumbered Index, general
19812@printindex cp
19813
19814@node   Index of Commands, Index of Builtins, Concept Index, Top
19815@comment node-name, next, previous, up
19816@unnumbered Index of Commands
19817@printindex fn
19818
19819@node   Index of Builtins, , Index of Commands, Top
19820@comment  node-name,  next,  previous,  up
19821@unnumbered Index of Built-in Variables and Synonyms
19822@printindex vr
19823
19824@c HTML -->
19825
19826@c @summarycontents
19827@c @contents
19828@bye
19829