1 /******************************************************************************
3 KPP - The Kinetic PreProcessor
4 Builds simulation code for chemical kinetic systems
6 Copyright (C) 1995-1996 Valeriu Damian and Adrian Sandu
7 Copyright (C) 1997-2005 Adrian Sandu
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.
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
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.
25 Computer Science Department
26 Virginia Polytechnic Institute and State University
28 E-mail: sandu@cs.vt.edu
30 ******************************************************************************/
43 #define MAX_OUTBUF 200000
47 #define WriteAll bprintf
49 enum types
{ NONE
, ADD
, SUB
, MUL
, DIV
, POW
, CONST
, ELM
, VELM
, MELM
, EELM
, FNC
};
52 enum signs
{ O_PAREN
= 20, C_PAREN
};
53 enum base_types
{ VOID
, INT
, REAL
, DOUBLE
, STRING
, DOUBLESTRING
};
55 extern FILE * initFile
;
57 extern FILE * driverFile
;
58 extern FILE * functionFile
;
59 extern FILE * global_dataFile
;
60 extern FILE * hessianFile
;
61 extern FILE * integratorFile
;
62 extern FILE * jacobianFile
;
63 extern FILE * linalgFile
;
64 extern FILE * mapFile
;
65 extern FILE * makeFile
;
66 extern FILE * monitorFile
;
67 extern FILE * mex_funFile
;
68 extern FILE * mex_jacFile
;
69 extern FILE * mex_hessFile
;
70 extern FILE * param_headerFile
;
71 extern FILE * rateFile
;
72 extern FILE * sparse_dataFile
;
73 extern FILE * sparse_jacFile
;
74 extern FILE * sparse_hessFile
;
75 extern FILE * sparse_stoicmFile
;
76 extern FILE * stoichiomFile
;
77 extern FILE * stochasticFile
;
78 extern FILE * utilFile
;
80 extern FILE * currentFile
;
84 extern char * CommonName
;
86 void OpenFile( FILE **fpp
, char *name
, char * ext
, char * identity
);
87 FILE * UseFile( FILE *fp
);
99 extern VARIABLE
* varTable
[];
102 extern char *outBuffer
;
105 void bprintf( char *fmt
, ... );
107 void FlushThisBuf( char * buf
);
108 void NewLines( int n
);
109 void C_Inline( char *fmt
, ... );
110 void F77_Inline( char *fmt
, ... );
111 void IncludeFile( char * fname
);
112 void IncludeCode( char *fmt
, ... );
113 void MapFunctionComment( int f
, int *vars
);
115 int DefineVariable( char * name
, int t
, int bt
, int maxi
, int maxj
, char * comment
);
116 void FreeVariable( int n
);
118 #define DefConst( name, bt, cmt ) DefineVariable( name, CONST, bt, 0, 0, cmt )
119 #define DefElm( name, bt, cmt ) DefineVariable( name, ELM, bt, 0, 0, cmt )
120 #define DefvElm( name, bt, n, cmt ) DefineVariable( name, VELM, bt, n, 0, cmt )
121 #define DefmElm( name, bt, m, n, cmt ) DefineVariable( name, MELM, bt, m, n, cmt )
122 #define DefeElm( name, cmt ) DefineVariable( name, EELM, 0, 0, 0, cmt )
123 #define DefFnc( name, n, cmt ) DefineVariable( name, FNC, 0, n, 0, cmt )
137 typedef struct node
{
145 extern char *F77_types
[];
146 extern char *F90_types
[];
147 extern char *C_types
[];
148 extern char *MATLAB_types
[];
150 NODE
* Elm( int v
, ... );
151 #define Const( x ) Elm( 0, (double)x )
152 #define Expr( x ) Elm( 1, x )
154 void FreeNode( NODE
* n
);
156 NODE
* Add( NODE
*n1
, NODE
*n2
);
157 NODE
* Sub( NODE
*n1
, NODE
*n2
);
158 NODE
* Mul( NODE
*n1
, NODE
*n2
);
159 NODE
* Div( NODE
*n1
, NODE
*n2
);
160 NODE
* Pow( NODE
*n1
, NODE
*n2
);
162 void Assign( NODE
*lval
, NODE
*rval
);
163 void MkSubst( NODE
*n1
, NODE
*n2
);
164 void RmSubst( NODE
*n
);
165 void CommentFncBegin( int f
, int *vars
);
166 void CommentFunctionBegin( int f
, ... );
167 void CommentFunctionEnd( int f
);
174 extern void (*WriteElm
)( NODE
*n
);
175 extern void (*WriteSymbol
)( int op
);
176 extern void (*WriteAssign
)( char* ls
, char* rs
);
177 extern void (*WriteComment
)( char *fmt
, ... );
178 extern void (*Declare
)( int v
);
179 extern void (*ExternDeclare
)( int v
);
180 extern void (*GlobalDeclare
)( int v
);
181 extern void (*InitDeclare
)( int v
, int n
, void * values
);
182 extern void (*DeclareConstant
)( int v
, char *val
);
183 extern void (*FunctionStart
)( int f
, int *vars
);
184 extern void (*FunctionPrototipe
)( int f
, ... );
185 extern void (*FunctionBegin
)( int f
, ... );
186 extern void (*FunctionEnd
)( int f
);