-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlinearize_file.cpp
More file actions
45 lines (37 loc) · 1.31 KB
/
linearize_file.cpp
File metadata and controls
45 lines (37 loc) · 1.31 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
#include "functions.h"
#include <fstream>
#include <vector>
#include <algorithm>
#include <cstring>
using std::vector;
using std::ifstream;
using std::ofstream;
using std::sort;
/**
* \brief Применяет алгоритм линеаризации со скользящим окном к заданному файлу.
* Выводит линеаризованные данные в отдельный файл в столбец.
* \param inputFilename Название файла, в котором заданы моменты PTS
* \param outputFilename Название файла для вывода линеаризованных моментов PTS
*/
void linearizeFile(const char* inputFilename, const char* outputFilename) {
ifstream inputStream(inputFilename);
ofstream outputStream(outputFilename);
vector<int> ptses;
char line[256];
int pts;
inputStream.getline(line, 256);
while (!inputStream.eof()) {
pts = atoi(strstr(line, ",") + 1);
if (pts < 0) {
pts = 0;
}
ptses.push_back(pts);
inputStream.getline(line, 256);
}
sort(ptses.begin(), ptses.end());
int width = 20;
vector<int> linearizedPTSes = linearizeDataEvenWidth(ptses, width);
for (int currentPTS : linearizedPTSes) {
outputStream << currentPTS << "\n";
}
}