Linuxpops  3.01.04
Spectral Anaysis Package for Single Dish Data
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
lcalc.c
Go to the documentation of this file.
1 /*
2 Copyright 2021 Arizona Board of Regents on behalf of the University of Arizona.
3 
4 For commercial uses, to obtain a license to sell and or sublicense copies of
5 the Software please contact the University of Arizona at Tech Launch Arizona:
6 lewish@tla.arizona.edu.
7 
8 Permission is hereby granted, free of charge, to any person obtaining a copy
9 of this software and associated documentation files (the "Software"), to deal
10 in the Software without restriction for non-commercial use educational and
11 research purposes, including without limitation the rights to use, copy,
12 modify, merge, publish, distribute, and to permit persons to whom the Software
13 is furnished to do so, subject to the following conditions:
14 
15 The entire above copyright notice and this permission notice shall be included
16 in all copies or substantial portions of the Software.
17 
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 SOFTWARE.
25 
26 1. Additional Required Provisions
27 
28 1.1. Arbitration. The parties agree that if a dispute arises between them
29 concerning this Agreement, the parties may be required to submit the matter to
30 arbitration pursuant to Arizona law.
31 
32 1.2. Applicable Law and Venue. This Agreement shall be interpreted pursuant
33 to the laws of the State of Arizona. Any arbitration or litigation between the
34 Parties shall be conducted in Pima County, ARIZONA, and LICENSEE hereby
35 submits to venue and jurisdiction in Pima County, ARIZONA.
36 
37 1.3. Non-Discrimination. The Parties agree to be bound by state and federal
38 laws and regulations governing equal opportunity and non-discrimination and
39 immigration.
40 
41 1.4. Appropriation of Funds. The Parties recognize that performance by
42 ARIZONA may depend upon appropriation of funds by the State Legislature of
43 ARIZONA. If the Legislature fails to appropriate the necessary funds, or if
44 ARIZONA’S appropriation is reduced during the fiscal year, ARIZONA may cancel
45 this Agreement without further duty or obligation. ARIZONA will notify
46 LICENSEE as soon as reasonably possible after it knows of the loss of funds.
47 
48 1.5. Conflict of Interest. This Agreement is subject to the provisions of
49 A.R.S. 38-511 and other conflict of interest regulations. Within three years
50 of the EFFECTIVE DATE, ARIZONA may cancel this Agreement if any person
51 significantly involved in initiating, negotiating, drafting, securing, or
52 creating this Agreement for or on behalf of ARIZONA becomes an employee or
53 consultant in any capacity of LICENSEE with respect to the subject matter of
54 this Agreement.
55 
56  */
57 
58 #include <stdlib.h>
59 #include <stdio.h>
60 #include <string.h>
61 #include <strings.h>
62 #include <math.h>
63 
64 #include "../calc/zmath.h"
65 #include "../calc/calc.h"
66 
67 /*
68 Name Args Description
69 
70 abs 1-2 absolute value within accuracy b
71 acos 1-2 arccosine of a within accuracy b
72 acosh 1-2 inverse hyperbolic cosine of a within accuracy b
73 acot 1-2 arccotangent of a within accuracy b
74 acoth 1-2 inverse hyperbolic cotangent of a within accuracy b
75 acsc 1-2 arccosecant of a within accuracy b
76 acsch 1-2 inverse csch of a within accuracy b
77 appr 1-3 approximate a by multiple of b using rounding c
78 asec 1-2 arcsecant of a within accuracy b
79 asech 1-2 inverse hyperbolic secant of a within accuracy b
80 asin 1-2 arcsine of a within accuracy b
81 asinh 1-2 inverse hyperbolic sine of a within accuracy b
82 atan 1-2 arctangent of a within accuracy b
83 atan2 2-3 angle to point (b,a) within accuracy c
84 atanh 1-2 inverse hyperbolic tangent of a within accuracy b
85 ceil 1 smallest integer greater than or equal to number
86 cmp 2 compare values returning -1, 0, or 1
87 cos 1-2 cosine of value a within accuracy b
88 cosh 1-2 hyperbolic cosine of a within accuracy b
89 cot 1-2 cotangent of a within accuracy b
90 coth 1-2 hyperbolic cotangent of a within accuracy b
91 csc 1-2 cosecant of a within accuracy b
92 csch 1-2 hyperbolic cosecant of a within accuracy b
93 exp 1-2 exponential of value a within accuracy b
94 factor 1-3 lowest prime factor < b of a, return c if error
95 fcnt 2 count of times one number divides another
96 fact 1 factorial
97 floor 1 greatest integer less than or equal to number
98 frac 1 fractional part of value
99 hmean 0+ harmonic mean of values
100 hnrmod 4 v mod h*2^n+r, h>0, n>0, r = -1, 0 or 1
101 hypot 2-3 hypotenuse of right triangle within accuracy c
102 ilog 2 integral log of a to integral base b
103 ilog10 1 integral log of a number base 10
104 ilog2 1 integral log of a number base 2
105 int 1 integer part of value
106 inverse 1 multiplicative inverse of value
107 iroot 2 integer b'th root of a
108 isprime 1-2 whether a is a small prime, return b if error
109 isqrt 1 integer part of square root
110 
111 jacobi 2 -1 => a is not quadratic residue mod b 1 => b is composite, or a is quad residue of b
112 join 1+ join one or more lists into one list
113 lcm 1+ least common multiple
114 lcmfact 1 lcm of all integers up till number
115 lfactor 2 lowest prime factor of a in first b primes
116 links 1 links to number or string value
117 list 0+ create list of specified values
118 ln 1-2 natural logarithm of value a within accuracy b
119 log 1-2 base 10 logarithm of value a within accuracy b
120 lowbit 1 low bit number in base 2 representation
121 ltol 1-2 leg-to-leg of unit right triangle (sqrt(1 - a^2))
122 makelist 1 create a list with a null elements
123 matdim 1 number of dimensions of matrix
124 matfill 2-3 fill matrix with value b (value c on diagonal)
125 matmax 2 maximum index of matrix a dim b
126 matmin 2 minimum index of matrix a dim b
127 matsum 1 sum the numeric values in a matrix
128 mattrace 1 return the trace of a square matrix
129 mattrans 1 transpose of matrix
130 max 0+ maximum value
131 memsize 1 number of octets used by the value, including overhead
132 meq 3 whether a and b are equal modulo c
133 min 0+ minimum value
134 minv 2 inverse of a modulo b
135 mmin 2 a mod b value with smallest abs value
136 mne 3 whether a and b are not equal modulo c
137 mod 2-3 residue of a modulo b, rounding type c
138 modify 2 modify elements of a list or matrix
139 name 1 name assigned to block or file
140 near 2-3 sign of (abs(a-b) - c)
141 newerror 0-1 create new error type with message a
142 nextcand 1-5 smallest value == d mod e > a, ptest(a,b,c) true
143 nextprime 1-2 return next small prime, return b if err
144 norm 1 norm of a value (square of absolute value)
145 null 0+ null value
146 num 1 numerator of fraction
147 ord 1 integer corresponding to character value
148 isupper 1 whether character is upper case
149 islower 1 whether character is lower case
150 isalnum 1 whether character is alpha-numeric
151 isalpha 1 whether character is alphabetic
152 iscntrl 1 whether character is a control character
153 isdigit 1 whether character is a digit
154 isgraph 1 whether character is a graphical character
155 isprint 1 whether character is printable
156 ispunct 1 whether character is a punctuation
157 isspace 1 whether character is a space character
158 isxdigit 1 whether character is a hexadecimal digit
159 param 1 value of parameter n (or parameter count if n is zero)
160 perm 2 permutation number a!/(a-b)!
161 prevcand 1-5 largest value == d mod e < a, ptest(a,b,c) true
162 prevprime 1-2 return previous small prime, return b if err
163 pfact 1 product of primes up till number
164 pi 0-1 value of pi accurate to within epsilon
165 pix 1-2 number of primes <= a < 2^32, return b if error
166 places 1-2 places after "decimal" point (-1 if infinite)
167 pmod 3 mod of a power (a ^ b (mod c))
168 polar 2-3 complex value of polar coordinate (a * exp(b*1i))
169 poly 1+ evaluates a polynomial given its coefficients or coefficient-list
170 pop 1 pop value from front of list
171 popcnt 1-2 number of bits in a that match b (or 1)
172 power 2-3 value a raised to the power b within accuracy c
173 protect 1-3 read or set protection level for variable
174 ptest 1-3 probabilistic primality test
175 printf 1+ print formatted output to stdout
176 prompt 1 prompt for input line using value a
177 push 1+ push values onto front of list
178 putenv 1-2 define an environment variable
179 quo 2-3 integer quotient of a by b, rounding type c
180 quomod 4-5 set c and d to quotient and remainder of a divided by b
181 rand 0-2 additive 55 random number [0,2^64), [0,a), or [a,b)
182 randbit 0-1 additive 55 random number [0,2^a)
183 random 0-2 Blum-Blum-Shub random number [0,2^64), [0,a), or [a,b)
184 randombit 0-1 Blum-Blum-Sub random number [0,2^a)
185 randperm 1 random permutation of a list or matrix
186 rcin 2 convert normal number a to REDC number mod b
187 rcmul 3 multiply REDC numbers a and b mod c
188 rcout 2 convert REDC number a mod b to normal number
189 rcpow 3 raise REDC number a to power b mod c
190 rcsq 2 square REDC number a mod b
191 re 1 real part of complex number
192 remove 1 remove value from end of list
193 reverse 1 reverse a copy of a matrix or list
194 rewind 0+ rewind file(s)
195 rm 1+ remove file(s), -f turns off no-such-file errors
196 root 2-3 value a taken to the b'th root within accuracy c
197 round 1-3 round value a to b number of decimal places
198 rsearch 2-4 reverse search matrix or list for value b starting at index c
199 runtime 0 user and kernel mode cpu time in seconds
200 saveval 1 set flag for saving values
201 scale 2 scale value up or down by a power of two
202 scan 1+ scan standard input for assignment to one or more variables
203 scanf 2+ formatted scan of standard input for assignment to variables
204 search 2-4 search matrix or list for value b starting at index c
205 sec 1-2 sec of a within accuracy b
206 sech 1-2 hyperbolic secant of a within accuracy b
207 seed 0 return a 64 bit seed for a psuedo-random generator
208 segment 2-3 specified segment of specified list
209 select 2 form sublist of selected elements from list
210 setbit 2-3 set specified bit in string
211 sgn 1 sign of value (-1, 0, 1)
212 sha1 0+ Secure Hash Algorithm (SHS-1 FIPS Pub 180-1)
213 sin 1-2 sine of value a within accuracy b
214 sinh 1-2 hyperbolic sine of a within accuracy b
215 size 1 total number of elements in value
216 sizeof 1 number of octets used to hold the value
217 sleep 0-1 suspend operation for a seconds
218 sort 1 sort a copy of a matrix or list
219 sqrt 1-3 square root of value a within accuracy b
220 srand 0-1 seed the rand() function
221 srandom 0-4 seed the random() function
222 ssq 1+ sum of squares of values
223 stoponerror 0-1 assign value to stoponerror flag
224 str 1 simple value converted to string
225 strtoupper 1 Make string upper case
226 strtolower 1 Make string lower case
227 strcat 1+ concatenate strings together
228 strcmp 2 compare two strings
229 strcasecmp 2 compare two strings case independent
230 strcpy 2 copy string to string
231 strerror 0-1 string describing error type
232 strlen 1 length of string
233 strncmp 3 compare strings a, b to c characters
234 strncasecmp 3 compare strings a, b to c characters case independent
235 strncpy 3 copy up to c characters from string to string
236 strpos 2 index of first occurrence of b in a
237 strprintf 1+ return formatted output as a string
238 strscan 2+ scan a string for assignments to one or more variables
239 strscanf 2+ formatted scan of string for assignments to variables
240 substr 3 substring of a from position b for c chars
241 sum 0+ sum of list or object sums and/or other terms
242 swap 2 swap values of variables a and b (can be dangerous)
243 system 1 call Unix command
244 systime 0 kernel mode cpu time in seconds
245 tail 2 retain list of specified number at tail of list
246 tan 1-2 tangent of a within accuracy b
247 tanh 1-2 hyperbolic tangent of a within accuracy b
248 test 1 test that value is nonzero
249 time 0 number of seconds since 00:00:00 1 Jan 1970 UTC
250 trunc 1-2 truncate a to b number of decimal places
251 ungetc 2 unget char read from file
252 usertime 0 user mode cpu time in seconds
253 version 0 calc version string
254 xor 1+ logical xor
255 
256  */
257 
258 char lcalc_tbuf[256];
259 
260 /* non-zero => calc_scanerr_jmpbuf ready */
261 extern int calc_use_scanerr_jmpbuf;
262 /* for scan and parse errors */
263 extern jmp_buf calc_scanerr_jmpbuf;
264 
265 
266 char *lcalc(cmdbuf)
267 char *cmdbuf;
268 {
269  /*int ret; */
270 
271  libcalc_call_me_first();
272 
273  if(strlen(cmdbuf))
274  {
275  /*
276  * establish error longjump point with initial conditions
277  */
278  if (setjmp(calc_scanerr_jmpbuf) == 0)
279  {
280  /*
281  * reset/initialize the computing environment
282  */
283  initialize();
285  }
286 
287  /*ret = */
288  openstring(cmdbuf, strlen(cmdbuf));
289 // fprintf(stderr, "openstring() returned %d\n", ret);
290 
291  math_divertio();
292 
293  getcommands(FALSE);
294 
295  strcpy(lcalc_tbuf, math_getdivertedio());
296 
297 // fprintf(stderr, "lcalc(): %s", lcalc_tbuf);
298 
299  closeinput();
300  }
301  else
302  {
303  strcpy(lcalc_tbuf, "0.0");
304  }
305 
306  return(lcalc_tbuf);
307 }
308 
#define FALSE
Definition: xgraphic.c:40
int calc_use_scanerr_jmpbuf
jmp_buf calc_scanerr_jmpbuf
char * lcalc(char *cmdbuf)
Definition: lcalc.c:266
char lcalc_tbuf[256]
Definition: lcalc.c:258