-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDatastruct.cpp
More file actions
68 lines (58 loc) · 1.6 KB
/
Copy pathDatastruct.cpp
File metadata and controls
68 lines (58 loc) · 1.6 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
#include "headers.hpp"
extern int myRank;
extern int nbTasks;
void readData(Problem& p, string filename)
{
string line;
int n, m;
ifstream datafile(filename.c_str());
if (!datafile)
printf("ERROR: Unable to open file named '%s'.\n", filename.c_str());
else
{
while (datafile.good())
{
getline (datafile,line);
if (line.compare("$BeginData") == 0)
datafile >> n >> m;
p.A.resize(n,m);
p.v.resize(n);
if (line.compare("$BeginMatrix") == 0)
{
for (int i = 0; i < n; ++i)
for (int j = 0; j < m; ++j)
datafile >> p.A(i,j);
}
if (line.compare("$BeginVector") == 0)
{
for (int i = 0; i < n; ++i)
datafile >> p.v(i);
//v = x;
}
}
}
datafile.close();
}
void writeData(Problem& p, string filename)
{
ofstream datafile(filename.c_str());
datafile << "------------------------------------------------------\n";
datafile << "|\n|\n|\n|\n|\n";
datafile << "-------------------------------------------------------\n\n";
datafile << "$BeginData" << endl;
datafile << p.A.rows() << " " << p.A.cols() << endl;
datafile << "$EndData" << endl;
datafile << "$BeginMatrix" << endl;
for (int i = 0; i < p.A.rows(); ++i)
{
for (int j = 0; j < p.A.cols(); ++j)
datafile << /*setprecision(2) <<*/ p.A(i,j) << " ";
datafile << endl;
}
datafile << "$EndMatrix" << endl;
datafile << "$BeginVector" << endl;
for (int i = 0; i < p.v.rows(); ++i)
datafile << p.v(i) << endl;
datafile << "$EndVector" << endl;
datafile.close();
}