1 |
johnpye |
485 |
/* ASCEND modelling environment |
2 |
|
|
Copyright (C) 1990, 1993, 1994 Thomas Guthrie Epperly |
3 |
|
|
Copyright (C) 2006 Carnegie Mellon University |
4 |
aw0a |
1 |
|
5 |
johnpye |
485 |
This program is free software; you can redistribute it and/or modify |
6 |
|
|
it under the terms of the GNU General Public License as published by |
7 |
|
|
the Free Software Foundation; either version 2, or (at your option) |
8 |
|
|
any later version. |
9 |
aw0a |
1 |
|
10 |
johnpye |
485 |
This program is distributed in the hope that it will be useful, |
11 |
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 |
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 |
|
|
GNU General Public License for more details. |
14 |
|
|
|
15 |
|
|
You should have received a copy of the GNU General Public License |
16 |
|
|
along with this program; if not, write to the Free Software |
17 |
|
|
Foundation, Inc., 59 Temple Place - Suite 330, |
18 |
|
|
Boston, MA 02111-1307, USA. |
19 |
|
|
*//** |
20 |
|
|
@file |
21 |
|
|
Ascend Dimensions Data Structure. |
22 |
|
|
*//* |
23 |
|
|
by Tom Epperly |
24 |
|
|
8/18/89 |
25 |
|
|
Version: $Revision: 1.7 $ |
26 |
|
|
Version control file: $RCSfile: dimen.h,v $ |
27 |
|
|
Date last modified: $Date: 1997/07/18 12:28:58 $ |
28 |
|
|
Last modified by: $Author: mthomas $ |
29 |
|
|
*/ |
30 |
|
|
|
31 |
johnpye |
67 |
#ifndef ASC_DIMEN_H |
32 |
|
|
#define ASC_DIMEN_H |
33 |
aw0a |
1 |
|
34 |
johnpye |
1066 |
/** addtogroup compiler Compiler |
35 |
|
|
@{ |
36 |
|
|
*/ |
37 |
|
|
|
38 |
johnpye |
485 |
#include <utilities/ascConfig.h> |
39 |
johnpye |
1039 |
#include "fractions.h" |
40 |
|
|
#include "compiler.h" |
41 |
johnpye |
485 |
|
42 |
johnpye |
1039 |
|
43 |
jds |
54 |
/* 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 |
aw0a |
1 |
struct DimStruct { |
58 |
jds |
54 |
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 |
aw0a |
1 |
#define DIM_WILD 0x1 |
62 |
jds |
54 |
/**< Code for a wild dimension. */ |
63 |
aw0a |
1 |
|
64 |
jds |
54 |
/** Dimension typedef for general use */ |
65 |
aw0a |
1 |
typedef struct DimStruct dim_type; |
66 |
|
|
|
67 |
johnpye |
1063 |
ASC_DLLSPEC struct gl_list_t *g_dimen_list; |
68 |
jds |
54 |
/**< |
69 |
aw0a |
1 |
* 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 |
jds |
54 |
/**< |
76 |
|
|
* Initialize the dimension list. |
77 |
aw0a |
1 |
* Must be called once and only once before any other dimension calls. |
78 |
|
|
*/ |
79 |
|
|
|
80 |
|
|
extern void DestroyDimenList(void); |
81 |
jds |
54 |
/**< |
82 |
aw0a |
1 |
* This can be called to deallocate all of the allocated dimensions. |
83 |
|
|
*/ |
84 |
|
|
|
85 |
|
|
#define GetDimFraction(d,i) ((d).f[i]) |
86 |
jds |
54 |
/**< |
87 |
aw0a |
1 |
* Returns a fraction struct from a dim_type. |
88 |
johnpye |
480 |
* i should be one of |
89 |
|
|
* - D_MASS |
90 |
|
|
* - D_QUANTITY |
91 |
|
|
* - D_LENGTH |
92 |
|
|
* - D_TIME |
93 |
jds |
54 |
* - D_TEMPERATURE |
94 |
johnpye |
480 |
* - D_CURRENCY |
95 |
|
|
* - D_ELECTRIC_CURRENT |
96 |
|
|
* - D_LUMINOUS_INTENSITY |
97 |
jds |
54 |
* - D_PLANE_ANGLE |
98 |
|
|
* - D_SOLID_ANGLE |
99 |
aw0a |
1 |
*/ |
100 |
|
|
|
101 |
|
|
#define GetDimPower(d,i) \ |
102 |
|
|
(int)(Denominator((d).f[i])==1 ? Numerator((d).f[i]) : 0) |
103 |
jds |
54 |
/**< |
104 |
aw0a |
1 |
* 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 |
jds |
54 |
/**< |
110 |
|
|
* Set fraction i in dim_type d to frac. |
111 |
|
|
*/ |
112 |
aw0a |
1 |
|
113 |
johnpye |
1063 |
ASC_DLLSPEC void ClearDimensions(dim_type *d); |
114 |
jds |
54 |
/**< |
115 |
aw0a |
1 |
* Initialize all the dimension fractions to zero. |
116 |
|
|
*/ |
117 |
|
|
|
118 |
johnpye |
1063 |
ASC_DLLSPEC CONST dim_type*Dimensionless(void); |
119 |
jds |
54 |
/**< |
120 |
aw0a |
1 |
* Return a pointer to the dimensionless structure. |
121 |
|
|
*/ |
122 |
|
|
|
123 |
johnpye |
1063 |
ASC_DLLSPEC CONST dim_type *TrigDimension(void); |
124 |
jds |
54 |
/**< |
125 |
aw0a |
1 |
* Return a pointer to the dimension structure for plane angle. |
126 |
|
|
*/ |
127 |
|
|
|
128 |
johnpye |
1063 |
ASC_DLLSPEC CONST dim_type *WildDimension(void); |
129 |
jds |
54 |
/**< |
130 |
aw0a |
1 |
* Return a pointer to a wild dimension structure. You don't need to |
131 |
|
|
* call FindOrAddDimen with this dimension. |
132 |
|
|
*/ |
133 |
|
|
|
134 |
jds |
54 |
extern CONST dim_type *HalfDimension(CONST dim_type *d, int b); |
135 |
|
|
/**< |
136 |
aw0a |
1 |
* Return a pointer to a dimension structure with sqrt dimensionality. |
137 |
|
|
* Returns null if sqrt dimensionality is fractional when tested (b true). |
138 |
|
|
* If not b, result may point to noninteger dim. Dim will be in global list. |
139 |
|
|
*/ |
140 |
|
|
|
141 |
jds |
54 |
extern CONST dim_type *ThirdDimension(CONST dim_type *d, int b); |
142 |
|
|
/**< |
143 |
aw0a |
1 |
* Return a pointer to a dimension structure with cbrt dimensionality. |
144 |
|
|
* Returns null if cbrt dimensionality is fractional when tested (b true). |
145 |
|
|
* If !b, result may point to noninteger dim. Dim will be in global list. |
146 |
|
|
*/ |
147 |
|
|
|
148 |
jds |
54 |
extern CONST dim_type *SquareDimension(CONST dim_type *d, int b); |
149 |
|
|
/**< |
150 |
aw0a |
1 |
* Return a pointer to a dimension structure with square dimensionality. |
151 |
|
|
* Returns null if square dimensionality is fractional when tested (b true). |
152 |
|
|
* If not b, result may point to noninteger dim. Dim will be in global list. |
153 |
|
|
*/ |
154 |
|
|
|
155 |
jds |
54 |
extern CONST dim_type *CubeDimension(CONST dim_type *d, int b); |
156 |
|
|
/**< |
157 |
aw0a |
1 |
* Return a pointer to a dimension structure with cube dimensionality. |
158 |
|
|
* Returns null if cube dimensionality is fractional when tested (b true). |
159 |
|
|
* If !b, result may point to noninteger dim. Dim will be in global list. |
160 |
|
|
*/ |
161 |
|
|
|
162 |
jds |
54 |
extern CONST dim_type *PowDimension(long mult, CONST dim_type *d, int b); |
163 |
|
|
/**< |
164 |
aw0a |
1 |
* Return a pointer to a dimension structure with d*mult dimensionality. |
165 |
|
|
* Returns null if cube dimensionality is fractional when tested (b true) |
166 |
|
|
* or if mult*d yields integer overflow of the dimensionality. |
167 |
|
|
* If !b, result may point to noninteger dim. Dim will be in global list. |
168 |
|
|
*/ |
169 |
|
|
|
170 |
jds |
54 |
extern void SetWild(dim_type *dim); |
171 |
|
|
/**< |
172 |
aw0a |
1 |
* Set the wild flag of dimensions dim. |
173 |
|
|
*/ |
174 |
|
|
|
175 |
johnpye |
1063 |
ASC_DLLSPEC int IsWild(CONST dim_type *d); |
176 |
jds |
54 |
/**< |
177 |
aw0a |
1 |
* Return a true value if d is wild, and otherwise return a false value. |
178 |
|
|
*/ |
179 |
|
|
|
180 |
jds |
54 |
extern int OddDimension(CONST dim_type *d); |
181 |
|
|
/**< |
182 |
aw0a |
1 |
* Return a true value if d has an odd, wild, or non-integer dimension. |
183 |
|
|
*/ |
184 |
|
|
|
185 |
jds |
54 |
extern int NonCubicDimension(CONST dim_type *d); |
186 |
|
|
/**< |
187 |
aw0a |
1 |
* Return a true value if d has an noncubic, wild, or non-integer dimension. |
188 |
|
|
*/ |
189 |
|
|
|
190 |
jds |
54 |
extern int SameDimen(CONST dim_type *d1, CONST dim_type *d2); |
191 |
|
|
/**< |
192 |
aw0a |
1 |
* Return 1 if d1 and d2 have the same dimensional value, or 0 |
193 |
|
|
* otherwise. Two wild dimensions are the same, regardless of any |
194 |
|
|
* other data they may contain. |
195 |
|
|
* Wild and any non-wild are NOT the same. |
196 |
|
|
*/ |
197 |
|
|
|
198 |
johnpye |
1063 |
ASC_DLLSPEC int CmpDimen(CONST dim_type *d1, CONST dim_type *d2); |
199 |
jds |
54 |
/**< |
200 |
aw0a |
1 |
* Return 1,0,-1 if d1 is >,=, or < d2 respectively. |
201 |
|
|
*/ |
202 |
|
|
|
203 |
johnpye |
1063 |
ASC_DLLSPEC CONST dim_type *FindOrAddDimen(CONST dim_type *d); |
204 |
jds |
54 |
/**< |
205 |
aw0a |
1 |
* This function is run to make sure only one copy of each dimensions |
206 |
|
|
* is stored. It is designed to be called as follows: |
207 |
jds |
54 |
* <pre> |
208 |
aw0a |
1 |
* Example: |
209 |
jds |
54 |
* dim_type d,*p; |
210 |
|
|
* ClearDimensions(&d); |
211 |
|
|
* SetDimFraction(d,D_MASS,CreateFraction(1,2)); |
212 |
|
|
* ...etc... |
213 |
|
|
* p = FindOrAddDimen(&d); |
214 |
|
|
* p will never point to d. p != &d. |
215 |
|
|
* </pre> |
216 |
aw0a |
1 |
*/ |
217 |
|
|
|
218 |
johnpye |
1063 |
ASC_DLLSPEC void CopyDimensions(CONST dim_type *src, dim_type *dest); |
219 |
jds |
54 |
/**< |
220 |
aw0a |
1 |
* Copy from src to dest. |
221 |
|
|
*/ |
222 |
|
|
|
223 |
johnpye |
1063 |
ASC_DLLSPEC dim_type AddDimensions(CONST dim_type *d1, CONST dim_type *d2); |
224 |
jds |
54 |
/**< |
225 |
|
|
* Add 2 dimensions. |
226 |
aw0a |
1 |
* Wild+anything equals wild. |
227 |
|
|
* return d1+d2; |
228 |
|
|
* NOTE: This returns a dim by value, not by pointer. There are places |
229 |
|
|
* where this is desirable. Where you want a pointer from the dim |
230 |
|
|
* table instead, use SumDimensions. |
231 |
|
|
*/ |
232 |
|
|
|
233 |
jds |
54 |
extern CONST dim_type *SumDimensions(CONST dim_type *d1, CONST dim_type *d2, int check); |
234 |
|
|
/**< |
235 |
|
|
* Add 2 dimensions with checking. |
236 |
aw0a |
1 |
* Wild+anything equals wild. |
237 |
|
|
* return d1+d2; |
238 |
|
|
* If check != 0, verifies that d1 and d2 are not fractional, returning |
239 |
|
|
* NULL if fractional found. |
240 |
|
|
* Result will be in global list. |
241 |
|
|
*/ |
242 |
|
|
|
243 |
johnpye |
1063 |
ASC_DLLSPEC dim_type SubDimensions(CONST dim_type *d1, CONST dim_type *d2); |
244 |
jds |
54 |
/**< |
245 |
|
|
* Subtract 2 dimensions. |
246 |
aw0a |
1 |
* Wild-anything equals wild. |
247 |
|
|
* return d1-d2; |
248 |
|
|
* NOTE: This returns a dim by value, not by pointer. There are places |
249 |
|
|
* where this is desirable. Where you want a pointer from the dim |
250 |
|
|
* table instead, use DiffDimensions. |
251 |
|
|
*/ |
252 |
|
|
|
253 |
jds |
54 |
extern CONST dim_type *DiffDimensions(CONST dim_type *d1, CONST dim_type *d2, int check); |
254 |
|
|
/**< |
255 |
|
|
* Subtract 2 dimensions with checking. |
256 |
aw0a |
1 |
* Wild-anything equals wild. |
257 |
|
|
* return d1-d2; |
258 |
|
|
* If check != 0, verifies that d1 and d2 are not fractional, returning |
259 |
|
|
* NULL if fractional found. |
260 |
|
|
* Result will be in global list. |
261 |
|
|
*/ |
262 |
|
|
|
263 |
johnpye |
1063 |
ASC_DLLSPEC dim_type ScaleDimensions(CONST dim_type *dim, struct fraction frac); |
264 |
jds |
54 |
/**< |
265 |
aw0a |
1 |
* Scale the dimensions by frac. A wild scaled always remains wild. |
266 |
|
|
*/ |
267 |
|
|
|
268 |
johnpye |
1063 |
ASC_DLLSPEC void ParseDim(dim_type *dim, CONST char *c); |
269 |
jds |
54 |
/**< |
270 |
aw0a |
1 |
* Initialize dim appropriately according to the string c. If c doesn't |
271 |
|
|
* match any of the dimension strings, dim will be dimensionless and |
272 |
|
|
* an error message will be printed. |
273 |
jds |
54 |
* <pre> |
274 |
aw0a |
1 |
* String Dimension Index |
275 |
|
|
* "M" D_MASS |
276 |
|
|
* "Q" D_QUANTITY |
277 |
|
|
* "T" D_TIME |
278 |
|
|
* "L" D_LENGTH |
279 |
|
|
* "TMP" D_TEMPERATURE |
280 |
|
|
* "C" D_CURRENCY |
281 |
|
|
* "E" D_ELECTRIC_CURRENT |
282 |
|
|
* "LUM" D_LUMINOUS_INTENSITY |
283 |
|
|
* "P" D_PLANE_ANGLE |
284 |
|
|
* "S" D_SOLID_ANGLE |
285 |
jds |
54 |
* </pre> |
286 |
aw0a |
1 |
*/ |
287 |
|
|
|
288 |
johnpye |
1063 |
ASC_DLLSPEC char *DimName(CONST int nIndex); |
289 |
jds |
54 |
/**< |
290 |
aw0a |
1 |
* Return the internal copy of the name of the dimension corresponding |
291 |
|
|
* to index if index is within [0..NUM_DIMENS-1], otherwise return NULL. |
292 |
|
|
*/ |
293 |
|
|
|
294 |
jds |
54 |
extern CONST dim_type *CheckDimensionsMatch(CONST dim_type *d1, CONST dim_type *d2); |
295 |
|
|
/**< |
296 |
|
|
* Compare 2 dimensions. |
297 |
|
|
* - Return d1 if d2 is wild |
298 |
|
|
* - Return d2 if d1 is wild or d1 == d2 |
299 |
|
|
* - Return d1 if *d1 == *d2 |
300 |
|
|
* - Otherwise return NULL |
301 |
aw0a |
1 |
*/ |
302 |
|
|
|
303 |
johnpye |
1063 |
ASC_DLLSPEC void PrintDimen(FILE *f ,CONST dim_type *d); |
304 |
jds |
54 |
/**< Print a dimension to a file. Used in interface */ |
305 |
johnpye |
619 |
|
306 |
|
|
|
307 |
johnpye |
1063 |
ASC_DLLSPEC void PrintDimenMessage(CONST char *message |
308 |
johnpye |
619 |
, CONST char *label1, CONST dim_type *d1 |
309 |
|
|
, CONST char *label2, CONST dim_type *d2 |
310 |
|
|
); |
311 |
|
|
|
312 |
|
|
/**< Print a message like "LABEL1='dim1', LABEL2='dim2'" */ |
313 |
|
|
|
314 |
johnpye |
1063 |
ASC_DLLSPEC void DumpDimens(FILE *f); |
315 |
jds |
54 |
/**< Dump all dimensions to a file. Used in interface */ |
316 |
aw0a |
1 |
|
317 |
johnpye |
1066 |
/* @} */ |
318 |
|
|
|
319 |
johnpye |
67 |
#endif /* ASC_DIMEN_H */ |