--- trunk/src/utils/ElementsTable.cpp 2008/01/24 21:38:53 1224 +++ trunk/src/utils/ElementsTable.cpp 2015/03/09 17:10:26 2077 @@ -1,7 +1,7 @@ This basic Periodic Table class was originally taken f /********************************************************************** This basic Periodic Table class was originally taken from the data.cpp -file in OpenBabel. The code has been modified to match the OOPSE coding style. +file in OpenBabel. The code has been modified to match the OpenMD coding style. We have retained the OpenBabel copyright and GPL license on this class: @@ -25,21 +25,20 @@ GNU General Public License for more details. * @file ElementsTable.cpp * @author gezelter * @date 12/21/2007 - * @time 11:30am * @version 1.0 */ #include "config.h" + +#include +#include #include #include +#include #include "utils/ElementsTable.hpp" #include "utils/simError.h" -#include "io/basic_ifstrstream.hpp" +#include "io/ifstrstream.hpp" -#if !HAVE_STRNCASECMP -extern "C" int strncasecmp(const char *s1, const char *s2, size_t n); -#endif - #ifdef WIN32 #define FILE_SEP_CHAR "\\" #else @@ -50,32 +49,31 @@ extern "C" int strncasecmp(const char *s1, const char #define BUFF_SIZE 32768 #endif -namespace oopse { +namespace OpenMD { ElementsTable etab; ElementsTable::ElementsTable() { init_ = false; - STR_DEFINE(dir_, FRC_PATH ); + dir_ = std::string("TO_STRING(FRC_PATH)"); envvar_ = "FORCE_PARAM_PATH"; filename_ = "element.txt"; } ElementsTable::~ElementsTable() { std::vector::iterator i; - for (i = elements_.begin(); i != elements_.end(); i++) + for (i = elements_.begin(); i != elements_.end(); ++i) delete *i; } void ElementsTable::ParseLine(const char *line) { int num, maxbonds; - char symbol[5]; + char symbol[6]; char name[256]; RealType Rcov,Rvdw,mass, elNeg, ionize, elAffin; RealType red, green, blue; // skip comment line (at the top) - if (line[0] != '#') { sscanf(line,"%d %5s %lf %*f %lf %d %lf %lf %lf %lf %lf %lf %lf %255s", &num, @@ -96,6 +94,7 @@ namespace oopse { elNeg, ionize, elAffin, red, green, blue, name); elements_.push_back(ele); + } } @@ -106,7 +105,7 @@ namespace oopse { return elements_.size(); } - char *ElementsTable::GetSymbol(int atomicnum) { + const char *ElementsTable::GetSymbol(int atomicnum) { if (!init_) Init(); @@ -264,7 +263,7 @@ namespace oopse { Init(); std::vector::iterator i; - for (i = elements_.begin();i != elements_.end();i++) + for (i = elements_.begin();i != elements_.end(); ++i) if (!strncasecmp(sym,(*i)->GetSymbol(),2)) return((*i)->GetAtomicNum()); @@ -291,21 +290,28 @@ namespace oopse { buffer = getenv(envvar_.c_str()); buffer += FILE_SEP_CHAR; + + + if (!subdir_.empty()) { subbuffer = buffer; subbuffer += subdir_; subbuffer += FILE_SEP_CHAR; } + + buffer += filename_; subbuffer += filename_; + ifs1.open(subbuffer.c_str()); ifsP= &ifs1; - if (!(*ifsP)) { + if (!(ifsP->is_open())) { ifs2.open(buffer.c_str()); ifsP = &ifs2; } + } else { sprintf( painCave.errMsg, "ElementsTable error.\n" @@ -314,29 +320,30 @@ namespace oopse { simError(); } - char charBuffer[BUFF_SIZE]; + if ((*ifsP)) { + char charBuffer[BUFF_SIZE]; while(ifsP->getline(charBuffer,BUFF_SIZE)) ParseLine(charBuffer); - - if (ifs1) - ifs1.close(); - if (ifs2) - ifs2.close(); - if (ifs3) - ifs3.close(); - if (ifs4) - ifs4.close(); + + if (ifs1) + ifs1.close(); + if (ifs2) + ifs2.close(); + if (ifs3) + ifs3.close(); + if (ifs4) + ifs4.close(); + + if (GetSize() == 0) { + sprintf( painCave.errMsg, + "ElementsTable error.\n" + "\tCannot initialize database %s \n", filename_.c_str()); + painCave.isFatal = 0; + simError(); + } - if (GetSize() == 0) { - sprintf( painCave.errMsg, - "ElementsTable error.\n" - "\tCannot initialize database %s \n", filename_.c_str()); - painCave.isFatal = 0; - simError(); } - - } } }