PGPLOT は、さまざまなグラフィックデバイス(画面や、プリンタで印刷するためのファイルなど)上に図やグラフを描くことを目的として作られた、Fortran 言語のサブルーチンパッケージである。元々はカリフォルニア工科大学天文学科で天文観測データの処理を目的として開発されたが、それ以外の幅広い用途にも耐える汎用性をもち、比較的簡単なプログラミングで、X-Yプロットをしたり様々な2次元の作図を行うことが可能である。
このマニュアルに登場する全てのサンプルは標準の Fortran-77 言語で書かれている。PGPLOT 自体も大部分、標準の Fortran-77 言語で書かれている。
pgplot を使う時に Fortran 言語でプログラムを書かねばならない訳ではない。基本的には Fortran でも良いし、C 言語でも構わない。ただし、C 言語でpgplot を使う場合は、若干の注意点があるらしい。(詳しくは Appendix C を参照)
本章では以下、各自のプログラムの中での pgplot のライブラリの呼び出し方や、pgplot で使うことが出来るグラフィックデバイスの種類について説明する。
第2章では、最低限必要な pgplot のサブルーチンを使ってグラフを描く方法を紹介するとともに、それぞれのサブルーチンの役割について説明する。したがって第2章を読めば、pgplot を使った基本的な作図プログラムを自分で書くことができるようになる(ハズ)。
個々のサブルーチンについて詳しい説明は、付録A を参照されたい。
第3章〜第5章では、pgplot の基本的な要素について紹介する。第3章では、ページ上のグラフの配置やスケーリング(縮尺)について説明する。第4章では、pgplot の
といった基本的な作図機能(「プリミティヴ」)について述べる。第5章では、これらのプリミティヴの『属性』(色、線の太さや種類、記号の種類、塗りつぶしのスタイル、文字の字体など)を変更する方法を説明する。第6章では、これらの基本サブルーチンを使って、より複雑な図(例えば、関数のプロット、ヒストグラム、棒グラフ、等値線図など)を描くための「高度な」サブルーチンについて述べる。第7章では、カーソルやマウス等を使って「会話的」に作図を行うための pgplot の機能について記述する。
この他に、本マニュアルには7つの付録が付いている。付録Aは、pgplot の総てのサブルーチンのリストとそれらについての詳細な説明書である。付録B には、グラフに注釈などを付ける際に用いることが出来る pgplot の文字や記号の一覧を示してある。Appendix C は、C 言語のプログラムで pgplot のサブルーチンを呼び出す方法についてまとめてある。Appendix D には、pgplot でサポートされているデバイスの詳細が書いてある。Appendix E は、pgplot を拡張して元々サポートされていない新たなデバイスを利用できるようにするための手引きである。Appendix F では pgplot のインストール方法を示し、Appendix G には pgplot を新しいOSに組み込むための幾つかのヒントが書かれている。
なお、この日本語版では、元々の pgplot の英語版マニュアルのうち、地球物理学実験を履修している学生諸君にとって必要と思われる範囲のみを日本語に訳してある。したがって、英語の部分は読まなくても、概ね使用には差し支えない。また、皆さんのプログラミングの際の参考となるよう、簡単な説明付きのサンプルプログラム集を用意した。あわせて利用されたい。
pgplot のサブルーチンを使って作図するためには、文法にしたがいプログラムを書いたあとで、コンパイル時に pgplot のサブルーチンライブラリとリンクさせなければならない。
たとえば今、honyarara.f という名前の作図プログラムを作ったとして、これを実行させるには、以下のようなコマンドを実行する(赤字が、実際に打ち込む部分。[CR}
は、リターン(Enter)キーを押すことを意味する)。
> pgf honyarara [CR]
すると、文法エラーなどが無ければ、同じディレクトリ内に ".f" の無い実行形式のプログラム "honyarara" が出来る。次に、これを実行するためには、
> honyarara [CR]
と打ち込む。すると、出力デバイスをプログラム内で指定していない限り(特に意図がなければ指定しない方が便利。詳しくは pgopen や pgbeg の説明を参照)、pgplot から出力デバイスを尋ねられる。画面に表示する場合は、単にリターンキーを押す。学生実験のプリンタ(PostScript プリンタ)で印刷するためには、/ps [CR]
と入力する。すると、前者の場合は直ちに画面に結果が表示され、後者の場合は "pgplot.ps" という名前のPostScriptファイル(本実験ではプリンタ出力用ファイルのこと。略して PS ファイルとも呼ぶ)が作られる。
作成したPSファイルをプリンタに出力するためには、
> lpr pgplot.ps [CR]
を実行する。また、一旦PSファイルにした図を再び画面に表示させることも出来る。そのためには、
> gs pgplot.ps [CR]
を実行すれば良い。
なお、ここに記したプログラムのコンパイルの仕方や実行後の操作(印刷、画面表示など)は、あくまで現在の地球物理学実験の計算機環境に限ったものである。
Graphics devices fall into two classes: devices which produce a hardcopy output, usually on paper; and interactive devices, which usually display the plot on a TV monitor. Some of the interactive devices allow modification to the displayed picture, and some have a movable cursor which can be used as a graphical input device. There is also a ``null device,'' to which unwanted graphical output can be directed. Hardcopy devices are not used interactively. One must first create a disk file and then send it to the appropriate device with a print or copy command. Consult Appendix D (or your System Manager) to determine the appropriate device-specific command.
A PGPLOT graphical output device is described by a ``device specification'' that consists of two parts, separated by a slash (/): the device name or file name, and the device type.
Device name or file name is the name by which the output device is
known to the operating system. For most
hardcopy devices, this should be the name of a disk file, while for
interactive devices, it should be the name of a device of the
appropriate type; in both cases, the name should be specified
according to the syntax of the operating system in use. If the device
or file name includes a slash (/
), enclose the name in
double quotation marks ("
). If the device name is
omitted from the device specification, a default device is used, the
default depending on the device type (see Appendix D). In Unix, device
and file names are case-sensitive.
Device type tells PGPLOT what sort of graphical device it is.
Appendix D lists the device types available at the time of writing,
together with the names by which they are known to PGPLOT. If the
device type is omitted, a system-dependent default type is assumed
(this is the value of the ``environment variable''
PGPLOT_TYPE
). The device type is not case-sensitive: you
can use uppercase or lowercase letters, or a mixture of the two.
A window on the default Xwindow display screen:
/XWINDOW
Tektronix 4006/4010 terminal:
/TEK
(the logged-in terminal) tta4/TEK
(VMS device _TTA4:
) "/dev/tty6"/TEK
(Unix device tty6
)Disk file, PostScript format:
plot.ps/PS
(in the current default directory)plot.ps/VPS
(the same, but in portrait orientation) "/scr/tjp/plot.ps"/PS
(in a specified directory)
Some aspects of the behavior of PGPLOT can be modified at run time by
specifying environment variables. The variables have names
which begin with PGPLOT_
.
In UNIX systems, environment variables can be defined using the shell. For the bash, bourne (sh), or korn (ksh) shell, use commands like the following:
PGPLOT_DIR="/usr/local/pgplot"; export PGPLOT_DIR
For the c-shell and tcsh, use
setenv PGPLOT_DIR "/usr/local/pgplot/"
Note that the names of PGPLOT environment variables are specified
using upper case characters, e.g. PGPLOT_DIR
, not
pgplot_dir
.
In VMS systems, environment variables are ``logical names'' and can be
defined with the DEFINE
or ASSIGN
command,
e.g.
$ DEFINE PGPLOT_DIR user_disk:[local.pgplot] $ DEASSIGN PGPLOT_DIR
The following environment variables affect all PGPLOT programs:
grfont.dat
and the color-name database is
rgb.txt
. If this variable is undefined, or if the
specified file does not exist in this directory, PGPLOT looks in the
current default directory. e.g.setenv PGPLOT_DIR /usr/local/lib/pgplot/
grfont.dat
in the
directory specified by PGPLOT_DIR. e.g.setenv PGPLOT_FONT /usr/local/pgplot/grfont.dat
rgb.txt
in the
directory specified by PGPLOT_DIR. The color-name database is only
used by programs that call PGSCRN
, or when environment
variable PGPLOT_BACKGROUND or PGPLOT_FOREGROUND is defined. e.g.setenv PGPLOT_RGB /usr/local/pgplot/rgb.txt
PGBEG
(or supplied by the user in
response to the PGPLOT prompt) is a blank string, this device
specification is used, e.g. setenv PGPLOT_DEV /xwin
PGBEG
consists of a file name without a
trailing slash (/) and device type, this device type is
assumed. e.g. setenv PGPLOT_TYPE ps
PGENV
. The characters supplied are
options for PGBOX
(in addition to those assumed by
default by PGENV
, i.e., `BCNST'. Useful options include
`G' to draw a grid, `V' to draw y-axis labels upright, `I' to draw
axis tick marks outside the box instead of inside, `1' or `2' to
change the numeric label style. e.g. setenv PGPLOT_ENVOPT IVG
PGSCRN
with this name as argument
immediately after the graphics device is opened. Color names are
case-insensitive and embedded spaces are ignored. e.g. setenv PGPLOT_FOREGROUND springgreen
PGSCRN
with this name as argument
immediately after the graphics device is opened. On devices without a
color lookup table, changing the background color only affects the
color of elements explicitly drawn in color index 0. To ensure that
the background of the entire view surface changes to the new color, it
is also necessary to call PGERAS
at the start of each
page. e.g. setenv PGPLOT_BACKGROUND slateblue
PGBBUF
is called immediately after opening the
graphics device, and PGEBUF
immediately before closing
it. It will have no effect on programs that already include these
calls. On some devices, buffering output can lead to large
improvements in speed, but enabling buffering may upset
synchronization between graphical output and other program
activity. e.g.setenv PGPLOT_BUFFER yes
setenv PGPLOT_DEBUG yes
In addition to these environment variables, several device drivers use device-specific environment variables. See the device descriptions for details.