28int main(
int argc,
char* argv[])
32 cout <<
"USAGE: " << argv[0] <<
" <mode> <arg1 <arg2>>\n"
33 <<
" <mode> ... Choose selection mode (random/interval).\n"
34 <<
" Arguments for mode \"random\":\n"
35 <<
" <arg1> ... Ratio of selected structures "
36 <<
"(1.0 equals 100 %).\n"
37 <<
" <arg2> ... Seed for random number generator "
39 <<
" Arguments for mode \"interval\":\n"
40 <<
" <arg1> ... Select structures in this interval "
42 <<
" Execute in directory with these NNP files present:\n"
43 <<
" - input.data (structure file)\n";
48 bool writeStructure =
false;
49 size_t countStructures = 0;
50 size_t countSelected = 0;
65 log <<
"*** NNP-SELECT **************************"
66 "**************************************\n";
69 if (strcmp(argv[1],
"random") == 0)
74 throw invalid_argument(
"ERROR: Wrong number of arguments.\n");
76 ratio = atof(argv[2]);
79 log <<
strpr(
"Selecting randomly %.2f %% of all structures.\n",
81 log <<
strpr(
"Random number generator seed: %d.\n", seed);
83 else if (strcmp(argv[1],
"interval") == 0)
88 throw invalid_argument(
"ERROR: Wrong number of arguments.\n");
90 interval = (size_t)atoi(argv[2]);
91 log <<
strpr(
"Selecting every %d structure.\n", interval);
95 throw invalid_argument(
"ERROR: Unknown selection mode.\n");
98 log <<
"*****************************************"
99 "**************************************\n";
101 inputFile.open(
"input.data");
102 outputFile.open(
"output.data");
103 rejectFile.open(
"reject.data");
105 while (getline(inputFile, line))
111 if (countStructures % interval == 0) writeStructure =
true;
112 else writeStructure =
false;
116 if ((
double)rand() / RAND_MAX <= ratio) writeStructure =
true;
117 else writeStructure =
false;
122 log <<
strpr(
"Structure %7d selected.\n", countStructures);
128 outputFile << line <<
'\n';
132 rejectFile << line <<
'\n';
139 log <<
"*****************************************"
140 "**************************************\n";
141 log <<
strpr(
"Total structures : %7d\n", countStructures);
142 log <<
strpr(
"Selected structures : %7d\n", countSelected);
143 log <<
strpr(
"Selected structures percentage: %.3f %%\n",
144 countSelected / (
double)countStructures * 100.0);
145 log <<
"*****************************************"
146 "**************************************\n";
Logging class for library output.
void registerStreamPointer(std::ofstream *const &streamPointer)
Register new C++ ofstream pointer.
string strpr(const char *format,...)
String version of printf function.
vector< string > split(string const &input, char delimiter)
Split string at each delimiter.
string reduce(string const &line, string const &whitespace, string const &fill)
Replace multiple whitespaces with fill.
int main(int argc, char *argv[])