/*-----------------------------------------------------------------------------

Copyright (C) 2007.

A. Ronald Gallant
Post Office Box 659
Chapel Hill NC 27514-0659
USA

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

-----------------------------------------------------------------------------*/

#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;

  return 0;
}
