-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathWFS_output.cpp
146 lines (129 loc) · 5.15 KB
/
WFS_output.cpp
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#include "WFS_output.h"
#include <sstream>
#include <fstream>
namespace wildland_firesim {
Output::Output(): weatherData()
{
}
std::string
Output::setfileName(std::string baseName, std::string extention, int i)
{
std::stringstream ss;
ss << baseName << i << extention;
return ss.str();
}
//functions for printing map to ASCII grid
void
Output::writeBurnMapToASCII(LandscapeInterface &landscape, std::string fileName)
{
// create variable for output file stream
std::ofstream burnDataFile;
//open output file stream
//burnDataFile.open("output/"+fileName);
burnDataFile.open(fileName);
burnDataFile << "NCOLS " << landscape.getWidth() << std::endl;
burnDataFile << "NROWS " << landscape.getHeight() << std::endl;
burnDataFile << "XLLCORNER " << "0" << std::endl;
burnDataFile << "YLLCORNER " << "0" << std::endl;
burnDataFile << "CELLSIZE " << "1" << std::endl; //may use cellsize later
burnDataFile << "NODATA_VALUE " << "-9999" << std::endl;
for (int y = (landscape.getHeight()-1); y >= 0; y--)
for (int x = 0; x <landscape.getWidth(); x++) {
burnDataFile << static_cast<int>(landscape.getCellInformation(x,y)->state) << " ";
}
burnDataFile << "\n";
burnDataFile.close();
}
void
Output::writeVegetationMapToASCII(LandscapeInterface &landscape, std::string fileName)
{
std::ofstream vegetationTypeDataFile;
//vegetationTypeDataFile.open("output/"+fileName);
vegetationTypeDataFile.open(fileName);
vegetationTypeDataFile << "nCols " << landscape.getWidth() << std::endl;
vegetationTypeDataFile << "nRows " << landscape.getHeight() << std::endl;
vegetationTypeDataFile << "xllcorner " << "0" << std::endl;
vegetationTypeDataFile << "yllcorner " << "0" << std::endl;
vegetationTypeDataFile << "cellsize " << 1 << std::endl; //may use cellsize later
vegetationTypeDataFile << "nodata_value " << "-9999" << std::endl;
for (int y = (landscape.getHeight()-1); y >= 0; y--)
for (int x = 0; x <landscape.getWidth(); x++) {
vegetationTypeDataFile << static_cast<int>(landscape.getCellInformation(x,y)->type) << " ";
}
vegetationTypeDataFile << "\n";
vegetationTypeDataFile.close();
}
//functions to write csv-files
void
Output::writeVegetationDataToCSV(LandscapeInterface &landscape, std::string fileName)
{
std::ofstream vegetationDataFile;
//vegetationDataFile.open("output/"+fileName);
vegetationDataFile.open(fileName);
//header
vegetationDataFile << "x,y,type,live,dead" << "\n";
//data
for (int y = (landscape.getHeight()-1); y >= 0; y--)
for (int x = 0; x <landscape.getWidth(); x++) {
vegetationDataFile << x << "," << y << ",";
VegetationType type = landscape.getCellInformation(x,y)->type;
float dead_biomass = landscape.getCellInformation(x,y)->deadBiomass;
float live_biomass = landscape.getCellInformation(x,y)->liveBiomass;
vegetationDataFile << static_cast<int>(type) << ",";
vegetationDataFile << live_biomass << ",";
vegetationDataFile << dead_biomass;
vegetationDataFile << "\n";
}
vegetationDataFile.close();
}
void
Output::writeBurnDataToCSV(LandscapeInterface &landscape, Fire &fire, std::string fileName)
{
std::ofstream burnDataFile;
//burnDataFile.open("output/"+fileName);
burnDataFile.open(fileName);
//header
burnDataFile << "x,y,state,intensity" << "\n";
//data
for (int y = (landscape.getHeight()-1); y >= 0; y--)
for (int x = 0; x <landscape.getWidth(); x++) {
burnDataFile << x << "," << y << ",";
CellState state = landscape.getCellInformation(x,y)->state;
burnDataFile << static_cast<int>(state) << ",";
if(state==CellState::Burning){
for(size_t i = 0; i < fire.burningCellInformationVector.size(); i++){
if(y == fire.burningCellInformationVector[i].yCoord &&
x == fire.burningCellInformationVector[i].xCoord){
burnDataFile << fire.burningCellInformationVector[i].meanFirelineIntensity;
}
}
}else{
burnDataFile << "0.0";
}
burnDataFile << "\n";
}
burnDataFile.close();
}
void
Output::writeFireWeatherDataToCSV(std::vector<std::string> weatherData , std::string fileName)
{
std::ofstream weatherDataFile;
//weatherDataFile.open("output/"+fileName);
weatherDataFile.open(fileName);
weatherDataFile << "t, temperature, relHumidity, windSpeed, windDirection" << std::endl;
for(size_t i = 0; i<weatherData.size(); i++){
weatherDataFile << weatherData[i] << "\n";
}
weatherDataFile.close();
}
//functions to store data in strings
std::string
Output::storeWeatherData(const FireWeatherVariables &weather, float durationOfBurn)
{
std::stringstream weatherData;
weatherData << durationOfBurn << ",";
weatherData << weather.temperature << "," << weather.relHumidity << ",";
weatherData << weather.windSpeed << "," << weather.windDirection;
return weatherData.str();
}
}//namespace wildland_firesim