ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE/libBASS/MakeStamps.cpp
Revision: 747
Committed: Fri Sep 5 21:28:52 2003 UTC (20 years, 10 months ago) by gezelter
File size: 10017 byte(s)
Log Message:
Changes to autoconf / configure method of configuring OOPSE

File Contents

# User Rev Content
1 mmeineke 377 #include <cstdlib>
2     #include <cstdio>
3    
4     #include "MakeStamps.hpp"
5     #include "MoleculeStamp.hpp"
6     #include "simError.h"
7     #ifdef IS_MPI
8     #include "mpiBASS.h"
9     #endif // is_mpi
10    
11     LinkedMolStamp::~LinkedMolStamp(){
12     if( mol_stamp != NULL ) delete mol_stamp;
13     if( next != NULL ) delete next;
14     }
15    
16     void LinkedMolStamp::add( LinkedMolStamp* newbie ){
17    
18     if( next != NULL ) next->add( newbie );
19     else{
20     next = newbie;
21     next->setPrev( this );
22     }
23     }
24    
25     MoleculeStamp* LinkedMolStamp::match( char* id ){
26    
27     if( mol_stamp != NULL ){
28     if(!strcmp( mol_stamp->getID(), id )){
29    
30     // make sure we aren't hiding somebody else with the same name
31     if(next != NULL ){
32     if( next->match( id ) != NULL){
33     sprintf( painCave.errMsg,
34     "Molecule Stamp Error. Two separate of declarations of "
35     "%s present.\n",
36     id );
37     painCave.isFatal = 1;
38     simError();
39     #ifdef IS_MPI
40     if( painCave.isEventLoop ){
41     if( worldRank == 0 ) mpiInterfaceExit();
42     }
43     #endif //is_mpi
44     }
45     else return mol_stamp;
46     }
47     else return mol_stamp;
48     }
49     }
50    
51     if( next != NULL ) return next->match( id );
52    
53     return NULL;
54     }
55    
56     LinkedMolStamp* LinkedMolStamp::extract( char* id ){
57    
58     if( mol_stamp != NULL ){
59     if(!strcmp( mol_stamp->getID(), id )){
60    
61     // make sure we aren't hiding somebody else with the same name
62     if(next != NULL ){
63     if( next->match( id ) != NULL){
64     sprintf( painCave.errMsg,
65     "Molecule Stamp Error. Two separate of declarations of "
66     "%s present.\n",
67     id );
68     painCave.isFatal = 1;
69     simError();
70     #ifdef IS_MPI
71     if( painCave.isEventLoop ){
72     if( worldRank == 0 ) mpiInterfaceExit();
73     }
74     #endif //is_mpi
75     }
76     }
77    
78     prev->setNext( next );
79     if( next != NULL ) next->setPrev( prev );
80     return this;
81     }
82     }
83    
84     if( next != NULL ) return next->extract( id );
85    
86     return NULL;
87     }
88    
89     MakeStamps::MakeStamps(){
90    
91     int i;
92 gezelter 747
93     hash_size = 47;
94     hash_shift = 4;
95 mmeineke 377
96     my_mols = new LinkedMolStamp*[hash_size];
97     for( i=0; i<hash_size; i++ ){
98     my_mols[i] = new LinkedMolStamp();
99     }
100    
101     }
102    
103     MakeStamps::~MakeStamps(){
104    
105     int i;
106    
107     for( i=0; i<hash_size; i++ ){
108     if( my_mols[i] != NULL ) delete my_mols[i];
109     }
110     delete[] my_mols;
111     }
112    
113     int MakeStamps::hash( char* text ){
114    
115     register unsigned short int i = 0; // loop counter
116     int key = 0; // the hash key
117    
118     while( text[i] != '\0' ){
119    
120     key = ( ( key << hash_shift ) + text[i] ) % hash_size;
121    
122     i++;
123     }
124    
125     if( key < 0 ){
126    
127     // if the key is less than zero, we've had an overflow error
128    
129     sprintf( painCave.errMsg,
130     "There has been an overflow error in the MakeStamps hash key.");
131     painCave.isFatal = 1;
132     simError();
133     #ifdef IS_MPI
134     if( painCave.isEventLoop ){
135     if( worldRank == 0 ) mpiInterfaceExit();
136     }
137     #endif //is_mpi
138     }
139    
140     return key;
141     }
142    
143     LinkedMolStamp* MakeStamps::extractMolStamp( char* the_id ){
144     int key;
145    
146     key = hash( the_id );
147     if( my_mols[key] != NULL ){
148     return my_mols[key]->extract( the_id );
149     }
150    
151     return NULL;
152     }
153    
154     void MakeStamps::addMolStamp( MoleculeStamp* the_stamp ){
155    
156     int key;
157     LinkedMolStamp* linked_mol;
158    
159     key = hash( the_stamp->getID() );
160    
161     linked_mol = new LinkedMolStamp;
162     linked_mol->setStamp( the_stamp );
163    
164     my_mols[key]->add( linked_mol );
165    
166     }
167    
168    
169     int MakeStamps::newMolecule( event* the_event ){
170    
171     current_mol = new MoleculeStamp;
172     return 1;
173     }
174    
175     int MakeStamps::moleculeAssign( event* the_event ){
176    
177     switch( the_event->evt.asmt.asmt_type ){
178    
179     case STRING:
180     the_event->err_msg = current_mol->assignString( the_event->evt.asmt.lhs,
181     the_event->evt.asmt.rhs.sval );
182     break;
183    
184     case DOUBLE:
185     the_event->err_msg = current_mol->assignDouble( the_event->evt.asmt.lhs,
186     the_event->evt.asmt.rhs.dval );
187     break;
188    
189     case INT:
190     the_event->err_msg = current_mol->assignInt( the_event->evt.asmt.lhs,
191     the_event->evt.asmt.rhs.ival );
192     break;
193    
194     default:
195     the_event->err_msg = strdup( "MakeStamp error. Invalid molecule"
196     " assignment type" );
197     return 0;
198     break;
199     }
200     if( the_event->err_msg != NULL ) return 0;
201     return 1;
202     }
203    
204     int MakeStamps::moleculeEnd( event* the_event ){
205    
206     the_event->err_msg = current_mol->checkMe();
207     // if err_msg is set, then something is wrong
208     if( the_event->err_msg != NULL ) return 0;
209    
210     addMolStamp( current_mol );
211     return 1;
212     }
213    
214     int MakeStamps::newAtom( event* the_event ){
215    
216     current_atom = new AtomStamp;
217    
218     the_event->err_msg = current_mol->addAtom( current_atom,
219     the_event->evt.blk_index );
220     if( the_event->err_msg != NULL ) return 0;
221     return 1;
222     }
223    
224     int MakeStamps::atomPosition( event* the_event ){
225    
226     current_atom->setPosition( the_event->evt.pos.x,
227     the_event->evt.pos.y,
228     the_event->evt.pos.z );
229     return 1;
230     }
231    
232    
233     int MakeStamps::atomOrientation( event* the_event ){
234    
235     current_atom->setOrientation( the_event->evt.ornt.x,
236     the_event->evt.ornt.y,
237     the_event->evt.ornt.z );
238     return 1;
239     }
240    
241     int MakeStamps::atomAssign( event* the_event ){
242    
243     switch( the_event->evt.asmt.asmt_type ){
244    
245     case STRING:
246     the_event->err_msg =
247     current_atom->assignString( the_event->evt.asmt.lhs,
248     the_event->evt.asmt.rhs.sval );
249     if( the_event->err_msg != NULL ) return 0;
250     return 1;
251     break;
252    
253     case DOUBLE:
254     the_event->err_msg =
255     current_atom->assignDouble( the_event->evt.asmt.lhs,
256     the_event->evt.asmt.rhs.dval );
257     if( the_event->err_msg != NULL ) return 0;
258     return 1;
259     break;
260    
261     case INT:
262     the_event->err_msg =
263     current_atom->assignInt( the_event->evt.asmt.lhs,
264     the_event->evt.asmt.rhs.ival );
265     if( the_event->err_msg != NULL ) return 0;
266     return 1;
267     break;
268    
269     default:
270     the_event->err_msg = strdup( "MakeStamp error. Invalid atom"
271     " assignment type" );
272     return 0;
273     break;
274     }
275     return 0;
276     }
277    
278     int MakeStamps::atomEnd( event* the_event ){
279    
280     the_event->err_msg = current_atom->checkMe();
281     if( the_event->err_msg != NULL ) return 0;
282    
283     return 1;
284     }
285    
286     int MakeStamps::newBond( event* the_event ){
287    
288     current_bond = new BondStamp;
289    
290     the_event->err_msg = current_mol->addBond( current_bond,
291     the_event->evt.blk_index );
292     if( the_event->err_msg != NULL ) return 0;
293    
294     return 1;
295     }
296    
297     int MakeStamps::bondAssign( event* the_event ){
298    
299     switch( the_event->evt.asmt.asmt_type ){
300    
301     case STRING:
302     current_bond->assignString( the_event->evt.asmt.lhs,
303     the_event->evt.asmt.rhs.sval );
304     return 1;
305     break;
306    
307     case DOUBLE:
308     current_bond->assignDouble( the_event->evt.asmt.lhs,
309     the_event->evt.asmt.rhs.dval );
310     return 1;
311     break;
312    
313     case INT:
314     current_bond->assignInt( the_event->evt.asmt.lhs,
315     the_event->evt.asmt.rhs.ival );
316     return 1;
317     break;
318    
319     default:
320     the_event->err_msg = strdup( "MakeStamp error. Invalid bond"
321     " assignment type" );
322     return 0;
323     break;
324     }
325     return 0;
326     }
327    
328     int MakeStamps::bondMember( event* the_event ){
329    
330     current_bond->members( the_event->evt.mbr.a,
331     the_event->evt.mbr.b );
332     return 1;
333     }
334    
335     int MakeStamps::bondConstraint( event* the_event ){
336    
337     current_bond->constrain( the_event->evt.cnstr );
338     return 1;
339     }
340    
341     int MakeStamps::bondEnd( event* the_event ){
342    
343     the_event->err_msg = current_bond->checkMe();
344     if( the_event->err_msg != NULL ) return 0;
345    
346     return 1;
347     }
348    
349     int MakeStamps::newBend( event* the_event ){
350    
351     current_bend = new BendStamp;
352    
353     the_event->err_msg = current_mol->addBend( current_bend,
354     the_event->evt.blk_index );
355     if( the_event->err_msg != NULL ) return 0;
356    
357     return 1;
358     }
359    
360     int MakeStamps::bendAssign( event* the_event ){
361    
362     switch( the_event->evt.asmt.asmt_type ){
363    
364     case STRING:
365     current_bend->assignString( the_event->evt.asmt.lhs,
366     the_event->evt.asmt.rhs.sval );
367     return 1;
368     break;
369    
370     case DOUBLE:
371     current_bend->assignDouble( the_event->evt.asmt.lhs,
372     the_event->evt.asmt.rhs.dval );
373     return 1;
374     break;
375    
376     case INT:
377     current_bend->assignInt( the_event->evt.asmt.lhs,
378     the_event->evt.asmt.rhs.ival );
379     return 1;
380     break;
381    
382     default:
383     the_event->err_msg = strdup( "MakeStamp error. Invalid bend"
384     " assignment type" );
385     return 0;
386     break;
387     }
388     return 0;
389     }
390    
391     int MakeStamps::bendMember( event* the_event ){
392    
393     current_bend->members( the_event->evt.mbr.a,
394     the_event->evt.mbr.b,
395     the_event->evt.mbr.c );
396     return 1;
397     }
398    
399     int MakeStamps::bendConstraint( event* the_event ){
400    
401     current_bend->constrain( the_event->evt.cnstr );
402     return 1;
403     }
404    
405     int MakeStamps::bendEnd( event* the_event ){
406    
407     the_event->err_msg = current_bend->checkMe();
408     if( the_event->err_msg != NULL ) return 0;
409    
410     return 1;
411     }
412    
413     int MakeStamps::newTorsion( event* the_event ){
414    
415     current_torsion = new TorsionStamp;
416    
417     the_event->err_msg = current_mol->addTorsion( current_torsion,
418     the_event->evt.blk_index );
419     if( the_event->err_msg != NULL ) return 0;
420    
421     return 1;
422     }
423    
424     int MakeStamps::torsionAssign( event* the_event ){
425    
426     switch( the_event->evt.asmt.asmt_type ){
427    
428     case STRING:
429     current_torsion->assignString( the_event->evt.asmt.lhs,
430     the_event->evt.asmt.rhs.sval );
431     return 1;
432     break;
433    
434     case DOUBLE:
435     current_torsion->assignDouble( the_event->evt.asmt.lhs,
436     the_event->evt.asmt.rhs.dval );
437     return 1;
438     break;
439    
440     case INT:
441     current_torsion->assignInt( the_event->evt.asmt.lhs,
442     the_event->evt.asmt.rhs.ival );
443     return 1;
444     break;
445    
446     default:
447     the_event->err_msg = strdup( "MakeStamp error. Invalid torsion"
448     " assignment type" );
449     return 0;
450     break;
451     }
452     return 0;
453     }
454    
455     int MakeStamps::torsionMember( event* the_event ){
456    
457     current_torsion->members( the_event->evt.mbr.a,
458     the_event->evt.mbr.b,
459     the_event->evt.mbr.c,
460     the_event->evt.mbr.d );
461     return 1;
462     }
463    
464     int MakeStamps::torsionConstraint( event* the_event ){
465    
466     current_torsion->constrain( the_event->evt.cnstr );
467     return 1;
468     }
469    
470     int MakeStamps::torsionEnd( event* the_event ){
471    
472     the_event->err_msg = current_torsion->checkMe();
473     if( the_event->err_msg != NULL ) return 0;
474    
475     return 1;
476     }