#include "libscl.h"

using namespace scl;
using namespace std;

int main(int argc, char** argp, char** envp)
{
  INTEGER count = argc;
  char** ptr = argp;

  char* arg = *ptr++;
  
  string progname;
  while(*arg) progname.push_back(*arg++);

  cout << '\n';

  realmat reject;
  while (--count) {
    arg = *ptr++;
    string filename;
    while(*arg) filename.push_back(*arg++);
    realmat rej;
    if ( !vecread(filename.c_str(),rej) ) {
      error("Error, " + progname + " cannot open " + filename);
    }
    else {
      cout << progname << " successfully read " << filename << '\n';
    }
    if (reject.size() == 0) {
      reject = rej;
    }
    else {
      reject += rej;
    }
  }

  INTEGER n = reject.nrow();

  for (INTEGER i=1; i<=n; ++i) {
    REAL bot = reject(i,4);
    if (bot>0.0) reject(i,1) = reject(i,3)/bot;
    bot = reject(n,4);
    if (bot>0.0) reject(i,2) = reject(i,4)/bot;
  }

  cout << reject;

  cout << '\n';
  cout << "Column 4 is the number of proposed moves.\n";
  cout << "Column 3 is the number of rejections.\n";
  cout << "Column 2 is the number of proposed moves as a proportion.\n";
  cout << "Column 1 is the rejection rate; "
          "i.e., column 3 divided by column 4.\n";
  cout << "Rows 1 through " << n-1 << " correspond to parameters; row "
       << n << " is the total." << '\n';
  cout << '\n';

  return 0;
}
