tutorial
36 Pages
English
Downloading requires you to have access to the YouScribe library
Learn all about the services we offer
Downloading requires you to have access to the YouScribe library
Learn all about the services we offer
36 Pages
English

Description

The Generic Mapping ToolsVersion 3.4.1A Map-Making TutorialbyPal˚ (Paul) WesselSchool of Ocean and Earth Science and TechnologyUniversity of Hawai’i at Manoa¯andWalter H. F. SmithLaboratory for Satellite AltimetryNOAA/NESDIS/NODCMarch 2002Generic Mapping Tools GraphicsContentsINTRODUCTION 1GMT overview: History, philosophy, and usage . . . . . . . . . . . . . . . . . . . . . . . . . . 1Historical highlights . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1Philosophy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1Why is GMT so popular? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1GMT installation considerations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 SESSION ONE 21.1 Tutorial setup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21.2 The GMT environment: What happens when you run GMT? . . . . . . . . . . . . . . . . 21.2.1 Input data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21.2.2 Job Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31.2.3 Output data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31.3 The UNIX Environment: Entry Level Knowledge . . . . . . . . . . . . . . . . . . . . . . 41.3.1 Redirection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41.3.2 Piping ( ...

Subjects

Informations

Published by
Reads 23
Language English

Exrait

The Generic Mapping Tools
Version 3.4.1
A Map-Making Tutorial
by
Pal˚ (Paul) Wessel
School of Ocean and Earth Science and Technology
University of Hawai’i at Manoa¯
and
Walter H. F. Smith
Laboratory for Satellite Altimetry
NOAA/NESDIS/NODC
March 2002
Generic Mapping Tools GraphicsContents
INTRODUCTION 1
GMT overview: History, philosophy, and usage . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Historical highlights . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Philosophy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Why is GMT so popular? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
GMT installation considerations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1 SESSION ONE 2
1.1 Tutorial setup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.2 The GMT environment: What happens when you run GMT? . . . . . . . . . . . . . . . . 2
1.2.1 Input data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.2.2 Job Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.2.3 Output data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.3 The UNIX Environment: Entry Level Knowledge . . . . . . . . . . . . . . . . . . . . . . 4
1.3.1 Redirection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.3.2 Piping ( ) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.3.3 Standard error (stderr) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.3.4 File name expansion or “wild cards” . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.4 GMT Defaults . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
1.5 GMT Units . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
1.6 GMT Common Command Line Options . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
1.6.1 The –B option . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
1.6.2 The –c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
1.6.3 The –H option . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
1.6.4 The –J? options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
1.6.5 The –K –O options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
1.6.6 The –P option . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
1.6.7 The –R . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
1.6.8 The –U option . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
1.6.9 The –V . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
1.6.10 The –X –Y options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
1.6.11 The –: option . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
1.7 Laboratory Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
1.7.1 Linear projection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
1.7.2 Logarithmic projection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
1.7.3 Mercator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
1.7.4 Albers projection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
1.7.5 Orthographic projection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
1.7.6 Eckert IV and VI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
2 SESSION TWO 15
2.1 General Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
2.1.1 Specifying pen attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
2.1.2 fill attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
2.1.3 Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
2.1.4 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
2.1.5 More exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
2.2 Plotting text strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
2.3 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
iiCONTENTS iii
3 SESSION THREE 22
3.1 Contouring gridded data sets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
3.1.1 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
3.2 Gridding of arbitrarily spaced data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
3.2.1 Nearest neighbor gridding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
3.2.2 Gridding with Splines in Tension . . . . . . . . . . . . . . . . . . . . . . . . . . 24
3.2.3 Preprocessing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
3.3 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
4 SESSION FOUR 26
4.1 The cpt file format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
4.1.1 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
4.2 Illumination and intensities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
4.3 Color images . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
4.3.1 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
4.4 Perspective views . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
4.4.1 Mesh-plot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
4.4.2 Color-coded view . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
5 References 31



CONTENTS 1
INTRODUCTION
The purpose of this tutorial is to introduce new users to , outline the environment, and enable
you to make several forms of graphics without having to know too much about UNIX and UNIX tools. We
will not be able to cover all aspects of nor will we necessarily cover the selected topics in sufficient
detail. Nevertheless, it is hoped that the exposure will prompt the users to improve their and UNIX
skills after completion of this short tutorial.
GMT overview: History, philosophy, and usage
Historical highlights
The system was initiated in late 1987 at Lamont-Doherty Earth Observatory, Columbia University
by graduate students Paul Wessel and Walter H. F. Smith. Version 1 was officially introduced to Lamont
scientists in July 1988. 1 migrated by word of mouth (and tape) to other institutions in the United
States, UK, Japan, France and attracted a small following. Paul took a Post-doctoral position at SOEST in
December 1989 and continued the development. Version 2.0 was released with an article in EOS,
October 1991, and quickly spread worldwide. We obtained minor NSF-funding for version 3.0 in
1993 which was released with another article in EOS on August 15, 1995. Significantly improved versions
(3.1, 3.2, 3.3, 3.3.1–6; 3.4) were released between Novenber 1998 and April 2001, culminating in the
March 2002 release of 3.4.1. now is used by 6,000 users worldwide in a broad range of disciplines.
Philosophy
follows the UNIX philosophy so that complex tasks are broken down into smaller and more man-
ageable components. Individual modules are small, easy to maintain, and can be used as any other
UNIX tool. was written in the ANSI C programming language (very portable), is POSIX and Y2K
compliant, and is independent of hardware constraints (e.g., memory). was deliberately written for
command-line usage, not a windows environment, in order to maximize flexibility. We standardized early
on to use PostScript output instead of meta-file formats. Apart from the built-in support for coastlines,
completely decouples data retrieval from the main programs. uses architecture-independent file
formats.
Why is GMT so popular?
The price is right! Also, offers unlimited flexibility since it can be called from the command line,
inside scripts, and from user programs. has attracted many users because of its high quality PostScript
output. easily installs on almost any computer.
GMT installation considerations
has been installed on machines ranging from super-computers to lap-top PCs. only contains
some 55,000 lines of code and has modest space/memory requirements. Minimum requirements are
The netCDF library 3.4 (free from www.unidata.edu).
A C Compiler (free from www.gnu.org).
About 100 Mb disk space (70 Mb additional for full- and high-resolution coast-lines).
About 16 Mb RAM.
In addition, we recommend access to a PostScript printer or equivalent (e.g., ghostscript), PostScript
previewer (e.g., ghostview), any flavor of the UNIX operating system, and more disk space and RAM.

CHAPTER 1. SESSION ONE 2
1. SESSION ONE
1.1 Tutorial setup
1. We assume that has been properly and fully installed and that you have the statementsetenv
GMTHOME path to directory in your .login as described in the README
file.
2. All man pages, documentation, and example scripts are available from the documentation
web page. It is assumed these pages have been installed locally at your site; if not they are always
1available from the main GMT home page .
3. We recommend you create a sub-directory called tutorial, cd into that directory, and copy all the
tutorial files directly there with “cp -r $GMTHOME/tutorial/* . ”.
4. As we discuss principles it may be a good idea to consult the Technical Reference and
Cookbook for more detailed explanations.
5. The tutorial uses the supplemental program grdraster to extract subsets of global gridded
data sets. For your convenience we also supply the subsets in the event you do not wish to install
grdraster and the public data sets it can read. Thus, run the grdraster commands if you have made
the installation or ignore them if you have not.
6. For all but the simplest jobs it is recommended that you place all the (and UNIX) com-
mands in a cshell script file and make it executable. To ensure that UNIX recognizes your script as
a cshell script it is a good habit always to start the script with the line #!/bin/csh. All the examples
in this tutorial assumes you are running the cshell; if you are using something different then you are
on your own.
7. Making a script executable is accomplished using the chmod command, e.g., the script figure 1 is
made executable with “chmod +x figure 1”.
8. To view a PostScript file (e.g., map.ps) on a UNIX workstation we use ghostview map.ps. On some
systems there will be similar commands, like imagetool and pageview on Sun workstations. In this
text we will refer to ghostview; please substitute the relevant PostScript previewer on your system.
9. Please cd into the directory tutorial. We are now ready to start.
1.2 The GMT environment: What happens when you run GMT?
To get a good grasp on one must understand what is going on “under the hood”. Figure 1.1 illustrates
the relationships you need to be aware of at run-time.
1.2.1 Input data
A program may or may not take input files. Three different types of input are recognized (more
details can be found in Appendix B in the Technical Reference):
1. Data tables. These are “spreadsheet” tables with a fixed number of columns and unlimited number
of rows. We distinguish between two groups:
ASCII (Preferred unless files are huge)
– Single segment [Default]
1http://www.soest.hawaii.edu/gmt


CHAPTER 1. SESSION ONE 3
INPUT JOB CONTROL OUTPUT
Command Line Options PostScript Plot File
Previous Command
ASCII or Binary Table(s)ASCII or Binary Table(s) Line Options
Gridded Data Set(s)GMT
Gridded Data Set(s)
Application
Statistics & Summaries
Program Defaults
Color Palette Table (cpt)
Warnings & Errors
Support DataGMT Defaults
(Hidden) Exit Status
Optional
Required
Figure 1.1: The GMT run-time environment
– Multi-segment with internal header records (–M)
Binary (to speed up input/output)
– Single segment [Default]
– Multi-segment (segment headers are all NaN fields) (–M)
2. Gridded dated sets. These are data matrices (evenly spaced in two coordinates) that come in two
flavors:
Grid-line registration
Pixel registration
You may choose among several file formats (even define your own format), but the default is
netCDF.
3. Color palette table (For imaging, color plots, and contour maps). We will discuss these later.
1.2.2 Job Control
programs may get operational parameters from several places:
1. Supplied command line options/switches or program defaults.
2. Short-hand notation to select previously used option arguments (stored in .gmtcommands).
3. Implicitly using defaults for a variety of parameters (stored in .gmtdefaults).
4. May use hidden support data like coastlines or PostScript patterns.
1.2.3 Output data
There are 6 general categories of output produced by :
1. PostScript plot file.
2. Data Table(s).
3. Gridded data set(s).
4. Statistics & Summaries.CHAPTER 1. SESSION ONE 4
5. Warnings and Errors, written to stderr.
6. Exit status (0 means success, otherwise failure).
Note: automatically creates and updates a history of past command options for the common
switches. These history file are called .gmtcommands and will be created in every directory from which
programs are executed. Many initial problems with usage result from not fully appreciating
the relationships shown in Figure 1.1.
1.3 The UNIX Environment: Entry Level Knowledge
1.3.1 Redirection
Most programs read their input from the terminal (called stdin) or from files, and write their output
to the terminal (called stdout). To use files instead one can use UNIX redirection:
GMTprogram input-file >! output-file < >! >> # Append to existing file
The exclamation sign (!) allows us to overwrite existing files.
1.3.2 Piping ( )
Sometimes we want to use the output from one program as input to another program. This is achieved with
UNIX pipes:
Someprogram | GMTprogram1 | GMTprogram2 >! Output-file (or | lp)
1.3.3 Standard error (stderr)
Most UNIX and programs will on occasion write error messages. These are typically written to a
separate data stream called stderr and can be redirected separately from the standard output (which goes to
stdout). To redirect error messages we use
UNIXprogram >& errors.log
When we want to save both program output and error messages to separate files we use the following
syntax:
(GMTprogram > output.d) >& errors.log
1.3.4 File name expansion or “wild cards”
UNIX provides several ways to select groups of files based on name patterns (Table 1.1):
Code Meaning
* Matches anything
? any single character
[list] Matches characters in the list
[range] in the given range
Table 1.1: UNIX wildcards
You can save much time by getting into the habit of selecting “good” filenames that make it easy to
select subsets of all files using the UNIX wild card notation.


{
CHAPTER 1. SESSION ONE 5
Examples
GMTprogram data *.d operates on all files starting with “data ” and ending in “.d”. line ?.d works on all files starting with “line ” followed by any single character and
ending in “.d”.
GMTprogram section 1[0-9]0.part [12] only processes data from sections 100 through 190, only
using every 10th profile, and gets both part 1 and 2.
1.4 GMT Defaults
Numerous minor options (more than 50) can only be changed by modifying the defaults settings.
These settings control such aspects of as font types and sizes, pen thickness used for basemaps,
linear interpolants used when interpolation is needed and many more (Figures 1.2, 1.3, and 1.4 show the
parameters that affect plots). The defaults reside in a file named .gmtdefaults. A user will typically
have a “master” .gmtdefaults file in the home directory, and possibly more specialized .gmtdefaults files
in certain sub- directories. If no such file exist in the current directory, will attempt to open the
user’s master defaults file. If it is not present then the site-specific defaults are used. These come
preset from the developers but may be modified prior to installation. One typical change at
this level is to select SI units rather than the default US/British units. It is recommended not to modify
the system defaults substantially since some applications may rely on the presence of a standard set
of default values. Users may create a new .gmtdefaults file with the current preset values using the
gmtdefaults utility.
HEADER_FONT
Plot Title
FRAME_WIDTH
HEADER_FONT_SIZE
BASEMAP_FRAME_RGB
10˚N
TICK_PEN
GRID_CROSS_SIZE

TICK_LEN
10 S
{
60˚W 50˚W 40˚W 30˚W
BASEMAP_TYPE ANOT_OFFSET
Figure 1.2: Some GMT parameters that affect plot appearance
There are at least two good reasons why the default options are placed in a separate parameter
file:
1. It would not be practical to allow for command-line syntax covering so many options, many of which
are rarely or never changed (such as the ellipsoid used for map projections).
2. It is convenient to keep separate .gmtdefaults files for specific projects, so that one may achieve a
special effect simply by running commands in a sub-directory whose .gmtdefaults file has the
desired settings. For example, when making final illustrations for a journal article one must often
standardize on font sizes and font types, etc. Keeping all those settings in a separate .gmtdefaults file
simplifies this process. Likewise, scripts that make slides often use a different color scheme
and font size than output intended for laser printers. Organizing these various scenarios into separate
.gmtdefaults files will minimize headaches associated with micro-editing of illustrations.90˚W
80˚W
70˚W
60˚W
80˚W
60˚W
70˚W
CHAPTER 1. SESSION ONE 6
DEGREE_FORMAT ANOT_MAX_ANGLE
FRAME_PEN GRID_PEN
LINE_STEP
X_ORIGIN
Y_ORIGIN OBLIQUE_ANOTATION
Figure 1.3: More GMT parameters that affect plot appearance
As mentioned, programs will attempt to open a file named .gmtdefaults. At times it may be desir-
able to override that default. As an alternative, we may supply another filename using the +filename syntax,
i.e., on the same command line as the command we append the name of the alternate .gmtdefaults
file with the plus sign as a prefix. A perhaps less tedious method is to start each script with making a copy
of the current .gmtdefaults, then copy the desired .gmtdefaults file to the current directory, and finally undo
the changes at the end of the script. To change some of the parameters on the fly inside a script the
gmtset utility can be used. E.g., to change the annotation font to 12 point Times-Bold we run
gmtset ANOT FONT Times-Bold ANOT FONT SIZE 12
In addition to these 29 parameters that directly affect the plot there are numerous parameters than
modify units, scales, etc. For a complete listing, see the gmtdefaults man pages.
PAPER_MEDIA
X_AXIS_LENGTH
Plot TitlePAGE_COLOR
210
Y_AXIS_TYPE
BASEMAP_AXES
110
Y_AXIS_LENGTH
010
ANOT_FONT
--111100
ANOT_FONT_SIZE
-2UNIX_TIME_POS 10
0 200 400 600 800 1000
UNIX_TIME x-axis label
LABEL_FONT
Feb 6 07:49:26 1996 Dazed and ConfusedGMT LABEL_FONT_SIZE
Figure 1.4: Even more GMT parameters that affect plot appearance
At the end of the script one can then reset the specific parameters back to what they originally were.
We suggest that you go through all the available parameters at least once so that you know what is available
20˚N
10˚N 10˚N
30˚N
˚20 N
30˚N
y-axis labelCHAPTER 1. SESSION ONE 7
to change via one of the proposed mechanisms.
1.5 GMT Units
programs can accept dimensional quantities in cm, inch, meter, or point. There are two ways to
ensure that understands which unit you intend to use.
1. Append the desired unit to the dimension you supply. This way is explicit and clearly communicates
what you intend, e.g., –X4c means 4 cm.
2. Set the parameter MEASURE UNIT to the desired unit. Then, all dimensions without explicit unit
will be interpreted accordingly.
The latter method is less secure as other users may have a different unit set and your script may not
work as intended. We therefore recommend you always supply the desired unit explicitly.
1.6 GMT Common Command Line Options
has 13 options that are identical to all programs. It is vital that you understand how to use these
options, which we here present alphabetically.
1.6.1 The –B option
This is by far the most complicated option in , but most examples of its usage are actually quite sim-
ple. Given as –Bxinfo[/yinfo][:.”title string”:][W w][E e][S s][N n], this switch specifies a map boundary
to be plotted by using the selected tick-mark intervals. xinfo and yinfo are of the form
[a]tick[m c][ftick[m c]][gtick[m c]][l p][:”axis label”:][:,”unit label”:]
where a, f, and g stand for annotation, frame, and grid interval. The m c indicates minutes (m) or
seconds (c). By default, all 4 boundaries are plotted (denoted W, E, S, N). To change this selection,
append the codes for those you want (e.g., WSn). Upper case (e.g., W) will annotate in addition to draw
2axis/tick-marks. The title, if given, will appear centered above the plot .
1˚W 0˚ 1˚E 2˚Eanotation frame grid
Figure 1.5: Geographic map border using separate selections for anotation, frame, and grid intervals.
Formatting of the anotation is controlled by the parameter DEGREE FORMAT in your .gmtdefaults file.
Options for log axes10
1. tick must be 1, 2, or 3. Annotations/ticks will then occur at 1, 1–2–5, or 1,2,3,4,...,9, respectively.
2. Append l to tick. Then, log of the annotation is plotted at every integer log value.10 10
53. Append p to tick. Then, annotations appear as 10 raised to log of the value (e.g., 10 ).10
2However, it is suppressed when a 3-D view is selected.