forked from qzhang62/vasp_analysis
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfilesorter.cpp
More file actions
84 lines (72 loc) · 1.5 KB
/
filesorter.cpp
File metadata and controls
84 lines (72 loc) · 1.5 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
// Originally designed to recognize POSCAR, CONTCAR and xyz files,
// However this is a simplfied version only able to distinguish between
// POSCAR and CONTCAR
#include <iostream>
#include <string>
#include <fstream>
#include <sstream>
#include <vector>
using namespace std;
enum FileType{
POSCAR,
CONTCAR,
XYZ,
UNKNOWN
};
FileType fileSorter(vector<vector<string> > fileContent){
if(fileContent.size()>=8 && fileContent[7].size()==1){
return POSCAR;
}
else if(fileContent.size()>=9 && fileContent[8].size()==1){
return CONTCAR;
}
else{
return UNKNOWN;
}
}
string FileTypeToString(FileType type){
switch(type){
case POSCAR:
return "POSCAR";
case CONTCAR:
return "CONTCAR";
case UNKNOWN:
return "UNKNOWN";
default:
return "";
}
}
int main(int argc, char* argv[]){
if(argc != 2){
cout<<"Usage: filesorter <File Name>"<<endl;
return -1;
}
FileType fileType;
ifstream ifs(argv[1]);
if(!ifs){
cout<<"Cannot open "<<argv[1]<<endl;
return -1;
}
vector<vector<string> > fileContent;
string line;
while(getline(ifs,line)){
vector<string> words;
istringstream iss(line);
string word;
while(iss>>word){
words.push_back(word);
}
fileContent.push_back(words);
}
ifs.close();
/*
for(int i=0;i<fileContent.size();i++){
for(int j=0;j<fileContent[i].size();j++){
cout<<fileContent[i][j]<<" ";
}
cout<<endl;
}
*/
cout<<FileTypeToString(fileSorter(fileContent));
return 0;
}