29{
   30    if (argc < 3)
   31    {
   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 "
   38             << "(integer).\n"
   39             << "       Arguments for mode \"interval\":\n"
   40             << "         <arg1> ... Select structures in this interval "
   41             << "(integer).\n"
   42             << "       Execute in directory with these NNP files present:\n"
   43             << "       - input.data (structure file)\n";
   44        return 1;
   45    }
   46 
   47    bool mode = false; 
   48    bool writeStructure = false;
   49    size_t countStructures = 0;
   50    size_t countSelected = 0;
   51    size_t interval = 10;
   52    int seed = 10;
   53    double ratio = 1.0;
   54 
   56    ifstream inputFile;
   57    ofstream outputFile;
   58    ofstream rejectFile;
   60 
   63 
   64    log << "\n";
   65    log << "*** NNP-SELECT **************************"
   66           "**************************************\n";
   67    log << "\n";
   68 
   69    if (strcmp(argv[1], "random") == 0)
   70    {
   71        mode = false;
   72        if (argc != 4)
   73        {
   74            throw invalid_argument("ERROR: Wrong number of arguments.\n");
   75        }
   76        ratio = atof(argv[2]);
   77        seed = atoi(argv[3]);
   78        srand(seed);
   79        log << 
strpr(
"Selecting randomly %.2f %% of all structures.\n",
 
   80                     ratio * 100.0);
   81        log << 
strpr(
"Random number generator seed: %d.\n", seed);
 
   82    }
   83    else if (strcmp(argv[1], "interval") == 0)
   84    {
   85        mode = true; 
   86        if (argc != 3)
   87        {
   88            throw invalid_argument("ERROR: Wrong number of arguments.\n");
   89        }
   90        interval = (size_t)atoi(argv[2]);
   91        log << 
strpr(
"Selecting every %d structure.\n", interval);
 
   92    }
   93    else
   94    {
   95        throw invalid_argument("ERROR: Unknown selection mode.\n");
   96    }
   97 
   98    log << "*****************************************"
   99           "**************************************\n";
  100 
  101    inputFile.open("input.data");
  102    outputFile.open("output.data");
  103    rejectFile.open("reject.data");
  104    string line;
  105    while (getline(inputFile, line))
  106    {
  108        {
  109            if (mode)
  110            {
  111                if (countStructures % interval == 0) writeStructure = true; 
  112                else writeStructure = false;
  113            }
  114            else
  115            {
  116                if ((double)rand() / RAND_MAX <= ratio) writeStructure = true;
  117                else writeStructure = false;
  118            }
  119            countStructures++; 
  120            if (writeStructure)
  121            {
  122                log << 
strpr(
"Structure %7d selected.\n", countStructures);
 
  123                countSelected++;
  124            }
  125        }
  126        if (writeStructure)
  127        {
  128            outputFile << line << '\n';
  129        }
  130        else
  131        {
  132            rejectFile << line << '\n';
  133        }
  134    }
  135    inputFile.close();
  136    outputFile.close();
  137    rejectFile.close();
  138 
  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";
  148 
  149    return 0;
  150}
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.