## GrADS Scripting Language Math Functions

A set of math functions has been developed for use within the GrADS scripting language. Their use is somewhat self-explanatory, based on the following descriptions of the arguments and return codes.

`rc = math_trigfunc(angle)`

`trigfunc` sin, cos, tan, asin, acos, atan, sinh, cosh, tanh, asinh, acosh, or atanh
`angle` must be given in radians
`rc` the result of the trig function calculation

`rc = math_format(format,num)`

`format` a C-language style format statement, e.g. `%5.2f`
`num` the number to be formatted
`rc` the formatted number

`rc = math_nint(num)`

`num` a real number in decimal form
`rc` `num` rounded up or down to the nearest integer

`rc = math_int(num)`

`num` a real number in decimal form
`rc` the integer part of `num` (decimal part truncated)

`rc = math_pow(num,exponent);`

`num` any number
`exponent` any number
`rc` `num` raised to the power `exponent`

`rc = math_exp(num)`

`num` any number
`rc` the result of the exponential function; `e` raised to the power `num`

`rc = math_fmod(num1,num2);`

`num1` any number
`num2` any number
`rc` the remainder when `num1` is divided by `num2`

`rc = math_strlen(string)`

`string` any string variable
`rc` the length of `string`

`rc = valnum(string)`

`string` any string variable
`rc 0 - string` is not a number
`1 - string` is an integer
`2 - string` is not an integer

`rc = wordpos(string,int)`

`string` any string, usually contains more than one word
`int` an integer
`rc` word #`int` string starts at this character #

### Usage Notes

These math functions will only work with GrADS version 1.8 (or higher).

### Examples

These script records were taken from a sample script called "script_math_demo.gs".

`v = 3.1456
fmt = '%-6.1f'
rc = math_format(fmt,v)
say fmt' of 'v' = 'rc
pi = 3.1415926
d2r = pi/180
angd = 45
ang = angd * d2r
cos = math_cos(ang)
say 'cos of 'angd' = 'cos
num = '3.1455'
rc = valnum(num)
if (rc = 0) ; say num' is not a number' ; endif
if (rc = 1) ; say num' is an integer' ; endif
if (rc = 2) ; say num' is not an integer' ; endif
v = 3.0
while(v < 4.0)
rc1 = math_nint(v)
rc2 = math_int(v)
print 'nint of 'v' = 'rc1' int of 'v' = 'rc2
v = v + 0.1
endwhile
pow = math_pow(2,0.5);
print '2 raised to the power 0.5 = 'pow
num = math_exp(1)
print 'exp(1) = 'num
fmod = math_fmod(5,2)
print '5 modulo 2 (the remainder when 5 is divided by 2) = 'fmod
s = 'this is a test'
rc = math_strlen(s)
print 'length of the string "'s'" = 'rc p = 2
rc = wrdpos(s,p)
print 'word 'p' of the string "'s'" starts at character 'rc
`