1 | /****************************************************************************** |
---|
2 | |
---|
3 | KPP - The Kinetic PreProcessor |
---|
4 | Builds simulation code for chemical kinetic systems |
---|
5 | |
---|
6 | Copyright (C) -2020 996 Valeriu Damian and Adrian Sandu |
---|
7 | Copyright (C) -2020 005 Adrian Sandu |
---|
8 | |
---|
9 | KPP is free software; you can redistribute it and/or modify it under the |
---|
10 | terms of the GNU General Public License as published by the Free Software |
---|
11 | Foundation (http://www.gnu.org/copyleft/gpl.html); either version 2 of the |
---|
12 | License, or (at your option) any later version. |
---|
13 | |
---|
14 | KPP is distributed in the hope that it will be useful, but WITHOUT ANY |
---|
15 | WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
---|
16 | FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
---|
17 | details. |
---|
18 | |
---|
19 | You should have received a copy of the GNU General Public License along |
---|
20 | with this program; if not, consult http://www.gnu.org/copyleft/gpl.html or |
---|
21 | write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
---|
22 | Boston, MA 02111-1307, USA. |
---|
23 | |
---|
24 | Adrian Sandu |
---|
25 | Computer Science Department |
---|
26 | Virginia Polytechnic Institute and State University |
---|
27 | Blacksburg, VA 24060 |
---|
28 | E-mail: sandu@cs.vt.edu |
---|
29 | |
---|
30 | ******************************************************************************/ |
---|
31 | |
---|
32 | |
---|
33 | #ifndef _CODE_H_ |
---|
34 | #define _CODE_H_ |
---|
35 | |
---|
36 | #include <stdlib.h> |
---|
37 | #include <time.h> |
---|
38 | #include "gdef.h" |
---|
39 | |
---|
40 | #define MAX_DEPTH 10 |
---|
41 | #define MAX_SUBST 20 |
---|
42 | #define SUBST 100 |
---|
43 | #define MAX_VAR 150 |
---|
44 | #define MAX_OUTBUF 200000 |
---|
45 | #define MAX_COLS 8 |
---|
46 | #define MAX_LINES 20 |
---|
47 | |
---|
48 | #define WriteAll bprintf |
---|
49 | |
---|
50 | enum types { NONE, ADD, SUB, MUL, DIV, POW, CONST, ELM, VELM, MELM, EELM, FNC }; |
---|
51 | extern int PRI[]; |
---|
52 | |
---|
53 | enum signs { O_PAREN = 20, C_PAREN }; |
---|
54 | enum base_types { VOID, INT, REAL, DOUBLE, STRING, DOUBLESTRING }; |
---|
55 | /* mz_rs_20050117+ */ |
---|
56 | extern FILE * initFile; |
---|
57 | /* mz_rs_20050117- */ |
---|
58 | extern FILE * driverFile; |
---|
59 | extern FILE * functionFile; |
---|
60 | extern FILE * global_dataFile; |
---|
61 | extern FILE * hessianFile; |
---|
62 | extern FILE * integratorFile; |
---|
63 | extern FILE * jacobianFile; |
---|
64 | extern FILE * linalgFile; |
---|
65 | extern FILE * mapFile; |
---|
66 | extern FILE * makeFile; |
---|
67 | extern FILE * monitorFile; |
---|
68 | extern FILE * mex_funFile; |
---|
69 | extern FILE * mex_jacFile; |
---|
70 | extern FILE * mex_hessFile; |
---|
71 | extern FILE * param_headerFile; |
---|
72 | extern FILE * rateFile; |
---|
73 | extern FILE * sparse_dataFile; |
---|
74 | extern FILE * sparse_jacFile; |
---|
75 | extern FILE * sparse_hessFile; |
---|
76 | extern FILE * sparse_stoicmFile; |
---|
77 | extern FILE * stoichiomFile; |
---|
78 | extern FILE * stochasticFile; |
---|
79 | extern FILE * utilFile; |
---|
80 | |
---|
81 | extern FILE * currentFile; |
---|
82 | |
---|
83 | extern int ident; |
---|
84 | extern int real; |
---|
85 | extern char * CommonName; |
---|
86 | |
---|
87 | void OpenFile( FILE **fpp, char *name, char * ext, char * identity ); |
---|
88 | FILE * UseFile( FILE *fp ); |
---|
89 | |
---|
90 | typedef struct { |
---|
91 | char *name; |
---|
92 | int type; |
---|
93 | int baseType; |
---|
94 | int maxi; |
---|
95 | int maxj; |
---|
96 | int value; |
---|
97 | char *comment; |
---|
98 | } VARIABLE; |
---|
99 | |
---|
100 | extern VARIABLE* varTable[]; |
---|
101 | |
---|
102 | extern char *outBuf; |
---|
103 | extern char *outBuffer; |
---|
104 | |
---|
105 | void AllowBreak(); |
---|
106 | void bprintf( char *fmt, ... ); |
---|
107 | void FlushBuf(); |
---|
108 | void FlushThisBuf( char * buf ); |
---|
109 | void NewLines( int n ); |
---|
110 | void C_Inline( char *fmt, ... ); |
---|
111 | void F77_Inline( char *fmt, ... ); |
---|
112 | void IncludeFile( char * fname ); |
---|
113 | void IncludeCode( char *fmt, ... ); |
---|
114 | void MapFunctionComment( int f, int *vars ); |
---|
115 | |
---|
116 | int DefineVariable( char * name, int t, int bt, int maxi, int maxj, char * comment ); |
---|
117 | void FreeVariable( int n ); |
---|
118 | |
---|
119 | #define DefConst( name, bt, cmt ) DefineVariable( name, CONST, bt, 0, 0, cmt ) |
---|
120 | #define DefElm( name, bt, cmt ) DefineVariable( name, ELM, bt, 0, 0, cmt ) |
---|
121 | #define DefvElm( name, bt, n, cmt ) DefineVariable( name, VELM, bt, n, 0, cmt ) |
---|
122 | #define DefmElm( name, bt, m, n, cmt ) DefineVariable( name, MELM, bt, m, n, cmt ) |
---|
123 | #define DefeElm( name, cmt ) DefineVariable( name, EELM, 0, 0, 0, cmt ) |
---|
124 | #define DefFnc( name, n, cmt ) DefineVariable( name, FNC, 0, n, 0, cmt ) |
---|
125 | |
---|
126 | typedef struct { |
---|
127 | int var; |
---|
128 | union { |
---|
129 | char * expr; |
---|
130 | float cnst; |
---|
131 | struct { |
---|
132 | int i; |
---|
133 | int j; |
---|
134 | } idx; |
---|
135 | } val; |
---|
136 | } ELEMENT; |
---|
137 | |
---|
138 | typedef struct node { |
---|
139 | struct node * left; |
---|
140 | struct node * right; |
---|
141 | int type; |
---|
142 | int sign; |
---|
143 | ELEMENT *elm; |
---|
144 | } NODE; |
---|
145 | |
---|
146 | extern char *F77_types[]; |
---|
147 | extern char *F90_types[]; |
---|
148 | extern char *C_types[]; |
---|
149 | extern char *MATLAB_types[]; |
---|
150 | |
---|
151 | NODE * Elm( int v, ... ); |
---|
152 | #define Const( x ) Elm( 0, (double)x ) |
---|
153 | #define Expr( x ) Elm( 1, x ) |
---|
154 | |
---|
155 | void FreeNode( NODE * n ); |
---|
156 | |
---|
157 | NODE * Add( NODE *n1, NODE *n2 ); |
---|
158 | NODE * Sub( NODE *n1, NODE *n2 ); |
---|
159 | NODE * Mul( NODE *n1, NODE *n2 ); |
---|
160 | NODE * Div( NODE *n1, NODE *n2 ); |
---|
161 | NODE * Pow( NODE *n1, NODE *n2 ); |
---|
162 | |
---|
163 | void Assign( NODE *lval, NODE *rval ); |
---|
164 | void MkSubst( NODE *n1, NODE *n2 ); |
---|
165 | void RmSubst( NODE *n ); |
---|
166 | void CommentFncBegin( int f, int *vars ); |
---|
167 | void CommentFunctionBegin( int f, ... ); |
---|
168 | void CommentFunctionEnd( int f ); |
---|
169 | |
---|
170 | void Use_C(); |
---|
171 | void Use_F(); |
---|
172 | void Use_F90(); |
---|
173 | void Use_MATLAB(); |
---|
174 | |
---|
175 | extern void (*WriteElm)( NODE *n ); |
---|
176 | extern void (*WriteSymbol)( int op ); |
---|
177 | extern void (*WriteAssign)( char* ls, char* rs ); |
---|
178 | extern void (*WriteComment)( char *fmt, ... ); |
---|
179 | extern void (*Declare)( int v ); |
---|
180 | extern void (*ExternDeclare)( int v ); |
---|
181 | extern void (*GlobalDeclare)( int v ); |
---|
182 | extern void (*InitDeclare)( int v, int n, void * values ); |
---|
183 | extern void (*DeclareConstant)( int v, char *val ); |
---|
184 | extern void (*FunctionStart)( int f, int *vars ); |
---|
185 | extern void (*FunctionPrototipe)( int f, ... ); |
---|
186 | extern void (*FunctionBegin)( int f, ... ); |
---|
187 | extern void (*FunctionEnd)( int f ); |
---|
188 | |
---|
189 | void WriteDelim(); |
---|
190 | |
---|
191 | #endif |
---|