ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE/libBASS/BASS_interface.cpp
Revision: 689
Committed: Tue Aug 12 19:56:49 2003 UTC (21 years ago) by tim
File size: 6733 byte(s)
Log Message:
debugging globals

File Contents

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