grdmath(1) GMT grdmath(1)

## NAME

grdmath - Reverse Polish Notation (RPN) calculator for grids (element by element)

## SYNOPSIS

grdmath[-Amin_area[/min_level/max_level][+ag|i|s|S][+r|l][ppercent] ] [-Dresolution[+] ] [-Iincrement] [-M] [-N] [-Rregion] [-V[level] ] [-bibinary ] [-dinodata ] [-fflags ] [-hheaders ] [-iflags ] [-nflags ] [-r] [-x[[-]n] ]operand[operand]OPERATOR[operand]OPERATORa|=outgrdfileNote:No space is allowed between the option flag and the associated arguments.

## DESCRIPTION

grdmathwill 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). Arbi- trarily complicated expressions may therefore be evaluated; the final result is written to an output grid file. Grid operations are ele- ment-by-element, not matrix manipulations. Some operators only require one operand (see below). If no grid files are used in the expression then options-R,-Imust be set (and optionally-r). The expression=outgrdfilecan occur as many times as the depth of the stack allows in order to save intermediate results. Complicated or frequently occur- ring expressions may be coded as a macro for future use or stored and recalled via named memory locations.

## REQUIRED ARGUMENTS

operandIfoperandcan 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).outgrdfileThe name of a 2-D grid file that will hold the final result. (See GRID FILE FORMATS below).

## OPTIONAL ARGUMENTS

-Amin_area[/min_level/max_level][+ag|i|s|S][+r|l][+ppercent] Features with an area smaller thanmin_areain km^2 or of hier- archical level that is lower thanmin_levelor higher thanmax_levelwill not be plotted [Default is 0/0/4 (all features)]. Level 2 (lakes) contains regular lakes and wide river bodies which we normally include as lakes; append+rto just get river-lakes or+lto just get regular lakes. By default (+ai) we select the ice shelf boundary as the coastline for Antarc- tica; append+agto instead select the ice grounding line as coastline. For expert users who wish to print their own Antarc- tica coastline and islands viapsxyyou can use+asto skip all GSHHG features below 60S or+aSto instead skip all features north of 60S. Finally, append+ppercentto exclude polygons whose percentage area of the corresponding full-resolution fea- ture is less thanpercent. See GSHHG INFORMATION below for more details. (-Ais only relevant to theLDISTGoperator)-Dresolution[+] Selects the resolution of the data set to use with the operator LDISTG ((f)ull, (h)igh, (i)ntermediate, (l)ow, and (c)rude). The resolution drops off by 80% between data sets [Default isl]. Append+to automatically select a lower resolution should the one requested not be available [abort if not found].-Ixinc[unit][+e|n][/yinc[unit][+e|n]]x_inc[and optionallyy_inc] is the grid spacing. Optionally, append a suffix modifier.Geographical(degrees)coordinates: Appendmto indicate arc minutes orsto indicate arc seconds. If one of the unitse,f,k,M,noruis appended instead, the increment is assumed to be given in meter, foot, km, Mile, nau- tical mile or US survey foot, respectively, and will be con- verted to the equivalent degrees longitude at the middle lati- tude of the region (the conversion depends on PROJ_ELLIPSOID). Ify_incis given but set to 0 it will be reset equal tox_inc; otherwise it will be converted to degrees latitude.Allcoordi-nates: If+eis appended then the corresponding maxx(east) ory(north) may be slightly adjusted to fit exactly the given increment [by default the increment may be adjusted slightly to fit the given domain]. Finally, instead of giving an increment you may specify thenumberofnodesdesired by appending+nto the supplied integer argument; the increment is then recalcu- lated from the number of nodes and the domain. The resulting increment value depends on whether you have selected a grid- line-registered or pixel-registered grid; see App-file-formats for details. Note: if-Rgrdfileis used then the grid spacing has already been initialized; use-Ito override the values.-MBy default any derivatives calculated are in z_units/ x(or y)_units. However, the user may choose this option to convert dx,dy in degrees of longitude,latitude into meters using a flat Earth approximation, so that gradients are in z_units/meter.-NTurn off strict domain match checking when multiple grids are manipulated [Default will insist that each grid domain is within 1e-4 * grid_spacing of the domain of the first grid listed].-Rxmin/xmax/ymin/ymax[+r][+uunit] (morea|) Specify the region of interest.-V[level] (morea|) Select verbosity level [c].-bi[ncols][t] (morea|) Select native binary input. The binary input option only applies to the data files needed by operatorsLDIST,PDIST, andINSIDE.-dinodata(morea|) Replace input columns that equalnodatawith NaN.-f[i|o]colinfo(morea|) Specify data types of input and/or output columns.-g[a]x|y|d|X|Y|D|[col]z[+|-]gap[u] (morea|) Determine data gaps and line breaks.-h[i|o][n][+c][+d][+rremark][+rtitle] (morea|) Skip or produce header record(s).-icols[+l][+sscale][+ooffset][,^<i>a|] (morea|) Select input columns and transformations (0 is first column).-n[b|c|l|n][+a][+bBC][+c][+tthreshold] (morea|) Select interpolation mode for grids.-r(morea|) Set pixel node registration [gridline]. Only used with-R-I.-x[[-]n] (morea|) Limit number of cores used in multi-threaded algorithms (OpenMP required).-^or just-Print a short message about the syntax of the command, then exits (NOTE: on Windows just use-).-+or just+Print an extensive usage (help) message, including the explana- tion of any module-specific option (but not the GMT common options), then exits.-?or no arguments Print a complete usage (help) message, including the explanation of all options, then exits.

## OPERATORS

Choose among the following 209 operators.aargsaare the number of input and output arguments. +----------+------+---------------------+ |Operator | args | Returns | +----------+------+---------------------+ |ABS| 1 1 | abs (A) | +----------+------+---------------------+ |ACOS| 1 1 | acos (A) | +----------+------+---------------------+ |ACOSH| 1 1 | acosh (A) | +----------+------+---------------------+ |ACOT| 1 1 | acot (A) | +----------+------+---------------------+ |ACSC| 1 1 | acsc (A) | +----------+------+---------------------+ |ADD| 2 1 | A + B | +----------+------+---------------------+ |AND| 2 1 | B if A == NaN, else | | | | A | +----------+------+---------------------+ |ARC| 2 1 | Return arc(A,B) on | | | | [0 pi] | +----------+------+---------------------+ |AREA| 0 1 | Area of each | | | | gridnode cell (in | | | | km^2 if geographic) | +----------+------+---------------------+ |ASEC| 1 1 | asec (A) | +----------+------+---------------------+ |ASIN| 1 1 | asin (A) | +----------+------+---------------------+ |ASINH| 1 1 | asinh (A) | +----------+------+---------------------+ |ATAN| 1 1 | atan (A) | +----------+------+---------------------+ |ATAN2| 2 1 | atan2 (A, B) | +----------+------+---------------------+ |ATANH| 1 1 | atanh (A) | +----------+------+---------------------+ |BCDF| 3 1 | Binomial cumulative | | | | distribution func- | | | | tion for p = A, n = | | | | B, and x = C | +----------+------+---------------------+ |BPDF| 3 1 | Binomial probabil- | | | | ity density func- | | | | tion for p = A, n = | | | | B, and x = C | +----------+------+---------------------+ |BEI| 1 1 | bei (A) | +----------+------+---------------------+ |BER| 1 1 | ber (A) | +----------+------+---------------------+ |BITAND| 2 1 | A & B (bitwise AND | | | | operator) | +----------+------+---------------------+ |BITLEFT| 2 1 | A << B (bitwise | | | | left-shift opera- | | | | tor) | +----------+------+---------------------+ |BITNOT| 1 1 | ~A (bitwise NOT | | | | operator, i.e., | | | | return twoas com- | | | | plement) | +----------+------+---------------------+ |BITOR| 2 1 | A | B (bitwise OR | | | | operator) | +----------+------+---------------------+ |BITRIGHT| 2 1 | A >> B (bitwise | | | | right-shift opera- | | | | tor) | +----------+------+---------------------+ |BITTEST| 2 1 | 1 if bit B of A is | | | | set, else 0 (bit- | | | | wise TEST operator) | +----------+------+---------------------+ |BITXOR| 2 1 | A ^ B (bitwise XOR | | | | operator) | +----------+------+---------------------+ |CAZ| 2 1 | Cartesian azimuth | | | | from grid nodes to | | | | stack x,y (i.e., A, | | | | B) | +----------+------+---------------------+ |CBAZ| 2 1 | Cartesian | | | | back-azimuth from | | | | grid nodes to stack | | | | x,y (i.e., A, B) | +----------+------+---------------------+ |CDIST| 2 1 | Cartesian distance | | | | between grid nodes | | | | and stack x,y | | | | (i.e., A, B) | +----------+------+---------------------+ |CDIST2| 2 1 | As CDIST but only | | | | to nodes that are | | | | != 0 | +----------+------+---------------------+ |CEIL| 1 1 | ceil (A) (smallest | | | | integer >= A) | +----------+------+---------------------+ |CHICRIT| 2 1 | Chi-squared criti- | | | | cal value for alpha | | | | = A and nu = B | +----------+------+---------------------+ |CHICDF| 2 1 | Chi-squared cumula- | | | | tive distribution | | | | function for chi2 = | | | | A and nu = B | +----------+------+---------------------+ |CHIPDF| 2 1 | Chi-squared proba- | | | | bility density | | | | function for chi2 = | | | | A and nu = B | +----------+------+---------------------+ |COMB| 2 1 | Combinations n_C_r, | | | | with n = A and r = | | | | B | +----------+------+---------------------+ |CORRCOEFF| 2 1 | Correlation coeffi- | | | | cient r(A, B) | +----------+------+---------------------+ |COS| 1 1 | cos (A) (A in radi- | | | | ans) | +----------+------+---------------------+ |COSD| 1 1 | cos (A) (A in | | | | degrees) | +----------+------+---------------------+ |COSH| 1 1 | cosh (A) | +----------+------+---------------------+ |COT| 1 1 | cot (A) (A in radi- | | | | ans) | +----------+------+---------------------+ |COTD| 1 1 | cot (A) (A in | | | | degrees) | +----------+------+---------------------+ |CSC| 1 1 | csc (A) (A in radi- | | | | ans) | +----------+------+---------------------+ |CSCD| 1 1 | csc (A) (A in | | | | degrees) | +----------+------+---------------------+ |CURV| 1 1 | Curvature of A | | | | (Laplacian) | +----------+------+---------------------+ |D2DX2| 1 1 | d^2(A)/dx^2 2nd de- | | | | rivative | +----------+------+---------------------+ |D2DY2| 1 1 | d^2(A)/dy^2 2nd de- | | | | rivative | +----------+------+---------------------+ |D2DXY| 1 1 | d^2(A)/dxdy 2nd de- | | | | rivative | +----------+------+---------------------+ |D2R| 1 1 | Converts Degrees to | | | | Radians | +----------+------+---------------------+ |DDX| 1 1 | d(A)/dx Central 1st | | | | derivative | +----------+------+---------------------+ |DDY| 1 1 | d(A)/dy Central 1st | | | | derivative | +----------+------+---------------------+ |DEG2KM| 1 1 | Converts Spherical | | | | Degrees to Kilome- | | | | ters | +----------+------+---------------------+ |DENAN| 2 1 | Replace NaNs in A | | | | with values from B | +----------+------+---------------------+ |DILOG| 1 1 | dilog (A) | +----------+------+---------------------+ |DIV| 2 1 | A / B | +----------+------+---------------------+ |DUP| 1 2 | Places duplicate of | | | | A on the stack | +----------+------+---------------------+ |ECDF| 2 1 | Exponential cumula- | | | | tive distribution | | | | function for x = A | | | | and lambda = B | +----------+------+---------------------+ |ECRIT| 2 1 | Exponential distri- | | | | bution critical | | | | value for alpha = A | | | | and lambda = B | +----------+------+---------------------+ |EPDF| 2 1 | Exponential proba- | | | | bility density | | | | function for x = A | | | | and lambda = B | +----------+------+---------------------+ |ERF| 1 1 | Error function erf | | | | (A) | +----------+------+---------------------+ |ERFC| 1 1 | Complementary Error | | | | function erfc (A) | +----------+------+---------------------+ |EQ| 2 1 | 1 if A == B, else 0 | +----------+------+---------------------+ |ERFINV| 1 1 | Inverse error func- | | | | tion of A | +----------+------+---------------------+ |EXCH| 2 2 | Exchanges A and B | | | | on the stack | +----------+------+---------------------+ |EXP| 1 1 | exp (A) | +----------+------+---------------------+ |FACT| 1 1 | A! (A factorial) | +----------+------+---------------------+ |EXTREMA| 1 1 | Local Extrema: | | | | +2/-2 is max/min, | | | | +1/-1 is saddle | | | | with max/min in x, | | | | 0 elsewhere | +----------+------+---------------------+ |FCDF| 3 1 | F cumulative dis- | | | | tribution function | | | | for F = A, nu1 = B, | | | | and nu2 = C | +----------+------+---------------------+ |FCRIT| 3 1 | F distribution | | | | critical value for | | | | alpha = A, nu1 = B, | | | | and nu2 = C | +----------+------+---------------------+ |FLIPLR| 1 1 | Reverse order of | | | | values in each row | +----------+------+---------------------+ |FLIPUD| 1 1 | Reverse order of | | | | values in each col- | | | | umn | +----------+------+---------------------+ |FLOOR| 1 1 | floor (A) (greatest | | | | integer <= A) | +----------+------+---------------------+ |FMOD| 2 1 | A % B (remainder | | | | after truncated | | | | division) | +----------+------+---------------------+ |FPDF| 3 1 | F probability den- | | | | sity function for F | | | | = A, nu1 = B, and | | | | nu2 = C | +----------+------+---------------------+ |GE| 2 1 | 1 if A >= B, else 0 | +----------+------+---------------------+ |GT| 2 1 | 1 if A > B, else 0 | +----------+------+---------------------+ |HYPOT| 2 1 | hypot (A, B) = sqrt | | | | (A*A + B*B) | +----------+------+---------------------+ |I0| 1 1 | Modified Bessel | | | | function of A (1st | | | | kind, order 0) | +----------+------+---------------------+ |I1| 1 1 | Modified Bessel | | | | function of A (1st | | | | kind, order 1) | +----------+------+---------------------+ |IFELSE| 3 1 | B if A != 0, else C | +----------+------+---------------------+ |IN| 2 1 | Modified Bessel | | | | function of A (1st | | | | kind, order B) | +----------+------+---------------------+ |INRANGE| 3 1 | 1 if B <= A <= C, | | | | else 0 | +----------+------+---------------------+ |INSIDE| 1 1 | 1 when inside or on | | | | polygon(s) in A, | | | | else 0 | +----------+------+---------------------+ |INV| 1 1 | 1 / A | +----------+------+---------------------+ |ISFINITE| 1 1 | 1 if A is finite, | | | | else 0 | +----------+------+---------------------+ |ISNAN| 1 1 | 1 if A == NaN, else | | | | 0 | +----------+------+---------------------+ |J0| 1 1 | Bessel function of | | | | A (1st kind, order | | | | 0) | +----------+------+---------------------+ |J1| 1 1 | Bessel function of | | | | A (1st kind, order | | | | 1) | +----------+------+---------------------+ |JN| 2 1 | Bessel function of | | | | A (1st kind, order | | | | B) | +----------+------+---------------------+ |K0| 1 1 | Modified Kelvin | | | | function of A (2nd | | | | kind, order 0) | +----------+------+---------------------+ |K1| 1 1 | Modified Bessel | | | | function of A (2nd | | | | kind, order 1) | +----------+------+---------------------+ |KEI| 1 1 | kei (A) | +----------+------+---------------------+ |KER| 1 1 | ker (A) | +----------+------+---------------------+ |KM2DEG| 1 1 | Converts Kilometers | | | | to Spherical | | | | Degrees | +----------+------+---------------------+ |KN| 2 1 | Modified Bessel | | | | function of A (2nd | | | | kind, order B) | +----------+------+---------------------+ |KURT| 1 1 | Kurtosis of A | +----------+------+---------------------+ |LCDF| 1 1 | Laplace cumulative | | | | distribution func- | | | | tion for z = A | +----------+------+---------------------+ |LCRIT| 1 1 | Laplace distribu- | | | | tion critical value | | | | for alpha = A | +----------+------+---------------------+ |LDIST| 1 1 | Compute minimum | | | | distance (in km if | | | | -fg) from lines in | | | | multi-segment ASCII | | | | file A | +----------+------+---------------------+ |LDIST2| 2 1 | As LDIST, from | | | | lines in ASCII file | | | | B but only to nodes | | | | where A != 0 | +----------+------+---------------------+ |LDISTG| 0 1 | As LDIST, but oper- | | | | ates on the GSHHG | | | | dataset (see -A, -D | | | | for options). | +----------+------+---------------------+ |LE| 2 1 | 1 if A <= B, else 0 | +----------+------+---------------------+ |LOG| 1 1 | log (A) (natural | | | | log) | +----------+------+---------------------+ |LOG10| 1 1 | log10 (A) (base 10) | +----------+------+---------------------+ |LOG1P| 1 1 | log (1+A) (accurate | | | | for small A) | +----------+------+---------------------+ |LOG2| 1 1 | log2 (A) (base 2) | +----------+------+---------------------+ |LMSSCL| 1 1 | LMS scale estimate | | | | (LMS STD) of A | +----------+------+---------------------+ |LMSSCLW| 2 1 | Weighted LMS scale | | | | estimate (LMS STD) | | | | of A for weights in | | | | B | +----------+------+---------------------+ |LOWER| 1 1 | The lowest (mini- | | | | mum) value of A | +----------+------+---------------------+ |LPDF| 1 1 | Laplace probability | | | | density function | | | | for z = A | +----------+------+---------------------+ |LRAND| 2 1 | Laplace random | | | | noise with mean A | | | | and std. deviation | | | | B | +----------+------+---------------------+ |LT| 2 1 | 1 if A < B, else 0 | +----------+------+---------------------+ |MAD| 1 1 | Median Absolute | | | | Deviation (L1 STD) | | | | of A | +----------+------+---------------------+ |MAX| 2 1 | Maximum of A and B | +----------+------+---------------------+ |MEAN| 1 1 | Mean value of A | +----------+------+---------------------+ |MEANW| 2 1 | Weighted mean value | | | | of A for weights in | | | | B | +----------+------+---------------------+ |MEDIAN| 1 1 | Median value of A | +----------+------+---------------------+ |MEDIANW| 2 1 | Weighted median | | | | value of A for | | | | weights in B | +----------+------+---------------------+ |MIN| 2 1 | Minimum of A and B | +----------+------+---------------------+ |MOD| 2 1 | A mod B (remainder | | | | after floored divi- | | | | sion) | +----------+------+---------------------+ |MODE| 1 1 | Mode value (Least | | | | Median of Squares) | | | | of A | +----------+------+---------------------+ |MODEW| 2 1 | Weighted mode value | | | | (Least Median of | | | | Squares) of A for | | | | weights in B | +----------+------+---------------------+ |MUL| 2 1 | A * B | +----------+------+---------------------+ |NAN| 2 1 | NaN if A == B, else | | | | A | +----------+------+---------------------+ |NEG| 1 1 | -A | +----------+------+---------------------+ |NEQ| 2 1 | 1 if A != B, else 0 | +----------+------+---------------------+ |NORM| 1 1 | Normalize (A) so | | | | max(A)-min(A) = 1 | +----------+------+---------------------+ |NOT| 1 1 | NaN if A == NaN, 1 | | | | if A == 0, else 0 | +----------+------+---------------------+ |NRAND| 2 1 | Normal, random val- | | | | ues with mean A and | | | | std. deviation B | +----------+------+---------------------+ |OR| 2 1 | NaN if B == NaN, | | | | else A | +----------+------+---------------------+ |PCDF| 2 1 | Poisson cumulative | | | | distribution func- | | | | tion for x = A and | | | | lambda = B | +----------+------+---------------------+ |PDIST| 1 1 | Compute minimum | | | | distance (in km if | | | | -fg) from points in | | | | ASCII file A | +----------+------+---------------------+ |PDIST2| 2 1 | As PDIST, from | | | | points in ASCII | | | | file B but only to | | | | nodes where A != 0 | +----------+------+---------------------+ |PERM| 2 1 | Permutations n_P_r, | | | | with n = A and r = | | | | B | +----------+------+---------------------+ |PLM| 3 1 | Associated Legendre | | | | polynomial P(A) | | | | degree B order C | +----------+------+---------------------+ |PLMg| 3 1 | Normalized associ- | | | | ated Legendre poly- | | | | nomial P(A) degree | | | | B order C (geophys- | | | | ical convention) | +----------+------+---------------------+ |POINT| 1 2 | Compute mean x and | | | | y from ASCII file A | | | | and place them on | | | | the stack | +----------+------+---------------------+ |POP| 1 0 | Delete top element | | | | from the stack | +----------+------+---------------------+ |POW| 2 1 | A ^ B | +----------+------+---------------------+ |PPDF| 2 1 | Poisson distribu- | | | | tion P(x,lambda), | | | | with x = A and | | | | lambda = B | +----------+------+---------------------+ |PQUANT| 2 1 | The Bath Quantile | | | | (0-100%) of A | +----------+------+---------------------+ |PQUANTW| 3 1 | The Cath weighted | | | | quantile (0-100%) | | | | of A for weights in | | | | B | +----------+------+---------------------+ |PSI| 1 1 | Psi (or Digamma) of | | | | A | +----------+------+---------------------+ |PV| 3 1 | Legendre function | | | | Pv(A) of degree v = | | | | real(B) + imag(C) | +----------+------+---------------------+ |QV| 3 1 | Legendre function | | | | Qv(A) of degree v = | | | | real(B) + imag(C) | +----------+------+---------------------+ |R2| 2 1 | R2 = A^2 + B^2 | +----------+------+---------------------+ |R2D| 1 1 | Convert Radians to | | | | Degrees | +----------+------+---------------------+ |RAND| 2 1 | Uniform random val- | | | | ues between A and B | +----------+------+---------------------+ |RCDF| 1 1 | Rayleigh cumulative | | | | distribution func- | | | | tion for z = A | +----------+------+---------------------+ |RCRIT| 1 1 | Rayleigh distribu- | | | | tion critical value | | | | for alpha = A | +----------+------+---------------------+ |RINT| 1 1 | rint (A) (round to | | | | integral value | | | | nearest to A) | +----------+------+---------------------+ |RMS| 1 1 | Root-mean-square of | | | | A | +----------+------+---------------------+ |RMSW| 1 1 | Root-mean-square of | | | | A for weights in B | +----------+------+---------------------+ |RPDF| 1 1 | Rayleigh probabil- | | | | ity density func- | | | | tion for z = A | +----------+------+---------------------+ |ROLL| 2 0 | Cyclicly shifts the | | | | top A stack items | | | | by an amount B | +----------+------+---------------------+ |ROTX| 2 1 | Rotate A by the | | | | (constant) shift B | | | | in x-direction | +----------+------+---------------------+ |ROTY| 2 1 | Rotate A by the | | | | (constant) shift B | | | | in y-direction | +----------+------+---------------------+ |SDIST| 2 1 | Spherical (Great | | | | circle|geodesic) | | | | distance (in km) | | | | between nodes and | | | | stack (A, B) | +----------+------+---------------------+ |SDIST2| 2 1 | As SDIST but only | | | | to nodes that are | | | | != 0 | +----------+------+---------------------+ |SAZ| 2 1 | Spherical azimuth | | | | from grid nodes to | | | | stack lon, lat | | | | (i.e., A, B) | +----------+------+---------------------+ |SBAZ| 2 1 | Spherical | | | | back-azimuth from | | | | grid nodes to stack | | | | lon, lat (i.e., A, | | | | B) | +----------+------+---------------------+ |SEC| 1 1 | sec (A) (A in radi- | | | | ans) | +----------+------+---------------------+ |SECD| 1 1 | sec (A) (A in | | | | degrees) | +----------+------+---------------------+ |SIGN| 1 1 | sign (+1 or -1) of | | | | A | +----------+------+---------------------+ |SIN| 1 1 | sin (A) (A in radi- | | | | ans) | +----------+------+---------------------+ |SINC| 1 1 | sinc (A) (sin | | | | (pi*A)/(pi*A)) | +----------+------+---------------------+ |SIND| 1 1 | sin (A) (A in | | | | degrees) | +----------+------+---------------------+ |SINH| 1 1 | sinh (A) | +----------+------+---------------------+ |SKEW| 1 1 | Skewness of A | +----------+------+---------------------+ |SQR| 1 1 | A^2 | +----------+------+---------------------+ |SQRT| 1 1 | sqrt (A) | +----------+------+---------------------+ |STD| 1 1 | Standard deviation | | | | of A | +----------+------+---------------------+ |STDW| 2 1 | Weighted standard | | | | deviation of A for | | | | weights in B | +----------+------+---------------------+ |STEP| 1 1 | Heaviside step | | | | function: H(A) | +----------+------+---------------------+ |STEPX| 1 1 | Heaviside step | | | | function in x: | | | | H(x-A) | +----------+------+---------------------+ |STEPY| 1 1 | Heaviside step | | | | function in y: | | | | H(y-A) | +----------+------+---------------------+ |SUB| 2 1 | A - B | +----------+------+---------------------+ |SUM| 1 1 | Sum of all values | | | | in A | +----------+------+---------------------+ |TAN| 1 1 | tan (A) (A in radi- | | | | ans) | +----------+------+---------------------+ |TAND| 1 1 | tan (A) (A in | | | | degrees) | +----------+------+---------------------+ |TANH| 1 1 | tanh (A) | +----------+------+---------------------+ |TAPER| 2 1 | Unit weights | | | | cosine-tapered to | | | | zero within A and B | | | | of x and y grid | | | | margins | +----------+------+---------------------+ |TCDF| 2 1 | Studentas t cumula- | | | | tive distribution | | | | function for t = A, | | | | and nu = B | +----------+------+---------------------+ |TCRIT| 2 1 | Studentas t distri- | | | | bution critical | | | | value for alpha = A | | | | and nu = B | +----------+------+---------------------+ |TN| 2 1 | Chebyshev polyno- | | | | mial Tn(-1<t<+1,n), | | | | with t = A, and n = | | | | B | +----------+------+---------------------+ |TPDF| 2 1 | Studentas t proba- | | | | bility density | | | | function for t = A, | | | | and nu = B | +----------+------+---------------------+ |TRIM| 3 1 | Alpha-trim C to NaN | | | | if values fall in | | | | tails A and B (in | | | | percentage) | +----------+------+---------------------+ |UPPER| 1 1 | The highest (maxi- | | | | mum) value of A | +----------+------+---------------------+ |VAR| 1 1 | Variance of A | +----------+------+---------------------+ |VARW| 2 1 | Weighted variance | | | | of A for weights in | | | | B | +----------+------+---------------------+ |WCDF| 3 1 | Weibull cumulative | | | | distribution func- | | | | tion for x = A, | | | | scale = B, and | | | | shape = C | +----------+------+---------------------+ |WCRIT| 3 1 | Weibull distribu- | | | | tion critical value | | | | for alpha = A, | | | | scale = B, and | | | | shape = C | +----------+------+---------------------+ |WPDF| 3 1 | Weibull density | | | | distribution | | | | P(x,scale,shape), | | | | with x = A, scale = | | | | B, and shape = C | +----------+------+---------------------+ |WRAP| 1 1 | wrap A in radians | | | | onto [-pi,pi] | +----------+------+---------------------+ |XOR| 2 1 | 0 if A == NaN and B | | | | == NaN, NaN if B == | | | | NaN, else A | +----------+------+---------------------+ |Y0| 1 1 | Bessel function of | | | | A (2nd kind, order | | | | 0) | +----------+------+---------------------+ |Y1| 1 1 | Bessel function of | | | | A (2nd kind, order | | | | 1) | +----------+------+---------------------+ |YLM| 2 2 | Re and Im orthonor- | | | | malized spherical | | | | harmonics degree A | | | | order B | +----------+------+---------------------+ |YLMg| 2 2 | Cos and Sin normal- | | | | ized spherical har- | | | | monics degree A | | | | order B (geophysi- | | | | cal convention) | +----------+------+---------------------+ |YN| 2 1 | Bessel function of | | | | A (2nd kind, order | | | | B) | +----------+------+---------------------+ |ZCDF| 1 1 | Normal cumulative | | | | distribution func- | | | | tion for z = A | +----------+------+---------------------+ |ZPDF| 1 1 | Normal probability | | | | density function | | | | for z = A | +----------+------+---------------------+ |ZCRIT| 1 1 | Normal distribution | | | | critical value for | | | | alpha = A | +----------+------+---------------------+

## SYMBOLS

The following symbols have special meaning: +-------+----------------------------+ |PI| 3.1415926a| | +-------+----------------------------+ |E| 2.7182818a| | +-------+----------------------------+ |EULER| 0.5772156a| | +-------+----------------------------+ |EPS_F| 1.192092896e-07 (single | | | precision epsilon | +-------+----------------------------+ |XMIN| Minimum x value | +-------+----------------------------+ |XMAX| Maximum x value | +-------+----------------------------+ |XRANGE| Range of x values | +-------+----------------------------+ |XINC| x increment | +-------+----------------------------+ |NX| The number of x nodes | +-------+----------------------------+ |YMIN| Minimum y value | +-------+----------------------------+ |YMAX| Maximum y value | +-------+----------------------------+ |YRANGE| Range of y values | +-------+----------------------------+ |YINC| y increment | +-------+----------------------------+ |NY| The number of y nodes | +-------+----------------------------+ |X| Grid with x-coordinates | +-------+----------------------------+ |Y| Grid with y-coordinates | +-------+----------------------------+ |XNORM| Grid with normalized [-1 | | | to +1] x-coordinates | +-------+----------------------------+ |YNORM| Grid with normalized [-1 | | | to +1] y-coordinates | +-------+----------------------------+ |XCOL| Grid with column numbers | | | 0, 1,a|, NX-1 | +-------+----------------------------+ |YROW| Grid with row numbers 0, | | | 1,a|, NY-1 | +-------+----------------------------+ |NODE| Grid with node numbers 0, | | | 1,a|, (NX*NY)-1 | +-------+----------------------------+

## NOTES ON OPERATORS

1. For Cartesian grids the operatorsMEAN,MEDIAN,MODE,LMSSCL,MAD,PQUANT,RMS,STD, andVARreturn the expected value from the given matrix. However, for geographic grids we perform a spherically weighted calculation where each node value is weighted by the geo- graphic area represented by that node. 2. The operatorSDISTcalculates spherical distances in km between the (lon, lat) point on the stack and all node positions in the grid. The grid domain and the (lon, lat) point are expected to be in degrees. Similarly, theSAZandSBAZoperators calculate spherical azimuth and back-azimuths in degrees, respectively. The operatorsLDISTandPDISTcompute spherical distances in km if-fgis set or implied, else they return Cartesian distances. Note: If the current PROJ_ELLIPSOID is ellipsoidal then geodesics are used in calcula- tions of distances, which can be slow. You can trade speed with accuracy by changing the algorithm used to compute the geodesic (see PROJ_GEODESIC). The operatorLDISTGis a version ofLDISTthat operates on the GSHHG data. Instead of reading an ASCII file, it directly accesses one of the GSHHG data sets as determined by the-Dand-Aoptions. 3. The operatorPOINTreads a ASCII table, computes the mean x and mean y values and places these on the stack. If geographic data then we use the mean 3-D vector to determine the mean location. 4. The operatorPLMcalculates the associated Legendre polynomial of degree L and order M (0 <= M <= L), and its argument is the sine of the latitude.PLMis not normalized and includes the Condon-Short- ley phase (-1)^M.PLMgis normalized in the way that is most com- monly used in geophysics. The C-S phase can be added by using -M as argument.PLMwill overflow at higher degrees, whereasPLMgis stable until ultra high degrees (at least 3000). 5. The operatorsYLMandYLMgcalculate normalized spherical harmonics for degree L and order M (0 <= M <= L) for all positions in the grid, which is assumed to be in degrees.YLMandYLMgreturn two grids, the real (cosine) and imaginary (sine) component of the com- plex spherical harmonic. Use thePOPoperator (andEXCH) to get rid of one of them, or save both by giving two consecutive = file.nc calls. The orthonormalized complex harmonicsYLMare most commonly used in physics and seismology. The square ofYLMintegrates to 1 over a sphere. In geophysics,YLMgis normalized to produce unit power when averaging the cosine and sine terms (separately!) over a sphere (i.e., their squares each integrate to 4 pi). The Con- don-Shortley phase (-1)^M is not included inYLMorYLMg, but it can be added by using -M as argument. 6. All the derivatives are based on central finite differences, with natural boundary conditions, and are Cartesian derivatives. 7. Files that have the same names as some operators, e.g.,ADD,SIGN,=, etc. should be identified by prepending the current directory (i.e., ./LOG). 8. Piping of files is not allowed. 9. The stack depth limit is hard-wired to 100. 10. All functions expecting a positive radius (e.g.,LOG,KEI, etc.) are passed the absolute value of their argument. (9) The bitwise operators (BITAND,BITLEFT,BITNOT,BITOR,BITRIGHT,BITTEST, andBITXOR) convert a gridas single precision values to unsigned 32-bit ints to perform the bitwise operations. Consequently, the largest whole integer value that can be stored in a float grid is 2^24 or 16,777,216. Any higher result will be masked to fit in the lower 24 bits. Thus, bit operations are effectively limited to 24 bit. All bitwise operators return NaN if given NaN arguments or bit-settings <= 0. 11. When OpenMP support is compiled in, a few operators will take advantage of the ability to spread the load onto several cores. At present, the list of such operators is:LDIST,LDIST2,PDIST,PDIST2,SAZ,SBAZ,SDIST,YLM, andgrd_YLMg.

## GRID VALUES PRECISION

Regardless of the precision of the input data, GMT programs that create grid files will internally hold the grids in 4-byte floating point arrays. This is done to conserve memory and furthermore most if not all real data can be stored using 4-byte floating point values. Data with higher precision (i.e., double precision values) will lose that preci- sion once GMT operates on the grid or writes out new grids. To limit loss of precision when processing data you should always consider nor- malizing the data prior to processing.

## GRID FILE FORMATS

By default GMT writes out grid as single precision floats in a COARDS-complaint netCDF file format. However, GMT is able to produce grid files in many other commonly used grid file formats and also facilitates so calledapackingaof grids, writing out floating point data as 1- or 2-byte integers. (morea|)

## GEOGRAPHICAL AND TIME COORDINATES

When the output grid type is netCDF, the coordinates will be labeledalongitudea,alatitudea, oratimeabased on the attributes of the input data or grid (if any) or on the-for-Roptions. For example, both-f0x-f1tand-R90w/90e/0t/3t will result in a longitude/time grid. When the x, y, or z coordinate is time, it will be stored in the grid as relative time since epoch as specified by TIME_UNIT and TIME_EPOCH in the gmt.conf file or on the command line. In addition, theunitattribute of the time variable will indicate both this unit and epoch.

## STORE, RECALL AND CLEAR

You may store intermediate calculations to a named variable that you may recall and place on the stack at a later time. This is useful if you need access to a computed quantity many times in your expression as it will shorten the overall expression and improve readability. To save a result you use the special operatorSTO@label, wherelabelis the name you choose to give the quantity. To recall the stored result to the stack at a later time, use [RCL]@label, i.e.,RCLis optional. To clear memory you may useCLR@label. Note thatSTOandCLRleave the stack unchanged.

## GSHHS INFORMATION

The coastline database is GSHHG (formerly GSHHS) which is compiled from three sources: World Vector Shorelines (WVS), CIA World Data Bank II (WDBII), and Atlas of the Cryosphere (AC, for Antarctica only). Apart from Antarctica, all level-1 polygons (ocean-land boundary) are derived from the more accurate WVS while all higher level polygons (level 2-4, representing land/lake, lake/island-in-lake, and island-in-lake/lake-in-island-in-lake boundaries) are taken from WDBII. The Antarctica coastlines come in two flavors: ice-front or grounding line, selectable via the-Aoption. Much processing has taken place to convert WVS, WDBII, and AC data into usable form for GMT: assembling closed polygons from line segments, checking for duplicates, and cor- recting for crossings between polygons. The area of each polygon has been determined so that the user may choose not to draw features smaller than a minimum area (see-A); one may also limit the highest hierarchical level of polygons to be included (4 is the maximum). The 4 lower-resolution databases were derived from the full resolution data- base using the Douglas-Peucker line-simplification algorithm. The clas- sification of rivers and borders follow that of the WDBII. See the GMT Cookbook and Technical Reference Appendix K for further details.

## MACROS

Users may save their favorite operator combinations as macros via the filegrdmath.macrosin their current or user directory. The file may contain any number of macros (one per record); comment lines starting with # are skipped. The format for the macros isname=arg1arg2a|arg2:commentwherenameis how the macro will be used. When this operator appears on the command line we simply replace it with the listed argument list. No macro may call another macro. As an example, the following macro expects three arguments (radius x0 y0) and sets the modes that are inside the given circle to 1 and those outside to 0: INCIRCLE = CDIST EXCH DIV 1 LE : usage: r x y INCIRCLE to return 1 inside circle Note: Because geographic or time constants may be present in a macro, it is required that the optional comment flag (:) must be followed by a space.

## EXAMPLES

To compute all distances to north pole: gmt grdmath -Rg -I1 0 90 SDIST = dist_to_NP.nc To take log10 of the average of 2 files, use gmt grdmath file1.nc file2.nc ADD 0.5 MUL LOG10 = file3.nc Given the file ages.nc, which holds seafloor ages in m.y., use the relation depth(in m) = 2500 + 350 * sqrt (age) to estimate normal seafloor depths: gmt grdmath ages.nc SQRT 350 MUL 2500 ADD = depths.nc To find the angle a (in degrees) of the largest principal stress from the stress tensor given by the three files s_xx.nc s_yy.nc, and s_xy.nc from the relation tan (2*a) = 2 * s_xy / (s_xx - s_yy), use gmt grdmath 2 s_xy.nc MUL s_xx.nc s_yy.nc SUB DIV ATAN 2 DIV = direction.nc To calculate the fully normalized spherical harmonic of degree 8 and order 4 on a 1 by 1 degree world map, using the real amplitude 0.4 and the imaginary amplitude 1.1: gmt grdmath -R0/360/-90/90 -I1 8 4 YLM 1.1 MUL EXCH 0.4 MUL ADD = harm.nc To extract the locations of local maxima that exceed 100 mGal in the file faa.nc: gmt grdmath faa.nc DUP EXTREMA 2 EQ MUL DUP 100 GT MUL 0 NAN = z.nc gmt grd2xyz z.nc -s > max.xyz To demonstrate the use of named variables, consider this radial wave where we store and recall the normalized radial arguments in radians: gmt grdmath -R0/10/0/10 -I0.25 5 5 CDIST 2 MUL PI MUL 5 DIV STO@r COS @r SIN MUL = wave.nc To creat a dumb file saved as a 32 bits float GeoTiff using GDAL, run gmt grdmath -Rd -I10 X Y MUL = lixo.tiff=gd:GTiff

## REFERENCES

Abramowitz, M., and I. A. Stegun, 1964,HandbookofMathematicalFunc-tions, Applied Mathematics Series, vol. 55, Dover, New York. 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.JournalofGeodesy, 76, 279-299. Press, W. H., S. A. Teukolsky, W. T. Vetterling, and B. P. Flannery, 1992,NumericalRecipes, 2nd edition, Cambridge Univ., New York. Spanier, J., and K. B. Oldman, 1987,AnAtlasofFunctions, Hemisphere Publishing Corp.

## SEE ALSO

gmt(1),gmtmath(1),grd2xyz(1),grdedit(1),grdinfo(1),xyz2grd(1)

## COPYRIGHT

2017, P. Wessel, W. H. F. Smith, R. Scharroo, J. Luis, and F. Wobbe 5.4.2 Jun 24, 2017 grdmath(1)

gmt5 5.4.2 - Generated Thu Jun 29 07:39:24 CDT 2017