GCC Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 68.1% 77 / 0 / 113
Functions: 85.7% 6 / 0 / 7
Branches: 48.4% 60 / 0 / 124

src/isomodel/EpwData.cpp
Line Branch Exec Source
1 /***********************************************************************************************************************
2 * OpenStudio(R), Copyright (c) Alliance for Energy Innovation, LLC.
3 * See also https://openstudio.net/license
4 ***********************************************************************************************************************/
5
6 #include "EpwData.hpp"
7 #include "SolarRadiation.hpp"
8
9 namespace openstudio {
10 namespace isomodel {
11
12
2/2
✓ Branch 3 taken 3 times.
✓ Branch 6 taken 3 times.
9 EpwData::EpwData(const openstudio::path& t_path) : m_data(7, std::vector<double>(8760)) {
13
1/1
✓ Branch 1 taken 3 times.
3 loadData(t_path);
14 3 }
15
16 3 void EpwData::parseHeader(const std::string& line) {
17
1/1
✓ Branch 2 taken 3 times.
3 std::stringstream linestream(line);
18
19 //cout << "Weather Location Header: "<<endl;
20
2/2
✓ Branch 0 taken 30 times.
✓ Branch 1 taken 3 times.
33 for (int i = 0; i < 10; i++) {
21 30 std::string s;
22
1/1
✓ Branch 1 taken 30 times.
30 std::getline(linestream, s, ',');
23
6/6
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 3 times.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 3 times.
✓ Branch 4 taken 3 times.
✓ Branch 5 taken 15 times.
30 switch (i) {
24 3 case 1:
25
1/1
✓ Branch 1 taken 3 times.
3 m_location = s;
26 //cout << "\tLocation: " << s <<endl;
27 3 break;
28 3 case 5:
29
1/1
✓ Branch 1 taken 3 times.
3 m_stationid = s;
30 //cout << "\tStation ID: " << s <<endl;
31 3 break;
32 3 case 6:
33 3 m_latitude = atof(s.c_str());
34 //cout << "\tLatitude: " << s <<endl;
35 3 break;
36 3 case 7:
37 3 m_longitude = atof(s.c_str());
38 //cout << "\tLongitude: " << s <<endl;
39 3 break;
40 3 case 8:
41 3 m_timezone = atoi(s.c_str());
42 //cout << "\tTimezone: " << s <<endl;
43 3 break;
44 15 default:
45 15 break;
46 }
47 30 }
48 3 }
49
50 26280 void EpwData::parseData(const std::string& line, size_t row) {
51
1/1
✓ Branch 2 taken 26280 times.
26280 std::stringstream linestream(line);
52 26280 size_t col = 0;
53
54
2/2
✓ Branch 0 taken 578160 times.
✓ Branch 1 taken 26280 times.
604440 for (size_t i = 0; i < 22; i++) {
55 578160 std::string s;
56
1/1
✓ Branch 1 taken 578160 times.
578160 std::getline(linestream, s, ',');
57
2/2
✓ Branch 0 taken 183960 times.
✓ Branch 1 taken 394200 times.
578160 switch (i) {
58 183960 case 6:
59 case 7:
60 case 8:
61 case 13:
62 case 14:
63 case 15:
64 case 21:
65 assert(col < m_data.size());
66 assert(row < m_data[col].size());
67 183960 m_data[col++][row] = ::atof(s.c_str());
68 183960 break;
69 394200 default:
70 394200 break;
71 }
72 578160 }
73 26280 }
74
75 3 void EpwData::toISOData(Matrix& _msolar, Matrix& _mhdbt, Matrix& _mhEgh, Vector& _mEgh, Vector& _mdbt, Vector& _mwind) const {
76 struct MakeMatrix
77 {
78 9 static Matrix makeMatrix(const std::vector<std::vector<double>>& t_matrix) {
79 9 size_t height = t_matrix.size();
80 9 size_t width = t_matrix.at(0).size();
81
82 9 Matrix ret(t_matrix.size(), t_matrix.at(0).size());
83
84
2/2
✓ Branch 0 taken 108 times.
✓ Branch 1 taken 9 times.
117 for (size_t i = 0; i < height; ++i) {
85
2/2
✓ Branch 0 taken 2016 times.
✓ Branch 1 taken 108 times.
2124 for (size_t j = 0; j < width; ++j) {
86
3/3
✓ Branch 1 taken 2016 times.
✓ Branch 4 taken 2016 times.
✓ Branch 7 taken 2016 times.
2016 ret(i, j) = t_matrix.at(i).at(j);
87 }
88 }
89
90 9 return ret;
91 ✗ }
92 };
93
94
1/1
✓ Branch 1 taken 3 times.
3 TimeFrame frames;
95
1/1
✓ Branch 1 taken 3 times.
3 SolarRadiation pos(frames, *this);
96
1/1
✓ Branch 1 taken 3 times.
3 pos.Calculate();
97
2/2
✓ Branch 2 taken 3 times.
✓ Branch 5 taken 3 times.
3 _msolar = MakeMatrix::makeMatrix(pos.monthlySolarRadiation());
98
2/2
✓ Branch 2 taken 3 times.
✓ Branch 5 taken 3 times.
3 _mhdbt = MakeMatrix::makeMatrix(pos.hourlyDryBulbTemp());
99
2/2
✓ Branch 2 taken 3 times.
✓ Branch 5 taken 3 times.
3 _mhEgh = MakeMatrix::makeMatrix(pos.hourlyGlobalHorizontalRadiation());
100
2/2
✓ Branch 2 taken 3 times.
✓ Branch 5 taken 3 times.
3 _mEgh = openstudio::createVector(pos.monthlyGlobalHorizontalRadiation());
101
2/2
✓ Branch 2 taken 3 times.
✓ Branch 5 taken 3 times.
3 _mdbt = openstudio::createVector(pos.monthlyDryBulbTemp());
102
2/2
✓ Branch 2 taken 3 times.
✓ Branch 5 taken 3 times.
3 _mwind = openstudio::createVector(pos.monthlyWindspeed());
103 3 }
104
105 ✗ std::string EpwData::toISOData() const {
106 ✗ TimeFrame frames;
107 ✗ SolarRadiation pos(frames, *this);
108 ✗ pos.Calculate();
109 ✗ std::stringstream sstream;
110 ✗ sstream << "mdbt" << '\n';
111 ✗ for (int i = 0; i < 12; i++) {
112 ✗ sstream << i << "," << pos.monthlyDryBulbTemp()[i] << '\n';
113 }
114 ✗ sstream << "mwind" << '\n';
115 ✗ for (int i = 0; i < 12; i++) {
116 ✗ sstream << i << "," << pos.monthlyWindspeed()[i] << '\n';
117 }
118 ✗ sstream << "mEgh" << '\n';
119 ✗ for (int i = 0; i < 12; i++) {
120 ✗ sstream << i << "," << pos.monthlyGlobalHorizontalRadiation()[i] << '\n';
121 }
122 ✗ sstream << "hdbt" << '\n';
123 ✗ for (int i = 0; i < 12; i++) {
124 ✗ sstream << i;
125 ✗ for (int h = 0; h < 24; h++) {
126 ✗ sstream << "," << pos.hourlyDryBulbTemp()[i][h];
127 }
128 ✗ sstream << '\n';
129 }
130 ✗ sstream << "hEgh" << '\n';
131 ✗ for (int i = 0; i < 12; i++) {
132 ✗ sstream << i;
133 ✗ for (int h = 0; h < 24; h++) {
134 ✗ sstream << "," << pos.hourlyGlobalHorizontalRadiation()[i][h];
135 }
136 ✗ sstream << '\n';
137 }
138 ✗ sstream << "solar" << '\n';
139 ✗ for (int i = 0; i < 12; i++) {
140 ✗ sstream << i;
141 ✗ for (int s = 0; s < SolarRadiation::NUM_SURFACES; s++) {
142 ✗ sstream << "," << pos.monthlySolarRadiation()[i][s];
143 }
144 ✗ sstream << '\n';
145 }
146 ✗ return sstream.str();
147 ✗ }
148
149 3 void EpwData::loadData(const openstudio::path& t_path) {
150 // Array was fully initialized in constructor
151
2/2
✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
3 std::ifstream myfile(openstudio::toSystemFilename(t_path));
152
1/2
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
3 if (myfile.is_open()) {
153 3 size_t i = 0;
154 3 size_t row = 0;
155
6/7
✓ Branch 1 taken 26307 times.
✓ Branch 3 taken 26307 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 26304 times.
✓ Branch 6 taken 3 times.
✓ Branch 7 taken 26304 times.
✓ Branch 8 taken 3 times.
26307 while (myfile.good() && row < 8760) {
156 26304 i++;
157 26304 std::string line;
158
1/1
✓ Branch 1 taken 26304 times.
26304 getline(myfile, line);
159
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 26301 times.
26304 if (i == 1) {
160
1/1
✓ Branch 1 taken 3 times.
3 parseHeader(line);
161
2/2
✓ Branch 0 taken 26280 times.
✓ Branch 1 taken 21 times.
26301 } else if (i > 8) {
162
1/1
✓ Branch 1 taken 26280 times.
26280 parseData(line, row++);
163 }
164 26304 }
165
1/1
✓ Branch 1 taken 3 times.
3 myfile.close();
166 } else {
167 ✗ throw std::runtime_error("Unable to open weather file: " + openstudio::toString(t_path));
168 }
169 3 }
170 } // namespace isomodel
171 } // namespace openstudio
172