-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfile.cpp
99 lines (93 loc) · 2.97 KB
/
file.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
#include "file.h"
#include "timer.h"
File::File()
{
QDir fileInputPath = QDir(QString("%1/%2").arg(QDir::currentPath()).arg("Initial Files"));
QStringList nameFilter("*.mpt");
srcFiles = fileInputPath.entryList(nameFilter);
}
void File::readAllFiles()
{
if(!srcFiles.size())
{
std::cout << "There are no files to analyse" << std::endl;
return;
}
for(QString & el : srcFiles)
{
QString srcFile = QString("%1/%2/%3").arg(QDir::currentPath()).arg("Initial files").arg(el);
QFile file(srcFile);
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
{
return;
}
fileLines = QString(file.readAll()).split('\n');
purifyFile();
el.truncate(el.lastIndexOf('.'));
Container::fillList(fileLines, el);
fileLines.clear();
std::cout << QString("File %1 is loaded. %2 msec").arg(el).arg(Timer::writeTime()).toStdString() << std::endl;
}
}
void File::writeNyquistFiles()
{
if(!srcFiles.size())
{
return;
}
foreach(QString el, srcFiles)
{
QString path = QString("%1/%2/%3").arg(QDir::currentPath()).arg("Final files").arg(el);
QDir dir(path);
if (!dir.exists())
{
dir.mkdir(path);
}
for(int j = 0; j < Container::getSpecta()[el].count(); ++j) //Specta count in the top of spectra file
{
QString name = Container::getSpecta()[el][j].getPot();
QString finFile = QString(path + "/%1-%2[%3].txt").arg(j + 1).arg(el).arg(name.toDouble(), 0, 'f', 5);
QFile file(finFile);
if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
{
return;
}
QTextStream out(&file);
out << Container::getSpecta()[el][j];
file.close();
}
std::cout << QString("Folder %1 is ready. %2 msec").arg(el).arg(Timer::writeTime()).toStdString() << std::endl;
}
}
void File::writeCVFile()
{
if(!srcFiles.size())
{
return;
}
for(int i = 0; i < srcFiles.count(); ++i)
{
QString path = QString("%1/%2/%3").arg(QDir::currentPath()).arg("Final files").arg(srcFiles[i]);
QString finFile = QString(path + "/%1-CV.txt").arg(srcFiles[i]);
QFile file(finFile);
if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
{
return;
}
QTextStream out(&file);
out << Container::createMottShottky(srcFiles[i]);
file.close();
std::cout << QString("File %1-CV is ready. %2 msec").arg(srcFiles[i]).arg(Timer::writeTime()).toStdString() << std::endl;
}
}
void File::purifyFile()
{
QRegExp expr("[0-9]+");
expr.indexIn(fileLines[1]);
int lineNumber = expr.cap().toInt();
while(lineNumber)
{
fileLines.pop_front();
--lineNumber;
}
}