Pgplot Manual
Pgplot Manual
T. J. Pearson
June 1989
1 INTRODUCTION . . . . . . . . . . . . . . . . . . . . . . 1-1
PGPLOT . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-1
This Manual . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-1
Using PGPLOT . . . . . . . . . . . . . . . . . . . . . . . . . 1-2
Graphics Devices . . . . . . . . . . . . . . . . . . . . . . . . . 1-3
Environment variables . . . . . . . . . . . . . . . . . . . . . . 1-4
2 SIMPLE USE OF PGPLOT . . . . . . . . . . . . . . . . . . 2-1
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-1
An Example . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-1
Data Initialization . . . . . . . . . . . . . . . . . . . . . . . . 2-2
Starting PGPLOT . . . . . . . . . . . . . . . . . . . . . . . . 2-3
Dening Plot Scales and Drawing Axes . . . . . . . . . . . . . . . 2-4
Labeling the Axes . . . . . . . . . . . . . . . . . . . . . . . . 2-4
Drawing Graph Markers . . . . . . . . . . . . . . . . . . . . . 2-5
Drawing Lines . . . . . . . . . . . . . . . . . . . . . . . . . . 2-5
Ending the Plot . . . . . . . . . . . . . . . . . . . . . . . . . 2-5
Compiling and running the program . . . . . . . . . . . . . . . . 2-6
3 WINDOWS AND VIEWPORTS . . . . . . . . . . . . . . . 3-1
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-1
Selecting a View Surface . . . . . . . . . . . . . . . . . . . . . 3-2
Dening the Viewport . . . . . . . . . . . . . . . . . . . . . . 3-3
Dening the Window . . . . . . . . . . . . . . . . . . . . . . . 3-4
Annotating the Viewport . . . . . . . . . . . . . . . . . . . . . 3-4
Routine PGENV . . . . . . . . . . . . . . . . . . . . . . . . . 3-5
4 PRIMITIVES . . . . . . . . . . . . . . . . . . . . . . . . . 4-1
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-1
Clipping . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-1
Lines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-2
Graph Markers . . . . . . . . . . . . . . . . . . . . . . . . . . 4-2
Text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-4
Area Fill . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-6
5 ATTRIBUTES . . . . . . . . . . . . . . . . . . . . . . . . 5-1
iii
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-1
Color Index . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-1
Color Representation . . . . . . . . . . . . . . . . . . . . . . . 5-2
Line Style . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-3
Line Width . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-3
Character Height . . . . . . . . . . . . . . . . . . . . . . . . . 5-4
Character Font . . . . . . . . . . . . . . . . . . . . . . . . . . 5-4
Fill-Area Style . . . . . . . . . . . . . . . . . . . . . . . . . . 5-4
6 HIGHER-LEVEL ROUTINES . . . . . . . . . . . . . . . . 6-1
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-1
XY-plots . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-1
Histograms . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-3
Functions of two variables . . . . . . . . . . . . . . . . . . . . . 6-3
7 INTERACTIVE GRAPHICS . . . . . . . . . . . . . . . . . 7-1
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-1
The Cursor . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-1
Using the Cursor . . . . . . . . . . . . . . . . . . . . . . . . . 7-1
Buering . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-2
8 METAFILES . . . . . . . . . . . . . . . . . . . . . . . . . 8-1
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-1
Creating Metales . . . . . . . . . . . . . . . . . . . . . . . . 8-1
Translating Metales . . . . . . . . . . . . . . . . . . . . . . . 8-2
A SUBROUTINE DESCRIPTIONS . . . . . . . . . . . . . . A-1
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . A-1
Arguments . . . . . . . . . . . . . . . . . . . . . . . . . . . A-1
Classied List . . . . . . . . . . . . . . . . . . . . . . . . . . A-1
Subroutine Synopses . . . . . . . . . . . . . . . . . . . . . . . A-4
PGADVANCE { non-standard alias for PGPAGE . . . . . . . . . . . A-5
PGASK { control new page prompting . . . . . . . . . . . . . . . A-5
PGBBUF { begin batch of output (buer) . . . . . . . . . . . . . . A-5
PGBEG { begin PGPLOT, open output device . . . . . . . . . . . . A-6
PGBEGIN { non-standard alias for PGBEG . . . . . . . . . . . . . A-6
PGBIN { histogram of binned data . . . . . . . . . . . . . . . . . A-7
PGBOX { draw labeled frame around viewport . . . . . . . . . . . . A-8
PGCONB { contour map of a 2D data array, with blanking . . . . . . A-9
PGCONS { contour map of a 2D data array (fast algorithm) . . . . . . A-10
iv
PGCONT { contour map of a 2D data array (contour-following) . . . . A-11
PGCONX { contour map of a 2D data array (non-rectangular) . . . . . A-12
PGCURS { read cursor position . . . . . . . . . . . . . . . . . . A-13
PGCURSE { non-standard alias for PGCURS . . . . . . . . . . . . A-13
PGDRAW { draw a line from the current pen position to a point . . . . A-13
PGEBUF { end batch of output (buer) . . . . . . . . . . . . . . . A-14
PGEND { terminate PGPLOT . . . . . . . . . . . . . . . . . . . A-14
PGENV { set window and viewport and draw labeled frame . . . . . . A-15
PGERRB { horizontal error bar . . . . . . . . . . . . . . . . . . A-16
PGERRX { horizontal error bar . . . . . . . . . . . . . . . . . . A-16
PGERRY { vertical error bar . . . . . . . . . . . . . . . . . . . . A-17
PGETXT { erase text from graphics display . . . . . . . . . . . . . A-17
PGFUNT { function dened by X = F(T), Y = G(T) . . . . . . . . . A-18
PGFUNX { function dened by Y = F(X) . . . . . . . . . . . . . . A-18
PGFUNY { function dened by X = F(Y) . . . . . . . . . . . . . . A-19
PGGRAY { gray-scale map of a 2D data array . . . . . . . . . . . . A-20
PGHI2D { cross-sections through a 2D data array . . . . . . . . . . . A-21
PGHIST { histogram of unbinned data . . . . . . . . . . . . . . . A-22
PGIDEN { write username, date, and time at bottom of plot . . . . . . A-22
PGLAB { write labels for x-axis, y-axis, and top of plot . . . . . . . . A-22
PGLABEL { non-standard alias for PGLAB . . . . . . . . . . . . . A-23
PGLCUR { draw a line using the cursor . . . . . . . . . . . . . . . A-23
PGLDEV { list available device types . . . . . . . . . . . . . . . . A-23
PGLEN { Find length of a string in a variety of units . . . . . . . . . A-24
PGLINE { draw a polyline (curve dened by line-segments) . . . . . . A-24
PGMOVE { move pen (change current pen position) . . . . . . . . . A-24
PGMTEXT { non-standard alias for PGMTXT . . . . . . . . . . . . A-25
PGMTXT { write text at position relative to viewport . . . . . . . . A-25
PGNCUR { mark a set of points using the cursor . . . . . . . . . . . A-26
PGNCURSE { non-standard alias for PGNCUR . . . . . . . . . . . A-26
PGNUMB { convert a number into a plottable character string . . . . . A-27
PGOLIN { mark a set of points using the cursor . . . . . . . . . . . A-28
PGPAGE { advance to new page . . . . . . . . . . . . . . . . . . A-28
PGPAP { change the size of the view surface ("paper size") . . . . . . A-29
PGPAPER { non-standard alias for PGPAP . . . . . . . . . . . . . A-29
PGPIXL { draw pixels . . . . . . . . . . . . . . . . . . . . . . A-30
PGPNTS { draw one or more graph markers . . . . . . . . . . . . . A-31
PGPOINT { non-standard alias for PGPT . . . . . . . . . . . . . . A-31
PGPOLY { ll a polygonal area with shading . . . . . . . . . . . . A-32
v
PGPT { draw one or more graph markers . . . . . . . . . . . . . . A-33
PGPTEXT { non-standard alias for PGPTXT . . . . . . . . . . . . A-33
PGPTXT { write text at arbitrary position and angle . . . . . . . . . A-34
PGQCF { inquire character font . . . . . . . . . . . . . . . . . . A-34
PGQCH { inquire character height . . . . . . . . . . . . . . . . . A-34
PGQCI { inquire color index . . . . . . . . . . . . . . . . . . . . A-35
PGQCOL { inquire color capability . . . . . . . . . . . . . . . . . A-35
PGQCR { inquire color representation . . . . . . . . . . . . . . . . A-35
PGQFS { inquire ll-area style . . . . . . . . . . . . . . . . . . . A-35
PGQINF { inquire PGPLOT general information . . . . . . . . . . . A-36
PGQLS { inquire line style . . . . . . . . . . . . . . . . . . . . . A-36
PGQLW { inquire line width . . . . . . . . . . . . . . . . . . . . A-37
PGQPOS { inquire current pen position . . . . . . . . . . . . . . . A-37
PGQVP { inquire viewport size and position . . . . . . . . . . . . . A-37
PGQWIN { inquire window boundary coordinates . . . . . . . . . . A-38
PGRECT { draw a rectangle, using ll-area attributes . . . . . . . . . A-38
PGRND { nd the smallest "round" number greater than x . . . . . . A-38
PGRNGE { choose axis limits . . . . . . . . . . . . . . . . . . . A-39
PGSCF { set character font . . . . . . . . . . . . . . . . . . . . A-39
PGSCH { set character height . . . . . . . . . . . . . . . . . . . A-39
PGSCI { set color index . . . . . . . . . . . . . . . . . . . . . . A-40
PGSCR { set color representation . . . . . . . . . . . . . . . . . . A-40
PGSFS { set ll-area style . . . . . . . . . . . . . . . . . . . . . A-41
PGSHLS { set color representation using HLS system . . . . . . . . . A-41
PGSLS { set line style . . . . . . . . . . . . . . . . . . . . . . . A-41
PGSLW { set line width . . . . . . . . . . . . . . . . . . . . . . A-42
PGSVP { set viewport (normalized device coordinates) . . . . . . . . A-42
PGSWIN { set window . . . . . . . . . . . . . . . . . . . . . . A-43
PGTBOX { Draw a box and optionally write HH MM SS labels . . . . A-43
PGTEXT { write text (horizontal, left-justied) . . . . . . . . . . . A-44
PGUPDT { update display . . . . . . . . . . . . . . . . . . . . . A-44
PGVPORT { non-standard alias for PGSVP . . . . . . . . . . . . . A-44
PGVSIZ { set viewport (inches) . . . . . . . . . . . . . . . . . . A-45
PGVSIZE { non-standard alias for PGVSIZ . . . . . . . . . . . . . A-45
PGVSTAND { non-standard alias for PGVSTD . . . . . . . . . . . A-45
PGVSTD { set standard (default) viewport . . . . . . . . . . . . . A-45
PGWINDOW { non-standard alias for PGSWIN . . . . . . . . . . . A-46
PGWNAD { set window and adjust viewport to same aspect ratio . . . A-46
vi
B PGPLOT SYMBOLS . . . . . . . . . . . . . . . . . . . . . B-1
C1 INSTALLATION INSTRUCTIONS (VMS) . . . . . . . . . C1-1
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . C1-1
Restoring the Save Set . . . . . . . . . . . . . . . . . . . . . . C1-1
Logical Names . . . . . . . . . . . . . . . . . . . . . . . . . . C1-3
The Shareable Image . . . . . . . . . . . . . . . . . . . . . . . C1-4
Recompiling PGPLOT . . . . . . . . . . . . . . . . . . . . . . C1-4
Recompiling the Example Programs . . . . . . . . . . . . . . . . C1-5
Rebuilding the Documentation Files . . . . . . . . . . . . . . . . C1-5
Printing the Manual . . . . . . . . . . . . . . . . . . . . . . . C1-5
Adding a new PGPLOT routine . . . . . . . . . . . . . . . . . . C1-6
C2 INSTALLATION INSTRUCTIONS (UNIX) . . . . . . . . . C2-1
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . C2-1
Basic Installation . . . . . . . . . . . . . . . . . . . . . . . . . C2-1
Advanced Installation . . . . . . . . . . . . . . . . . . . . . . . C2-4
Device Handlers . . . . . . . . . . . . . . . . . . . . . . . . . C2-6
Special Notes: Sun . . . . . . . . . . . . . . . . . . . . . . . . C2-8
Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . C2-8
D SUPPORTED DEVICES . . . . . . . . . . . . . . . . . . . D-1
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . D-1
Versatec . . . . . . . . . . . . . . . . . . . . . . . . . . . . D-4
PostScript printers . . . . . . . . . . . . . . . . . . . . . . . . D-5
QMS Lasergrax . . . . . . . . . . . . . . . . . . . . . . . . . D-6
Printronix . . . . . . . . . . . . . . . . . . . . . . . . . . . . D-7
VT125 (DEC REGIS terminals) . . . . . . . . . . . . . . . . . . D-9
VAX Workstations . . . . . . . . . . . . . . . . . . . . . . . . D-11
Sun Workstations . . . . . . . . . . . . . . . . . . . . . . . . D-12
Grinnell . . . . . . . . . . . . . . . . . . . . . . . . . . . . . D-13
IVAS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . D-13
Sigma ARGS . . . . . . . . . . . . . . . . . . . . . . . . . . D-14
Tektronix 4006, 4010 . . . . . . . . . . . . . . . . . . . . . . . D-14
Tektronix 4100 . . . . . . . . . . . . . . . . . . . . . . . . . . D-15
Retrographics . . . . . . . . . . . . . . . . . . . . . . . . . . D-15
Null Device . . . . . . . . . . . . . . . . . . . . . . . . . . . D-16
Canon . . . . . . . . . . . . . . . . . . . . . . . . . . . . . D-16
Colorwriter 6320 Plotter . . . . . . . . . . . . . . . . . . . . . D-17
Ikon . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . D-18
vii
Zeta . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . D-18
E WRITING A DEVICE HANDLER . . . . . . . . . . . . . . E-1
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . E-1
Device handler interface . . . . . . . . . . . . . . . . . . . . . . E-2
Handler state . . . . . . . . . . . . . . . . . . . . . . . . . . E-3
Summary of operations . . . . . . . . . . . . . . . . . . . . . . E-4
Testing a new device handler . . . . . . . . . . . . . . . . . . . E-10
F CALLING PGPLOT FROM A C PROGRAM . . . . . . . . F-1
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . F-1
VMS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . F-1
Convex UNIX . . . . . . . . . . . . . . . . . . . . . . . . . . F-2
viii
Chapter 1
INTRODUCTION
1.1 PGPLOT
PGPLOT is a Fortran subroutine package for drawing simple scientic
graphs on various graphics display devices. It was originally developed for
use with astronomical data reduction programs in the Caltech Astronomy
department.
This manual is intended for the Fortran programmer who wishes to
write a program generating graphical output. For most applications, the
program can be device-independent, and the output can be directed to the
appropriate device at run time. The output device is described by a \device
specication," discussed below. The programmer can build a specic device
specication into the program, but it is better to make this a parameter
which the user of the program can supply.
All the examples in this manual use standard Fortran-77. PGPLOT
itself is written mostly in standard Fortran-77, with a few non-standard,
system-dependent subroutines. At Caltech, it runs under the VAX/VMS,
Convex-UNIX, and Sun-UNIX operating systems.
On other VMS computers, the automatic search of the graphics library may
not occur. You will then need to include the graphics library explicitly by
using a LINK commands like the following:
$ LINK EXAMPLE,PGPLOT_DIR:GRPSHR/LIB
INTRODUCTION 1-3
The PGPLOT subroutines are not included in your .EXE le, but are fetched
from a shareable image when you execute the RUN command. This makes
the .EXE le much smaller, and means that the program need not be re-
linked when changes are made to the graphics subroutines but the .EXE le
can only be run on a machine that has a copy of the shareable image and
is running a compatible version of VAX/VMS. For more information, see
Appendix C.
Unix The following assumes that the PGPLOT library libpgplot.a has
been installed in a standard location where the loader can nd it. To com-
pile, link, and run a graphics program example.f:
fc -o example example.f -lpgplot
example
Unlike the VMS version, the PGPLOT routines are included in the exe-
cutable le.
In Unix (csh):
setenv PGPLOT_ENVOPT VG
2.1 Introduction
This chapter introduces the basic subroutines needed to create a graph us-
ing PGPLOT, by way of a concrete example. It does not describe all the
capabilities of PGPLOT these are presented in later chapters.
A graph is composed of several elements: a box or axes delineating the
graph and indicating the scale, labels if required, and one or more points
or lines. To draw a graph you need to call at least four of the PGPLOT
subroutines:
1. PGBEGIN, to start up PGPLOT and specify the device you want to plot
on
2. PGENV, to dene the range and scale of the graph, and draw labels, axes
etc
3. one or more calls to PGPOINT or PGLINE or both, or other drawing rou-
tines, to draw points or lines.
4. PGEND to close the plot.
To draw more than graph on the same device, repeat steps (2) and (3). It
is only necessary to call PGBEGIN and PGEND once each, unless you want to
plot on more than one device.
This chapter presents a very simple example program to demonstrate
the above four steps.
2.2 An Example
A typical application of PGPLOT is to draw a set of measured data points
and a theoretical curve for comparison. This chapter describes a simple
program for drawing such a plot in this case there are ve data points
2-2 SIMPLE USE OF PGPLOT
and the theoretical curve is y = x2. Here is the complete Fortran code for
the program:
PROGRAM SIMPLE
REAL XR(100), YR(100)
REAL XS(5), YS(5)
DATA XS/1.,2.,3.,4.,5./
DATA YS/1.,4.,9.,16.,25./
CALL PGBEGIN(0,'?',1,1)
CALL PGENV(0.,10.,0.,20.,0,1)
CALL PGLABEL('(x)', '(y)', 'A Simple Graph')
CALL PGPOINT(5,XS,YS,9)
DO 10 I=1,60
XR(I) = 0.1*I
YR(I) = XR(I)**2
10 CONTINUE
CALL PGLINE(60,XR,YR)
CALL PGEND
END
The following sections of this chapter describe how the program works, and
the resulting plot is shown in Figure 2.1.
All three arguments are character variables or constants any of them can
be blank (' ').
1. A label for the x-axis (bottom of picture).
2. A label for the y -axis (left-hand edge).
3. A label for the plot (top of picture).
SIMPLE USE OF PGPLOT 2-5
2.7 Drawing Graph Markers
Subroutine PGPOINT draws graph markers at one or more points on the
graph. Here we use it to mark the ve data points:
CALL PGPOINT(5,XS,YS,9)
If any of the specied points fall outside the window dened in the call to
PGENV, they will not be plotted. The arguments to PGPOINT are:
1. The number of points to be marked (integer).
2, 3. The x and y coordinates of the points (real arrays).
4. The number of the symbol to be used to mark the points. In this
example, we use symbol number 9 which is a circle with a central dot.
The available symbols are shown in Chapter 4.
Under Unix:
ed simple.f
...
fc -o simple simple.f -lpgplot
When you run the program, it will ask you to supply the graphics device
specication. Type in any allowed device specication, or type a question-
mark (?) to get a list of the available device types. For example, if you are
using a VT125 terminal, type /VT: the graph will appear on the terminal
screen.
If you want a hard copy, you can run the program again, and specify a
dierent device type, e.g., SIMPLE.PLT/VERS to make a disk le in Versatec
format. To obtain the hard copy, print the le (but rst check with your
system manager what the correct print command is it is possible to waste
a lot of paper by using the wrong command or sending a le to the wrong
sort of printer!).
Chapter 3
WINDOWS AND VIEWPORTS
3.1 Introduction
This chapter is concerned with positioning a graph on the screen or hardcopy
page, and controlling its scale. In simple applications, the position and scale
of the graph are controlled more-or-less automatically by the routine PGENV,
but in order to obtain complete control of positioning and scaling, it is
necessary to understand the concepts of the View Surface, the Window, and
the Viewport, and two coordinate systems: World Coordinates and Device
Coordinates.
A simple PGPLOT picture might be a two-dimensional graph showing
the dependence of one variable on another. A typical graph has data points,
represented by error bars or special markers such as dots or diamonds, possi-
bly connected by lines, or perhaps plotted on the same scale as a theoretical
model drawn as a smooth curve. The graph must be labeled with two axes
to indicate the coordinate scales.
The programmer must describe to PGPLOT the various elements of the
graph in terms of rectangular Cartesian coordinates. The only limitation
on the coordinates is that they be represented as oating-point (REAL*4)
numbers otherwise we are totally free to choose the meaning of the co-
ordinates. For example, in a graph showing the temporal variation of a
radio source, the abscissa (x-coordinate) might be Epoch (in years) and the
ordinate (y -coordinate) Flux Density (in Jy).
In accordance with common practice in graphics programming, these
coordinates, chosen by the programmer, are termed world coordinates . PG-
PLOT maps a selected rectangular region of the world-coordinate space
(termed the window ) onto a specied rectangle (termed the viewport ) on
the view surface (the screen of an interactive display or a sheet of paper on
a hardcopy plotter). The program must make calls to PGPLOT routines to
dene both the window and the viewport. For complete descriptions of the
routines and their arguments, refer to Appendix A.
3-2 WINDOWS AND VIEWPORTS
3.2 Selecting a View Surface
The rst thing a graphics program must do is to tell PGPLOT what device
it is going to use. This is done by calling routine PGBEGIN. For example, to
create a plot le for the Versatec printer:
CALL PGBEGIN (0, 'PLOTFILE.LIS/VERSATEC', 1, 1)
Note that only one device can be used at a time. If PGBEGIN is called while
a plot is in progress, the old plot is closed and a new one is begun.
After calling PGBEGIN the program has access to a view surface. For
interactive devices, this is the full screen of the device. For hardcopy devices,
it is a standard page, usually 10(x) 8:5(y ) inches on a device used in
\landscape" mode (e.g., device types /VE and /QMS), or 8:5(x) 10(y ) inches
a device used in \portrait" mode (e.g., device types /VV and /VQMS).
On some devices, it is possible to plot on a larger piece of paper than
the standard page see the description of routine PGPAPER, which must be
called immediately after PGBEGIN to change the size of the view surface. The
dierent devices dier not only in the size of the view surface, but also in
its aspect ratio (height/width). PGPAPER can be called to ensure that a plot
has the same aspect ratio no matter what device it is plotted on.
After completing a graph, it is possible to advance to a new page to
start a new graph (without closing the plot le) by calling PGPAGE:
CALL PGPAGE
This clears the screen on interactive devices, or gives a new piece of paper
on hardcopy devices. It does not change the viewport or window.
The last two arguments of PGBEGIN (NX and NY) can be used to sub-
divide the view surface into smaller pieces called sub-pages, each of which
can then be used separately. The view-surface is divided into NX (hori-
zontally) by NY (vertically) sub-pages. When the view surface has been
subdivided in this way, PGPAGE moves the plotter to the next sub-page, and
only clears the screen or loads a new piece of paper if there are no sub-pages
left on the current page.
In addition to selecting the view surface, PGBEGIN also denes a default
viewport and window. It is good practice, however, to dene the viewport
and window explicitly as described below.
WINDOWS AND VIEWPORTS 3-3
3.3 Dening the Viewport
A viewport is a rectangular portion of the plotting surface onto which the
graph is mapped. PGPLOT has a default viewport which is centered on the
plotting surface and leaves sucient space around it for annotation. The
application program can redene the viewport by calling routine PGVPORT
or PGVSIZE.
PGVPORT denes the viewport in a device-independent manner, using
a coordinate system whose coordinates run from 0 to 1 in both x and y .
This coordinate system is called normalized device coordinate space . For
example, if we wish to divide the view surface into four quadrants and map
a dierent plot onto each quadrant, we can dene a new viewport before
starting each plot. PGVPORT has the format:
CALL PGVPORT (XMIN, XMAX, YMIN, YMAX)
For example, to map the viewport onto the upper left quadrant of the view
surface:
CALL PGVPORT (0.0, 0.5, 0.5, 1.0)
(Note that this does not leave room around the edge of the viewport for
annotation.)
PGVSIZE denes the viewport in absolute coordinates (inches) it should
only be used when it is known how big the view surface is and a denite plot
scale is required. The arguments are the same as for PGVPORT, but measured
in inches from the bottom left corner of the view surface. For example:
CALL PGVSIZE (1.5, 9.5, 1.5, 6.5)
species that the x-axis (epoch) is going to run (left to right) from 1975 to
1984, and the y -axis (ux density) is going to run (bottom to top) from 5 to
20 Jy. Note that the arguments are oating-point numbers (Fortran REAL
variables or constants), and require decimal points. If the order of either
the x pair or the y pair is reversed, the corresponding axis will point in the
opposite sense, i.e., right to left for x or top to bottom for y . PGPLOT uses
the window specication to construct a mapping that causes the image of
the window to coincide with the viewport on the view surface. Furthermore,
PGPLOT \clips" lines so that only those portions of objects that lie within
the window are displayed on the view surface.
Like the viewport, the window must be dened before drawing any
objects. The window can be dened either before or after the viewport: the
eect will be the same. The default window, set up by PGBEGIN, has x limits
0.0{1.0 and y limits 0.0{1.0.
If the ratio of the sides of the window does not equal the ratio of the
sides of the viewport, the mapping of the world coordinates onto the view
surface results in an image whose shape is compressed in either x or y . One
way to avoid this compression is to carefully choose the viewport to have the
same aspect ratio as the window. Routine PGWNAD can do this: it denes the
window and simultaneously adjusts the viewport to have the same aspect
ratio as the window. The new viewport is the largest that can t inside the
old one, and is centered in the old one.
Another routine, PGLABEL, provides text labels for the bottom, left hand
side, and top of the viewport:
CALL PGLABEL ('Epoch', 'Flux Density (Jy)',
'Variation of 3C345 at 10.7 GHz')
WINDOWS AND VIEWPORTS 3-5
The rst two arguments provide explanations for the two axes the third
provides a title for the whole plot. Note that unlike all the other plotting
routines, the lines and characters drawn by PGBOX and PGLABEL are not
clipped at the boundaries of the window. PGLABEL actually calls a more
general routine, PGMTEXT, which can be used for plotting labels at any point
relative to the viewport.
The amount of space needed outside the viewport for annotation de-
pends on the exact options specied in PGBOX usually four character heights
will be sucient, and this is the amount allowed when the standard view-
port (created by PGVSTAND) is used. The character height can be changed
by using routine PGSCH.
PGENV uses the standard viewport. The rst four arguments dene the
world-coordinate limits of the window. The fth argument can be 0 or 1
it is 1, PGENV calls PGWNAD instead of PGWINDOW so that the plot has equal
scales in x and y . The sixth argument controls the amount of annotation.
Chapter 4
PRIMITIVES
4.1 Introduction
Having selected a view surface and dened the viewport and the window,
we are ready to draw the substance of the image that is to appear within the
viewport. This chapter describes the most basic routines, called primitives,
that can be used for drawing elements of the image. There are four dierent
sorts of primitive: lines, graph-markers, text, and area ll. Chapter 5 ex-
plains how to change the attributes of these primitives, e.g., color, line-style,
text font and Chapter 6 describes some higher-level routines that simplify
the composition of images that would require a large number of calls to the
primitive routines.
The primitive routines can be used in any combination and order after
the viewport and window have been dened. They all indicate where the
primitive is to appear on the view surface by specifying world coordinates.
See the subroutine descriptions in Appendix A for more details.
4.2 Clipping
The primitives are \clipped" at the edge of the viewport: any parts of the
image that would appear outside the viewport are suppressed. The various
primitives behave slightly dierently. A line is clipped where it crosses
the edge of the viewport. A graph marker is plotted if the center (the point
marked) lies within or on the edge of the viewport otherwise it is suppressed.
Text , which is usually used for annotation, is not clipped (except at the edge
of the view surface. A lled area is clipped at the edge of the viewport.
4-2 PRIMITIVES
4.3 Lines
The primitive line-drawing routine is PGLINE. This draws one or more con-
nected straight-line segments (generally called a polyline in computer graph-
ics). It has three arguments: the number (N) of points dening the polyline,
and two arrays (XPTS and YPTS) containing the world x and y -coordinates of
the points. The polyline consists of N ; 1 straight-line segments connecting
points 1{2, 2{3, : : :, (N ; 1){N :
CALL PGLINE (N, XPTS, YPTS)
The two routines PGMOVE and PGDRAW are even more primitive than PG-
LINE, in the sense that any line graph can be produced by calling these two
routines alone. In general, PGLINE should be preferred, as it is more modular.
PGMOVE and PGDRAW are provided for those who are used to Calcomp-style
plotting packages. PGMOVE moves the plotter \pen" to a specied point, with-
out drawing a line (\pen up"). It has two arguments: the world-coordinates
of the required new pen position. PGDRAW moves the plotter \pen" from its
current position (dened by the last call of PGMOVE or PGDRAW) to a new
point, drawing a straight line as it goes (\pen down"). The above call to
PGLINE could be replaced by the following:
CALL PGMOVE (XPTS(1), YPTS(1))
DO I=2,N
CALL PGDRAW (XPTS(I), YPTS(I))
END DO
The routine PGPTEXT (and all the PGPLOT routines which call it, e.g.,
PGTEXT, PGLABEL) allows one to include escape sequences in the text string
to be plotted. These are character-sequences that are not plotted, but are
interpreted as instructions to change font, draw superscripts or subscripts,
draw non-ASCII characters (e.g., Greek letters), etc. All escape sequences
start with a backslash character (\). The following escape sequences are
dened (the letter following the \ may be either upper or lower case):
\u { start a superscript, or end a subscript
\d { start a subscript, or end a superscript (note that \u and \d must always
be used in pairs)
PRIMITIVES 4-5
If the polygon is not convex, it may not be obvious which points in the
image are inside the polygon. PGPLOT assumes that a point is inside the
polygon if a straight line drawn from the point to innity intersects an odd
number of the polygon's edges.
PRIMITIVES 4-7
For the special case of a rectangle with edges parallel to the coordinates
axes, it is better to use routine PGRECT instead of PGPOLY this routine will
use the hardware rectangle-ll capability if available. PGRECT has four argu-
ments: the (x y ) world coordinates of two opposite corners (note the order
of the arguments):
CALL PGRECT (X1, X2, Y1, Y2)
Chapter 5
ATTRIBUTES
5.1 Introduction
The appearance of the primitive elements of a graphical image (lines, graph-
markers, text, and area-ll) can be changed by specifying primitive at-
tributes. The attributes, and the corresponding routines for changing them,
are:
Color Index and Color Representation: PGSCI, PGSCR, and PGSHLS.
Line Style: PGSLS.
Line Width: PGSLW.
Character Height: PGSCH.
Character Font: PGSCF.
Fill-area Style: PGSFS.
The routines to change attributes can be freely intermixed with the
PGPLOT drawing routines. Once an attribute has been changed by a call
to the appropriate routine, it remains in eect for all subsequent plotting
until it is changed again. In addition to the routines that set attributes
(PGSxx) there are routines for determining the current value of each attribute
(PGQxx). These make it possible to write subroutines which change attribute
values temporarily but restore the old attributes before returning to the
calling program.
6.1 Introduction
This chapter describes a number of \high level" routines that simplify the
composition of complicated graphical images. They include routines for
drawing graphs of one variable or function against another (\xy-plots"),
histograms, and display of two-dimensional data (functions of two variables).
Rather than giving complete details of all the available routines, this chapter
just points out some of the ways that they can be used. See Appendix A
for details of the calling sequences.
6.2 XY-plots
The basic technique for drawing xy-plots is described in Chapter 2, which
showed how to make scatter plots using graph markers produced by PGPOINT
and line plots produced by PGLINE. Considerable variation in the appearance
of the graph can be achieved using the following techniques.
Attributes. Use dierent attributes to distinguish dierent datasets.
Graph markers can be distinguished by choosing dierent markers, dierent
colors, or dierent sizes (character height attribute). Lines and curves can
be distinguished by line-style, color, or line-width.
Box parameters. If routine PGENV is replaced by calls to the more basic
routines (see x3.6), including PGBOX, considerable variety in the appearance
of the graph can be achieved. For example, one can suppress the tick marks,
draw the tick marks projecting out of the box instead of into it, or draw a
grid over the whole viewport. Note that PGBOX may be called many times:
one might call it once to draw a grid using thin dotted lines, and again to
draw the frame and tick marks using thick lines:
CALL PGSLW(1)
CALL PGSLS(4)
CALL PGBOX('G',30.0,0,'G',0.2,0)
CALL PGSLW(3)
CALL PGSLS(1)
CALL PGBOX('ABCTSN',90.0,3,'ABCTSNV',0.0,0)
6-2 HIGHER-LEVEL ROUTINES
Note that in this example we have also specied tick intervals explicitly. If
the horizontal axis is to represent an angle in degrees, it is convenient to
choose a tick interval that is a simple fraction of 360 here we have a major
tick interval of 90 and a minor tick interval of 30 .
Stepped-line plots. As an alternative to PGLINE, which \joins up the
dots" using straight line segments, it is sometimes appropriate to use PG-
BIN which produces a \stepped line plot" (sometimes misleadingly called
a histogram) with horizontal line segments at each data point and vertical
line segments joining them. This is often used, for example, in displaying
digitized spectra.
Error bars. Graphs of real data often require the inclusion of error bars.
The two routines PGERRX and PGERRY draw horizontal and vertical error bars,
respectively. These routines are usually used in combination with PGPOINT,
e.g., to draw a set of points with 2 error-bars:
DO 10 I=1,15
YHI = YPTS(I) + 2.0*ERR(I)
YLO = YPTS(I) - 2.0*ERR(I)
CALL PGPOINT(1, XPTS(I), YPTS(I), 17)
CALL PGERRY(1, XPTS(I), YLO, YHI, 1.0)
10 CONTINUE
6.3 Histograms
The routine PGHIST draws a histogram, that is, the frequency distribution
of measured values in a dataset. Suppose we have 500 measurements of a
quantity (the sky brightness temperature at 20 GHz, say, in mK) stored in
Fortran array VALUES. The following program-fragment draws a histogram
of the distribution of these values in the range 0.0 to 5.0, using 25 bins (so
that each bin is 0.2 K wide, the rst running from 0.0 to 0.2, the second
from 0.2 to 0.4, etc.):
DO 10 I=1,500
VALUES(I) = ....
10 CONTINUE
CALL PGHIST(500, VALUES, 0.00, 5.00, 25, 0)
CALL PGLABEL('Temperature (K)',
1 'Number of measurements',
2 'Sky Brightness at 20 GHz' )
The histogram does not depend on the order of the values within the array.
7.1 Introduction
The previous chapters have described how to produce a static graphical im-
age: if the same program is run twice with the same input parameters, the
same image will result. An interactive program allows the user to control
the behavior of the program with a graphical input device. PGPLOT sup-
ports a limited interactive capability on devices with a cursor for graphical
input (e.g., Grinnell, VT125 terminal, some Tektronix terminals, VT640
Retrographics terminal). The capabilities are necessarily limited by the aim
to keep PGPLOT device-independent.
PGNCURSE is similar to PGOLIN, but the points are sorted into increasing
order of x before being returned to the calling program. In addition, the
delete command deletes the point nearest to the cursor, rather than the
last-entered point. It can be used, for example, to allow the user to supply
a set of points to represent the continuum level on a spectrum.
PGLCUR is similar to PGOLIN but instead of using a graph marker to mark
each entered point it draws a polyline through them.
7.4 Buering
By default, PGPLOT ensures that the image seen on the view surface is
up to date at all times that is, each PGPLOT subroutine updates the
image before returning control to the calling program. To improve eciency,
PGPLOT can save instructions for controlling the graphics device in a buer,
and only send them to the device when the buer is lled up. This means
that at any given moment, the image displayed on the screen may not be
completely up to date. This can be a problem in an interactive program,
where, for example, the user has to tell the program what to do next based on
his interpretation of the current display. Three PGPLOT routines (PGBBUF,
PGEBUF, and PGUPDT) are provided for controlling the buering of output.
All three routines have no arguments.
The routine PGBBUF causes PGPLOT to begin saving graphical output
in a buer. The output is saved until (1) a matching PGEBUF call is made,
or (2) the buer lls up, or (3) the buer is emptied by a call to PGUPDT,
INTERACTIVE GRAPHICS 7-3
or (4) PGEND is called. The routine PGEBUF stops buering and causes the
buered commands to be sent to the output device. Calls to PGBBUF and
PGEBUF should always be paired. PGBBUF increments an internal counter,
while PGEBUF decrements this counter and ushes the buer to the output
device when the counter drops to zero. This allows a subroutine to turn on
and turn o buering without disturbing any buering that may have been
established by the calling program.
Routine PGUPDT empties the buer created by PGBBUF, but it does not
alter the internal counter. The routine should be called when it is essential
that the display be completely up-to-date (before interaction with the user,
for example) but it is not known if output is being buered.
Usually output is not buered this is the default state established by
PGBEGIN. The default behavior can be changed, however, by dening an
environment variable PGPLOT_BUFFER (see Chapter 1). If this variable is
dened, with any value, PGBEGIN will start buering output (by calling
PGBBUF).
The following example shows how routine PGLABEL might be imple-
mented in terms of routine PGMTEXT:
SUBROUTINE PGLABEL (XLBL, YLBL, TOPLBL)
CHARACTER*(*) XLBL, YLBL, TOPLBL
CALL PGBBUF
CALL PGMTEXT('T', 2.0, 0.5, 0.5, TOPLBL)
CALL PGMTEXT('B', 3.2, 0.5, 0.5, XLBL)
CALL PGMTEXT('L', 2.2, 0.5, 0.5, YLBL)
CALL PGEBUF
END
The calls to PGBBUF and PGEBUF ensure that the output generated by the
three calls to PGMTEXT is buered (i.e., sent to the output device as a single
command instead of three separate ones). If buering is already enabled by
the program which calls PGLABEL, the calls to PGBBUF and PGEBUF have no
eect.
Chapter 8
METAFILES
8.1 Introduction
A graphics metale is a disk le in which a device-independent represen-
tation of a graphics image can be stored. Such a le cannot be displayed
directly on a graphics device, but must rst be translated into the com-
mands appropriate for the specic device using a metale translator. This
may seem like an unnecessary complication, when PGPLOT can create the
device-specic commands directly, but it has some advantages. Metales
can be used, for example, to transfer pictures between two computing sites
(they are usually smaller than the corresponding device-specic les) or for
archiving pictures. It is sometimes convenient to make a program generate
a metale rather than a device-specic le so that one can, for example,
take a \quick look" at the picture on an interactive display before making
hard copies. One may not know what hard-copy devices will be available
when the program runs: for example, if it turns out after your 6-hour batch
job has nished that the Versatec printer has broken, it is nice to be able to
send the plot to some other device without re-running the batch job.
The metales generated by PGPLOT follow the \GSPC Metale Pro-
posal" described in Computer Graphics (A. C. M.), volume 13, number 3
(August 1979).
At present, metales are available only in the VMS version of PGPLOT,
not in the UNIX versions.
The PLOT command takes two arguments: the name of the input metale,
and the device specication for the output. The following sample commands
display a metale on a Grinnell and on a Versatec printer:
$ PLOT PLOT17.GMF /GR
$ PLOT PLOT17 DEIMOS::LVA0:/VE
A.1 Introduction
This appendix includes a classied list of all the PGPLOT subroutines,
and then gives detailed instructions for the use of each routine in Fortran
programs. The subroutine descriptions are in alphabetical order.
A.2 Arguments
The subroutine descriptions indicate the data type of each argument. When
arguments are described as \input", they may be replaced with constants
or expressions in the CALL statement, but make sure that the constant or
expression has the correct data type.
1. INTEGER arguments: these should be declared INTEGER or INTEGER*4 in
the calling program, not INTEGER*2.
2. REAL arguments: these should be declared REAL or REAL*4 in the calling
program, not REAL*8 or DOUBLE PRECISION.
3. CHARACTER arguments: any valid Fortran CHARACTER variable may be
used (declared CHARACTER*n for some integer n).
A.18 PGDRAW { draw a line from the current pen position to a point
SUBROUTINE PGDRAW (X, Y)
REAL X, Y
Draw a line from the current pen position to the point
with world-coordinates (X,Y). The line is clipped at the edge of the
current window. The new pen position is (X,Y) in world coordinates.
Arguments:
X (input) : world x-coordinate of the end point of the line.
Y (input) : world y-coordinate of the end point of the line.
A-14 SUBROUTINE DESCRIPTIONS
A.19 PGEBUF { end batch of output (buer)
SUBROUTINE PGEBUF
A call to PGEBUF marks the end of a batch of graphical output begun
with the last call of PGBBUF. PGBBUF and PGEBUF calls should always
be paired. Each call to PGBBUF increments a counter, while each call
to PGEBUF decrements the counter. When the counter reaches 0, the
batch of output is written on the output device.
Arguments: none
A.33 PGLAB { write labels for x-axis, y-axis, and top of plot
SUBROUTINE PGLAB (XLBL, YLBL, TOPLBL)
CHARACTER*(*) XLBL, YLBL, TOPLBL
Write labels outside the viewport. This routine is a simple
interface to PGMTXT, which should be used if PGLAB is inadequate.
Arguments:
XLBL (input) : a label for the x-axis (centered below the
viewport).
YLBL (input) : a label for the y-axis (centered to the left
of the viewport, drawn vertically).
TOPLBL (input) : a label for the entire plot (centered above the
viewport).
SUBROUTINE DESCRIPTIONS A-23
A.81 PGTBOX { Draw a box and optionally write HH MM SS style numeric labelling.
SUBROUTINE PGTBOX (XOPT, XTICKD, NXSUBD, YOPT, YTICKD, NYSUBD)
REAL XTICKD, YTICKD
INTEGER NXSUBD, NYSUBD
CHARACTER XOPT*(*), YOPT*(*)
Draw a box and optionally label one or both axes with HH MM SS style
numeric labels (useful for time or RA - DEC plots). Should deal with
axes that increase or decrease, and are positive or negative, or both.
If the HH MM SS labelling is desired, then PGSWIN should have been
previously called with the extrema in SECONDS.
Inputs:
XOPT : X-options for PGBOX. Same as for PGBOX plus 'Z' for time
labelling, and 'F' means write only the last part of the
label for the first time tick on the axis. E.g., if
the full first label is 17 42 34.4 then write only 34.4
YOPT : Y-options for PGBOX. Same as for PGBOX plus 'Z' and 'F'
XTICKD : X-axis major tick increment. Use 0.0 to get default.
YTICKD : Y-axis major tick increment. Use 0.0 to get default.
NXSUB : Number of intervals for minor ticks on X-axis. Use 0 for default
NYSUB : Number of intervals for minor ticks on Y-axis. Use 0 for default
A-44 SUBROUTINE DESCRIPTIONS
A.82 PGTEXT { write text (horizontal, left-justied)
SUBROUTINE PGTEXT (X, Y, TEXT)
REAL X, Y
CHARACTER*(*) TEXT
Write text. The bottom left corner of the first character is placed
at the specified position, and the text is written horizontally.
This is a simplified interface to the primitive routine PGPTXT.
For non-horizontal text, use PGPTXT.
Arguments:
X (input) : world x-coordinate of start of string.
Y (input) : world y-coordinate of start of string.
TEXT (input) : the character string to be plotted.
A.90 PGWNAD { set window and adjust viewport to same aspect ratio
SUBROUTINE PGWNAD (X1, X2, Y1, Y2)
REAL X1, X2, Y1, Y2
Change the window in world coordinate space that is to be mapped on
to the viewport, and simultaneously adjust the viewport so that the
world-coordinate scales are equal in x and y. The new viewport is
the largest one that can fit within the previously set viewport
while retaining the required aspect ratio.
Arguments:
X1 (input) : the x-coordinate of the bottom left corner
of the viewport.
X2 (input) : the x-coordinate of the top right corner
of the viewport (note X2 may be less than X1).
Y1 (input) : the y-coordinate of the bottom left corner
of the viewport.
Y2 (input) : the y-coordinate of the top right corner of the
viewport (note Y2 may be less than Y1).
Appendix B
PGPLOT SYMBOLS
C1.1 Introduction
PGPLOT consists of four \layers" of subroutines. The subroutines in each
layer call only subroutines in the same layer or in the next layer down:
1. The top-level PGPLOT subroutines these routines call only other PG-
PLOT routines.
2. The \primitive" PGPLOT routines these are used by the top-level rou-
tines and can be called by users' programs. They call the routines at
the next level to perform graphical output.
3. Device-independent support routines. These are responsible for things
like scaling, windowing, and character-generation.
4. Device handler routines: these generate graphical output for specic
device types. There is one device handler subroutine for each supported
device type.
Routines at levels 1 and 2 are the only ones that should be referenced
directly by a user's program. They are all described fully in Appendix A.
Usually the rst library (GRPSHR.OLB) should be used. When this library is
used, the subroutines are not included in the .EXE le, but are fetched from
a shareable image when you execute the RUN command. This makes the .EXE
le much smaller, and means that the program need not be relinked when
changes are made to the graphics subroutines but the .EXE le can only be
run on a machine which has a copy of the shareable image. If the second
library (GRPCKG.OLB) is used, the subroutines are included in the .EXE le
and the program can be run on any VAX computer running a compatible
version of VMS. In general, the shareable image is to be preferred.
The rst command compiles PGEX7. The second compiles all the example
programs.
The le PGPLOT.TEX contains TEX \input commands that reference the
other .TEX les. Please do not modify the TEX les: send your comments
and bug reports to the author.
The gures in the manual were generated using PGPLOT subroutines.
The Fortran programs used to generate them can also be found in the PG-
PLOT.MANUAL] directory.
C1-6 INSTALLATION INSTRUCTIONS (VMS)
C1.9 Adding a new PGPLOT routine
The author is happy to receive contributions of new high-level routines for
inclusion in PGPLOT. Some general guidelines should be observed when
preparing such routines:
1. The routine should be written (as far as possible) in standard Fortran-
77.
2. The routine should call only other PGPLOT routines, or special support
routines provided along with it. It should not use routines from other
libraries (especially commercial ones!). Note that if it is to be installed
in the shareable library, it cannot use common blocks for communication
with the program that calls it. It may, if necessary, use common blocks
to communicate with other PGPLOT routines, but this is discouraged.
3. It should be modular: that is, it should avoid, as far as possible, making
assumptions about the environment it is to run in, or modifying that
environment. In particular: if it changes any attribute (e.g., color index)
it should save the previous value of that attribute (obtained by calling
a PGQ... routine) and reset it before exiting it should not change the
window or viewport, but if it must, it should restore the old values
before exiting it should not call PGBEGIN or PGEND.
4. It should call routine PGBBUF at the beginning, and PGEBUF before exit-
ing, in order to buer its output.
5. It should provide a generally useful function rather than a highly specic
one, with as many parameters as possible accessible to the user (e.g., as
arguments) rather than xed in the program.
Appendix C2
INSTALLATION INSTRUCTIONS (UNIX)
C2.1 Introduction
All UNIX systems are dierent, so the installation procedure described here
may not work on your system, and some editing and debugging may be
required. Please read all the installation instructions before attempting to
install PGPLOT. I rst describe the installation procedure which I have used
on our systems (Convex and Sun) I hope it will work on other Berkeley-
derived UNIX systems. If you have trouble with the installation, you should
read Section C.3, which is intended to provide sucient background infor-
mation for you to adapt PGPLOT to a dierent system.
The UNIX version of PGPLOT is distributed in source form on a `tar'
tape (usually a 9-track, 1600-bpi tape).
This will create a pgplot directory in your current directory and install
the PGPLOT les in it. (If you already have a pgplot directory, remove
it rst.) If you are not using `tar' but are copying the les from another
system, make sure that you put the les in the correct directories.
C2-2 INSTALLATION INSTRUCTIONS (UNIX)
2. Compile the PGPLOT subroutines and create the PGPLOT object li-
brary. Change your default directory to PGPLOT and then use `make'
to do the compilation. The distribution tape contains two `makeles', one
for Convex (Makefile.CONVEX) and one for Sun (Makefile.SUN). You can
rename the appropriate le to Makefile, or use the -f option of `make':
cd pgplot
make -f Makefile.SUN
If all goes well, you should get no error messages from the compilation. (The
SUN Fortran compiler issues an incorrect warning message that MOD is an
unused variable when compiling grre04 and grte04 you can ignore this
message.)
3. Build the binary font le. The font le (read at run time by PGPLOT
programs) is distributed in an ASCII text form in le grfont.txt and must
be converted to binary form before use. This is done using the `makele' in
the fonts directory again there are separate versions for Convex and Sun:
cd fonts
make -f Makefile.SUN grfont.dat
This compiles a program pgpack to do the conversion and then runs it. It
should display a message like the following:
Characters defined: 996
Array cells used: 26732
You now need to dene an environment variable that denes the location of
the binary font le, e.g.:
setenv PGPLOT_FONT /usr/name/pgplot/fonts/grfont.dat
The fonts directory also contains utility programs pgunpack and pgdchar
that you will need only if you plan to modify the font le (not recommended).
4. Compile the test and demonstration programs in the examples directory.
Again there there are separate `makeles' for Convex and Sun:
cd ../examples
make -f Makefile.SUN
INSTALLATION INSTRUCTIONS (UNIX) C2-3
At this point, you may run out of disk space (if you haven't done already)
as the executable programs are rather large. If necessary, you can compile
the programs one at a time, e.g.:
make -f Makefile.SUN pgdemo1
pgdemo1
The program will prompt for a device specication. Type a question mark
? to get a list of available device handlers. Read the PGPLOT manual for
details of device specications, and the remainder of this Appendix for notes
on the available device handlers. Run the program once for each device that
you wish to test. I hope that all will go well if not, read the next section.
The commonest problem is that you get graphs with no text. This implies
that the program cannot read the font le (you should also get a message
to this eect). Check the denition of PGPLOT_FONT (see above).
6. If everything so far looks all right, you can move the les to their -
nal destinations (this may require superuser privilege and the cooperation
of your system manager). You need to keep two les: the object library
pgplot/libpgplot.a and the binary font le pgplot/fonts/grfont.dat.
Everything else can be deleted if you want to conserve disk space it can
always be recovered from the distribution tape. The object library should
(ideally) be moved to the directory where the loader expects to nd libraries
usually /usr/lib:
cd pgplot
cp libpgplot.a /usr/lib
You can then use -lpgplot with ld or your Fortran compiler to link a pro-
gram with the PGPLOT library. The location of the font le is arbitrary, but
as distributed, PGPLOT expects to nd it in /usr/local/lib/grfont.dat:
cd fonts
cp grfont.dat /usr/local/lib
If you want to put it in some other location, you can either dene PG-
PLOT_FONT every time you use a PGPLOT program (see above), or modify
C2-4 INSTALLATION INSTRUCTIONS (UNIX)
the default location by editing le pgplot/grsy00.f and recompiling (see
step 2). (Note that if you modify any PGPLOT routine, you will have to
remodify it each time you install a new version of PGPLOT.)
7. Finally, you should attempt to compile and link a PGPLOT program of
your own. On Convex:
fc -o program program.f -lpgplot
On Sun:
f77 -o program program.f -lpgplot -lsuntool -lcgi77 -lcgi\
-lsunwindow -lpixrect -lm
Note that the Sun version requires all the above libraries to be included,
in the order indicated (assuming that the /SUNVIEW and /CGI device
handlers are included, as they are in the distribution tape).
Use device specication /SUNVIEW. Please let me know if you have any prob-
lems with this handler, or make improvements to it.
Sun-CGI (Sun only) File cgdriv is another handler for Sun workstations
running SunView, from Allyn Tennant. It only works with color worksta-
tions, but could probably be easily modied for monochrome workstations.
It calls on the Sun CGI routines, and hence programs which use it must be
linked with several libraries (in order):
-lcgi77 -lcgi -lsunwindow -lpixrect -lm
C2.6 Acknowledgments
I am grateful to Jon Danskin of Convex Computer Corporation for the ini-
tial port of PGPLOT to Convex-UNIX, Allyn Tennant (NASA Marshall)
for providing the Sun-CGI device handler, Brian Sutin (University of Mary-
land) for the SunView device handler, Neil Killeen (University of Illinois)
for comments on the Sun implementation, and Judy Cohen (Caltech) for
providing time on Sun-3 and Sun-4 workstations.
T. J. Pearson
29 May 1989
Appendix D
SUPPORTED DEVICES
D.1 Introduction
This Appendix presents device-specic information for some of the sup-
ported devices. Table D.1 shows the devices for which device handlers are
available, together with the names by which they are known to PGPLOT.
The names of the device types can be abbreviated so long as there is no am-
biguity in most cases, this means the rst two letters are sucient. Each
installation of PGPLOT is congured with the devices appropriate for that
installation, so not every device is available in every installation of PGPLOT.
Some devices are available under VMS only, and others are available under
Unix only.
The description of each device is organized under the following headings:
Supported device: description of device.
Device type code: the code to be used (following the /) in a PGPLOT
device specication usually this can be abbreviated to two letters. Some
devices can be used in two modes: landscape (long axis horizontal) and
portrait (long axis vertical). Dierent device type codes are used for the
two modes.
Default le or device name: the le or device name that is used by
default if none is included in the device specication. (For example, if the de-
vice specication is given as /VERS, it is expanded to PGPLOT.VEPLOT/VERS
if it is given as UV/VERS, it is expanded to UV.VEPLOT/VERS.)
Default view surface dimensions: Most hardcopy devices print on
11 8:5-inch paper, and the standard usable \view surface" is 10:5 8:0
inches. The dimensions are meaningless for most CRT devices where the
image size depends on the size of the monitor.
Resolution: The nominal resolution of the device in pixels/inch. The
exact resolution can be ill-dened e.g., on a pen plotter, it depends on the
size of the pen nib.
Color capability: What color indices are available? Can the representa-
tion of each color index be changed? Do changes to the representation aect
primitive elements that have already been drawn?
D-2 SUPPORTED DEVICES
Table D.1 Available Devices
Terminals
GraphOn GO-230 terminal /GF
Tektronix 4006/4010 storage-tube terminal /TEK4010
Retrographics modied VT100 terminal (VT640) /RETRO
DEC VT125, VT240, or VT340 terminal (REGIS) /VT125
Tektronix 4100-series color terminal /TK4100
ZSTEM 240/4014 terminal emulators (IBM PC) /ZSTEM
High-resolution Display Devices
DeAnza (Gould 8500 low resolution) /DEanza
Grinnell GMR-270 Image Display System /GRINNELL
Digisolve Ikon Pixel Engine /IKon
Liacom Graphic Video Display (GVD-02) /LIacom
Peritek Corp. VCH-Q frame-buer video /PERITEK
Peritek Corp. VCK-Q frame-buer video /PK
Sigma Args, 7000 series /ARgs
Sigma, T5670 terminal /GOC
Tektronix 4014 (12 bit addressing) /TFILE
VAX/VMS workstations /WS
Sun workstations (SunView mode) /SUNVIEW
Sun workstations (using CGI routines) /CGI
IIS IVAS image display /IVAS
Imagraph image display /IMA
Pen Plotters
Gould (now Bryans) Colourwriter 6320 /CW6320
HPGL Driver (tested on HP7475A plotter) /HPGL
HPGL Driver (portrait mode) /VHPG
Hewlett Packard 7221 pen plotter /HP7221
Houston Instruments HIDMP pen plotter /HIDMP
Bruning (fmr Nicolet) Zeta 8 Digital Plotter /ZEta
Laser Printers
Hewlett Packard LaserJet, LaserJet+,II /LJ
PostScript device (landscape mode) /PS
PostScript device (portrait mode) /VPS
QUIC devices (QMS 800 etc) (landscape mode) /QMS
QUIC devices (QMS 800 etc) (portrait mode) /VQMS
Canon LBP-8/A2 Laser printer (landscape mode) /BCanon
Canon LBP-8/A2 Laser printer (landscape mode) /CAnon
Canon LBP-8/A2 Laser printer (portrait mode) /VCanon
Impress (Imagen) device (landscape mode) /IMPRESS
Impress (Imagen) device (portrait mode) /VIMPRESS
SUPPORTED DEVICES D-3
Table D.1 (continued)
Dot-matrix Printers
EPSON FX100 printer /EPSON
EXCL (C.Itoh Megaserve) printer /EXCL
LA50 and other DEC sixel printers /LA50
Printronix P300 or P600 printer /PRINTRONIX
Toshiba \3-in-on"" printer, model P351 /TOSHIBA
Versatec V80 printer (landscape mode) /VERSATEC
Versatec V80 printer (portrait mode) /VVERSATEC
Other
Null device (no graphical output) /NULL
Metale /FILE
D-4 SUPPORTED DEVICES
Input capability: Instructions for the use of the graphics cursor, if one
is available.
File format: Description of the le in which the graphic commands are
stored. For some devices, the commands are sent directly to the device and
no intermediate le is required.
Obtaining hardcopy: When an intermediate le is used, this section
gives instructions for sending the graphic commands from the le to the
device. It is important to check the correct procedure with your System
Manager before attempting to generate a hardcopy plot. Attempting to print
or plot a le on the wrong sort of device will at best waste a large quantity
of paper, and may damage the device or crash the VAX.
D.2 Versatec
Supported device: Versatec V-80 printer/plotter (and compatible mod-
els).
Device type code: /VErsatec (landscape mode), /VVersatec (portrait
mode).
Default le name: PGPLOT.VEPLOT (landscape mode), PGPLOT.VVPLOT
(portrait mode).
Default view surface dimensions: 10.5 inches horizontal 8.0 inches
vertical (landscape mode), 8.0 inches horizontal 10.5 inches vertical (por-
trait mode). These are nominal values the actual scale may vary, particu-
larly in the dimension parallel to the paper motion.
Resolution: 200 pixels/inch (both dimensions).
Color capability: Color indices 0 (erase) and 1 (black) are supported.
Requests for other color indices are converted to 1. It is not possible to
change color representation.
Input capability: None.
File format: The le contains variable length records (up to 265 bytes),
one record corresponding to one horizontal dot row of the plot. The le has
record attributes \No Carriage Control." The rst byte in each record is
control-D (hexadecimal 04: plot mode specier). The remaining 8-bit bytes
each represent 8 dots, with the most signicant bit representing the left-most
dot 1 implies the corresponding dot is to be lled in. Thus the maximum
number of dots per line is 264 8 = 2112, corresponding to 10.56 inches
at 200 dots per inch. The vertical spacing of dot rows is also 200 per inch.
Plot pages are separated by a record containing a form-feed character only (1
byte, hexadecimal 0C). These les are intended for use with a special driver
SUPPORTED DEVICES D-5
and printer symbiont which recognize the control-D and send the remainder
of the record to the Versatec in plot mode instead of text mode. This is not
the format expected by the standard VMS driver provided by Versatec.
Obtaining hardcopy: Use the VMS COPY command to send the le to a
suitable device or use the VMS PRINT command if a suitable printer queue
has been established. Examples:
$ COPY PGPLOT.VEPLOT LVA0:
$ PRINT/NOTIFY/QUEUE=VERSATEC PGPLOT.VEPLOT
On DEIMOS:
$ PRINT PGPLOT.VEPLOT
On PHOBOS:
$ VPRINT PGPLOT.VEPLOT
On Starlink:
$ PRINT/PASSALL/QUEUE=SYS_VERSATEC PGPLOT.VEPLOT
On XHMEIA:
$ LASER PGPLOT.QMPLOT
On CVAX:
$ PRINT/QUEUE=TXA0 PGPLOT.QMPLOT
D.5 Printronix
Supported device: Printronix P300, P600 and equivalent dot-matrix
printer-plotters.
Device type code: /PRintronix (landscape mode only).
Default le name: PGPLOT.PRPLOT.
Default view surface dimensions: 13.2 inches horizontal 10.0 inches
vertical, on standard 15 11:0-inch computer paper. These are nominal
values, but the printer is usually quite accurately aligned.
Resolution: 60 pixels/inch horizontal 72 pixels/inch vertical.
Color capability: Color indices 0 (erase) and 1 (black) are supported.
Requests for other color indices are converted to 1. It is not possible to
change color representation.
Input capability: None.
File format: A Printronix le contains variable length records (up to 135
bytes), one record corresponding to one horizontal dot row of the plot. The
le has record attributes \No Carriage Control." The last three bytes in each
record are control-E (hexadecimal 05: plot mode specier), carriage-return,
line-feed. The remaining bytes each use the 6 lower-order bits to represent 6
dots, with the least signicant bit representing the left-most dot 1 implies
the corresponding dot is to be lled in. The top two bits are always 1. Thus
the maximum number of dots per line is 132 6 = 792, corresponding to 13.2
inches at 60 dots per inch. If a plot covers more than one page, no form-feed
codes are inserted rather a sucient number of blank plot lines are inserted
to advance to the top of the next page (792 lines per 11-inch page). If these
D-8 SUPPORTED DEVICES
les are to be printed on a Printronix printer using the standard VAX/VMS
line-printer driver (LPDRIVER or LCDRIVER), the system manager must
set the characteristics of the printer and associated queue correctly. It is
important to ensure that (1) all 8-bit characters, including non-printable
control characters, are passed to the printer, (2) lines of 135 bytes or less
are not truncated, and (3) no extra formatting commands (e.g., form-feeds)
are sent to the printer. The following setup is used on Phobos:
$ SET PRINTER/LOWER/CR/PRINTALL LPA0:
$ SET DEVICE/SPOOLED=(SYS$PRINT,SYS2:) LPA0:
$ DEFINE/FORM/NOTRUNC/NOWRAP DEFAULT 0
$ INITIALIZE/QUEUE/START/ON=LPA0: SYS$PRINT -
/DEFAULT=(FLAG=ONE)/PROT=(W:RW)/SCHED=NOSIZE
On Phobos:
$ PRINT/PASSALL PGPLOT.PRPLOT
On Deimos:
$ PPRINT/PASSALL PGPLOT.PRPLOT
On Starlink:
$ PRINT/PASSALL/QUEUE=SYS_PRINTRONIX PGPLOT.PRPLOT
On Ikaros (Convex-Unix):
lpr -l PGPLOT.PRPLOT
SUPPORTED DEVICES D-9
D.6 VT125 (DEC REGIS terminals)
Supported device: Digital Equipment Corporation VT125, VT240, or
VT241 terminal other REGIS devices may also work.
Device type code: /VT125.
Default le name (VMS): TT:PGPLOT.VTPLOT. This usually means the
terminal you are logged in to (logical name TT), but the plot can be sent
to another terminal by giving the device name, e.g., TTC0:/VT, or it can be
saved in a le by specifying a le name, e.g., CITSCR:TJP]XPLOT/VT (in
this case a disk name must be included as part of the le name).
Default le name (Unix): /dev/tty, the terminal you are logged in to.
the plot can be sent to another terminal by giving the device name, or it
can be saved in a le by specifying a le name.
Default view surface dimensions: Depends on monitor.
Resolution: The default view surface is 768 (horizontal) 460 (vertical)
pixels. On most Regis devices, the resolution is degraded in the vertical
direction giving only 230 distinguishable raster lines. (There are actually
240 raster lines, but 10 are reserved for a line of text.)
Color capability: Color indices 0{3 are supported. By default, color
index 0 is black (the background color). Color indices 1{3 are white, red, and
green on color monitors, or white, dark grey, and light grey on monochrome
monitors. The color representation of all the color indices can be changed,
although only a nite number of dierent colors can be obtained (see the
manual for the terminal).
Input capability: The graphics cursor is a blinking diamond-crosshair.
The user positions the cursor using the arrow keys and PF1{PF4 keys on his
keyboard "Note: NOT the keyboard of the terminal on which he is plotting,
if that is dierent.] The arrow keys move the cursor in the appropriate
direction the size of the step for each keystroke is controlled by the PF1{
PF4 keys: PF1 ) 1 pixel, PF2 ) 4 pixels, PF3 ) 16 pixels, PF4 ) 64
pixels. "The VT240 terminal has a built-in capability to position the cursor,
but PGPLOT does not use this as it is not available on the VT125.] The
user indicates that the cursor has been positioned by typing any character
other than an arrow or PF1-PF4 key "control characters, e.g., ^C, and other
special characters should be avoided, as they may be intercepted by the
operating system].
D-10 SUPPORTED DEVICES
File format: A REGIS plot le is formatted in records of 80 characters
or less, and has no carriage-control attributes. The records are grouped
into \buers," each of which begins with hesciPp to put the terminal into
graphics mode and ends with hescin to put it back into text mode. The
terminal is in graphics mode only while a buer is being transmitted, so a
user's program can write to the terminal at any time (in text mode) without
worrying if it might be in graphics mode. Everything between the escape
sequences is REGIS: see the VT125 or VT240 manual for an explanation.
PGPLOT attempts to minimize the number of characters in the REGIS
commands, but REGIS is not a very ecient format. It does have the great
advantage, though, that it can easily be examined with an editor. The le
may also contain characters outside the hesciPp: : : hescin delimiters, e.g.,
escape sequences to erase the text screen and home the cursor.
The following escape sequences are used:
hesci2J { Erase entire screen (text)
hesciH { Move cursor to home position
hesciPp { Enter REGIS graphics mode
hescin { Leave REGIS graphics mode
PGPLOT uses a very limited subset of the REGIS commands supported
by the VT125 and VT240. The following list summarizes the REGIS com-
mands presently used.
Initialization: the following standard commands are used to initialize the
device every time a new frame is started most of these restore a VT125 or
VT240 to its default state, but the screen addressing mode is nonstandard.
! { resynchronize
W(R) { replace mode writing
W(I3) { color index 1
W(F3) { both bit planes
W(M1) { unit multiplier
W(N0) { negative o
W(P1) { pattern 1
W(P(M2)) { pattern multiplier 2
W(S0) { shading o
S(G1) { select graphics plane "Rainbow REGIS]
S(A0,479]767,0]) { screen addressing, origin at bottom left
S(I0) { background dark
S(S1) { scale 1
S(M0(L0)(AL0)) { output map section 0 (black)
S(M1(L30)(AH120L50S100)) { output map section 1 (red/dim grey)
S(M2(L59)(AH240L50S100)) { output map section 2 (green/light grey)
S(M3(L100)(AL100)) { output map section 3 (white)
SUPPORTED DEVICES D-11
Drawing lines: the P and V commands are used with absolute coordinates,
relative coordinates, and pixel vectors. The (B), (S), (E), and (W) modiers
are not used. Coordinates which do not change are omitted.
Px,y] { move to position, e.g. P499,0]
Vx,y] { draw vector to position, e.g. V]767],479]0],0]
Line attributes: the line style and line color attributes are specied with W
commands, e.g.
W(P2) { line style 2
W(I2) { intensity (color index) 2
and S commands are used to change the output map. The PGPLOT color
indices 0, 1, 2, 3 correspond to output map sections 0, 3, 1, 2.
Obtaining hardcopy: A hardcopy of the plot can be obtained using a
printer attached to the VT125/VT240 terminal (see the instruction manual
for the terminal). A plot stored in disk le can be displayed by copying it
to a suitable terminal e.g., use TYPE on VMS or cat on Unix.
D.10 IVAS
Supported device: International Imaging Systems IVAS Display Proces-
sor.
Device type code: /IVAS.
Default device name: /dev/ga0 (Unix).
Default view surface dimensions: Depends on monitor.
Resolution: The full view surface is 1024 1024 pixels.
Color capability: Color indices 0{15 are supported. The default color
representation is as listed in Chapter 5. The representation of all color
indices can be changed.
D-14 SUPPORTED DEVICES
Input capability: The graphics cursor is a yellow cross. The user po-
sitions the cursor using the mouse, and indicates that the cursor has been
positioned by typing any character other than an arrow or PF1-PF4 key
"control characters, e.g., ^C, and other special characters should be avoided,
as they may be intercepted by the operating system].
File format: It is not possible to send IVAS plots to a disk le.
Obtaining hardcopy: Not possible.
D.14 Retrographics
Supported device: Digital Engineering, Inc., Retrographics modied
VT100 terminal (VT640).
Device type code: /REtro.
Default device name: TT: (the logged-in terminal).
Default view surface dimensions: Depends on monitor.
Resolution: The full view surface is 1024 (horizontal) 780 pixels.
Color capability: Color indices 0 (erase, black) and 1 (bright: usually
green) are supported. It is not possible to change color representation.
D-16 SUPPORTED DEVICES
Input capability: The graphics cursor is a crosshair across the entire
screen. The user positions the cursor using the four arrow keys on the
keyboard of the Retrographics terminal. \By striking the desired directional
arrow key, the crosshair will move across the display screen at the rate of
one dot per keystroke. Applying a constant pressure on an arrow key will
cause the crosshair to move at a continuous rapid rate releasing the key will
stop the crosshair's movement." The user indicates that the cursor has been
positioned by typing any printable ASCII character on the keyboard of the
Retrographics terminal. Most control characters (e.g., ^C) are intercepted
by the operating system and cannot be used.
File format: It is not possible to send Retro plots to a disk le.
Obtaining hardcopy: Not possible.
D.16 Canon
Supported device: Canon LBP-8/A2 Laser printer. Conforms to ISO
646, 2022, 2375 and 6429 specications. VDM (graphics) conforms to pro-
posed American National Standard VDM mode.
Device type code: /CAnon (landscape mode), /VCanon (portrait mode)
and /BCanon (bitmap in landscape mode only).
Default le name: PGPLOT.CAN
Default view surface dimensions: 24 cm by 19 cm.
SUPPORTED DEVICES D-17
Resolution: 300 pixels per inch in both directions.
Color capability: Color indices 0 (erase) and 1 (black) are supported.
Note, hardware polygon ll is used and colors 0-11 control the ll pattern.
Input capability: None.
File format: Variable length records with Carriage control of LIST.
Obtaining hardcopy: If printer is connected to a terminal line (RS-232
option) then printing the le on the corresponding queue should suce.
If the printer is connected using the Centronics interface that appears the
to VAX as an LP device then it is important to ensure that (1) all 8 bit
characters are passed to the printer (2) lines longer than 132 bytes are not
truncated, and (3) no extra formatting commands (e.g. form-feeds) are sent
to the printer. This can be done with the VMS command:
$ SET PRINT/PASSALL/LOWER/CR <device>
Note, some interface boards have a option to append a carriage return after
a formfeed or LF character, it is necessary that this be disabled. The le
should be printed with the /PASSALL qualier i.e.,
$ PRINT/PASSALL <filename>
D.18 Ikon
Supported device: Digisolve Ikon Pixel Engine
Device type code: /IKon.
Default device name: IKON_DEFAULT (a logical name).
Default view surface dimensions: Depends on monitor.
Resolution: The full view surface is 1024 by 780 pixels.
Color capability: Color indices 0-255 are supported. The default repre-
sentation is listed in Chapter 5 of the PGPLOT manual. The representation
of all color indices can be changed.
Input capability:
File format: It is not possible to send IKON plots to a disk le.
Obtaining hardcopy: Not possible.
D.19 Zeta
Supported device: Zeta 8 Digital Plotter.
Device type code: /ZEta
Default le name: PGPLOT.ZET
Default view surface dimensions: 11 inches by 11 inches. Current
version does not allow larger plots although the manual indicates plots up
to 144 feet are possible.
SUPPORTED DEVICES D-19
Resolution: This version is written for the case where the resolution
switch is set to .025 mm. Actual resolution depends on thickness of pen tip.
Color capability: Color indices 1 to 8 are supported corresponding to
pens 1-8. It is not possible to erase lines.
Input capability: None.
File format: Variable length records with Carriage control of LIST.
Obtaining hardcopy: On Starlink print the le on the queue associated
with the Zeta plotter. If the Plotter is attached to a terminal line, then
TYPEing the le at the terminal will produce a plot. On Starlink:
$ PRINT/NOFEED/QUE=ZETA PGPLOT.ZET
To stop a Zeta plot job, once it has been started, use the buttons on the
plotter. Press PAUSE, NEXT PLOT and CLEAR. Only after this sequence
is it safe to delete the job from the ZETA Queue. Failing to press the
NEXT PLOT button will not correctly advance the paper. Failing to press
CLEAR but, deleting the current job can prevent the following plot from
being plotted.
Appendix E
WRITING A DEVICE HANDLER
E.1 Introduction
PGPLOT can be congured for a particular installation by adding or re-
moving \device handlers". A device handler is a subroutine which handles
all the device-specic aspects of graphical output for a particular device or
class of devices.
All graphical output is handled by a \device dispatch routine" in PG-
PLOT, called GREXEC. This routine calls on the appropriate device han-
dler to perform the output. Reconguring PGPLOT involves modifying the
GREXEC routine to use a dierent set of device handlers no other changes
to PGPLOT are needed.*
To write a new device handler, it is simplest to start by modifying an
existing one. This Appendix explains what the device handler must do,
but it does not explain how to do it|which is, of course, very hardware-
dependent.
The supported device types fall into three classes, and when adding a
new device you should determine which class it belongs to, and then add
the new device by copying and modifying the support routines for one of
the existing devices in this class. The three classes are:
1. Bit map devices (e.g., Versatec). The complete image is assembled in
memory as a bit map and then written in an output le in a format
acceptable to the device. The existing devices in this class use one bit
per pixel, but more bits could be allocated.
2. Instruction stream devices (e.g., QMS): Graphical instructions are writ-
ten sequentially in the output le using Fortran I/O. Usually the in-
structions are composed of printable ASCII characters, but this is not
essential.
* In the VMS version of PGPLOT, the modication of GREXEC can be
done automatically using the command procedure NEWEXEC.COM which nds
all the device handlers currently installed in the PGPLOT.SOURCE] directory.
E-2 WRITING A DEVICE HANDLER
3. Direct I/O devices (e.g., Grinnell): devices that require special com-
mands that cannot be encoded in text strings use the low-level oper-
ating system I/O routines (SYS$QIO in VMS) to directly control the
device. It is not possible to store images in a disk le for these devices.
F.1 Introduction
It is possible to call PGPLOT routines from a program written in C. The
methods for calling a Fortran subroutine from a C program are operating-
system dependent, and indeed it is impossible in some systems. The details
are rather complicated, and if there is a demand, we could create a C-
callable library that hides these details from the user. Examples of the
same program written in Fortran-77, VAX/VMS C, and Convex UNIX C
are included below.
F.2 VMS
The following is a prescription for calling PGPLOT subroutines from a C
program on a VAX running VMS.
1. All arguments (except arrays and character strings) are passed by ad-
dress using the & operator. As you cannot take the address of a constant,
constants must be passed in dummy variables.
2. INTEGER arguments correspond to C type long int or int.
3. REAL arguments correspond to C type float.
4. CHARACTER arguments correspond to C character strings, but they must
be passed by descriptor. The VAX-C manual explains how to do this
using the $DESCRIPTOR macro for xed strings it is a little more com-
plicated for variable strings.
5. Note that the backslash character (\) must be escaped (\\).
F-2 CALLING PGPLOT FROM A C PROGRAM
F.3 Convex UNIX
The following is a prescription for calling PGPLOT subroutines from a C
program on the Convex. It may also work on other Berkeley UNIX systems.
1. The main program must be called MAIN__() instead of main(). I don't
know why this is so, but it must have to do with the initialization of
the Fortran library.
2. Use the C compiler to compile the program, but use fc to load it. This
ensures that the Fortran system libraries are scanned.
3. All PGPLOT subroutine names must be typed in lower case, with an
underscore appended, e.g., pgbegin_(), pgend_().
4. All arguments (except arrays and character strings) are passed by ad-
dress using the & operator. As you cannot take the address of a constant,
constants must be passed in dummy variables.
5. INTEGER arguments correspond to C type long int.
6. REAL arguments correspond to C type float.
7. For CHARACTER arguments, pass a pointer to a C character string, and
add the length of the string (number of characters) as an extra long
int argument at the end of the argument list.
8. Note that the backslash character (\) must be escaped (\\).
Example:
cc -c example1.c
fc -o example1 example1.o -lpgplot
example1
CALLING PGPLOT FROM A C PROGRAM F-3
C ---------------------------------------------------------------------
C Demonstration program for PGPLOT (Fortran version).
C ---------------------------------------------------------------------
C
PROGRAM PGDEMO
C
INTEGER I
REAL XS(5),YS(5), XR(100), YR(100)
DATA XS/1.,2.,3.,4.,5./
DATA YS/1.,4.,9.,16.,25./
C
C Call PGBEGIN to initiate PGPLOT and open the output device PGBEGIN
C will prompt the user to supply the device name and type.
C
CALL PGBEGIN(0,'?',1,1)
C
C Call PGENV to specify the range of the axes and to draw a box, and
C PGLABEL to label it. The x-axis runs from 0 to 10, and y from 0 to 20.
C
CALL PGENV(0.,10.,0.,20.,0,1)
CALL PGLABEL('(x)', '(y)', 'PGPLOT Example 1 - y = x\u2')
C
C Mark five points (coordinates in arrays XS and YS), using symbol
C number 9.
C
CALL PGPOINT(5,XS,YS,9)
C
C Compute the function at 60 points, and use PGLINE to draw it.
C
DO 10 I=1,60
XR(I) = 0.1*I
YR(I) = XR(I)**2
10 CONTINUE
CALL PGLINE(60,XR,YR)
C
C Finally, call PGEND to terminate things properly.
C
CALL PGEND
C
END
F-4 CALLING PGPLOT FROM A C PROGRAM
/* ---------------------------------------------------------------------
* Demonstration program for PGPLOT called from C VMS].
*----------------------------------------------------------------------
*/
#include descrip
main()
{
int i
static float xs] = {1.0, 2.0, 3.0, 4.0, 5.0 }
static float ys] = {1.0, 4.0, 9.0, 16.0, 25.0 }
float xr100], yr100]
long dummy, nx, ny
float xmin, xmax, ymin, ymax
long just, axis, n, symbol
$DESCRIPTOR(device, "?")
$DESCRIPTOR(xlabel, "(x)")
$DESCRIPTOR(ylabel, "(y)")
$DESCRIPTOR(toplabel, "PGPLOT Example 1 - y = x\\u2")
/*
* Call PGBEGIN to initiate PGPLOT and open the output device PGBEGIN
* will prompt the user to supply the device name and type.
*/
dummy = 0
nx = 1
ny = 1
pgbegin(&dummy, &device, &nx, &ny)
/*
* Call PGENV to specify the range of the axes and to draw a box, and
* PGLABEL to label it. The x-axis runs from 0 to 10, and y from 0 to 20.
*/
xmin = 0.0
xmax = 10.0
ymin = 0.0
ymax = 20.0
just = 0
axis = 1
pgenv(&xmin, &xmax, &ymin, &ymax, &just, &axis)
pglabel(&xlabel, &ylabel, &toplabel)
/*
* Mark five points (coordinates in arrays XS and YS), using symbol
* number 9.
*/
n = 5
symbol = 9
pgpoint(&n, xs, ys, &symbol)
/*
* Compute the function at 60 points, and use PGLINE to draw it.
*/
n = 60
for (i=0 i<n i++)
{
xri] = 0.1*i
yri] = xri]*xri]
}
pgline(&n, xr, yr)
/*
* Finally, call PGEND to terminate things properly.
*/
pgend()
}
CALLING PGPLOT FROM A C PROGRAM F-5
/* ---------------------------------------------------------------------
* Demonstration program for PGPLOT called from C Convex UNIX].
*----------------------------------------------------------------------
*/
MAIN__()
{
int i
static float xs] = {1.0, 2.0, 3.0, 4.0, 5.0 }
static float ys] = {1.0, 4.0, 9.0, 16.0, 25.0 }
float xr100], yr100]
long dummy, nx, ny, just, axis, n, symbol
float xmin, xmax, ymin, ymax
/*
* Call PGBEGIN to initiate PGPLOT and open the output device PGBEGIN
* will prompt the user to supply the device name and type.
*/
dummy = 0
nx = 1
ny = 1
pgbegin_(&dummy, "?", &nx, &ny, 1L)
/*
* Call PGENV to specify the range of the axes and to draw a box, and
* PGLABEL to label it. The x-axis runs from 0 to 10, and y from 0 to 20.
*/
xmin = 0.0
xmax = 10.0
ymin = 0.0
ymax = 20.0
just = 0
axis = 1
pgenv_(&xmin, &xmax, &ymin, &ymax, &just, &axis)
pglabel_("(x)", "(y)", "PGPLOT Example 1 - y = x\\u2", 3L, 3L, 27L)
/*
* Mark five points (coordinates in arrays XS and YS), using symbol
* number 9.
*/
n = 5
symbol = 9
pgpoint_(&n, xs, ys, &symbol)
/*
* Compute the function at 60 points, and use PGLINE to draw it.
*/
n = 60
for (i=0 i<n i++)
{
xri] = 0.1*i
yri] = xri]*xri]
}
pgline_(&n, xr, yr)
/*
* Finally, call PGEND to terminate things properly.
*/
pgend_()
}
F-6 CALLING PGPLOT FROM A C PROGRAM