Monday, November 2, 2009

Installing GMT under Cygwin

I just struggled through installing GMT under Cygwin, and since I not only had to rely on piecing together information from out-of-date online tutorials, but also on direct help from Kurt, I figured I would write everything down here for future reference and to also hopefully make someone else's life easier.

First things first, check your home directory:

Always check your home directory in cygwin to see if it is actually what it should be. When you install Fledermaus on your machine, it sets a 'HOME' variable that is Program File/IVS/Fledermaus. Now Cygwin thinks this is its home as well. The CCOM wiki offers this solution:

To resolve this, you can create a system-wide HOME area that may be more suitable for any/all programs. To do this, create (or decide) the folder you'd like to be your Cygwin home area. Once you have the folder, edit the HOME variable in the Advanced System properties in Windows and specify that folder. Finally, copy the contents of the previously specified home area into your new home area folder. This will prevent IVS or GMT from breaking. This situation may not be limited to these two products, so it's important to check your 'HOME' environment variable before installing Cygwin software.

Once you are happy with your home directory, here are the steps I followed to successfully install GMT:

1) Make sure you have bzip2 installed. You will also need the 'make' utility and a good C++ compiler (I have a couple different ones, including the gcc one. netcdf will fail to compile without the right one, so if it fails, try grabbing another C compiler. I think gcc is the one to have).

2) Go to the GMT webpage and create an install parameter file. Save this as GMTparams.txt in your usr/local/ directory under your cygwin directory. (If you do not have netcdf already, make sure to let GMT get it and install it for you)

3) Get the GMT install file here, and save it as install_gmt to usr/local/

4) Under cygwin, navigate to usr/local/ and type the following command (this may fail, but this is okay):

./install_gmt GMTparams.txt > install.log

5) If it failed, you probably got a message about a missing -lnetcdf file. This is because netcdf is bad, and uses a .lib extension rather than .a. To fix this, you can just create a symbolic link:

navigate to usr/local/netcdf-xxx/lib
type ln -s libnetcdf.lib libnetcdf.a

Now modify your GMTparams.txt so that netcdf is not downloaded or installed again. You can also modify not to download the GMT files again.

6) navigate back to usr/local/ and rerun ./install_gmt GMTparams.txt >install.log. This should complete without failing, though you may see warnings scroll by.

7) Once it is installed, you must edit your .bashrc or .bash_profile. Cygwin, by default, does not create a .bashrc or .bash_profile in your home directory, so you may need to create one from scratch. GMT looks for a .bash_profile, so if you use .bashrc, make sure you create a .bash_profile that points to it. I'll share mine below:

my .bashrc file (all are needed for GMT to work):

export PATH=/usr/local/gmt/bin:$PATH
export NETCDFHOME=/usr/local/netcdf
export GMTHOME=/usr/local/gmt
export MANPATH=/usr/local/gmt/man:$MANPATH
export DISPLAY=:0

my .bash_profile file:

if [ -f ~/.bashrc ]; then
. ~/.bashrc

export BASH_ENV=$HOME/.bashrc

8) Now you may notice that my paths in .bashrc do not seem to be correct. I use "gmt" and "netcdf" instead of "GMT4.5.1" and "netcdf-3.6.3." This is because I want to be able to update both of these in the future without having to edit any scripts or my .bashrc every time. Therefore I set up the following symbolic links:

navigate to usr/local/ and then type the following commands:

ln -s GMT4.5.1 gmt
ln -s netcdf-3.6.3 netcdf

9) You should be good to go!

To test one of the examples GMT runs upon successful install, you can navigate to any one of the examples found in /GMT4.5.1/share/doc/gmt/examples/. Each ex directory will contain the example scripts, necessary files, and the resulting postscript. I found that to view these files, I need to make sure the X-windows environment is up and running (from cygwin command prompt, type startx). Then I use ghostview (gs) to view the ps:


here is the result:

No comments:

Post a Comment