Manually compiling and installing PGPlot

Compiling and installing PGPlot may be tricky, because no default build tools are provided. Common issues include compilation problems in general, no generation of a shared library or problems building it (-fPIC), no linking against X11, etc. Stealing from the Gentoo Linux PGPlot ebuild script, here is how it can be done on Gentoo and Arch Linux, and hopefully on MacOSX.

As a normal user, download and unpack the necessary tarballs:

$ wget ftp://ftp.astro.caltech.edu/pub/pgplot/pgplot522.tar.gz # Download the latest PGPlot tarball
$ tar xfz pgplot522.tar.gz # Unpack it
$ cd pgplot/
$ wget http://astrofloyd.org/downloads/pgplot_gentoo_patches.tar.gz # Download the Gentoo patches
$ tar xfz pgplot_gentoo_patches.tar.gz # Unpack them

Apply Gentoo patches:

$ patch sys_linux/g77_gcc.conf gentoo_patches/pgplot-compile-setup.patch
$ patch drivers.list gentoo_patches/pgplot-drivers.patch
$ #patch sys/grtermio.c gentoo_patches/pgplot-headers.patch  # May give errors - try/fix if you need it
$ patch drivers/pndriv.c gentoo_patches/pgplot-libpng15.patch
$ patch makemake gentoo_patches/pgplot-makemake.patch
$ #patch pgdispd/proccom.c gentoo_patches/pgplot-pgdisp.patch  # May give errors - try/fix if you need it
$ patch drivers/xtk/tkpgplot.c gentoo_patches/pgplot-tk86.patch

For 64-bit systems:

$ sed -i -e 's/INTEGER PIXMAP/INTEGER*8 PIXMAP/g' drivers/{gi,pp,wd}driv.f || echo "sed 64bits failed"
$ cp sys_linux/g77_gcc.conf local.conf

When using the gcc/gfortran compilers:

$ sed -i -e "s:FCOMPL=.*:FCOMPL=\"gfortran\":g" -e "s:CCOMPL=.*:CCOMPL=\"gcc\":g" local.conf || echo "sed gcc compilers failed" # Set compilers to gfortran and gcc

When using the Intel compilers:

$ sed -i -e "s:FCOMPL=.*:FCOMPL=\"ifort\":g" -e "s:CCOMPL=.*:CCOMPL=\"icc\":g" local.conf || echo "sed Intel compilers failed" # Set compilers to ifort and icc
$ sed -i -e 's/-Wall//g' -e 's/TK_LIBS="/TK_LIBS="-nofor-main /' local.conf || echo "sed Intel compiler options failed"
$ sed -i -e "s:/usr/local/pgplot:/usr/lib/pgplot:g" -e "s:/usr/local/bin:/usr/bin:g" src/grgfil.f makehtml maketex || echo "sed path failed" # Ensure your lib and bin dir are specified

End of the Gentoo fixes

Configure and compile:

$ ./makemake . linux # Creates makefile using local.conf
$ make -j6 CFLAGC="${CFLAGC} -fPIC" FFLAGC="${FFLAGC} -fPIC" shared cpg-shared pgxwin_server pgdisp pgplot.doc # Creates the shared/dynamic libraries - set the -j value to your number of cores
$ make clean && make -j6 all cpg # Only if you need the static libraries
$ make clean
$ strip --strip-unneeded -R .comment -R .GCC.command.line -R .note.gnu.gold-version lib*pgplot.* pgdisp pgxwin_server  # Remove unnecessary symbols

Create documentation:

$ export VARTEXFONTS="./fonts"
$ make pgplot.html pgplot-routines.tex
$ pdflatex -draftmode pgplot-routines.tex ; pdflatex pgplot-routines.tex

Installation. If you want to install PGPlot in the default locations in your filesystem, you must do these steps as root. If you install PGPlot in your home directory, there’s no need — proceed as a normal user. The directories below are typical on a Linux system, but may be different on yours — please check in advance. Make sure the target directories exist in both cases.

# cp grexec.f grfont.dat grpckg1.inc pgplot.inc rgb.txt /usr/lib/pgplot/
# cp lib*pgplot.* /usr/lib/
# cp cpgplot.h /usr/include/

Install documentation:

# cp aaaread.me pgplot.doc cpg/cpgplot.doc applications/curvefit/curvefit.doc pgplot.html pgplot-routines.pdf pgplot-routines.tex /usr/share/doc/pgplot/
# cp pgdispd/aaaread.me /usr/share/doc/pgplot/pgdispd.txt

You will need to set the environment variable to the proper path of grfont.dat in order to use text (e.g. insert in your ~/.bashrc):

$ PGPLOT_FONT=/usr/lib/pgplot/grfont.dat

Notes:

  • for safety reasons, most steps are executed as a normal user. If you want to install PGPlot in your home directory, there’s no need to become root at any point
  • the Gentoo bits were stolen from the pgplot-5.2.2-r6.ebuild on 2015-10-11
  • on MacOSX, shared/dynamic libraries are called *.dylib, rather than *.so. You may want to rename them
  • the png driver is not very good — if you want bitmap ouput with more than 256 colours, create ppm (and convert using ImageMagick’s $ convert -depth 8 file.ppm file.png)
This entry was posted in All, Software and tagged , , , , . Bookmark the permalink.

2 Responses to Manually compiling and installing PGPlot

  1. Lazaro says:

    Excellent tutorial!!!

    • AstroFloyd says:

      Well, basically I cheat by listing what the Gentoo scripts do. The scheme I used before (own work by trial and error) worked as well, but wasn’t as good as this 😉

Leave a comment