/[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 1063 - (show annotations) (download) (as text)
Sun Jan 7 07:54:06 2007 UTC (17 years, 9 months ago) by johnpye
File MIME type: text/x-chdr
File size: 9988 byte(s)
Changed ASC_DLLSPEC(TYPE) to ASC_DLLSPEC TYPE, because it was causing havoc with doxygen and ctags.
1 /* ASCEND modelling environment
2 Copyright (C) 1990, 1993, 1994 Thomas Guthrie Epperly
3 Copyright (C) 2006 Carnegie Mellon University
4
5 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
10 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 #ifndef ASC_DIMEN_H
32 #define ASC_DIMEN_H
33
34 #include <utilities/ascConfig.h>
35 #include "fractions.h"
36 #include "compiler.h"
37
38
39 /* Keep these defines current with DimNames in dimen.h. */
40 #define NUM_DIMENS 10 /**< Number of dimension types. */
41 #define D_MASS 0 /**< Index for mass dimension. */
42 #define D_QUANTITY 1 /**< Index for quantity dimension. */
43 #define D_LENGTH 2 /**< Index for length dimension. */
44 #define D_TIME 3 /**< Index for time dimension. */
45 #define D_TEMPERATURE 4 /**< Index for temperature dimension. */
46 #define D_CURRENCY 5 /**< Index for currency dimension. */
47 #define D_ELECTRIC_CURRENT 6 /**< Index for electric current dimension. */
48 #define D_LUMINOUS_INTENSITY 7 /**< Index for luminous intensity dimension. */
49 #define D_PLANE_ANGLE 8 /**< Index for plane angle dimension. */
50 #define D_SOLID_ANGLE 9 /**< Index for solid angle dimension. */
51
52 /** Dimension data structure. */
53 struct DimStruct {
54 struct fraction f[NUM_DIMENS]; /**< Array of fractions, one for each dimension type. */
55 unsigned int wild; /**< Wild flag. Only valid values are 0 and DIM_WILD */
56 };
57 #define DIM_WILD 0x1
58 /**< Code for a wild dimension. */
59
60 /** Dimension typedef for general use */
61 typedef struct DimStruct dim_type;
62
63 ASC_DLLSPEC struct gl_list_t *g_dimen_list;
64 /**<
65 * Global list of dimension data structures. All persistent dim pointers
66 * should resolve to something pointed at in this list to minimize dim
67 * overhead.
68 */
69
70 extern void InitDimenList(void);
71 /**<
72 * Initialize the dimension list.
73 * Must be called once and only once before any other dimension calls.
74 */
75
76 extern void DestroyDimenList(void);
77 /**<
78 * This can be called to deallocate all of the allocated dimensions.
79 */
80
81 #define GetDimFraction(d,i) ((d).f[i])
82 /**<
83 * Returns a fraction struct from a dim_type.
84 * i should be one of
85 * - D_MASS
86 * - D_QUANTITY
87 * - D_LENGTH
88 * - D_TIME
89 * - D_TEMPERATURE
90 * - D_CURRENCY
91 * - D_ELECTRIC_CURRENT
92 * - D_LUMINOUS_INTENSITY
93 * - D_PLANE_ANGLE
94 * - D_SOLID_ANGLE
95 */
96
97 #define GetDimPower(d,i) \
98 (int)(Denominator((d).f[i])==1 ? Numerator((d).f[i]) : 0)
99 /**<
100 * Returns an int value of the numerator, or 0 if the
101 * denominator != 1.
102 */
103
104 #define SetDimFraction(d,i,frac) ( (d).f[(i)] = (frac) )
105 /**<
106 * Set fraction i in dim_type d to frac.
107 */
108
109 ASC_DLLSPEC void ClearDimensions(dim_type *d);
110 /**<
111 * Initialize all the dimension fractions to zero.
112 */
113
114 ASC_DLLSPEC CONST dim_type*Dimensionless(void);
115 /**<
116 * Return a pointer to the dimensionless structure.
117 */
118
119 ASC_DLLSPEC CONST dim_type *TrigDimension(void);
120 /**<
121 * Return a pointer to the dimension structure for plane angle.
122 */
123
124 ASC_DLLSPEC CONST dim_type *WildDimension(void);
125 /**<
126 * Return a pointer to a wild dimension structure. You don't need to
127 * call FindOrAddDimen with this dimension.
128 */
129
130 extern CONST dim_type *HalfDimension(CONST dim_type *d, int b);
131 /**<
132 * Return a pointer to a dimension structure with sqrt dimensionality.
133 * Returns null if sqrt dimensionality is fractional when tested (b true).
134 * If not b, result may point to noninteger dim. Dim will be in global list.
135 */
136
137 extern CONST dim_type *ThirdDimension(CONST dim_type *d, int b);
138 /**<
139 * Return a pointer to a dimension structure with cbrt dimensionality.
140 * Returns null if cbrt dimensionality is fractional when tested (b true).
141 * If !b, result may point to noninteger dim. Dim will be in global list.
142 */
143
144 extern CONST dim_type *SquareDimension(CONST dim_type *d, int b);
145 /**<
146 * Return a pointer to a dimension structure with square dimensionality.
147 * Returns null if square dimensionality is fractional when tested (b true).
148 * If not b, result may point to noninteger dim. Dim will be in global list.
149 */
150
151 extern CONST dim_type *CubeDimension(CONST dim_type *d, int b);
152 /**<
153 * Return a pointer to a dimension structure with cube dimensionality.
154 * Returns null if cube dimensionality is fractional when tested (b true).
155 * If !b, result may point to noninteger dim. Dim will be in global list.
156 */
157
158 extern CONST dim_type *PowDimension(long mult, CONST dim_type *d, int b);
159 /**<
160 * Return a pointer to a dimension structure with d*mult dimensionality.
161 * Returns null if cube dimensionality is fractional when tested (b true)
162 * or if mult*d yields integer overflow of the dimensionality.
163 * If !b, result may point to noninteger dim. Dim will be in global list.
164 */
165
166 extern void SetWild(dim_type *dim);
167 /**<
168 * Set the wild flag of dimensions dim.
169 */
170
171 ASC_DLLSPEC int IsWild(CONST dim_type *d);
172 /**<
173 * Return a true value if d is wild, and otherwise return a false value.
174 */
175
176 extern int OddDimension(CONST dim_type *d);
177 /**<
178 * Return a true value if d has an odd, wild, or non-integer dimension.
179 */
180
181 extern int NonCubicDimension(CONST dim_type *d);
182 /**<
183 * Return a true value if d has an noncubic, wild, or non-integer dimension.
184 */
185
186 extern int SameDimen(CONST dim_type *d1, CONST dim_type *d2);
187 /**<
188 * Return 1 if d1 and d2 have the same dimensional value, or 0
189 * otherwise. Two wild dimensions are the same, regardless of any
190 * other data they may contain.
191 * Wild and any non-wild are NOT the same.
192 */
193
194 ASC_DLLSPEC int CmpDimen(CONST dim_type *d1, CONST dim_type *d2);
195 /**<
196 * Return 1,0,-1 if d1 is >,=, or < d2 respectively.
197 */
198
199 ASC_DLLSPEC CONST dim_type *FindOrAddDimen(CONST dim_type *d);
200 /**<
201 * This function is run to make sure only one copy of each dimensions
202 * is stored. It is designed to be called as follows:
203 * <pre>
204 * Example:
205 * dim_type d,*p;
206 * ClearDimensions(&d);
207 * SetDimFraction(d,D_MASS,CreateFraction(1,2));
208 * ...etc...
209 * p = FindOrAddDimen(&d);
210 * p will never point to d. p != &d.
211 * </pre>
212 */
213
214 ASC_DLLSPEC void CopyDimensions(CONST dim_type *src, dim_type *dest);
215 /**<
216 * Copy from src to dest.
217 */
218
219 ASC_DLLSPEC dim_type AddDimensions(CONST dim_type *d1, CONST dim_type *d2);
220 /**<
221 * Add 2 dimensions.
222 * Wild+anything equals wild.
223 * return d1+d2;
224 * NOTE: This returns a dim by value, not by pointer. There are places
225 * where this is desirable. Where you want a pointer from the dim
226 * table instead, use SumDimensions.
227 */
228
229 extern CONST dim_type *SumDimensions(CONST dim_type *d1, CONST dim_type *d2, int check);
230 /**<
231 * Add 2 dimensions with checking.
232 * Wild+anything equals wild.
233 * return d1+d2;
234 * If check != 0, verifies that d1 and d2 are not fractional, returning
235 * NULL if fractional found.
236 * Result will be in global list.
237 */
238
239 ASC_DLLSPEC dim_type SubDimensions(CONST dim_type *d1, CONST dim_type *d2);
240 /**<
241 * Subtract 2 dimensions.
242 * Wild-anything equals wild.
243 * return d1-d2;
244 * NOTE: This returns a dim by value, not by pointer. There are places
245 * where this is desirable. Where you want a pointer from the dim
246 * table instead, use DiffDimensions.
247 */
248
249 extern CONST dim_type *DiffDimensions(CONST dim_type *d1, CONST dim_type *d2, int check);
250 /**<
251 * Subtract 2 dimensions with checking.
252 * Wild-anything equals wild.
253 * return d1-d2;
254 * If check != 0, verifies that d1 and d2 are not fractional, returning
255 * NULL if fractional found.
256 * Result will be in global list.
257 */
258
259 ASC_DLLSPEC dim_type ScaleDimensions(CONST dim_type *dim, struct fraction frac);
260 /**<
261 * Scale the dimensions by frac. A wild scaled always remains wild.
262 */
263
264 ASC_DLLSPEC void ParseDim(dim_type *dim, CONST char *c);
265 /**<
266 * Initialize dim appropriately according to the string c. If c doesn't
267 * match any of the dimension strings, dim will be dimensionless and
268 * an error message will be printed.
269 * <pre>
270 * String Dimension Index
271 * "M" D_MASS
272 * "Q" D_QUANTITY
273 * "T" D_TIME
274 * "L" D_LENGTH
275 * "TMP" D_TEMPERATURE
276 * "C" D_CURRENCY
277 * "E" D_ELECTRIC_CURRENT
278 * "LUM" D_LUMINOUS_INTENSITY
279 * "P" D_PLANE_ANGLE
280 * "S" D_SOLID_ANGLE
281 * </pre>
282 */
283
284 ASC_DLLSPEC char *DimName(CONST int nIndex);
285 /**<
286 * Return the internal copy of the name of the dimension corresponding
287 * to index if index is within [0..NUM_DIMENS-1], otherwise return NULL.
288 */
289
290 extern CONST dim_type *CheckDimensionsMatch(CONST dim_type *d1, CONST dim_type *d2);
291 /**<
292 * Compare 2 dimensions.
293 * - Return d1 if d2 is wild
294 * - Return d2 if d1 is wild or d1 == d2
295 * - Return d1 if *d1 == *d2
296 * - Otherwise return NULL
297 */
298
299 ASC_DLLSPEC void PrintDimen(FILE *f ,CONST dim_type *d);
300 /**< Print a dimension to a file. Used in interface */
301
302
303 ASC_DLLSPEC void PrintDimenMessage(CONST char *message
304 , CONST char *label1, CONST dim_type *d1
305 , CONST char *label2, CONST dim_type *d2
306 );
307
308 /**< Print a message like "LABEL1='dim1', LABEL2='dim2'" */
309
310 ASC_DLLSPEC void DumpDimens(FILE *f);
311 /**< Dump all dimensions to a file. Used in interface */
312
313 #endif /* ASC_DIMEN_H */

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