1 |
chuckv |
134 |
|
2 |
mmeineke |
10 |
#include <cstring> |
3 |
|
|
#include <cstdio> |
4 |
|
|
#include <cstdlib> |
5 |
|
|
|
6 |
|
|
#include "SimSetup.hpp" |
7 |
|
|
#include "Globals.hpp" |
8 |
|
|
#include "BASS_interface.h" |
9 |
|
|
|
10 |
chuckv |
131 |
#ifdef IS_MPI |
11 |
chuckv |
139 |
#include "mpiBASS.h" |
12 |
chuckv |
131 |
#endif |
13 |
mmeineke |
10 |
|
14 |
|
|
|
15 |
|
|
// Globals ************************************************ |
16 |
|
|
|
17 |
|
|
typedef enum { GLOBAL_BLK, MOLECULE_BLK, ATOM_BLK, BOND_BLK, BEND_BLK, |
18 |
|
|
TORSION_BLK, COMPONENT_BLK } block_type; |
19 |
|
|
|
20 |
|
|
block_type current_block = GLOBAL_BLK; |
21 |
|
|
#define MAX_NEST 20 // the max number of nested blocks |
22 |
|
|
block_type block_stack[MAX_NEST]; |
23 |
|
|
int block_stack_ptr = 0; |
24 |
|
|
|
25 |
|
|
void incr_block( block_type new_block ); |
26 |
|
|
void decr_block(); |
27 |
|
|
|
28 |
|
|
MakeStamps *the_stamps; |
29 |
|
|
Globals *the_globals; |
30 |
|
|
|
31 |
|
|
// Functions ********************************************** |
32 |
|
|
|
33 |
|
|
/* |
34 |
|
|
* This is the main event handler |
35 |
|
|
* |
36 |
|
|
* returns 1 if the event was handled. If the event isn't handled, the |
37 |
|
|
* event's err_msg is set, and 0 is returned |
38 |
|
|
*/ |
39 |
|
|
|
40 |
|
|
int event_handler( event* the_event ){ |
41 |
|
|
|
42 |
|
|
int handled = 0; |
43 |
|
|
|
44 |
|
|
switch( current_block ){ |
45 |
|
|
|
46 |
|
|
case GLOBAL_BLK: |
47 |
|
|
switch( the_event->event_type ){ |
48 |
|
|
|
49 |
|
|
case MOLECULE: |
50 |
|
|
incr_block( MOLECULE_BLK ); |
51 |
|
|
handled = the_stamps->newMolecule( the_event ); |
52 |
|
|
break; |
53 |
|
|
|
54 |
|
|
case COMPONENT: |
55 |
|
|
incr_block( COMPONENT_BLK ); |
56 |
|
|
handled = the_globals->newComponent( the_event ); |
57 |
|
|
break; |
58 |
|
|
|
59 |
|
|
case ASSIGNMENT: |
60 |
|
|
handled = the_globals->globalAssign( the_event ); |
61 |
|
|
break; |
62 |
|
|
|
63 |
|
|
case BLOCK_END: |
64 |
|
|
handled = the_globals->globalEnd( the_event ); |
65 |
|
|
break; |
66 |
|
|
|
67 |
|
|
default: |
68 |
|
|
the_event->err_msg = |
69 |
|
|
strdup("Not a valid global event\n" ); |
70 |
|
|
return 0; |
71 |
|
|
} |
72 |
|
|
break; |
73 |
|
|
|
74 |
|
|
case MOLECULE_BLK: |
75 |
|
|
|
76 |
|
|
switch( the_event->event_type ){ |
77 |
|
|
|
78 |
|
|
case ATOM: |
79 |
|
|
incr_block( ATOM_BLK ); |
80 |
|
|
handled = the_stamps->newAtom( the_event ); |
81 |
|
|
break; |
82 |
|
|
|
83 |
|
|
case BOND: |
84 |
|
|
incr_block( BOND_BLK ); |
85 |
|
|
handled = the_stamps->newBond( the_event ); |
86 |
|
|
break; |
87 |
|
|
|
88 |
|
|
case BEND: |
89 |
|
|
incr_block( BEND_BLK ); |
90 |
|
|
handled = the_stamps->newBend( the_event ); |
91 |
|
|
break; |
92 |
|
|
|
93 |
|
|
case TORSION: |
94 |
|
|
incr_block( TORSION_BLK ); |
95 |
|
|
handled = the_stamps->newTorsion( the_event ); |
96 |
|
|
break; |
97 |
|
|
|
98 |
|
|
case ASSIGNMENT: |
99 |
|
|
handled = the_stamps->moleculeAssign( the_event ); |
100 |
|
|
break; |
101 |
|
|
|
102 |
|
|
case BLOCK_END: |
103 |
|
|
decr_block(); |
104 |
|
|
handled = the_stamps->moleculeEnd( the_event ); |
105 |
|
|
break; |
106 |
|
|
|
107 |
|
|
default: |
108 |
|
|
the_event->err_msg = |
109 |
|
|
strdup( "Not a valid molecule event\n" ); |
110 |
|
|
return 0; |
111 |
|
|
} |
112 |
|
|
break; |
113 |
|
|
|
114 |
|
|
case ATOM_BLK: |
115 |
|
|
|
116 |
|
|
switch( the_event->event_type ){ |
117 |
|
|
|
118 |
|
|
case POSITION: |
119 |
|
|
handled = the_stamps->atomPosition( the_event ); |
120 |
|
|
break; |
121 |
|
|
|
122 |
|
|
case ORIENTATION: |
123 |
|
|
handled = the_stamps->atomOrientation( the_event ); |
124 |
|
|
break; |
125 |
|
|
|
126 |
|
|
case ASSIGNMENT: |
127 |
|
|
handled = the_stamps->atomAssign( the_event ); |
128 |
|
|
break; |
129 |
|
|
|
130 |
|
|
case BLOCK_END: |
131 |
|
|
decr_block(); |
132 |
|
|
handled = the_stamps->atomEnd( the_event ); |
133 |
|
|
break; |
134 |
|
|
|
135 |
|
|
default: |
136 |
|
|
the_event->err_msg = |
137 |
|
|
strdup( "Not a valid atom event\n" ); |
138 |
|
|
return 0; |
139 |
|
|
} |
140 |
|
|
break; |
141 |
|
|
|
142 |
|
|
case BOND_BLK: |
143 |
|
|
|
144 |
|
|
switch( the_event->event_type ){ |
145 |
|
|
|
146 |
|
|
case ASSIGNMENT: |
147 |
|
|
handled = the_stamps->bondAssign( the_event ); |
148 |
|
|
break; |
149 |
|
|
|
150 |
|
|
case MEMBER: |
151 |
|
|
handled = the_stamps->bondMember( the_event ); |
152 |
|
|
break; |
153 |
|
|
|
154 |
|
|
case CONSTRAINT: |
155 |
|
|
handled = the_stamps->bondConstraint( the_event ); |
156 |
|
|
break; |
157 |
|
|
|
158 |
|
|
case BLOCK_END: |
159 |
|
|
decr_block(); |
160 |
|
|
handled = the_stamps->bondEnd(the_event ); |
161 |
|
|
break; |
162 |
|
|
|
163 |
|
|
default: |
164 |
|
|
the_event->err_msg = |
165 |
|
|
strdup( "not a valid bond event\n" ); |
166 |
|
|
return 0; |
167 |
|
|
} |
168 |
|
|
break; |
169 |
|
|
|
170 |
|
|
case BEND_BLK: |
171 |
|
|
|
172 |
|
|
switch( the_event->event_type ){ |
173 |
|
|
|
174 |
|
|
case ASSIGNMENT: |
175 |
|
|
handled = the_stamps->bendAssign( the_event ); |
176 |
|
|
break; |
177 |
|
|
|
178 |
|
|
case MEMBER: |
179 |
|
|
handled = the_stamps->bendMember( the_event ); |
180 |
|
|
break; |
181 |
|
|
|
182 |
|
|
case CONSTRAINT: |
183 |
|
|
handled = the_stamps->bendConstraint( the_event ); |
184 |
|
|
break; |
185 |
|
|
|
186 |
|
|
case BLOCK_END: |
187 |
|
|
decr_block(); |
188 |
|
|
handled = the_stamps->bendEnd(the_event ); |
189 |
|
|
break; |
190 |
|
|
|
191 |
|
|
default: |
192 |
|
|
the_event->err_msg = |
193 |
|
|
strdup( "not a valid bend event\n" ); |
194 |
|
|
return 0; |
195 |
|
|
} |
196 |
|
|
break; |
197 |
|
|
|
198 |
|
|
case TORSION_BLK: |
199 |
|
|
|
200 |
|
|
switch( the_event->event_type ){ |
201 |
|
|
|
202 |
|
|
case ASSIGNMENT: |
203 |
|
|
handled = the_stamps->torsionAssign( the_event ); |
204 |
|
|
break; |
205 |
|
|
|
206 |
|
|
case MEMBER: |
207 |
|
|
handled = the_stamps->torsionMember( the_event ); |
208 |
|
|
break; |
209 |
|
|
|
210 |
|
|
case CONSTRAINT: |
211 |
|
|
handled = the_stamps->torsionConstraint( the_event ); |
212 |
|
|
break; |
213 |
|
|
|
214 |
|
|
case BLOCK_END: |
215 |
|
|
decr_block(); |
216 |
|
|
handled = the_stamps->torsionEnd(the_event ); |
217 |
|
|
break; |
218 |
|
|
|
219 |
|
|
default: |
220 |
|
|
the_event->err_msg = |
221 |
|
|
strdup( "not a valid torsion event\n" ); |
222 |
|
|
return 0; |
223 |
|
|
} |
224 |
|
|
break; |
225 |
|
|
|
226 |
|
|
case COMPONENT_BLK: |
227 |
|
|
|
228 |
|
|
switch( the_event->event_type ){ |
229 |
|
|
|
230 |
|
|
case ASSIGNMENT: |
231 |
|
|
handled = the_globals->componentAssign( the_event ); |
232 |
|
|
break; |
233 |
|
|
|
234 |
|
|
case START_INDEX: |
235 |
|
|
handled = the_globals->componentStartIndex( the_event ); |
236 |
|
|
break; |
237 |
|
|
|
238 |
|
|
case BLOCK_END: |
239 |
|
|
decr_block(); |
240 |
|
|
handled = the_globals->componentEnd(the_event ); |
241 |
|
|
break; |
242 |
|
|
|
243 |
|
|
default: |
244 |
|
|
the_event->err_msg = |
245 |
|
|
strdup( "not a valid component event\n" ); |
246 |
|
|
return 0; |
247 |
|
|
} |
248 |
|
|
break; |
249 |
|
|
|
250 |
|
|
default: |
251 |
|
|
the_event->err_msg = |
252 |
|
|
strdup( "event is not in a valid block type\n" ); |
253 |
|
|
return 0; |
254 |
|
|
} |
255 |
|
|
|
256 |
|
|
return handled; |
257 |
|
|
} |
258 |
|
|
|
259 |
|
|
void incr_block( block_type new_block ){ |
260 |
|
|
|
261 |
|
|
block_stack[block_stack_ptr] = current_block; |
262 |
|
|
block_stack_ptr++; |
263 |
|
|
|
264 |
|
|
if( block_stack_ptr >= MAX_NEST ){ |
265 |
|
|
fprintf( stderr, "Event blocks nested too deeply\n" ); |
266 |
chuckv |
131 |
#ifdef IS_MPI |
267 |
chuckv |
118 |
mpiInterfaceExit(); |
268 |
|
|
#endif |
269 |
mmeineke |
10 |
exit(1); |
270 |
|
|
} |
271 |
|
|
|
272 |
|
|
else current_block = new_block; |
273 |
|
|
} |
274 |
|
|
|
275 |
|
|
|
276 |
|
|
void decr_block( void ){ |
277 |
|
|
|
278 |
|
|
block_stack_ptr--; |
279 |
|
|
|
280 |
|
|
if( block_stack_ptr < 0 ){ |
281 |
|
|
|
282 |
|
|
fprintf( stderr, "Too many event blocks closed\n" ); |
283 |
chuckv |
131 |
#ifdef IS_MPI |
284 |
chuckv |
118 |
mpiInterfaceExit(); |
285 |
|
|
#endif |
286 |
mmeineke |
10 |
exit(1); |
287 |
|
|
} |
288 |
|
|
|
289 |
|
|
else current_block = block_stack[block_stack_ptr]; |
290 |
|
|
} |
291 |
|
|
|
292 |
|
|
void set_interface_stamps( MakeStamps* ms, Globals* g ){ |
293 |
|
|
|
294 |
|
|
the_stamps = ms; |
295 |
|
|
the_globals = g; |
296 |
|
|
} |