ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE/libBASS/BASS_interface.cpp
Revision: 828
Committed: Tue Oct 28 16:03:06 2003 UTC (20 years, 8 months ago) by gezelter
File size: 6577 byte(s)
Log Message:
replace c++ header stuff with more portable c header stuff
Also, mod file fixes and portability changes

File Contents

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