| 44 | } |
| 45 | |
| 46 | void ErrorFile::parse(openstudio::filesystem::ifstream& is) { |
| 47 | std::string line; |
| 48 | |
| 49 | // matches[1], warning/error type |
| 50 | // matches[2], rest of line |
| 51 | boost::regex warningOrError(R"(^\s*\**\s+\*\*\s*([[:alpha:]]+)\s*\*\*(.*)$)"); |
| 52 | |
| 53 | // matches[1], rest of line |
| 54 | boost::regex warningOrErrorContinue(R"(^\s*\**\s+\*\*\s*~~~\s*\*\*(.*)$)"); |
| 55 | |
| 56 | // completed successfully |
| 57 | boost::regex completedSuccessful(R"(^\s*\*+ EnergyPlus Completed Successfully.*)"); |
| 58 | |
| 59 | // ground temp completed successfully |
| 60 | boost::regex groundTempCompletedSuccessful(R"(^\s*\*+ GroundTempCalc\S* Completed Successfully.*)"); |
| 61 | |
| 62 | // completed unsuccessfully |
| 63 | boost::regex completedUnsuccessful(R"(^\s*\*+ EnergyPlus Terminated.*)"); |
| 64 | |
| 65 | // repeat count |
| 66 | |
| 67 | // read the file line by line using regexes |
| 68 | bool alreadyGotLine = false; |
| 69 | |
| 70 | while (alreadyGotLine || std::getline(is, line)) { |
| 71 | |
| 72 | alreadyGotLine = false; |
| 73 | boost::smatch matches; |
| 74 | |
| 75 | // LOG(Trace, "Parsing ErrorFile Line '" << line << "'"); |
| 76 | |
| 77 | // parse the file |
| 78 | if (boost::regex_search(line, matches, warningOrError)) { |
| 79 | |
| 80 | std::string warningOrErrorType = std::string(matches[1].first, matches[1].second); |
| 81 | boost::trim(warningOrErrorType); |
| 82 | std::string warningOrErrorString = std::string(matches[2].first, matches[2].second); |
| 83 | boost::trim(warningOrErrorString); |
| 84 | |
| 85 | // read the rest of the multi line warning or error |
| 86 | while (true) { |
| 87 | // std::streampos pos = is.tellg(); |
| 88 | if (!std::getline(is, line)) { |
| 89 | break; |
| 90 | } |
| 91 | if (boost::regex_search(line, matches, warningOrErrorContinue)) { |
| 92 | std::string temp = std::string(matches[1].first, matches[1].second); |
| 93 | boost::trim_right(temp); |
| 94 | warningOrErrorString += "\n" + temp; |
| 95 | } else { |
| 96 | // unget the line |
| 97 | // is.seekg(pos); |
| 98 | // Instead of rewind then reread (which fails on Windows if you have LF line endings) |
| 99 | // We just use this bool to avoid having to re-read the line. |
| 100 | alreadyGotLine = true; |
| 101 | break; |
| 102 | } |
| 103 | } |