.TH GRDMATH 1gmt "Feb 27 2014" "GMT 4.5.13 (SVN)" "Generic Mapping Tools" .SH NAME grdmath \- Reverse Polish Notation calculator for grid files .SH SYNOPSIS \fBgrdmath\fP [ \fB\-F\fP ] [ \fB\-I\fP\fIxinc\fP[\fIunit\fP][\fB=\fP|\fB+\fP][/\fIyinc\fP[\fIunit\fP][\fB=\fP|\fB+\fP]] ] [ \fB\-M\fP ] [ \fB\-N\fP ] [ \fB\-R\fP\fIwest\fP/\fIeast\fP/\fIsouth\fP/\fInorth\fP[\fBr\fP] ] [ \fB\-V\fP ] [ \fB\-bi\fP[\fBs\fP|\fBS\fP|\fBd\fP|\fBD\fP[\fIncol\fP]|\fBc\fP[\fIvar1\fP\fB/\fP\fI...\fP]] ] [ \fB\-f\fP\fIcolinfo\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 grid files or constants using Reverse Polish Notation (RPN) syntax (e.g., Hewlett-Packard calculator-style). Arbitrarily complicated expressions may therefore be evaluated; the final result is written to an output grid file. When two grids 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 grid files are used in the expression then options \fB\-R\fP, \fB\-I\fP must be set (and optionally \fB\-F\fP). The expression \fB=\fP \fIoutgrdfile\fP can occur as many times as the depth of the stack allows. .TP \fIoperand\fP If \fIoperand\fP can be opened as a file it will be read as a grid file. If not a file, it is interpreted as a numerical constant or a special symbol (see below). .TP \fIoutgrdfile\fP The name of a 2-D grid file that will hold the final result. (See GRID FILE FORMATS below). .TP .B OPERATORS Choose among the following 147 operators. "args" are the number of input and output arguments. .br .sp Operator args Returns .br .sp \fBABS \fP 1 1 abs (A). .br \fBACOS \fP 1 1 acos (A). .br \fBACOSH \fP 1 1 acosh (A). .br \fBACOT \fP 1 1 acot (A). .br \fBACSC \fP 1 1 acsc (A). .br \fBADD \fP 2 1 A + B. .br \fBAND \fP 2 1 NaN if A and B == NaN, B if A == NaN, else A. .br \fBASEC \fP 1 1 asec (A). .br \fBASIN \fP 1 1 asin (A). .br \fBASINH \fP 1 1 asinh (A). .br \fBATAN \fP 1 1 atan (A). .br \fBATAN2 \fP 2 1 atan2 (A, B). .br \fBATANH \fP 1 1 atanh (A). .br \fBBEI \fP 1 1 bei (A). .br \fBBER \fP 1 1 ber (A). .br \fBCAZ \fP 2 1 Cartesian azimuth from grid nodes to stack x,y. .br \fBCBAZ \fP 2 1 Cartesian backazimuth from grid nodes to stack x,y. .br \fBCDIST \fP 2 1 Cartesian distance between grid nodes and stack x,y. .br \fBCEIL \fP 1 1 ceil (A) (smallest integer >= A). .br \fBCHICRIT \fP 2 1 Critical value for chi-squared-distribution, with alpha = A and n = B. .br \fBCHIDIST \fP 2 1 chi-squared-distribution P(chi2,n), with chi2 = A and n = B. .br \fBCORRCOEFF\fP 2 1 Correlation coefficient r(A, B). .br \fBCOS \fP 1 1 cos (A) (A in radians). .br \fBCOSD \fP 1 1 cos (A) (A in degrees). .br \fBCOSH \fP 1 1 cosh (A). .br \fBCOT \fP 1 1 cot (A) (A in radians). .br \fBCOTD \fP 1 1 cot (A) (A in degrees). .br \fBCPOISS \fP 2 1 Cumulative Poisson distribution F(x,lambda), with x = A and lambda = B. .br \fBCSC \fP 1 1 csc (A) (A in radians). .br \fBCSCD \fP 1 1 csc (A) (A in degrees). .br \fBCURV \fP 1 1 Curvature of A (Laplacian). .br \fBD2DX2 \fP 1 1 d^2(A)/dx^2 2nd derivative. .br \fBD2DXY \fP 1 1 d^2(A)/dxdy 2nd derivative. .br \fBD2DY2 \fP 1 1 d^2(A)/dy^2 2nd derivative. .br \fBD2R \fP 1 1 Converts Degrees to Radians. .br \fBDDX \fP 1 1 d(A)/dx Central 1st derivative. .br \fBDDY \fP 1 1 d(A)/dy Central 1st derivative. .br \fBDEG2KM \fP 1 1 Converts Spherical Degrees to Kilometers. .br \fBDILOG \fP 1 1 dilog (A). .br \fBDIV \fP 2 1 A / B. .br \fBDUP \fP 1 2 Places duplicate of A on the stack. .br \fBEQ \fP 2 1 1 if A == B, else 0. .br \fBERF \fP 1 1 Error function erf (A). .br \fBERFC \fP 1 1 Complementary Error function erfc (A). .br \fBERFINV \fP 1 1 Inverse error function of A. .br \fBEXCH \fP 2 2 Exchanges A and B on the stack. .br \fBEXP \fP 1 1 exp (A). .br \fBEXTREMA \fP 1 1 Local Extrema: +2/-2 is max/min, +1/-1 is saddle with max/min in x, 0 elsewhere. .br \fBFACT \fP 1 1 A! (A factorial). .br \fBFCRIT \fP 3 1 Critical value for F-distribution, with alpha = A, n1 = B, and n2 = C. .br \fBFDIST \fP 3 1 F-distribution Q(F,n1,n2), with F = A, n1 = B, and n2 = C. .br \fBFLIPLR \fP 1 1 Reverse order of values in each row. .br \fBFLIPUD \fP 1 1 Reverse order of values in each column. .br \fBFLOOR \fP 1 1 floor (A) (greatest integer <= A). .br \fBFMOD \fP 2 1 A % B (remainder after truncated division). .br \fBGE \fP 2 1 1 if A >= B, else 0. .br \fBGT \fP 2 1 1 if A > B, else 0. .br \fBHYPOT \fP 2 1 hypot (A, B) = sqrt (A*A + B*B). .br \fBI0 \fP 1 1 Modified Bessel function of A (1st kind, order 0). .br \fBI1 \fP 1 1 Modified Bessel function of A (1st kind, order 1). .br \fBIN \fP 2 1 Modified Bessel function of A (1st kind, order B). .br \fBINRANGE \fP 3 1 1 if B <= A <= C, else 0. .br \fBINSIDE \fP 1 1 1 when inside or on polygon(s) in A, else 0. .br \fBINV \fP 1 1 1 / A. .br \fBISNAN \fP 1 1 1 if A == NaN, else 0. .br \fBJ0 \fP 1 1 Bessel function of A (1st kind, order 0). .br \fBJ1 \fP 1 1 Bessel function of A (1st kind, order 1). .br \fBJN \fP 2 1 Bessel function of A (1st kind, order B). .br \fBK0 \fP 1 1 Modified Kelvin function of A (2nd kind, order 0). .br \fBK1 \fP 1 1 Modified Bessel function of A (2nd kind, order 1). .br \fBKEI \fP 1 1 kei (A). .br \fBKER \fP 1 1 ker (A). .br \fBKM2DEG \fP 1 1 Converts Kilometers to Spherical Degrees. .br \fBKN \fP 2 1 Modified Bessel function of A (2nd kind, order B). .br \fBKURT \fP 1 1 Kurtosis of A. .br \fBLDIST \fP 1 1 Compute distance from lines in multi-segment ASCII file A. .br \fBLE \fP 2 1 1 if A <= B, else 0. .br \fBLMSSCL \fP 1 1 LMS scale estimate (LMS STD) of A. .br \fBLOG \fP 1 1 log (A) (natural log). .br \fBLOG10 \fP 1 1 log10 (A) (base 10). .br \fBLOG1P \fP 1 1 log (1+A) (accurate for small A). .br \fBLOG2 \fP 1 1 log2 (A) (base 2). .br \fBLOWER \fP 1 1 The lowest (minimum) value of A. .br \fBLRAND \fP 2 1 Laplace random noise with mean A and std. deviation B. .br \fBLT \fP 2 1 1 if A < B, else 0. .br \fBMAD \fP 1 1 Median Absolute Deviation (L1 STD) of A. .br \fBMAX \fP 2 1 Maximum of A and B. .br \fBMEAN \fP 1 1 Mean value of A. .br \fBMED \fP 1 1 Median value of A. .br \fBMIN \fP 2 1 Minimum of A and B. .br \fBMOD \fP 2 1 A mod B (remainder after floored division). .br \fBMODE \fP 1 1 Mode value (Least Median of Squares) of A. .br \fBMUL \fP 2 1 A * B. .br \fBNAN \fP 2 1 NaN if A == B, else A. .br \fBNEG \fP 1 1 -A. .br \fBNEQ \fP 2 1 1 if A != B, else 0. .br \fBNOT \fP 1 1 NaN if A == NaN, 1 if A == 0, else 0. .br \fBNRAND \fP 2 1 Normal, random values with mean A and std. deviation B. .br \fBOR \fP 2 1 NaN if A or B == NaN, else A. .br \fBPDIST \fP 1 1 Compute distance from points in ASCII file A. .br \fBPLM \fP 3 1 Associated Legendre polynomial P(A) degree B order C. .br \fBPLMg \fP 3 1 Normalized associated Legendre polynomial P(A) degree B order C (geophysical convention). .br \fBPOP \fP 1 0 Delete top element from the stack. .br \fBPOW \fP 2 1 A ^ B. .br \fBPQUANT \fP 2 1 The B'th Quantile (0-100%) of A.\"' .br \fBPSI \fP 1 1 Psi (or Digamma) of A. .br \fBPV \fP 3 1 Legendre function Pv(A) of degree v = real(B) + imag(C). .br \fBQV \fP 3 1 Legendre function Qv(A) of degree v = real(B) + imag(C). .br \fBR2 \fP 2 1 R2 = A^2 + B^2. .br \fBR2D \fP 1 1 Convert Radians to Degrees. .br \fBRAND \fP 2 1 Uniform random values between A and B. .br \fBRINT \fP 1 1 rint (A) (nearest integer). .br \fBROTX \fP 2 1 Rotate A by the (constant) shift B in x-direction. .br \fBROTY \fP 2 1 Rotate A by the (constant) shift B in y-direction. .br \fBSAZ \fP 2 1 Spherical azimuth from grid nodes to stack x,y. .br \fBSBAZ \fP 2 1 Spherical backazimuth from grid nodes to stack x,y. .br \fBSDIST \fP 2 1 Spherical (Great circle|geodesic) distance (in km) between grid nodes and stack lon,lat (A, B). .br \fBSEC \fP 1 1 sec (A) (A in radians). .br \fBSECD \fP 1 1 sec (A) (A in degrees). .br \fBSIGN \fP 1 1 sign (+1 or -1) of A. .br \fBSIN \fP 1 1 sin (A) (A in radians). .br \fBSINC \fP 1 1 sinc (A) (sin (pi*A)/(pi*A)). .br \fBSIND \fP 1 1 sin (A) (A in degrees). .br \fBSINH \fP 1 1 sinh (A). .br \fBSKEW \fP 1 1 Skewness of A. .br \fBSQR \fP 1 1 A^2. .br \fBSQRT \fP 1 1 sqrt (A). .br \fBSTD \fP 1 1 Standard deviation of A. .br \fBSTEP \fP 1 1 Heaviside step function: H(A). .br \fBSTEPX \fP 1 1 Heaviside step function in x: H(x-A). .br \fBSTEPY \fP 1 1 Heaviside step function in y: H(y-A). .br \fBSUB \fP 2 1 A - B. .br \fBTAN \fP 1 1 tan (A) (A in radians). .br \fBTAND \fP 1 1 tan (A) (A in degrees). .br \fBTANH \fP 1 1 tanh (A). .br \fBTCRIT \fP 2 1 Critical value for Student's t-distribution, with alpha = A and n = B.\"' .br \fBTDIST \fP 2 1 Student's t-distribution A(t,n), with t = A, and n = B.\"' .br \fBTN \fP 2 1 Chebyshev polynomial Tn(-1 max.xyz .SH REFERENCES Abramowitz, M., and I. A. Stegun, 1964, \fIHandbook of Mathematical Functions\fP, Applied Mathematics Series, vol. 55, Dover, New York. .br Holmes, S. A., and W. E. Featherstone, 2002, A unified approach to the Clenshaw summation and the recursive computation of very high degree and order normalised associated Legendre functions. \fIJournal of Geodesy\fP, 76, 279-299. .br Press, W. H., S. A. Teukolsky, W. T. Vetterling, and B. P. Flannery, 1992, \fINumerical Recipes\fP, 2nd edition, Cambridge Univ., New York. .br Spanier, J., and K. B. Oldman, 1987, \fIAn Atlas of Functions\fP, Hemisphere Publishing Corp. .SH "SEE ALSO" .IR GMT (1), .IR gmtmath (1), .IR grd2xyz (1), .IR grdedit (1), .IR grdinfo (1), .IR xyz2grd (1)