/[ascend]/trunk/ascend/compiler/dimen_io.c
ViewVC logotype

Contents of /trunk/ascend/compiler/dimen_io.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2781 - (show annotations) (download) (as text)
Fri Jun 20 05:12:07 2014 UTC (3 years, 11 months ago) by jpye
File MIME type: text/x-csrc
File size: 2892 byte(s)
remove RCS comments per warnings from clang 3.4
1 /*
2 * Dimensions Output Routine
3 * by Tom Epperly
4 * Created: 2/14/90
5 * Version: $Revision: 1.8 $
6 * Version control file: $RCSfile: dimen_io.c,v $
7 * Date last modified: $Date: 1998/04/11 01:31:06 $
8 * Last modified by: $Author: ballan $
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 this program. If not, see <http://www.gnu.org/licenses/>.
26 */
27 #include <ascend/general/platform.h>
28 #include <ascend/general/ascMalloc.h>
29 #include <ascend/general/dstring.h>
30
31 #include "dimen_io.h"
32
33 static
34 void WriteFrac(FILE *f, struct fraction frac, CONST char *str, int *CONST p)
35 {
36 if (Numerator(frac)){
37 if (*p) PUTC('*',f);
38 (*p) = 1;
39 if (Denominator(frac)==1) {
40 FPRINTF(f,"%s^%d",str,Numerator(frac));
41 } else {
42 FPRINTF(f,"%s^(%d/%d)",str,Numerator(frac),Denominator(frac));
43 }
44 }
45 }
46
47 void WriteDimensions(FILE *f, CONST dim_type *dimp)
48 {
49 struct fraction frac;
50 int printed=0;
51 if (IsWild(dimp)) {
52 FPRINTF(f,"*");
53 } else {
54 int i;
55 for( i=0; i<NUM_DIMENS; i++ ) {
56 frac = GetDimFraction(*dimp,i);
57 WriteFrac(f,frac,DimName(i),&printed);
58 }
59 if (!printed) FPRINTF(f,"dimensionless");
60 }
61 }
62
63 char *WriteDimensionString(CONST dim_type *p)
64 {
65 Asc_DString ds, *dsPtr;
66 char *result;
67 int numseen = 0, i, k;
68 char expo[40];
69 if (p==NULL) {
70 return NULL;
71 }
72 if (IsWild(p)) {
73 result = ASC_NEW_ARRAY(char,2);
74 sprintf(result,"*");
75 return result;
76 }
77 dsPtr = &ds;
78 Asc_DStringInit(dsPtr);
79 for (i=0; i < NUM_DIMENS; i++) {
80 k = GetDimPower(*(p),i);
81 if (k > 0) {
82 if (numseen) {
83 Asc_DStringAppend(dsPtr,"*",1);
84 }
85 Asc_DStringAppend(dsPtr,DimName(i),-1);
86 if (k > 1) {
87 sprintf(expo,"^%d",k);
88 Asc_DStringAppend(dsPtr,expo,-1);
89 }
90 numseen = 1;
91 }
92 }
93 if (!numseen) {
94 Asc_DStringAppend(dsPtr,"1",1);
95 }
96 for (i=0; i < NUM_DIMENS; i++) {
97 k = GetDimPower(*(p),i);
98 if (k < 0) {
99 Asc_DStringAppend(dsPtr,"/",1);
100 Asc_DStringAppend(dsPtr,DimName(i),-1);
101 if (k < -1) {
102 sprintf(expo,"^%d",-k);
103 Asc_DStringAppend(dsPtr,expo,-1);
104 }
105 }
106 }
107 result = Asc_DStringResult(dsPtr);
108 return result;
109 }

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