1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195
|
<!--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://grads.iges.org/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>
|