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.


else if (cmpwrd(name,"math_sqrt")) rc = gsfmath(pcmn,8);
else if (cmpwrd(name,"math_abs")) rc = gsfmath(pcmn,9);

rc = math_trigfunc(angle <,angle2> )

rc = math_format(format,num)

rc = math_nint(num) rc = math_int(num) rc = math_log(num); rc = math_log10(num); rc = math_pow(num,exponent);

rc = math_sqrt(num)

rc = math_abs(num)

rc = math_exp(num)

rc = math_fmod(num1,num2); rc = math_mod(num1,num2); rc = math_strlen(string) rc = valnum(string) rc = wrdpos(string,int)

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