-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdatagen.cpp
49 lines (41 loc) · 1.09 KB
/
datagen.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
#include <iostream>
#include <cstdlib>
#include <fstream>
#include <vector>
#include <string>
using namespace std;
int main(int argc, char** argv) {
if (argc != 2) {
cout << "Usage: " << argv[0] << " config.txt" << endl;
cout << "Config format:" << endl;
cout << "filename val x y z" << endl;
cout << "val lx ly lz rx ry rz" << endl;
exit(0);
}
fstream fs(argv[1], ios_base::in);
if (!fs.is_open()) throw logic_error("Can't open file");
double val;
string filename;
long nx, ny, nz;
fs >> filename >> val >> nx >> ny >> nz;
vector<double> data(nx * ny * nz, val);
while (true) {
long lx, ly, lz;
long rx, ry, rz;
fs >> val >> lx >> ly >> lz >> rx >> ry >> rz;
if (fs.eof()) break;
for (int k = lz; k < rz; ++k)
for (int j = ly; j < ry; ++j)
for (int i = lx; i < rx; ++i) {
data[i + j * nx + k * nx * ny] = val;
}
}
fs.close();
fs.open(filename.c_str(), ios_base::out | ios_base::trunc);
for (int k = 0; k < nz; ++k)
for (int j = 0; j < ny; ++j)
for (int i = 0; i < nx; ++i) {
fs.write((char*)&data[i + j * nx + k * nx * ny], sizeof(double));
}
fs.close();
}