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

grdmathwill perform operations like add, subtract, multiply, and divide on one or more grd files or constants using Reverse Polish Nota- tion (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,-Imust be set (and optionally-F). The expression=outgrdfilecan occur as many times as the depth of the stack allows.operandIfoperandcan 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).outgrdfileis a 2-D grd file that will hold the final result.OPERATORSChoose among the following operators: Operator n_args ReturnsABS1 abs (A).ACOS1 acos (A).ACOSH1 acosh (A).ADD(+)2 A + B.AND2 NaN if A and B == NaN, B if A == NaN, else A.ASIN1 asin (A).ASINH1 asinh (A).ATAN1 atan (A).ATAN22 atan2 (A, B).ATANH1 atanh (A).BEI1 bei (A).BER1 ber (A).CAZ2 Cartesian azimuth from grid nodes to stack x,yCDIST2 Cartesian distance between grid nodes and stack x,y.CEIL1 ceil (A) (smallest integer >= A).CHICRIT2 Critical value for chi-squared-distribution, with alpha = A and n = B.CHIDIST2 chi-squared-distribution P(chi2,nn), with chi2 = A and n = B.COS1 cos (A) (A in radians).COSD1 cos (A) (A in degrees).COSH1 cosh (A).CURV1 Curvature of A (Laplacian).D2DX21 d^2(A)/dx^2 2nd derivative.D2DY21 d^2(A)/dy^2 2nd derivative.D2R1 Converts Degrees to Radians.DDX1 d(A)/dx 1st derivative.DDY1 d(A)/dy 1st derivative.DILOG1 dilog (A).DIV(/)2 A / B.DUP1 Places duplicate of A on the stack.ERF1 Error function erf (A).ERFC1 Complementary Error function erfc (A).ERFINV1 Inverse error function of A.EQ2 1 if A == B, else 0.EXCH2 Exchanges A and B on the stack.EXP1 exp (A).EXTREMA1 Local Extrema: +2/-2 is max/min, +1/-1 is saddle with max/min in x, 0 elsewhere.FCRIT3 Critical value for F-distribution, with alpha = A, n1 = B, and n2 = C.FDIST3 F-distribution Q(F,n1,n2), with F = A, n1 = B, and n2 = C.FLIPLR1 Reverse order of values in each rowFLIPUD1 Reverse order of values in each columnFLOOR1 floor (A) (greatest integer <= A).FMOD2 A % B (remainder).GE2 1 if A >= B, else 0.GT2 1 if A > B, else 0.HYPOT2 hypot (A, B) = sqrt (A*A + B*B).I01 Modified Bessel function of A (1st kind, order 0).I11 Modified Bessel function of A (1st kind, order 1).IN2 Modified Bessel function of A (1st kind, order B).INRANGE3 1 if B <= A <= C, else 0INSIDE1 1 when inside polygon(s) in A, else 0INV1 1 / A.ISNAN1 1 if A == NaN, else 0.J01 Bessel function of A (1st kind, order 0).J11 Bessel function of A (1st kind, order 1).JN2 Bessel function of A (1st kind, order B).K01 Modified Kelvin function of A (2nd kind, order 0).K11 Modified Bessel function of A (2nd kind, order 1).KN2 Modified Bessel function of A (2nd kind, order B).KEI1 kei (A).KER1 ker (A).LDIST1 Compute distance from lines in multi-segment ASCII file ALE2 1 if A <= B, else 0.LMSSCL1 LMS scale estimate (LMS STD) of A.LOG1 log (A) (natural log).LOG101 log10 (A) (base 10).LOG1P1 log (1+A) (accurate for small A).LOG21 log2 (A) (base 2).LOWER1 The lowest (minimum) value of A.LRAND2 Laplace random noise with mean A and std. deviation B.LT2 1 if A < B, else 0.MAD1 Median Absolute Deviation (L1 STD) of A.MAX2 Maximum of A and B.MEAN1 Mean value of A.MED1 Median value of A.MIN2 Minimum of A and B.MODE1 Mode value (Least Median of Squares) of A.MUL(x)2 A * B.NAN2 NaN if A == B, else A.NEG1 -A.NEQ2 1 if A != B, else 0.NRAND2 Normal, random values with mean A and std. deviation B.OR2 NaN if A or B == NaN, else A.PDIST1 Compute distance from points in ASCII file APLM3 Associated Legendre polynomial P(-1<A<+1) degree B order C.POP1 Delete top element from the stack.POW(^)2 A ^ B.R22 R2 = A^2 + B^2.R2D1 Convert Radians to Degrees.RAND2 Uniform random values between A and B.RINT1 rint (A) (nearest integer).ROTX2 Rotate A by the (constant) shift B in x-directionROTY2 Rotate A by the (constant) shift B in y-directionSAZ2 Sperhical azimuth from grid nodes to stack x,ySDIST2 Spherical (Great circle) distance (in degrees) between grid nodes and stack lon,lat (A, B).SIGN1 sign (+1 or -1) of A.SIN1 sin (A) (A in radians).SINC1 sinc (A) (sin (pi*A)/(pi*A)).SIND1 sin (A) (A in degrees).SINH1 sinh (A).SQRT1 sqrt (A).STD1 Standard deviation of A.STEP1 Heaviside step function: H(A).STEPX1 Heaviside step function in x: H(x-A).STEPY1 Heaviside step function in y: H(y-A).SUB(-)2 A - B.TAN1 tan (A) (A in radians).TAND1 tan (A) (A in degrees).TANH1 tanh (A).TCRIT2 Critical value for Studentâ€™s t-distribution, with alpha = A and n = B.TDIST2 Studentâ€™s t-distribution A(t,n), with t = A, and n = B.UPPER1 The highest (maximum) value of A.XOR2 B if A == NaN, else A.Y01 Bessel function of A (2nd kind, order 0).Y11 Bessel function of A (2nd kind, order 1).YLM2 Re and Im normalized surface harmonics (degree A, order B).YN2 Bessel function of A (2nd kind, order B).ZCRIT1 Critical value for the normal-distribution, with alpha = A.SYMBOLSThe following symbols have special meaning:PI3.1415926...E2.7182818...XGrid with x-coordinatesYGrid with y-coordinates

-FSelect pixel registration (used with-R,-I). [Default is grid registration].-Ix_inc[and optionallyy_inc] is the grid spacing. Appendmto indicate minutes orcto indicate seconds.-Rxmin,xmax,ymin,andymaxspecify the Region of interest. For geographic regions, these limits correspond towest,east,south,andnorthand you may specify them in decimal degrees or in [+-]dd:mm[:ss.xxx][W|E|S|N] format. Appendrif lower left and upper right map coordinates are given instead of wesn. The two shorthands-Rg-Rdstand 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; appendtto-JX|x), or absolute time of the form [date]T[clock] (appendTto-JX|x). At least one ofdateandclockmust be present; theTis always required. Thedatestring must be of the form [-]yyyy[-mm[-dd]] (Gregorian calendar) or yyyy[-Www[-d]] (ISO week calendar), while theclockstring 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).-VSelects verbose mode, which will send progress reports to stderr [Default runs "silently"].

The operatorGDISTcalculates 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. The operatorYLMcalculates the fully normalized spherical harmonics for degree L and order M for all positions in the grid, which is assumed to be in degrees.YLMreturns two grids, the Real (cosine) and Imaginary (sine) component of the complex spherical harmonic. Use thePOPopera- tor (andEXCH) to get rid of one of them, of save both by giving two consequtive = file.grd calls. The operatorPLMcalculates the associ- ated Legendre polynomial of degree L and order M, and its argument is the cosine of the colatitude which must satisfy -1 <= x <= +1. UnlikeYLM,PLMis not normalized. All the derivatives are based on central finite differences, with natu- ral boundary conditions.

To take log10 of the average of 2 files, usegrdmathfile1.grd file2.grdADD0.5MULLOG10=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:grdmathages.grdSQRT350MUL2500ADD=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), usegrdmath2 s_xy.grdMULs_xx.grd s_yy.grdSUBDIVATAN22DIV=direc- tion.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 4YML1.1MULEXCH0.4MULADD= harm.grd To extract the locations of local maxima that exceed 100 mGal in the file faa.grd:grdmathfaa.grdDUPEXTREMA2EQMULDUP100GTMUL0NAN= z.grdgrd2xyzz.grd-S> max.xyz

Files that has the same name as some operators, e.g.,ADD,SIGN,=, etc. cannot be read and must not be present in the current directory. Piping of files are not allowed. The stack limit is hard-wired to 50. All functions expecting a positive radius (e.g.,LOG,KEI, etc.) are passed the absolute value of their argument.

Abramowitz, M., and I. A. Stegun, 1964,HandbookofMathematicalFunc-tions, Applied Mathematics Series, vol. 55, Dover, New York. Press, W. H., S. A. Teukolsky, W. T. Vetterling, B. P. Flannery, 1992,NumericalRecipes, 2nd edition, Cambridge Univ., New York.

gmt(l),gmtmath(l),grd2xyz(l),grdedit(l),grdinfo(l),xyz2grd(l) GMT4.0 1 Oct 2004 GRDMATH(l)

Man(1) output converted with man2html