<!--Copyright (C) 1988-2005 by the Institute of Global Environment and Society (IGES). See file COPYRIGHT for more information.--> <html> <head> <title>GrADS Scripting Language Math Functions</title> </head> <body text="#000000" bgcolor="e0f0ff"> <h2><b>GrADS Scripting Language Math Functions</b></h2> <p> 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. <p> <br> else if (cmpwrd(name,"math_sqrt")) rc = gsfmath(pcmn,8);<br> else if (cmpwrd(name,"math_abs")) rc = gsfmath(pcmn,9);<br> <p><code>rc = math_<i>trigfunc</i>(<i>angle <,angle2> </i>)</code> <ul> <code><i>trigfunc</i> </code> sin, cos, tan, asin, acos, atan, atan2, sinh, cosh, tanh, asinh, acosh, or atanh<br> <code><i>angle</i> </code> must be given in radians <br> <code><i>angle2</i> </code> (only used for atan2) <br> <code>rc </code> the result of the trig function calculation </ul> <p> <code>rc = math_format(<i>format,num</i>)</code> <ul> <code><i>format</i> </code> a C-language style format statement for a floating point number, e.g. <code>%5.2f</code><br> <code><i>num</i> </code> the number to be formatted<br> <code>rc </code> the formatted number </ul> <code>rc = math_nint(<i>num</i>)</code> <ul> <code><i>num</i> </code> a real number in decimal form<br> <code>rc </code> <code><i>num</i></code> rounded up or down to the nearest integer </ul> <code>rc = math_int(<i>num</i>)</code> <ul> <code><i>num</i> </code> a real number in decimal form<br> <code>rc </code> the integer part of <code><i>num</i></code> not greater than <code><i>num</i></code> </ul> <code>rc = math_log(<i>num</i>);</code> <ul> <code><i>num</i> </code> any number > 0<br> <code>rc </code> natural logarithm of <code><i>num</i></code> </ul> <code></code><code>rc = math_log10(<i>num</i>);</code> <ul> <code><i>num</i> </code> any number > 0.0<br> <code>rc </code> base 10 logarithm of <code><i>num</i></code> </ul> <code></code><code></code><code>rc = math_pow(<i>num,exponent</i>);</code> <ul> <p><code><i>num</i> </code> any number<br> <code><i>exponent</i> </code> any number<br> <code>rc </code> <code><i>num</i></code> raised to the power <code><i>exponent</i></code> </p> </ul> <p><code>rc = math_sqrt(<i>num</i>)</code> </p> <ul> <code><i>num</i> </code> any number<br> <code>rc </code> the square root of <code><i>num</i></code> </ul> <p><code>rc = math_abs(<i>num</i>)</code> </p> <ul> <code><i>num</i> </code> any number<br> <code>rc </code> the absolute value of <code><i>num</i></code> </ul> <p><code>rc = math_exp(<i>num</i>)</code> </p> <ul> <code><i>num</i> </code> any number<br> <code>rc </code> the result of the exponential function; <code>e</code> raised to the power <code><i>num</i></code> </ul> <code></code><code>rc = math_fmod(<i>num1,num2</i>);</code> <ul> <code><i>num1</i> </code> any number<br> <code><i>num2</i> </code> any number not equal to zero<br> <code>rc </code> the remainder when <code><i>num1</i></code> is divided by <code><i>num2</i></code> </ul> <code>rc = math_mod(<i>num1,num2</i>);</code> <ul> <code><i>num1</i> </code> any number<br> <code><i>num2</i> </code> any number not equal to zero<br> <code>rc </code> the integer part of the remainder when <code><i>num1</i></code> is divided by <code><i>num2</i></code> </ul> <code>rc = math_strlen(<i>string</i>)</code> <ul> <code><i>string</i> </code> any string variable<br> <code>rc </code> the length of <code><i>string</i></code> </ul> <code>rc = valnum(<i>string</i>)</code> <ul> <code><i>string</i> </code> any string variable<br> <code>rc 0 - <i>string</i></code> is not a number<br> <code> 1 - <i>string</i></code> is an integer<br> <code> 2 - <i>string</i></code> is not an integer </ul> <code>rc = wrdpos(<i>string,int</i>)</code> <ul> <code><i>string</i> </code> any string, usually contains more than one word<br> <code><i>int</i> </code> an integer<br> <code>rc </code> word #<code><i>int</i></code of ><code><i>string</i></code> starts at this character #<br> </ul> <p> <h3>Usage Notes</h3> <p> These math functions will only work with GrADS version 1.8 (or higher). <p> <h3>Examples </h3> <p> These script records were taken from a sample script called "<a href="ftp://cola.gmu.edu/grads/scripts/script_math_demo.gs">script_math_demo.gs</a>". <p> <code> v = 3.1456<br> fmt = '%-6.1f'<br> rc = math_format(fmt,v)<br> say fmt' of 'v' = 'rc<br> <br> pi = 3.1415926<br> d2r = pi/180<br> angd = 45<br> ang = angd * d2r<br> cos = math_cos(ang)<br> say 'cos of 'angd' = 'cos<br> <br> num = '3.1455'<br> rc = valnum(num)<br> if (rc = 0) ; say num' is not a number' ; endif<br> if (rc = 1) ; say num' is an integer' ; endif<br> if (rc = 2) ; say num' is not an integer' ; endif<br> <br> v = 3.0<br> while(v < 4.0) <br> rc1 = math_nint(v)<br> rc2 = math_int(v)<br> print 'nint of 'v' = 'rc1' int of 'v' = 'rc2<br> v = v + 0.1<br> endwhile<br> <br> pow = math_pow(2,0.5);<br> print '2 raised to the power 0.5 = 'pow<br> <br> num = math_exp(1)<br> print 'exp(1) = 'num<br> <br> fmod = math_fmod(5,2)<br> print '5 modulo 2 (the remainder when 5 is divided by 2) = 'fmod<br> <br> s = 'this is a test'<br> rc = math_strlen(s)<br> print 'length of the string "'s'" = 'rc p = 2<br> rc = wrdpos(s,p)<br> print 'word 'p' of the string "'s'" starts at character 'rc<br> <br> </code> </body> </html>