-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcombine_Ht.cpp
118 lines (99 loc) · 2.63 KB
/
combine_Ht.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#include <iostream>
#include <locale>
#include <string>
#include <sstream>
#include <algorithm>
#include <iterator>
#include <cstring>
#include <experimental/filesystem>
#include <Eigen/Dense>
#include <fstream>
#include "ed_library.h"
using namespace std;
using namespace Eigen;
std::string extract_ints(std::ctype_base::mask category, std::string str, std::ctype<char> const& facet)
{
using std::strlen;
char const *begin = &str.front(),
*end = &str.back();
auto res = facet.scan_is(category, begin, end);
begin = &res[0];
end = &res[strlen(res)];
return std::string(begin, end);
}
std::string extract_ints(std::string str)
{
return extract_ints(std::ctype_base::digit, str,
std::use_facet<std::ctype<char>>(std::locale("")));
}
std::vector<std::string> explode(std::string const & s, char delim)
{
std::vector<std::string> result;
std::istringstream iss(s);
for (std::string token; std::getline(iss, token, delim); )
{
result.push_back(std::move(token));
}
return result;
}
void get_params(string filename, int& size, int& start_row, int& start_col, int& cluster_size)
{
int params [5];
auto v = explode(filename, '_');
for(int i=0; i<v.size(); i++)
{
string s = v.at(i);
stringstream ss(extract_ints(s));
ss >> params[i];
}
size = params[1];
start_row = params[2];
start_col = params[3];
cluster_size = params[4];
}
namespace fs = std::experimental::filesystem;
int main(int argc, char* argv[])
{
if(argc!=2) {cout << "give matrix size\n"; exit(1);}
int m_size = stoi(argv[1]);
MatrixXd Ht = MatrixXd::Constant(m_size,m_size,9);
for (auto & p : fs::directory_iterator("EDdata/"))
{
std::ostringstream oss;
oss << p;
std::string path = oss.str();
if ( path.front() == '"' )
{
path.erase( 0, 1 ); // erase the first character
path.erase( path.size() - 1 ); // erase the last character
}
cout << path << endl;
ifstream fin(path);
if(fin.fail())
{
cout << path << " not avaliable." << endl;
continue;
}
int size, start_row, start_col, csize;
get_params(path, size, start_row, start_col, csize);
for(int i=start_row; i<start_row+csize; i++)
{
for(int j=start_col; j<start_col+csize; j++)
{
fin >> Ht(i,j);
// double a; fin >> a; cout << a;
}
}
fin.close()
};
// VectorXd lambda; MatrixXd vc;
// diagonalize(Ht, lambda, vc);
// ofstream fout("check_eivals.txt");
// fout << lambda << endl;
// fout.close();
ofstream fout;
fout.open("check_Ht.txt");
fout << Ht << endl;
fout.close();
return 0;
}