.TH GRDMATH l DATE
.SH NAME
grdmath \- Reverse Polish calculator for grd files
.SH SYNOPSIS
\fBgrdmath\fP [ \fB\-I\fP\fIxinc\fP[m|c][/\fIyinc\fP[m|c]] \fB\-R\fP\fIwest/east/south/north\fP \fB\-V\fP] 
\fIoperand\fP [ \fIoperand\fP ] \fBOPERATOR\fP [ \fIoperand\fP ] \fBOPERATOR\fP ... \fB=\fP \fIoutgrdfile\fP
.SH DESCRIPTION
\fBgrdmath\fP will perform operations like add, subtract, multiply, 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 \fB\-R, \-I\fP must be set (and optionally \fB\-F\fP).
.TP
\fIoperand\fP
If \fIoperand\fP can be opened as a file it will be read as a grd file.  If not a file, it is interpreted
as a numerical constant or a special symbol (see below).
.TP
\fIoutgrdfile\fP is a 2-D grd file that will hold the final result.
.TP
.B OPERATORS
Choose among the following operators:
.br
Operator		n_args	Returns
.br
.sp
#include "grdmath_man.i"
.TP
.B SYMBOLS
The following symbols have special meaning:
.br
.sp
\fBPI\fP	3.1415926...
.br
\fBE \fP	2.7182818...
.br
\fBX \fP	Grid with x-coordinates
.br
\fBY \fP	Grid with y-coordinates
.br
.SH OPTIONS
.TP
.B \-I
\fIxinc\fP [and optionally \fIyinc\fP] is the grid spacing. Append m to indicate minutes, c to indicate seconds.
#include "explain_-R.txt"
.TP
.B \-F
Select pixel registration.  [Default is grid registration].
#include "explain_-V.txt"
.SH EXAMPLES
To multiply test.grd by 10.0, try 
.br
	grdmath test.grd 10.0 \fBMUL =\fP test10.grd
.br
.sp
To take log10 of the average of 2 files, use
.br
	grdmath file1.grd file2.grd \fBADD\fP 0.5 \fBMUL LOG10 =\fP file3.grd
.br
.sp
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:
.br
	grdmath ages.grd \fBSQRT\fP 350 \fBMUL \fP2500 \fBADD =\fP depths.grd
.br
.sp
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
.br
	grdmath 2 s_xy.grd \fBMUL\fP s_xx.grd s_yy.grd \fBSUB DIV ATAN2\fP 2 \fBDIV =\fP direction.grd
.SH 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.
.SH SEE ALSO
gmt, grd2xyz, grdedit, grdinfo, xyz2grd
#include "refs.i"
