#include "libscl.h" 
using namespace scl; 
using namespace std;

int main(int argc, char** argp, char** envp)
{

  vector<string> string_names;
  vector< vector<string> > string_data;
  vector<string> numeric_names;
  realmat numeric_data;
  vector<string> unknown_names;

  csvread("epa.csv", true, string_names, string_data,
    numeric_names, numeric_data, unknown_names);

  cout << starbox("/Names of the columns of numeric_data//");
  for (vector<string>::size_type i = 0; i != numeric_names.size(); ++i) {
    cout << "\t Col" << fmt('d',4,i+1) << "    " << numeric_names[i] << '\n';
  }

  cout << starbox("/First five rows of numeric_data//");
  cout << numeric_data("1:5","");

  cout << starbox("/Last five rows of numeric_data//");
  cout << numeric_data(seq(numeric_data.nrow()-4,numeric_data.nrow()),"");

  vector<string> model = string_data[0];

  realmat mpg_sorted = numeric_data("",1);
  intvec mpg_rank = mpg_sorted.sort();

  cout << starbox("/Five least efficient cars/unadjusted data//");
  cout << "\tRow  Make and Model        Miles per Gallon \n";
  for (INTEGER i=1; i<=5; ++i) {
    cout << '\t' << fmt('i',3,mpg_rank[i]) << "  " << model[mpg_rank[i]-1] 
         << ' ' << fmt('f',5,2,mpg_sorted[i]) << '\n';
  }

  cout << starbox("/Five most efficient cars/unadjusted data//");
  cout << "\tRow  Make and Model        Miles per Gallon \n";
  for (INTEGER i=numeric_data.nrow(); i>numeric_data.nrow()-5; --i) {
    cout << '\t' << fmt('i',3,mpg_rank[i]) << "  " << model[mpg_rank[i]-1] 
         << ' ' << fmt('f',5,2,mpg_sorted[i]) << '\n';
  }

  realmat X = numeric_data("","3:14");
  realmat y = numeric_data("",2);

  return 0;
}
