-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmerge.cpp
More file actions
76 lines (63 loc) · 1.91 KB
/
merge.cpp
File metadata and controls
76 lines (63 loc) · 1.91 KB
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
// Compile using "g++ -fsanitize=address merge.cpp"
#include <fstream>
#include <iostream>
#include <sstream>
#include <string>
constexpr int nMinAnalysedRows{6}; // Minimum index of analysed rows INCLUDED
constexpr int nMaxAnalysedRows{4008}; // Maximum rows EXCLUDED
void mergeCsv() {
// Create file to write on
std::ofstream outputFile{"./data/refl60.txt"};
// Read input files
std::string fileRoot{"./data/conf2_60_0/Autosave/C2SCOPE#"};
std::string fileType{".csv"};
std::string line{};
// Loop on files to merge
for (int i = 200001; i <= 201000; ++i) {
std::cout << "\n*** FILE n. " << i << " ***\n";
std::string fileName{fileRoot + std::to_string(i) + fileType};
std::ifstream currentInfile(fileName);
int row{1};
// Check if file exists
if (!currentInfile.is_open()) {
std::cerr << "Error: could not be able to open file " << fileName << '\n';
return;
}
// Loop on rows for each file
while (std::getline(currentInfile, line)) {
if (row < nMinAnalysedRows) {
++row;
continue;
}
if (row >= nMaxAnalysedRows) {
break;
}
// Defining loop variables
std::stringstream ss(line);
std::string item{};
int column{1};
// std::cout << "\n*** ROW n. " << row << " ***\n";
// Loop on columns for each file
while (std::getline(ss, item, ',')) {
if (item.empty()) {
continue;
}
if (column == 1 && row == 6) {
// std::cout << "Timestamp = " << std::stod(item) << '\n';
outputFile << "0\t0\t" << std::stod(item) << "\t0\t0\t0\t";
} else if (column == 2) {
// std::cout << "Amplitude = " << std::stod(item) << '\n';
outputFile << std::stod(item) << '\t';
}
++column;
}
++row;
}
outputFile << '\n';
}
outputFile.close();
}
int main() {
mergeCsv();
return EXIT_SUCCESS;
}