ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE-4/src/io/make_nodes.c
Revision: 2263
Committed: Wed Jul 13 15:54:00 2005 UTC (18 years, 11 months ago) by tim
Content type: text/plain
File size: 11066 byte(s)
Log Message:
replace c++ style comment in c files

File Contents

# Content
1 /*
2 * Copyright (c) 2005 The University of Notre Dame. All Rights Reserved.
3 *
4 * The University of Notre Dame grants you ("Licensee") a
5 * non-exclusive, royalty free, license to use, modify and
6 * redistribute this software in source and binary code form, provided
7 * that the following conditions are met:
8 *
9 * 1. Acknowledgement of the program authors must be made in any
10 * publication of scientific results based in part on use of the
11 * program. An acceptable form of acknowledgement is citation of
12 * the article in which the program was described (Matthew
13 * A. Meineke, Charles F. Vardeman II, Teng Lin, Christopher
14 * J. Fennell and J. Daniel Gezelter, "OOPSE: An Object-Oriented
15 * Parallel Simulation Engine for Molecular Dynamics,"
16 * J. Comput. Chem. 26, pp. 252-271 (2005))
17 *
18 * 2. Redistributions of source code must retain the above copyright
19 * notice, this list of conditions and the following disclaimer.
20 *
21 * 3. Redistributions in binary form must reproduce the above copyright
22 * notice, this list of conditions and the following disclaimer in the
23 * documentation and/or other materials provided with the
24 * distribution.
25 *
26 * This software is provided "AS IS," without a warranty of any
27 * kind. All express or implied conditions, representations and
28 * warranties, including any implied warranty of merchantability,
29 * fitness for a particular purpose or non-infringement, are hereby
30 * excluded. The University of Notre Dame and its licensors shall not
31 * be liable for any damages suffered by licensee as a result of
32 * using, modifying or distributing the software or its
33 * derivatives. In no event will the University of Notre Dame or its
34 * licensors be liable for any lost revenue, profit or data, or for
35 * direct, indirect, special, consequential, incidental or punitive
36 * damages, however caused and regardless of the theory of liability,
37 * arising out of the use of or inability to use software, even if the
38 * University of Notre Dame has been advised of the possibility of
39 * such damages.
40 */
41
42 #include <stdio.h>
43 #include <stdlib.h>
44 #include <string.h>
45
46 #include "io/node_list.h"
47 #include "io/make_nodes.h"
48 #include "utils/simError.h"
49
50 /*
51 walks to to the top of a stmt_list. Needed when assigning the
52 statment list to a block of code.
53 */
54
55 struct node_tag* walk_to_top( struct node_tag* walk_me ){
56
57 while( walk_me->prev_stmt != NULL ){
58 walk_me = walk_me->prev_stmt;
59 }
60 return walk_me;
61 }
62
63 /*
64 the next three functions are for creating and initializing the
65 assignment statements.
66 */
67
68 struct node_tag* assign_i( char* lhs, int rhs ){
69
70 struct node_tag* the_node;
71 the_node = ( struct node_tag* )malloc( sizeof( node ) );
72
73 the_node->type = ASSIGNMENT_STMT;
74 the_node->index = 0;
75 the_node->next_stmt = NULL;
76 the_node->prev_stmt = NULL;
77 the_node->stmt_list = NULL;
78
79 the_node->the_data.asmt.type = INT_ASSN;
80 the_node->the_data.asmt.identifier = lhs;
81 the_node->the_data.asmt.rhs.i_val = rhs;
82
83 return the_node;
84 }
85
86 struct node_tag* assign_d( char* lhs, double rhs ){
87
88 struct node_tag* the_node;
89 the_node = ( struct node_tag* )malloc( sizeof( node ) );
90
91 the_node->type = ASSIGNMENT_STMT;
92 the_node->index = 0;
93 the_node->next_stmt = NULL;
94 the_node->prev_stmt = NULL;
95 the_node->stmt_list = NULL;
96
97 the_node->the_data.asmt.type = DOUBLE_ASSN;
98 the_node->the_data.asmt.identifier = lhs;
99 the_node->the_data.asmt.rhs.d_val = rhs;
100
101 return the_node;
102 }
103
104 struct node_tag* assign_s( char* lhs, char* rhs ){
105
106 struct node_tag* the_node;
107 the_node = ( struct node_tag* )malloc( sizeof( node ) );
108
109 the_node->type = ASSIGNMENT_STMT;
110 the_node->index = 0;
111 the_node->next_stmt = NULL;
112 the_node->prev_stmt = NULL;
113 the_node->stmt_list = NULL;
114
115 the_node->the_data.asmt.type = STR_ASSN;
116 the_node->the_data.asmt.identifier = lhs;
117 the_node->the_data.asmt.rhs.str_ptr = rhs;
118
119 return the_node;
120 }
121
122 /*
123 The next function deals with creating and initializing of the
124 members statements used by the bonds, bends, torsions, rigid bodies,
125 and cutoff groups.
126 */
127
128 struct node_tag* members( char* list_str ){
129
130 int nTokens, i;
131 char *foo;
132
133 struct node_tag* the_node;
134 the_node = ( struct node_tag* )malloc( sizeof( node ) );
135
136 the_node->type = MEMBERS_STMT;
137 the_node->index = 0;
138 the_node->next_stmt = NULL;
139 the_node->prev_stmt = NULL;
140 the_node->stmt_list = NULL;
141
142 nTokens = count_tokens(list_str, " ,;\t");
143
144 if (nTokens < 1) {
145 yyerror("can't find any members in this members statement");
146 }
147
148 the_node->the_data.mbrs.nMembers = nTokens;
149
150 the_node->the_data.mbrs.memberList = (int *) calloc(nTokens, sizeof(int));
151
152 foo = strtok(list_str, " ,;\t");
153 the_node->the_data.mbrs.memberList[0] = atoi( foo );
154
155 for (i = 1; i < nTokens; i++) {
156 foo = strtok(NULL, " ,;\t");
157 the_node->the_data.mbrs.memberList[i] = atoi( foo );
158 }
159
160 free(list_str);
161 return the_node;
162 }
163
164 /*
165 This function does the C & I of the constraint statements
166 */
167
168 struct node_tag* constraint( char* list_str ){
169
170 int nTokens;
171 char *foo;
172
173 struct node_tag* the_node;
174 the_node = ( struct node_tag* )malloc( sizeof( node ) );
175
176 the_node->type = CONSTRAINT_STMT;
177 the_node->index = 0;
178 the_node->next_stmt = NULL;
179 the_node->prev_stmt = NULL;
180 the_node->stmt_list = NULL;
181
182 nTokens = count_tokens(list_str, " ,;\t");
183 if (nTokens != 1) {
184 yyerror("wrong number of arguments given in constraint statement");
185 }
186
187 foo = strtok(list_str, " ,;\t");
188 the_node->the_data.cnstr.constraint_val = atof( foo );
189
190 free(list_str);
191 return the_node;
192 }
193
194 /*
195 This function does the C & I for the orientation statements
196 */
197
198 struct node_tag* orientation( char* list_str ){
199
200 int nTokens;
201 char *foo;
202
203 struct node_tag* the_node;
204 the_node = ( struct node_tag* )malloc( sizeof( node ) );
205
206 the_node->type = ORIENTATION_STMT;
207 the_node->index = 0;
208 the_node->next_stmt = NULL;
209 the_node->prev_stmt = NULL;
210 the_node->stmt_list = NULL;
211
212 nTokens = count_tokens(list_str, " ,;\t");
213 if (nTokens != 3) {
214 yyerror("wrong number of arguments given in orientation");
215 }
216
217 foo = strtok(list_str, " ,;\t");
218 the_node->the_data.ort.phi = atof( foo );
219
220 foo = strtok(NULL, " ,;\t");
221 the_node->the_data.ort.theta = atof( foo );
222
223 foo = strtok(NULL, " ,;\t");
224 the_node->the_data.ort.psi = atof( foo );
225
226 free(list_str);
227 return the_node;
228 }
229
230 /*
231 This function does the C & I for the position statements
232 */
233
234 struct node_tag* position( char* list_str ){
235
236 int nTokens;
237 char *foo;
238
239 struct node_tag* the_node;
240 the_node = ( struct node_tag* )malloc( sizeof( node ) );
241
242 the_node->type = POSITION_STMT;
243 the_node->index = 0;
244 the_node->next_stmt = NULL;
245 the_node->prev_stmt = NULL;
246 the_node->stmt_list = NULL;
247
248 nTokens = count_tokens(list_str, " ,;\t");
249 if (nTokens != 3) {
250 yyerror("wrong number of arguments given in position");
251 }
252
253 foo = strtok(list_str, " ,;\t");
254 the_node->the_data.pos.x = atof( foo );
255
256 foo = strtok(NULL, " ,;\t");
257 the_node->the_data.pos.y = atof( foo );
258
259 foo = strtok(NULL, " ,;\t");
260 the_node->the_data.pos.z = atof( foo );
261
262 free(list_str);
263 return the_node;
264 }
265
266 /*
267 The following six functions initialize the statement nodes
268 coresponding to the different code block types.
269 */
270
271 struct node_tag* molecule_blk( struct node_tag* stmt_list ){
272
273 struct node_tag* the_node;
274 the_node = ( struct node_tag* )malloc( sizeof( node ) );
275
276 the_node->type = MOLECULE_HEAD;
277 the_node->index = 0;
278 the_node->next_stmt = NULL;
279 the_node->prev_stmt = NULL;
280 the_node->stmt_list = walk_to_top( stmt_list );
281
282 return the_node;
283 }
284
285 struct node_tag* rigidbody_blk( int index, struct node_tag* stmt_list ){
286
287 struct node_tag* the_node;
288 the_node = ( struct node_tag* )malloc( sizeof( node ) );
289
290 the_node->type = RIGIDBODY_HEAD;
291 the_node->index = index;
292 the_node->next_stmt = NULL;
293 the_node->prev_stmt = NULL;
294 the_node->stmt_list = walk_to_top( stmt_list );
295
296 return the_node;
297 }
298
299 struct node_tag* cutoffgroup_blk( int index, struct node_tag* stmt_list ){
300
301 struct node_tag* the_node;
302 the_node = ( struct node_tag* )malloc( sizeof( node ) );
303
304 /* The guillotine statement:*/
305 the_node->type = CUTOFFGROUP_HEAD;
306 the_node->index = index;
307 the_node->next_stmt = NULL;
308 the_node->prev_stmt = NULL;
309 the_node->stmt_list = walk_to_top( stmt_list );
310
311 return the_node;
312 }
313
314 struct node_tag* atom_blk( int index, struct node_tag* stmt_list ){
315
316 struct node_tag* the_node;
317 the_node = ( struct node_tag* )malloc( sizeof( node ) );
318
319 the_node->type = ATOM_HEAD;
320 the_node->index = index;
321 the_node->next_stmt = NULL;
322 the_node->prev_stmt = NULL;
323 the_node->stmt_list = walk_to_top( stmt_list );
324
325 return the_node;
326 }
327
328 struct node_tag* bond_blk( int index, struct node_tag* stmt_list ){
329
330 struct node_tag* the_node;
331 the_node = ( struct node_tag* )malloc( sizeof( node ) );
332
333 the_node->type = BOND_HEAD;
334 the_node->index = index;
335 the_node->next_stmt = NULL;
336 the_node->prev_stmt = NULL;
337 the_node->stmt_list = walk_to_top( stmt_list );
338
339 return the_node;
340 }
341
342 struct node_tag* bend_blk( int index, struct node_tag* stmt_list ){
343
344 struct node_tag* the_node;
345 the_node = ( struct node_tag* )malloc( sizeof( node ) );
346
347 the_node->type = BEND_HEAD;
348 the_node->index = index;
349 the_node->next_stmt = NULL;
350 the_node->prev_stmt = NULL;
351 the_node->stmt_list = walk_to_top( stmt_list );
352
353 return the_node;
354 }
355
356 struct node_tag* torsion_blk( int index, struct node_tag* stmt_list ){
357
358 struct node_tag* the_node;
359 the_node = ( struct node_tag* )malloc( sizeof( node ) );
360
361 the_node->type = TORSION_HEAD;
362 the_node->index = index;
363 the_node->next_stmt = NULL;
364 the_node->prev_stmt = NULL;
365 the_node->stmt_list = walk_to_top( stmt_list );
366
367 return the_node;
368 }
369
370 struct node_tag* zconstraint_blk( int index, struct node_tag* stmt_list ){
371
372 struct node_tag* the_node;
373 the_node = ( struct node_tag* )malloc( sizeof( node ) );
374
375 the_node->type = ZCONSTRAINT_HEAD;
376 the_node->index = index;
377 the_node->next_stmt = NULL;
378 the_node->prev_stmt = NULL;
379 the_node->stmt_list = walk_to_top( stmt_list );
380
381 return the_node;
382 }
383
384 struct node_tag* component_blk( struct node_tag* stmt_list ){
385
386 struct node_tag* the_node;
387 the_node = ( struct node_tag* )malloc( sizeof( node ) );
388
389 the_node->type = COMPONENT_HEAD;
390 the_node->index = 0;
391 the_node->next_stmt = NULL;
392 the_node->prev_stmt = NULL;
393 the_node->stmt_list = walk_to_top( stmt_list );
394
395 return the_node;
396 }
397
398
399 int count_tokens(char *line, char *delimiters) {
400 /* PURPOSE: RETURN A COUNT OF THE NUMBER OF TOKENS ON THE LINE. */
401
402 char *working_line; /* WORKING COPY OF LINE. */
403 int ntokens; /* NUMBER OF TOKENS FOUND IN LINE. */
404 char *strtok_ptr; /* POINTER FOR STRTOK. */
405
406 strtok_ptr= working_line= strdup(line);
407
408 ntokens=0;
409 while (strtok(strtok_ptr,delimiters)!=NULL)
410 {
411 ntokens++;
412 strtok_ptr=NULL;
413 }
414
415 free(working_line);
416 return(ntokens);
417 }