1 |
#include <stdio.h> |
2 |
#include <stdlib.h> |
3 |
#include <string.h> |
4 |
|
5 |
#include "parse_interface.h" |
6 |
#include "BASS_interface.h" |
7 |
#include "simError.h" |
8 |
#ifdef IS_MPI |
9 |
#include "mpiBASS.h" |
10 |
#endif |
11 |
|
12 |
void interface_error( event* the_event ); |
13 |
|
14 |
void init_component( int comp_index ){ |
15 |
event* the_event; |
16 |
|
17 |
the_event = (event* )malloc( sizeof( event ) ); |
18 |
|
19 |
the_event->event_type = COMPONENT; |
20 |
the_event->err_msg = NULL; |
21 |
the_event->evt.blk_index = comp_index; |
22 |
|
23 |
if( !event_handler( the_event ) ) interface_error( the_event ); |
24 |
#ifdef IS_MPI |
25 |
throwMPIEvent(the_event); |
26 |
#endif |
27 |
|
28 |
free( the_event ); |
29 |
} |
30 |
|
31 |
void init_molecule( int mol_index ){ |
32 |
event* the_event; |
33 |
|
34 |
the_event = (event* )malloc( sizeof( event ) ); |
35 |
|
36 |
the_event->event_type = MOLECULE; |
37 |
the_event->err_msg = NULL; |
38 |
the_event->evt.blk_index = mol_index; |
39 |
|
40 |
if( !event_handler( the_event ) ) interface_error( the_event ); |
41 |
#ifdef IS_MPI |
42 |
throwMPIEvent(the_event); |
43 |
#endif |
44 |
|
45 |
free( the_event ); |
46 |
} |
47 |
|
48 |
void init_rigidbody( int rigidbody_index ){ |
49 |
event* the_event; |
50 |
|
51 |
the_event = (event* )malloc( sizeof( event ) ); |
52 |
|
53 |
the_event->event_type = RIGIDBODY; |
54 |
the_event->err_msg = NULL; |
55 |
the_event->evt.blk_index = rigidbody_index; |
56 |
|
57 |
if( !event_handler( the_event ) ) interface_error( the_event ); |
58 |
#ifdef IS_MPI |
59 |
throwMPIEvent(the_event); |
60 |
#endif |
61 |
|
62 |
free( the_event ); |
63 |
} |
64 |
|
65 |
void init_atom( int atom_index ){ |
66 |
event* the_event; |
67 |
|
68 |
the_event = (event* )malloc( sizeof( event ) ); |
69 |
|
70 |
the_event->event_type = ATOM; |
71 |
the_event->err_msg = NULL; |
72 |
the_event->evt.blk_index = atom_index; |
73 |
|
74 |
if( !event_handler( the_event ) ) interface_error( the_event ); |
75 |
#ifdef IS_MPI |
76 |
throwMPIEvent(the_event); |
77 |
#endif |
78 |
|
79 |
free( the_event ); |
80 |
} |
81 |
|
82 |
void init_bond( int bond_index ){ |
83 |
event* the_event; |
84 |
|
85 |
the_event = (event* )malloc( sizeof( event ) ); |
86 |
|
87 |
the_event->event_type = BOND; |
88 |
the_event->err_msg = NULL; |
89 |
the_event->evt.blk_index = bond_index; |
90 |
|
91 |
if( !event_handler( the_event ) ) interface_error( the_event ); |
92 |
#ifdef IS_MPI |
93 |
throwMPIEvent(the_event); |
94 |
#endif |
95 |
|
96 |
free( the_event ); |
97 |
} |
98 |
|
99 |
void init_bend( int bend_index ){ |
100 |
event* the_event; |
101 |
|
102 |
the_event = (event* )malloc( sizeof( event ) ); |
103 |
|
104 |
the_event->event_type = BEND; |
105 |
the_event->err_msg = NULL; |
106 |
the_event->evt.blk_index = bend_index; |
107 |
|
108 |
if( !event_handler( the_event ) ) interface_error( the_event ); |
109 |
#ifdef IS_MPI |
110 |
throwMPIEvent(the_event); |
111 |
#endif |
112 |
|
113 |
free( the_event ); |
114 |
} |
115 |
|
116 |
void init_torsion( int torsion_index ){ |
117 |
event* the_event; |
118 |
|
119 |
the_event = (event* )malloc( sizeof( event ) ); |
120 |
|
121 |
the_event->event_type = TORSION; |
122 |
the_event->err_msg = NULL; |
123 |
the_event->evt.blk_index = torsion_index; |
124 |
|
125 |
if( !event_handler( the_event ) ) interface_error( the_event ); |
126 |
#ifdef IS_MPI |
127 |
throwMPIEvent(the_event); |
128 |
#endif |
129 |
|
130 |
free( the_event ); |
131 |
} |
132 |
|
133 |
void init_zconstraint( int zconstraint_index ){ |
134 |
event* the_event; |
135 |
|
136 |
the_event = (event* )malloc( sizeof( event ) ); |
137 |
|
138 |
the_event->event_type = ZCONSTRAINT; |
139 |
the_event->err_msg = NULL; |
140 |
the_event->evt.blk_index = zconstraint_index; |
141 |
|
142 |
if( !event_handler( the_event ) ) interface_error( the_event ); |
143 |
#ifdef IS_MPI |
144 |
throwMPIEvent(the_event); |
145 |
#endif |
146 |
|
147 |
free( the_event ); |
148 |
} |
149 |
|
150 |
|
151 |
/* |
152 |
* the next few deal with the statement initializations |
153 |
*/ |
154 |
|
155 |
void init_members( struct node_tag* the_node, |
156 |
struct namespc the_namespc ){ |
157 |
event* the_event; |
158 |
int i; |
159 |
|
160 |
the_event = (event* )malloc( sizeof( event ) ); |
161 |
|
162 |
the_event->event_type = MEMBERS; |
163 |
the_event->err_msg = NULL; |
164 |
|
165 |
the_event->evt.mbrs.nMembers = the_node->the_data.mbrs.nMembers; |
166 |
|
167 |
the_event->evt.mbrs.memberList = (int *) calloc(the_node->the_data.mbrs.nMembers, |
168 |
sizeof(int)); |
169 |
|
170 |
for (i = 0; i < the_node->the_data.mbrs.nMembers; i++) { |
171 |
the_event->evt.mbrs.memberList[i] = the_node->the_data.mbrs.memberList[i]; |
172 |
} |
173 |
|
174 |
if( !event_handler( the_event ) ) interface_error( the_event ); |
175 |
#ifdef IS_MPI |
176 |
throwMPIEvent(the_event); |
177 |
#endif |
178 |
|
179 |
free( the_event->evt.mbrs.memberList ); |
180 |
free( the_event ); |
181 |
} |
182 |
|
183 |
void init_constraint( struct node_tag* the_node, |
184 |
struct namespc the_namespc ){ |
185 |
event* the_event; |
186 |
|
187 |
the_event = (event* )malloc( sizeof( event ) ); |
188 |
|
189 |
the_event->event_type = CONSTRAINT; |
190 |
the_event->err_msg = NULL; |
191 |
the_event->evt.cnstr = the_node->the_data.cnstr.constraint_val; |
192 |
|
193 |
if( !event_handler( the_event ) ) interface_error( the_event ); |
194 |
#ifdef IS_MPI |
195 |
throwMPIEvent(the_event); |
196 |
#endif |
197 |
|
198 |
free( the_event ); |
199 |
} |
200 |
|
201 |
void init_assignment( struct node_tag* the_node, |
202 |
struct namespc the_namespc ){ |
203 |
event* the_event; |
204 |
|
205 |
the_event = (event* )malloc( sizeof( event ) ); |
206 |
|
207 |
the_event->event_type = ASSIGNMENT; |
208 |
the_event->err_msg = NULL; |
209 |
|
210 |
strcpy( the_event->evt.asmt.lhs, the_node->the_data.asmt.identifier ); |
211 |
switch( the_node->the_data.asmt.type ){ |
212 |
|
213 |
case STR_ASSN: |
214 |
the_event->evt.asmt.asmt_type = STRING; |
215 |
strcpy( the_event->evt.asmt.rhs.sval, |
216 |
the_node->the_data.asmt.rhs.str_ptr ); |
217 |
break; |
218 |
|
219 |
case INT_ASSN: |
220 |
the_event->evt.asmt.asmt_type = INT; |
221 |
the_event->evt.asmt.rhs.ival = the_node->the_data.asmt.rhs.i_val; |
222 |
break; |
223 |
|
224 |
case DOUBLE_ASSN: |
225 |
the_event->evt.asmt.asmt_type = DOUBLE; |
226 |
the_event->evt.asmt.rhs.dval = the_node->the_data.asmt.rhs.d_val; |
227 |
break; |
228 |
} |
229 |
|
230 |
if( !event_handler( the_event ) ) interface_error( the_event ); |
231 |
#ifdef IS_MPI |
232 |
throwMPIEvent(the_event); |
233 |
#endif |
234 |
|
235 |
free( the_event ); |
236 |
} |
237 |
|
238 |
void init_position( struct node_tag* the_node, |
239 |
struct namespc the_namespc ){ |
240 |
event* the_event; |
241 |
|
242 |
the_event = (event* )malloc( sizeof( event ) ); |
243 |
|
244 |
the_event->event_type = POSITION; |
245 |
the_event->err_msg = NULL; |
246 |
the_event->evt.pos.x = the_node->the_data.pos.x; |
247 |
the_event->evt.pos.y = the_node->the_data.pos.y; |
248 |
the_event->evt.pos.z = the_node->the_data.pos.z; |
249 |
|
250 |
if( !event_handler( the_event ) ) interface_error( the_event ); |
251 |
#ifdef IS_MPI |
252 |
throwMPIEvent(the_event); |
253 |
#endif |
254 |
|
255 |
free( the_event ); |
256 |
} |
257 |
|
258 |
void init_orientation( struct node_tag* the_node, |
259 |
struct namespc the_namespc ){ |
260 |
event* the_event; |
261 |
|
262 |
the_event = (event* )malloc( sizeof( event ) ); |
263 |
|
264 |
the_event->event_type = ORIENTATION; |
265 |
the_event->err_msg = NULL; |
266 |
the_event->evt.ornt.phi = the_node->the_data.ort.phi; |
267 |
the_event->evt.ornt.theta = the_node->the_data.ort.theta; |
268 |
the_event->evt.ornt.psi = the_node->the_data.ort.psi; |
269 |
|
270 |
if( !event_handler( the_event ) ) interface_error( the_event ); |
271 |
#ifdef IS_MPI |
272 |
throwMPIEvent(the_event); |
273 |
#endif |
274 |
|
275 |
free( the_event ); |
276 |
} |
277 |
|
278 |
|
279 |
void end_of_block( void ){ |
280 |
event* the_event; |
281 |
|
282 |
the_event = (event* )malloc( sizeof( event ) ); |
283 |
|
284 |
the_event->event_type = BLOCK_END; |
285 |
the_event->err_msg = NULL; |
286 |
|
287 |
if( !event_handler( the_event ) ) interface_error( the_event ); |
288 |
#ifdef IS_MPI |
289 |
throwMPIEvent(the_event); |
290 |
#endif |
291 |
|
292 |
free( the_event ); |
293 |
} |
294 |
|
295 |
void interface_error( event* the_event ){ |
296 |
|
297 |
sprintf( painCave.errMsg, |
298 |
"**Interface event error**\n" |
299 |
"%s\n", |
300 |
the_event->err_msg ); |
301 |
painCave.isFatal = 1; |
302 |
simError(); |
303 |
#ifdef IS_MPI |
304 |
mpiInterfaceExit(); |
305 |
#endif //IS_MPI |
306 |
} |