|If operand can be opened as a file it will be read as an ASCII (or binary, see -bi) table data file. If not a file, it is interpreted as a numerical constant or a special symbol (see below). The special argument STDIN means that stdin will be read and placed on the stack; STDIN can appear more than once if necessary.|
|The name of a table data file that will hold the final result. If not given then the output is sent to stdout.|
Choose among the following 131 operators. "args" are the number of input and output arguments.
Operator args Returns
ABS 1 1 abs (A).
The following symbols have special meaning:
-A Requires -N and will partially initialize a table with values from the given file containing t and f(t) only. The t is placed in column t_col while f(t) goes into column n_col - 1 (see -N). -C Select the columns that will be operated on until next occurrence of -C. List columns separated by commas; ranges like 1,3-5,7 are allowed. -C (no arguments) resets the default action of using all columns except time column (see -N). -Ca selects all columns, including time column, while -Cr reverses (toggles) the current choices. -F Give a comma-separated list of desired columns or ranges that should be part of the output (0 is first column) [Default outputs all columns]. -H Input file(s) has header record(s). If used, the default number of header records is N_HEADER_RECS. Use -Hi if only input data should have header records [Default will write out header records if the input data have them]. Blank lines and lines starting with # are always skipped. -I Reverses the output row sequence from ascending time to descending [ascending]. -N Select the number of columns and the column number that contains the "time" variable. Columns are numbered starting at 0 [2/0]. -Q Quick mode for scalar calculation. Shorthand for -Ca -N 1/0 -T 0/0/1. -S Only report the first or last row of the results [Default is all rows]. This is useful if you have computed a statistic (say the MODE) and only want to report a single number instead of numerous records with identical values. Append l to get the last row and f to get the first row only [Default]. -T Required when no input files are given. Sets the t-coordinates of the first and last point and the equidistant sampling interval for the "time" column (see -N). Append + if you are specifying the number of equidistant points instead. If there is no time column (only data columns), give -T with no arguments; this also implies -Ca. Alternatively, give the name of a file whose first column contains the desired t-coordinates which may be irregular. -V Selects verbose mode, which will send progress reports to stderr [Default runs "silently"]. -bi Selects binary input. Append s for single precision [Default is d (double)]. Uppercase S or D will force byte-swapping. Optionally, append ncol, the number of columns in your binary input file if it exceeds the columns needed by the program. Or append c if the input file is netCDF. Optionally, append var1/var2/... to specify the variables to be read. -bo Selects binary output. Append s for single precision [Default is d (double)]. Uppercase S or D will force byte-swapping. Optionally, append ncol, the number of desired columns in your binary output file. [Default is same as input, but see -F] -m Multiple segment file(s). Segments are separated by a special record. For ASCII files the first character must be flag [Default is >]. For binary files all fields must be NaN and -b must set the number of output columns explicitly. By default the -m setting applies to both input and output. Use -mi and -mo to give separate settings to input and output.
The ASCII output formats of numerical data are controlled by parameters in your .gmtdefaults4 file. Longitude and latitude are formatted according to OUTPUT_DEGREE_FORMAT, whereas other values are formatted according to D_FORMAT. Be aware that the format in effect can lead to loss of precision in the output, which can lead to various problems downstream. If you find the output is not written with enough precision, consider switching to binary output (-bo if available) or specify more decimals using the D_FORMAT setting.
(1) The operators PLM and PLMg calculate the associated Legendre polynomial of degree L and order M in x which must satisfy -1 <= x <= +1 and 0 <= M <= L. x, L, and M are the three arguments preceding the operator. PLM is not normalized and includes the Condon-Shortley phase (-1)^M. PLMg is normalized in the way that is most commonly used in geophysics. The C-S phase can be added by using -M as argument. PLM will overflow at higher degrees, whereas PLMg is stable until ultra high degrees (at least 3000).
(2) 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).
(3) The stack depth limit is hard-wired to 100.
(4) All functions expecting a positive radius (e.g., LOG, KEI, etc.) are passed the absolute value of their argument.
(5) The DDT and D2DT2 functions only work on regularly spaced data.
(6) All derivatives are based on central finite differences, with natural boundary conditions.
(7) ROOTS must be the last operator on the stack, only followed by =.
To take the square root of the content of the second data column being piped through gmtmath by process1 and pipe it through a 3rd process, use
process1 | gmtmath STDIN SQRT | process3
To take log10 of the average of 2 data files, use
gmtmath file1.d file2.d ADD 0.5 MUL LOG10 file3.d
Given the file samples.d, which holds seafloor ages in m.y. and seafloor depth in m, use the relation depth(in m) = 2500 + 350 * sqrt (age) to print the depth anomalies:
gmtmath samples.d T SQRT 350 MUL 2500 ADD SUB | lpr
To take the average of columns 1 and 4-6 in the three data sets sizes.1, sizes.2, and sizes.3, use
gmtmath -C 1,4-6 sizes.1 sizes.2 ADD sizes.3 ADD 3 DIV ave.d
To take the 1-column data set ages.d and calculate the modal value and assign it to a variable, try
set mode_age = gmtmath -S -T ages.d MODE
To evaluate the dilog(x) function for coordinates given in the file t.d:
gmtmath -T t.d T DILOG dilog.d
To use gmtmath as a RPN Hewlett-Packard calculator on scalars (i.e., no input files) and calculate arbitrary expressions, use the -Q option. As an example, we will calculate the value of Kei (((1 + 1.75)/2.2) + cos (60)) and store the result in the shell variable z:
set z = gmtmath -Q 1 1.75 ADD 2.2 DIV 60 COSD ADD KEI
To use gmtmath as a general least squares equation solver, imagine that the current table is the augmented matrix [ A | b ] and you want the least squares solution x to the matrix equation A * x = b. The operator LSQFIT does this; it is your job to populate the matrix correctly first. The -A option will facilitate this. Suppose you have a 2-column file ty.d with t and b(t) and you would like to fit a the model y(t) = a + b*t + c*H(t-t0), where H is the Heaviside step function for a given t0 = 1.55. Then, you need a 4-column augmented table loaded with t in column 1 and your observed y(t) in column 3. The calculation becomes
gmtmath -N 4/1 -A ty.d -C0 1 ADD -C2 1.55 STEPT ADD -Ca LSQFIT solution.d
Note we use the -C option to select which columns we are working on, then make active all the columns we need (here all of them, with -Ca) before calling LSQFIT. The second and fourth columns (col numbers 1 and 3) are preloaded with t and y(t), respectively, the other columns are zero. If you already have a precalculated table with the augmented matrix [ A | b ] in a file (say lsqsys.d), the least squares solution is simply
gmtmath -T lsqsys.d LSQFIT solution.d
Abramowitz, M., and I. A. Stegun, 1964, Handbook of Mathematical Functions, 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. Journal of Geodesy, 76, 279-299.
Press, W. H., S. A. Teukolsky, W. T. Vetterling, and B. P. Flannery, 1992, Numerical Recipes, 2nd edition, Cambridge Univ., New York.
Spanier, J., and K. B. Oldman, 1987, An Atlas of Functions, Hemisphere Publishing Corp.
|GMT 4.5.14||GMTMATH (1)||1 Nov 2015|