--- trunk/OOPSE-4/src/utils/ElementsTable.cpp 2008/01/23 03:45:33 3319 +++ trunk/OOPSE-4/src/utils/ElementsTable.cpp 2008/09/18 21:51:20 3453 @@ -29,11 +29,15 @@ GNU General Public License for more details. * @version 1.0 */ +#include #include "config.h" +#include #include #include +#include #include "utils/ElementsTable.hpp" #include "utils/simError.h" +#include "io/basic_ifstrstream.hpp" #if !HAVE_STRNCASECMP extern "C" int strncasecmp(const char *s1, const char *s2, size_t n); @@ -74,7 +78,6 @@ namespace oopse { 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, @@ -95,6 +98,7 @@ namespace oopse { elNeg, ionize, elAffin, red, green, blue, name); elements_.push_back(ele); + } } @@ -284,27 +288,34 @@ namespace oopse { init_ = true; std::string buffer, subbuffer; - std::ifstream ifs1, ifs2, ifs3, ifs4, *ifsP; + ifstrstream ifs1, ifs2, ifs3, ifs4, *ifsP; // First, look for an environment variable if (getenv(envvar_.c_str()) != NULL) { 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" @@ -317,25 +328,25 @@ namespace oopse { if ((*ifsP)) { 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(); } - - } } }