grdmath − Reverse Polish Notation calculator for grd files |
grdmath [ −F ] [ −Ixinc[m|c][/yinc[m|c]] −Rwest/east/south/north −V] operand [ operand ] OPERATOR [ operand ] OPERATOR ... = outgrdfile |
grdmath will perform operations like add, subtract, multiply, and divide on one or more grd 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 grd file. When two grd files are on the stack, each element in file A is modified by the corresponding element in file B. However, some operators only require one operand (see below). If no grdfiles are used in the expression then options −R, −I must be set (and optionally −F). The expression = outgrdfile can occur as many times as the depth of the stack allows. |
operand |
If operand can be opened as a file it will be read as a grd file. If not a file, it is interpreted as a numerical constant or a special symbol (see below). |
outgrdfile is a 2-D grd file that will hold the final result. |
OPERATORS |
Choose among the following operators: ABS 1 abs (A). |
SYMBOLS |
The following symbols have special meaning: PI 3.1415926... |
−F |
Select pixel registration (used with −R, −I). [Default is grid registration]. |
||
−I |
x_inc [and optionally y_inc] is the grid spacing. Append m to indicate minutes or c to indicate seconds. If one of the units e, k, i, or n is appended instead, the increment will be assumed to be in meter, km, miles, or nautical miles, respectively, and will be converted to the equivalent degrees longitude at the middle latitude of the region (the conversion depends on ELLIPSOID). If /y_inc is given but set to 0 it will be reset equal to x_inc; otherwise it will be converted to degrees latitude. If = is appended then the corresponding max x (east) or y (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 the number of nodes desired by appending + to the supplied increment; the increment is then recalculated from the number of nodes and the domain. The resulting increment value depends on whether you have selected a gridline-registered or pixel- registered grid; see Appendix B for details. |
||
−R |
xmin, xmax, ymin, and ymax specify the Region of interest. For geographic regions, these limits correspond to west, east, south, and north and you may specify them in decimal degrees or in [+-]dd:mm[:ss.xxx][W|E|S|N] format. Append r if lower left and upper right map coordinates are given instead of wesn. The two shorthands −Rg −Rd stand for global domain (0/360 or -180/+180 in longitude respectively, with -90/+90 in latitude). For calendar time coordinates you may either give relative time (relative to the selected TIME_EPOCH and in the selected TIME_UNIT; append t to −JX|x), or absolute time of the form [date]T[clock] (append T to −JX|x). At least one of date and clock must be present; the T is always required. The date string must be of the form [-]yyyy[-mm[-dd]] (Gregorian calendar) or yyyy[-Www[-d]] (ISO week calendar), while the clock string must be of the form hh:mm:ss[.xxx]. The use of delimiters and their type and positions must be as indicated (however, input/output and plotting formats are flexible). |
||
−V |
Selects verbose mode, which will send progress reports to stderr [Default runs "silently"]. |
(1) The operator SDIST calculates spherical
distances bewteen 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. |
To take log10 of the average of 2 files, use grdmath file1.grd file2.grd ADD 0.5 MUL LOG10 = file3.grd Given the file ages.grd, which holds seafloor ages in m.y., use the relation depth(in m) = 2500 + 350 * sqrt (age) to estimate normal seafloor depths: grdmath ages.grd SQRT 350 MUL 2500 ADD = depths.grd To find the angle a (in degrees) of the largest principal stress from the stress tensor given by the three files s_xx.grd s_yy.grd, and s_xy.grd from the relation tan (2*a) = 2 * s_xy / (s_xx - s_yy), use grdmath 2 s_xy.grd MUL s_xx.grd s_yy.grd SUB DIV ATAN2 2 DIV = direction.grd 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: grdmath −R0/360/-90/90 −I1 8 4 YML 1.1 MUL EXCH 0.4 MUL ADD = harm.grd To extract the locations of local maxima that exceed 100 mGal in the file faa.grd: grdmath faa.grd DUP EXTREMA 2 EQ MUL
DUP 100 GT MUL 0 NAN = z.grd |
(1) 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). |
Abramowitz, M., and I. A. Stegun, 1964, Handbook of
Mathematical Functions, Applied Mathematics Series, vol.
55, Dover, New York. |
GMT(l), gmtmath(l), grd2xyz(l), grdedit(l), grdinfo(l), xyz2grd(l) |