Getting Started Using
Generic Mapping Tools (GMT)


SLU Specific Settings/Changes:

Here's the local edition of the online manual.

You must set an environment variable called GMTHOME to point at the directory containing GMT. Put the following in your .cshrc file:







setenv GMTHOME /usr/local/gmt3.3.3

You should also add /usr/local/gmt3.3.3/bin to your path and /usr/local/gmt3.3.3/man to your MAPATH (again, you do this by editing your .cshrc file).


Table of Contents

Introduction
Give Credit to the Authors
Locating the Programs
GMT Plots
Data Format
A Simple Example
Previewing Postscript
A More Complicated Example
The "us.cpt" Color Table
Importing Postscript into Adobe Illustrator 5.5
Back To CJA's Guide

 

Introduction

GMT is a collection of programs developed by Wessel and Smith (1991) that facilitate the processing and plotting of scientific data. As the name suggests, the package is at it best when making maps, although familiarity with the package allows complex mathemtatical operations on large volumes of data. The GMT package is accessed using the UNIX computers, although it could be ported to PC's and Mac's (the command line interface is not very mac-like and would cause headaches in that port.).

For details, refer to the online manual pages on GMT and the manuals that are printed out and available in the Geoscience IO room. In particular, look through the "cookbook" section to get a feel for the potential of the package.

Contents


Give Credit to the Authors

If you use the package for calculations, you should cite:

Wessel, P. and W. H. F. Smith, New version of the Generic Mapping Tools released, EOS Trans. Am. Geophys. Union, 76, 329, 1995.

Wessel, P. and W. H. F. Smith, Free software helps map and display data, EOS Trans. Am. Geophys. Union, 72, 441, 445-446, 1991.

If you use it simply for drafting some figures, you should at least acknowledge Wessel and Smith's efforts since they helped you communicate your work.

Contents


Locating the Programs

The most recent version of GMT, 3.3.3, is installed in /usr/local/gmt3.3.3. Older versions are installed in other local directories under /usr/local. DO NOT COPY THE PROGRAMS! Copying the executables wastes disk space and it is stupid to copy widely-used programs tinto your home directory. If you access the "installed" or established codes, when the programs are updated, you will not fall behind because you are relying on private copies. The appropriate way to access the new versions of the programs is to add /usr/local/gmt3.3.3 to your $PATH variable. To make permanent changes to your $PATH variable, you must edit you .cshrc file, which is located in your home directory.


GMT Plots

The output of GMT graphics programs is postscript. Postscript is a graphics programming that is the standard on modern, high-end graphics output devices. The department laser-printers and the HP color paintjet in the computer room all interpret postscript.

On the UNIX machines, postscript can be previewed using ghostscript, a commonly available, free program. Ghostscript is also available for IBM compatibles and Macintoshes. On the Mac's, any postscript can be improted into Adobe Illustrator using the Program Adobe Distiller - which is on the three Power Macintoshes in the Geoscience IO room. Tranfer the postscript to the Mac using Telnet of Fetch and drag and drop the postscript file icon onto the Distiller icon. Distiller launches and creates a file with a ".pdf" extension. Illustrator can parse this file and you can annotate the figure as well as edit any of the objects in the map.

Contents


Data Format

The data format of GMT is the "netcdf" format that is one of several standard formats that scientists use to store numerical data. Before using the package to plot you own data, you must convert it to GMT format. However, to begin making maps, you can rely on the data that are available (and installed at slu) with GMT.

 

There are two easy ways to convert your data to "GMT" format. If you want to average a large amount of data using a nearest-neighbor gridding algorithm, use the command nearestneighbor. If you have evenly or unevenly spaced xyz triplets, store them in an ascii file, one entry per line, and use xyz2grd. If you have evenly spaced data, you can store them in ascii or binary and convert them directly using xyz2grd.

Contents


Making a Simple Map

TO run GMT, the most effective and flexible approach is to use shell scripts. Depending on your UNIX user profile, you can use either "sh" or "csh" to execute a sequence of commands, or run a sequence of programs. In general, it is best to use variables to set up the map window, since this allows easy modifification of the file for repeated use. You can look up the exact operation caused by specific command-line arguments in the GMT manual.




 
         #
# simple c-shell to generate a map of the United States
#
# First, define the geographic window
#     the specification format is w/e/s/n
#
set GWINDOW = "-R-130/-65/25/50"
#
# Next select the projection type
#
set PROJECTION = "-Jb-102.5/0/29.5/45.5/0.125 -V -P"
#
# Now I'll set the tick spacing for east-west and north-south
#
set ewtick = "10"
set nstick = "10"
#
#  Use the pscoast command to generate a plot of
#      the coastlines and state boundaries
#
pscoast $PROJECTION $GWINDOW -B$ewtick/$nstick -Na -Dcrude -V -K -W1 >! ps.map
#
# end of script
# 

In the end, we only executed one command to generate the postscript map. Here's what that figure looks like (after converting it to a crude bitmap, the postscript version produces very precise lines when printed):

Contents


Previewing Postscript with Ghostscript

The output of the shell script is a file called ps.map. To preview this file under X-Windows, use the command:

gs ps.map

This command should open up a window and display a map of the United States. To exit ghostscript (gs), type "quit " at the GS> prompt in the window from which you executed the gs command. If you are using openwindows, you can also preview the file with pageview, which is often faster than ghostscript.

Important Note: For the new version of GMT you should be using a newer version of ghostscript - something like 5.5.1. Using an older version may cause gs to halt.

Contents


A More Complicated Example

Here is an example of how to combine images and line drawings, and plot a focal mechanism using a sequence of gmt commands. This script accesses a data base that right now only is available on Mantle; but that will change when Eric has time to install it is a more accessible location.




#
# plot the topography, focal mechanism, and a symbol for an
#     earthquake
#
# bounds are for the grdcut (make wider than PROJ)
#
set BOUNDS = "-R-107/-84/11/24"
set PROJ = "-Jm0.25 -R-106/-85/12/23"
#
# cut and filter the topographic data
#
grdcut /geo/GeoData/GLOBAL/global_topo.grd $BOUNDS -Gjunk.grd -V
grdfilter junk.grd -D1 -Fb35 -N -V -Gxfile.grd
#
/bin/rm junk.grd
#
# compute the gradient of topography
#
grdgradient xfile.grd -A315 -Ggradient.grd -Nt -V
#
# plot the image using the shading and cpt file
#   us.cpt
#
grdimage xfile.grd -K -Cus.cpt -X2 -Y3 \
-Igradient.grd \
-B5 $PROJ -P -V >! eqtopo.ps
#
# draw the coast line
#
pscoast -Di $PROJ -W1 -O -K >> eqtopo.ps
#
# the focal mechanism
#
psvelomeca $PROJ  -O -K -G255/0/0 -L -Sa0.3 -H1 -C <<EOF >> eqtopo.ps
  lon lat strike dip rake Mw
-97.88 15.97 112 65 94 7.0 -102 15
EOF
#
# plot a symbol at the epicenter
#
psxy $PROJ -Sc -L -W1 -G255/0/0 -P -V -O <<EOF >> eqtopo.ps
-97.88 15.97 0.1
EOF
#  

And here is the result, which can be previewed using "gs eqtopo.ps"

Contents


Here's the color table:




#
# Color table for gmt topo plots
# - Chuck Ammon - Saint Louis University
#
-1000   100     200     255     -500    100     200     255
-500    150     225     255     0       150     225     255
0       100     150     100     30      100     150     100
30      125     175     125     60      125     175     125
60      150     200     150     122     150     200     150
122     175     225     175     183     175     225     175
183     200     255     200     244     200     255     200
244     212     255     212     305     212     255     212
305     255     255     225     457     255     255     225
457     255     225     175     610     255     225     175
610     255     225     125     702     255     225     125
702     255     175     75      914     255     175     75
914     200     150     50      1219    200     150     50
1219    175     125     50      1450    175     125     50
1450    150     100     50      1700    150     100     50
1700    150     125     100     1981    150     125     100
1981    125     125     125     2134    125     125     125
2134    150     150     150     2438    150     150     150
2438    175     175     175     2743    175     175     175
2743    200     200     200     3048    200     200     200
3048    233     233     233     9000    233     233     233
B       100     200     255
F       100     200     255

Contents


Importing Postscript into Adobe Illustrator 5.5 - 8.x

Adobe Illustrator is a program that is available on the Macintosh Computers located in the Geoscience IO Room. Illustrator is a powerful graphics program that is often the choice among graphic artists. For our purposes, it is a convenient tool for annotating scientific figures and illustrating ideas with cartoons and diagrams. Refer to the Illustrator manuals for more information on using this application.

One of the nicest features of Illustrator is it's ability to import postcript graphics and allow the editing of the graphics objects using the mouse. Obviously, the first step in getting the graphics into Illustrator is to transfer the postscript file to the Mac. You do this with the Applications "Fetch" or "NCSA Telnet". Make sure to transfer the postscript as ASCII.

In version 5.5 of Illustrator, importing postscript is a two-step procedure. First, the generic postscript must be converted to "PDF" format; PDF is Adobe's Portable Document Format, which you may have seen around the WWW. To convert the document to PDF format, use the Application Distiller, which is available on the Mac's in the IO room. Just drag and drop the icon of your postscript file on to the distiller icon. The program Distiller will launch and convert the postscript file into a new file with a ".pdf" extension.

Start up Illustrator and "open" the PDF file that you just created and make the necessary changes. Once you get proficient with Illustrator it becomes easier to add labels, figure captions, arrows, etc. using Illustrator than it does using the GMT package (where you need to specify the latitude and longitude of the all the symbols that you place on the figure).

In versions 6.x - 8.x of Illustrator you can read the file directly into the program, you don't need to convert to PDF first.

Contents


Top | CJA's Guide Index | Ammon's Home | Department of Geosciences
Prepared by: Charles J. Ammon,