1GMTMATH(1) GMT GMTMATH(1)
2
3
4
6 gmtmath - Reverse Polish Notation (RPN) calculator for data tables
7
9 gmtmath [ -At_f(t).d[+e][+s|w] ] [ -Ccols ] [ -Eeigen ] [ -I ] [
10 -Nn_col[/t_col] ] [ -Q ] [ -S[f|l] ] [ -Tt_min/t_max/t_inc[+n]|tfile
11 ] [ -V[level] ] [ -bbinary ] [ -dnodata ] [ -eregexp ] [ -fflags ] [
12 -ggaps ] [ -hheaders ] [ -iflags ] [ -oflags ] [ -sflags ] operand [
13 operand ] OPERATOR [ operand ] OPERATOR ... = [ outfile ]
14
15 Note: No space is allowed between the option flag and the associated
16 arguments.
17
19 gmtmath will perform operations like add, subtract, multiply, and
20 divide on one or more table data files or constants using Reverse Pol‐
21 ish Notation (RPN) syntax (e.g., Hewlett-Packard calculator-style).
22 Arbitrarily complicated expressions may therefore be evaluated; the
23 final result is written to an output file [or standard output]. Data
24 operations are element-by-element, not matrix manipulations (except
25 where noted). Some operators only require one operand (see below). If
26 no data tables are used in the expression then options -T, -N can be
27 set (and optionally -bo to indicate the data type for binary tables).
28 If STDIN is given, the standard input will be read and placed on the
29 stack as if a file with that content had been given on the command
30 line. By default, all columns except the "time" column are operated on,
31 but this can be changed (see -C). Complicated or frequently occurring
32 expressions may be coded as a macro for future use or stored and
33 recalled via named memory locations.
34
36 operand
37 If operand can be opened as a file it will be read as an ASCII
38 (or binary, see -bi) table data file. If not a file, it is
39 interpreted as a numerical constant or a special symbol (see
40 below). The special argument STDIN means that stdin will be read
41 and placed on the stack; STDIN can appear more than once if nec‐
42 essary.
43
44 outfile
45 The name of a table data file that will hold the final result.
46 If not given then the output is sent to stdout.
47
49 -At_f(t).d[+e][+r][+s|w]
50 Requires -N and will partially initialize a table with values
51 from the given file containing t and f(t) only. The t is placed
52 in column t_col while f(t) goes into column n_col - 1 (see -N).
53 Append +r to only place f(t) and leave the left hand side of the
54 matrix equation alone. If used with operators LSQFIT and SVDFIT
55 you can optionally append the modifier +e which will instead
56 evaluate the solution and write a data set with four columns: t,
57 f(t), the model solution at t, and the the residuals at t,
58 respectively [Default writes one column with model coeffi‐
59 cients]. Append +w if t_f(t).d has a third column with weights,
60 or append +s if t_f(t).d has a third column with 1-sigma. In
61 those two cases we find the weighted solution. The weights (or
62 sigmas) will be output as the last column when +e is in effect.
63
64 -Ccols Select the columns that will be operated on until next occur‐
65 rence of -C. List columns separated by commas; ranges like
66 1,3-5,7 are allowed. -C (no arguments) resets the default action
67 of using all columns except time column (see -N). -Ca selects
68 all columns, including time column, while -Cr reverses (toggles)
69 the current choices. When -C is in effect it also controls
70 which columns from a file will be placed on the stack.
71
72 -Eeigen
73 Sets the minimum eigenvalue used by operators LSQFIT and SVDFIT
74 [1e-7]. Smaller eigenvalues are set to zero and will not be
75 considered in the solution.
76
77 -I Reverses the output row sequence from ascending time to descend‐
78 ing [ascending].
79
80 -Nn_col[/t_col]
81 Select the number of columns and optionally the column number
82 that contains the "time" variable [0]. Columns are numbered
83 starting at 0 [2/0]. If input files are specified then -N will
84 add any missing columns.
85
86 -Q Quick mode for scalar calculation. Shorthand for -Ca -N1/0
87 -T0/0/1. In this mode, constants may have plot units (i.e., c,
88 i, p) and if so the final answer will be reported in the unit
89 set by PROJ_LENGTH_UNIT.
90
91 -S[f|l]
92 Only report the first or last row of the results [Default is all
93 rows]. This is useful if you have computed a statistic (say the
94 MODE) and only want to report a single number instead of numer‐
95 ous records with identical values. Append l to get the last row
96 and f to get the first row only [Default].
97
98 -Tt_min/t_max/t_inc[+n]|tfile
99 Required when no input files are given. Sets the t-coordinates
100 of the first and last point and the equidistant sampling inter‐
101 val for the "time" column (see -N). Append +n if you are speci‐
102 fying the number of equidistant points instead. If there is no
103 time column (only data columns), give -T with no arguments; this
104 also implies -Ca. Alternatively, give the name of a file whose
105 first column contains the desired t-coordinates which may be
106 irregular.
107
108 -V[level] (more ...)
109 Select verbosity level [c].
110
111 -bi[ncols][t] (more ...)
112 Select native binary input.
113
114 -bo[ncols][type] (more ...)
115 Select native binary output. [Default is same as input, but see
116 -o]
117
118 -d[i|o]nodata (more ...)
119 Replace input columns that equal nodata with NaN and do the
120 reverse on output.
121
122 -e[~]"pattern" | -e[~]/regexp/[i] (more ...)
123 Only accept data records that match the given pattern.
124
125 -f[i|o]colinfo (more ...)
126 Specify data types of input and/or output columns.
127
128 -g[a]x|y|d|X|Y|D|[col]z[+|-]gap[u] (more ...)
129 Determine data gaps and line breaks.
130
131 -h[i|o][n][+c][+d][+rremark][+rtitle] (more ...)
132 Skip or produce header record(s).
133
134 -icols[+l][+sscale][+ooffset][,...] (more ...)
135 Select input columns and transformations (0 is first column).
136
137 -ocols[,...] (more ...)
138 Select output columns (0 is first column).
139
140 -s[cols][a|r] (more ...)
141 Set handling of NaN records.
142
143 -^ or just -
144 Print a short message about the syntax of the command, then
145 exits (NOTE: on Windows just use -).
146
147 -+ or just +
148 Print an extensive usage (help) message, including the explana‐
149 tion of any module-specific option (but not the GMT common
150 options), then exits.
151
152 -? or no arguments
153 Print a complete usage (help) message, including the explanation
154 of all options, then exits.
155
157 Choose among the following 185 operators. "args" are the number of
158 input and output arguments.
159
160 ┌──────────┬──────┬─────────────────────┐
161 │Operator │ args │ Returns │
162 ├──────────┼──────┼─────────────────────┤
163 │ABS │ 1 1 │ abs (A) │
164 ├──────────┼──────┼─────────────────────┤
165 │ACOS │ 1 1 │ acos (A) │
166 ├──────────┼──────┼─────────────────────┤
167 │ACOSH │ 1 1 │ acosh (A) │
168 ├──────────┼──────┼─────────────────────┤
169 │ACSC │ 1 1 │ acsc (A) │
170 ├──────────┼──────┼─────────────────────┤
171 │ACOT │ 1 1 │ acot (A) │
172 ├──────────┼──────┼─────────────────────┤
173 │ADD │ 2 1 │ A + B │
174 ├──────────┼──────┼─────────────────────┤
175 │AND │ 2 1 │ B if A == NaN, else │
176 │ │ │ A │
177 ├──────────┼──────┼─────────────────────┤
178 │ASEC │ 1 1 │ asec (A) │
179 ├──────────┼──────┼─────────────────────┤
180 │ASIN │ 1 1 │ asin (A) │
181 ├──────────┼──────┼─────────────────────┤
182 │ASINH │ 1 1 │ asinh (A) │
183 ├──────────┼──────┼─────────────────────┤
184 │ATAN │ 1 1 │ atan (A) │
185 ├──────────┼──────┼─────────────────────┤
186 │ATAN2 │ 2 1 │ atan2 (A, B) │
187 ├──────────┼──────┼─────────────────────┤
188 │ATANH │ 1 1 │ atanh (A) │
189 ├──────────┼──────┼─────────────────────┤
190 │BCDF │ 3 1 │ Binomial cumulative │
191 │ │ │ distribution func‐ │
192 │ │ │ tion for p = A, n = │
193 │ │ │ B, and x = C │
194 ├──────────┼──────┼─────────────────────┤
195 │BPDF │ 3 1 │ Binomial probabil‐ │
196 │ │ │ ity density func‐ │
197 │ │ │ tion for p = A, n = │
198 │ │ │ B, and x = C │
199 └──────────┴──────┴─────────────────────┘
200
201 │BEI │ 1 1 │ bei (A) │
202 ├──────────┼──────┼─────────────────────┤
203 │BER │ 1 1 │ ber (A) │
204 ├──────────┼──────┼─────────────────────┤
205 │BITAND │ 2 1 │ A & B (bitwise AND │
206 │ │ │ operator) │
207 ├──────────┼──────┼─────────────────────┤
208 │BITLEFT │ 2 1 │ A << B (bitwise │
209 │ │ │ left-shift opera‐ │
210 │ │ │ tor) │
211 ├──────────┼──────┼─────────────────────┤
212 │BITNOT │ 1 1 │ ~A (bitwise NOT │
213 │ │ │ operator, i.e., │
214 │ │ │ return two's com‐ │
215 │ │ │ plement) │
216 ├──────────┼──────┼─────────────────────┤
217 │BITOR │ 2 1 │ A | B (bitwise OR │
218 │ │ │ operator) │
219 ├──────────┼──────┼─────────────────────┤
220 │BITRIGHT │ 2 1 │ A >> B (bitwise │
221 │ │ │ right-shift opera‐ │
222 │ │ │ tor) │
223 ├──────────┼──────┼─────────────────────┤
224 │BITTEST │ 2 1 │ 1 if bit B of A is │
225 │ │ │ set, else 0 (bit‐ │
226 │ │ │ wise TEST operator) │
227 ├──────────┼──────┼─────────────────────┤
228 │BITXOR │ 2 1 │ A ^ B (bitwise XOR │
229 │ │ │ operator) │
230 ├──────────┼──────┼─────────────────────┤
231 │CEIL │ 1 1 │ ceil (A) (smallest │
232 │ │ │ integer >= A) │
233 ├──────────┼──────┼─────────────────────┤
234 │CHICRIT │ 2 1 │ Chi-squared distri‐ │
235 │ │ │ bution critical │
236 │ │ │ value for alpha = A │
237 │ │ │ and nu = B │
238 ├──────────┼──────┼─────────────────────┤
239 │CHICDF │ 2 1 │ Chi-squared cumula‐ │
240 │ │ │ tive distribution │
241 │ │ │ function for chi2 = │
242 │ │ │ A and nu = B │
243 ├──────────┼──────┼─────────────────────┤
244 │CHIPDF │ 2 1 │ Chi-squared proba‐ │
245 │ │ │ bility density │
246 │ │ │ function for chi2 = │
247 │ │ │ A and nu = B │
248 ├──────────┼──────┼─────────────────────┤
249 │COL │ 1 1 │ Places column A on │
250 │ │ │ the stack │
251 ├──────────┼──────┼─────────────────────┤
252 │COMB │ 2 1 │ Combinations n_C_r, │
253 │ │ │ with n = A and r = │
254 │ │ │ B │
255 ├──────────┼──────┼─────────────────────┤
256 │CORRCOEFF │ 2 1 │ Correlation coeffi‐ │
257 │ │ │ cient r(A, B) │
258 ├──────────┼──────┼─────────────────────┤
259 │COS │ 1 1 │ cos (A) (A in radi‐ │
260 │ │ │ ans) │
261 ├──────────┼──────┼─────────────────────┤
262 │COSD │ 1 1 │ cos (A) (A in │
263 │ │ │ degrees) │
264 ├──────────┼──────┼─────────────────────┤
265 │COSH │ 1 1 │ cosh (A) │
266 └──────────┴──────┴─────────────────────┘
267
268 │COT │ 1 1 │ cot (A) (A in radi‐ │
269 │ │ │ ans) │
270 ├──────────┼──────┼─────────────────────┤
271 │COTD │ 1 1 │ cot (A) (A in │
272 │ │ │ degrees) │
273 ├──────────┼──────┼─────────────────────┤
274 │CSC │ 1 1 │ csc (A) (A in radi‐ │
275 │ │ │ ans) │
276 ├──────────┼──────┼─────────────────────┤
277 │CSCD │ 1 1 │ csc (A) (A in │
278 │ │ │ degrees) │
279 ├──────────┼──────┼─────────────────────┤
280 │DDT │ 1 1 │ d(A)/dt Central 1st │
281 │ │ │ derivative │
282 ├──────────┼──────┼─────────────────────┤
283 │D2DT2 │ 1 1 │ d^2(A)/dt^2 2nd de‐ │
284 │ │ │ rivative │
285 ├──────────┼──────┼─────────────────────┤
286 │D2R │ 1 1 │ Converts Degrees to │
287 │ │ │ Radians │
288 ├──────────┼──────┼─────────────────────┤
289 │DENAN │ 2 1 │ Replace NaNs in A │
290 │ │ │ with values from B │
291 ├──────────┼──────┼─────────────────────┤
292 │DILOG │ 1 1 │ dilog (A) │
293 ├──────────┼──────┼─────────────────────┤
294 │DIFF │ 1 1 │ Forward difference │
295 │ │ │ between adjacent │
296 │ │ │ elements of A │
297 │ │ │ (A[1]-A[0], │
298 │ │ │ A[2]-A[1], ..., │
299 │ │ │ NaN) │
300 ├──────────┼──────┼─────────────────────┤
301 │DIV │ 2 1 │ A / B │
302 ├──────────┼──────┼─────────────────────┤
303 │DUP │ 1 2 │ Places duplicate of │
304 │ │ │ A on the stack │
305 ├──────────┼──────┼─────────────────────┤
306 │ECDF │ 2 1 │ Exponential cumula‐ │
307 │ │ │ tive distribution │
308 │ │ │ function for x = A │
309 │ │ │ and lambda = B │
310 ├──────────┼──────┼─────────────────────┤
311 │ECRIT │ 2 1 │ Exponential distri‐ │
312 │ │ │ bution critical │
313 │ │ │ value for alpha = A │
314 │ │ │ and lambda = B │
315 ├──────────┼──────┼─────────────────────┤
316 │EPDF │ 2 1 │ Exponential proba‐ │
317 │ │ │ bility density │
318 │ │ │ function for x = A │
319 │ │ │ and lambda = B │
320 ├──────────┼──────┼─────────────────────┤
321 │ERF │ 1 1 │ Error function erf │
322 │ │ │ (A) │
323 ├──────────┼──────┼─────────────────────┤
324 │ERFC │ 1 1 │ Complementary Error │
325 │ │ │ function erfc (A) │
326 ├──────────┼──────┼─────────────────────┤
327 │ERFINV │ 1 1 │ Inverse error func‐ │
328 │ │ │ tion of A │
329 ├──────────┼──────┼─────────────────────┤
330 │EQ │ 2 1 │ 1 if A == B, else 0 │
331 └──────────┴──────┴─────────────────────┘
332
333
334
335 │EXCH │ 2 2 │ Exchanges A and B │
336 │ │ │ on the stack │
337 ├──────────┼──────┼─────────────────────┤
338 │EXP │ 1 1 │ exp (A) │
339 ├──────────┼──────┼─────────────────────┤
340 │FACT │ 1 1 │ A! (A factorial) │
341 ├──────────┼──────┼─────────────────────┤
342 │FCDF │ 3 1 │ F cumulative dis‐ │
343 │ │ │ tribution function │
344 │ │ │ for F = A, nu1 = B, │
345 │ │ │ and nu2 = C │
346 ├──────────┼──────┼─────────────────────┤
347 │FCRIT │ 3 1 │ F distribution │
348 │ │ │ critical value for │
349 │ │ │ alpha = A, nu1 = B, │
350 │ │ │ and nu2 = C │
351 ├──────────┼──────┼─────────────────────┤
352 │FLIPUD │ 1 1 │ Reverse order of │
353 │ │ │ each column │
354 ├──────────┼──────┼─────────────────────┤
355 │FLOOR │ 1 1 │ floor (A) (greatest │
356 │ │ │ integer <= A) │
357 ├──────────┼──────┼─────────────────────┤
358 │FMOD │ 2 1 │ A % B (remainder │
359 │ │ │ after truncated │
360 │ │ │ division) │
361 ├──────────┼──────┼─────────────────────┤
362 │FPDF │ 3 1 │ F probability den‐ │
363 │ │ │ sity function for F │
364 │ │ │ = A, nu1 = B, and │
365 │ │ │ nu2 = C │
366 ├──────────┼──────┼─────────────────────┤
367 │GE │ 2 1 │ 1 if A >= B, else 0 │
368 ├──────────┼──────┼─────────────────────┤
369 │GT │ 2 1 │ 1 if A > B, else 0 │
370 ├──────────┼──────┼─────────────────────┤
371 │HYPOT │ 2 1 │ hypot (A, B) = sqrt │
372 │ │ │ (A*A + B*B) │
373 ├──────────┼──────┼─────────────────────┤
374 │I0 │ 1 1 │ Modified Bessel │
375 │ │ │ function of A (1st │
376 │ │ │ kind, order 0) │
377 ├──────────┼──────┼─────────────────────┤
378 │I1 │ 1 1 │ Modified Bessel │
379 │ │ │ function of A (1st │
380 │ │ │ kind, order 1) │
381 ├──────────┼──────┼─────────────────────┤
382 │IFELSE │ 3 1 │ B if A != 0, else C │
383 ├──────────┼──────┼─────────────────────┤
384 │IN │ 2 1 │ Modified Bessel │
385 │ │ │ function of A (1st │
386 │ │ │ kind, order B) │
387 ├──────────┼──────┼─────────────────────┤
388 │INRANGE │ 3 1 │ 1 if B <= A <= C, │
389 │ │ │ else 0 │
390 ├──────────┼──────┼─────────────────────┤
391 │INT │ 1 1 │ Numerically inte‐ │
392 │ │ │ grate A │
393 ├──────────┼──────┼─────────────────────┤
394 │INV │ 1 1 │ 1 / A │
395 ├──────────┼──────┼─────────────────────┤
396 │ISFINITE │ 1 1 │ 1 if A is finite, │
397 │ │ │ else 0 │
398 └──────────┴──────┴─────────────────────┘
399
400
401
402 │ISNAN │ 1 1 │ 1 if A == NaN, else │
403 │ │ │ 0 │
404 ├──────────┼──────┼─────────────────────┤
405 │J0 │ 1 1 │ Bessel function of │
406 │ │ │ A (1st kind, order │
407 │ │ │ 0) │
408 ├──────────┼──────┼─────────────────────┤
409 │J1 │ 1 1 │ Bessel function of │
410 │ │ │ A (1st kind, order │
411 │ │ │ 1) │
412 ├──────────┼──────┼─────────────────────┤
413 │JN │ 2 1 │ Bessel function of │
414 │ │ │ A (1st kind, order │
415 │ │ │ B) │
416 ├──────────┼──────┼─────────────────────┤
417 │K0 │ 1 1 │ Modified Kelvin │
418 │ │ │ function of A (2nd │
419 │ │ │ kind, order 0) │
420 ├──────────┼──────┼─────────────────────┤
421 │K1 │ 1 1 │ Modified Bessel │
422 │ │ │ function of A (2nd │
423 │ │ │ kind, order 1) │
424 ├──────────┼──────┼─────────────────────┤
425 │KN │ 2 1 │ Modified Bessel │
426 │ │ │ function of A (2nd │
427 │ │ │ kind, order B) │
428 ├──────────┼──────┼─────────────────────┤
429 │KEI │ 1 1 │ kei (A) │
430 ├──────────┼──────┼─────────────────────┤
431 │KER │ 1 1 │ ker (A) │
432 ├──────────┼──────┼─────────────────────┤
433 │KURT │ 1 1 │ Kurtosis of A │
434 ├──────────┼──────┼─────────────────────┤
435 │LCDF │ 1 1 │ Laplace cumulative │
436 │ │ │ distribution func‐ │
437 │ │ │ tion for z = A │
438 ├──────────┼──────┼─────────────────────┤
439 │LCRIT │ 1 1 │ Laplace distribu‐ │
440 │ │ │ tion critical value │
441 │ │ │ for alpha = A │
442 ├──────────┼──────┼─────────────────────┤
443 │LE │ 2 1 │ 1 if A <= B, else 0 │
444 ├──────────┼──────┼─────────────────────┤
445 │LMSSCL │ 1 1 │ LMS scale estimate │
446 │ │ │ (LMS STD) of A │
447 ├──────────┼──────┼─────────────────────┤
448 │LMSSCLW │ 2 1 │ Weighted LMS scale │
449 │ │ │ estimate (LMS STD) │
450 │ │ │ of A for weights in │
451 │ │ │ B │
452 ├──────────┼──────┼─────────────────────┤
453 │LOG │ 1 1 │ log (A) (natural │
454 │ │ │ log) │
455 ├──────────┼──────┼─────────────────────┤
456 │LOG10 │ 1 1 │ log10 (A) (base 10) │
457 ├──────────┼──────┼─────────────────────┤
458 │LOG1P │ 1 1 │ log (1+A) (accurate │
459 │ │ │ for small A) │
460 ├──────────┼──────┼─────────────────────┤
461 │LOG2 │ 1 1 │ log2 (A) (base 2) │
462 ├──────────┼──────┼─────────────────────┤
463 │LOWER │ 1 1 │ The lowest (mini‐ │
464 │ │ │ mum) value of A │
465 └──────────┴──────┴─────────────────────┘
466
467
468
469 │LPDF │ 1 1 │ Laplace probability │
470 │ │ │ density function │
471 │ │ │ for z = A │
472 ├──────────┼──────┼─────────────────────┤
473 │LRAND │ 2 1 │ Laplace random │
474 │ │ │ noise with mean A │
475 │ │ │ and std. deviation │
476 │ │ │ B │
477 ├──────────┼──────┼─────────────────────┤
478 │LSQFIT │ 1 0 │ Let current table │
479 │ │ │ be [A | b] return │
480 │ │ │ least squares solu‐ │
481 │ │ │ tion x = A \ b │
482 ├──────────┼──────┼─────────────────────┤
483 │LT │ 2 1 │ 1 if A < B, else 0 │
484 ├──────────┼──────┼─────────────────────┤
485 │MAD │ 1 1 │ Median Absolute │
486 │ │ │ Deviation (L1 STD) │
487 │ │ │ of A │
488 ├──────────┼──────┼─────────────────────┤
489 │MADW │ 2 1 │ Weighted Median │
490 │ │ │ Absolute Deviation │
491 │ │ │ (L1 STD) of A for │
492 │ │ │ weights in B │
493 ├──────────┼──────┼─────────────────────┤
494 │MAX │ 2 1 │ Maximum of A and B │
495 ├──────────┼──────┼─────────────────────┤
496 │MEAN │ 1 1 │ Mean value of A │
497 ├──────────┼──────┼─────────────────────┤
498 │MEANW │ 2 1 │ Weighted mean value │
499 │ │ │ of A for weights in │
500 │ │ │ B │
501 ├──────────┼──────┼─────────────────────┤
502 │MEDIAN │ 1 1 │ Median value of A │
503 ├──────────┼──────┼─────────────────────┤
504 │MEDIANW │ 2 1 │ Weighted median │
505 │ │ │ value of A for │
506 │ │ │ weights in B │
507 ├──────────┼──────┼─────────────────────┤
508 │MIN │ 2 1 │ Minimum of A and B │
509 ├──────────┼──────┼─────────────────────┤
510 │MOD │ 2 1 │ A mod B (remainder │
511 │ │ │ after floored divi‐ │
512 │ │ │ sion) │
513 ├──────────┼──────┼─────────────────────┤
514 │MODE │ 1 1 │ Mode value (Least │
515 │ │ │ Median of Squares) │
516 │ │ │ of A │
517 ├──────────┼──────┼─────────────────────┤
518 │MODEW │ 2 1 │ Weighted mode value │
519 │ │ │ (Least Median of │
520 │ │ │ Squares) of A for │
521 │ │ │ weights in B │
522 ├──────────┼──────┼─────────────────────┤
523 │MUL │ 2 1 │ A * B │
524 ├──────────┼──────┼─────────────────────┤
525 │NAN │ 2 1 │ NaN if A == B, else │
526 │ │ │ A │
527 ├──────────┼──────┼─────────────────────┤
528 │NEG │ 1 1 │ -A │
529 ├──────────┼──────┼─────────────────────┤
530 │NEQ │ 2 1 │ 1 if A != B, else 0 │
531 ├──────────┼──────┼─────────────────────┤
532 │NORM │ 1 1 │ Normalize (A) so │
533 │ │ │ max(A)-min(A) = 1 │
534 └──────────┴──────┴─────────────────────┘
535
536 │NOT │ 1 1 │ NaN if A == NaN, 1 │
537 │ │ │ if A == 0, else 0 │
538 ├──────────┼──────┼─────────────────────┤
539 │NRAND │ 2 1 │ Normal, random val‐ │
540 │ │ │ ues with mean A and │
541 │ │ │ std. deviation B │
542 ├──────────┼──────┼─────────────────────┤
543 │OR │ 2 1 │ NaN if B == NaN, │
544 │ │ │ else A │
545 ├──────────┼──────┼─────────────────────┤
546 │PCDF │ 2 1 │ Poisson cumulative │
547 │ │ │ distribution func‐ │
548 │ │ │ tion for x = A and │
549 │ │ │ lambda = B │
550 ├──────────┼──────┼─────────────────────┤
551 │PERM │ 2 1 │ Permutations n_P_r, │
552 │ │ │ with n = A and r = │
553 │ │ │ B │
554 ├──────────┼──────┼─────────────────────┤
555 │PPDF │ 2 1 │ Poisson distribu‐ │
556 │ │ │ tion P(x,lambda), │
557 │ │ │ with x = A and │
558 │ │ │ lambda = B │
559 ├──────────┼──────┼─────────────────────┤
560 │PLM │ 3 1 │ Associated Legendre │
561 │ │ │ polynomial P(A) │
562 │ │ │ degree B order C │
563 ├──────────┼──────┼─────────────────────┤
564 │PLMg │ 3 1 │ Normalized associ‐ │
565 │ │ │ ated Legendre poly‐ │
566 │ │ │ nomial P(A) degree │
567 │ │ │ B order C (geophys‐ │
568 │ │ │ ical convention) │
569 ├──────────┼──────┼─────────────────────┤
570 │POP │ 1 0 │ Delete top element │
571 │ │ │ from the stack │
572 ├──────────┼──────┼─────────────────────┤
573 │POW │ 2 1 │ A ^ B │
574 ├──────────┼──────┼─────────────────────┤
575 │PQUANT │ 2 1 │ The B'th quantile │
576 │ │ │ (0-100%) of A │
577 ├──────────┼──────┼─────────────────────┤
578 │PQUANTW │ 3 1 │ The C'th weighted │
579 │ │ │ quantile (0-100%) │
580 │ │ │ of A for weights in │
581 │ │ │ B │
582 ├──────────┼──────┼─────────────────────┤
583 │PSI │ 1 1 │ Psi (or Digamma) of │
584 │ │ │ A │
585 ├──────────┼──────┼─────────────────────┤
586 │PV │ 3 1 │ Legendre function │
587 │ │ │ Pv(A) of degree v = │
588 │ │ │ real(B) + imag(C) │
589 ├──────────┼──────┼─────────────────────┤
590 │QV │ 3 1 │ Legendre function │
591 │ │ │ Qv(A) of degree v = │
592 │ │ │ real(B) + imag(C) │
593 ├──────────┼──────┼─────────────────────┤
594 │R2 │ 2 1 │ R2 = A^2 + B^2 │
595 ├──────────┼──────┼─────────────────────┤
596 │R2D │ 1 1 │ Convert radians to │
597 │ │ │ degrees │
598 ├──────────┼──────┼─────────────────────┤
599 │RAND │ 2 1 │ Uniform random val‐ │
600 │ │ │ ues between A and B │
601 └──────────┴──────┴─────────────────────┘
602
603 │RCDF │ 1 1 │ Rayleigh cumulative │
604 │ │ │ distribution func‐ │
605 │ │ │ tion for z = A │
606 ├──────────┼──────┼─────────────────────┤
607 │RCRIT │ 1 1 │ Rayleigh distribu‐ │
608 │ │ │ tion critical value │
609 │ │ │ for alpha = A │
610 ├──────────┼──────┼─────────────────────┤
611 │RINT │ 1 1 │ rint (A) (round to │
612 │ │ │ integral value │
613 │ │ │ nearest to A) │
614 ├──────────┼──────┼─────────────────────┤
615 │RMS │ 1 1 │ Root-mean-square of │
616 │ │ │ A │
617 ├──────────┼──────┼─────────────────────┤
618 │RMSW │ 1 1 │ Weighted │
619 │ │ │ root-mean-square of │
620 │ │ │ A for weights in B │
621 ├──────────┼──────┼─────────────────────┤
622 │RPDF │ 1 1 │ Rayleigh probabil‐ │
623 │ │ │ ity density func‐ │
624 │ │ │ tion for z = A │
625 ├──────────┼──────┼─────────────────────┤
626 │ROLL │ 2 0 │ Cyclicly shifts the │
627 │ │ │ top A stack items │
628 │ │ │ by an amount B │
629 ├──────────┼──────┼─────────────────────┤
630 │ROTT │ 2 1 │ Rotate A by the │
631 │ │ │ (constant) shift B │
632 │ │ │ in the t-direction │
633 ├──────────┼──────┼─────────────────────┤
634 │SEC │ 1 1 │ sec (A) (A in radi‐ │
635 │ │ │ ans) │
636 ├──────────┼──────┼─────────────────────┤
637 │SECD │ 1 1 │ sec (A) (A in │
638 │ │ │ degrees) │
639 ├──────────┼──────┼─────────────────────┤
640 │SIGN │ 1 1 │ sign (+1 or -1) of │
641 │ │ │ A │
642 ├──────────┼──────┼─────────────────────┤
643 │SIN │ 1 1 │ sin (A) (A in radi‐ │
644 │ │ │ ans) │
645 ├──────────┼──────┼─────────────────────┤
646 │SINC │ 1 1 │ sinc (A) (sin │
647 │ │ │ (pi*A)/(pi*A)) │
648 ├──────────┼──────┼─────────────────────┤
649 │SIND │ 1 1 │ sin (A) (A in │
650 │ │ │ degrees) │
651 ├──────────┼──────┼─────────────────────┤
652 │SINH │ 1 1 │ sinh (A) │
653 ├──────────┼──────┼─────────────────────┤
654 │SKEW │ 1 1 │ Skewness of A │
655 ├──────────┼──────┼─────────────────────┤
656 │SQR │ 1 1 │ A^2 │
657 ├──────────┼──────┼─────────────────────┤
658 │SQRT │ 1 1 │ sqrt (A) │
659 ├──────────┼──────┼─────────────────────┤
660 │STD │ 1 1 │ Standard deviation │
661 │ │ │ of A │
662 ├──────────┼──────┼─────────────────────┤
663 │STDW │ 2 1 │ Weighted standard │
664 │ │ │ deviation of A for │
665 │ │ │ weights in B │
666 └──────────┴──────┴─────────────────────┘
667
668
669
670 │STEP │ 1 1 │ Heaviside step │
671 │ │ │ function H(A) │
672 ├──────────┼──────┼─────────────────────┤
673 │STEPT │ 1 1 │ Heaviside step │
674 │ │ │ function H(t-A) │
675 ├──────────┼──────┼─────────────────────┤
676 │SUB │ 2 1 │ A - B │
677 ├──────────┼──────┼─────────────────────┤
678 │SUM │ 1 1 │ Cumulative sum of A │
679 ├──────────┼──────┼─────────────────────┤
680 │TAN │ 1 1 │ tan (A) (A in radi‐ │
681 │ │ │ ans) │
682 ├──────────┼──────┼─────────────────────┤
683 │TAND │ 1 1 │ tan (A) (A in │
684 │ │ │ degrees) │
685 ├──────────┼──────┼─────────────────────┤
686 │TANH │ 1 1 │ tanh (A) │
687 ├──────────┼──────┼─────────────────────┤
688 │TAPER │ 1 1 │ Unit weights │
689 │ │ │ cosine-tapered to │
690 │ │ │ zero within A of │
691 │ │ │ end margins │
692 ├──────────┼──────┼─────────────────────┤
693 │TN │ 2 1 │ Chebyshev polyno‐ │
694 │ │ │ mial Tn(-1<A<+1) of │
695 │ │ │ degree B │
696 ├──────────┼──────┼─────────────────────┤
697 │TCRIT │ 2 1 │ Student's t distri‐ │
698 │ │ │ bution critical │
699 │ │ │ value for alpha = A │
700 │ │ │ and nu = B │
701 ├──────────┼──────┼─────────────────────┤
702 │TPDF │ 2 1 │ Student's t proba‐ │
703 │ │ │ bility density │
704 │ │ │ function for t = A, │
705 │ │ │ and nu = B │
706 ├──────────┼──────┼─────────────────────┤
707 │TCDF │ 2 1 │ Student's t cumula‐ │
708 │ │ │ tive distribution │
709 │ │ │ function for t = A, │
710 │ │ │ and nu = B │
711 ├──────────┼──────┼─────────────────────┤
712 │UPPER │ 1 1 │ The highest (maxi‐ │
713 │ │ │ mum) value of A │
714 ├──────────┼──────┼─────────────────────┤
715 │VAR │ 1 1 │ Variance of A │
716 ├──────────┼──────┼─────────────────────┤
717 │VARW │ 2 1 │ Weighted variance │
718 │ │ │ of A for weights in │
719 │ │ │ B │
720 ├──────────┼──────┼─────────────────────┤
721 │WCDF │ 3 1 │ Weibull cumulative │
722 │ │ │ distribution func‐ │
723 │ │ │ tion for x = A, │
724 │ │ │ scale = B, and │
725 │ │ │ shape = C │
726 ├──────────┼──────┼─────────────────────┤
727 │WCRIT │ 3 1 │ Weibull distribu‐ │
728 │ │ │ tion critical value │
729 │ │ │ for alpha = A, │
730 │ │ │ scale = B, and │
731 │ │ │ shape = C │
732 └──────────┴──────┴─────────────────────┘
733
734
735
736
737 │WPDF │ 3 1 │ Weibull density │
738 │ │ │ distribution │
739 │ │ │ P(x,scale,shape), │
740 │ │ │ with x = A, scale = │
741 │ │ │ B, and shape = C │
742 ├──────────┼──────┼─────────────────────┤
743 │XOR │ 2 1 │ B if A == NaN, else │
744 │ │ │ A │
745 ├──────────┼──────┼─────────────────────┤
746 │Y0 │ 1 1 │ Bessel function of │
747 │ │ │ A (2nd kind, order │
748 │ │ │ 0) │
749 ├──────────┼──────┼─────────────────────┤
750 │Y1 │ 1 1 │ Bessel function of │
751 │ │ │ A (2nd kind, order │
752 │ │ │ 1) │
753 ├──────────┼──────┼─────────────────────┤
754 │YN │ 2 1 │ Bessel function of │
755 │ │ │ A (2nd kind, order │
756 │ │ │ B) │
757 ├──────────┼──────┼─────────────────────┤
758 │ZCDF │ 1 1 │ Normal cumulative │
759 │ │ │ distribution func‐ │
760 │ │ │ tion for z = A │
761 ├──────────┼──────┼─────────────────────┤
762 │ZPDF │ 1 1 │ Normal probability │
763 │ │ │ density function │
764 │ │ │ for z = A │
765 ├──────────┼──────┼─────────────────────┤
766 │ZCRIT │ 1 1 │ Normal distribution │
767 │ │ │ critical value for │
768 │ │ │ alpha = A │
769 ├──────────┼──────┼─────────────────────┤
770 │ROOTS │ 2 1 │ Treats col A as │
771 │ │ │ f(t) = 0 and │
772 │ │ │ returns its roots │
773 └──────────┴──────┴─────────────────────┘
774
776 The following symbols have special meaning:
777
778 ┌───────┬────────────────────────────┐
779 │PI │ 3.1415926... │
780 ├───────┼────────────────────────────┤
781 │E │ 2.7182818... │
782 ├───────┼────────────────────────────┤
783 │EULER │ 0.5772156... │
784 ├───────┼────────────────────────────┤
785 │EPS_F │ 1.192092896e-07 (sgl. │
786 │ │ prec. eps) │
787 ├───────┼────────────────────────────┤
788 │EPS_D │ 2.2204460492503131e-16 │
789 │ │ (dbl. prec. eps) │
790 ├───────┼────────────────────────────┤
791 │TMIN │ Minimum t value │
792 ├───────┼────────────────────────────┤
793 │TMAX │ Maximum t value │
794 ├───────┼────────────────────────────┤
795 │TRANGE │ Range of t values │
796 ├───────┼────────────────────────────┤
797 │TINC │ t increment │
798 ├───────┼────────────────────────────┤
799 │N │ The number of records │
800 ├───────┼────────────────────────────┤
801 │T │ Table with t-coordinates │
802 └───────┴────────────────────────────┘
803
804 │TNORM │ Table with normalized │
805 │ │ t-coordinates │
806 ├───────┼────────────────────────────┤
807 │TROW │ Table with row numbers 1, │
808 │ │ 2, ..., N-1 │
809 └───────┴────────────────────────────┘
810
812 The ASCII output formats of numerical data are controlled by parameters
813 in your gmt.conf file. Longitude and latitude are formatted according
814 to FORMAT_GEO_OUT, absolute time is under the control of FOR‐
815 MAT_DATE_OUT and FORMAT_CLOCK_OUT, whereas general floating point val‐
816 ues are formatted according to FORMAT_FLOAT_OUT. Be aware that the for‐
817 mat in effect can lead to loss of precision in ASCII output, which can
818 lead to various problems downstream. If you find the output is not
819 written with enough precision, consider switching to binary output (-bo
820 if available) or specify more decimals using the FORMAT_FLOAT_OUT set‐
821 ting.
822
824 1. The operators PLM and PLMg calculate the associated Legendre polyno‐
825 mial of degree L and order M in x which must satisfy -1 <= x <= +1 and
826 0 <= M <= L. x, L, and M are the three arguments preceding the opera‐
827 tor. PLM is not normalized and includes the Condon-Shortley phase
828 (-1)^M. PLMg is normalized in the way that is most commonly used in
829 geophysics. The C-S phase can be added by using -M as argument. PLM
830 will overflow at higher degrees, whereas PLMg is stable until ultra
831 high degrees (at least 3000).
832
833 2. Files that have the same names as some operators, e.g., ADD, SIGN,
834 =, etc. should be identified by prepending the current directory (i.e.,
835 ./).
836
837 3. The stack depth limit is hard-wired to 100.
838
839 4. All functions expecting a positive radius (e.g., LOG, KEI, etc.) are
840 passed the absolute value of their argument.
841
842 5. The DDT and D2DT2 functions only work on regularly spaced data.
843
844 6. All derivatives are based on central finite differences, with natu‐
845 ral boundary conditions.
846
847 7. ROOTS must be the last operator on the stack, only followed by =.
848
850 You may store intermediate calculations to a named variable that you
851 may recall and place on the stack at a later time. This is useful if
852 you need access to a computed quantity many times in your expression as
853 it will shorten the overall expression and improve readability. To save
854 a result you use the special operator STO@label, where label is the
855 name you choose to give the quantity. To recall the stored result to
856 the stack at a later time, use [RCL]@label, i.e., RCL is optional. To
857 clear memory you may use CLR@label. Note that STO and CLR leave the
858 stack unchanged.
859
860 8. The bitwise operators (BITAND, BITLEFT, BITNOT, BITOR, BITRIGHT,
861 BITTEST, and BITXOR) convert a tables's double precision values to
862 unsigned 64-bit ints to perform the bitwise operations. Consequently,
863 the largest whole integer value that can be stored in a double preci‐
864 sion value is 2^53 or 9,007,199,254,740,992. Any higher result will be
865 masked to fit in the lower 54 bits. Thus, bit operations are effec‐
866 tively limited to 54 bits. All bitwise operators return NaN if given
867 NaN arguments or bit-settings <= 0.
868
869 9. TAPER will interpret its argument to be a width in the same units as
870 the time-axis, but if no time is provided (i.e., plain data tables)
871 then the width is taken to be given in number of rows.
872
874 Users may save their favorite operator combinations as macros via the
875 file gmtmath.macros in their current or user directory. The file may
876 contain any number of macros (one per record); comment lines starting
877 with # are skipped. The format for the macros is name = arg1 arg2 ...
878 arg2 [ : comment] where name is how the macro will be used. When this
879 operator appears on the command line we simply replace it with the
880 listed argument list. No macro may call another macro. As an example,
881 the following macro expects that the time-column contains seafloor ages
882 in Myr and computes the predicted half-space bathymetry:
883
884 DEPTH = SQRT 350 MUL 2500 ADD NEG : usage: DEPTH to return half-space
885 seafloor depths
886
887 Note: Because geographic or time constants may be present in a macro,
888 it is required that the optional comment flag (:) must be followed by a
889 space. As another example, we show a macro GPSWEEK which determines
890 which GPS week a timestamp belongs to:
891
892 GPSWEEK = 1980-01-06T00:00:00 SUB 86400 DIV 7 DIV FLOOR : GPS week
893 without rollover
894
896 When -Ccols is set then any operation, including loading of data from
897 files, will restrict which columns are affected. To avoid unexpected
898 results, note that if you issue a -Ccols option before you load in the
899 data then only those columns will be updated, hence the unspecified
900 columns will be zero. On the other hand, if you load the file first
901 and then issue -Ccols then the unspecified columns will have been
902 loaded but are then ignored until you undo the effect of -C.
903
905 To add two plot dimensions of different units, we can run
906
907 length=`gmt math -Q 15c 2i SUB =`
908
909 To take the square root of the content of the second data column being
910 piped through gmtmath by process1 and pipe it through a 3rd process,
911 use
912
913 process1 | gmt math STDIN SQRT = | process3
914
915 To take log10 of the average of 2 data files, use
916
917 gmt math file1.d file2.d ADD 0.5 MUL LOG10 = file3.d
918
919 Given the file samples.d, which holds seafloor ages in m.y. and
920 seafloor depth in m, use the relation depth(in m) = 2500 + 350 * sqrt
921 (age) to print the depth anomalies:
922
923 gmt math samples.d T SQRT 350 MUL 2500 ADD SUB = | lpr
924
925 To take the average of columns 1 and 4-6 in the three data sets
926 sizes.1, sizes.2, and sizes.3, use
927
928 gmt math -C1,4-6 sizes.1 sizes.2 ADD sizes.3 ADD 3 DIV = ave.d
929
930 To take the 1-column data set ages.d and calculate the modal value and
931 assign it to a variable, try
932
933 gmt set mode_age = `gmt math -S -T ages.d MODE =`
934
935 To evaluate the dilog(x) function for coordinates given in the file
936 t.d:
937
938 gmt math -Tt.d T DILOG = dilog.d
939
940 To demonstrate the use of stored variables, consider this sum of the
941 first 3 cosine harmonics where we store and repeatedly recall the
942 trigonometric argument (2*pi*T/360):
943
944 gmt math -T0/360/1 2 PI MUL 360 DIV T MUL STO@kT COS @kT 2 MUL COS ADD \
945 @kT 3 MUL COS ADD = harmonics.d
946
947 To use gmtmath as a RPN Hewlett-Packard calculator on scalars (i.e., no
948 input files) and calculate arbitrary expressions, use the -Q option.
949 As an example, we will calculate the value of Kei (((1 + 1.75)/2.2) +
950 cos (60)) and store the result in the shell variable z:
951
952 set z = `gmt math -Q 1 1.75 ADD 2.2 DIV 60 COSD ADD KEI =`
953
954 To use gmtmath as a general least squares equation solver, imagine that
955 the current table is the augmented matrix [ A | b ] and you want the
956 least squares solution x to the matrix equation A * x = b. The operator
957 LSQFIT does this; it is your job to populate the matrix correctly
958 first. The -A option will facilitate this. Suppose you have a 2-column
959 file ty.d with t and b(t) and you would like to fit a the model y(t) =
960 a + b*t + c*H(t-t0), where H is the Heaviside step function for a given
961 t0 = 1.55. Then, you need a 4-column augmented table loaded with t in
962 column 1 and your observed y(t) in column 3. The calculation becomes
963
964 gmt math -N4/1 -Aty.d -C0 1 ADD -C2 1.55 STEPT ADD -Ca LSQFIT = solution.d
965
966 Note we use the -C option to select which columns we are working on,
967 then make active all the columns we need (here all of them, with -Ca)
968 before calling LSQFIT. The second and fourth columns (col numbers 1 and
969 3) are preloaded with t and y(t), respectively, the other columns are
970 zero. If you already have a pre-calculated table with the augmented
971 matrix [ A | b ] in a file (say lsqsys.d), the least squares solution
972 is simply
973
974 gmt math -T lsqsys.d LSQFIT = solution.d
975
976 Users must be aware that when -C controls which columns are to be
977 active the control extends to placing columns from files as well. Con‐
978 trast the different result obtained by these very similar commands:
979
980 echo 1 2 3 4 | gmt math STDIN -C3 1 ADD =
981 1 2 3 5
982
983 versus
984
985 echo 1 2 3 4 | gmt math -C3 STDIN 1 ADD =
986 0 0 0 5
987
989 Abramowitz, M., and I. A. Stegun, 1964, Handbook of Mathematical Func‐
990 tions, Applied Mathematics Series, vol. 55, Dover, New York.
991
992 Holmes, S. A., and W. E. Featherstone, 2002, A unified approach to the
993 Clenshaw summation and the recursive computation of very high degree
994 and order normalized associated Legendre functions. Journal of Geodesy,
995 76, 279-299.
996
997 Press, W. H., S. A. Teukolsky, W. T. Vetterling, and B. P. Flannery,
998 1992, Numerical Recipes, 2nd edition, Cambridge Univ., New York.
999
1000 Spanier, J., and K. B. Oldman, 1987, An Atlas of Functions, Hemisphere
1001 Publishing Corp.
1002
1004 gmt, grdmath
1005
1007 2019, P. Wessel, W. H. F. Smith, R. Scharroo, J. Luis, and F. Wobbe
1008
1009
1010
1011
10125.4.5 Feb 24, 2019 GMTMATH(1)