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

Copyright (C) 2002, 2003.

A. Ronald Gallant

Permission to use, copy, modify, and distribute this software and its docu-
mentation for any purpose and without fee is hereby granted, provided that 
the above copyright notice appears in all copies and that both that copyright 
notice and this permission notice appear in supporting documentation.  This 
software is provided "as is" without any expressed or implied warranty.

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

#include "libscl.h"
#include "var_usrmod.h"

using namespace std;
using namespace scl;

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

  bool head = false;
  bool tail = true;
  
  string filename("theta001005.dat");
  
  for (INTEGER i=1; i<argc; i++) {
    switch (argp[i][0]) {
      case '-' :
        if (argp[i][1] == 'h') {
	  head = true; 
	  tail = false;
        }
        if (argp[i][1] == 't') {
	  head = false; 
	  tail = true;
        }
	break;
      default:
        filename = argp[i];
	break;
    }
  }

  ifstream sim_stream(filename.c_str());
  if(!sim_stream) error("Error, ends, bad filename");

  realmat sim;
  
  vecread(sim_stream,sim);

  INTEGER t = sim.ncol();
  if (head) t = 1;

  if (tail) cerr << starbox("/tail value is//_") << '\n';
  if (head) cerr << starbox("/head value is//_") << '\n';

  streamsize default_precision = cout.precision(18);
  cout.setf(ios::scientific,ios::floatfield);

  cout << "  const REAL b1_start  = " << sim(1,t) << ";\n";
  cout << "  const REAL b2_start  = " << sim(2,t) << ";\n";
  cout << "  const REAL B11_start = " << sim(3,t) << ";\n";
  cout << "  const REAL B21_start = " << sim(4,t) << ";\n";
  cout << "  const REAL B12_start = " << sim(5,t) << ";\n";
  cout << "  const REAL B22_start = " << sim(6,t) << ";\n";
  cout << "  const REAL R11_start = " << sim(7,t) << ";\n";
  cout << "  const REAL R12_start = " << sim(8,t) << ";\n";
  cout << "  const REAL R22_start = " << sim(9,t) << ";\n";

  cout.setf(ios::fmtflags(0),ios::floatfield);
  cout.precision(default_precision);

  intvec idx = seq(1,n_parms);
  intvec jdx(1,t);
  realmat theta = sim(idx,jdx);

  return 0;
}

