Skip to content

Commit

Permalink
Merge pull request #49 from JoshuaSBrown/fix-bug-io-log-reader-energies
Browse files Browse the repository at this point in the history
Fix problem with no spaces when reading in energies from gaussian log…
  • Loading branch information
JoshuaSBrown authored Aug 20, 2019
2 parents a897c9f + 2af2709 commit 15f3002
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 4 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ option(CODE_COVERAGE "Enable coverage reporting" OFF)
# Defining settings
##############################################################################
set(calcJ_VERSION_MAJOR 1 )
set(calcJ_VERSION_MINOR 8 )
set(calcJ_VERSION_MINOR 9 )
set(calcJ_YEAR_PUBLISHED 2018 )
set(calcJ_AUTHOR_SURNAME "\"Brown\"" )
set(calcJ_AUTHOR_INITIALS "\"J. S.\"" )
Expand Down
52 changes: 51 additions & 1 deletion src/libcatnip/io/file_readers/logreader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,56 @@
using namespace catnip;
using namespace std;

/**
* \brief Specifically designed to split up energies in the log file
**/
vector<string> splitStEnergies(const string & line){
vector<string> items = splitSt(line);
if(items.size()==9) return items;

// There should normally be 5 energies listed per line in a log file, if
// there are fewer it may be the case that there are no spaces between
// the doubles on the same line e.g.
// col 1 col 2 col 3 col4 col 5 col 6 col 7 col 8 col 9
// Alpha occ. eigenvalues -- -101.56324-101.56318-101.56026-101.56021-101.55975

vector<string> items2;
std::string delimiter = "-";

for( size_t inc=0; inc<items.size(); ++inc){
string s = items.at(inc);
if(inc<4){
items2.push_back(s);
}else{
size_t pos = s.find(delimiter);
if(pos==std::string::npos){
items2.push_back(s);
}else{
while (pos != std::string::npos) {
string token = s.substr(0,pos);
if(pos==0){
string temp_s = s;
temp_s.erase(0,delimiter.length());
pos = temp_s.find(delimiter);
if( pos == std::string::npos){
token = s;
pos = s.length();
}else{
token = s.substr(0,pos+delimiter.length());
}
s.erase(0, delimiter.length());
}
s.erase(0, pos);
items2.push_back(token);
pos = s.find(delimiter);
}
}
}

}
return items2;
}

LogReader::LogReader(const string &fileName) : FileReader(fileName) {
validFileName_();
registerSections_();
Expand Down Expand Up @@ -239,7 +289,7 @@ void LogReader::ReadOrbEnergies(const string &orb_type) {

if (occFound || virtFound) {

auto vec_str = splitSt(line);
auto vec_str = splitStEnergies(line);
for (size_t inc = 4; inc < vec_str.size(); inc++) {
OREnergies[orb_type].push_back((double)atof(vec_str.at(inc).c_str()));
if (occFound) homoLevel[orb_type]++;
Expand Down
2 changes: 1 addition & 1 deletion src/libcatnip/string_support.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ void rtrim_(string &s) {
}

// Split a string up by spaces
vector<string> splitSt(string input) {
vector<string> splitSt(const string & input) {
istringstream iss(input);
list<string> tokens;
copy(istream_iterator<string>(iss), istream_iterator<string>(),
Expand Down
2 changes: 1 addition & 1 deletion src/libcatnip/string_support.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
namespace catnip {

// Split a std::string up by spaces
std::vector<std::string> splitSt(std::string input);
std::vector<std::string> splitSt(const std::string & input);

// Given a path name this function finds the last part
// in the path which should be associated with the path
Expand Down

0 comments on commit 15f3002

Please sign in to comment.