-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcluster-grouping.cpp
More file actions
86 lines (79 loc) · 2.13 KB
/
Copy pathcluster-grouping.cpp
File metadata and controls
86 lines (79 loc) · 2.13 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
#include <iostream>
#include <fstream>
#include <filesystem>
namespace fs = std::filesystem;
using namespace std;
string cluster_path = "cluster/";
string cluster_file = "mpi_kmean.txt";
int num_cluster = 20;
void show_help()
{
cout << "Please use -h or --help to get information about argument" << endl;
cout << "-clusterPath path to indicate out folder" << endl;
cout << "-clusterFile * solution file of k mean step" << endl;
}
int main(int argc, char **argv)
{
int mandatory_field = 0;
for (int i = 1; i < argc; ++i)
{
string arg = argv[i];
if ((arg == "-h") || (arg == "--help"))
{
show_help();
}
if ((arg == "-clusterPath") || (arg == "--clusterPath"))
{
cluster_path = argv[i + 1];
}
if ((arg == "-clusterFile") || (arg == "--clusterFile"))
{
cluster_file = argv[i + 1];
mandatory_field++;
}
if ((arg == "-numCluster") || (arg == "--numCluster"))
{
num_cluster = atoi(argv[i + 1]);
mandatory_field++;
}
}
if (mandatory_field < 2)
{
cout << "Please set value for mandatory field!" << endl;
return 1;
}
int num_file[num_cluster];
for(int i=0; i<num_cluster; i++){
num_file[i] = 0;
}
ifstream file(cluster_file, ios::in);
if (file.is_open())
{
while (!file.eof())
{
string line;
getline(file, line);
string delimiter = " ";
int pos = line.find(delimiter);
if (pos != string::npos)
{
string path = line.substr(0, pos);
string cluster = line.substr(pos + 1, line.length() - pos);
cout << "path is |" << path << "| cluster |" << cluster << "|" << endl;
string filename;
int pos_2 = path.find_last_of("/");
if (pos_2 != string::npos)
filename = path.substr(pos_2, path.length() - pos_2);
else
filename = pos;
cout << "file name " << filename << endl;
fs::create_directories(cluster_path + cluster);
fs::copy(path, cluster_path + cluster + std::to_string(num_file[stoi(cluster)]));
num_file[stoi(cluster)]++;
}
}
}
else
cout << "Unable to open file";
return 0;
}