Benjamin Weiner, May 2012
PGPLOT is a library of plotting subroutines written by Tim Pearson, callable from Fortran and C, that have been used in a variety of astronomy programs, and some other software packages. PGPLOT is free for non-commercial use and downloadable as source. Although a new version has not appeared for some time, it is convenient, flexible, and many people and a number of useful programs depend on it.
Historically you typically installed PGPLOT by either compiling from source or installing a software package that included a compiled library (libpgplot.a) and various other stuff like fonts. This used to be fairly easy on Linux or Mac, but starting around OS X 10.6 and/or 64-bit CPU Macs, I and other people had difficulty compiling PGPLOT on OS X. Typically one gets an error message like: /usr/bin/ranlib: archive member: libpgplot.a(grdate.o) cputype (16777223) does not match previous archive members cputype (7) (all members must match)
.
If you google around you can find lots of puzzled people, and a number of web pages that suggest workarounds (not all of which are specifically for 10.6; none have solved the problem for me). I've diagnosed the issue and provide here a couple of configuration files which you can add to a regular PGPLOT source distribution so it will compile correctly.
sudo mkdir /usr/local/src
cd /usr/local/src
, copy PGPLOT distribution there and untar it, which will create a pgplot/
subdirectory: sudo tar zxvf pgplot5.2.tar.gz
/usr/local/src/pgplot
directory: cd /usr/local/src/pgplot ; sudo tar xvf pgplot_macosx_conf.tar
. This will make a subdirectory called sys_macosx
with three configuration files.sudo mkdir /usr/local/lib/pgplot
sudo cp /usr/local/src/pgplot/drivers.list /usr/local/lib/pgplot
/GIF, /NULL, /PS, /VPS, /CPS, /VCPS, /XTERM, /XWINDOW
, and /XSERVE
. Trying /PNG
or /TPNG
will cause a compilation failure; a note on how to fix this is below.makemake
configuration script using one of my new config files: choose one depending on whether you will compile other programs with g77 or gfortran and in 32 or 64 bit.sudo /usr/local/src/pgplot/makemake /usr/local/src/pgplot macosx g77_gcc_32
sudo /usr/local/src/pgplot/makemake /usr/local/src/pgplot macosx gfortran_gcc_32
sudo /usr/local/src/pgplot/makemake /usr/local/src/pgplot macosx gfortran_gcc_64
sudo make all
sudo make lib grfont.dat pgplot.doc pgxwin_server
, but this should not usually happen.sudo make clean ; sudo rm libpgplot.a
. This will remove any intermediate partially-compiled libraries.You now have a library, libpgplot.a
.
To compile programs using it, link to /usr/local/lib/pgplot/libpgplot.a /usr/X11/lib/libX11.dylib
For example g77 -o myprog myprog.f /usr/local/lib/pgplot/libpgplot.a /usr/X11/lib/libX11.dylib
To run programs with PGPLOT, don't forget to set the environment variable PGPLOT_DIR
to the library directory. Otherwise it can't find the fonts at runtime. This is best done in a startup file like .bash_profile
or .cshrc
, for example for bash: export PGPLOT_DIR=/usr/local/lib/pgplot
; and for csh: setenv PGPLOT_DIR /usr/local/lib/pgplot
You must use the same compiler for your program that you used for the library: g77 OR gfortran. You could compile PGPLOT libraries with the two compilers in two different directories and use one or the other as needed.
The /xs
device should work when run from a mac Terminal, but /xt
won't. /xt
will work when run from an xterm
under X11.
If you want to get the /PNG
driver to work, uncomment it in drivers.list, and after running makemake
and before compiling, edit the makefile to comment out the following line: pndriv.o : ./png.h ./pngconf.h ./zlib.h ./zconf.h
. This has an incorrect location for the PNG library header files which causes compilation to fail.
Mac OS X for 64-bit machines allows you to run 32 or 64 bit binaries. But the inexplicable error message from ranlib above is complaining that it can't mix object files compiled for 32 bit cputype (i386) and 64 bit (x86_64) into a single object library archive, the libpgplot.a file.
The problem is that PGPLOT source is actually a mix of Fortran and C. The Fortran compilers compile into 32-bit by default (g77 is only 32 bit capable) and the C compiler now compiles into 64 bit by default. So ranlib has to mix 32 and 64 bit object files and it can't do that. This is why it only became a problem with 64 bit Macs and OS X 10.6. The new config files force the C compiler to compile in 32 bit with the "-m32
" option. So then the files are all 32-bit and it compiles ok. For 64 bit the config file forces gfortran to compile in 64 bit with "-m64
". With Apple's C compiler you can also use "-arch i386
" and "-arch x86_64
" to force 32 or 64 bit. The "-m32
" and "-m64
" options should work with a non-Apple gcc, although I have not tested them.
Other notes: I have not tested all the more exotic drivers and library locations, and if you do something arcane like use a PGPLOT-Tk interface, it may require adjustment. See above for how to get the PNG driver to work by editing the makefile.
I tested this on OS X 10.6 Snow Leopard, and have not tested PGPLOT on OS X 10.7 Lion myself. I have one report that forcing the 64-bit option by using a configuration similar to "gfortran_gcc_64" will work, so try that.
Apple's gcc C compiler comes with Xcode, their development kit. Xcode was on my OS X install CDs, but is not installed by default. You can also download it from Apple.
Mac OS X versions of gfortran, g77, and non-Apple versions of gcc can be downloaded from http://hpc.sourceforge.net/. The HPC page does not have quick links to binaries of the compilers for older versions of Mac OS X, but they are in the file tree at http://sourceforge.net/projects/hpc/files/hpc/. Some other useful information about Fortran and Mac is listed here.
Benjamin Weiner, email bjw at as.arizona.edu
29 May 2012, updated 6 June 2012, 10 April 2013