edit · print · PDF

Please note that all the SIEpedia's articles address specific issues or questions raised by IAC users, so they do not attempt to be rigorous or exhaustive, and may or may not be useful or applicable in different or more general contexts.

How to install PGPLOT with TK and PNG drivers in Mac OS X

Compiling and installing PGPLOT in a Mac OS X box from source code, while not too complicated, requires some care and modifications to a couple of files.

You can also install pgplot via MacPorts; however, while it apparently includes the PNG driver, it does not include the TK driver, which I needed to build the E3D - The Euro3D Visualization Tool.

I managed to install PGPLOT with both the PNG and the TK drivers in an iMac with Lion v10.7.4. Here I explain step by step the installation procedure, which is based on the excellent Compiling PGPLOT on Mac OS X webpage by Benjamin Weiner.

General Mac OS X Lion setup

  • I use wget to retrieve tarfiles. wget can be installed using MacPorts.
  • I generally set /scratch/software/ as the root of the directory tree where I download and compile software packages; it's owned by myself. /usr/pkg/ is the root of the directory tree where packages are installed; it's owned by root, so we need to use sudo to work in it. Replace both directories with the paths of your choice.
  • The package management system I use is MacPorts. You must have at least libpng and zlib.
  • gfortran and gcc compilers from HPC. I do not know if a different set of compilers, for instance the one installed by MacPorts, will work too (though I think it's likely they'll do).
  • I set up an alias for sudo so that it recognizes all my aliases. Instructions at the end of this page.

Download and uncompress pgplot tarfiles

Create installation directory and select drivers.

  • Create installation target directory:
    sudo mkdir -p /usr/pkg/pgplot
  • Copy the drivers.list file
    cd /usr/pkg/pgplot/
    sudo cp /scratch/software/pgplot/drivers.list .
  • Edit drivers file to select the drivers we need. This is done simply by removing the comment sign (the !) at the beginning of the line:
    sudo nedit drivers.list
    (I use nedit, but you can use your favorite editor.) The drivers I selected are: /GIF, /VGIF, /NULL, /PS, /VPS, /CPS, /VCPS, /XTERM, /XWINDOW, /XSERVE, /PNG, /TPNG, /XTK, /LATEX

Modify configuration files and patch a C source file.

  • Select the compilers (gfortran and gcc) from the HPC set. We will compile in 64-bit.
    cd /scratch/software/pgplot/sys_macosx
    nedit gfortran_gcc_64.conf
    and change the FCOMPL and CCOMPL lines as:
    FCOMPL="/usr/local/bin/gfortran"
    CCOMPL="/usr/local/bin/gcc"
    (note that in this file SHARED_LIB="", so we do not create shared libs, only static).
  • Modify makemake file to fix problem with the PNG driver.
    cd /scratch/software/pgplot/
    nedit makemake
    Change the line:
    pndriv.o : ./png.h ./pngconf.h ./zlib.h ./zconf.h
    to
    pndriv.o : /opt/local/include/png.h /opt/local/include/pngconf.h /opt/local/include/zlib.h /opt/local/include/zconf.h
    (here I'm using the header files provided by MacPorts)
  • Last, edit file pndriv.c to fix a problem with a pointer, which otherwise makes the compilation abort with an "error: dereferencing pointer to incomplete type" message.
    nedit /scratch/software/pgplot/drivers/pndriv.c
    and change setjmp(png_ptr->jmpbuf) to setjmp(png_jmpbuf(png_ptr))
  • If you wish to enable the GIF driver, there is a further step: just follow the simple instructions in https://trac.macports.org/ticket/37551 (thanks to mcs@iaa.es for pointing this out).

Compile

  • Run makemake
    cd /usr/pkg/pgplot/
    sudo /scratch/software/pgplot/makemake /scratch/software/pgplot macosx gfortran_gcc_64
  • and then make
    sudo make
    There are many many (hopefully harmless) warnings, but compilation succeeds.

Tests

  • We run the pgdemo programs to test our installation. This should better be done in a directory other than the one where we compiled or installed pgplot, for instance the home directory:
    cd
    export PGPLOT_DIR="/usr/pkg/pgplot"
    $PGPLOT_DIR/pgdemo2
    If we type "?" to see the devices list, we should find PNG and TPNG. If we select either, the output will be saved in files with the name pgplot.png, pgplot.png_2, etc.

Linking against PGPLOT

  • This is the command to link a fortran code against pgplot. Do nor forget to include the X11 and the PNG libraries:
    /usr/local/bin/gfortran -o starpos -ffixed-line-length-132 -L/usr/pkg/pgplot -lpgplot -L/usr/X11/lib -lX11 -lpng starpos_linux.f

Neat sudo alias trick

edit · print · PDF
Page last modified on March 28, 2016, at 12:21 PM