-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathread_config.cpp
More file actions
96 lines (89 loc) · 2.19 KB
/
read_config.cpp
File metadata and controls
96 lines (89 loc) · 2.19 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#include <fstream>
#include <sstream>
#include <iostream>
#include "read_config.h"
std::vector<Processor> read_processors(std::string file_name)
{
std::ifstream file;
file.open(file_name);
if (file.is_open())
{
std::string line;
int procs;
while (std::getline(file, line))
{
size_t pos = line.find("MaxProcs: ");
if (pos != -1)
{
auto found = line.find_first_of("123456789");
if (found != std::string::npos){
procs = std::stoi(line.substr(found));
}
}
}
file.close();
std::vector<Processor> result;
for (int i = 0; i < procs; i++)
{
result.emplace_back(i);
}
return result;
}
else
{
throw "Cannot open file: " + file_name;
}
}
std::vector<int> findNumbers(std::string jobLine)
{
std::stringstream s;
s << jobLine;
std::string temp;
std::vector<int> result;
int found, x = 0;
// 5 because there are this many job variables
while (!s.eof() && x < 5)
{
s >> temp;
if (std::stringstream(temp) >> found)
{
result.emplace_back(found);
}
temp = "";
x++;
}
return result;
}
std::vector<Job> read_jobs(std::string file_name, int limit)
{
std::ifstream file;
file.open(file_name);
if (file.is_open())
{
std::string line;
std::vector<Job> result;
while (std::getline(file, line) && result.size() < limit)
{
size_t pos = line.find(";", 0, 1);
if (pos == -1)
{
std::vector<int> tabJob = findNumbers(line);
if (!tabJob.empty())
{
// tabJob[3]=run time
if (tabJob[0] >= 0 && tabJob[1] >= 0 && tabJob[3] > 0 &&
tabJob[4] > 0)
{
result.emplace_back(tabJob);
}
}
}
}
file.close();
return result;
}
else
{
throw "Cannot open file: " + file_name;
}
}