MCPcopy Create free account
hub / github.com/NatLabRockies/OpenStudio / translateToMos

Method translateToMos

src/utilities/filetypes/EpwFile.cpp:4739–4881  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4737}
4738
4739bool EpwFile::translateToMos(const openstudio::path& path) {
4740 if (m_data.empty()) {
4741 if (!openstudio::filesystem::exists(m_path) || !openstudio::filesystem::is_regular_file(m_path)) {
4742 LOG_AND_THROW("Path '" << m_path << "' is not an EPW file");
4743 }
4744
4745 m_checksum = openstudio::checksum(m_path);
4746
4747 std::ifstream ifs(openstudio::toSystemFilename(m_path));
4748
4749 if (!parse(ifs, true)) {
4750 ifs.close();
4751 LOG(Error, "EpwFile '" << toString(m_path) << "' cannot be processed");
4752 return false;
4753 }
4754 ifs.close();
4755 }
4756
4757 if (data().empty()) {
4758 LOG(Error, "EPW file contains no data to translate");
4759 return false;
4760 }
4761
4762 std::vector<std::string> epwHeaderLines;
4763 bool sawDataPeriods = false;
4764 if (!m_path.empty() && openstudio::filesystem::exists(m_path)) {
4765 std::ifstream headerStream(openstudio::toSystemFilename(m_path));
4766 std::string rawLine;
4767 while (std::getline(headerStream, rawLine)) {
4768 epwHeaderLines.push_back(rawLine);
4769 std::string trimmed = rawLine;
4770 boost::trim(trimmed);
4771 if (boost::istarts_with(trimmed, "DATA PERIODS")) {
4772 sawDataPeriods = true;
4773 break;
4774 }
4775 }
4776 }
4777
4778 if (!sawDataPeriods) {
4779 LOG(Error, "Failed to read EPW header information from '" << m_path << "' needed for MOS export");
4780 return false;
4781 }
4782
4783 openstudio::filesystem::ofstream fp(path);
4784 if (!fp.is_open()) {
4785 LOG(Error, "Failed to open file '" + openstudio::toString(path) + "'");
4786 return false;
4787 }
4788
4789 fp << "#1\n";
4790 fp << fmt::format("double tab1({},{})\n", data().size(), 30);
4791 for (const auto& headerLine : epwHeaderLines) {
4792 fp << '#' << headerLine << '\n';
4793 }
4794
4795 static const std::array<const char*, 30> kColumnDescriptions = {
4796 "#C1 Time in seconds. Beginning of a year is 0s.",

Callers 1

runModelicaMeasuresMethod · 0.80

Calls 14

toSystemFilenameFunction · 0.85
dateTimeMethod · 0.80
totalSecondsMethod · 0.80
toEpwStringsMethod · 0.80
DateClass · 0.70
TimeClass · 0.70
checksumFunction · 0.50
toStringFunction · 0.50
emptyMethod · 0.45
closeMethod · 0.45
push_backMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected