(Last update: 24-Jan-2013)
What follows is a description of the procedure I have followed to have PGPLOT working under Mac OS X and Linux. Note that this is a two step procedure: you need to install the graphic library first, and then define some environment variables that are needed in order to work comfortably with PGPLOT. In this sense it is useful to check that the demo programs run properly.I installed MacPorts downloading the "dmg" disk image installation file
corresponding to my OS Version (Snow Leopard) from here. After the installation,
one needs to execute (in order to ensure you have the latest revisions to the
"Portfiles" needed when building and installing ports):
$ sudo port -v selfupdate
Once MacPorts is available, you can trivially install many packages, in
particular PGPLOT (which in addition requires xorg-server):
$ sudo port install xorg-server
In order to use MacPorts' X11 as the default server, you need to log out,
and then log back in.
$ sudo port install pgplot
Note that the previous command can take several minutes if the system detects
the need of installing additional packages.
The different versions of the PGPLOT library (libpgplot.* and libcpgplot.*) are installed under: /opt/local/lib. The X11 server is installed in /opt/local/bin/pgxwin_server, whereas auxiliary files (including the demos) are placed under:/opt/local/share/pgplot.
After the installation, make sure that the expected environment variables are
properly set (at least PGPLOT_DIR must exist; PGPLOT_DEV is
also quite useful). You can check this by executing:
$ echo $PGPLOT_DIR
$ echo $PGPLOT_DEV
If the previous environment variables are not set, you can easily define them:
$ export PGPLOT_DIR=/opt/local/lib
$ export PGPLOT_DEV=/Xserve
It is useful to introduce those definitions in the .bashrc file at the
home directory of the user.
Execute any of the demos in order to check that everything is fine:
$ /opt/local/share/pgplot/examples/pgdemo1
$ /opt/local/share/pgplot/examples/pgdemo2
$ /opt/local/share/pgplot/examples/pgdemo3
...
Finally, compile your own code. For example, is gfortran was the
fortran compiler employed to install PGPLOT, the following command
should work:
$ gfortran -o outputFileName inputFotranFile.f -L/opt/local/lib -lpgplot
-lX11
Note that you should use the same fortran compiler to install PGPLOT and to
compile your own files.
In the above example the X11 library was assumed to be installed in
/opt/local/lib. If this is not the case, include an extra
-L/directory_path_to_libX11 in the compilation command before
-lpgplot.
(Mac users may find also useful the instructions provided by Benjamin Weiner)
After the installation, make sure that the expected environment variables are
properly set (at least PGPLOT_DIR must exist; PGPLOT_DEV is
also quite useful):
$ export PGPLOT_DIR=/usr/local/pgplot
$ export PGPLOT_DEV=/Xserve
It is useful to introduce those definitions in the .bashrc file at the
home directory of the user.
Execute any of the demos in order to check that everything is fine:
$ /usr/local/pgplot/pgdemo1
$ /usr/local/pgplot/pgdemo2
$ /usr/local/pgplot/pgdemo3
...
Finally, compile your own code. For example, is gfortran was the
fortran compiler employed to install PGPLOT, the following command
should work:
$ gfortran -o outputFileName inputFotranFile.f -L/usr/local/pgplot
-L/usr/X11/lib -lpgplot -lX11
Note that you should use the same fortran compiler to install PGPLOT and to
compile your own files.
In the above example the X11 library was assumed to be installed in
/usr/X11/lib. If this is not the case, include the actual directory
using -L/directory_path_to_libX11 in the compilation instead of
-L/usr/X11/lib above.