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;
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 */
149  *Gets(char*); /* used only in io.c to get string from fin. */
150 
151 extern List
152 #if HAVE_STDARG_H || MAC
153  *makelist(int narg, ...),
154  *itemarray(int narg, ...), /* item ITEMARRAY, array of item pointers */
155 #else
156  *makelist(), /* item LIST */
157  *itemarray(), /* item ITEMARRAY, array of item pointers */
158 #endif
160  *newlist(), /* begins new empty list */
161  *inputtext(); /* used by parser to get block text from
162  * VERBATIM and COMMENT */
163 extern Item *putintoken(char*s, short type, short), /* construct symbol and store input tokens */
164  *insertstr(Item*item, char*str), /* before a known Item */
165  *insertsym(List*list, Symbol*sym), *linsertstr(List*list, char*str), /* prepend to list */
166  *lappendstr(List*list, char*str), /* append to list */
167  *linsertsym(List*list, Symbol*sym), *lappendsym(List*list, Symbol*sym),
169  *car(List*), *next(Item*), *prev(Item*);
170 
171 
172 #include "modlunit.h" /* void functions */
173 
174 extern Symbol *install(char*, int), /* Install token in symbol table */
175  *lookup(char*), /* lookup name in symbol table */
176  *ifnew_constinstall(); /* new .var info only if
177  * not already done. */
178 
179 extern int unitonflag;
180 
181 extern char finname[], /* the input file prefix */
182  buf[]; /* general purpose temporary buffer */
183 
184 extern Item *parseroot, *lex_tok; /* intoken pointer for nonzero parse passes */
185 
186 extern List *intoken, /* Main list of input tokens */
187  *initfunc, /* see discussion above */
189  *misc; /* place to stick isolated items */
190 
191 extern FILE *fin, /* .mod input file descriptor */
192  *fparout, /* .var file */
193  *fcout; /* .c file */
194 
195 extern Symbol *indepsym, /* The model independent variable */
196  *semi, /* ';'. When seen on output, causes newline */
197  *beginblk, /* '{'. Used for rudimentary indentation */
198  *endblk; /* on output. */
199 
200 
201 /* the following is to get lint to shut up */
202 #if LINT
203 #undef assert
204 #define assert(arg) \
205  { \
206  if (arg) \
207  ; \
208  } /* so fprintf doesn't give lint */
209 extern char* clint;
210 extern int ilint;
211 extern Item* qlint;
212 #define Sprintf clint = sprintf
213 #define Fprintf ilint = fprintf
214 #define Fclose ilint = fclose
215 #define Fflush ilint = fflush
216 #define Printf ilint = printf
217 #define Strcpy clint = strcpy
218 #define Strcat clint = strcat
219 #define Insertstr qlint = insertstr
220 #define Insertsym qlint = insertsym
221 #define Linsertsym qlint = linsertsym
222 #define Linsertstr qlint = linsertstr
223 #define Lappendsym qlint = lappendsym
224 #define Lappendstr qlint = lappendstr
225 #define Lappenditem qlint = lappenditem
226 #define IGNORE(arg) \
227  { \
228  if (arg) \
229  ; \
230  }
231 #define Free(arg) free((char*) (arg))
232 #else
233 #define Sprintf sprintf
234 #define Fprintf fprintf
235 #define Fclose fclose
236 #define Fflush fflush
237 #define Printf printf
238 #define Strcpy strcpy
239 #define Strcat strcat
240 #define Insertstr insertstr
241 #define Insertsym insertsym
242 #define Linsertsym linsertsym
243 #define Linsertstr linsertstr
244 #define Lappendsym lappendsym
245 #define Lappendstr lappendstr
246 #define Lappenditem lappenditem
247 #define IGNORE(arg) arg
248 #define Free(arg) free((void*) (arg))
249 #endif
250 
251 /* model.h,v
252  * Revision 1.2 1997/11/24 16:19:13 hines
253  * modlunit port to MAC (not complete)
254  *
255  * Revision 1.1.1.1 1994/10/12 17:22:45 hines
256  * NEURON 3.0 distribution
257  *
258  * Revision 1.5 1993/11/04 15:52:23 hines
259  * port to solaris2 (no more warnings)
260  *
261  * Revision 1.4 1991/08/13 10:05:08 hines
262  * to work on rs6000
263  *
264  * Revision 1.3 90/11/20 15:33:05 hines
265  * added 4 varieties of unit factors. They are
266  * name = (real)
267  * name = ((unit) -> (unit)) must be conformable
268  * name = (physical_constant)
269  * name = (physical_constant (unit)) must be conformable
270  *
271  * Revision 1.2 90/11/15 13:01:17 hines
272  * function units and number units work. accepts NEURON block
273  *
274  * Revision 1.1 90/11/13 16:12:00 hines
275  * Initial revision
276  * */
short type
Definition: cabvars.h:9
char * emalloc(unsigned)
Definition: list.cpp:166
char buf[]
Definition: model.h:182
Symbol * semi
Definition: model.h:196
char * stralloc(char *, char *)
Definition: list.cpp:184
static char line[MAXLINE]
Definition: ivecop.c:35
static int narg()
Definition: ivocvect.cpp:150
Item * linsertstr(List *list, char *str)
char * Gets(char *)
Definition: io.cpp:93
char * decode_units(Symbol *)
List * _LST(Item *q, char *file, int line)
Definition: io.cpp:206
List * plotlist
Definition: model.h:188
List * initfunc
Definition: model.h:187
Item * lappendsym(List *list, Symbol *sym)
Item * insertsym(List *list, Symbol *sym)
List * procfunc
Definition: model.h:188
FILE * fcout
Definition: model.h:193
Item * lappenditem(List *list, Item *item)
int unitonflag
Definition: units.cpp:45
Item List
Definition: model.h:24
Symbol * install(char *, int)
Symbol * beginblk
Definition: model.h:197
Item * _ITM(Item *q, char *file, int line)
Definition: io.cpp:192
List * firstlist
Definition: model.h:188
Item * putintoken(char *s, short type, short)
struct Item Item
List * makelist()
Item * prev(Item *)
Definition: list.cpp:93
Item * car(List *)
Item * parseroot
Definition: model.cpp:38
Symbol * lookup(char *)
char * inputline()
char * _STR(Item *q, char *file, int line)
Definition: io.cpp:185
List * initlist
Definition: model.h:188
List * misc
Definition: model.h:189
char finname[]
Definition: model.cpp:37
FILE * fparout
Definition: model.h:192
char * unit_str()
Symbol * _SYM(Item *, char *, int)
Definition: io.cpp:178
List * intoken
Definition: init.cpp:12
Item * lex_tok
Definition: model.h:184
List * termfunc
Definition: model.h:188
Item * listtype()
FILE * fin
Definition: model.cpp:32
Symbol * endblk
Definition: model.h:198
Item ** _ITMA(Item *q, char *file, int line)
Definition: io.cpp:199
Item * prev_parstok(Item *)
struct Symbol Symbol
char * inputtopar()
Item * insertstr(Item *item, char *str)
List * itemarray()
Item * next_parstok(Item *)
List * inputtext()
List * newlist()
Item * linsertsym(List *list, Symbol *sym)
Symbol * ifnew_constinstall()
List * prepend()
Symbol * indepsym
Definition: declare.cpp:11
List * modelfunc
Definition: model.h:188
Item * lappendstr(List *list, char *str)
Item * next(Item *)
size_t q
Definition: model.h:15
struct Item * prev
Definition: model.h:20
void * element
Definition: model.h:18
short itemtype
Definition: model.h:16
short itemsubtype
Definition: model.h:17
struct Item * next
Definition: model.h:19
Definition: model.h:57
int i
Definition: model.h:62
int usage
Definition: model.h:66
short type
Definition: model.h:58
short level
Definition: model.h:71
int araydim
Definition: model.h:67
long subtype
Definition: model.h:59
Item * info
Definition: model.h:60
union Symbol::@18 u
char * name
Definition: model.h:72
char * str
Definition: model.h:63
int discdim
Definition: model.h:68
int used
Definition: model.h:65
int varnum
Definition: model.h:69