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

Method parseLocation

src/utilities/filetypes/EpwFile.cpp:5083–5146  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5081}
5082
5083bool EpwFile::parseLocation(const std::string& line) {
5084 // LOCATION,Chicago Ohare Intl Ap,IL,USA,TMY3,725300,41.98,-87.92,-6.0,201.0
5085 // LOCATION, city, stateProvinceRegion, country, dataSource, wmoNumber, latitude, longitude, timeZone, elevation
5086 std::vector<std::string> split = splitString(line, ',');
5087 if (split.size() < 10) {
5088 LOG(Error, "Expected 10 location fields rather than the " << split.size() << " fields in EPW file '" << m_path << "'");
5089 return false;
5090 } else if (split.size() > 10) {
5091 LOG(Warn, "Expected 10 location fields rather than the " << split.size() << " fields in EPW file '" << m_path
5092 << "', additional fields will be ignored");
5093 }
5094
5095 if (split[0] != "LOCATION") {
5096 LOG(Error, "Missing LOCATION specifier in EPW file '" << m_path << "'");
5097 return false;
5098 }
5099
5100 m_city = split[1];
5101 boost::trim(m_city);
5102 m_stateProvinceRegion = split[2];
5103 boost::trim(m_stateProvinceRegion);
5104 m_country = split[3];
5105 boost::trim(m_country);
5106 m_dataSource = split[4];
5107 boost::trim(m_dataSource);
5108 m_wmoNumber = split[5];
5109 boost::trim(m_wmoNumber);
5110
5111 std::string latitude = split[6];
5112 boost::trim(latitude);
5113 std::string longitude = split[7];
5114 boost::trim(longitude);
5115 std::string timeZone = split[8];
5116 boost::trim(timeZone);
5117 std::string elevation = split[9];
5118 boost::trim(elevation);
5119
5120 try {
5121 m_latitude = std::stod(latitude);
5122 } catch (...) {
5123 LOG(Error, "Non-numerical latitude in EPW file '" << m_path << "'");
5124 return false;
5125 }
5126 try {
5127 m_longitude = std::stod(longitude);
5128 } catch (...) {
5129 LOG(Error, "Non-numerical longitude in EPW file '" << m_path << "'");
5130 return false;
5131 }
5132 try {
5133 m_timeZone = std::stod(timeZone);
5134 } catch (...) {
5135 LOG(Error, "Non-numerical timezone in EPW file '" << m_path << "'");
5136 return false;
5137 }
5138 try {
5139 m_elevation = std::stod(elevation);
5140 } catch (...) {

Callers

nothing calls this directly

Calls 2

splitStringFunction · 0.85
sizeMethod · 0.45

Tested by

no test coverage detected