NEURON
model.h
Go to the documentation of this file.
1 /* /local/src/master/nrn/src/modlunit/model.h,v 1.2 1997/11/24 16:19:13 hines Exp */
2 
3 #include <stdio.h>
4 #if 1
5 #if defined(STDC_HEADERS) || defined(__TURBOC__) || defined(SYSV) || defined(VMS)
6 #include <string.h>
7 #else
8 #include <strings.h>
9 #endif
10 #endif
11 #include <assert.h>
12 
13 #define NRN_BUFSIZE 8192
14 
15 typedef struct Item {
16  short itemtype;
17  short itemsubtype;
18  void *element;/* pointer to the actual item */
19  struct Item *next;
20  struct Item *prev;
21 } Item;
22 #define ITEM0 (Item *)0
23 
24 typedef Item List; /* list of mixed items */
25 #define ITERATE(itm,lst) for (itm = (lst)->next; itm != (lst); itm = itm->next)
26 
27 /*-
28 The symbol structure gives info about tokens. Not all tokens need all
29 elements. Eg. the STRING uses only type and name. Much storage could be
30 saved and much greater clarity could be attained if each type had its own
31 sub stucture. Currently many of the structure elements serve very different
32 purposes depending on the type.
33 The following is a list of the current element usage:
34  type token number from parse1.ypp
35  subtype see definitions below
36  u.i integration method - flag for variable step
37  equation block - function number for generating variables
38  u.str scop variables - max,min,units for .var file
39  used state variable - temporary flag that it is used in an equation
40  equation block - number of state variables used (# unknowns)
41  in parout.c - the numeric order in the .var file. Generated
42  and used in parout.c for the plotlist.
43  usage a token is used as a variable (DEP) or function (FUNC)
44  Another field, EXPLICIT_DECL, is used to determine if a
45  variable appears in the input file or is automatically
46  created, thus helping to organize the .var file.
47  araydim arrays - dimension
48  discdim discrete variable - dimension
49  varnum state variable - during processing of a block containing
50  equations in which simultaneous equations result; column
51  number of state variable in the matrix.
52  level lowest submodel level number for declarations of this
53  symbol. Used for constants ( in explicit_decl()).
54  The default value is 100.
55  name token name
56 */
57 typedef struct Symbol {
58  short type;
59  long subtype;
61  union {
62  int i;
63  char *str;
64  } u;
65  int used;
66  int usage;
67  int araydim;
68  int discdim;
69  int varnum; /* column number of state variable in
70  * equations */
71  short level;
72  char *name;
73 } Symbol;
74 #define SYM0 (Symbol *)0
75 
76 /*
77  * this is convenient way to get the element pointer if you know what type
78  * the item is
79  */
80 #if DEBUG || 1
81 extern Symbol *_SYM(Item*, char*, int);
82 extern char *_STR(Item* q, char* file, int line);
83 extern Item *_ITM(Item* q, char* file, int line);
84 extern Item **_ITMA(Item* q, char* file, int line); /* array of item pointers */
85 extern List *_LST(Item* q, char* file, int line);
86 #define SYM(q) _SYM(q,(char*)__FILE__,__LINE__)
87 #define STR(q) _STR(q,(char*)__FILE__,__LINE__)
88 #define ITM(q) _ITM(q,(char*)__FILE__,__LINE__)
89 #define ITMA(q) _ITMA(q,(char*)__FILE__,__LINE__)
90 #define LST(q) _LST(q,(char*)__FILE__,__LINE__)
91 #else
92 #define SYM(q) ((Symbol *)((q)->element))
93 #define STR(q) ((char *)((q)->element))
94 #define ITM(q) ((Item *)((q)->element))
95 #define ITMA(q) ((Item **)((q)->element))
96 #define LST(q) ((List *)((q)->element))
97 #endif
98 
99 /* types not defined in parser */
100 #define SPECIAL 1
101 /* itemtype of 0 is used by list implementation */
102 #define SYMBOL 1
103 #define ITEM 2
104 #define LIST 3
105 #define ITEMARRAY 4
106 /*
107  * An item type, STRING is also used as an item type
108  * An item type, VERBATIM is also used as an item type which is to be
109  * treated the same as a STRING but with no prepended space on output.
110  */
111 
112 /* subtypes */
113 #define KEYWORD 01L
114 #define modlunitCONST 02L
115 #define INDEP 04L
116 #define DEP 010L /* also in usage field */
117 #define STAT 020L
118 #define ARRAY 040L
119 #define FUNCT 0100L /* also in usage field */
120 #define PROCED 0200L
121 #define NEGATIVE 0400L
122 #define SEMI 01L /* ";" */
123 #define BEGINBLK 02L /* "{" */
124 #define ENDBLK 04L /* "}" */
125 #define DERF 01000L
126 #define LINF 02000L
127 #define NLINF 04000L
128 #define DISCF 010000L
129 #define STEP1 020000L
130 #define PARF 040000L
131 #define EXTDEF 0100000L
132 #define KINF 0200000L
133 #define LOCL 0400000L
134 #define CNVFAC 01000000L
135 #define UFACTOR 02000000L
136 
137 #define EXPLICIT_DECL 01 /* usage field, variable occurs in input file */
138 
139 #if LINT
140 extern double *emalloc(unsigned); /* lint thinks doubles align with anything*/
141 #else
142 extern char *emalloc(unsigned); /* malloc with out of space checking */
143 #endif
144 extern char *stralloc(char*, char*); /* copies string to new space */
145 
146 extern char *inputline(), /* used only by parser to get title line */
147  *inputtopar(), /* used only by parser to get units */
148  *decode_units(Symbol*),
149  *unit_str(),
150  *Gets(char*); /* used only in io.c to get string from fin. */
151 
152 extern List
153 #if HAVE_STDARG_H || MAC
154  *makelist(int narg, ...),
155  *itemarray(int narg, ...), /* item ITEMARRAY, array of item pointers */
156 #else
157  *makelist(), /* item LIST */
158  *itemarray(), /* item ITEMARRAY, array of item pointers */
159 #endif
160  *prepend(),
161  *newlist(), /* begins new empty list */
162  *inputtext(); /* used by parser to get block text from
163  * VERBATIM and COMMENT */
164 extern Item
165  *putintoken(char *s, short type, short), /* construct symbol and store input tokens */
166  *insertstr(Item* item, char* str), /* before a known Item */
167  *insertsym(List* list, Symbol* sym),
168  *linsertstr(List* list, char* str), /* prepend to list */
169  *lappendstr(List* list, char* str), /* append to list */
170  *linsertsym(List* list, Symbol* sym),
171  *lappendsym(List* list, Symbol* sym),
172  *lappenditem(List* list, Item* item),
173  *listtype(),
174  *next_parstok(Item*),
175  *prev_parstok(Item*),
176  *car(List*),
177  *next(Item*),
178  *prev(Item*);
179 
180 
181 
182 
183 #include "modlunit.h" /* void functions */
184 
185 extern Symbol
186  *install(char*, int), /* Install token in symbol table */
187  *lookup(char*), /* lookup name in symbol table */
188  *ifnew_constinstall(); /* new .var info only if
189  * not already done. */
190 
191 extern int
192  unitonflag;
193 
194 extern char finname[], /* the input file prefix */
195  buf[]; /* general purpose temporary buffer */
196 
197 extern Item
198  *parseroot,
199  *lex_tok; /* intoken pointer for nonzero parse passes */
200 
201 extern List
202  *intoken, /* Main list of input tokens */
203  *initfunc, /* see discussion above */
204  *modelfunc,
205  *termfunc,
206  *procfunc,
207  *initlist,
208  *firstlist,
209  *plotlist,
210  *misc; /* place to stick isolated items */
211 
212 extern FILE
213  *fin, /* .mod input file descriptor */
214  *fparout, /* .var file */
215  *fcout; /* .c file */
216 
217 extern Symbol
218  *indepsym, /* The model independent variable */
219  *semi, /* ';'. When seen on output, causes newline */
220  *beginblk, /* '{'. Used for rudimentary indentation */
221  *endblk; /* on output. */
222 
223 
224 /* the following is to get lint to shut up */
225 #if LINT
226 #undef assert
227 #define assert(arg) {if (arg) ;} /* so fprintf doesn't give lint */
228 extern char *clint;
229 extern int ilint;
230 extern Item *qlint;
231 #define Sprintf clint = sprintf
232 #define Fprintf ilint = fprintf
233 #define Fclose ilint = fclose
234 #define Fflush ilint = fflush
235 #define Printf ilint = printf
236 #define Strcpy clint = strcpy
237 #define Strcat clint = strcat
238 #define Insertstr qlint = insertstr
239 #define Insertsym qlint = insertsym
240 #define Linsertsym qlint = linsertsym
241 #define Linsertstr qlint = linsertstr
242 #define Lappendsym qlint = lappendsym
243 #define Lappendstr qlint = lappendstr
244 #define Lappenditem qlint = lappenditem
245 #define IGNORE(arg) {if (arg);}
246 #define Free(arg) free((char *)(arg))
247 #else
248 #define Sprintf sprintf
249 #define Fprintf fprintf
250 #define Fclose fclose
251 #define Fflush fflush
252 #define Printf printf
253 #define Strcpy strcpy
254 #define Strcat strcat
255 #define Insertstr insertstr
256 #define Insertsym insertsym
257 #define Linsertsym linsertsym
258 #define Linsertstr linsertstr
259 #define Lappendsym lappendsym
260 #define Lappendstr lappendstr
261 #define Lappenditem lappenditem
262 #define IGNORE(arg) arg
263 #define Free(arg) free((void *)(arg))
264 #endif
265 
266 /* model.h,v
267  * Revision 1.2 1997/11/24 16:19:13 hines
268  * modlunit port to MAC (not complete)
269  *
270  * Revision 1.1.1.1 1994/10/12 17:22:45 hines
271  * NEURON 3.0 distribution
272  *
273  * Revision 1.5 1993/11/04 15:52:23 hines
274  * port to solaris2 (no more warnings)
275  *
276  * Revision 1.4 1991/08/13 10:05:08 hines
277  * to work on rs6000
278  *
279  * Revision 1.3 90/11/20 15:33:05 hines
280  * added 4 varieties of unit factors. They are
281  * name = (real)
282  * name = ((unit) -> (unit)) must be conformable
283  * name = (physical_constant)
284  * name = (physical_constant (unit)) must be conformable
285  *
286  * Revision 1.2 90/11/15 13:01:17 hines
287  * function units and number units work. accepts NEURON block
288  *
289  * Revision 1.1 90/11/13 16:12:00 hines
290  * Initial revision
291  * */
292 
Symbol * endblk
Definition: init.cpp:11
short itemsubtype
Definition: model.h:17
char * inputline()
short itemtype
Definition: model.h:16
FILE * fparout
Definition: model.cpp:33
Item * parseroot
Definition: model.cpp:39
List * initfunc
Definition: init.cpp:8
short type
Definition: cabvars.h:10
Item * _ITM(Item *q, char *file, int line)
Definition: io.cpp:198
Item * insertstr(Item *item, char *str)
List * misc
Definition: init.cpp:9
List * makelist()
int usage
Definition: model.h:66
struct Item Item
short type
Definition: model.h:58
int discdim
Definition: model.h:68
char * unit_str()
List * initlist
Definition: init.cpp:8
Item * linsertsym(List *list, Symbol *sym)
List * itemarray()
List * termfunc
Definition: init.cpp:8
List * firstlist
Definition: init.cpp:8
Item * putintoken(char *s, short type, short)
char * name
Definition: model.h:72
struct Item * prev
Definition: model.h:20
static int narg()
Definition: ivocvect.cpp:135
int unitonflag
Definition: units.cpp:44
Symbol * _SYM(Item *, char *, int)
Definition: io.cpp:184
FILE * fcout
Definition: model.cpp:33
struct Item * next
Definition: model.h:19
Item * lex_tok
Definition: passn.cpp:16
int i
Definition: model.h:62
Item * lappendsym(List *list, Symbol *sym)
List * intoken
Definition: init.cpp:12
Definition: model.h:15
Item * listtype()
Item * insertsym(List *list, Symbol *sym)
char * _STR(Item *q, char *file, int line)
Definition: io.cpp:191
Symbol * lookup(char *)
List * modelfunc
Definition: init.cpp:8
Item * car(List *)
_CONST char * s
Definition: system.cpp:74
char * inputtopar()
Item * lappendstr(List *list, char *str)
List * plotlist
Definition: init.cpp:9
char finname[]
Definition: model.cpp:38
Symbol * beginblk
Definition: init.cpp:11
FILE * fin
Definition: model.cpp:33
char * Gets(char *)
Definition: io.cpp:97
Definition: model.h:57
Symbol * install(char *, int)
struct Symbol Symbol
char buf[]
Definition: init.cpp:13
Symbol * indepsym
Definition: declare.cpp:11
void * element
Definition: model.h:18
Symbol * semi
Definition: init.cpp:11
short level
Definition: model.h:71
List * newlist()
char * emalloc(unsigned)
Definition: list.cpp:189
Item * linsertstr(List *list, char *str)
struct Symbol * sym
Definition: modl.h:102
Item * lappenditem(List *list, Item *item)
long subtype
Definition: model.h:59
Item List
Definition: model.h:24
int used
Definition: model.h:65
Item * prev_parstok(Item *)
char * str
Definition: modl.h:101
int araydim
Definition: model.h:67
Symbol * ifnew_constinstall()
static char line[MAXLINE]
Definition: ivecop.c:35
Item * next_parstok(Item *)
Item * info
Definition: model.h:60
List * procfunc
Definition: init.cpp:9
size_t q
List * _LST(Item *q, char *file, int line)
Definition: io.cpp:212
int varnum
Definition: model.h:69
char * str
Definition: model.h:63
Item ** _ITMA(Item *q, char *file, int line)
Definition: io.cpp:205
char * decode_units(Symbol *)
List * prepend()
char * stralloc(char *, char *)
Definition: list.cpp:208
List * inputtext()