ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE/libBASS/BASS_interface.cpp
Revision: 998
Committed: Thu Jan 29 23:01:17 2004 UTC (20 years, 5 months ago) by gezelter
File size: 7239 byte(s)
Log Message:
member list fixes for rigid bodies

File Contents

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