ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE/libBASS/RigidBodyStamp.cpp
Revision: 957
Committed: Mon Jan 19 16:08:21 2004 UTC (20 years, 7 months ago) by gezelter
File size: 3411 byte(s)
Log Message:
BASS changes to add RigidBodies and LJrcut

File Contents

# Content
1 #include <stdlib.h>
2 #include <stdio.h>
3 #include <string.h>
4 #include <iostream>
5
6 #include "RigidBodyStamp.hpp"
7
8 char RigidBodyStamp::errMsg[500];
9
10 RigidBodyStamp::RigidBodyStamp(){
11
12 unhandled = NULL;
13 have_position = 0;
14 have_orientation = 0;
15 have_name = 0;
16 have_atoms = 0;
17 have_extras = 0;
18 }
19
20 RigidBodyStamp::~RigidBodyStamp(){
21 int i;
22
23 if( unhandled != NULL ) delete unhandled;
24
25 if( atoms != NULL ){
26 for( i=0; i<n_atoms; i++ ) delete atoms[i];
27 }
28 }
29
30 void RigidBodyStamp::setPosition( double x, double y, double z ){
31
32 pos[0] = x;
33 pos[1] = y;
34 pos[2] = z;
35
36 // Do I tell atoms about this?
37
38 have_position = 1;
39 }
40
41 void RigidBodyStamp::setOrientation( double x, double y, double z ){
42
43 ornt[0] = x;
44 ornt[1] = y;
45 ornt[2] = z;
46
47 // Do I tell atoms about this?
48
49 have_orientation = 1;
50 }
51
52 char* RigidBodyStamp::assignString( char* lhs, char* rhs ){
53
54 if( !strcmp( lhs, "name" ) ){
55 strcpy( name, rhs );
56 have_name = 1;
57 }
58 else{
59 if( unhandled == NULL ) unhandled = new LinkedAssign( lhs, rhs );
60 else unhandled->add( lhs, rhs );
61 have_extras = 1;
62 }
63 return NULL;
64 }
65
66 char* RigidBodyStamp::assignDouble( char* lhs, double rhs ){
67 int i;
68
69 if( !strcmp( lhs, "nAtoms" ) ){
70 n_atoms = (int)rhs;
71
72 if( have_atoms ){
73 sprintf( errMsg,
74 "RigidBodyStamp error, n_atoms already declared"
75 "for RigidBody: %s\n",
76 name);
77 return strdup( errMsg );
78 }
79 have_atoms = 1;
80 atoms = new AtomStamp*[n_atoms];
81 for( i=0; i<n_atoms; i++ ) atoms[i] = NULL;
82 }
83 else {
84 if( unhandled == NULL ) unhandled = new LinkedAssign( lhs, rhs );
85 else unhandled->add( lhs, rhs );
86 have_extras = 1;
87 }
88 return NULL;
89 }
90
91 char* RigidBodyStamp::assignInt( char* lhs, int rhs ){
92 int i;
93
94 if( !strcmp( lhs, "nAtoms" ) ){
95 n_atoms = rhs;
96
97 if( have_atoms ){
98 sprintf( errMsg,
99 "RigidBodyStamp error, n_atoms already declared for"
100 " RigidBody: %s\n",
101 name);
102 return strdup( errMsg );
103 }
104 have_atoms = 1;
105 atoms = new AtomStamp*[n_atoms];
106 for( i=0; i<n_atoms; i++ ) atoms[i] = NULL;
107 }
108 else {
109 if( unhandled == NULL ) unhandled = new LinkedAssign( lhs, rhs );
110 else unhandled->add( lhs, rhs );
111 have_extras = 1;
112 }
113 return NULL;
114 }
115
116 char* RigidBodyStamp::addAtom( AtomStamp* the_atom, int atomIndex ){
117
118 if( have_atoms && atomIndex < n_atoms ) atoms[atomIndex] = the_atom;
119 else{
120 if( have_atoms ){
121 sprintf( errMsg, "RigidBodyStamp error, %d out of nAtoms range",
122 atomIndex );
123 return strdup( errMsg );
124 }
125 else return strdup("RigidBodyStamp error, nAtoms not given before"
126 "first atom declaration." );
127 }
128 return NULL;
129 }
130
131 char* RigidBodyStamp::checkMe( void ){
132
133 int i;
134 short int no_atom;
135
136 if( !have_name || !have_atoms ){
137 if( !have_name ) return strdup( "RigidBodyStamp error. RigidBody's name"
138 " was not given.\n" );
139 else return strdup( "RigidBodyStamp error. RigidBody contains no atoms." );
140 }
141
142 no_atom = 0;
143 for( i=0; i<n_atoms; i++ ){
144 if( atoms[i] == NULL ) no_atom = 1;
145 }
146
147 if( no_atom ){
148 sprintf( errMsg,
149 "RigidBodyStamp error. Not all of the atoms were"
150 " declared in RigidBody \"%s\".\n", name );
151 return strdup( errMsg );
152 }
153
154 return NULL;
155
156 }