PGPLOT on Snow Leopard 3
One of the packages I use a lot in my research is the venerable PGPLOT package put together by Tim Pearson (currently at Caltech). You see evidence of this set of plotting routines in the figures in many astronomy papers from the 1980s onward. PGPLOT was written in FORTRAN and supports a wide variety of drivers to export its graphics, including color postscript, GIF, and Xwindows displays. In addition to using PGPLOT, I use PGPLOT.pm, a perl module for calling PGPLOT from perl scripts written by Karl Glazebrook. I have used it to make interactive perl scripts for ‘marking’ spectral lines in HI spectra among other things.
When I moved to Snow Leopard, I discovered that I could not get PGPLOT.pm compiled against the PGPLOT package that comes with Scisoft OSX and soon realized this was because Perl on my Mac Pro is 64-bit whereas the PGPLOT package included with Scisoft OSX was 32 bit. I decided to compile PGPLOT 64-bit native to try to remedy the problem and on the way discovered a few other issues. Here’s what I did to get both PGPLOT and PGPLOT.pm working under Snow Leopard (on both 32-bit and 64-bit computers).
- Install GFORTRAN: The first thing I did was install Gnu Fortran (aka gfortran) as configured by Gaurav Hanna at the High Performance Computing for Mac OS X website. It turns out the version he compiled for Snow Leopard (here) is 64-bit Intel ONLY, so for my venerable first generation MacBook Pro, I grabbed the 32-bit Intel Leopard version (here), which worked fine in Snow Leopard. Installing them is a simple matter of issuing the proper tar command to unpack the tarball into
/usr/local, where all the binaries are installed.-
sudo tar -C / -xzvf gfortran-snwleo-intel.bin.gz
(for the 64-bit Snow Leopard version) -
sudo tar -C / -xzvf gfortran-leopard-intel.bin.gz
(for the 32-bit Leopard version)
Once they are installed, you simply have to make sure
/usr/local/binis in your$PATH. -
- Install PGPLOT: I grabbed the PGPLOT source code from Tim Pearson’s website (here) and untarred the tarball into
/usr/local/src/pgplot, the default location the code expects to be in (based on the instructions in theinstall-unix.txtfile included in the source code tarball).
sudo tar -C /usr/local/src/ -xzvf pgplot pgplot5.2.tar.gz
- Install sys_macosx configuration: The PGPLOT source code has various compiler configurations stored in “configuration directories” but it doesn’t come with one for Mac OS X. The MacPorts folks, when they ported PGPLOT, did create such a configuration. However, that configuration is hard coded to require AquaTerm, a nice MacOS X native display program that has not been made 64-bit compliant yet. Furthermore, their version of the configuration requires g77 to compile. The only g77 I could find was not 6-bit compliant, so I ended up hacking the
sys_macosx/configuration directory to include a new gfortran configuration that didn’t require AquaTerm. I am making a tarball of that configuration directory available in the pgplot5.2_macosx_addition.tgz which you can download and unpack into the PGPLOT source directory using:
sudo tar -C -xzvf /usr/local/src/pgplot5.2_macosx_addition.tgz
[The above line was edited to fix an error noticed by a commenter. - Juan (Oct. 24, 2009)] - Compile the PGPLOT binaries: At this point, if you follow the instructions in the
install-unix.txtfile in the PGPLOT directory you will be fine, baring in mind the configuration you want to use is the “maxosx gfortran_gcc” configuration. However, I will outline the steps I used below.- Create a PGPLOT library/binary directory:Create a directory to contain the PGPLOT libraries. I created
/usr/local/pgplotusing the command:
sudo mkdir /usr/local/pgplot
- Choose the graphics drivers you want: Copy the drivers.list file from the source directory to this new pgplot directory and edit it to match your needs:
(You can replace this last step with emacs or whatever text editor you prefer). You make a graphics driver part of the compilation by removing the leading exclamation point from the line. I choose to activate the X-Window drivers, the GIF drivers (to create GIF images), and the PostScript printer drivers (which you can use to create PostScript versions of plots for publication). Be aware PNG support requires libpng be installed.cd /usr/local/pgplot sudo cp /usr/local/src/pgplot/drivers.list . sudo vi drivers.list
- Create the makefile: We now need to create the makefile using PGPLOT’s
makemakescript. Within the/usr/local/pgplotdirectory execute:
sudo /usr/local/src/pgplot/makemake /usr/local/src/pgplot macosx gfortran_gcc
which should result in the following output
Reading configuration file: /usr/local/src/pgplot/sys_macosx/gfortran_gcc.conf Selecting uncommented drivers from ./drivers.list Found drivers GIDRIV NUDRIV PSDRIV XWDRIV Creating make file: makefile Determining object file dependencies.
- Create all the binaries: Now you just have to create all the binaries, which is a simple
makecommand:
sudo make
Assuming everything proceeds without error, you should then see at the end of the output
At this point, you should (if you are going to use PGPLOT within perl or C compile the C library as well using*** Finished compilation of PGPLOT *** Note that if you plan to install PGPLOT in a different directory than the current one, the following files will be needed. libpgplot.a libpgplot.dylib grfont.dat rgb.txt pgxwin_server Also note that subsequent usage of PGPLOT programs requires that the full path of the chosen installation directory be named in an environment variable named PGPLOT_DIR.
sudo make cpg
Finally, clean out all the temporary object files, you don’t need them. Do this using the makefile by typing
sudo make clean
If you want to test if things are working you can run one of the PGPLOT demo programs created in this directory. However, thepgdemo*executables seem hard coded to expect the pgplot libraries in the/usr/local/libdirectory, to it might be a good idea to do the following step before trying the demos. [Edited in response to a comment about the demos not working. - Juan (Oct. 24, 2009)] - Copy library and header files: This step is optional, but since most programs (including the
pgdemo*executables) don’t look in/usr/local/pgplotfor library and header files, I copy them to/usr/local/liband/usr/local/includerespectively using
- Create a PGPLOT library/binary directory:Create a directory to contain the PGPLOT libraries. I created
- Making sure I use these PGPLOT binaries: Since I am using Scisoft OSX, I modified my
~/.tcshrcfile to change the PGPLOT related environmental variables after loading Scisoft’s environment
setenv PGPLOT_DIR /usr/local/pgplot/
. If you are not using Scisoft, you can place these lines anywhere in your~/.tcshrcfile. If you stick to using bash, then the corresponding lines in the~/.bashrcfile that you need to create (after setting up Scisoft, if you are using that) are:
export PGPLOT_DIR=/usr/local/pgplot/
At this point you have a working PGPLOT set of libraries installed. You can stop here if you just want to use PGPLOT from C or FORTRAN source code. If you want to use PGPLOT from within Perl, you need to go further. - Install the ExtUtils:: F77 perl module: In order to install PGPLOT support, you need to install ExtUtils:F77 first. You can download ExtUtils::F77 here and once you untar the tarball,
tar xzvf ExtUtils-F77-1.16.tar.gz
it can be easily compiled using the following standard perl module compilation steps:
cd ExtUtils-F77-1.16 perl Makefile.PL make sudo make install
- Install the PGPLOT perl module: You can download PGPLOT here. Untar the tarball.
tar xzvf PGPLOT-2.20.tar.gz
We start as we usually do for Perl modules, creating the makefile using the Makefile.PL script:
cd ExtUtils-F77-1.16
Unfortunately, theMakefile.PLscript will create amakefilethis creates doesn’t work because it doesn’t call gfortran so we have to change theMakefile.PLscript to know about gfortran. So load Makefile.PL and edit the line that reads
use ExtUtils::F77;
to read
use ExtUtils::F77 qw{Darwin GFortran};Once you have done that, create themakefileusing
perl Makefile.PL
Now you still have a problem because thismakefileis designed to create a universal binary. However, depending on which platform you downloaded gfortran for (in step 1), you only have 64-bit intel or 32-bit intel support. So you have to delete all mentions of
-arch ppc
from themakefileas well as removing
-arch i386
if you are compiling on a 64-bit system or
-arch x86_64
if you are compiling on a 32-bit system. Once you have done that, you can finish installing the perl module using:
I did have some issues withmake make test sudo make install
make testbecause it couldn’t find my X-windows driver due to a bad environment, but the compile reported no errors and I was able to get themake testto work once I had the proper environmental variable settings forPGPLOT_DIR(see step 5).
So that is it, I now have working PGPLOT installations with perl support on both my 32-bit MacBook Pro and my 64-bit Mac Pro.



