ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE/libBASS/RigidBodyStamp.cpp
(Generate patch)

Comparing trunk/OOPSE/libBASS/RigidBodyStamp.cpp (file contents):
Revision 982 by gezelter, Mon Jan 26 21:26:40 2004 UTC vs.
Revision 998 by gezelter, Thu Jan 29 23:01:17 2004 UTC

# Line 10 | Line 10 | RigidBodyStamp::RigidBodyStamp(){
10   RigidBodyStamp::RigidBodyStamp(){
11    
12    unhandled = NULL;
13 <  have_position = 0;
14 <  have_orientation = 0;
15 <  have_atoms = 0;
13 >  have_members = 0;
14    have_extras = 0;
15 +  n_members = 0;
16 +  which = 0;
17 +
18   }
19  
20   RigidBodyStamp::~RigidBodyStamp(){
# Line 21 | Line 22 | RigidBodyStamp::~RigidBodyStamp(){
22    
23    if( unhandled != NULL ) delete unhandled;
24  
25 <  if( atoms != NULL ){
26 <    for( i=0; i<n_atoms; i++ ) delete atoms[i];
26 <  }
25 >  free(members);
26 >
27   }
28  
29 void RigidBodyStamp::setPosition( double x, double y, double z ){
30
31  pos[0] = x;
32  pos[1] = y;
33  pos[2] = z;
34
35  // Do I tell atoms about this?
36
37  have_position = 1;
38 }
39
40 void RigidBodyStamp::setOrientation( double phi, double theta, double psi ){
41
42  // in order of application (see Goldstein)
43
44  ornt[0] = phi;
45  ornt[1] = theta;
46  ornt[2] = psi;
47
48  // Do I tell atoms about this?
49
50  have_orientation = 1;
51 }
52
29   char* RigidBodyStamp::assignString( char* lhs, char* rhs ){
30  
31    if( unhandled == NULL ) unhandled = new LinkedAssign( lhs, rhs );
32    else unhandled->add( lhs, rhs );
33    have_extras = 1;
34    return NULL;
35 +
36   }
37  
38   char* RigidBodyStamp::assignDouble( char* lhs, double rhs ){
39    int i;
40  
41 <  if( !strcmp( lhs, "nAtoms" ) ){
42 <    n_atoms = (int)rhs;
43 <
44 <    if( have_atoms ){
41 >  if( !strcmp( lhs, "nMembers" ) ){
42 >    n_members = (int)rhs;
43 >    
44 >    if( have_members ){
45        sprintf( errMsg,
46 <               "RigidBodyStamp error, n_atoms already declared"
46 >               "RigidBodyStamp error, nMembers already declared"
47                 " for this RigidBody.\n");
48        return strdup( errMsg );
49      }
50 <    have_atoms = 1;
51 <    atoms = new AtomStamp*[n_atoms];
75 <    for( i=0; i<n_atoms; i++ ) atoms[i] = NULL;
50 >    have_members = 1;
51 >    members = (int *) calloc(n_members, sizeof(int));    
52    }
53    else {
54      if( unhandled == NULL ) unhandled = new LinkedAssign( lhs, rhs );
# Line 85 | Line 61 | char* RigidBodyStamp::assignInt( char* lhs, int rhs ){
61   char* RigidBodyStamp::assignInt( char* lhs, int rhs ){
62    int i;
63  
64 <  if( !strcmp( lhs, "nAtoms" ) ){
65 <    n_atoms = rhs;
64 >  if( !strcmp( lhs, "nMembers" ) ){
65 >    n_members = rhs;
66  
67 <    if( have_atoms ){
67 >    if( have_members ){
68        sprintf( errMsg,
69 <               "RigidBodyStamp error, n_atoms already declared for"
69 >               "RigidBodyStamp error, nMembers already declared for"
70                 " this RigidBody.\n");
71        return strdup( errMsg );
72      }
73 <    have_atoms = 1;
74 <    atoms = new AtomStamp*[n_atoms];
99 <    for( i=0; i<n_atoms; i++ ) atoms[i] = NULL;
73 >    have_members = 1;
74 >    members = (int *) calloc(n_members, sizeof(int));    
75    }
76    else {  
77      if( unhandled == NULL ) unhandled = new LinkedAssign( lhs, rhs );
# Line 106 | Line 81 | char* RigidBodyStamp::assignInt( char* lhs, int rhs ){
81    return NULL;
82   }
83  
84 < char* RigidBodyStamp::addAtom( AtomStamp* the_atom, int atomIndex ){
85 <  
86 <  if( have_atoms && atomIndex < n_atoms ) atoms[atomIndex] = the_atom;
87 <  else{
88 <    if( have_atoms ){
89 <      sprintf( errMsg, "RigidBodyStamp error, %d out of nAtoms range",
90 <               atomIndex );
84 > char* RigidBodyStamp::addMember( int atomIndex ){
85 >
86 >  if( have_members && which < n_members ) {
87 >    members[which] = atomIndex;
88 >    which++;
89 >  } else {
90 >    if( have_members ){
91 >      sprintf( errMsg, "RigidBodyStamp error, %d out of nMembers range",
92 >               which );
93        return strdup( errMsg );
94      }
95 <    else return strdup("RigidBodyStamp error, nAtoms not given before"
96 <                       "first atom declaration." );
95 >    else return strdup("RigidBodyStamp error, nMembers not given before"
96 >                       " member list declaration." );
97    }
98    return NULL;
99   }
# Line 124 | Line 101 | char* RigidBodyStamp::checkMe( void ){
101   char* RigidBodyStamp::checkMe( void ){
102  
103    int i;
104 <  short int no_atom;
104 >  short int no_member;
105    
106 <  if( !have_atoms ){
107 <    return strdup( "RigidBodyStamp error. RigidBody contains no atoms." );
106 >  if( !have_members ){
107 >    return strdup( "RigidBodyStamp error. RigidBody contains no members." );
108    }
109 <  
110 <  no_atom = 0;
134 <  for( i=0; i<n_atoms; i++ ){
135 <    if( atoms[i] == NULL ) no_atom = 1;
136 <  }
137 <  
138 <  if( no_atom ){
109 >
110 >  if (which < n_members) {
111      sprintf( errMsg,
112 <             "RigidBodyStamp error. Not all of the atoms were"
113 <             " declared in this RigidBody.");
112 >             "RigidBodyStamp error. Not all of the members were"
113 >             " declared for this RigidBody.");
114      return strdup( errMsg );
115    }
116    

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines