"...git@code.it4i.cz:sccs/docs.it4i.cz.git" did not exist on "cd2debe0a9116476d99cf5151f35a36b9b7f89aa"
Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include "CSVWriter.h"
namespace math1d_cl
{
void CSVWriter::saveMCResult(std::shared_ptr<math1d_cl::MatData> matData, std::vector<math1d_cl::Hydrograph>& hydrographs, int nTimeSteps, std::string qFileName, std::string hFileName)
{
if(matData->getChannels().size() != hydrographs.size())
{
std::cerr << "ERROR: Hydrograph count different from original channel count!" << std::endl;
return;
}
std::ofstream qFile(qFileName.c_str());
//std::ofstream hFile(hFileName.c_str());
//std::ofstream vFile(m_vCsvFilePath.c_str()); // only zeros
std::string firstLine = "time\\id;";
for(size_t i = 0; i < matData->getChannels().size(); i++)
{
firstLine += std::to_string(matData->getChannels()[i]->getStationId());
firstLine += (i < (matData->getChannels().size() - 1)) ? ";" : "\n";
/*if(i < matData->getChannels().size())
{
firstLine += ";";
}
else
{
firstLine += "\n";
}*/
}
qFile << firstLine;
//hFile << firstLine;
//vFile << firstLine;
for(int i = 0; i < nTimeSteps; i++)
{
qFile << printDateTime(matData->getPrecipitations()[i].first) << ";";
//vFile << printDateTime(m_precipitations[i].first);
//hFile << printDateTime(matData->getPrecipitations()[i].first) << ";";
for(size_t j = 0; j < matData->getChannels().size(); j++)
{
qFile << std::fixed << std::setprecision(6) << hydrographs.at(j).getQOut()[i];
//if(m_channels[j]->getHydrograph().getHOut().size() > i)
//hFile << std::fixed << std::setprecision(6) << hydrographs->at(j).getHOut()[i];
//else
// hFile << ";";
if(j < (matData->getChannels().size() - 1))
{
qFile << "; ";
//hFile << "; ";
}
}
qFile << "\n";
//hFile << "\n";
//vFile << "\n";
}
qFile.close();
//hFile.close();
//vFile.close();
}
std::string CSVWriter::printDateTime(const time_t& dateTime)
{
std::ostringstream str;
struct tm * timeInfo;
char buffer[6];
timeInfo = localtime(&dateTime);
strftime(buffer, 6, "%H:%M", timeInfo);
std::string month = std::to_string(timeInfo->tm_mon + 1);
if(month.length() == 1)
{
month = "0" + month;
}
str << timeInfo->tm_year + 1900 << "-" << month << "-" << timeInfo->tm_mday << " "
<< buffer;
return str.str();
}
}