ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/mdtools/interface_implementation/BASS_interface.cpp
Revision: 164
Committed: Tue Nov 5 22:04:46 2002 UTC (21 years, 7 months ago) by mmeineke
File size: 6150 byte(s)
Log Message:
*** empty log message ***

File Contents

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