ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/trunk/src/utils/ElementsTable.cpp
(Generate patch)

Comparing trunk/src/utils/ElementsTable.cpp (file contents):
Revision 1224 by chuckv, Thu Jan 24 21:38:53 2008 UTC vs.
Revision 2077 by gezelter, Mon Mar 9 17:10:26 2015 UTC

# Line 1 | Line 1 | This basic Periodic Table class was originally taken f
1   /**********************************************************************
2  
3   This basic Periodic Table class was originally taken from the data.cpp
4 < file in OpenBabel. The code has been modified to match the OOPSE coding style.
4 > file in OpenBabel. The code has been modified to match the OpenMD coding style.
5  
6   We have retained the OpenBabel copyright and GPL license on this class:  
7  
# Line 25 | Line 25 | GNU General Public License for more details.
25   * @file ElementsTable.cpp
26   * @author gezelter
27   * @date 12/21/2007
28 * @time 11:30am
28   * @version 1.0
29   */
30  
31   #include "config.h"
32 +
33 + #include <iostream>
34 + #include <cstdlib>
35   #include <string>
36   #include <fstream>
37 + #include <cstdlib>
38   #include "utils/ElementsTable.hpp"
39   #include "utils/simError.h"
40 < #include "io/basic_ifstrstream.hpp"
40 > #include "io/ifstrstream.hpp"
41  
39 #if !HAVE_STRNCASECMP
40 extern "C" int strncasecmp(const char *s1, const char *s2, size_t n);
41 #endif
42
42   #ifdef WIN32
43   #define FILE_SEP_CHAR "\\"
44   #else
# Line 50 | Line 49 | extern "C" int strncasecmp(const char *s1, const char
49   #define BUFF_SIZE 32768
50   #endif
51  
52 < namespace oopse {
52 > namespace OpenMD {
53  
54    ElementsTable etab;
55  
56    ElementsTable::ElementsTable() {
57      init_ = false;
58 <    STR_DEFINE(dir_, FRC_PATH );
58 >    dir_ = std::string("TO_STRING(FRC_PATH)");
59      envvar_ = "FORCE_PARAM_PATH";
60      filename_ = "element.txt";
61    }
62    
63    ElementsTable::~ElementsTable() {
64      std::vector<Element*>::iterator i;
65 <    for (i = elements_.begin(); i != elements_.end(); i++)
65 >    for (i = elements_.begin(); i != elements_.end(); ++i)
66        delete *i;
67    }
68    
69    void ElementsTable::ParseLine(const char *line) {
70      int num, maxbonds;
71 <    char symbol[5];
71 >    char symbol[6];
72      char name[256];
73      RealType Rcov,Rvdw,mass, elNeg, ionize, elAffin;
74      RealType red, green, blue;
75  
76      // skip comment line (at the top)
78    
77      if (line[0] != '#')  {
78        sscanf(line,"%d %5s %lf %*f %lf %d %lf %lf %lf %lf %lf %lf %lf %255s",
79               &num,
# Line 96 | Line 94 | namespace oopse {
94                                   elNeg, ionize, elAffin, red, green, blue,
95                                   name);
96        elements_.push_back(ele);
97 +
98      }
99    }
100  
# Line 106 | Line 105 | namespace oopse {
105      return elements_.size();
106    }
107  
108 <  char *ElementsTable::GetSymbol(int atomicnum) {
108 >  const char *ElementsTable::GetSymbol(int atomicnum) {
109      if (!init_)
110        Init();
111      
# Line 264 | Line 263 | namespace oopse {
263        Init();
264      
265      std::vector<Element*>::iterator i;
266 <    for (i = elements_.begin();i != elements_.end();i++)
266 >    for (i = elements_.begin();i != elements_.end(); ++i)
267        if (!strncasecmp(sym,(*i)->GetSymbol(),2))
268          return((*i)->GetAtomicNum());
269  
# Line 291 | Line 290 | namespace oopse {
290        buffer = getenv(envvar_.c_str());
291        buffer += FILE_SEP_CHAR;
292        
293 +
294 +
295 +
296        if (!subdir_.empty()) {
297          subbuffer = buffer;
298          subbuffer += subdir_;
299          subbuffer += FILE_SEP_CHAR;
300        }
301        
302 +
303 +      
304        buffer += filename_;
305        subbuffer += filename_;
306 +
307        
308        ifs1.open(subbuffer.c_str());
309        ifsP= &ifs1;
310 <      if (!(*ifsP)) {
310 >      if (!(ifsP->is_open())) {
311          ifs2.open(buffer.c_str());
312          ifsP = &ifs2;
313        }
314 +      
315      } else {
316        sprintf( painCave.errMsg,
317                 "ElementsTable error.\n"
# Line 314 | Line 320 | namespace oopse {
320        simError();
321      }
322        
323 <    char charBuffer[BUFF_SIZE];
323 >
324      if ((*ifsP)) {
325 +      char charBuffer[BUFF_SIZE];
326        while(ifsP->getline(charBuffer,BUFF_SIZE))
327          ParseLine(charBuffer);
328 <          
329 <    if (ifs1)
330 <      ifs1.close();
331 <    if (ifs2)
332 <      ifs2.close();
333 <    if (ifs3)
334 <      ifs3.close();
335 <    if (ifs4)
336 <      ifs4.close();
328 >      
329 >      if (ifs1)
330 >        ifs1.close();
331 >      if (ifs2)
332 >        ifs2.close();
333 >      if (ifs3)
334 >        ifs3.close();
335 >      if (ifs4)
336 >        ifs4.close();
337 >      
338 >      if (GetSize() == 0) {
339 >        sprintf( painCave.errMsg,
340 >                 "ElementsTable error.\n"
341 >                 "\tCannot initialize database %s \n", filename_.c_str());
342 >        painCave.isFatal = 0;
343 >        simError();
344 >      }
345      
331    if (GetSize() == 0) {
332      sprintf( painCave.errMsg,
333               "ElementsTable error.\n"
334               "\tCannot initialize database %s \n", filename_.c_str());
335      painCave.isFatal = 0;
336      simError();
346      }
338    
339    }
347    
348    }
349   }

Comparing trunk/src/utils/ElementsTable.cpp (property svn:keywords):
Revision 1224 by chuckv, Thu Jan 24 21:38:53 2008 UTC vs.
Revision 2077 by gezelter, Mon Mar 9 17:10:26 2015 UTC

# Line 0 | Line 1
1 + Author Id Revision Date

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines