NAME
grdmath - Reverse Polish calculator for grd files
SYNOPSIS
grdmath [ -Ixinc[m|c][/yinc[m|c]] -Rwest/east/south/north -
V] operand [ operand ] OPERATOR [ operand ] OPERATOR ... =
outgrdfile
DESCRIPTION
grdmath will perform operations like add, subtract, multi-
ply, and divide on one or more grd files or constants using
Reverse Polish syntax (e.g., Hewlett-Packard calculator-
style). Arbitrarily complicated expressions may therefore
be evaluated; the final result is written to an output grd
file. When two grd files are on the stack, each element in
file A is modified by the corresponding element in file B.
However, some operators only require one operand (see
below). If no grdfiles are used in the expression then
options -R, -I must be set (and optionally -F).
operand
If operand can be opened as a file it will be read as a
grd file. If not a file, it is interpreted as a numer-
ical constant or a special symbol (see below).
outgrdfile is a 2-
D grd file that will hold the final result.
OPERATORS
Choose among the following operators:
Operator n_args Returns
ABS 1 abs (A).
ACOS 1 acos (A).
ACOSH 1 acosh (A).
ADD(+) 2 A + B.
AND 2 NaN if A and B == NaN, B if A == NaN,
else A.
ASIN 1 asin (A).
ASINH 1 asinh (A).
ATAN 1 atan (A).
ATAN2 2 atan2 (A, B).
ATANH 1 atanh (A).
CEIL 1 ceil (A) (smallest integer >= A).
COS 1 cos (A) (A in radians).
COSD 1 cos (A) (A in degrees).
COSH 1 cosh (A).
DIV(/) 2 A / B.
D2R 1 Converts Degrees to Radians.
DUP 1 Places duplicate of A on the stack.
EXCH 2 Exchanges A and B on the stack.
EXP 1 exp (A).
FLOOR 1 floor (A) (greatest integer <= A).
FMOD 2 A % B (remainder).
GDIST 2 Great distance (in degrees) between
grid nodes and stack lon,lat.
HYPOT 2 hypot (A, B).
INV 1 1 / A.
LOG 1 log (A) (natural log).
LOG10 1 log10 (A).
MAX 2 Maximum of A and B.
MEAN 1 Mean value of A.
MED 1 Median value of A.
MIN 2 Minimum of A and B.
MUL(x) 2 A * B.
NEG 1 -A.
OR 2 NaN if A or B == NaN, else A.
POW(^) 2 A ^ B.
R2 2 R2 = A^2 + B^2.
R2D 1 Convert Radians to Degrees.
RINT 1 rint (A) (nearest integer).
SIGN 1 sign (+1 or -1) of A.
SIN 1 sin (A) (A in radians).
SIND 1 sin (A) (A in degrees).
SINH 1 sinh (A).
SQRT 1 sqrt (A).
STD 1 Standard deviation of A.
SUB(-) 2 A - B.
TAN 1 tan (A) (A in radians).
TAND 1 tan (A) (A in degrees).
TANH 1 tanh (A).
SYMBOLS
The following symbols have special meaning:
PI 3.1415926...
E 2.7182818...
X Grid with x-coordinates
Y Grid with y-coordinates
OPTIONS
-I x_inc [and optionally y_inc] is the grid spacing.
Append m to indicate minutes or c to indicate seconds.
-R west, east, south, and north specify the Region of
interest. To specify boundaries in degrees and minutes
[and seconds], use the dd:mm[:ss] format. Append r if
lower left and upper right map coordinates are given
instead of wesn.
-F Select pixel registration. [Default is grid registra-
tion].
-V Selects verbose mode, which will send progress reports
to stderr [Default runs "silently"].
EXAMPLES
To multiply test.grd by 10.0, try
grdmath test.grd 10.0 MUL = test10.grd
To take log10 of the average of 2 files, use
grdmath file1.grd file2.grd ADD 0.5 MUL LOG10 =
file3.grd
Given the file ages.grd, which holds seafloor ages in m.y.,
use the relation depth(in m) = 2500 + 350 * sqrt (age) to
estimate normal seafloor depths:
grdmath ages.grd SQRT 350 MUL 2500 ADD = depths.grd
To find the angle a (in degrees) of the largest principal
stress from the stress tensor given by the three files
s_xx.grd s_yy.grd, and s_xy.grd from the relation tan (2*a)
= 2 * s_xy / (s_xx - s_yy), try
grdmath 2 s_xy.grd MUL s_xx.grd s_yy.grd SUB DIV ATAN2
2 DIV = direction.grd
BUGS
Files that has the same name as some operators, e.g., ADD,
SIGN, =, etc. cannot be read and must not be present in the
current directory. Piping of files are not allowed. The
stack limit is hard-wired to 50.
SEE ALSO
gmt, grd2xyz, grdedit, grdinfo, xyz2grd
REFERENCES
Wessel, P., and W. H. F. Smith, 1995, The Generic Mapping
Tools (GMT) version 3.0 Technical Reference & Cookbook,
SOEST/NOAA.
Wessel, P., and W. H. F. Smith, 1995, New Version of the
Generic Mapping Tools Released, EOS Trans. AGU, 76, p. 329.
Wessel, P., and W. H. F. Smith, 1995, New Version of the
Generic Mapping Tools Released,
http://www.agu.org/eos_elec/95154e.html, Copyright 1995 by
the American Geophysical Union.
Wessel, P., and W. H. F. Smith, 1991, Free Software Helps
Map and Display Data, EOS Trans. AGU, 72, p. 441.