/[ascend]/trunk/base/generic/compiler/dimen.h
ViewVC logotype

Contents of /trunk/base/generic/compiler/dimen.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 67 - (show annotations) (download) (as text)
Wed Nov 30 16:31:29 2005 UTC (14 years, 2 months ago) by johnpye
File MIME type: text/x-chdr
File size: 13508 byte(s)
Standardised the "if seen" #defines to [ASC|ASCTK|ASCPY|ASCXX]_FILENAME_H
Fixed compile on FC3
1 /*
2 * Ascend Dimensions Data Structure
3 * by Tom Epperly
4 * 8/18/89
5 * Version: $Revision: 1.7 $
6 * Version control file: $RCSfile: dimen.h,v $
7 * Date last modified: $Date: 1997/07/18 12:28:58 $
8 * Last modified by: $Author: mthomas $
9 *
10 * This file is part of the Ascend Language Interpreter.
11 *
12 * Copyright (C) 1990, 1993, 1994 Thomas Guthrie Epperly
13 *
14 * The Ascend Language Interpreter is free software; you can redistribute
15 * it and/or modify it under the terms of the GNU General Public License as
16 * published by the Free Software Foundation; either version 2 of the
17 * License, or (at your option) any later version.
18 *
19 * The Ascend Language Interpreter is distributed in hope that it will be
20 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 * General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with the program; if not, write to the Free Software Foundation,
26 * Inc., 675 Mass Ave, Cambridge, MA 02139 USA. Check the file named
27 * COPYING.
28 */
29
30 /** @file
31 * Ascend Dimensions Data Structure.
32 * <pre>
33 * When #including dimen.h, make sure these files are #included first:
34 * #include "utilities/ascConfig.h"
35 * #include "fractions.h"
36 * #include "compiler.h"
37 * </pre>
38 */
39
40 #ifndef ASC_DIMEN_H
41 #define ASC_DIMEN_H
42
43 /* Keep these defines current with DimNames in dimen.h. */
44 #define NUM_DIMENS 10 /**< Number of dimension types. */
45 #define D_MASS 0 /**< Index for mass dimension. */
46 #define D_QUANTITY 1 /**< Index for quantity dimension. */
47 #define D_LENGTH 2 /**< Index for length dimension. */
48 #define D_TIME 3 /**< Index for time dimension. */
49 #define D_TEMPERATURE 4 /**< Index for temperature dimension. */
50 #define D_CURRENCY 5 /**< Index for currency dimension. */
51 #define D_ELECTRIC_CURRENT 6 /**< Index for electric current dimension. */
52 #define D_LUMINOUS_INTENSITY 7 /**< Index for luminous intensity dimension. */
53 #define D_PLANE_ANGLE 8 /**< Index for plane angle dimension. */
54 #define D_SOLID_ANGLE 9 /**< Index for solid angle dimension. */
55
56 /** Dimension data structure. */
57 struct DimStruct {
58 struct fraction f[NUM_DIMENS]; /**< Array of fractions, one for each dimension type. */
59 unsigned int wild; /**< Wild flag. Only valid values are 0 and DIM_WILD */
60 };
61 #define DIM_WILD 0x1
62 /**< Code for a wild dimension. */
63
64 /** Dimension typedef for general use */
65 typedef struct DimStruct dim_type;
66
67 extern struct gl_list_t *g_dimen_list;
68 /**<
69 * Global list of dimension data structures. All persistent dim pointers
70 * should resolve to something pointed at in this list to minimize dim
71 * overhead.
72 */
73
74 extern void InitDimenList(void);
75 /**<
76 * Initialize the dimension list.
77 * Must be called once and only once before any other dimension calls.
78 */
79
80 extern void DestroyDimenList(void);
81 /**<
82 * This can be called to deallocate all of the allocated dimensions.
83 */
84
85 #define GetDimFraction(d,i) ((d).f[i])
86 /**<
87 * Returns a fraction struct from a dim_type.
88 * i should be one of
89 * - D_MASS
90 * - D_QUANTITY
91 * - D_LENGTH
92 * - D_TIME
93 * - D_TEMPERATURE
94 * - D_CURRENCY
95 * - D_ELECTRIC_CURRENT
96 * - D_LUMINOUS_INTENSITY
97 * - D_PLANE_ANGLE
98 * - D_SOLID_ANGLE
99 */
100
101 #define GetDimPower(d,i) \
102 (int)(Denominator((d).f[i])==1 ? Numerator((d).f[i]) : 0)
103 /**<
104 * Returns an int value of the numerator, or 0 if the
105 * denominator != 1.
106 */
107
108 #define SetDimFraction(d,i,frac) ( (d).f[(i)] = (frac) )
109 /**<
110 * Set fraction i in dim_type d to frac.
111 */
112
113 extern void ClearDimensions(dim_type *d);
114 /**<
115 * <!-- ClearDimensions(d) -->
116 * <!-- dim_type *d; -->
117 * Initialize all the dimension fractions to zero.
118 */
119
120 extern CONST dim_type *Dimensionless(void);
121 /**<
122 * <!-- dim_type *Dimensionless(); -->
123 * Return a pointer to the dimensionless structure.
124 */
125
126 extern CONST dim_type *TrigDimension(void);
127 /**<
128 * <!-- dim_type *TrigDimension(); -->
129 * Return a pointer to the dimension structure for plane angle.
130 */
131
132 extern CONST dim_type *WildDimension(void);
133 /**<
134 * <!-- dim_type *WildDimension() -->
135 * Return a pointer to a wild dimension structure. You don't need to
136 * call FindOrAddDimen with this dimension.
137 */
138
139 extern CONST dim_type *HalfDimension(CONST dim_type *d, int b);
140 /**<
141 * <!-- dim_type *HalfDimension(d,b) -->
142 * Return a pointer to a dimension structure with sqrt dimensionality.
143 * Returns null if sqrt dimensionality is fractional when tested (b true).
144 * If not b, result may point to noninteger dim. Dim will be in global list.
145 */
146
147 extern CONST dim_type *ThirdDimension(CONST dim_type *d, int b);
148 /**<
149 * <!-- dim_type *ThirdDimension(d,b) -->
150 * Return a pointer to a dimension structure with cbrt dimensionality.
151 * Returns null if cbrt dimensionality is fractional when tested (b true).
152 * If !b, result may point to noninteger dim. Dim will be in global list.
153 */
154
155 extern CONST dim_type *SquareDimension(CONST dim_type *d, int b);
156 /**<
157 * <!-- dim_type *SquareDimension(d,b) -->
158 * Return a pointer to a dimension structure with square dimensionality.
159 * Returns null if square dimensionality is fractional when tested (b true).
160 * If not b, result may point to noninteger dim. Dim will be in global list.
161 */
162
163 extern CONST dim_type *CubeDimension(CONST dim_type *d, int b);
164 /**<
165 * <!-- dim_type *CubeDimension(d,b) -->
166 * Return a pointer to a dimension structure with cube dimensionality.
167 * Returns null if cube dimensionality is fractional when tested (b true).
168 * If !b, result may point to noninteger dim. Dim will be in global list.
169 */
170
171 extern CONST dim_type *PowDimension(long mult, CONST dim_type *d, int b);
172 /**<
173 * <!-- dim_type *IntDimension(mult,d,b) -->
174 * Return a pointer to a dimension structure with d*mult dimensionality.
175 * Returns null if cube dimensionality is fractional when tested (b true)
176 * or if mult*d yields integer overflow of the dimensionality.
177 * If !b, result may point to noninteger dim. Dim will be in global list.
178 */
179
180 extern void SetWild(dim_type *dim);
181 /**<
182 * <!-- void SetWild(dim) -->
183 * <!-- dim_type *dim; -->
184 * Set the wild flag of dimensions dim.
185 */
186
187 extern int IsWild(CONST dim_type *d);
188 /**<
189 * <!-- int IsWild(d) -->
190 * <!-- const dim_type *d; -->
191 * Return a true value if d is wild, and otherwise return a false value.
192 */
193
194 extern int OddDimension(CONST dim_type *d);
195 /**<
196 * <!-- int OddDimension(d) -->
197 * <!-- const dim_type *d; -->
198 * Return a true value if d has an odd, wild, or non-integer dimension.
199 */
200
201 extern int NonCubicDimension(CONST dim_type *d);
202 /**<
203 * <!-- int CubicDimension(d) -->
204 * <!-- const dim_type *d; -->
205 * Return a true value if d has an noncubic, wild, or non-integer dimension.
206 */
207
208 extern int SameDimen(CONST dim_type *d1, CONST dim_type *d2);
209 /**<
210 * <!-- SameDimen(d1,d2) -->
211 * <!-- const dim_type *d1,*d2; -->
212 * Return 1 if d1 and d2 have the same dimensional value, or 0
213 * otherwise. Two wild dimensions are the same, regardless of any
214 * other data they may contain.
215 * Wild and any non-wild are NOT the same.
216 */
217
218 extern int CmpDimen(CONST dim_type *d1, CONST dim_type *d2);
219 /**<
220 * <!-- CmpDimen(d1,d2) -->
221 * <!-- const dim_type *d1,*d2; -->
222 * Return 1,0,-1 if d1 is >,=, or < d2 respectively.
223 */
224
225 extern CONST dim_type *FindOrAddDimen(CONST dim_type *d);
226 /**<
227 * <!-- const dim_type *FindOrAddDimen(d) -->
228 * <!-- const dim_type *d; -->
229 * This function is run to make sure only one copy of each dimensions
230 * is stored. It is designed to be called as follows:
231 * <pre>
232 * Example:
233 * dim_type d,*p;
234 * ClearDimensions(&d);
235 * SetDimFraction(d,D_MASS,CreateFraction(1,2));
236 * ...etc...
237 * p = FindOrAddDimen(&d);
238 * p will never point to d. p != &d.
239 * </pre>
240 */
241
242 extern void CopyDimensions(CONST dim_type *src, dim_type *dest);
243 /**<
244 * <!-- void CopyDimensions(src,dest) -->
245 * <!-- const dim_type *src; -->
246 * <!-- dim_type *dest; -->
247 * Copy from src to dest.
248 */
249
250 extern dim_type AddDimensions(CONST dim_type *d1, CONST dim_type *d2);
251 /**<
252 * <!-- dim_type AddDimensions(d1,d2) -->
253 * <!-- const dim_type *d1,*d2; -->
254 * Add 2 dimensions.
255 * Wild+anything equals wild.
256 * return d1+d2;
257 * NOTE: This returns a dim by value, not by pointer. There are places
258 * where this is desirable. Where you want a pointer from the dim
259 * table instead, use SumDimensions.
260 */
261
262 extern CONST dim_type *SumDimensions(CONST dim_type *d1, CONST dim_type *d2, int check);
263 /**<
264 * <!-- CONST dim_type *SumDimensions(d1,d2,check) -->
265 * <!-- const dim_type *d1,*d2; -->
266 * <!-- int check; -->
267 * Add 2 dimensions with checking.
268 * Wild+anything equals wild.
269 * return d1+d2;
270 * If check != 0, verifies that d1 and d2 are not fractional, returning
271 * NULL if fractional found.
272 * Result will be in global list.
273 */
274
275 extern dim_type SubDimensions(CONST dim_type *d1, CONST dim_type *d2);
276 /**<
277 * <!-- dim_type SubDimensions(d1,d2) -->
278 * <!-- const dim_type *d1,*d2; -->
279 * Subtract 2 dimensions.
280 * Wild-anything equals wild.
281 * return d1-d2;
282 * NOTE: This returns a dim by value, not by pointer. There are places
283 * where this is desirable. Where you want a pointer from the dim
284 * table instead, use DiffDimensions.
285 */
286
287 extern CONST dim_type *DiffDimensions(CONST dim_type *d1, CONST dim_type *d2, int check);
288 /**<
289 * <!-- CONST dim_type *SumDimensions(d1,d2,check) -->
290 * <!-- const dim_type *d1,*d2; -->
291 * <!-- int check; -->
292 * Subtract 2 dimensions with checking.
293 * Wild-anything equals wild.
294 * return d1-d2;
295 * If check != 0, verifies that d1 and d2 are not fractional, returning
296 * NULL if fractional found.
297 * Result will be in global list.
298 */
299
300 extern dim_type ScaleDimensions(CONST dim_type *dim, struct fraction frac);
301 /**<
302 * <!-- dim_type ScaleDimensions(dim,frac) -->
303 * <!-- dim_type *dim; -->
304 * <!-- struct fraction frac; -->
305 * Scale the dimensions by frac. A wild scaled always remains wild.
306 */
307
308 extern void ParseDim(dim_type *dim, CONST char *c);
309 /**<
310 * <!-- void ParseDim(dim,c) -->
311 * <!-- dim_type *dim; -->
312 * <!-- char *c; -->
313 * Initialize dim appropriately according to the string c. If c doesn't
314 * match any of the dimension strings, dim will be dimensionless and
315 * an error message will be printed.
316 * <pre>
317 * String Dimension Index
318 * "M" D_MASS
319 * "Q" D_QUANTITY
320 * "T" D_TIME
321 * "L" D_LENGTH
322 * "TMP" D_TEMPERATURE
323 * "C" D_CURRENCY
324 * "E" D_ELECTRIC_CURRENT
325 * "LUM" D_LUMINOUS_INTENSITY
326 * "P" D_PLANE_ANGLE
327 * "S" D_SOLID_ANGLE
328 * </pre>
329 */
330
331 extern char *DimName(CONST int index);
332 /**<
333 * <!-- char *DimName(index) -->
334 * <!-- int index; -->
335 * Return the internal copy of the name of the dimension corresponding
336 * to index if index is within [0..NUM_DIMENS-1], otherwise return NULL.
337 */
338
339 extern CONST dim_type *CheckDimensionsMatch(CONST dim_type *d1, CONST dim_type *d2);
340 /**<
341 * <!-- dim_t *CheckDimensionsMatch(d1,d2) -->
342 * <!-- const dim_t *d1,*d2; -->
343 * Compare 2 dimensions.
344 * - Return d1 if d2 is wild
345 * - Return d2 if d1 is wild or d1 == d2
346 * - Return d1 if *d1 == *d2
347 * - Otherwise return NULL
348 */
349
350 extern void PrintDimen(FILE *f ,CONST dim_type *d);
351 /**< Print a dimension to a file. Used in interface */
352 extern void DumpDimens(FILE *f);
353 /**< Dump all dimensions to a file. Used in interface */
354
355 #endif /* ASC_DIMEN_H */
356

john.pye@anu.edu.au
ViewVC Help
Powered by ViewVC 1.1.22