/* Copyright (c) 1997-2004
   Ewgenij Gawrilow, Michael Joswig (Technische Universitaet Berlin, Germany)
   http://www.math.tu-berlin.de/polymake,  mailto:polymake@math.tu-berlin.de

   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, or (at your option) any
   later version: http://www.gnu.org/licenses/gpl.txt.

   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.
*/

#ident "$Project: polymake $$Id: rational_float.cc,v 1.10 2004/06/22 16:22:38 gawrilow Exp $"

#include <Poly.h>
#include <Rational.h>
#include <Matrix.h>

using namespace polymake;

namespace {

template <typename Target> inline
void convert_to(Poly& p, const char *in_section, const char *out_section)
{
   const Matrix<Target> X=p.give(in_section);
   p.take(out_section) << X;
}

}

int main(int argc, char *argv[]) {
   if (argc < 4 || argc > 5 || strcmp(argv[argc-1],"Rational") && strcmp(argv[argc-1],"float")) {
      cerr << "usage: " << argv[0] << " <file> <section> [ <out-section> ] { Rational | float }" << endl;
      return 1;
   }
   try {
      Poly p(argv[1], ios::in | ios::out);
      if (!strcmp(argv[argc-1],"Rational"))
	 convert_to<Rational>(p, argv[2], argv[argc-2]);
      else
	 convert_to<double>(p, argv[2], argv[argc-2]);
   }
   catch (const std::exception& e) {
      cerr << e.what() << endl;
      return 1;
   }
   return 0;
}
