#include <string>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <vector>

#include "JGeometry2D/JVector2D.hh"
#include "JGeometry2D/JEigen2D.hh"

#include "Jeep/JPrint.hh"
#include "Jeep/JParser.hh"
#include "Jeep/JMessage.hh"

namespace {

  /**
   * Write vector to output stream.
   *
   * \param  out          output stream
   * \param  vector       vector
   * \return              output stream
   */
  inline std::ostream& operator<<(std::ostream& out, const JGEOMETRY2D::JVector2D& vector)
  {
    using namespace std;
    using namespace JPP;

    out << "(" 
	<< FIXED(7,3) << vector.getX() << ", " 
	<< FIXED(7,3) << vector.getY() 
	<< ")";
    
    return out;
  }
}


/**
 * \file
 *
 * Example program to print eigen values in 2D.
 * \author mdejong
 */
int main(int argc, char **argv)
{
  using namespace std;
  using namespace JPP;

  string  inputFile;
  int     debug;

  try { 

    JParser<> zap("Example program to print eigen values in 2D.");
    
    zap['f'] = make_field(inputFile);
    zap['d'] = make_field(debug)      = 1;
    
    zap(argc, argv);
  }
  catch(const exception& error) {
    FATAL(error.what() << endl);
  }


  vector<JVector2D> buffer;

  if (inputFile != "") {

    ifstream in(inputFile.c_str());

    for (double x, y; in >> x >> y; ) {
      
      buffer.push_back(JVector2D(x,y));
    }
    
    in.close();
  }

  const JEigenValues2D eigen(buffer.begin(), buffer.end());

  for (JEigenValues2D::const_iterator i = eigen.begin(); i != eigen.end(); ++i) {
    cout << FIXED(7,3) << i->first << ' ' << i->second << endl;
  }
}