1.はじめに


1.1 PGPLOT とは?

PGPLOT は、さまざまなグラフィックデバイス(画面や、プリンタで印刷するためのファイルなど)上に図やグラフを描くことを目的として作られた、Fortran 言語のサブルーチンパッケージである。元々はカリフォルニア工科大学天文学科で天文観測データの処理を目的として開発されたが、それ以外の幅広い用途にも耐える汎用性をもち、比較的簡単なプログラミングで、X-Yプロットをしたり様々な2次元の作図を行うことが可能である。

このマニュアルに登場する全てのサンプルは標準の Fortran-77 言語で書かれている。PGPLOT 自体も大部分、標準の Fortran-77 言語で書かれている。

pgplot を使う時に Fortran 言語でプログラムを書かねばならない訳ではない。基本的には Fortran でも良いし、C 言語でも構わない。ただし、C 言語でpgplot を使う場合は、若干の注意点があるらしい。(詳しくは Appendix C を参照)


1.2 このマニュアルについて

本章では以下、各自のプログラムの中での 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 の英語版マニュアルのうち、地球物理学実験を履修している学生諸君にとって必要と思われる範囲のみを日本語に訳してある。したがって、英語の部分は読まなくても、概ね使用には差し支えない。また、皆さんのプログラミングの際の参考となるよう、簡単な説明付きのサンプルプログラム集を用意した。あわせて利用されたい。


1.3 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]

を実行すれば良い。

なお、ここに記したプログラムのコンパイルの仕方や実行後の操作(印刷、画面表示など)は、あくまで現在の地球物理学実験の計算機環境に限ったものである。


1.4 Graphics Devices

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.

1.4.1 Device Name

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.

1.4.2 Device Type

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.

1.4.3 Examples

A window on the default Xwindow display screen:

Tektronix 4006/4010 terminal:

Disk file, PostScript format:

1.5 Environment Variables

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:

PGPLOT_DIR
Directory name. Unless told otherwise by environment variables PGPLOT_FONT and PGPLOT_RGB, PGPLOT looks for the files it needs at run-time in this directory. The binary font file is 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/
PGPLOT_FONT
File name for the binary font file. If this variable is defined, PGPLOT will interpret the value as a file name for the binary font file. If it is not defined, PGPLOT will look for the binary font file under name grfont.dat in the directory specified by PGPLOT_DIR. e.g.
setenv PGPLOT_FONT /usr/local/pgplot/grfont.dat
PGPLOT_RGB
File name for the color-name database. If this variable is defined, PGPLOT will interpret the value as a file name for the color-name database. If it is not defined, PGPLOT will look for the binary font file under name 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
PGPLOT_DEV
Device specification. If this variable is defined, it is used as the default device specification: if the device specification given to 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
PGPLOT_TYPE
Device type. If this variable is defined, it is used as the default device type: if the device specification supplied to PGBEG consists of a file name without a trailing slash (/) and device type, this device type is assumed. e.g.
setenv PGPLOT_TYPE ps
PGPLOT_ENVOPT
Character string. This affects programs that call routine 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
PGPLOT_FOREGROUND
Color name. This variable can be used to change the color representation of color index 1 (the ``foreground'' color) from its device-dependent default (usually white or black). The value of the variable should be a color name defined in the color-name database. If the variable is defined, the effect is the same as a call to 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
PGPLOT_BACKGROUND
Color name. This variable can be used to change the color representation of color index 0 (the ``background'' color) from its device-dependent default (usually black or white). The value of the variable should be a color name defined in the color-name database. If the variable is defined, the effect is the same as a call to 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
PGPLOT_BUFFER
Switch. If this variable is defined, with any non-null value, PGPLOT buffers output. The effect is the same as if 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
PGPLOT_DEBUG
Switch. If this variable is defined, with any non-null value, PGPLOT will print some debugging information on the standard output. Currently this includes attempts to open input files (binary font file and color-name database), and, when the null device is selected for output, statistics of device-driver calls. e.g.
setenv PGPLOT_DEBUG yes

In addition to these environment variables, several device drivers use device-specific environment variables. See the device descriptions for details.


Previous: 目次  Next: 第2章