Repository navigation
Expand file tree
/
Copy pathsplit_fci.cpp
More file actions
116 lines (89 loc) · 3.17 KB
/
Copy pathsplit_fci.cpp
File metadata and controls
116 lines (89 loc) · 3.17 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
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
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main(int argc, char* argv[])
{
cout<<"--------------------------------------------"<<endl;
cout<<"--------------------------------------------"<<endl;
cout<<"--- Split the FCIDUMP.out CI vectors ---"<<endl;
cout<<"--------------------------------------------"<<endl;
cout<<"--------------------------------------------"<<endl;
cout<<"-- Developed by: Dr. M. Rodriguez-Mayorga --"<<endl;
cout<<"-- email: marm3.14@gmail.com --"<<endl;
cout<<"--------------------------------------------"<<endl;
cout<<"--------------------------------------------"<<endl;
if (argc != 2)
{
cout<<endl;
cout<<"Include the input file"<<endl;
cout<<"./split_fci FCIDUMP.out"<<endl;
cout<<endl;
cout<<"----------------------------------------"<<endl;
cout<<"-- Normal termination --"<<endl;
cout<<"----------------------------------------"<<endl;
cout<<"----------------------------------------"<<endl;
return 1;
}
std::string input_filename = argv[1];
std::ifstream input(input_filename);
if (!input.is_open()) {
std::cerr << "Error: cannot open input file: "
<< input_filename << '\n';
return 1;
}
// Separate filename and extension
std::string base_name = input_filename;
std::string extension;
std::size_t dot = base_name.find_last_of('.');
if (dot != std::string::npos) {
extension = base_name.substr(dot);
base_name = base_name.substr(0, dot);
}
std::string line;
std::ofstream output;
int vector_number = 0;
bool inside_vector = false;
while (std::getline(input, line)) {
// Beginning of a CI vector
if (!inside_vector &&
line.find("Final CI vector") != std::string::npos) {
++vector_number;
std::string output_filename =
base_name + "_" +
std::to_string(vector_number) +
extension;
output.open(output_filename);
if (!output.is_open()) {
std::cerr << "Error: cannot create "
<< output_filename << '\n';
return 1;
}
inside_vector = true;
// Write the beginning of the vector
output << line << '\n';
continue;
}
// Write lines belonging to the current CI vector
if (inside_vector) {
output << line << '\n';
// End of CI vector
if (line.find("/EOF") != std::string::npos) {
output.close();
inside_vector = false;
}
}
}
// Check for an unfinished vector
if (inside_vector) {
output.close();
std::cerr << "Warning: last CI vector has no /EOF marker.\n";
}
cout << "Extracted "<< vector_number<< " CI vectors.\n";
cout<<endl;
cout<<"----------------------------------------"<<endl;
cout<<"-- Normal termination --"<<endl;
cout<<"----------------------------------------"<<endl;
cout<<"----------------------------------------"<<endl;
return 0;
}