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

int main(int argc, char** argp, char** envp)
{
  // If you know how big a vector will be ahead of time, you can declare
  // its length and use it like an array rather than use push_back.

  INT_32BIT seed = 12345;
  
  typedef vector<REAL>::size_type rv_int;

  rv_int len_rv = 9;
  
  vector<REAL> rv(len_rv); 
  
  for (rv_int i=0; i<len_rv; i++) {    // Note: counting from zero
    rv[i] = scl::unsk(seed);           // unsk is normal(0,1)
  }

  cout << starbox("/Contents of rv//") << '\n';
  for (rv_int i=0; i<rv.size(); i++) { // Note: counting from zero
    cout << "     rv["<<i<<"] = " << rv[i] << '\n';
  }
  
  // This usage has some of the pitfalls of arrays.  The use of
  // push_back as in the book is safer.  If you want to make it
  // more efficient, do this.

  rv_int est_len_rmv = 1000;
  vector<realmat> rmv;
  rmv.reserve(est_len_rmv);

  INTEGER j = 1;
  while (j < 9) {
    realmat rm(1,j);
    for (INTEGER i=1; i<=j; i++) {     // Note: counting from one
      rm[i] = scl::ran(seed);       // ran is uniform on (0,1)
    }
    j = scl::iran(seed,9)+1;        // iran is uniform on 0,..,9 
    rmv.push_back(rm);        
  }

  // Regardless of the amount of space reserved, this works the same as
  // in the text and size reports what was actually pushed, not what you
  // reserved.

  cout << starbox("/Contents of rmv//");

  typedef vector<realmat>::size_type rmv_int;
  for (rmv_int i=0; i<rmv.size(); i++) { // Note: counting from zero.
    cout << rmv[i];
  }
  cout << "\n     Unused capacity = "<< rmv.capacity()-rmv.size()<<'\n';
  
  // As with vectors, realmats can be grown as needed.
  
  realmat A(2,1,REAL_MAX);
  realmat B(1,2,-REAL_MAX);

  for (INTEGER i=1; i<=iran(seed,15)+1; i++) { // Note: counting from one
    realmat new_col(2,1,unsk(seed));
    A = cbind(A,new_col);
    realmat new_row(1,2,unsk(seed));
    B = rbind(B,new_row);
  }

  cout << starbox("/Contents of A and B//") << A << B;

  return 0;

}
