Urania

A blog named for the muse of Astronomy containing musings by an astronomer

PGPLOT on Snow Leopard

Posted on October 23, 2009 by admin

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).

  1. 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/bin is in your $PATH.

  2. 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 the install-unix.txt file included in the source code tarball).
    sudo tar -C /usr/local/src/ -xzvf pgplot pgplot5.2.tar.gz
  3. 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)]
  4. Compile the PGPLOT binaries: At this point, if you follow the instructions in the install-unix.txt file 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.
    1. Create a PGPLOT library/binary directory:Create a directory to contain the PGPLOT libraries. I created /usr/local/pgplot using the command:
      sudo mkdir /usr/local/pgplot
    2. 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:
      cd /usr/local/pgplot
      sudo cp /usr/local/src/pgplot/drivers.list .
      sudo vi drivers.list
      (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.
    3. Create the makefile: We now need to create the makefile using PGPLOT’s makemake script. Within the /usr/local/pgplot directory 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.
    4. Create all the binaries: Now you just have to create all the binaries, which is a simple make command:
      sudo make
      Assuming everything proceeds without error, you should then see at the end of the output
      *** 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.
      At this point, you should (if you are going to use PGPLOT within perl or C compile the C library as well using
      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, the pgdemo* executables seem hard coded to expect the pgplot libraries in the /usr/local/lib directory, 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)]
    5. Copy library and header files: This step is optional, but since most programs (including the pgdemo* executables) don’t look in /usr/local/pgplot for library and header files, I copy them to /usr/local/lib and /usr/local/include respectively using
  5. Making sure I use these PGPLOT binaries: Since I am using Scisoft OSX, I modified my ~/.tcshrc file 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 ~/.tcshrc file. If you stick to using bash, then the corresponding lines in the ~/.bashrc file 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.
  6. 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
  7. 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, the Makefile.PL script will create a makefile this creates doesn’t work because it doesn’t call gfortran so we have to change the Makefile.PL script 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 the makefile using
    perl Makefile.PL
    Now you still have a problem because this makefile is 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 the makefile as 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:
    make
    make test
    sudo make install
    I did have some issues with make test because 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 the make test to work once I had the proper environmental variable settings for PGPLOT_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.

6 to “PGPLOT on Snow Leopard”

  1. Grappin says:
    Thanks for all these nice instructions - it almost works for me a) about the OS X addition. You write: sudo tar -C /usr/local/src/pgplot5.2_macosx_addition.tgz which is incomplete The following worked for me: sudo tar -C /usr/local/src/pgplot -xvf pgplot5.2_macosx_addition.tar b) I arrive up to point 4d included, everything seems ok However I cannot run any pgdemo file: sudo ./pgdemo2 dyld: Library not loaded: /usr/local/lib/libpgplot.dylib Referenced from: /usr/local/pgplot/./pgdemo2 Reason: image not found Trace/BPT trap What is wrong with libpgplot.dylib?
  2. Grappin says:
    well, of course the solution is to copy libpgplot.dylib from /usr/local/pgplot to/usr/local/lib/libpgplot.dylib where pgplot expects to find it now pgplot works thanks again
  3. Peter Jung says:
    The build went O.K., and the demos work O.K. with the xwindow drivers. The GIF drivers and many others result in segmentation faults. Who can help?
  4. Jack says:
    At step 4d I run into a errors with GRGENV.F and GRTERMIO.C. I've copied the info here. I made a couple of quick changes to GRGENV.F that allows it to compile. Basically, deleted the Readonly Attribute, replace * with a file name, and changed pause to write and read statements. I am new to the MAC OSX, which also means I am new to GFORTRAN, GCC, etc. (I've programmed in Fortran on IBM 360/370s, VAX, MSDOS, and a few others, but just got my first MAC and trying to come up to speed. Any suggestions as to what is causing these problems and how to fix them would be greatly appreciated. Jack jack {at} jriegel(.)com (ERRORS IN GRGENV.F - Appears that the compiler does not like Readonly; Some of the lines exceed the default line length; it doesn’t like the use of FILE=*; and, it doesn’t like pause statements ) gfortran -c /usr/local/src/pgplot/sys_mac/grgenv.f /usr/local/src/pgplot/sys_mac/grgenv.f:63.59: Open(Unit = lun,File=FilNam,Status='OLD',Err = 10,Readonly) 1 Error: Syntax error in OPEN statement at (1) /usr/local/src/pgplot/sys_mac/grgenv.f:67.66: 10 Open(Unit = lun,File='pgplotenvnames',Status='OLD',Err = 20,Readon 1 Error: Syntax error in OPEN statement at (1) /usr/local/src/pgplot/sys_mac/grgenv.f:74.18: 20 CALL GRWARN('Could not find file PGPLOTENVNAMES in current directo 1 Error: Unterminated character constant beginning at (1) /usr/local/src/pgplot/sys_mac/grgenv.f:75.18: CALL GRWARN('A dialog box will come up allowing you to find the fi 1 Error: Unterminated character constant beginning at (1) /usr/local/src/pgplot/sys_mac/grgenv.f:76.18: CALL GRWARN('environment variables. Hit return for the dialog box 1 Error: Unterminated character constant beginning at (1) /usr/local/src/pgplot/sys_mac/grgenv.f:77.72: Pause 1 Warning: Deleted feature: PAUSE statement at (1) /usr/local/src/pgplot/sys_mac/grgenv.f:78.20: Open(Unit=lun,File=*,STATUS='OLD',err=100,Readonly) 1 Error: Syntax error in OPEN statement at (1) make: *** [grgenv.o] Error 1 (ERRORS IN GRTERMIO.C - Appears that there is a conflict with and intrinsic c function called strncpy; Compiler doesn’t like something about the Record statement) gfortran -c /usr/local/src/pgplot/sys_mac/grsy00.f gcc -c -DPG_PPU -O2 -I. /usr/local/src/pgplot/sys/grtermio.c /usr/local/src/pgplot/sys/grtermio.c: In function ‘groter_’: /usr/local/src/pgplot/sys/grtermio.c:39: warning: incompatible implicit declaration of built-in function ‘strncpy’ gfortran -c /usr/local/src/pgplot/sys_mac/grtrml.f gfortran -c /usr/local/src/pgplot/sys/grtter.f gfortran -c /usr/local/src/pgplot/sys_mac/gruser.f /usr/local/src/pgplot/sys_mac/gruser.f:29.9: Record /StringHandle/ UserName 1 Error: Unclassifiable statement at (1) /usr/local/src/pgplot/sys_mac/gruser.f:32.6: STRING = UserName.h^.P^ 1 Error: Unclassifiable statement at (1) make: *** [gruser.o] Error 1
  5. Jack says:
    FOLLOW UP{ The GRGENV.F file in sys_mac was a problem. The one in sys was a better start for my MAC. Need to confirm, but it seems to be working Still have a conflict with an intrinsic c function called strncpy; Number of args is different. In a number of routines (ie grdate.c, grtermio.c, grgmem.c, grfileio.c, gruser.c, the names were mangled. The functions need to have a trailing underscore, but the define statements were not setting the option for that. I have finally managed to run the first demo to output to gif files. However, the naming scheme for the 2nd and higher number files is such that the MAC does not recognize them as gif files. Renaming them works, but I need to find in the source code where the default names are created so I can avoid this step in the future. A quick point in the right direction would save some time. Also, I have not been able to generate interactive output. I guess that will be the hurdle for tomorrow unless somebody has a tip.
  6. Daniel says:
    Step 4d terminates in an error. I get several ranlib errors such as the following ar: creating archive libpgplot.a ranlib: archive member: libpgplot.a(grdate.o) cputype (16777223) does not match previous archive members cputype (7) (all members must match) Any ideas?


Leave a Reply




↑ Top