ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE-2.0/src/io/ShapeAtomTypesSectionParser.cpp
(Generate patch)

Comparing trunk/OOPSE-2.0/src/io/ShapeAtomTypesSectionParser.cpp (file contents):
Revision 2209 by chrisfen, Mon Apr 18 03:50:23 2005 UTC vs.
Revision 2211 by chrisfen, Thu Apr 21 14:12:19 2005 UTC

# Line 40 | Line 40
40   */
41  
42   #include "UseTheForce/ForceField.hpp"
43 #include "io/basic_ifstrstream.hpp"
43   #include "io/ShapeAtomTypesSectionParser.hpp"
44   #include "math/RealSphericalHarmonic.hpp"
45   #include "math/SquareMatrix3.hpp"
# Line 52 | Line 51 | namespace oopse {
51  
52   namespace oopse {
53    
54 <  ShapeAtomTypesSectionParser::ShapesAtomTypesSectionParser() {
55 <    setSectionName("ShapesAtomTypes");
54 >  ShapeAtomTypesSectionParser::ShapeAtomTypesSectionParser() {
55 >    setSectionName("ShapeAtomTypes");
56    }
57    
58    void ShapeAtomTypesSectionParser::parseLine(ForceField& ff,
59                                                const std::string& line,
60                                                int lineNo){
61      StringTokenizer tokenizer(line);
62 <    
62 >      
63      if (tokenizer.countTokens() >= 2) {
64        std::string shapeTypeName = tokenizer.nextToken();
65        std::string shapeFile = tokenizer.nextToken();
66 <      
66 >      
67        AtomType* atomType = ff.getAtomType(shapeTypeName);
68 <      
69 <      if (atomType != NULL){
70 <        DirectionalAtomType* dAtomType =
71 <        dynamic_cast<DirectionalAtomType*>(atomType);
72 <        
73 <        if (dAtomType != NULL) {
74 <          ShapeAtomType* sAtomType = dynamic_cast<ShapeAtomType*>(dAtomType);
75 <          
76 <          sAtomType->setShape();  
77 <          parseShapesFile(ff, shapeFile, sAtomType);                                                    
78 <        } else {
79 <          sprintf(painCave.errMsg,
81 <                  "ShapesAtomTypesSectionParser Error: "
82 <                  "Can't find ShapeAtomType [%s]\n",
83 <                  atomTypeName.c_str());
68 >      ShapeAtomType* sAtomType;
69 >      if (atomType == NULL){
70 >        sAtomType = new ShapeAtomType();
71 >        int ident = ff.getNAtomType() + 1;
72 >        sAtomType->setIdent(ident);
73 >        sAtomType->setName(shapeTypeName);
74 >        ff.addAtomType(shapeTypeName, sAtomType);
75 >      } else {
76 >        sAtomType = dynamic_cast<ShapeAtomType*>(atomType);
77 >        if (sAtomType == NULL) {
78 >          sprintf(painCave.errMsg,
79 >                  "ShapeAtomTypesSectionParser:: Can't cast to ShapeAtomType");
80            painCave.severity = OOPSE_ERROR;
81            painCave.isFatal = 1;
82 <          simError();  
82 >          simError();
83          }
88      } else {
89        sprintf(painCave.errMsg,
90                "ShapesAtomTypesSectionParser Error: "
91                "Can't find ShapeAtomType [%s]\n",
92                atomTypeName.c_str());
93        painCave.severity = OOPSE_ERROR;
94        painCave.isFatal = 1;
95        simError();  
84        }
85 +      
86 +      sAtomType->setShape();  
87 +      parseShapeFile(ff, shapeFile, sAtomType);                                                    
88 +  
89      } else {
90        sprintf(painCave.errMsg,
91                "ShapesAtomTypesSectionParser Error: "
# Line 106 | Line 98 | namespace oopse {
98    }
99    
100    void ShapeAtomTypesSectionParser::parseShapeFile(ForceField& ff,
101 <                                                   string shapeFileName,
101 >                                                   std::string& shapeFileName,
102                                                     ShapeAtomType* st) {
103      
112    ifstrstream* shapeStream = ff.openForceFieldFile(shapeFileName);
104      const int bufferSize = 65535;
105      char buffer[bufferSize];
106 <    char *token;
106 >    std::string token;
107      std::string line;
108      int junk;
109      Mat3x3d momInert;
110      RealSphericalHarmonic* rsh;
111      std::vector<RealSphericalHarmonic*> functionVector;
112 +    ifstrstream shapeStream;
113 +    std::string tempString;
114 +    std::string ffPath;
115 +    char* tempPath;
116      
117 +    tempPath = getenv("FORCE_PARAM_PATH");
118 +    
119 +    if (tempPath == NULL) {
120 +      //convert a macro from compiler to a string in c++
121 +      STR_DEFINE(ffPath, FRC_PATH );
122 +    } else {
123 +      ffPath = tempPath;
124 +    }
125 +    
126 +    shapeStream.open( shapeFileName.c_str() );
127 +    
128 +    if( shapeStream == NULL ){
129 +      
130 +      tempString = ffPath;
131 +      tempString += "/";
132 +      tempString += shapeFileName;
133 +      shapeFileName = tempString;
134 +      
135 +      shapeStream.open( shapeFileName.c_str() );
136 +      
137 +      if( shapeStream == NULL ){
138 +        
139 +        sprintf( painCave.errMsg,
140 +                 "Error opening the shape file:\n"
141 +                 "\t%s\n"
142 +                 "\tHave you tried setting the FORCE_PARAM_PATH environment "
143 +                 "variable?\n",
144 +                 shapeFileName.c_str() );
145 +        painCave.severity = OOPSE_ERROR;
146 +        painCave.isFatal = 1;
147 +        simError();
148 +      }
149 +    }
150 +    
151 +    
152      // first parse the info. in the ShapeInfo section
153      findBegin( shapeStream, "ShapeInfo");
154 <    shapeStream->getline(buffer, bufferSize);
154 >    shapeStream.getline(buffer, bufferSize);
155      
156      // loop over the interior of the ShapeInfo section
157      while( !shapeStream.eof() ) {
# Line 144 | Line 174 | namespace oopse {
174              junk = tokenInfo.nextTokenAsInt();
175              st->setMass( tokenInfo.nextTokenAsDouble() );
176              momInert(0,0) = tokenInfo.nextTokenAsDouble();
177 <            momInert(1,1) = tokenInfo.nextTokenAsDouble()
178 <            momInert(2,2) = tokenInfo.nextTokenAsDouble()
177 >            momInert(1,1) = tokenInfo.nextTokenAsDouble();
178 >            momInert(2,2) = tokenInfo.nextTokenAsDouble();
179              st->setI(momInert);
180            }
181          }
182        }
183 <      shapeStream->getline(buffer, bufferSize);
183 >      shapeStream.getline(buffer, bufferSize);
184      }
185      
186      // now grab the contact functions
187      findBegin(shapeStream, "ContactFunctions");
188      functionVector.clear();
189      
190 <    shapeStream->getline(buffer, bufferSize);
190 >    shapeStream.getline(buffer, bufferSize);
191      while( !shapeStream.eof() ) {
192        // toss comment lines
193        if( buffer[0] != '!' && buffer[0] != '#' ){
# Line 179 | Line 209 | namespace oopse {
209              rsh = new RealSphericalHarmonic();
210              rsh->setL( tokenInfo1.nextTokenAsInt() );
211              rsh->setM( tokenInfo1.nextTokenAsInt() );
212 <            token = tokenInfo1.nextTokenAsChar();
213 <            if (!strcasecmp("sin",token))
212 >            token = tokenInfo1.nextToken();
213 >            transform(token.begin(), token.end(), token.begin(), tolower);
214 >            if (token == "sin")
215                rsh->makeSinFunction();
216              else
217                rsh->makeCosFunction();
# Line 200 | Line 231 | namespace oopse {
231      findBegin(shapeStream, "RangeFunctions");
232      functionVector.clear();
233      
234 <    shapeStream->getline(buffer, bufferSize);
234 >    shapeStream.getline(buffer, bufferSize);
235      while( !shapeStream.eof() ) {
236        // toss comment lines
237        if( buffer[0] != '!' && buffer[0] != '#' ){
# Line 222 | Line 253 | namespace oopse {
253              rsh = new RealSphericalHarmonic();
254              rsh->setL( tokenInfo2.nextTokenAsInt() );
255              rsh->setM( tokenInfo2.nextTokenAsInt() );
256 <            token = tokenInfo2.nextTokenAsChar();
257 <            if (!strcasecmp("sin",token))
256 >            token = tokenInfo2.nextToken();
257 >            transform(token.begin(), token.end(), token.begin(), tolower);
258 >            if (token == "sin")
259                rsh->makeSinFunction();
260              else
261                rsh->makeCosFunction();
# Line 243 | Line 275 | namespace oopse {
275      findBegin(shapeStream, "StrengthFunctions");
276      functionVector.clear();
277      
278 <    shapeStream->getline(buffer, bufferSize);
278 >    shapeStream.getline(buffer, bufferSize);
279      while( !shapeStream.eof() ) {
280        // toss comment lines
281        if( buffer[0] != '!' && buffer[0] != '#' ){
# Line 265 | Line 297 | namespace oopse {
297              rsh = new RealSphericalHarmonic();
298              rsh->setL( tokenInfo3.nextTokenAsInt() );
299              rsh->setM( tokenInfo3.nextTokenAsInt() );
300 <            token = tokenInfo3.nextTokenAsChar();
301 <            if (!strcasecmp("sin",token))
300 >            token = tokenInfo3.nextToken();
301 >            transform(token.begin(), token.end(), token.begin(), tolower);
302 >            if (token == "sin")
303                rsh->makeSinFunction();
304              else
305                rsh->makeCosFunction();
# Line 282 | Line 315 | namespace oopse {
315      // pass strength functions to ShapeType
316      st->setStrengthFuncs(functionVector);
317          
318 <    delete shapeStream;
318 >  //  delete shapeStream;
319    }
320   } //end namespace oopse
321  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines