ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE-2.0/src/io/make_nodes.c
Revision: 1930
Committed: Wed Jan 12 22:41:40 2005 UTC (19 years, 6 months ago) by gezelter
Content type: text/plain
File size: 10994 byte(s)
Log Message:
merging new_design branch into OOPSE-2.0

File Contents

# User Rev Content
1 gezelter 1930 /*
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 gezelter 1490 #include <stdio.h>
43     #include <stdlib.h>
44     #include <string.h>
45    
46 tim 1492 #include "io/node_list.h"
47     #include "io/make_nodes.h"
48     #include "utils/simError.h"
49 gezelter 1490
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     return the_node;
161     }
162    
163     /*
164     This function does the C & I of the constraint statements
165     */
166    
167     struct node_tag* constraint( char* list_str ){
168    
169     int nTokens;
170     char *foo;
171    
172     struct node_tag* the_node;
173     the_node = ( struct node_tag* )malloc( sizeof( node ) );
174    
175     the_node->type = CONSTRAINT_STMT;
176     the_node->index = 0;
177     the_node->next_stmt = NULL;
178     the_node->prev_stmt = NULL;
179     the_node->stmt_list = NULL;
180    
181     nTokens = count_tokens(list_str, " ,;\t");
182     if (nTokens != 1) {
183     yyerror("wrong number of arguments given in constraint statement");
184     }
185    
186     foo = strtok(list_str, " ,;\t");
187     the_node->the_data.cnstr.constraint_val = atof( foo );
188    
189     return the_node;
190     }
191    
192     /*
193     This function does the C & I for the orientation statements
194     */
195    
196     struct node_tag* orientation( char* list_str ){
197    
198     int nTokens;
199     char *foo;
200    
201     struct node_tag* the_node;
202     the_node = ( struct node_tag* )malloc( sizeof( node ) );
203    
204     the_node->type = ORIENTATION_STMT;
205     the_node->index = 0;
206     the_node->next_stmt = NULL;
207     the_node->prev_stmt = NULL;
208     the_node->stmt_list = NULL;
209    
210     nTokens = count_tokens(list_str, " ,;\t");
211     if (nTokens != 3) {
212     yyerror("wrong number of arguments given in orientation");
213     }
214    
215     foo = strtok(list_str, " ,;\t");
216     the_node->the_data.ort.phi = atof( foo );
217    
218     foo = strtok(NULL, " ,;\t");
219     the_node->the_data.ort.theta = atof( foo );
220    
221     foo = strtok(NULL, " ,;\t");
222     the_node->the_data.ort.psi = atof( foo );
223    
224     return the_node;
225     }
226    
227     /*
228     This function does the C & I for the position statements
229     */
230    
231     struct node_tag* position( char* list_str ){
232    
233     int nTokens;
234     char *foo;
235    
236     struct node_tag* the_node;
237     the_node = ( struct node_tag* )malloc( sizeof( node ) );
238    
239     the_node->type = POSITION_STMT;
240     the_node->index = 0;
241     the_node->next_stmt = NULL;
242     the_node->prev_stmt = NULL;
243     the_node->stmt_list = NULL;
244    
245     nTokens = count_tokens(list_str, " ,;\t");
246     if (nTokens != 3) {
247     yyerror("wrong number of arguments given in position");
248     }
249    
250     foo = strtok(list_str, " ,;\t");
251     the_node->the_data.pos.x = atof( foo );
252    
253     foo = strtok(NULL, " ,;\t");
254     the_node->the_data.pos.y = atof( foo );
255    
256     foo = strtok(NULL, " ,;\t");
257     the_node->the_data.pos.z = atof( foo );
258    
259    
260     return the_node;
261     }
262    
263     /*
264     The following six functions initialize the statement nodes
265     coresponding to the different code block types.
266     */
267    
268     struct node_tag* molecule_blk( struct node_tag* stmt_list ){
269    
270     struct node_tag* the_node;
271     the_node = ( struct node_tag* )malloc( sizeof( node ) );
272    
273     the_node->type = MOLECULE_HEAD;
274     the_node->index = 0;
275     the_node->next_stmt = NULL;
276     the_node->prev_stmt = NULL;
277     the_node->stmt_list = walk_to_top( stmt_list );
278    
279     return the_node;
280     }
281    
282     struct node_tag* rigidbody_blk( int index, struct node_tag* stmt_list ){
283    
284     struct node_tag* the_node;
285     the_node = ( struct node_tag* )malloc( sizeof( node ) );
286    
287     the_node->type = RIGIDBODY_HEAD;
288     the_node->index = index;
289     the_node->next_stmt = NULL;
290     the_node->prev_stmt = NULL;
291     the_node->stmt_list = walk_to_top( stmt_list );
292    
293     return the_node;
294     }
295    
296     struct node_tag* cutoffgroup_blk( int index, struct node_tag* stmt_list ){
297    
298     struct node_tag* the_node;
299     the_node = ( struct node_tag* )malloc( sizeof( node ) );
300    
301     // The guillotine statement:
302     the_node->type = CUTOFFGROUP_HEAD;
303     the_node->index = index;
304     the_node->next_stmt = NULL;
305     the_node->prev_stmt = NULL;
306     the_node->stmt_list = walk_to_top( stmt_list );
307    
308     return the_node;
309     }
310    
311     struct node_tag* atom_blk( int index, struct node_tag* stmt_list ){
312    
313     struct node_tag* the_node;
314     the_node = ( struct node_tag* )malloc( sizeof( node ) );
315    
316     the_node->type = ATOM_HEAD;
317     the_node->index = index;
318     the_node->next_stmt = NULL;
319     the_node->prev_stmt = NULL;
320     the_node->stmt_list = walk_to_top( stmt_list );
321    
322     return the_node;
323     }
324    
325     struct node_tag* bond_blk( int index, struct node_tag* stmt_list ){
326    
327     struct node_tag* the_node;
328     the_node = ( struct node_tag* )malloc( sizeof( node ) );
329    
330     the_node->type = BOND_HEAD;
331     the_node->index = index;
332     the_node->next_stmt = NULL;
333     the_node->prev_stmt = NULL;
334     the_node->stmt_list = walk_to_top( stmt_list );
335    
336     return the_node;
337     }
338    
339     struct node_tag* bend_blk( int index, struct node_tag* stmt_list ){
340    
341     struct node_tag* the_node;
342     the_node = ( struct node_tag* )malloc( sizeof( node ) );
343    
344     the_node->type = BEND_HEAD;
345     the_node->index = index;
346     the_node->next_stmt = NULL;
347     the_node->prev_stmt = NULL;
348     the_node->stmt_list = walk_to_top( stmt_list );
349    
350     return the_node;
351     }
352    
353     struct node_tag* torsion_blk( int index, struct node_tag* stmt_list ){
354    
355     struct node_tag* the_node;
356     the_node = ( struct node_tag* )malloc( sizeof( node ) );
357    
358     the_node->type = TORSION_HEAD;
359     the_node->index = index;
360     the_node->next_stmt = NULL;
361     the_node->prev_stmt = NULL;
362     the_node->stmt_list = walk_to_top( stmt_list );
363    
364     return the_node;
365     }
366    
367     struct node_tag* zconstraint_blk( int index, struct node_tag* stmt_list ){
368    
369     struct node_tag* the_node;
370     the_node = ( struct node_tag* )malloc( sizeof( node ) );
371    
372     the_node->type = ZCONSTRAINT_HEAD;
373     the_node->index = index;
374     the_node->next_stmt = NULL;
375     the_node->prev_stmt = NULL;
376     the_node->stmt_list = walk_to_top( stmt_list );
377    
378     return the_node;
379     }
380    
381     struct node_tag* component_blk( struct node_tag* stmt_list ){
382    
383     struct node_tag* the_node;
384     the_node = ( struct node_tag* )malloc( sizeof( node ) );
385    
386     the_node->type = COMPONENT_HEAD;
387     the_node->index = 0;
388     the_node->next_stmt = NULL;
389     the_node->prev_stmt = NULL;
390     the_node->stmt_list = walk_to_top( stmt_list );
391    
392     return the_node;
393     }
394    
395    
396     int count_tokens(char *line, char *delimiters) {
397     /* PURPOSE: RETURN A COUNT OF THE NUMBER OF TOKENS ON THE LINE. */
398    
399     char *working_line; /* WORKING COPY OF LINE. */
400     int ntokens; /* NUMBER OF TOKENS FOUND IN LINE. */
401     char *strtok_ptr; /* POINTER FOR STRTOK. */
402    
403     strtok_ptr= working_line= strdup(line);
404    
405     ntokens=0;
406     while (strtok(strtok_ptr,delimiters)!=NULL)
407     {
408     ntokens++;
409     strtok_ptr=NULL;
410     }
411    
412     free(working_line);
413     return(ntokens);
414     }