-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathLSDGrainMatrix.cpp
145 lines (101 loc) · 3.25 KB
/
LSDGrainMatrix.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
/// LSDGrainMatrix.cpp
///
/// IMPLEMENTATION FILE
/*
* SUMMARY
*
* LSDGrainMatrix is a class that defines an object to store data
* about the surface and subsurface layers of raster or catchment.
* It stores the grainsize fractions (of n fractions) for a given number
* of surface and n subsurface layers. Be warned it is quite a large object
* if you wish to define multiple fractions and multiple
* subsurface layers!
*
* @author Declan Valters
* @date 2016
* University of Manchester
* @contact [email protected]
* @version 0.01
*
* Released under the GNU v2 Public License
*
*/
#include <string>
#include <cmath>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <iterator> // For the printing vector method
#include <sys/stat.h> // For fatal errors
// Only for the debug macro
#include <cstdio>
#include "LSDGrainMatrix.hpp"
#ifndef LSDGrainMatrix_CPP
#define LSDGrainMatrix_CPP
/*void LSDGrainMatrix::create()
{
std::cout << "You are trying to create an LSDGrainMatrix object with no supplied files or parameters." << std::endl << "Exiting..." << std::endl;
exit(EXIT_FAILURE);
}*/
void LSDGrainMatrix::create(int imax, int jmax, int NoDataVal, int G_MAX)
{
NRows = imax; // +2? -check in LSDCatchmentModel
NCols = jmax;
NoData = NoDataVal;
GrainFracMax = G_MAX;
std::cout << "Initialised a Grain Matrix..." << std::endl;
}
void LSDGrainMatrix::write_grainMatrix_to_ascii_file(std::string filename,
std::string fname_extension)
{
std::string string_filename;
std::string dot = ".";
string_filename = filename + dot + fname_extension;
std::cout << "The graindata filename is: " << string_filename << std::endl;
if (fname_extension == "asc")
{
// Open a grain data file
std::ofstream data_out(string_filename.c_str());
if( data_out.fail() )
{
std::cout << "\n ERREUR FATALE!!!: Unable to write to " << string_filename \
<< std::endl;
exit(EXIT_FAILURE);
}
for(int i=1; i<=NRows; ++i)
{
for(int j=1; j<=NCols; ++j)
{
//std::cout << rasterIndex[i][j] << ", " << NoData << std::endl;
if (rasterIndex[i][j] != NoData)
{
// Write the first part of the output file line (x,y location and index)
data_out << i << " " << j << " " << rasterIndex[i][j] << " ";
// Now write the Surface Grain bit
for (int inc=0; inc<= GrainFracMax; inc++)
{
//std::cout << rasterIndex[i][j] << std::endl;
data_out << grainData[rasterIndex[i][j]][inc] << " ";
}
// Now write the subsurface grain fractions
for(int z=0; z<=9; z++) // Loop through subsurface layers...
{
for(int inc=0; inc<=(GrainFracMax-2); inc++)
{
data_out << strataData[rasterIndex[i][j]][z][inc] << " ";
}
}
data_out << std::endl;
}
}
}
data_out.close();
}
else
{
std::cout << "You did not enter and approprate extension!" << std::endl
<< "You entered: " << fname_extension << ", options are: asc" << std::endl;
exit(EXIT_FAILURE);
}
}
#endif