Urania

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

Archive for the ‘Homebrew’


PGPLOT on Mountain Lion 0

Posted on October 20, 2012 by Juan

One of the most popular posts I made on this site was back in 2009 when I wrote about how I got  the increasingly dated PGPLOT package put together by Tim Pearson running under Snow Leopard.  I decided to update that entry to how I approach things today, using homebrew as a package manager under Mountain Lion.  Honestly, these days I do most of my programming and plotting with Python and matplotlib, but I still have old code that needs to be run sometimes, so getting PGPLOT running under Mountain Lion allows me to keep that old software running.

  1. Install X11: You will need to install XQuartz in order to have XWindows support for PGPLOT.  Grab the package installer and install it.
  2. Install Homebrew:   Intall the homebrew package manager.
  3. Install GFORTRAN: The first thing you need to do after installing homebrew isinstall Gnu Fortran (aka gfortran).  This is fairly simple.  All you need to do is say:
    brew install gfortran
    There is a glitch here.  For some reason, the home-brew version of gfortran doesn’t bother to link the gfortran libraries from /usr/local/lib.  To workaround this,  symbolically linked them using:

    ln -s /usr/local/Cellar/gfortran/4.2.4-5666.3/lib/gcc/i686-apple-darwin11/4.2.1/x86_64/libgfortran.a /usr/local/lib/libgfortran.a
    ln -s /usr/local/Cellar/gfortran/4.2.4-5666.3/lib/gcc/i686-apple-darwin11/4.2.1/x86_64/libgfortranbegin.a /usr/local/lib//libgfortranbegin.a
    ln -s /usr/local/Cellar/gfortran/4.2.4-5666.3/lib/gcc/i686-apple-darwin11/4.2.1/x86_64/libgfortranbegin.la /usr/local/lib//libgfortranbegin.la

    The exact path to the original gfortran libraries may change if you install a newer version of gfortran! 
     
  4. Once they are installed, you simply have to make sure /usr/local/bin is in your $PATH.
     
  5. 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.txtfile included in the source code tarball).
    sudo tar -C /usr/local/src/ -xzvf pgplot pgplot5.2.tar.gz
  6. 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.  I ended up hacking the sys_macosx/ configuration directory to include a gfortran configuration. I have made a tarball of that configuration directory available in the pgplot5.2_macosx_addition.tgz that you can download and unpack into the PGPLOT source directory using:
    sudo tar -C -xzvf /usr/local/src/pgplot5.2_macosx_addition.tgz
  7. 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.
     
  8. 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
  9. 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.
     
  10. Create the makefile: We now need to create the makefile using PGPLOT’s makemake script. 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.
  11. 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
    *** 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. 
     
  12. Link 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 symbolically linked the versions in the /usr/local/pgplot directory to /usr/local/lib and /usr/local/include respectively using
    sudo ln -s /usr/local/pgplot/libcpgplot.a /usr/local/lib/libcpgplot.a
    sudo ln -s /usr/local/pgplot/libpgplot.a /usr/local/lib/libpgplot.a
    sudo ln -s /usr/local/pgplot/libpgplot.dylib /usr/local/lib/libpgplot.dylib
    sudo ln -s /usr/local/pgplot/cpgplot.h /usr/local/include/cpgplot.h
  13. 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 ~/.tcshrc file. 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. 
     
  14. Installing PGPLOT support in Perl: 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.
    1. 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.17.tar.gz

      It can be easily compiled using the following standard perl module compilation steps:
      cd ExtUtils-F77-1.17
      perl Makefile.PL
      make
      sudo make install
    2. Install the PGPLOT perl module: You can download PGPLOT here. Untar the tarball.
      tar xzvf PGPLOT-2.21.tar.gz

      We start as we usually do for Perl modules, creating the makefile using the Makefile.PL script:
      cd PGPLOT-2.21

      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

      Once you have done that, you can finish installing the perl module using:
      make

      you will see some warnings related to missing type specifiers and non-void functions.  Ignore them and continue
      make test
      sudo make install

      I was able to get the make test to work once I had the proper environmental variable settings for PGPLOT_DIR (see step 13).

So that is it, I now have working PGPLOT installations with perl support on my Mountain Lion Macs.

Experimenting with a little Homebrew 0

Posted on March 01, 2011 by Juan

Well, today it finally happened.  I got sick and tired of MacPorts behavior of replacing every binary already included in the Mac OS with its own version.  I don’t need two versions of perl or python installed on my Macs and I am getting tired that every time I try to install a port, it insists on installing a complete perl/python installation or its own set of libraries the MacOS already has built in,  in order to install a small utility.  I know that MacPorts has some justification for this, but it seems messy to me.

As such, I started looking for alternatives and came back to homebrew, which I had discovered a few months ago.  It is a package management system in which everything relies on already installed Mac binaries/libraries as much as possible.  By default, homebrew packages are installed into their own isolated directory (/usr/local/Library/Cellar/) and then symlinked into /usr/local/bin, /usr/local/sbin, or /usr/local/lib directories as needed. But it is flexible enough that you can install it where ever you want and it will still run.  Another nice feature, it doesn’t require you install it as root, it can run completely as the user permission level!

The negatives of homebrew:

  1. There are no where near as many packages (they call them “Formula”) are available for Homebrew as for MacPorts or Fink.
  2. For an astronomer, another big problem, there is no TeX under Homebrew.

It turned out the first negative was a bit of annoyance, but I was willing to live with it because the installation was so much cleaner and most of the important packages I needed MacPorts for were already there.  The second negative turned into a postive because I discovered here is a very easy to install MacTeX package available now that installs a complete TeXlive installation, including AASTeX, by default!  It even has some nice GUI controls included for keeping it up to date.

What follows is a description of what I did to transition from MacPorts to HomeBrew+MacTeX.

  1. Backing up MacPorts: No need to not have a way to change my mind if this blows up in my face.  I backed up my entire MacPorts installation by using the command

    tar czvf /opt_backup.tgz /opt

    and then when that was done, I had a 1.6 Gig tarball at the root level of my drive called opt_backup.tgz.

  2. Disable MacPorts: At this point, I deleted the /opt directory and commented out the commands in my ~/.tcshrc that added those directories to the PATH environmental variable.   If you use the default bash shell, you will need to edit ~/.bashrc to disable MacPorts.
  3. Install Homebrew: Following the directions on the Homebrew site. I originally wanted to place homebrew in its own custom install directory (/usr/local/homebrew).But after reviewing the Homebrew installation documentation, I came to realize that using the default /usr/local location for the install makes the most sense.

    I did this in the recommended manner, using the install script, which does some nice permission checking to make sure things will run nicely before installing. Since my default shell isn’t bash, I had to switch to it, then just run the install script from the command line:

    bash
    ruby -e "$(curl -fsSLk https://gist.github.com/raw/323731/install_homebrew.rb)"

    The first time I ran it, it failed because my permissions for /usr/local had been tweaked. So I had to run the command

    sudo chown -R root:staff /usr/local

    to get the permissions so the script could run.

  4. Activate Homebrew: Since I am not using a custom directory for the installation, there is not configuration needed in terms of setting up the environment. /usr/local/bin/ is in the default PATH, so as soon as I start up a new terminal window, homebrew is available! Otherwise, I would have to edit my default ~/.tcshrc or ~/.bashrc to add the homebrew binaries directories (bin and sbin) to the PATH environmental variable.
  5. Install my favorite packages using homebrew: Installing packages in homebrew is just a matter of making sure the Formula for the package exists (all the publicaly available Formula are here) and then typing

    brew install (formula name)

    So for example, installing CFITSIO was just a matter of typing:

    brew install cfitsio

    Actually, this was for the most part simple for my attempts to install git.  It kept crashing with an error that said:

    The current directory must be set to the ITT directory.

    Well, ITT is the vendor of IDL (a package commonly used by astronomers for data reduction) and I discovered that I had accidentally set the IDL binary directory to be in the PATH ahead of the default system directories.  This meant the IDL version of a binary called install was replacing the system default version of this.  Just the kind of problem I was trying to get away from in MacPorts.  I  changed to my ~/.tcshrc to make sure the IDL binaries directory was later in the PATH than the system directories fixed things.  The only package this affected the install of was git, all the other packages installed without a hitch thus far.  The other brew formulae I installed were installed with the following commands:

    brew install subversion  imagemagick ghostscript macvim lynx coreutils findutils plotutils

    I can get a list of all the packages I have installed using the command:

    brew list

  6. Installing MacTeX: This was extremely easy, I downloaded the MacTeX 2010 package (The version I got was dated 10 Sept 2010 and was 1.6 Gig) and then uncompressed it and double clicked it. It installs using the Mac Installer. I did make sure to customize the install to remove some of the stuff I didn’t feel I needed, but I kept the GUI tools. Turns out there is a nice TeX Live Utility installed in /Applications/TeX that lets you customize which TeX packages are installed and can automatically update things. Review of this tool also showed a very astronomer friendly decision to include AASTeX by default! The TeX installation is in the /usr/local/texlive/ directory and it installs a symlink at /usr/texbin/ to all the LaTeX binaries. I added the following lines to my ~/.tcshrc file to get the tex binaries in my PATH:

    # Set up MacTeX 2010 by including path to that installation of LaTeX
    setenv PATH ${PATH}:/usr/texbin

So there you have it, how I went from using MacPorts and the literally hundreds of packages to support the few I wanted to trimming things down to a few packages in homebrew and one double-clickable TeX installer.

[Edited on Mar. 2, 2011 11:04 am to update the instructions to the default homebrew instructions, which are cleaned and easier to implement.]

  • Translate

  • Astro Pic o' the Day

  • Archives

  • Admin



↑ Top